diff --git a/kdecoration/breezebutton.cpp b/kdecoration/breezebutton.cpp index 9c1dbad1..60f38d80 100644 --- a/kdecoration/breezebutton.cpp +++ b/kdecoration/breezebutton.cpp @@ -41,16 +41,6 @@ namespace Breeze m_animation->setPropertyName( "opacity" ); m_animation->setEasingCurve( QEasingCurve::InOutQuad ); - // setup geometry - const int height = decoration->buttonHeight(); - setGeometry(QRect(0, 0, height, height)); - connect(decoration, &Decoration::bordersChanged, this, [this, decoration] - { - const int height = decoration->buttonHeight(); - if (height == geometry().height()) return; - setGeometry(QRectF(geometry().topLeft(), QSizeF(height, height))); - }); - // connect hover state changed connect( this, &KDecoration2::DecorationButton::hoveredChanged, this, &Button::updateAnimationState ); @@ -107,6 +97,7 @@ namespace Breeze painter->save(); painter->setRenderHints( QPainter::Antialiasing ); + painter->translate( 0, m_verticalOffset ); /* scale painter so that its window matches QRect( -1, -1, 20, 20 ) @@ -114,7 +105,7 @@ namespace Breeze all further rendering is preformed inside QRect( 0, 0, 18, 18 ) */ painter->translate( geometry().topLeft() ); - painter->scale( geometry().width()/20, geometry().height()/20 ); + painter->scale( geometry().width()/20, geometry().width()/20 ); painter->translate( 1, 1 ); // render background @@ -394,6 +385,6 @@ namespace Breeze m_animation->setDirection( hovered ? QPropertyAnimation::Forward : QPropertyAnimation::Backward ); if( m_animation->state() != QPropertyAnimation::Running ) m_animation->start(); - } + } } // namespace diff --git a/kdecoration/breezebutton.h b/kdecoration/breezebutton.h index bd608c2d..95d0c84b 100644 --- a/kdecoration/breezebutton.h +++ b/kdecoration/breezebutton.h @@ -55,6 +55,10 @@ namespace Breeze //* standalone buttons bool isStandAlone() const { return m_standalone; } + //* vertical offset, for rendering + void setVerticalOffset( int value ) + { m_verticalOffset = value; } + //*@name active state change animation //@{ void setOpacity( qreal value ) @@ -70,6 +74,8 @@ namespace Breeze //@} private Q_SLOTS: + + //* animation state void updateAnimationState(bool); private: @@ -91,6 +97,9 @@ namespace Breeze //* active state change animation QPropertyAnimation *m_animation; + //* vertical offset (for rendering) + int m_verticalOffset = 0; + //* active state change opacity qreal m_opacity = 0; }; diff --git a/kdecoration/breezedecoration.cpp b/kdecoration/breezedecoration.cpp index 6da9b893..549e1115 100644 --- a/kdecoration/breezedecoration.cpp +++ b/kdecoration/breezedecoration.cpp @@ -173,10 +173,10 @@ namespace Breeze connect(client().data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar); connect(client().data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setOpaque); - connect(client().data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonPositions); - connect(client().data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonPositions); + connect(client().data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry); + connect(client().data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry); connect(client().data(), &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::recalculateBorders); - connect(client().data(), &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonPositions); + connect(client().data(), &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonsGeometry); createButtons(); createShadow(); @@ -284,10 +284,10 @@ namespace Breeze // padding below // extra pixel is used for the active window outline const int baseSize = settings()->smallSpacing(); - top += baseSize*Metrics::TitleBar_TopMargin + 1; + top += baseSize*Metrics::TitleBar_BottomMargin + 1; // padding above - if (!isMaximized()) top += baseSize*TitleBar_BottomMargin; + top += baseSize*TitleBar_TopMargin; int bottom = isMaximizedVertically() || c->isShaded() || edges.testFlag(Qt::BottomEdge) ? 0 : borderSize(true); setBorders(QMargins(left, top, right, bottom)); @@ -315,14 +315,26 @@ namespace Breeze { m_leftButtons = new KDecoration2::DecorationButtonGroup(KDecoration2::DecorationButtonGroup::Position::Left, this, &Button::create); m_rightButtons = new KDecoration2::DecorationButtonGroup(KDecoration2::DecorationButtonGroup::Position::Right, this, &Button::create); - updateButtonPositions(); + updateButtonsGeometry(); } //________________________________________________________________ - void Decoration::updateButtonPositions() + void Decoration::updateButtonsGeometry() { auto s = settings(); - const int vPadding = (isMaximized() ? 0 : s->smallSpacing()*Metrics::TitleBar_TopMargin) + (captionHeight()-buttonHeight())/2; + + // adjust button position + const int bHeight = captionHeight() + (isMaximized() ? s->smallSpacing()*Metrics::TitleBar_TopMargin:0); + const int bWidth = buttonHeight(); + const int verticalOffset = (isMaximized() ? s->smallSpacing()*Metrics::TitleBar_TopMargin:0) + (captionHeight()-buttonHeight())/2; + foreach( const QPointer& button, m_leftButtons->buttons() + m_rightButtons->buttons() ) + { + button.data()->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth, bHeight ) ) ); + static_cast( button.data() )->setVerticalOffset( verticalOffset ); + } + + // adjust buttons position + const int vPadding = isMaximized() ? 0 : s->smallSpacing()*Metrics::TitleBar_TopMargin; const int hPadding = isMaximized() ? 0 : s->smallSpacing()*Metrics::TitleBar_SideMargin; m_rightButtons->setSpacing(s->smallSpacing()*Metrics::TitleBar_ButtonSpacing); @@ -430,19 +442,14 @@ namespace Breeze //________________________________________________________________ int Decoration::captionHeight() const - { - - return isMaximized() ? - borderTop() - settings()->smallSpacing()*Metrics::TitleBar_BottomMargin - 1: - borderTop() - settings()->smallSpacing()*(Metrics::TitleBar_BottomMargin + Metrics::TitleBar_TopMargin ) - 1; - } + { return borderTop() - settings()->smallSpacing()*(Metrics::TitleBar_BottomMargin + Metrics::TitleBar_TopMargin ) - 1; } //________________________________________________________________ QRect Decoration::captionRect() const { const int leftOffset = m_leftButtons->geometry().x() + m_leftButtons->geometry().width() + Metrics::TitleBar_SideMargin*settings()->smallSpacing(); const int rightOffset = size().width() - m_rightButtons->geometry().x() + Metrics::TitleBar_SideMargin*settings()->smallSpacing(); - const int yOffset = isMaximized() ? 0 : settings()->smallSpacing()*Metrics::TitleBar_TopMargin; + const int yOffset = settings()->smallSpacing()*Metrics::TitleBar_TopMargin; QRect boundingRect( settings()->fontMetrics().boundingRect( client().data()->caption()).toRect() ); boundingRect.setTop( yOffset ); diff --git a/kdecoration/breezedecoration.h b/kdecoration/breezedecoration.h index 692d7adf..9eb6c659 100644 --- a/kdecoration/breezedecoration.h +++ b/kdecoration/breezedecoration.h @@ -84,7 +84,6 @@ namespace Breeze //@} - //*@name colors //@{ QColor titleBarColor( void ) const; @@ -92,13 +91,20 @@ namespace Breeze QColor fontColor( void ) const; //@} + //*@name maximization modes + //@{ + inline bool isMaximized( void ) const; + inline bool isMaximizedHorizontally( void ) const; + inline bool isMaximizedVertically( void ) const; + //@} + public Q_SLOTS: void init() override; private Q_SLOTS: void reconfigure(); void recalculateBorders(); - void updateButtonPositions(); + void updateButtonsGeometry(); void updateTitleBar(); void updateAnimationState(); @@ -116,13 +122,6 @@ namespace Breeze inline bool hasNoSideBorders( void ) const; //@} - //*@name maximization modes - //@{ - inline bool isMaximized( void ) const; - inline bool isMaximizedHorizontally( void ) const; - inline bool isMaximizedVertically( void ) const; - //@} - //*@name size grip //@{ void createSizeGrip( void );