Skip to content

Commit

Permalink
TabWidget: Made the artworks' color themeable
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrille Bollu committed May 20, 2016
1 parent b75969e commit 5b162c0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
2 changes: 2 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
18 changes: 13 additions & 5 deletions include/TabWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class TabWidget : public QWidget
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 );
Expand All @@ -67,6 +69,10 @@ class TabWidget : public QWidget
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 );
Expand Down Expand Up @@ -96,11 +102,13 @@ class TabWidget : public QWidget
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
46 changes: 38 additions & 8 deletions src/gui/widgets/TabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QBitmap>
#include <QToolTip>
#include <QWheelEvent>

Expand All @@ -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
Expand Down Expand Up @@ -242,7 +245,6 @@ void TabWidget::paintEvent( QPaintEvent * pe )
}

// Draw all tabs
p.setPen( tabText() );
for( widgetStack::iterator it = first ; it != last ; ++it )
{

Expand All @@ -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
Expand All @@ -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 );
}

Expand Down Expand Up @@ -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;
}

0 comments on commit 5b162c0

Please sign in to comment.