Skip to content

Commit 5b162c0

Browse files
author
Cyrille Bollu
committed
TabWidget: Made the artworks' color themeable
1 parent b75969e commit 5b162c0

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

data/themes/default/style.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ TabWidget {
133133
qproperty-tabSelected: rgb(160, 160, 160);
134134
qproperty-tabBackground: rgb(60, 67, 75);
135135
qproperty-tabBorder: rgb(60, 67, 75);
136+
qproperty-tabArtworkActive: rgb(255, 255, 255);
137+
qproperty-tabArtworkInactive: rgb(160, 160, 160);
136138
}
137139

138140
/* main toolbar oscilloscope - can have transparent bg now */

include/TabWidget.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class TabWidget : public QWidget
5656
Q_PROPERTY( QColor tabSelected READ tabSelected WRITE setTabSelected)
5757
Q_PROPERTY( QColor tabBackground READ tabBackground WRITE setTabBackground)
5858
Q_PROPERTY( QColor tabBorder READ tabBorder WRITE setTabBorder)
59+
Q_PROPERTY( QColor tabArtworkActive READ tabArtworkActive WRITE setTabArtworkActive)
60+
Q_PROPERTY( QColor tabArtworkInactive READ tabArtworkInactive WRITE setTabArtworkInactive)
5961

6062
QColor tabText() const;
6163
void setTabText( const QColor & c );
@@ -67,6 +69,10 @@ class TabWidget : public QWidget
6769
void setTabBackground( const QColor & c );
6870
QColor tabBorder() const;
6971
void setTabBorder( const QColor & c );
72+
QColor tabArtworkActive() const;
73+
void setTabArtworkActive( const QColor & c );
74+
QColor tabArtworkInactive() const;
75+
void setTabArtworkInactive( const QColor & c );
7076

7177
protected:
7278
virtual bool event( QEvent * event );
@@ -96,11 +102,13 @@ class TabWidget : public QWidget
96102
quint8 m_tabheight; // The height of the tabs
97103
bool m_usePixmap; // true if the tabs are to be displayed with icons. False for text tabs.
98104

99-
QColor m_tabText; // The color of the tabs' text.
100-
QColor m_tabTitleText; // The color of the TabWidget's title text.
101-
QColor m_tabSelected; // The highlighting color for the selected tab.
102-
QColor m_tabBackground; // The TabWidget's background color.
103-
QColor m_tabBorder; // The TabWidget's borders color.
105+
QColor m_tabText; // The color of the tabs' text.
106+
QColor m_tabTitleText; // The color of the TabWidget's title text.
107+
QColor m_tabSelected; // The highlighting color for the selected tab.
108+
QColor m_tabBackground; // The TabWidget's background color.
109+
QColor m_tabBorder; // The TabWidget's borders color.
110+
QColor m_tabArtworkActive; // The color for active artwork tabs.
111+
QColor m_tabArtworkInactive; // The color for inactive artwork tabs.
104112
} ;
105113

106114
#endif

src/gui/widgets/TabWidget.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QMouseEvent>
2929
#include <QPainter>
3030
#include <QPixmap>
31+
#include <QBitmap>
3132
#include <QToolTip>
3233
#include <QWheelEvent>
3334

@@ -43,7 +44,9 @@ TabWidget::TabWidget( const QString & caption, QWidget * parent, bool usePixmap
4344
m_tabTitleText( 0, 0, 0 ),
4445
m_tabSelected( 0, 0, 0 ),
4546
m_tabBackground( 0, 0, 0 ),
46-
m_tabBorder( 0, 0, 0 )
47+
m_tabBorder( 0, 0, 0 ),
48+
m_tabArtworkActive( 0, 0, 0 ),
49+
m_tabArtworkInactive( 0, 0, 0 )
4750
{
4851

4952
// Create taller tabbar when it's to display artwork tabs
@@ -242,7 +245,6 @@ void TabWidget::paintEvent( QPaintEvent * pe )
242245
}
243246

244247
// Draw all tabs
245-
p.setPen( tabText() );
246248
for( widgetStack::iterator it = first ; it != last ; ++it )
247249
{
248250

@@ -252,17 +254,21 @@ void TabWidget::paintEvent( QPaintEvent * pe )
252254
// Fixes tab's width, because original size is only correct for text tabs
253255
( *it ).nwidth = tab_width;
254256

255-
// Get artwork
256-
QPixmap artwork( embed::getIconPixmap( ( *it ).inactivePixmap ) );
257+
// Create a mask out of the tab's artwork (for changing it's color later on)
258+
QBitmap mask = QPixmap( embed::getIconPixmap( ( *it ).activePixmap ) ).createMaskFromColor( Qt::black, Qt::MaskOutColor );
257259

258-
// Highlight active tab
260+
// Select artwork's color and highlight active tab
259261
if( it.key() == m_activeTab )
260262
{
261263
p.fillRect( tab_x_offset, 0, ( *it ).nwidth, m_tabbarHeight - 1, tabSelected() );
264+
p.setPen( tabArtworkActive() );
265+
} else
266+
{
267+
p.setPen( tabArtworkInactive() );
262268
}
263-
264-
// Draw artwork
265-
p.drawPixmap(tab_x_offset + ( ( *it ).nwidth - artwork.width() ) / 2, 1, artwork );
269+
270+
// Draw colorized artwork
271+
p.drawPixmap(tab_x_offset + ( ( *it ).nwidth - mask.width() ) / 2, 1, mask );
266272
} else
267273
{
268274
// Highlight tab when active
@@ -272,6 +278,7 @@ void TabWidget::paintEvent( QPaintEvent * pe )
272278
}
273279

274280
// Draw text
281+
p.setPen( tabText() );
275282
p.drawText( tab_x_offset + 3, m_tabheight + 1, ( *it ).name );
276283
}
277284

@@ -363,3 +370,26 @@ void TabWidget::setTabBorder( const QColor & c )
363370
m_tabBorder = c;
364371
}
365372

373+
// Return the color to be used for drawing active artwork tabs
374+
QColor TabWidget::tabArtworkActive() const
375+
{
376+
return m_tabArtworkActive;
377+
}
378+
379+
// Set the color to be used for drawing active artwork tabs
380+
void TabWidget::setTabArtworkActive( const QColor & c )
381+
{
382+
m_tabArtworkActive = c;
383+
}
384+
385+
// Return the color to be used for drawing inactive artwork tabs
386+
QColor TabWidget::tabArtworkInactive() const
387+
{
388+
return m_tabArtworkInactive;
389+
}
390+
391+
// Set the color to be used for drawing inactive artwork tabs
392+
void TabWidget::setTabArtworkInactive( const QColor & c )
393+
{
394+
m_tabArtworkInactive = c;
395+
}

0 commit comments

Comments
 (0)