diff --git a/src/ui/Avatar.cc b/src/ui/Avatar.cc
index 878f7999..c8068366 100644
--- a/src/ui/Avatar.cc
+++ b/src/ui/Avatar.cc
@@ -7,16 +7,16 @@
Avatar::Avatar(QWidget *parent)
: QWidget(parent)
{
- size_ = ui::AvatarSize;
- type_ = ui::AvatarType::Letter;
- letter_ = QChar('A');
+ size_ = ui::AvatarSize;
+ type_ = ui::AvatarType::Letter;
+ letter_ = QChar('A');
- QFont _font(font());
- _font.setPointSizeF(ui::FontSize);
- setFont(_font);
+ QFont _font(font());
+ _font.setPointSizeF(ui::FontSize);
+ setFont(_font);
- QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
- setSizePolicy(policy);
+ QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+ setSizePolicy(policy);
}
Avatar::~Avatar()
@@ -26,128 +26,130 @@ Avatar::~Avatar()
QColor
Avatar::textColor() const
{
- if (!text_color_.isValid())
- return QColor("black");
+ if (!text_color_.isValid())
+ return QColor("black");
- return text_color_;
+ return text_color_;
}
QColor
Avatar::backgroundColor() const
{
- if (!text_color_.isValid())
- return QColor("white");
+ if (!text_color_.isValid())
+ return QColor("white");
- return background_color_;
+ return background_color_;
}
int
Avatar::size() const
{
- return size_;
+ return size_;
}
QSize
Avatar::sizeHint() const
{
- return QSize(size_ + 2, size_ + 2);
+ return QSize(size_ + 2, size_ + 2);
}
void
Avatar::setTextColor(const QColor &color)
{
- text_color_ = color;
+ text_color_ = color;
}
void
Avatar::setBackgroundColor(const QColor &color)
{
- background_color_ = color;
+ background_color_ = color;
}
void
Avatar::setSize(int size)
{
- size_ = size;
+ size_ = size;
- if (!image_.isNull()) {
- pixmap_ =
- QPixmap::fromImage(image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
- }
+ if (!image_.isNull()) {
+ pixmap_ = QPixmap::fromImage(
+ image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ }
- QFont _font(font());
- _font.setPointSizeF(size_ * (ui::FontSize) / 40);
+ QFont _font(font());
+ _font.setPointSizeF(size_ * (ui::FontSize) / 40);
- setFont(_font);
- update();
+ setFont(_font);
+ update();
}
void
Avatar::setLetter(const QChar &letter)
{
- letter_ = letter;
- type_ = ui::AvatarType::Letter;
- update();
+ letter_ = letter;
+ type_ = ui::AvatarType::Letter;
+ update();
}
void
Avatar::setImage(const QImage &image)
{
- image_ = image;
- type_ = ui::AvatarType::Image;
- pixmap_ = QPixmap::fromImage(image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
- update();
+ image_ = image;
+ type_ = ui::AvatarType::Image;
+ pixmap_ = QPixmap::fromImage(
+ image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ update();
}
void
Avatar::setIcon(const QIcon &icon)
{
- icon_ = icon;
- type_ = ui::AvatarType::Icon;
- update();
+ icon_ = icon;
+ type_ = ui::AvatarType::Icon;
+ update();
}
void
Avatar::paintEvent(QPaintEvent *)
{
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
-
- QRect r = rect();
- const int hs = size_ / 2;
-
- if (type_ != ui::AvatarType::Image) {
- QBrush brush;
- brush.setStyle(Qt::SolidPattern);
- brush.setColor(backgroundColor());
-
- painter.setPen(Qt::NoPen);
- painter.setBrush(brush);
- painter.drawEllipse(r.center(), hs, hs);
- }
-
- switch (type_) {
- case ui::AvatarType::Icon: {
- icon_.paint(&painter,
- QRect((width() - hs) / 2, (height() - hs) / 2, hs, hs),
- Qt::AlignCenter,
- QIcon::Normal);
- break;
- }
- case ui::AvatarType::Image: {
- QPainterPath ppath;
- ppath.addEllipse(width() / 2 - hs, height() / 2 - hs, size_, size_);
- painter.setClipPath(ppath);
- painter.drawPixmap(QRect(width() / 2 - hs, height() / 2 - hs, size_, size_), pixmap_);
- break;
- }
- case ui::AvatarType::Letter: {
- painter.setPen(textColor());
- painter.setBrush(Qt::NoBrush);
- painter.drawText(r.translated(0, -1), Qt::AlignCenter, letter_);
- break;
- }
- default:
- break;
- }
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ QRect r = rect();
+ const int hs = size_ / 2;
+
+ if (type_ != ui::AvatarType::Image) {
+ QBrush brush;
+ brush.setStyle(Qt::SolidPattern);
+ brush.setColor(backgroundColor());
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(brush);
+ painter.drawEllipse(r.center(), hs, hs);
+ }
+
+ switch (type_) {
+ case ui::AvatarType::Icon: {
+ icon_.paint(&painter,
+ QRect((width() - hs) / 2, (height() - hs) / 2, hs, hs),
+ Qt::AlignCenter,
+ QIcon::Normal);
+ break;
+ }
+ case ui::AvatarType::Image: {
+ QPainterPath ppath;
+ ppath.addEllipse(width() / 2 - hs, height() / 2 - hs, size_, size_);
+ painter.setClipPath(ppath);
+ painter.drawPixmap(QRect(width() / 2 - hs, height() / 2 - hs, size_, size_),
+ pixmap_);
+ break;
+ }
+ case ui::AvatarType::Letter: {
+ painter.setPen(textColor());
+ painter.setBrush(Qt::NoBrush);
+ painter.drawText(r.translated(0, -1), Qt::AlignCenter, letter_);
+ break;
+ }
+ default:
+ break;
+ }
}
diff --git a/src/ui/Badge.cc b/src/ui/Badge.cc
index b4a04343..ab34be0f 100644
--- a/src/ui/Badge.cc
+++ b/src/ui/Badge.cc
@@ -5,21 +5,21 @@
Badge::Badge(QWidget *parent)
: OverlayWidget(parent)
{
- init();
+ init();
}
Badge::Badge(const QIcon &icon, QWidget *parent)
: OverlayWidget(parent)
{
- init();
- setIcon(icon);
+ init();
+ setIcon(icon);
}
Badge::Badge(const QString &text, QWidget *parent)
: OverlayWidget(parent)
{
- init();
- setText(text);
+ init();
+ setText(text);
}
Badge::~Badge()
@@ -29,195 +29,195 @@ Badge::~Badge()
void
Badge::init()
{
- x_ = 0;
- y_ = 0;
- // TODO: Make padding configurable.
- padding_ = 5;
- diameter_ = 24;
+ x_ = 0;
+ y_ = 0;
+ // TODO: Make padding configurable.
+ padding_ = 5;
+ diameter_ = 24;
- setAttribute(Qt::WA_TransparentForMouseEvents);
+ setAttribute(Qt::WA_TransparentForMouseEvents);
- QFont _font(font());
- _font.setPointSizeF(7.5);
- _font.setStyleName("Bold");
+ QFont _font(font());
+ _font.setPointSizeF(7.5);
+ _font.setStyleName("Bold");
- setFont(_font);
- setText("");
+ setFont(_font);
+ setText("");
}
QString
Badge::text() const
{
- return text_;
+ return text_;
}
QIcon
Badge::icon() const
{
- return icon_;
+ return icon_;
}
QSize
Badge::sizeHint() const
{
- const int d = diameter();
- return QSize(d + 4, d + 4);
+ const int d = diameter();
+ return QSize(d + 4, d + 4);
}
qreal
Badge::relativeYPosition() const
{
- return y_;
+ return y_;
}
qreal
Badge::relativeXPosition() const
{
- return x_;
+ return x_;
}
QPointF
Badge::relativePosition() const
{
- return QPointF(x_, y_);
+ return QPointF(x_, y_);
}
QColor
Badge::backgroundColor() const
{
- if (!background_color_.isValid())
- return QColor("black");
+ if (!background_color_.isValid())
+ return QColor("black");
- return background_color_;
+ return background_color_;
}
QColor
Badge::textColor() const
{
- if (!text_color_.isValid())
- return QColor("white");
+ if (!text_color_.isValid())
+ return QColor("white");
- return text_color_;
+ return text_color_;
}
void
Badge::setTextColor(const QColor &color)
{
- text_color_ = color;
+ text_color_ = color;
}
void
Badge::setBackgroundColor(const QColor &color)
{
- background_color_ = color;
+ background_color_ = color;
}
void
Badge::setRelativePosition(const QPointF &pos)
{
- setRelativePosition(pos.x(), pos.y());
+ setRelativePosition(pos.x(), pos.y());
}
void
Badge::setRelativePosition(qreal x, qreal y)
{
- x_ = x;
- y_ = y;
- update();
+ x_ = x;
+ y_ = y;
+ update();
}
void
Badge::setRelativeXPosition(qreal x)
{
- x_ = x;
- update();
+ x_ = x;
+ update();
}
void
Badge::setRelativeYPosition(qreal y)
{
- y_ = y;
- update();
+ y_ = y;
+ update();
}
void
Badge::setIcon(const QIcon &icon)
{
- icon_ = icon;
- update();
+ icon_ = icon;
+ update();
}
void
Badge::setText(const QString &text)
{
- text_ = text;
+ text_ = text;
- if (!icon_.isNull())
- icon_ = QIcon();
+ if (!icon_.isNull())
+ icon_ = QIcon();
- size_ = fontMetrics().size(Qt::TextShowMnemonic, text);
+ size_ = fontMetrics().size(Qt::TextShowMnemonic, text);
- update();
+ update();
}
void
Badge::setDiameter(int diameter)
{
- if (diameter > 0) {
- diameter_ = diameter;
- update();
- }
+ if (diameter > 0) {
+ diameter_ = diameter;
+ update();
+ }
}
void
Badge::paintEvent(QPaintEvent *)
{
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
- painter.translate(x_, y_);
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.translate(x_, y_);
- QBrush brush;
- brush.setStyle(Qt::SolidPattern);
- brush.setColor(isEnabled() ? backgroundColor() : QColor("#cccccc"));
+ QBrush brush;
+ brush.setStyle(Qt::SolidPattern);
+ brush.setColor(isEnabled() ? backgroundColor() : QColor("#cccccc"));
- painter.setBrush(brush);
- painter.setPen(Qt::NoPen);
+ painter.setBrush(brush);
+ painter.setPen(Qt::NoPen);
- const int d = diameter();
+ const int d = diameter();
- QRectF r(0, 0, d, d);
- r.translate(QPointF((width() - d), (height() - d)) / 2);
+ QRectF r(0, 0, d, d);
+ r.translate(QPointF((width() - d), (height() - d)) / 2);
- if (icon_.isNull()) {
- QPen pen;
- // TODO: Make badge width configurable.
- pen.setWidth(1);
- pen.setColor(textColor());
+ if (icon_.isNull()) {
+ QPen pen;
+ // TODO: Make badge width configurable.
+ pen.setWidth(1);
+ pen.setColor(textColor());
- painter.setPen(pen);
- painter.drawEllipse(r);
+ painter.setPen(pen);
+ painter.drawEllipse(r);
- painter.setPen(textColor());
- painter.setBrush(Qt::NoBrush);
- painter.drawText(r.translated(0, -0.5), Qt::AlignCenter, text_);
- } else {
- painter.drawEllipse(r);
- QRectF q(0, 0, 16, 16);
- q.moveCenter(r.center());
- QPixmap pixmap = icon().pixmap(16, 16);
- QPainter icon(&pixmap);
- icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
- icon.fillRect(pixmap.rect(), textColor());
- painter.drawPixmap(q.toRect(), pixmap);
- }
+ painter.setPen(textColor());
+ painter.setBrush(Qt::NoBrush);
+ painter.drawText(r.translated(0, -0.5), Qt::AlignCenter, text_);
+ } else {
+ painter.drawEllipse(r);
+ QRectF q(0, 0, 16, 16);
+ q.moveCenter(r.center());
+ QPixmap pixmap = icon().pixmap(16, 16);
+ QPainter icon(&pixmap);
+ icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ icon.fillRect(pixmap.rect(), textColor());
+ painter.drawPixmap(q.toRect(), pixmap);
+ }
}
int
Badge::diameter() const
{
- if (icon_.isNull()) {
- return qMax(size_.width(), size_.height()) + padding_;
- }
+ if (icon_.isNull()) {
+ return qMax(size_.width(), size_.height()) + padding_;
+ }
- return diameter_;
+ return diameter_;
}
diff --git a/src/ui/FlatButton.cc b/src/ui/FlatButton.cc
index d59fe259..4ba92a38 100644
--- a/src/ui/FlatButton.cc
+++ b/src/ui/FlatButton.cc
@@ -14,54 +14,54 @@
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));
-
- QPainterPath path;
- path.addRoundedRect(rect(), corner_radius_, corner_radius_);
-
- ripple_overlay_->setClipPath(path);
- ripple_overlay_->setClipping(true);
-
- state_machine_->setupProperties();
- state_machine_->startAnimations();
+ 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));
+
+ QPainterPath path;
+ path.addRoundedRect(rect(), corner_radius_, corner_radius_);
+
+ ripple_overlay_->setClipPath(path);
+ ripple_overlay_->setClipping(true);
+
+ 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()
@@ -71,406 +71,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");
- }
+ 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");
- }
- }
+ 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.setPixelSize(size);
- setFont(f);
+ QFont f(font());
+ f.setPixelSize(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, text()));
+ QSize label(fontMetrics().size(Qt::TextSingleLine, 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();
-
- if (Qt::OpaqueMode == bg_mode_) {
- QBrush brush;
- brush.setStyle(Qt::SolidPattern);
-
- if (isEnabled()) {
- brush.setColor(backgroundColor());
- } else {
- brush.setColor(disabledBackgroundColor());
- }
-
- painter->setOpacity(1);
- painter->setBrush(brush);
- painter->setPen(Qt::NoPen);
- painter->drawRect(rect());
- }
-
- QBrush brush;
- brush.setStyle(Qt::SolidPattern);
- painter->setPen(Qt::NoPen);
-
- if (!isEnabled()) {
- return;
- }
-
- if ((ui::OverlayStyle::NoOverlay != overlay_style_) && (overlayOpacity > 0)) {
- if (ui::OverlayStyle::TintedOverlay == overlay_style_) {
- brush.setColor(overlayColor());
- } else {
- brush.setColor(Qt::gray);
- }
-
- 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);
- }
+ 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());
+ }
+
+ painter->setOpacity(1);
+ painter->setBrush(brush);
+ painter->setPen(Qt::NoPen);
+ painter->drawRect(rect());
+ }
+
+ QBrush brush;
+ brush.setStyle(Qt::SolidPattern);
+ painter->setPen(Qt::NoPen);
+
+ if (!isEnabled()) {
+ return;
+ }
+
+ if ((ui::OverlayStyle::NoOverlay != overlay_style_) && (overlayOpacity > 0)) {
+ if (ui::OverlayStyle::TintedOverlay == overlay_style_) {
+ brush.setColor(overlayColor());
+ } else {
+ brush.setColor(Qt::gray);
+ }
+
+ 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()
@@ -478,63 +478,64 @@ 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 (icon().isNull()) {
- painter->drawText(rect(), Qt::AlignCenter, text());
- return;
- }
-
- QSize textSize(fontMetrics().size(Qt::TextSingleLine, text()));
- QSize base(size() - textSize);
-
- 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());
-
- /* if (ui::LeftIcon == icon_placement_) { */
- /* textGeometry.translate(iw, 0); */
- /* } else { */
- /* iconGeometry.translate(textSize.width() + IconPadding, 0); */
- /* } */
-
- painter->drawText(textGeometry, Qt::AlignCenter, 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);
+ 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, text());
+ return;
+ }
+
+ QSize textSize(fontMetrics().size(Qt::TextSingleLine, text()));
+ QSize base(size() - textSize);
+
+ 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());
+
+ /* if (ui::LeftIcon == icon_placement_) { */
+ /* textGeometry.translate(iw, 0); */
+ /* } else { */
+ /* iconGeometry.translate(textSize.width() + IconPadding, 0); */
+ /* } */
+
+ painter->drawText(textGeometry, Qt::AlignCenter, 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);
}
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)
@@ -554,45 +555,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()
@@ -602,97 +603,105 @@ 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
-FlatButtonStateMachine::addTransition(QObject *object, const char *signal, QState *fromState, QState *toState)
+FlatButtonStateMachine::addTransition(QObject *object,
+ const char *signal,
+ QState *fromState,
+ QState *toState)
{
- addTransition(new QSignalTransition(object, signal), fromState, toState);
+ addTransition(new QSignalTransition(object, signal), fromState, toState);
}
void
-FlatButtonStateMachine::addTransition(QObject *object, QEvent::Type eventType, QState *fromState, QState *toState)
+FlatButtonStateMachine::addTransition(QObject *object,
+ QEvent::Type eventType,
+ QState *fromState,
+ QState *toState)
{
- addTransition(new QEventTransition(object, eventType), fromState, toState);
+ addTransition(new QEventTransition(object, eventType), fromState, toState);
}
void
-FlatButtonStateMachine::addTransition(QAbstractTransition *transition, QState *fromState, QState *toState)
+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);
}
diff --git a/src/ui/OverlayModal.cc b/src/ui/OverlayModal.cc
index 9bce351b..1da009d4 100644
--- a/src/ui/OverlayModal.cc
+++ b/src/ui/OverlayModal.cc
@@ -26,50 +26,50 @@ OverlayModal::OverlayModal(QWidget *parent, QWidget *content)
, duration_{ 500 }
, color_{ QColor(55, 55, 55) }
{
- setAttribute(Qt::WA_TranslucentBackground);
+ setAttribute(Qt::WA_TranslucentBackground);
- auto layout = new QVBoxLayout();
- layout->addWidget(content);
- layout->setAlignment(Qt::AlignCenter);
+ auto layout = new QVBoxLayout();
+ layout->addWidget(content);
+ layout->setAlignment(Qt::AlignCenter);
- setLayout(layout);
+ setLayout(layout);
- opacity_ = new QGraphicsOpacityEffect(this);
- setGraphicsEffect(opacity_);
+ opacity_ = new QGraphicsOpacityEffect(this);
+ setGraphicsEffect(opacity_);
- opacity_->setOpacity(1);
- animation_ = new QPropertyAnimation(opacity_, "opacity", this);
- animation_->setStartValue(1);
- animation_->setEndValue(0);
- animation_->setDuration(duration_);
- animation_->setEasingCurve(QEasingCurve::Linear);
+ opacity_->setOpacity(1);
+ animation_ = new QPropertyAnimation(opacity_, "opacity", this);
+ animation_->setStartValue(1);
+ animation_->setEndValue(0);
+ animation_->setDuration(duration_);
+ animation_->setEasingCurve(QEasingCurve::Linear);
- connect(animation_, &QPropertyAnimation::finished, [this]() {
- if (animation_->direction() == QAbstractAnimation::Forward)
- this->close();
- });
+ connect(animation_, &QPropertyAnimation::finished, [this]() {
+ if (animation_->direction() == QAbstractAnimation::Forward)
+ this->close();
+ });
}
void
OverlayModal::paintEvent(QPaintEvent *event)
{
- Q_UNUSED(event);
+ Q_UNUSED(event);
- QPainter painter(this);
- painter.fillRect(rect(), color_);
+ QPainter painter(this);
+ painter.fillRect(rect(), color_);
}
void
OverlayModal::fadeIn()
{
- animation_->setDirection(QAbstractAnimation::Backward);
- animation_->start();
- show();
+ animation_->setDirection(QAbstractAnimation::Backward);
+ animation_->start();
+ show();
}
void
OverlayModal::fadeOut()
{
- animation_->setDirection(QAbstractAnimation::Forward);
- animation_->start();
+ animation_->setDirection(QAbstractAnimation::Forward);
+ animation_->start();
}
diff --git a/src/ui/OverlayWidget.cc b/src/ui/OverlayWidget.cc
index ab394966..c69f81f7 100644
--- a/src/ui/OverlayWidget.cc
+++ b/src/ui/OverlayWidget.cc
@@ -4,58 +4,58 @@
OverlayWidget::OverlayWidget(QWidget *parent)
: QWidget(parent)
{
- if (parent) {
- parent->installEventFilter(this);
- setGeometry(overlayGeometry());
- raise();
- }
+ if (parent) {
+ parent->installEventFilter(this);
+ setGeometry(overlayGeometry());
+ raise();
+ }
}
bool
OverlayWidget::event(QEvent *event)
{
- if (!parent())
- return QWidget::event(event);
-
- switch (event->type()) {
- case QEvent::ParentChange: {
- parent()->installEventFilter(this);
- setGeometry(overlayGeometry());
- break;
- }
- case QEvent::ParentAboutToChange: {
- parent()->removeEventFilter(this);
- break;
- }
- default:
- break;
- }
-
- return QWidget::event(event);
+ if (!parent())
+ return QWidget::event(event);
+
+ switch (event->type()) {
+ case QEvent::ParentChange: {
+ parent()->installEventFilter(this);
+ setGeometry(overlayGeometry());
+ break;
+ }
+ case QEvent::ParentAboutToChange: {
+ parent()->removeEventFilter(this);
+ break;
+ }
+ default:
+ break;
+ }
+
+ return QWidget::event(event);
}
bool
OverlayWidget::eventFilter(QObject *obj, QEvent *event)
{
- switch (event->type()) {
- case QEvent::Move:
- case QEvent::Resize:
- setGeometry(overlayGeometry());
- break;
- default:
- break;
- }
-
- return QWidget::eventFilter(obj, event);
+ switch (event->type()) {
+ case QEvent::Move:
+ case QEvent::Resize:
+ setGeometry(overlayGeometry());
+ break;
+ default:
+ break;
+ }
+
+ return QWidget::eventFilter(obj, event);
}
QRect
OverlayWidget::overlayGeometry() const
{
- QWidget *widget = parentWidget();
+ QWidget *widget = parentWidget();
- if (!widget)
- return QRect();
+ if (!widget)
+ return QRect();
- return widget->rect();
+ return widget->rect();
}
diff --git a/src/ui/RaisedButton.cc b/src/ui/RaisedButton.cc
index f3bdb7c9..c30f253a 100644
--- a/src/ui/RaisedButton.cc
+++ b/src/ui/RaisedButton.cc
@@ -6,68 +6,68 @@
void
RaisedButton::init()
{
- shadow_state_machine_ = new QStateMachine(this);
- normal_state_ = new QState;
- pressed_state_ = new QState;
- effect_ = new QGraphicsDropShadowEffect;
+ shadow_state_machine_ = new QStateMachine(this);
+ normal_state_ = new QState;
+ pressed_state_ = new QState;
+ effect_ = new QGraphicsDropShadowEffect;
- effect_->setBlurRadius(7);
- effect_->setOffset(QPointF(0, 2));
- effect_->setColor(QColor(0, 0, 0, 75));
+ effect_->setBlurRadius(7);
+ effect_->setOffset(QPointF(0, 2));
+ effect_->setColor(QColor(0, 0, 0, 75));
- setBackgroundMode(Qt::OpaqueMode);
- setMinimumHeight(42);
- setGraphicsEffect(effect_);
- setBaseOpacity(0.3);
+ setBackgroundMode(Qt::OpaqueMode);
+ setMinimumHeight(42);
+ setGraphicsEffect(effect_);
+ setBaseOpacity(0.3);
- shadow_state_machine_->addState(normal_state_);
- shadow_state_machine_->addState(pressed_state_);
+ shadow_state_machine_->addState(normal_state_);
+ shadow_state_machine_->addState(pressed_state_);
- normal_state_->assignProperty(effect_, "offset", QPointF(0, 2));
- normal_state_->assignProperty(effect_, "blurRadius", 7);
+ normal_state_->assignProperty(effect_, "offset", QPointF(0, 2));
+ normal_state_->assignProperty(effect_, "blurRadius", 7);
- pressed_state_->assignProperty(effect_, "offset", QPointF(0, 5));
- pressed_state_->assignProperty(effect_, "blurRadius", 29);
+ pressed_state_->assignProperty(effect_, "offset", QPointF(0, 5));
+ pressed_state_->assignProperty(effect_, "blurRadius", 29);
- QAbstractTransition *transition;
+ QAbstractTransition *transition;
- transition = new QEventTransition(this, QEvent::MouseButtonPress);
- transition->setTargetState(pressed_state_);
- normal_state_->addTransition(transition);
+ transition = new QEventTransition(this, QEvent::MouseButtonPress);
+ transition->setTargetState(pressed_state_);
+ normal_state_->addTransition(transition);
- transition = new QEventTransition(this, QEvent::MouseButtonDblClick);
- transition->setTargetState(pressed_state_);
- normal_state_->addTransition(transition);
+ transition = new QEventTransition(this, QEvent::MouseButtonDblClick);
+ transition->setTargetState(pressed_state_);
+ normal_state_->addTransition(transition);
- transition = new QEventTransition(this, QEvent::MouseButtonRelease);
- transition->setTargetState(normal_state_);
- pressed_state_->addTransition(transition);
+ transition = new QEventTransition(this, QEvent::MouseButtonRelease);
+ transition->setTargetState(normal_state_);
+ pressed_state_->addTransition(transition);
- QPropertyAnimation *animation;
+ QPropertyAnimation *animation;
- animation = new QPropertyAnimation(effect_, "offset", this);
- animation->setDuration(100);
- shadow_state_machine_->addDefaultAnimation(animation);
+ animation = new QPropertyAnimation(effect_, "offset", this);
+ animation->setDuration(100);
+ shadow_state_machine_->addDefaultAnimation(animation);
- animation = new QPropertyAnimation(effect_, "blurRadius", this);
- animation->setDuration(100);
- shadow_state_machine_->addDefaultAnimation(animation);
+ animation = new QPropertyAnimation(effect_, "blurRadius", this);
+ animation->setDuration(100);
+ shadow_state_machine_->addDefaultAnimation(animation);
- shadow_state_machine_->setInitialState(normal_state_);
- shadow_state_machine_->start();
+ shadow_state_machine_->setInitialState(normal_state_);
+ shadow_state_machine_->start();
}
RaisedButton::RaisedButton(QWidget *parent)
: FlatButton(parent)
{
- init();
+ init();
}
RaisedButton::RaisedButton(const QString &text, QWidget *parent)
: FlatButton(parent)
{
- init();
- setText(text);
+ init();
+ setText(text);
}
RaisedButton::~RaisedButton()
@@ -77,15 +77,15 @@ RaisedButton::~RaisedButton()
bool
RaisedButton::event(QEvent *event)
{
- if (QEvent::EnabledChange == event->type()) {
- if (isEnabled()) {
- shadow_state_machine_->start();
- effect_->setEnabled(true);
- } else {
- shadow_state_machine_->stop();
- effect_->setEnabled(false);
- }
- }
-
- return FlatButton::event(event);
+ if (QEvent::EnabledChange == event->type()) {
+ if (isEnabled()) {
+ shadow_state_machine_->start();
+ effect_->setEnabled(true);
+ } else {
+ shadow_state_machine_->stop();
+ effect_->setEnabled(false);
+ }
+ }
+
+ return FlatButton::event(event);
}
diff --git a/src/ui/Ripple.cc b/src/ui/Ripple.cc
index 636b45d1..2869bf7b 100644
--- a/src/ui/Ripple.cc
+++ b/src/ui/Ripple.cc
@@ -10,7 +10,7 @@ Ripple::Ripple(const QPoint ¢er, QObject *parent)
, opacity_(0)
, center_(center)
{
- init();
+ init();
}
Ripple::Ripple(const QPoint ¢er, RippleOverlay *overlay, QObject *parent)
@@ -22,7 +22,7 @@ Ripple::Ripple(const QPoint ¢er, RippleOverlay *overlay, QObject *parent)
, opacity_(0)
, center_(center)
{
- init();
+ init();
}
Ripple::~Ripple()
@@ -32,80 +32,80 @@ Ripple::~Ripple()
void
Ripple::setRadius(qreal radius)
{
- Q_ASSERT(overlay_);
+ Q_ASSERT(overlay_);
- if (radius_ == radius)
- return;
+ if (radius_ == radius)
+ return;
- radius_ = radius;
- overlay_->update();
+ radius_ = radius;
+ overlay_->update();
}
void
Ripple::setOpacity(qreal opacity)
{
- Q_ASSERT(overlay_);
+ Q_ASSERT(overlay_);
- if (opacity_ == opacity)
- return;
+ if (opacity_ == opacity)
+ return;
- opacity_ = opacity;
- overlay_->update();
+ opacity_ = opacity;
+ overlay_->update();
}
void
Ripple::setColor(const QColor &color)
{
- if (brush_.color() == color)
- return;
+ if (brush_.color() == color)
+ return;
- brush_.setColor(color);
+ brush_.setColor(color);
- if (overlay_)
- overlay_->update();
+ if (overlay_)
+ overlay_->update();
}
void
Ripple::setBrush(const QBrush &brush)
{
- brush_ = brush;
+ brush_ = brush;
- if (overlay_)
- overlay_->update();
+ if (overlay_)
+ overlay_->update();
}
void
Ripple::destroy()
{
- Q_ASSERT(overlay_);
+ Q_ASSERT(overlay_);
- overlay_->removeRipple(this);
+ overlay_->removeRipple(this);
}
QPropertyAnimation *
Ripple::animate(const QByteArray &property, const QEasingCurve &easing, int duration)
{
- QPropertyAnimation *animation = new QPropertyAnimation;
- animation->setTargetObject(this);
- animation->setPropertyName(property);
- animation->setEasingCurve(easing);
- animation->setDuration(duration);
+ QPropertyAnimation *animation = new QPropertyAnimation;
+ animation->setTargetObject(this);
+ animation->setPropertyName(property);
+ animation->setEasingCurve(easing);
+ animation->setDuration(duration);
- addAnimation(animation);
+ addAnimation(animation);
- return animation;
+ return animation;
}
void
Ripple::init()
{
- setOpacityStartValue(0.5);
- setOpacityEndValue(0);
- setRadiusStartValue(0);
- setRadiusEndValue(300);
+ setOpacityStartValue(0.5);
+ setOpacityEndValue(0);
+ setRadiusStartValue(0);
+ setRadiusEndValue(300);
- brush_.setColor(Qt::black);
- brush_.setStyle(Qt::SolidPattern);
+ brush_.setColor(Qt::black);
+ brush_.setStyle(Qt::SolidPattern);
- connect(this, SIGNAL(finished()), this, SLOT(destroy()));
+ connect(this, SIGNAL(finished()), this, SLOT(destroy()));
}
diff --git a/src/ui/RippleOverlay.cc b/src/ui/RippleOverlay.cc
index be070355..cf264363 100644
--- a/src/ui/RippleOverlay.cc
+++ b/src/ui/RippleOverlay.cc
@@ -7,8 +7,8 @@ RippleOverlay::RippleOverlay(QWidget *parent)
: OverlayWidget(parent)
, use_clip_(false)
{
- setAttribute(Qt::WA_TransparentForMouseEvents);
- setAttribute(Qt::WA_NoSystemBackground);
+ setAttribute(Qt::WA_TransparentForMouseEvents);
+ setAttribute(Qt::WA_NoSystemBackground);
}
RippleOverlay::~RippleOverlay()
@@ -18,49 +18,49 @@ RippleOverlay::~RippleOverlay()
void
RippleOverlay::addRipple(Ripple *ripple)
{
- ripple->setOverlay(this);
- ripples_.push_back(ripple);
- ripple->start();
+ ripple->setOverlay(this);
+ ripples_.push_back(ripple);
+ ripple->start();
}
void
RippleOverlay::addRipple(const QPoint &position, qreal radius)
{
- Ripple *ripple = new Ripple(position);
- ripple->setRadiusEndValue(radius);
- addRipple(ripple);
+ Ripple *ripple = new Ripple(position);
+ ripple->setRadiusEndValue(radius);
+ addRipple(ripple);
}
void
RippleOverlay::removeRipple(Ripple *ripple)
{
- if (ripples_.removeOne(ripple))
- delete ripple;
+ if (ripples_.removeOne(ripple))
+ delete ripple;
}
void
RippleOverlay::paintEvent(QPaintEvent *event)
{
- Q_UNUSED(event)
+ Q_UNUSED(event)
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
- painter.setPen(Qt::NoPen);
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setPen(Qt::NoPen);
- if (use_clip_)
- painter.setClipPath(clip_path_);
+ if (use_clip_)
+ painter.setClipPath(clip_path_);
- for (auto it = ripples_.constBegin(); it != ripples_.constEnd(); it++)
- paintRipple(&painter, *it);
+ for (auto it = ripples_.constBegin(); it != ripples_.constEnd(); it++)
+ paintRipple(&painter, *it);
}
void
RippleOverlay::paintRipple(QPainter *painter, Ripple *ripple)
{
- const qreal radius = ripple->radius();
- const QPointF center = ripple->center();
+ const qreal radius = ripple->radius();
+ const QPointF center = ripple->center();
- painter->setOpacity(ripple->opacity());
- painter->setBrush(ripple->brush());
- painter->drawEllipse(center, radius, radius);
+ painter->setOpacity(ripple->opacity());
+ painter->setBrush(ripple->brush());
+ painter->drawEllipse(center, radius, radius);
}
diff --git a/src/ui/ScrollBar.cc b/src/ui/ScrollBar.cc
index 73cdf2ba..b186be23 100644
--- a/src/ui/ScrollBar.cc
+++ b/src/ui/ScrollBar.cc
@@ -25,86 +25,86 @@ ScrollBar::ScrollBar(QScrollArea *area, QWidget *parent)
: QScrollBar(parent)
, area_{ area }
{
- hideTimer_.setSingleShot(true);
+ hideTimer_.setSingleShot(true);
- connect(&hideTimer_, &QTimer::timeout, this, &ScrollBar::fadeOut);
+ connect(&hideTimer_, &QTimer::timeout, this, &ScrollBar::fadeOut);
- eff = new QGraphicsOpacityEffect(this);
- setGraphicsEffect(eff);
+ eff = new QGraphicsOpacityEffect(this);
+ setGraphicsEffect(eff);
}
void
ScrollBar::fadeOut()
{
- isActive = false;
-
- QPropertyAnimation *anim = new QPropertyAnimation(eff, "opacity");
- anim->setDuration(AnimationDuration);
- anim->setStartValue(1);
- anim->setEndValue(0);
- anim->setEasingCurve(QEasingCurve::Linear);
- anim->start(QPropertyAnimation::DeleteWhenStopped);
+ isActive = false;
+
+ QPropertyAnimation *anim = new QPropertyAnimation(eff, "opacity");
+ anim->setDuration(AnimationDuration);
+ anim->setStartValue(1);
+ anim->setEndValue(0);
+ anim->setEasingCurve(QEasingCurve::Linear);
+ anim->start(QPropertyAnimation::DeleteWhenStopped);
}
void
ScrollBar::fadeIn()
{
- QPropertyAnimation *anim = new QPropertyAnimation(eff, "opacity");
- anim->setDuration(AnimationDuration);
- anim->setStartValue(0);
- anim->setEndValue(1);
- anim->setEasingCurve(QEasingCurve::Linear);
- anim->start(QPropertyAnimation::DeleteWhenStopped);
+ QPropertyAnimation *anim = new QPropertyAnimation(eff, "opacity");
+ anim->setDuration(AnimationDuration);
+ anim->setStartValue(0);
+ anim->setEndValue(1);
+ anim->setEasingCurve(QEasingCurve::Linear);
+ anim->start(QPropertyAnimation::DeleteWhenStopped);
}
void
ScrollBar::sliderChange(SliderChange change)
{
- if (!isActive)
- fadeIn();
+ if (!isActive)
+ fadeIn();
- hideTimer_.stop();
- hideTimer_.start(1500);
- isActive = true;
+ hideTimer_.stop();
+ hideTimer_.start(1500);
+ isActive = true;
- QScrollBar::sliderChange(change);
+ QScrollBar::sliderChange(change);
}
void
ScrollBar::paintEvent(QPaintEvent *)
{
- if (!width() && !height()) {
- hide();
- return;
- }
+ if (!width() && !height()) {
+ hide();
+ return;
+ }
- QPainter p(this);
- p.setRenderHint(QPainter::TextAntialiasing);
- p.setRenderHint(QPainter::Antialiasing);
- p.setRenderHint(QPainter::SmoothPixmapTransform);
+ QPainter p(this);
+ p.setRenderHint(QPainter::TextAntialiasing);
+ p.setRenderHint(QPainter::Antialiasing);
+ p.setRenderHint(QPainter::SmoothPixmapTransform);
- p.setPen(Qt::NoPen);
+ p.setPen(Qt::NoPen);
- QColor bg(33, 33, 33, 30);
- QColor handle(0, 0, 0, 80);
+ QColor bg(33, 33, 33, 30);
+ QColor handle(0, 0, 0, 80);
- p.setBrush(bg);
- QRect backgroundArea(Padding, 0, handleWidth_, height());
- p.drawRoundedRect(backgroundArea, roundRadius_, roundRadius_);
+ p.setBrush(bg);
+ QRect backgroundArea(Padding, 0, handleWidth_, height());
+ p.drawRoundedRect(backgroundArea, roundRadius_, roundRadius_);
- int areaHeight = area_->height();
- int widgetHeight = area_->widget()->height();
+ int areaHeight = area_->height();
+ int widgetHeight = area_->widget()->height();
- double visiblePercentage = (double)areaHeight / (double)widgetHeight;
- int handleHeight = std::max(visiblePercentage * areaHeight, (double)minHandleHeight_);
+ double visiblePercentage = (double)areaHeight / (double)widgetHeight;
+ int handleHeight = std::max(visiblePercentage * areaHeight, (double)minHandleHeight_);
- if (maximum() == 0) {
- return;
- }
+ if (maximum() == 0) {
+ return;
+ }
- int handle_y = (value() * (areaHeight - handleHeight - roundRadius_ / 2)) / maximum();
+ int handle_y = (value() * (areaHeight - handleHeight - roundRadius_ / 2)) / maximum();
- p.setBrush(handle);
- QRect handleArea(Padding, handle_y, handleWidth_, handleHeight);
- p.drawRoundedRect(handleArea, roundRadius_, roundRadius_);
+ p.setBrush(handle);
+ QRect handleArea(Padding, handle_y, handleWidth_, handleHeight);
+ p.drawRoundedRect(handleArea, roundRadius_, roundRadius_);
}
diff --git a/src/ui/TextField.cc b/src/ui/TextField.cc
index 2d529326..efa77c39 100644
--- a/src/ui/TextField.cc
+++ b/src/ui/TextField.cc
@@ -10,26 +10,26 @@
TextField::TextField(QWidget *parent)
: QLineEdit(parent)
{
- // Get rid of the focus border on macOS.
- setAttribute(Qt::WA_MacShowFocusRect, 0);
-
- state_machine_ = new TextFieldStateMachine(this);
- label_ = 0;
- label_font_size_ = 13;
- show_label_ = false;
- background_color_ = QColor("white");
-
- setFrame(false);
- setAttribute(Qt::WA_Hover);
- setMouseTracking(true);
- setTextMargins(0, 4, 0, 6);
-
- QFont font("Open Sans");
- font.setPixelSize(12);
- setFont(font);
-
- state_machine_->start();
- QCoreApplication::processEvents();
+ // Get rid of the focus border on macOS.
+ setAttribute(Qt::WA_MacShowFocusRect, 0);
+
+ state_machine_ = new TextFieldStateMachine(this);
+ label_ = 0;
+ label_font_size_ = 13;
+ show_label_ = false;
+ background_color_ = QColor("white");
+
+ setFrame(false);
+ setAttribute(Qt::WA_Hover);
+ setMouseTracking(true);
+ setTextMargins(0, 4, 0, 6);
+
+ QFont font("Open Sans");
+ font.setPixelSize(12);
+ setFont(font);
+
+ state_machine_->start();
+ QCoreApplication::processEvents();
}
TextField::~TextField()
@@ -39,238 +39,238 @@ TextField::~TextField()
void
TextField::setBackgroundColor(const QColor &color)
{
- background_color_ = color;
+ background_color_ = color;
}
QColor
TextField::backgroundColor() const
{
- return background_color_;
+ return background_color_;
}
void
TextField::setShowLabel(bool value)
{
- if (show_label_ == value) {
- return;
- }
-
- show_label_ = value;
-
- if (!label_ && value) {
- label_ = new TextFieldLabel(this);
- state_machine_->setLabel(label_);
- }
-
- if (value) {
- setContentsMargins(0, 23, 0, 0);
- } else {
- setContentsMargins(0, 0, 0, 0);
- }
+ if (show_label_ == value) {
+ return;
+ }
+
+ show_label_ = value;
+
+ if (!label_ && value) {
+ label_ = new TextFieldLabel(this);
+ state_machine_->setLabel(label_);
+ }
+
+ if (value) {
+ setContentsMargins(0, 23, 0, 0);
+ } else {
+ setContentsMargins(0, 0, 0, 0);
+ }
}
bool
TextField::hasLabel() const
{
- return show_label_;
+ return show_label_;
}
void
TextField::setLabelFontSize(qreal size)
{
- label_font_size_ = size;
-
- if (label_) {
- QFont font(label_->font());
- font.setPixelSize(size);
- label_->setFont(font);
- label_->update();
- }
+ label_font_size_ = size;
+
+ if (label_) {
+ QFont font(label_->font());
+ font.setPixelSize(size);
+ label_->setFont(font);
+ label_->update();
+ }
}
qreal
TextField::labelFontSize() const
{
- return label_font_size_;
+ return label_font_size_;
}
void
TextField::setLabel(const QString &label)
{
- label_text_ = label;
- setShowLabel(true);
- label_->update();
+ label_text_ = label;
+ setShowLabel(true);
+ label_->update();
}
QString
TextField::label() const
{
- return label_text_;
+ return label_text_;
}
void
TextField::setTextColor(const QColor &color)
{
- text_color_ = color;
- setStyleSheet(QString("QLineEdit { color: %1; }").arg(color.name()));
+ text_color_ = color;
+ setStyleSheet(QString("QLineEdit { color: %1; }").arg(color.name()));
}
QColor
TextField::textColor() const
{
- if (!text_color_.isValid()) {
- return QColor("black");
- }
+ if (!text_color_.isValid()) {
+ return QColor("black");
+ }
- return text_color_;
+ return text_color_;
}
void
TextField::setLabelColor(const QColor &color)
{
- label_color_ = color;
+ label_color_ = color;
}
QColor
TextField::labelColor() const
{
- if (!label_color_.isValid()) {
- return QColor("#abb"); // TODO: Move this into Theme.h
- }
+ if (!label_color_.isValid()) {
+ return QColor("#abb"); // TODO: Move this into Theme.h
+ }
- return label_color_;
+ return label_color_;
}
void
TextField::setInkColor(const QColor &color)
{
- ink_color_ = color;
+ ink_color_ = color;
}
QColor
TextField::inkColor() const
{
- if (!ink_color_.isValid()) {
- return QColor("black");
- }
+ if (!ink_color_.isValid()) {
+ return QColor("black");
+ }
- return ink_color_;
+ return ink_color_;
}
void
TextField::setUnderlineColor(const QColor &color)
{
- underline_color_ = color;
+ underline_color_ = color;
}
QColor
TextField::underlineColor() const
{
- if (!underline_color_.isValid()) {
- return QColor("black");
- }
+ if (!underline_color_.isValid()) {
+ return QColor("black");
+ }
- return underline_color_;
+ return underline_color_;
}
bool
TextField::event(QEvent *event)
{
- switch (event->type()) {
- case QEvent::Resize:
- case QEvent::Move: {
- if (label_)
- label_->setGeometry(rect());
- break;
- }
- default:
- break;
- }
-
- return QLineEdit::event(event);
+ switch (event->type()) {
+ case QEvent::Resize:
+ case QEvent::Move: {
+ if (label_)
+ label_->setGeometry(rect());
+ break;
+ }
+ default:
+ break;
+ }
+
+ return QLineEdit::event(event);
}
void
TextField::paintEvent(QPaintEvent *event)
{
- QLineEdit::paintEvent(event);
-
- QPainter painter(this);
-
- if (text().isEmpty()) {
- painter.setOpacity(1 - state_machine_->progress());
- // painter.fillRect(rect(), parentWidget()->palette().color(backgroundRole()));
- painter.fillRect(rect(), backgroundColor());
- }
-
- const int y = height() - 1;
- const int wd = width() - 5;
-
- QPen pen;
- pen.setWidth(1);
- pen.setColor(underlineColor());
- painter.setPen(pen);
- painter.setOpacity(1);
- painter.drawLine(2, y, wd, y);
-
- QBrush brush;
- brush.setStyle(Qt::SolidPattern);
- brush.setColor(inkColor());
-
- const qreal progress = state_machine_->progress();
-
- if (progress > 0) {
- painter.setPen(Qt::NoPen);
- painter.setBrush(brush);
- const int w = (1 - progress) * static_cast<qreal>(wd / 2);
- painter.drawRect(w + 2.5, height() - 2, wd - 2 * w, 2);
- }
+ QLineEdit::paintEvent(event);
+
+ QPainter painter(this);
+
+ if (text().isEmpty()) {
+ painter.setOpacity(1 - state_machine_->progress());
+ // painter.fillRect(rect(), parentWidget()->palette().color(backgroundRole()));
+ painter.fillRect(rect(), backgroundColor());
+ }
+
+ const int y = height() - 1;
+ const int wd = width() - 5;
+
+ QPen pen;
+ pen.setWidth(1);
+ pen.setColor(underlineColor());
+ painter.setPen(pen);
+ painter.setOpacity(1);
+ painter.drawLine(2, y, wd, y);
+
+ QBrush brush;
+ brush.setStyle(Qt::SolidPattern);
+ brush.setColor(inkColor());
+
+ const qreal progress = state_machine_->progress();
+
+ if (progress > 0) {
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(brush);
+ const int w = (1 - progress) * static_cast<qreal>(wd / 2);
+ painter.drawRect(w + 2.5, height() - 2, wd - 2 * w, 2);
+ }
}
TextFieldStateMachine::TextFieldStateMachine(TextField *parent)
: QStateMachine(parent)
, text_field_(parent)
{
- normal_state_ = new QState;
- focused_state_ = new QState;
+ normal_state_ = new QState;
+ focused_state_ = new QState;
- label_ = 0;
- offset_anim_ = 0;
- color_anim_ = 0;
- progress_ = 0.0;
+ label_ = 0;
+ offset_anim_ = 0;
+ color_anim_ = 0;
+ progress_ = 0.0;
- addState(normal_state_);
- addState(focused_state_);
+ addState(normal_state_);
+ addState(focused_state_);
- setInitialState(normal_state_);
+ setInitialState(normal_state_);
- QEventTransition *transition;
- QPropertyAnimation *animation;
+ QEventTransition *transition;
+ QPropertyAnimation *animation;
- transition = new QEventTransition(parent, QEvent::FocusIn);
- transition->setTargetState(focused_state_);
- normal_state_->addTransition(transition);
+ transition = new QEventTransition(parent, QEvent::FocusIn);
+ transition->setTargetState(focused_state_);
+ normal_state_->addTransition(transition);
- animation = new QPropertyAnimation(this, "progress", this);
- animation->setEasingCurve(QEasingCurve::InCubic);
- animation->setDuration(310);
- transition->addAnimation(animation);
+ animation = new QPropertyAnimation(this, "progress", this);
+ animation->setEasingCurve(QEasingCurve::InCubic);
+ animation->setDuration(310);
+ transition->addAnimation(animation);
- transition = new QEventTransition(parent, QEvent::FocusOut);
- transition->setTargetState(normal_state_);
- focused_state_->addTransition(transition);
+ transition = new QEventTransition(parent, QEvent::FocusOut);
+ transition->setTargetState(normal_state_);
+ focused_state_->addTransition(transition);
- animation = new QPropertyAnimation(this, "progress", this);
- animation->setEasingCurve(QEasingCurve::OutCubic);
- animation->setDuration(310);
- transition->addAnimation(animation);
+ animation = new QPropertyAnimation(this, "progress", this);
+ animation->setEasingCurve(QEasingCurve::OutCubic);
+ animation->setDuration(310);
+ transition->addAnimation(animation);
- normal_state_->assignProperty(this, "progress", 0);
- focused_state_->assignProperty(this, "progress", 1);
+ normal_state_->assignProperty(this, "progress", 0);
+ focused_state_->assignProperty(this, "progress", 1);
- setupProperties();
+ setupProperties();
- connect(text_field_, SIGNAL(textChanged(QString)), this, SLOT(setupProperties()));
+ connect(text_field_, SIGNAL(textChanged(QString)), this, SLOT(setupProperties()));
}
TextFieldStateMachine::~TextFieldStateMachine()
@@ -280,75 +280,76 @@ TextFieldStateMachine::~TextFieldStateMachine()
void
TextFieldStateMachine::setLabel(TextFieldLabel *label)
{
- if (label_) {
- delete label_;
- }
-
- if (offset_anim_) {
- removeDefaultAnimation(offset_anim_);
- delete offset_anim_;
- }
-
- if (color_anim_) {
- removeDefaultAnimation(color_anim_);
- delete color_anim_;
- }
-
- label_ = label;
-
- if (label_) {
- offset_anim_ = new QPropertyAnimation(label_, "offset", this);
- offset_anim_->setDuration(210);
- offset_anim_->setEasingCurve(QEasingCurve::OutCubic);
- addDefaultAnimation(offset_anim_);
-
- color_anim_ = new QPropertyAnimation(label_, "color", this);
- color_anim_->setDuration(210);
- addDefaultAnimation(color_anim_);
- }
-
- setupProperties();
+ if (label_) {
+ delete label_;
+ }
+
+ if (offset_anim_) {
+ removeDefaultAnimation(offset_anim_);
+ delete offset_anim_;
+ }
+
+ if (color_anim_) {
+ removeDefaultAnimation(color_anim_);
+ delete color_anim_;
+ }
+
+ label_ = label;
+
+ if (label_) {
+ offset_anim_ = new QPropertyAnimation(label_, "offset", this);
+ offset_anim_->setDuration(210);
+ offset_anim_->setEasingCurve(QEasingCurve::OutCubic);
+ addDefaultAnimation(offset_anim_);
+
+ color_anim_ = new QPropertyAnimation(label_, "color", this);
+ color_anim_->setDuration(210);
+ addDefaultAnimation(color_anim_);
+ }
+
+ setupProperties();
}
void
TextFieldStateMachine::setupProperties()
{
- if (label_) {
- const int m = text_field_->textMargins().top();
-
- if (text_field_->text().isEmpty()) {
- normal_state_->assignProperty(label_, "offset", QPointF(0, 26));
- } else {
- normal_state_->assignProperty(label_, "offset", QPointF(0, 0 - m));
- }
-
- focused_state_->assignProperty(label_, "offset", QPointF(0, 0 - m));
- focused_state_->assignProperty(label_, "color", text_field_->inkColor());
- normal_state_->assignProperty(label_, "color", text_field_->labelColor());
-
- if (0 != label_->offset().y() && !text_field_->text().isEmpty()) {
- label_->setOffset(QPointF(0, 0 - m));
- } else if (!text_field_->hasFocus() && label_->offset().y() <= 0 && text_field_->text().isEmpty()) {
- label_->setOffset(QPointF(0, 26));
- }
- }
-
- text_field_->update();
+ if (label_) {
+ const int m = text_field_->textMargins().top();
+
+ if (text_field_->text().isEmpty()) {
+ normal_state_->assignProperty(label_, "offset", QPointF(0, 26));
+ } else {
+ normal_state_->assignProperty(label_, "offset", QPointF(0, 0 - m));
+ }
+
+ focused_state_->assignProperty(label_, "offset", QPointF(0, 0 - m));
+ focused_state_->assignProperty(label_, "color", text_field_->inkColor());
+ normal_state_->assignProperty(label_, "color", text_field_->labelColor());
+
+ if (0 != label_->offset().y() && !text_field_->text().isEmpty()) {
+ label_->setOffset(QPointF(0, 0 - m));
+ } else if (!text_field_->hasFocus() && label_->offset().y() <= 0 &&
+ text_field_->text().isEmpty()) {
+ label_->setOffset(QPointF(0, 26));
+ }
+ }
+
+ text_field_->update();
}
TextFieldLabel::TextFieldLabel(TextField *parent)
: QWidget(parent)
, text_field_(parent)
{
- x_ = 0;
- y_ = 26;
- scale_ = 1;
- color_ = parent->labelColor();
-
- QFontDatabase db;
- QFont font(db.font("Open Sans", "Medium", parent->labelFontSize()));
- font.setLetterSpacing(QFont::PercentageSpacing, 102);
- setFont(font);
+ x_ = 0;
+ y_ = 26;
+ scale_ = 1;
+ color_ = parent->labelColor();
+
+ QFontDatabase db;
+ QFont font(db.font("Open Sans", "Medium", parent->labelFontSize()));
+ font.setLetterSpacing(QFont::PercentageSpacing, 102);
+ setFont(font);
}
TextFieldLabel::~TextFieldLabel()
@@ -358,15 +359,15 @@ TextFieldLabel::~TextFieldLabel()
void
TextFieldLabel::paintEvent(QPaintEvent *)
{
- if (!text_field_->hasLabel())
- return;
+ if (!text_field_->hasLabel())
+ return;
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
- painter.scale(scale_, scale_);
- painter.setPen(color_);
- painter.setOpacity(1);
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.scale(scale_, scale_);
+ painter.setPen(color_);
+ painter.setOpacity(1);
- QPointF pos(2 + x_, height() - 36 + y_);
- painter.drawText(pos.x(), pos.y(), text_field_->label());
+ QPointF pos(2 + x_, height() - 36 + y_);
+ painter.drawText(pos.x(), pos.y(), text_field_->label());
}
diff --git a/src/ui/Theme.cc b/src/ui/Theme.cc
index 328bd874..1560cf12 100644
--- a/src/ui/Theme.cc
+++ b/src/ui/Theme.cc
@@ -5,21 +5,21 @@
Theme::Theme(QObject *parent)
: QObject(parent)
{
- setColor("Black", ui::Color::Black);
+ setColor("Black", ui::Color::Black);
- setColor("BrightWhite", ui::Color::BrightWhite);
- setColor("FadedWhite", ui::Color::FadedWhite);
- setColor("MediumWhite", ui::Color::MediumWhite);
+ setColor("BrightWhite", ui::Color::BrightWhite);
+ setColor("FadedWhite", ui::Color::FadedWhite);
+ setColor("MediumWhite", ui::Color::MediumWhite);
- setColor("BrightGreen", ui::Color::BrightGreen);
- setColor("DarkGreen", ui::Color::DarkGreen);
- setColor("LightGreen", ui::Color::LightGreen);
+ setColor("BrightGreen", ui::Color::BrightGreen);
+ setColor("DarkGreen", ui::Color::DarkGreen);
+ setColor("LightGreen", ui::Color::LightGreen);
- setColor("Gray", ui::Color::Gray);
- setColor("Red", ui::Color::Red);
- setColor("Blue", ui::Color::Blue);
+ setColor("Gray", ui::Color::Gray);
+ setColor("Red", ui::Color::Red);
+ setColor("Blue", ui::Color::Blue);
- setColor("Transparent", ui::Color::Transparent);
+ setColor("Transparent", ui::Color::Transparent);
}
Theme::~Theme()
@@ -29,43 +29,43 @@ Theme::~Theme()
QColor
Theme::rgba(int r, int g, int b, qreal a) const
{
- QColor color(r, g, b);
- color.setAlphaF(a);
+ QColor color(r, g, b);
+ color.setAlphaF(a);
- return color;
+ return color;
}
QColor
Theme::getColor(const QString &key) const
{
- if (!colors_.contains(key)) {
- qWarning() << "Color with key" << key << "could not be found";
- return QColor();
- }
+ if (!colors_.contains(key)) {
+ qWarning() << "Color with key" << key << "could not be found";
+ return QColor();
+ }
- return colors_.value(key);
+ return colors_.value(key);
}
void
Theme::setColor(const QString &key, const QColor &color)
{
- colors_.insert(key, color);
+ colors_.insert(key, color);
}
void
Theme::setColor(const QString &key, ui::Color color)
{
- static const QColor palette[] = {
- QColor("#171919"),
+ static const QColor palette[] = {
+ QColor("#171919"),
- QColor("#EBEBEB"), QColor("#C9C9C9"), QColor("#929292"),
+ QColor("#EBEBEB"), QColor("#C9C9C9"), QColor("#929292"),
- QColor("#1C3133"), QColor("#577275"), QColor("#46A451"),
+ QColor("#1C3133"), QColor("#577275"), QColor("#46A451"),
- QColor("#5D6565"), QColor("#E22826"), QColor("#81B3A9"),
+ QColor("#5D6565"), QColor("#E22826"), QColor("#81B3A9"),
- rgba(0, 0, 0, 0),
- };
+ rgba(0, 0, 0, 0),
+ };
- colors_.insert(key, palette[static_cast<int>(color)]);
+ colors_.insert(key, palette[static_cast<int>(color)]);
}
diff --git a/src/ui/ThemeManager.cc b/src/ui/ThemeManager.cc
index 021008b1..172ddc41 100644
--- a/src/ui/ThemeManager.cc
+++ b/src/ui/ThemeManager.cc
@@ -4,19 +4,19 @@
ThemeManager::ThemeManager()
{
- setTheme(new Theme);
+ setTheme(new Theme);
}
void
ThemeManager::setTheme(Theme *theme)
{
- theme_ = theme;
- theme_->setParent(this);
+ theme_ = theme;
+ theme_->setParent(this);
}
QColor
ThemeManager::themeColor(const QString &key) const
{
- Q_ASSERT(theme_);
- return theme_->getColor(key);
+ Q_ASSERT(theme_);
+ return theme_->getColor(key);
}
|