TabWidget: Made the artworks' color themeable

This commit is contained in:
Cyrille Bollu
2016-05-20 16:00:04 +02:00
parent b75969e3fe
commit 5b162c07e2
3 changed files with 53 additions and 13 deletions

View File

@@ -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 */

View File

@@ -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

View File

@@ -28,6 +28,7 @@
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QBitmap>
#include <QToolTip>
#include <QWheelEvent>
@@ -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;
}