From 8ee681588ee8fd848fd6f456b613d4e98d368e75 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Wed, 15 Jun 2022 10:57:36 +0200 Subject: [PATCH] Revert "QskPushButton: respect the graphics alignment" This reverts commit 3c69498026c0a4e26b585a265a25ecf73857ab5d. --- skins/material/QskMaterialSkin.cpp | 1 - skins/squiek/QskSquiekSkin.cpp | 3 -- src/controls/QskPushButtonSkinlet.cpp | 72 +++++---------------------- 3 files changed, 13 insertions(+), 63 deletions(-) diff --git a/skins/material/QskMaterialSkin.cpp b/skins/material/QskMaterialSkin.cpp index 0b573eed..4fe1fa53 100644 --- a/skins/material/QskMaterialSkin.cpp +++ b/skins/material/QskMaterialSkin.cpp @@ -489,7 +489,6 @@ void Editor::setupPushButton() setColor( Q::Text | Q::Disabled, c1, combination ); - setAnimation( Q::Panel | A::Color, qskDuration ); setAnimation( Q::Panel | A::Metric, qskDuration ); setAnimation( Q::Text | A::Color, qskDuration ); diff --git a/skins/squiek/QskSquiekSkin.cpp b/skins/squiek/QskSquiekSkin.cpp index 974d0e6c..4a0d8cae 100644 --- a/skins/squiek/QskSquiekSkin.cpp +++ b/skins/squiek/QskSquiekSkin.cpp @@ -594,9 +594,6 @@ void Editor::setupPushButton() setColor( Q::Text, m_pal.themeForeground ); setColor( Q::Text | Q::Disabled, m_pal.darker200 ); - - // Graphic - setPadding( Q::Graphic, 2 ); } void Editor::setupDialogButton() diff --git a/src/controls/QskPushButtonSkinlet.cpp b/src/controls/QskPushButtonSkinlet.cpp index 407cd51b..6063d9eb 100644 --- a/src/controls/QskPushButtonSkinlet.cpp +++ b/src/controls/QskPushButtonSkinlet.cpp @@ -77,24 +77,11 @@ QRectF QskPushButtonSkinlet::textRect( if ( button->hasGraphic() ) { - const auto alignment = button->alignmentHint( QskPushButton::Graphic, Qt::AlignTop ); + // in case of having text + graphic we put the text at the bottom - switch( alignment ) - { - case Qt::AlignLeft: - { - const auto graphicsRect = subControlRect( button, contentsRect, QskPushButton::Graphic ); - const auto spacing = button->metric( QskPushButton::Panel | QskAspect::Spacing ); - r.setX( r.x() + graphicsRect.width() + spacing ); - break; - } - default: // AlignTop - { - qreal h = QFontMetricsF( button->effectiveFont( QskPushButton::Text ) ).height(); - if ( h < r.height() ) - r.setTop( r.bottom() - h ); - } - } + qreal h = button->effectiveFontHeight( QskPushButton::Text ); + if ( h < r.height() ) + r.setTop( r.bottom() - h ); } return r; @@ -107,9 +94,7 @@ QRectF QskPushButtonSkinlet::graphicRect( auto r = button->subControlContentsRect( contentsRect, QskPushButton::Panel ); - const auto alignment = button->alignmentHint( QskPushButton::Graphic, Qt::AlignTop ); - - if ( !button->text().isEmpty() && alignment != Qt::AlignLeft ) + if ( !button->text().isEmpty() ) { const auto textRect = subControlRect( button, contentsRect, QskPushButton::Text ); qreal h = textRect.height() + button->spacingHint( QskPushButton::Panel ); @@ -121,7 +106,6 @@ QRectF QskPushButtonSkinlet::graphicRect( } const auto maxSize = button->graphicSourceSize(); - if ( maxSize.width() >= 0 || maxSize.height() >= 0 ) { // limiting the size by graphicSize @@ -150,31 +134,15 @@ QRectF QskPushButtonSkinlet::graphicRect( const double scaleFactor = qMin( r.width() / sz.width(), r.height() / sz.height() ); + // early aligning to avoid pointless operations, that finally will + // have no effect, when drawing to an integer based paint device + const int w = qFloor( scaleFactor * sz.width() ); const int h = qFloor( scaleFactor * sz.height() ); - int x, y; - - switch( alignment ) - { - case Qt::AlignLeft: - { - x = r.left(); - y = r.top(); - break; - } - default: // AlignTop - { - // early aligning to avoid pointless operations, that finally will - // have no effect, when drawing to an integer based paint device - - x = qFloor( r.center().x() - 0.5 * w ); - y = qFloor( r.center().y() - 0.5 * h ); - } - } + const int x = qFloor( r.center().x() - 0.5 * w ); + const int y = qFloor( r.center().y() - 0.5 * h ); r = QRectF( x, y, w, h ); - const auto padding = button->paddingHint( QskPushButton::Graphic ); - r = r.marginsRemoved( padding ); } return r; @@ -245,24 +213,10 @@ QSizeF QskPushButtonSkinlet::sizeHint( const QskSkinnable* skinnable, } } - const auto alignment = button->alignmentHint( QskPushButton::Graphic, Qt::AlignTop ); + const qreal padding = 2.0; // paddingHint( Graphic ) ??? - const QMarginsF padding = button->paddingHint( QskPushButton::Graphic ); - - switch( alignment ) - { - case Qt::AlignLeft: - { - size.rwidth() += padding.left() + w + padding.right(); - size.rheight() = qMax( size.height(), h ); - break; - } - default: // AlignTop - { - size.rheight() += padding.top() + h + padding.bottom(); - size.rwidth() = qMax( size.width(), w ); - } - } + size.rheight() += 2 * padding + h; + size.rwidth() = qMax( size.width(), w ); } size = size.expandedTo( button->strutSizeHint( QskPushButton::Panel ) );