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