From 943d0c3499b1d1fdbf07daff55f27c36874b85bc Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Fri, 1 Aug 2014 13:48:36 +0200 Subject: [PATCH] implemented toolbuttons in tabbars --- kstyle/breezestyle.cpp | 72 +++++++++++++++++++++++++++++++----------- kstyle/breezestyle.h | 2 +- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index cd7ef687..e4204fc7 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -456,6 +456,7 @@ namespace Breeze // buttons case PE_PanelButtonCommand: fcn = &Style::drawPanelButtonCommandPrimitive; break; + case PE_PanelButtonTool: fcn = &Style::drawPanelButtonToolPrimitive; break; // checkboxes and radio buttons case PE_IndicatorCheckBox: fcn = &Style::drawIndicatorCheckBoxPrimitive; break; @@ -1647,22 +1648,8 @@ namespace Breeze // color QColor color; - const QToolButton* toolButton( qobject_cast( widget ) ); - if( toolButton && toolButton->arrowType() != Qt::NoArrow ) - { - - // set color properly - color = (toolButton->autoRaise() ? palette.color( QPalette::WindowText ):palette.color( QPalette::ButtonText ) ); - - } else if( mouseOver ) { - - color = _helper->viewHoverBrush().brush( palette ).color(); - - } else { - - color = palette.color( QPalette::WindowText ); - - } + if( mouseOver ) color = _helper->viewHoverBrush().brush( palette ).color(); + else color = palette.color( QPalette::WindowText ); // arrow const QPolygonF arrow( genericArrow( orientation, ArrowNormal ) ); @@ -1737,6 +1724,56 @@ namespace Breeze } + //______________________________________________________________ + bool Style::drawPanelButtonToolPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const + { + + /* + For toolbutton in TabBars, corresponding to expanding arrows, no frame is drawn + However one needs to draw the window background, because the button rect might + overlap with some tab below. ( this is a Qt bug ) + */ + const QTabBar* tabBar( widget ? qobject_cast( widget->parent() ):nullptr ); + if( tabBar ) + { + QRect rect( option->rect ); + + // adjust rect based on tabbar shape + switch( tabBar->shape() ) + { + case QTabBar::RoundedNorth: + case QTabBar::TriangularNorth: + rect.adjust( 0, 0, 0, -Metrics::TabBar_BaseOverlap ); + break; + + case QTabBar::RoundedSouth: + case QTabBar::TriangularSouth: + rect.adjust( 0, Metrics::TabBar_BaseOverlap, 0, 0 ); + break; + + case QTabBar::RoundedWest: + case QTabBar::TriangularWest: + rect.adjust( 0, 0, -Metrics::TabBar_BaseOverlap, 0 ); + break; + + case QTabBar::RoundedEast: + case QTabBar::TriangularEast: + rect.adjust( Metrics::TabBar_BaseOverlap, 0, 0, 0 ); + break; + + default: break; + + } + + painter->setPen( Qt::NoPen ); + painter->setBrush( tabBar->palette().color( QPalette::Window ) ); + painter->drawRect( rect ); + return true; + } + + return true; + } + //___________________________________________________________________________________ bool Style::drawIndicatorCheckBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { @@ -2700,8 +2737,7 @@ namespace Breeze } // outline - QColor outline; - if( selected ) outline = _helper->alphaColor( palette.color( QPalette::WindowText ), 0.25 ); + const QColor outline( selected ? _helper->alphaColor( palette.color( QPalette::WindowText ), 0.25 ); // render _helper->renderTabBarTab( painter, rect, color, outline, corners ); diff --git a/kstyle/breezestyle.h b/kstyle/breezestyle.h index bcc35d5e..eccd90bd 100644 --- a/kstyle/breezestyle.h +++ b/kstyle/breezestyle.h @@ -295,8 +295,8 @@ namespace Breeze // /*! it uses the same painting as QSplitter, but due to Qt, the horizontal/vertical convention is inverted */ // bool drawIndicatorDockWidgetResizeHandlePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget) const; bool drawPanelButtonCommandPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawPanelButtonToolPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; // bool drawPanelMenuPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; -// bool drawPanelButtonToolPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; // bool drawPanelScrollAreaCornerPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; // bool drawPanelTipLabelPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; // bool drawPanelItemViewItemPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;