KTabBar: add way to revert tab color to default

This commit adds a resetTabColor(...) method to TQTabBar and TQTabWidget which allows the color of the appropriate tab to be reset to the default as specified by the desktop color scheme.

It also changes how invalid color values are handled; before, an invalid value would be used as a valid color, resulting in 0,0,0 (black). Seeing that an invalid color is returned by KColorDialog when the default color checkbox is checked, it makes more sense to ignore invalid colors, using the appropriate color from the color scheme instead.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
(cherry picked from commit c28a87c7d2)
pull/271/head
Mavridis Philippe 1 year ago
parent 10b5c67d72
commit 050ff82bcc
No known key found for this signature in database
GPG Key ID: 93F66F98F906147D

@ -298,9 +298,19 @@ void KTabBar::setTabColor( int id, const TQColor& color )
} }
} }
const TQColor &KTabBar::tabColor( int id ) const void KTabBar::resetTabColor( int id )
{ {
TQTab *t = tab(id);
if (t) {
if (mTabColors.contains(id)) if (mTabColors.contains(id))
mTabColors.remove(id);
repaint(t->rect(), false);
}
}
const TQColor &KTabBar::tabColor( int id ) const
{
if ( mTabColors.contains(id) && mTabColors[id].isValid() )
return mTabColors[id]; return mTabColors[id];
return colorGroup().foreground(); return colorGroup().foreground();
@ -359,7 +369,7 @@ void KTabBar::paintLabel( TQPainter *p, const TQRect& br,
flags |= TQStyle::Style_HasFocus; flags |= TQStyle::Style_HasFocus;
TQColorGroup cg( colorGroup() ); TQColorGroup cg( colorGroup() );
if ( mTabColors.contains( t->identifier() ) ) if ( mTabColors.contains(t->identifier()) && mTabColors[t->identifier()].isValid() )
cg.setColor( TQColorGroup::Foreground, mTabColors[t->identifier()] ); cg.setColor( TQColorGroup::Foreground, mTabColors[t->identifier()] );
style().drawControl( TQStyle::CE_TabBarLabel, p, this, r, style().drawControl( TQStyle::CE_TabBarLabel, p, this, r,

@ -44,6 +44,7 @@ public:
const TQColor &tabColor( int ) const; const TQColor &tabColor( int ) const;
void setTabColor( int, const TQColor& ); void setTabColor( int, const TQColor& );
void resetTabColor( int );
virtual int insertTab( TQTab *, int index = -1 ); virtual int insertTab( TQTab *, int index = -1 );
virtual void removeTab( TQTab * ); virtual void removeTab( TQTab * );

@ -135,6 +135,14 @@ void KTabWidget::setTabColor( TQWidget *w, const TQColor& color )
} }
} }
void KTabWidget::resetTabColor( TQWidget *w )
{
TQTab *t = tabBar()->tabAt( indexOf( w ) );
if (t) {
static_cast<KTabBar*>(tabBar())->resetTabColor( t->identifier() );
}
}
TQColor KTabWidget::tabColor( TQWidget *w ) const TQColor KTabWidget::tabColor( TQWidget *w ) const
{ {
TQTab *t = tabBar()->tabAt( indexOf( w ) ); TQTab *t = tabBar()->tabAt( indexOf( w ) );

@ -55,6 +55,11 @@ public:
*/ */
void setTabColor( TQWidget *, const TQColor& color ); void setTabColor( TQWidget *, const TQColor& color );
/*!
Reset the color of the tab of the given widget.
*/
void resetTabColor( TQWidget * );
/*! /*!
Returns the tab color for the given widget. Returns the tab color for the given widget.
*/ */

Loading…
Cancel
Save