From 3549e07e940e883e88d16ff6601b9df7e59a41d8 Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Thu, 12 May 2016 16:33:18 +0200 Subject: [PATCH] The highlighting color for a TabWidget'selected tab is now themeable. --- data/themes/default/style.css | 1 + include/TabWidget.h | 7 +++++++ src/gui/widgets/TabWidget.cpp | 29 ++++++++++++++++++++--------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/data/themes/default/style.css b/data/themes/default/style.css index 8a81f1c7f..20acde994 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -128,6 +128,7 @@ PianoRoll { TabWidget { background-color: #5b6571; + qproperty-tabSelected: rgb(160, 160, 160); } /* main toolbar oscilloscope - can have transparent bg now */ diff --git a/include/TabWidget.h b/include/TabWidget.h index 04ef71068..fddcf8de1 100644 --- a/include/TabWidget.h +++ b/include/TabWidget.h @@ -50,6 +50,11 @@ public: return( m_activeTab ); } + // Themeability + Q_PROPERTY( QColor tabSelected READ tabSelected WRITE setTabSelected) + + QColor tabSelected() const; + void setTabSelected( const QColor & c ); protected: virtual bool event( QEvent * event ); @@ -78,6 +83,8 @@ private: quint8 m_tabbarHeight; // The height of the tab bar 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_tabSelected; // The highlighting color for the selected tab. } ; #endif diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index 331a2cc81..dea841a8c 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -38,11 +38,13 @@ TabWidget::TabWidget( const QString & caption, QWidget * parent, bool usePixmap QWidget( parent ), m_activeTab( 0 ), m_caption( caption ), - m_usePixmap( usePixmap ) + m_usePixmap( usePixmap ), + m_tabSelected( 0, 0, 0 ) { // Create taller tabbar when it's to display artwork tabs m_tabbarHeight = usePixmap ? GRAPHIC_TAB_HEIGHT : TEXT_TAB_HEIGHT; + m_tabheight = caption.isEmpty() ? m_tabbarHeight - 3 : m_tabbarHeight - 4; setFont( pointSize<8>( font() ) ); @@ -231,20 +233,18 @@ void TabWidget::paintEvent( QPaintEvent * pe ) p.drawText( 5, 11, m_caption ); } - // Calculate the tabs' x (tabs are painted next to the caption) - int tab_x_offset = m_caption.isEmpty() ? 4 : 14 + fontMetrics().width( m_caption ); + // Calculate the tabs' x (tabs are painted next to the caption) + int tab_x_offset = m_caption.isEmpty() ? 4 : 14 + fontMetrics().width( m_caption ); - QColor cap_col( 160, 160, 160 ); if( big_tab_captions ) { p.setFont( pointSize<8>( p.font() ) ); - cap_col = QColor( 224, 224, 224 ); } else { p.setFont( pointSize<7>( p.font() ) ); } - p.setPen( cap_col ); + p.setPen( tabSelected() ); // Compute tabs' width depending on the number of tabs (only applicable for artwork tabs) widgetStack::iterator first = m_widgets.begin(); @@ -271,7 +271,7 @@ void TabWidget::paintEvent( QPaintEvent * pe ) if( it.key() == m_activeTab ) { artwork = new QPixmap( embed::getIconPixmap( ( *it ).activePixmap ) ); - p.fillRect( tab_x_offset, 3, ( *it ).nwidth, m_tabbarHeight - 5, cap_col ); + p.fillRect( tab_x_offset, 3, ( *it ).nwidth, m_tabbarHeight - 5, tabSelected() ); } else { artwork = new QPixmap( embed::getIconPixmap( ( *it ).inactivePixmap ) ); @@ -287,14 +287,14 @@ void TabWidget::paintEvent( QPaintEvent * pe ) if( it.key() == m_activeTab ) { p.setPen( QColor( 32, 48, 64 ) ); - p.fillRect( tab_x_offset, 2, ( *it ).nwidth - 6, m_tabbarHeight - 4, cap_col ); + 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( cap_col ); + p.setPen( tabSelected() ); } // Next tab's horizontal position @@ -324,3 +324,14 @@ void TabWidget::wheelEvent( QWheelEvent * we ) } setActiveTab( tab ); } + +QColor TabWidget::tabSelected() const +{ + return m_tabSelected; +} + +void TabWidget::setTabSelected( const QColor & c ) +{ + m_tabSelected = c; +} +