From 2fb62271d777f7c5862576661252ecc3511c68f3 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Mon, 8 Sep 2014 12:55:27 +0200 Subject: [PATCH] Added the possibility to draw left-aligned toolbuttons Apply to Gwenview's side bar toolbuttons --- kstyle/breezepropertynames.cpp | 1 + kstyle/breezepropertynames.h | 1 + kstyle/breezestyle.cpp | 23 +++++++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/kstyle/breezepropertynames.cpp b/kstyle/breezepropertynames.cpp index 0d9422cf..81e6990a 100644 --- a/kstyle/breezepropertynames.cpp +++ b/kstyle/breezepropertynames.cpp @@ -25,5 +25,6 @@ namespace Breeze const char* const PropertyNames::noAnimations = "_kde_no_animations"; const char* const PropertyNames::noWindowGrab = "_kde_no_window_grab"; + const char* const PropertyNames::toolButtonAlignment = "_kde_toolButton_alignment"; } diff --git a/kstyle/breezepropertynames.h b/kstyle/breezepropertynames.h index b453b7c8..c70c0e58 100644 --- a/kstyle/breezepropertynames.h +++ b/kstyle/breezepropertynames.h @@ -29,6 +29,7 @@ namespace Breeze static const char* const noAnimations; static const char* const noWindowGrab; + static const char* const toolButtonAlignment; }; diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index f73e0648..f1f65290 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -48,6 +48,7 @@ #include "breezehelper.h" #include "breezemdiwindowshadow.h" #include "breezemnemonics.h" +#include "breezepropertynames.h" #include "breezeshadowhelper.h" #include "breezesplitterproxy.h" #include "breezestyleconfigdata.h" @@ -308,6 +309,11 @@ namespace Breeze widget->setForegroundRole( QPalette::WindowText ); } + if( widget->parentWidget() && + widget->parentWidget()->parentWidget() && + widget->parentWidget()->parentWidget()->inherits( "Gwenview::SideBarGroup" ) ) + { widget->setProperty( PropertyNames::toolButtonAlignment, Qt::AlignLeft ); } + } else if( qobject_cast( widget ) ) { // add event filter on dock widgets @@ -352,7 +358,7 @@ namespace Breeze } // alter palette for non document mode tab widgets - if( QTabWidget *tabWidget = qobject_cast( widget ) ) + else if( QTabWidget *tabWidget = qobject_cast( widget ) ) { if( !tabWidget->documentMode() ) { @@ -362,7 +368,7 @@ namespace Breeze } // alter palette for dock widgets - if( qobject_cast( widget ) && StyleConfigData::dockWidgetDrawFrame() ) + else if( qobject_cast( widget ) && StyleConfigData::dockWidgetDrawFrame() ) { const QPalette palette( _helper->framePalette( QApplication::palette() ) ); widget->setPalette( palette ); @@ -3773,8 +3779,17 @@ namespace Breeze } else { - const int contentsWidth( iconSize.width() + textSize.width() + Metrics::ToolButton_ItemSpacing ); - iconRect = QRect( QPoint( rect.left() + (rect.width() - contentsWidth )/2, rect.top() + (rect.height() - iconSize.height())/2 ), iconSize ); + const QVariant alignmentProperty( widget ? widget->property( PropertyNames::toolButtonAlignment ) : QVariant() ); + const bool leftAlign = alignmentProperty.isValid() && alignmentProperty.toInt() == Qt::AlignLeft; + + if( leftAlign ) iconRect = QRect( QPoint( rect.left(), rect.top() + (rect.height() - iconSize.height())/2 ), iconSize ); + else { + + const int contentsWidth( iconSize.width() + textSize.width() + Metrics::ToolButton_ItemSpacing ); + iconRect = QRect( QPoint( rect.left() + (rect.width() - contentsWidth )/2, rect.top() + (rect.height() - iconSize.height())/2 ), iconSize ); + + } + textRect = QRect( QPoint( iconRect.right() + Metrics::ToolButton_ItemSpacing + 1, rect.top() + (rect.height() - textSize.height())/2 ), textSize ); // handle right to left layouts