Forward port rev 1137263:

Make icon sizes 64x64 and 128x128 available in KWin and use it in TabBox for large icon modes.
So no more ugly upscaling.
CCBUG: 241384

svn path=/trunk/KDE/kdebase/workspace/; revision=1137264
This commit is contained in:
Martin Gräßlin 2010-06-12 06:56:40 +00:00
parent b9975cb40d
commit 5b54bb1d03
10 changed files with 104 additions and 14 deletions

View file

@ -1878,7 +1878,7 @@ void Client::getMotifHints()
updateDecoration( true ); // Check if noborder state has changed
}
void Client::readIcons( Window win, QPixmap* icon, QPixmap* miniicon )
void Client::readIcons( Window win, QPixmap* icon, QPixmap* miniicon, QPixmap* bigicon, QPixmap* hugeicon )
{
// Get the icons, allow scaling
if( icon != NULL )
@ -1890,16 +1890,32 @@ void Client::readIcons( Window win, QPixmap* icon, QPixmap* miniicon )
else
*miniicon = QPixmap();
}
if( bigicon != NULL )
{
if( icon == NULL || !icon->isNull() )
*bigicon = KWindowSystem::icon( win, 64, 64, false, KWindowSystem::NETWM | KWindowSystem::WMHints );
else
*bigicon = QPixmap();
}
if( hugeicon != NULL )
{
if( icon == NULL || !icon->isNull() )
*hugeicon = KWindowSystem::icon( win, 128, 128, false, KWindowSystem::NETWM | KWindowSystem::WMHints );
else
*hugeicon = QPixmap();
}
}
void Client::getIcons()
{
// First read icons from the window itself
readIcons( window(), &icon_pix, &miniicon_pix );
readIcons( window(), &icon_pix, &miniicon_pix, &bigicon_pix, &hugeicon_pix );
if( icon_pix.isNull() )
{ // Then try window group
icon_pix = group()->icon();
miniicon_pix = group()->miniIcon();
bigicon_pix = group()->bigIcon();
hugeicon_pix = group()->hugeIcon();
}
if( icon_pix.isNull() && isTransient() )
{ // Then mainclients
@ -1910,17 +1926,34 @@ void Client::getIcons()
{
icon_pix = (*it)->icon();
miniicon_pix = (*it)->miniIcon();
bigicon_pix = (*it)->bigIcon();
hugeicon_pix = (*it)->hugeIcon();
}
}
if( icon_pix.isNull())
{ // And if nothing else, load icon from classhint or xapp icon
icon_pix = KWindowSystem::icon( window(), 32, 32, true, KWindowSystem::ClassHint | KWindowSystem::XApp );
miniicon_pix = KWindowSystem::icon( window(), 16, 16, true, KWindowSystem::ClassHint | KWindowSystem::XApp );
bigicon_pix = KWindowSystem::icon( window(), 64, 64, false, KWindowSystem::ClassHint | KWindowSystem::XApp );
hugeicon_pix = KWindowSystem::icon( window(), 128, 128, false, KWindowSystem::ClassHint | KWindowSystem::XApp );
}
if( isManaged() && decoration != NULL )
decoration->iconChange();
}
QPixmap Client::icon( const QSize& size ) const
{
const int iconSize = qMin( size.width(), size.height() );
if( iconSize <= 16 )
return miniIcon();
else if( iconSize <= 32 )
return icon();
if( iconSize <= 64 )
return bigIcon();
else
return hugeIcon();
}
void Client::getWindowProtocols()
{
Atom* p;

View file

@ -134,7 +134,10 @@ class Client
QSize adjustedSize() const;
QPixmap icon() const;
QPixmap icon( const QSize& size ) const;
QPixmap miniIcon() const;
QPixmap bigIcon() const;
QPixmap hugeIcon() const;
bool isActive() const;
void setActive( bool );
@ -299,7 +302,7 @@ class Client
static bool belongToSameApplication( const Client* c1, const Client* c2, bool active_hack = false );
static bool sameAppWindowRoleMatch( const Client* c1, const Client* c2, bool active_hack );
static void readIcons( Window win, QPixmap* icon, QPixmap* miniicon );
static void readIcons( Window win, QPixmap* icon, QPixmap* miniicon, QPixmap* bigicon, QPixmap* hugeicon );
void minimize( bool avoid_animation = false );
void unminimize( bool avoid_animation = false );
@ -586,6 +589,8 @@ class Client
void getWindowProtocols();
QPixmap icon_pix;
QPixmap miniicon_pix;
QPixmap bigicon_pix;
QPixmap hugeicon_pix;
QCursor cursor;
// DON'T reorder - Saved to config files !!!
enum FullScreenMode
@ -791,6 +796,16 @@ inline QPixmap Client::miniIcon() const
return miniicon_pix;
}
inline QPixmap Client::bigIcon() const
{
return bigicon_pix;
}
inline QPixmap Client::hugeIcon() const
{
return hugeicon_pix;
}
inline QRect Client::geometryRestore() const
{
return geom_restore;

View file

@ -241,7 +241,7 @@ QPixmap Group::icon() const
else if( leader_wid != None )
{
QPixmap ic;
Client::readIcons( leader_wid, &ic, NULL );
Client::readIcons( leader_wid, &ic, NULL, NULL, NULL );
return ic;
}
return QPixmap();
@ -254,7 +254,33 @@ QPixmap Group::miniIcon() const
else if( leader_wid != None )
{
QPixmap ic;
Client::readIcons( leader_wid, NULL, &ic );
Client::readIcons( leader_wid, NULL, &ic, NULL, NULL );
return ic;
}
return QPixmap();
}
QPixmap Group::bigIcon() const
{
if( leader_client != NULL )
return leader_client->bigIcon();
else if( leader_wid != None )
{
QPixmap ic;
Client::readIcons( leader_wid, NULL, NULL, &ic, NULL );
return ic;
}
return QPixmap();
}
QPixmap Group::hugeIcon() const
{
if( leader_client != NULL )
return leader_client->hugeIcon();
else if( leader_wid != None )
{
QPixmap ic;
Client::readIcons( leader_wid, NULL, NULL, NULL, &ic );
return ic;
}
return QPixmap();

View file

@ -44,6 +44,8 @@ class Group
const ClientList& members() const;
QPixmap icon() const;
QPixmap miniIcon() const;
QPixmap bigIcon() const;
QPixmap hugeIcon() const;
void addMember( Client* member );
void removeMember( Client* member );
void gotLeader( Client* leader );

View file

@ -44,9 +44,9 @@ QString PreviewClientImpl::caption() const
return info.visibleName();
}
QPixmap PreviewClientImpl::icon() const
QPixmap PreviewClientImpl::icon( const QSize& size ) const
{
return KWindowSystem::icon( m_id );
return KWindowSystem::icon( m_id, size.width(), size.height(), true );
}
bool PreviewClientImpl::isMinimized() const

View file

@ -38,7 +38,7 @@ class PreviewClientImpl :
virtual QString caption() const;
virtual int height() const;
virtual QPixmap icon() const;
virtual QPixmap icon( const QSize& size = QSize( 32, 32 ) ) const;
virtual bool isMinimized() const;
virtual int width() const;
virtual WId window() const;

View file

@ -214,9 +214,9 @@ QString TabBoxClientImpl::caption() const
return m_client->caption();
}
QPixmap TabBoxClientImpl::icon() const
QPixmap TabBoxClientImpl::icon( const QSize& size ) const
{
return m_client->icon();
return m_client->icon( size );
}
WId TabBoxClientImpl::window() const

View file

@ -65,7 +65,7 @@ class TabBoxClientImpl : public TabBoxClient
virtual ~TabBoxClientImpl();
virtual QString caption() const;
virtual QPixmap icon() const;
virtual QPixmap icon( const QSize& size = QSize( 32, 32 ) ) const;
virtual WId window() const;
virtual bool isMinimized() const;
virtual int x() const;

View file

@ -172,7 +172,7 @@ void ClientItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& o
if( element.isRowSpan() )
iconY = option.rect.top() + option.rect.height() * 0.5 - element.iconSize().height() * 0.5;
QRectF iconRect = QRectF( iconX, iconY, element.iconSize().width(), element.iconSize().height() );
QPixmap icon = client->icon();
QPixmap icon = client->icon( element.iconSize().toSize() );
if( !icon.isNull() )
{
if( m_config.isHighlightSelectedIcons() && option.state & QStyle::State_Selected )
@ -185,7 +185,20 @@ void ClientItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& o
KIconEffect *effect = KIconLoader::global()->iconEffect();
icon = effect->apply( icon, KIconLoader::Desktop, KIconLoader::DisabledState );
}
QRectF sourceRect = QRectF( 0.0, 0.0, icon.width(), icon.height() );
QRectF sourceRect = QRectF( QPointF( 0.0, 0.0 ), element.iconSize() );
if( icon.width() > element.iconSize().width() )
{
// if icon is bigger than our region, scale it down
sourceRect = QRectF( 0.0, 0.0, icon.width(), icon.height() );
}
else if ( icon.width() < element.iconSize().width() )
{
// don't scale - center in requested area
sourceRect = QRectF( 0.0, 0.0, icon.width(), icon.height() );
iconRect = QRectF( iconX + (element.iconSize().width()-icon.width())/2,
iconY + (element.iconSize().height()-icon.height())/2,
icon.width(), icon.height() );
}
painter->drawPixmap( iconRect, icon, sourceRect );
}
x += element.width();

View file

@ -329,9 +329,10 @@ class TabBoxClient
*/
virtual QString caption() const = 0;
/**
* @param size Requested size of the icon
* @return The icon of the client
*/
virtual QPixmap icon() const = 0;
virtual QPixmap icon( const QSize& size = QSize( 32, 32 ) ) const = 0;
/**
* @return The window Id of the client
*/