From 5b162c07e2ee26796b6e9408364eba19142acd71 Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Fri, 20 May 2016 16:00:04 +0200 Subject: [PATCH] TabWidget: Made the artworks' color themeable --- data/themes/default/style.css | 2 ++ include/TabWidget.h | 18 ++++++++++---- src/gui/widgets/TabWidget.cpp | 46 +++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/data/themes/default/style.css b/data/themes/default/style.css index 3c306f159..7408fc059 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -133,6 +133,8 @@ TabWidget { qproperty-tabSelected: rgb(160, 160, 160); qproperty-tabBackground: rgb(60, 67, 75); qproperty-tabBorder: rgb(60, 67, 75); + qproperty-tabArtworkActive: rgb(255, 255, 255); + qproperty-tabArtworkInactive: rgb(160, 160, 160); } /* main toolbar oscilloscope - can have transparent bg now */ diff --git a/include/TabWidget.h b/include/TabWidget.h index e2239b103..fbee38f0b 100644 --- a/include/TabWidget.h +++ b/include/TabWidget.h @@ -56,6 +56,8 @@ public: Q_PROPERTY( QColor tabSelected READ tabSelected WRITE setTabSelected) Q_PROPERTY( QColor tabBackground READ tabBackground WRITE setTabBackground) Q_PROPERTY( QColor tabBorder READ tabBorder WRITE setTabBorder) + Q_PROPERTY( QColor tabArtworkActive READ tabArtworkActive WRITE setTabArtworkActive) + Q_PROPERTY( QColor tabArtworkInactive READ tabArtworkInactive WRITE setTabArtworkInactive) QColor tabText() const; void setTabText( const QColor & c ); @@ -67,6 +69,10 @@ public: void setTabBackground( const QColor & c ); QColor tabBorder() const; void setTabBorder( const QColor & c ); + QColor tabArtworkActive() const; + void setTabArtworkActive( const QColor & c ); + QColor tabArtworkInactive() const; + void setTabArtworkInactive( const QColor & c ); protected: virtual bool event( QEvent * event ); @@ -96,11 +102,13 @@ private: quint8 m_tabheight; // The height of the tabs bool m_usePixmap; // true if the tabs are to be displayed with icons. False for text tabs. - QColor m_tabText; // The color of the tabs' text. - QColor m_tabTitleText; // The color of the TabWidget's title text. - QColor m_tabSelected; // The highlighting color for the selected tab. - QColor m_tabBackground; // The TabWidget's background color. - QColor m_tabBorder; // The TabWidget's borders color. + QColor m_tabText; // The color of the tabs' text. + QColor m_tabTitleText; // The color of the TabWidget's title text. + QColor m_tabSelected; // The highlighting color for the selected tab. + QColor m_tabBackground; // The TabWidget's background color. + QColor m_tabBorder; // The TabWidget's borders color. + QColor m_tabArtworkActive; // The color for active artwork tabs. + QColor m_tabArtworkInactive; // The color for inactive artwork tabs. } ; #endif diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index a4f02f184..d23f8ac3b 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,9 @@ TabWidget::TabWidget( const QString & caption, QWidget * parent, bool usePixmap m_tabTitleText( 0, 0, 0 ), m_tabSelected( 0, 0, 0 ), m_tabBackground( 0, 0, 0 ), - m_tabBorder( 0, 0, 0 ) + m_tabBorder( 0, 0, 0 ), + m_tabArtworkActive( 0, 0, 0 ), + m_tabArtworkInactive( 0, 0, 0 ) { // Create taller tabbar when it's to display artwork tabs @@ -242,7 +245,6 @@ void TabWidget::paintEvent( QPaintEvent * pe ) } // Draw all tabs - p.setPen( tabText() ); for( widgetStack::iterator it = first ; it != last ; ++it ) { @@ -252,17 +254,21 @@ void TabWidget::paintEvent( QPaintEvent * pe ) // Fixes tab's width, because original size is only correct for text tabs ( *it ).nwidth = tab_width; - // Get artwork - QPixmap artwork( embed::getIconPixmap( ( *it ).inactivePixmap ) ); + // Create a mask out of the tab's artwork (for changing it's color later on) + QBitmap mask = QPixmap( embed::getIconPixmap( ( *it ).activePixmap ) ).createMaskFromColor( Qt::black, Qt::MaskOutColor ); - // Highlight active tab + // Select artwork's color and highlight active tab if( it.key() == m_activeTab ) { p.fillRect( tab_x_offset, 0, ( *it ).nwidth, m_tabbarHeight - 1, tabSelected() ); + p.setPen( tabArtworkActive() ); + } else + { + p.setPen( tabArtworkInactive() ); } - - // Draw artwork - p.drawPixmap(tab_x_offset + ( ( *it ).nwidth - artwork.width() ) / 2, 1, artwork ); + + // Draw colorized artwork + p.drawPixmap(tab_x_offset + ( ( *it ).nwidth - mask.width() ) / 2, 1, mask ); } else { // Highlight tab when active @@ -272,6 +278,7 @@ void TabWidget::paintEvent( QPaintEvent * pe ) } // Draw text + p.setPen( tabText() ); p.drawText( tab_x_offset + 3, m_tabheight + 1, ( *it ).name ); } @@ -363,3 +370,26 @@ void TabWidget::setTabBorder( const QColor & c ) m_tabBorder = c; } +// Return the color to be used for drawing active artwork tabs +QColor TabWidget::tabArtworkActive() const +{ + return m_tabArtworkActive; +} + +// Set the color to be used for drawing active artwork tabs +void TabWidget::setTabArtworkActive( const QColor & c ) +{ + m_tabArtworkActive = c; +} + +// Return the color to be used for drawing inactive artwork tabs +QColor TabWidget::tabArtworkInactive() const +{ + return m_tabArtworkInactive; +} + +// Set the color to be used for drawing inactive artwork tabs +void TabWidget::setTabArtworkInactive( const QColor & c ) +{ + m_tabArtworkInactive = c; +}