From 5b54bb1d03ddda7180d8b30bf1444634985402aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 12 Jun 2010 06:56:40 +0000 Subject: [PATCH] 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 --- client.cpp | 37 +++++++++++++++++++++-- client.h | 17 ++++++++++- group.cpp | 30 ++++++++++++++++-- group.h | 2 ++ kcmkwin/kwintabbox/previewhandlerimpl.cpp | 4 +-- kcmkwin/kwintabbox/previewhandlerimpl.h | 2 +- tabbox.cpp | 4 +-- tabbox.h | 2 +- tabbox/clientitemdelegate.cpp | 17 +++++++++-- tabbox/tabboxhandler.h | 3 +- 10 files changed, 104 insertions(+), 14 deletions(-) diff --git a/client.cpp b/client.cpp index a3dfdf8124..61656c2116 100644 --- a/client.cpp +++ b/client.cpp @@ -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; diff --git a/client.h b/client.h index da14c2f157..e13bd0f3ed 100644 --- a/client.h +++ b/client.h @@ -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; diff --git a/group.cpp b/group.cpp index ce18c644ae..868080c638 100644 --- a/group.cpp +++ b/group.cpp @@ -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(); diff --git a/group.h b/group.h index 5776183cf4..b1a80129d7 100644 --- a/group.h +++ b/group.h @@ -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 ); diff --git a/kcmkwin/kwintabbox/previewhandlerimpl.cpp b/kcmkwin/kwintabbox/previewhandlerimpl.cpp index 470cd2f2a3..c437f29d98 100644 --- a/kcmkwin/kwintabbox/previewhandlerimpl.cpp +++ b/kcmkwin/kwintabbox/previewhandlerimpl.cpp @@ -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 diff --git a/kcmkwin/kwintabbox/previewhandlerimpl.h b/kcmkwin/kwintabbox/previewhandlerimpl.h index b8f51fe01b..2f906f34a8 100644 --- a/kcmkwin/kwintabbox/previewhandlerimpl.h +++ b/kcmkwin/kwintabbox/previewhandlerimpl.h @@ -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; diff --git a/tabbox.cpp b/tabbox.cpp index f0cec22375..d66d243e5f 100644 --- a/tabbox.cpp +++ b/tabbox.cpp @@ -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 diff --git a/tabbox.h b/tabbox.h index 90e42b1f71..20e7aa2323 100644 --- a/tabbox.h +++ b/tabbox.h @@ -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; diff --git a/tabbox/clientitemdelegate.cpp b/tabbox/clientitemdelegate.cpp index 2e56e65fe5..2d73b70e10 100644 --- a/tabbox/clientitemdelegate.cpp +++ b/tabbox/clientitemdelegate.cpp @@ -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(); diff --git a/tabbox/tabboxhandler.h b/tabbox/tabboxhandler.h index bd24888a18..3096fc44c2 100644 --- a/tabbox/tabboxhandler.h +++ b/tabbox/tabboxhandler.h @@ -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 */