diff --git a/src/ui/FlatButton.cpp b/src/ui/FlatButton.cpp
index c036401b..4d19c8bb 100644
--- a/src/ui/FlatButton.cpp
+++ b/src/ui/FlatButton.cpp
@@ -30,60 +30,60 @@
static QString
removeKDEAccelerators(QString text)
{
- return text.remove(QChar('&'));
+ return text.remove(QChar('&'));
}
void
FlatButton::init()
{
- ripple_overlay_ = new RippleOverlay(this);
- state_machine_ = new FlatButtonStateMachine(this);
- role_ = ui::Role::Default;
- ripple_style_ = ui::RippleStyle::PositionedRipple;
- icon_placement_ = ui::ButtonIconPlacement::LeftIcon;
- overlay_style_ = ui::OverlayStyle::GrayOverlay;
- bg_mode_ = Qt::TransparentMode;
- fixed_ripple_radius_ = 64;
- corner_radius_ = 3;
- base_opacity_ = 0.13;
- font_size_ = 10; // 10.5;
- use_fixed_ripple_radius_ = false;
-
- setStyle(&ThemeManager::instance());
- setAttribute(Qt::WA_Hover);
- setMouseTracking(true);
- setCursor(QCursor(Qt::PointingHandCursor));
+ ripple_overlay_ = new RippleOverlay(this);
+ state_machine_ = new FlatButtonStateMachine(this);
+ role_ = ui::Role::Default;
+ ripple_style_ = ui::RippleStyle::PositionedRipple;
+ icon_placement_ = ui::ButtonIconPlacement::LeftIcon;
+ overlay_style_ = ui::OverlayStyle::GrayOverlay;
+ bg_mode_ = Qt::TransparentMode;
+ fixed_ripple_radius_ = 64;
+ corner_radius_ = 3;
+ base_opacity_ = 0.13;
+ font_size_ = 10; // 10.5;
+ use_fixed_ripple_radius_ = false;
- QPainterPath path;
- path.addRoundedRect(rect(), corner_radius_, corner_radius_);
+ setStyle(&ThemeManager::instance());
+ setAttribute(Qt::WA_Hover);
+ setMouseTracking(true);
+ setCursor(QCursor(Qt::PointingHandCursor));
+
+ QPainterPath path;
+ path.addRoundedRect(rect(), corner_radius_, corner_radius_);
- ripple_overlay_->setClipPath(path);
- ripple_overlay_->setClipping(true);
+ ripple_overlay_->setClipPath(path);
+ ripple_overlay_->setClipping(true);
- state_machine_->setupProperties();
- state_machine_->startAnimations();
+ state_machine_->setupProperties();
+ state_machine_->startAnimations();
}
FlatButton::FlatButton(QWidget *parent, ui::ButtonPreset preset)
: QPushButton(parent)
{
- init();
- applyPreset(preset);
+ init();
+ applyPreset(preset);
}
FlatButton::FlatButton(const QString &text, QWidget *parent, ui::ButtonPreset preset)
: QPushButton(text, parent)
{
- init();
- applyPreset(preset);
+ init();
+ applyPreset(preset);
}
FlatButton::FlatButton(const QString &text, ui::Role role, QWidget *parent, ui::ButtonPreset preset)
: QPushButton(text, parent)
{
- init();
- applyPreset(preset);
- setRole(role);
+ init();
+ applyPreset(preset);
+ setRole(role);
}
FlatButton::~FlatButton() {}
@@ -91,406 +91,406 @@ FlatButton::~FlatButton() {}
void
FlatButton::applyPreset(ui::ButtonPreset preset)
{
- switch (preset) {
- case ui::ButtonPreset::FlatPreset:
- setOverlayStyle(ui::OverlayStyle::NoOverlay);
- break;
- case ui::ButtonPreset::CheckablePreset:
- setOverlayStyle(ui::OverlayStyle::NoOverlay);
- setCheckable(true);
- break;
- default:
- break;
- }
+ switch (preset) {
+ case ui::ButtonPreset::FlatPreset:
+ setOverlayStyle(ui::OverlayStyle::NoOverlay);
+ break;
+ case ui::ButtonPreset::CheckablePreset:
+ setOverlayStyle(ui::OverlayStyle::NoOverlay);
+ setCheckable(true);
+ break;
+ default:
+ break;
+ }
}
void
FlatButton::setRole(ui::Role role)
{
- role_ = role;
- state_machine_->setupProperties();
+ role_ = role;
+ state_machine_->setupProperties();
}
ui::Role
FlatButton::role() const
{
- return role_;
+ return role_;
}
void
FlatButton::setForegroundColor(const QColor &color)
{
- foreground_color_ = color;
+ foreground_color_ = color;
}
QColor
FlatButton::foregroundColor() const
{
- if (!foreground_color_.isValid()) {
- if (bg_mode_ == Qt::OpaqueMode) {
- return ThemeManager::instance().themeColor("BrightWhite");
- }
-
- switch (role_) {
- case ui::Role::Primary:
- return ThemeManager::instance().themeColor("Blue");
- case ui::Role::Secondary:
- return ThemeManager::instance().themeColor("Gray");
- case ui::Role::Default:
- default:
- return ThemeManager::instance().themeColor("Black");
- }
+ if (!foreground_color_.isValid()) {
+ if (bg_mode_ == Qt::OpaqueMode) {
+ return ThemeManager::instance().themeColor("BrightWhite");
+ }
+
+ switch (role_) {
+ case ui::Role::Primary:
+ return ThemeManager::instance().themeColor("Blue");
+ case ui::Role::Secondary:
+ return ThemeManager::instance().themeColor("Gray");
+ case ui::Role::Default:
+ default:
+ return ThemeManager::instance().themeColor("Black");
}
+ }
- return foreground_color_;
+ return foreground_color_;
}
void
FlatButton::setBackgroundColor(const QColor &color)
{
- background_color_ = color;
+ background_color_ = color;
}
QColor
FlatButton::backgroundColor() const
{
- if (!background_color_.isValid()) {
- switch (role_) {
- case ui::Role::Primary:
- return ThemeManager::instance().themeColor("Blue");
- case ui::Role::Secondary:
- return ThemeManager::instance().themeColor("Gray");
- case ui::Role::Default:
- default:
- return ThemeManager::instance().themeColor("Black");
- }
+ if (!background_color_.isValid()) {
+ switch (role_) {
+ case ui::Role::Primary:
+ return ThemeManager::instance().themeColor("Blue");
+ case ui::Role::Secondary:
+ return ThemeManager::instance().themeColor("Gray");
+ case ui::Role::Default:
+ default:
+ return ThemeManager::instance().themeColor("Black");
}
+ }
- return background_color_;
+ return background_color_;
}
void
FlatButton::setOverlayColor(const QColor &color)
{
- overlay_color_ = color;
- setOverlayStyle(ui::OverlayStyle::TintedOverlay);
+ overlay_color_ = color;
+ setOverlayStyle(ui::OverlayStyle::TintedOverlay);
}
QColor
FlatButton::overlayColor() const
{
- if (!overlay_color_.isValid()) {
- return foregroundColor();
- }
+ if (!overlay_color_.isValid()) {
+ return foregroundColor();
+ }
- return overlay_color_;
+ return overlay_color_;
}
void
FlatButton::setDisabledForegroundColor(const QColor &color)
{
- disabled_color_ = color;
+ disabled_color_ = color;
}
QColor
FlatButton::disabledForegroundColor() const
{
- if (!disabled_color_.isValid()) {
- return ThemeManager::instance().themeColor("FadedWhite");
- }
+ if (!disabled_color_.isValid()) {
+ return ThemeManager::instance().themeColor("FadedWhite");
+ }
- return disabled_color_;
+ return disabled_color_;
}
void
FlatButton::setDisabledBackgroundColor(const QColor &color)
{
- disabled_background_color_ = color;
+ disabled_background_color_ = color;
}
QColor
FlatButton::disabledBackgroundColor() const
{
- if (!disabled_background_color_.isValid()) {
- return ThemeManager::instance().themeColor("FadedWhite");
- }
+ if (!disabled_background_color_.isValid()) {
+ return ThemeManager::instance().themeColor("FadedWhite");
+ }
- return disabled_background_color_;
+ return disabled_background_color_;
}
void
FlatButton::setFontSize(qreal size)
{
- font_size_ = size;
+ font_size_ = size;
- QFont f(font());
- f.setPointSizeF(size);
- setFont(f);
+ QFont f(font());
+ f.setPointSizeF(size);
+ setFont(f);
- update();
+ update();
}
qreal
FlatButton::fontSize() const
{
- return font_size_;
+ return font_size_;
}
void
FlatButton::setOverlayStyle(ui::OverlayStyle style)
{
- overlay_style_ = style;
- update();
+ overlay_style_ = style;
+ update();
}
ui::OverlayStyle
FlatButton::overlayStyle() const
{
- return overlay_style_;
+ return overlay_style_;
}
void
FlatButton::setRippleStyle(ui::RippleStyle style)
{
- ripple_style_ = style;
+ ripple_style_ = style;
}
ui::RippleStyle
FlatButton::rippleStyle() const
{
- return ripple_style_;
+ return ripple_style_;
}
void
FlatButton::setIconPlacement(ui::ButtonIconPlacement placement)
{
- icon_placement_ = placement;
- update();
+ icon_placement_ = placement;
+ update();
}
ui::ButtonIconPlacement
FlatButton::iconPlacement() const
{
- return icon_placement_;
+ return icon_placement_;
}
void
FlatButton::setCornerRadius(qreal radius)
{
- corner_radius_ = radius;
- updateClipPath();
- update();
+ corner_radius_ = radius;
+ updateClipPath();
+ update();
}
qreal
FlatButton::cornerRadius() const
{
- return corner_radius_;
+ return corner_radius_;
}
void
FlatButton::setBackgroundMode(Qt::BGMode mode)
{
- bg_mode_ = mode;
- state_machine_->setupProperties();
+ bg_mode_ = mode;
+ state_machine_->setupProperties();
}
Qt::BGMode
FlatButton::backgroundMode() const
{
- return bg_mode_;
+ return bg_mode_;
}
void
FlatButton::setBaseOpacity(qreal opacity)
{
- base_opacity_ = opacity;
- state_machine_->setupProperties();
+ base_opacity_ = opacity;
+ state_machine_->setupProperties();
}
qreal
FlatButton::baseOpacity() const
{
- return base_opacity_;
+ return base_opacity_;
}
void
FlatButton::setCheckable(bool value)
{
- state_machine_->updateCheckedStatus();
- state_machine_->setCheckedOverlayProgress(0);
+ state_machine_->updateCheckedStatus();
+ state_machine_->setCheckedOverlayProgress(0);
- QPushButton::setCheckable(value);
+ QPushButton::setCheckable(value);
}
void
FlatButton::setHasFixedRippleRadius(bool value)
{
- use_fixed_ripple_radius_ = value;
+ use_fixed_ripple_radius_ = value;
}
bool
FlatButton::hasFixedRippleRadius() const
{
- return use_fixed_ripple_radius_;
+ return use_fixed_ripple_radius_;
}
void
FlatButton::setFixedRippleRadius(qreal radius)
{
- fixed_ripple_radius_ = radius;
- setHasFixedRippleRadius(true);
+ fixed_ripple_radius_ = radius;
+ setHasFixedRippleRadius(true);
}
QSize
FlatButton::sizeHint() const
{
- ensurePolished();
+ ensurePolished();
- QSize label(fontMetrics().size(Qt::TextSingleLine, removeKDEAccelerators(text())));
+ QSize label(fontMetrics().size(Qt::TextSingleLine, removeKDEAccelerators(text())));
- int w = 20 + label.width();
- int h = label.height();
+ int w = 20 + label.width();
+ int h = label.height();
- if (!icon().isNull()) {
- w += iconSize().width() + FlatButton::IconPadding;
- h = qMax(h, iconSize().height());
- }
+ if (!icon().isNull()) {
+ w += iconSize().width() + FlatButton::IconPadding;
+ h = qMax(h, iconSize().height());
+ }
- return QSize(w, 20 + h);
+ return QSize(w, 20 + h);
}
void
FlatButton::checkStateSet()
{
- state_machine_->updateCheckedStatus();
- QPushButton::checkStateSet();
+ state_machine_->updateCheckedStatus();
+ QPushButton::checkStateSet();
}
void
FlatButton::mousePressEvent(QMouseEvent *event)
{
- if (ui::RippleStyle::NoRipple != ripple_style_) {
- QPoint pos;
- qreal radiusEndValue;
+ if (ui::RippleStyle::NoRipple != ripple_style_) {
+ QPoint pos;
+ qreal radiusEndValue;
- if (ui::RippleStyle::CenteredRipple == ripple_style_) {
- pos = rect().center();
- } else {
- pos = event->pos();
- }
+ if (ui::RippleStyle::CenteredRipple == ripple_style_) {
+ pos = rect().center();
+ } else {
+ pos = event->pos();
+ }
- if (use_fixed_ripple_radius_) {
- radiusEndValue = fixed_ripple_radius_;
- } else {
- radiusEndValue = static_cast<qreal>(width()) / 2;
- }
+ if (use_fixed_ripple_radius_) {
+ radiusEndValue = fixed_ripple_radius_;
+ } else {
+ radiusEndValue = static_cast<qreal>(width()) / 2;
+ }
- Ripple *ripple = new Ripple(pos);
+ Ripple *ripple = new Ripple(pos);
- ripple->setRadiusEndValue(radiusEndValue);
- ripple->setOpacityStartValue(0.35);
- ripple->setColor(foregroundColor());
- ripple->radiusAnimation()->setDuration(250);
- ripple->opacityAnimation()->setDuration(250);
+ ripple->setRadiusEndValue(radiusEndValue);
+ ripple->setOpacityStartValue(0.35);
+ ripple->setColor(foregroundColor());
+ ripple->radiusAnimation()->setDuration(250);
+ ripple->opacityAnimation()->setDuration(250);
- ripple_overlay_->addRipple(ripple);
- }
+ ripple_overlay_->addRipple(ripple);
+ }
- QPushButton::mousePressEvent(event);
+ QPushButton::mousePressEvent(event);
}
void
FlatButton::mouseReleaseEvent(QMouseEvent *event)
{
- QPushButton::mouseReleaseEvent(event);
- state_machine_->updateCheckedStatus();
+ QPushButton::mouseReleaseEvent(event);
+ state_machine_->updateCheckedStatus();
}
void
FlatButton::resizeEvent(QResizeEvent *event)
{
- QPushButton::resizeEvent(event);
- updateClipPath();
+ QPushButton::resizeEvent(event);
+ updateClipPath();
}
void
FlatButton::paintEvent(QPaintEvent *event)
{
- Q_UNUSED(event)
+ Q_UNUSED(event)
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
- const qreal cr = corner_radius_;
+ const qreal cr = corner_radius_;
- if (cr > 0) {
- QPainterPath path;
- path.addRoundedRect(rect(), cr, cr);
+ if (cr > 0) {
+ QPainterPath path;
+ path.addRoundedRect(rect(), cr, cr);
- painter.setClipPath(path);
- painter.setClipping(true);
- }
+ painter.setClipPath(path);
+ painter.setClipping(true);
+ }
- paintBackground(&painter);
+ paintBackground(&painter);
- painter.setOpacity(1);
- painter.setClipping(false);
+ painter.setOpacity(1);
+ painter.setClipping(false);
- paintForeground(&painter);
+ paintForeground(&painter);
}
void
FlatButton::paintBackground(QPainter *painter)
{
- const qreal overlayOpacity = state_machine_->overlayOpacity();
- const qreal checkedProgress = state_machine_->checkedOverlayProgress();
+ const qreal overlayOpacity = state_machine_->overlayOpacity();
+ const qreal checkedProgress = state_machine_->checkedOverlayProgress();
- if (Qt::OpaqueMode == bg_mode_) {
- QBrush brush;
- brush.setStyle(Qt::SolidPattern);
-
- if (isEnabled()) {
- brush.setColor(backgroundColor());
- } else {
- brush.setColor(disabledBackgroundColor());
- }
+ if (Qt::OpaqueMode == bg_mode_) {
+ QBrush brush;
+ brush.setStyle(Qt::SolidPattern);
- painter->setOpacity(1);
- painter->setBrush(brush);
- painter->setPen(Qt::NoPen);
- painter->drawRect(rect());
+ if (isEnabled()) {
+ brush.setColor(backgroundColor());
+ } else {
+ brush.setColor(disabledBackgroundColor());
}
- QBrush brush;
- brush.setStyle(Qt::SolidPattern);
+ painter->setOpacity(1);
+ painter->setBrush(brush);
painter->setPen(Qt::NoPen);
+ painter->drawRect(rect());
+ }
- if (!isEnabled()) {
- return;
- }
+ QBrush brush;
+ brush.setStyle(Qt::SolidPattern);
+ painter->setPen(Qt::NoPen);
- if ((ui::OverlayStyle::NoOverlay != overlay_style_) && (overlayOpacity > 0)) {
- if (ui::OverlayStyle::TintedOverlay == overlay_style_) {
- brush.setColor(overlayColor());
- } else {
- brush.setColor(Qt::gray);
- }
+ if (!isEnabled()) {
+ return;
+ }
- painter->setOpacity(overlayOpacity);
- painter->setBrush(brush);
- painter->drawRect(rect());
+ if ((ui::OverlayStyle::NoOverlay != overlay_style_) && (overlayOpacity > 0)) {
+ if (ui::OverlayStyle::TintedOverlay == overlay_style_) {
+ brush.setColor(overlayColor());
+ } else {
+ brush.setColor(Qt::gray);
}
- if (isCheckable() && checkedProgress > 0) {
- const qreal q = Qt::TransparentMode == bg_mode_ ? 0.45 : 0.7;
- brush.setColor(foregroundColor());
- painter->setOpacity(q * checkedProgress);
- painter->setBrush(brush);
- QRect r(rect());
- r.setHeight(static_cast<qreal>(r.height()) * checkedProgress);
- painter->drawRect(r);
- }
+ painter->setOpacity(overlayOpacity);
+ painter->setBrush(brush);
+ painter->drawRect(rect());
+ }
+
+ if (isCheckable() && checkedProgress > 0) {
+ const qreal q = Qt::TransparentMode == bg_mode_ ? 0.45 : 0.7;
+ brush.setColor(foregroundColor());
+ painter->setOpacity(q * checkedProgress);
+ painter->setBrush(brush);
+ QRect r(rect());
+ r.setHeight(static_cast<qreal>(r.height()) * checkedProgress);
+ painter->drawRect(r);
+ }
}
#define COLOR_INTERPOLATE(CH) (1 - progress) * source.CH() + progress *dest.CH()
@@ -498,64 +498,63 @@ FlatButton::paintBackground(QPainter *painter)
void
FlatButton::paintForeground(QPainter *painter)
{
- if (isEnabled()) {
- painter->setPen(foregroundColor());
- const qreal progress = state_machine_->checkedOverlayProgress();
-
- if (isCheckable() && progress > 0) {
- QColor source = foregroundColor();
- QColor dest =
- Qt::TransparentMode == bg_mode_ ? Qt::white : backgroundColor();
- if (qFuzzyCompare(1, progress)) {
- painter->setPen(dest);
- } else {
- painter->setPen(QColor(COLOR_INTERPOLATE(red),
- COLOR_INTERPOLATE(green),
- COLOR_INTERPOLATE(blue),
- COLOR_INTERPOLATE(alpha)));
- }
- }
- } else {
- painter->setPen(disabledForegroundColor());
+ if (isEnabled()) {
+ painter->setPen(foregroundColor());
+ const qreal progress = state_machine_->checkedOverlayProgress();
+
+ if (isCheckable() && progress > 0) {
+ QColor source = foregroundColor();
+ QColor dest = Qt::TransparentMode == bg_mode_ ? Qt::white : backgroundColor();
+ if (qFuzzyCompare(1, progress)) {
+ painter->setPen(dest);
+ } else {
+ painter->setPen(QColor(COLOR_INTERPOLATE(red),
+ COLOR_INTERPOLATE(green),
+ COLOR_INTERPOLATE(blue),
+ COLOR_INTERPOLATE(alpha)));
+ }
}
+ } else {
+ painter->setPen(disabledForegroundColor());
+ }
- if (icon().isNull()) {
- painter->drawText(rect(), Qt::AlignCenter, removeKDEAccelerators(text()));
- return;
- }
+ if (icon().isNull()) {
+ painter->drawText(rect(), Qt::AlignCenter, removeKDEAccelerators(text()));
+ return;
+ }
- QSize textSize(fontMetrics().size(Qt::TextSingleLine, removeKDEAccelerators(text())));
- QSize base(size() - textSize);
+ QSize textSize(fontMetrics().size(Qt::TextSingleLine, removeKDEAccelerators(text())));
+ QSize base(size() - textSize);
- const int iw = iconSize().width() + IconPadding;
- QPoint pos((base.width() - iw) / 2, 0);
+ const int iw = iconSize().width() + IconPadding;
+ QPoint pos((base.width() - iw) / 2, 0);
- QRect textGeometry(pos + QPoint(0, base.height() / 2), textSize);
- QRect iconGeometry(pos + QPoint(0, (height() - iconSize().height()) / 2), iconSize());
+ QRect textGeometry(pos + QPoint(0, base.height() / 2), textSize);
+ QRect iconGeometry(pos + QPoint(0, (height() - iconSize().height()) / 2), iconSize());
- /* if (ui::LeftIcon == icon_placement_) { */
- /* textGeometry.translate(iw, 0); */
- /* } else { */
- /* iconGeometry.translate(textSize.width() + IconPadding, 0); */
- /* } */
+ /* if (ui::LeftIcon == icon_placement_) { */
+ /* textGeometry.translate(iw, 0); */
+ /* } else { */
+ /* iconGeometry.translate(textSize.width() + IconPadding, 0); */
+ /* } */
- painter->drawText(textGeometry, Qt::AlignCenter, removeKDEAccelerators(text()));
+ painter->drawText(textGeometry, Qt::AlignCenter, removeKDEAccelerators(text()));
- QPixmap pixmap = icon().pixmap(iconSize());
- QPainter icon(&pixmap);
- icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
- icon.fillRect(pixmap.rect(), painter->pen().color());
- painter->drawPixmap(iconGeometry, pixmap);
+ QPixmap pixmap = icon().pixmap(iconSize());
+ QPainter icon(&pixmap);
+ icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ icon.fillRect(pixmap.rect(), painter->pen().color());
+ painter->drawPixmap(iconGeometry, pixmap);
}
void
FlatButton::updateClipPath()
{
- const qreal radius = corner_radius_;
+ const qreal radius = corner_radius_;
- QPainterPath path;
- path.addRoundedRect(rect(), radius, radius);
- ripple_overlay_->setClipPath(path);
+ QPainterPath path;
+ path.addRoundedRect(rect(), radius, radius);
+ ripple_overlay_->setClipPath(path);
}
FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent)
@@ -575,45 +574,45 @@ FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent)
, checked_overlay_progress_(parent->isChecked() ? 1 : 0)
, was_checked_(false)
{
- Q_ASSERT(parent);
+ Q_ASSERT(parent);
- parent->installEventFilter(this);
+ parent->installEventFilter(this);
- config_state_->setInitialState(neutral_state_);
- addState(top_level_state_);
- setInitialState(top_level_state_);
+ config_state_->setInitialState(neutral_state_);
+ addState(top_level_state_);
+ setInitialState(top_level_state_);
- checkable_state_->setInitialState(parent->isChecked() ? checked_state_ : unchecked_state_);
- QSignalTransition *transition;
- QPropertyAnimation *animation;
+ checkable_state_->setInitialState(parent->isChecked() ? checked_state_ : unchecked_state_);
+ QSignalTransition *transition;
+ QPropertyAnimation *animation;
- transition = new QSignalTransition(this, SIGNAL(buttonChecked()));
- transition->setTargetState(checked_state_);
- unchecked_state_->addTransition(transition);
+ transition = new QSignalTransition(this, SIGNAL(buttonChecked()));
+ transition->setTargetState(checked_state_);
+ unchecked_state_->addTransition(transition);
- animation = new QPropertyAnimation(this, "checkedOverlayProgress", this);
- animation->setDuration(200);
- transition->addAnimation(animation);
+ animation = new QPropertyAnimation(this, "checkedOverlayProgress", this);
+ animation->setDuration(200);
+ transition->addAnimation(animation);
- transition = new QSignalTransition(this, SIGNAL(buttonUnchecked()));
- transition->setTargetState(unchecked_state_);
- checked_state_->addTransition(transition);
+ transition = new QSignalTransition(this, SIGNAL(buttonUnchecked()));
+ transition->setTargetState(unchecked_state_);
+ checked_state_->addTransition(transition);
- animation = new QPropertyAnimation(this, "checkedOverlayProgress", this);
- animation->setDuration(200);
- transition->addAnimation(animation);
+ animation = new QPropertyAnimation(this, "checkedOverlayProgress", this);
+ animation->setDuration(200);
+ transition->addAnimation(animation);
- addTransition(button_, QEvent::FocusIn, neutral_state_, neutral_focused_state_);
- addTransition(button_, QEvent::FocusOut, neutral_focused_state_, neutral_state_);
- addTransition(button_, QEvent::Enter, neutral_state_, hovered_state_);
- addTransition(button_, QEvent::Leave, hovered_state_, neutral_state_);
- addTransition(button_, QEvent::Enter, neutral_focused_state_, hovered_focused_state_);
- addTransition(button_, QEvent::Leave, hovered_focused_state_, neutral_focused_state_);
- addTransition(button_, QEvent::FocusIn, hovered_state_, hovered_focused_state_);
- addTransition(button_, QEvent::FocusOut, hovered_focused_state_, hovered_state_);
- addTransition(this, SIGNAL(buttonPressed()), hovered_state_, pressed_state_);
- addTransition(button_, QEvent::Leave, pressed_state_, neutral_focused_state_);
- addTransition(button_, QEvent::FocusOut, pressed_state_, hovered_state_);
+ addTransition(button_, QEvent::FocusIn, neutral_state_, neutral_focused_state_);
+ addTransition(button_, QEvent::FocusOut, neutral_focused_state_, neutral_state_);
+ addTransition(button_, QEvent::Enter, neutral_state_, hovered_state_);
+ addTransition(button_, QEvent::Leave, hovered_state_, neutral_state_);
+ addTransition(button_, QEvent::Enter, neutral_focused_state_, hovered_focused_state_);
+ addTransition(button_, QEvent::Leave, hovered_focused_state_, neutral_focused_state_);
+ addTransition(button_, QEvent::FocusIn, hovered_state_, hovered_focused_state_);
+ addTransition(button_, QEvent::FocusOut, hovered_focused_state_, hovered_state_);
+ addTransition(this, SIGNAL(buttonPressed()), hovered_state_, pressed_state_);
+ addTransition(button_, QEvent::Leave, pressed_state_, neutral_focused_state_);
+ addTransition(button_, QEvent::FocusOut, pressed_state_, hovered_state_);
}
FlatButtonStateMachine::~FlatButtonStateMachine() {}
@@ -621,73 +620,73 @@ FlatButtonStateMachine::~FlatButtonStateMachine() {}
void
FlatButtonStateMachine::setOverlayOpacity(qreal opacity)
{
- overlay_opacity_ = opacity;
- button_->update();
+ overlay_opacity_ = opacity;
+ button_->update();
}
void
FlatButtonStateMachine::setCheckedOverlayProgress(qreal opacity)
{
- checked_overlay_progress_ = opacity;
- button_->update();
+ checked_overlay_progress_ = opacity;
+ button_->update();
}
void
FlatButtonStateMachine::startAnimations()
{
- start();
+ start();
}
void
FlatButtonStateMachine::setupProperties()
{
- QColor overlayColor;
+ QColor overlayColor;
- if (Qt::TransparentMode == button_->backgroundMode()) {
- overlayColor = button_->backgroundColor();
- } else {
- overlayColor = button_->foregroundColor();
- }
+ if (Qt::TransparentMode == button_->backgroundMode()) {
+ overlayColor = button_->backgroundColor();
+ } else {
+ overlayColor = button_->foregroundColor();
+ }
- const qreal baseOpacity = button_->baseOpacity();
+ const qreal baseOpacity = button_->baseOpacity();
- neutral_state_->assignProperty(this, "overlayOpacity", 0);
- neutral_focused_state_->assignProperty(this, "overlayOpacity", 0);
- hovered_state_->assignProperty(this, "overlayOpacity", baseOpacity);
- hovered_focused_state_->assignProperty(this, "overlayOpacity", baseOpacity);
- pressed_state_->assignProperty(this, "overlayOpacity", baseOpacity);
- checked_state_->assignProperty(this, "checkedOverlayProgress", 1);
- unchecked_state_->assignProperty(this, "checkedOverlayProgress", 0);
+ neutral_state_->assignProperty(this, "overlayOpacity", 0);
+ neutral_focused_state_->assignProperty(this, "overlayOpacity", 0);
+ hovered_state_->assignProperty(this, "overlayOpacity", baseOpacity);
+ hovered_focused_state_->assignProperty(this, "overlayOpacity", baseOpacity);
+ pressed_state_->assignProperty(this, "overlayOpacity", baseOpacity);
+ checked_state_->assignProperty(this, "checkedOverlayProgress", 1);
+ unchecked_state_->assignProperty(this, "checkedOverlayProgress", 0);
- button_->update();
+ button_->update();
}
void
FlatButtonStateMachine::updateCheckedStatus()
{
- const bool checked = button_->isChecked();
- if (was_checked_ != checked) {
- was_checked_ = checked;
- if (checked) {
- emit buttonChecked();
- } else {
- emit buttonUnchecked();
- }
+ const bool checked = button_->isChecked();
+ if (was_checked_ != checked) {
+ was_checked_ = checked;
+ if (checked) {
+ emit buttonChecked();
+ } else {
+ emit buttonUnchecked();
}
+ }
}
bool
FlatButtonStateMachine::eventFilter(QObject *watched, QEvent *event)
{
- if (QEvent::FocusIn == event->type()) {
- QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event);
- if (focusEvent && Qt::MouseFocusReason == focusEvent->reason()) {
- emit buttonPressed();
- return true;
- }
+ if (QEvent::FocusIn == event->type()) {
+ QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event);
+ if (focusEvent && Qt::MouseFocusReason == focusEvent->reason()) {
+ emit buttonPressed();
+ return true;
}
+ }
- return QStateMachine::eventFilter(watched, event);
+ return QStateMachine::eventFilter(watched, event);
}
void
@@ -696,7 +695,7 @@ FlatButtonStateMachine::addTransition(QObject *object,
QState *fromState,
QState *toState)
{
- addTransition(new QSignalTransition(object, signal), fromState, toState);
+ addTransition(new QSignalTransition(object, signal), fromState, toState);
}
void
@@ -705,7 +704,7 @@ FlatButtonStateMachine::addTransition(QObject *object,
QState *fromState,
QState *toState)
{
- addTransition(new QEventTransition(object, eventType), fromState, toState);
+ addTransition(new QEventTransition(object, eventType), fromState, toState);
}
void
@@ -713,13 +712,13 @@ FlatButtonStateMachine::addTransition(QAbstractTransition *transition,
QState *fromState,
QState *toState)
{
- transition->setTargetState(toState);
+ transition->setTargetState(toState);
- QPropertyAnimation *animation;
+ QPropertyAnimation *animation;
- animation = new QPropertyAnimation(this, "overlayOpacity", this);
- animation->setDuration(150);
- transition->addAnimation(animation);
+ animation = new QPropertyAnimation(this, "overlayOpacity", this);
+ animation->setDuration(150);
+ transition->addAnimation(animation);
- fromState->addTransition(transition);
+ fromState->addTransition(transition);
}
|