From f541a863017f47533960d7562d0b85b66f89b161 Mon Sep 17 00:00:00 2001 From: laserpants Date: Sat, 28 May 2016 16:58:29 +0300 Subject: [PATCH] make halo animation use float precision --- components/flatbutton.cpp | 5 +++-- components/raisedbutton.cpp | 30 ++++++++++++++++++------------ examples/raisedbuttonexamples.cpp | 2 ++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/components/flatbutton.cpp b/components/flatbutton.cpp index 1fad80d..c686f24 100644 --- a/components/flatbutton.cpp +++ b/components/flatbutton.cpp @@ -123,7 +123,7 @@ void FlatButton::paintEvent(QPaintEvent *event) const qreal bgOpacity = d->delegate->backgroundOpacity(); const qreal haloOpacity = d->delegate->focusHaloOpacity(); - const int hs = (width()/2)*d->delegate->focusHaloSize(); + const qreal hs = static_cast(width())*d->delegate->focusHaloSize()/2; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); @@ -145,7 +145,8 @@ void FlatButton::paintEvent(QPaintEvent *event) painter.setOpacity(haloOpacity); painter.setBrush(brush); painter.setPen(Qt::NoPen); - painter.drawEllipse(rect().center(), hs, hs); + QPointF center = rect().center(); + painter.drawEllipse(center, hs, hs); } QStylePainter style(this); diff --git a/components/raisedbutton.cpp b/components/raisedbutton.cpp index 45c1da1..ae55dfb 100644 --- a/components/raisedbutton.cpp +++ b/components/raisedbutton.cpp @@ -134,20 +134,26 @@ void RaisedButton::paintEvent(QPaintEvent *event) painter.save(); QBrush brush; - brush.setStyle(Qt::SolidPattern); - brush.setColor(palette().color(QPalette::Active, QPalette::Background)); - painter.setBrush(brush); - painter.setPen(Qt::NoPen); - painter.drawRoundedRect(rect(), 3, 3); - const int hs = (width()/2)*d->delegate->focusHaloSize(); - const qreal haloOpacity = d->delegate->focusHaloOpacity(); + if (isEnabled()) { + brush.setStyle(Qt::SolidPattern); + brush.setColor(palette().color(QPalette::Active, QPalette::Background)); + painter.setBrush(brush); + painter.setPen(Qt::NoPen); + painter.drawRoundedRect(rect(), 3, 3); + } - brush.setColor(palette().color(QPalette::Active, QPalette::ButtonText)); - painter.setBrush(brush); - painter.setOpacity(haloOpacity); - painter.setPen(Qt::NoPen); - painter.drawEllipse(rect().center(), hs, hs); + if (isEnabled()) { + const qreal hs = static_cast(width())*d->delegate->focusHaloSize()/2; + const qreal haloOpacity = d->delegate->focusHaloOpacity(); + + brush.setColor(palette().color(QPalette::Active, QPalette::ButtonText)); + painter.setBrush(brush); + painter.setOpacity(haloOpacity); + painter.setPen(Qt::NoPen); + QPointF center = rect().center(); + painter.drawEllipse(center, hs, hs); + } painter.restore(); diff --git a/examples/raisedbuttonexamples.cpp b/examples/raisedbuttonexamples.cpp index e8592ab..6963d8b 100644 --- a/examples/raisedbuttonexamples.cpp +++ b/examples/raisedbuttonexamples.cpp @@ -13,6 +13,8 @@ RaisedButtonExamples::RaisedButtonExamples(QWidget *parent) raisedButton->setRole(Material::Primary); raisedButton->setText("Press me!"); + raisedButton->setDisabled(true); + //raisedButton->setFixedSize(400, 50); layout->addWidget(raisedButton);