From 179008faa4ddb8a4b1298613d27a42f7a1ce2191 Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Fri, 13 May 2016 12:41:53 +0200 Subject: [PATCH] Made TabWidget's Title text and tab text themeable. --- data/themes/default/style.css | 2 ++ include/TabWidget.h | 8 +++++++ src/gui/widgets/TabWidget.cpp | 42 +++++++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/data/themes/default/style.css b/data/themes/default/style.css index 20acde994..813e705b3 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -128,6 +128,8 @@ PianoRoll { TabWidget { background-color: #5b6571; + qproperty-tabText: rgb(32, 48, 64); + qproperty-tabTitleText: rgb(255, 255, 255); qproperty-tabSelected: rgb(160, 160, 160); } diff --git a/include/TabWidget.h b/include/TabWidget.h index fddcf8de1..c289f684d 100644 --- a/include/TabWidget.h +++ b/include/TabWidget.h @@ -51,8 +51,14 @@ public: } // Themeability + Q_PROPERTY( QColor tabText READ tabText WRITE setTabText) + Q_PROPERTY( QColor tabTitleText READ tabTitleText WRITE setTabTitleText) Q_PROPERTY( QColor tabSelected READ tabSelected WRITE setTabSelected) + QColor tabText() const; + void setTabText( const QColor & c ); + QColor tabTitleText() const; + void setTabTitleText( const QColor & c ); QColor tabSelected() const; void setTabSelected( const QColor & c ); @@ -84,6 +90,8 @@ 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. } ; diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index dea841a8c..4f726ea95 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -39,6 +39,8 @@ TabWidget::TabWidget( const QString & caption, QWidget * parent, bool usePixmap m_activeTab( 0 ), m_caption( caption ), m_usePixmap( usePixmap ), + m_tabText( 0, 0, 0 ), + m_tabTitleText( 0, 0, 0 ), m_tabSelected( 0, 0, 0 ) { @@ -59,12 +61,10 @@ TabWidget::TabWidget( const QString & caption, QWidget * parent, bool usePixmap } - TabWidget::~TabWidget() { } - void TabWidget::addTab( QWidget * w, const QString & name, const QString & tooltip, const char *activePixmap, const char *inactivePixmap, int idx ) { setFont( pointSize<8>( font() ) ); @@ -208,7 +208,6 @@ void TabWidget::paintEvent( QPaintEvent * pe ) setFont( pointSize<8>( font() ) ); QPainter p( this ); -// QColor bg_color = QApplication::palette().color( QPalette::Active, QPalette::Background ); QBrush bg_color = p.background(); p.fillRect( 0, 0, width() - 1, height() - 1, bg_color ); @@ -229,7 +228,7 @@ void TabWidget::paintEvent( QPaintEvent * pe ) if( ! m_caption.isEmpty() ) { - p.setPen( QColor( 255, 255, 255 ) ); + p.setPen( tabTitleText() ); p.drawText( 5, 11, m_caption ); } @@ -244,7 +243,6 @@ void TabWidget::paintEvent( QPaintEvent * pe ) { p.setFont( pointSize<7>( p.font() ) ); } - p.setPen( tabSelected() ); // Compute tabs' width depending on the number of tabs (only applicable for artwork tabs) widgetStack::iterator first = m_widgets.begin(); @@ -256,13 +254,13 @@ void TabWidget::paintEvent( QPaintEvent * pe ) } // Draw all tabs + p.setPen( tabText() ); for( widgetStack::iterator it = first ; it != last ; ++it ) { // Draw a text tab or a artwork tab. if ( m_usePixmap ) { - // Fixes tab's width, because original size is only correct for text tabs ( *it ).nwidth = tab_width; @@ -279,22 +277,16 @@ void TabWidget::paintEvent( QPaintEvent * pe ) // Draw artwork p.drawPixmap(tab_x_offset + ( ( *it ).nwidth - ( *artwork ).width() ) / 2, 3, *artwork ); - } else { - // Highlight tab when active if( it.key() == m_activeTab ) { - p.setPen( QColor( 32, 48, 64 ) ); p.fillRect( tab_x_offset, 2, ( *it ).nwidth - 6, m_tabbarHeight - 4, tabSelected() ); } // Draw text p.drawText( tab_x_offset + 3, m_tabheight, ( *it ).name ); - - // Reset text color - p.setPen( tabSelected() ); } // Next tab's horizontal position @@ -325,11 +317,37 @@ void TabWidget::wheelEvent( QWheelEvent * we ) setActiveTab( tab ); } +// Return the color to be used to draw a TabWidget's title text (if any) +QColor TabWidget::tabTitleText() const +{ + return m_tabTitleText; +} + +// Set the color to be used to draw a TabWidget's title text (if any) +void TabWidget::setTabTitleText( const QColor & c ) +{ + m_tabTitleText = c; +} + +// Return the color to be used to draw a TabWidget's text (if any) +QColor TabWidget::tabText() const +{ + return m_tabText; +} + +// Set the color to be used to draw a TabWidget's text (if any) +void TabWidget::setTabText( const QColor & c ) +{ + m_tabText = c; +} + +// Return the color to be used to highlight a TabWidget'selected tab (if any) QColor TabWidget::tabSelected() const { return m_tabSelected; } +// Set the color to be used to highlight a TabWidget'selected tab (if any) void TabWidget::setTabSelected( const QColor & c ) { m_tabSelected = c;