diff --git a/resources/styles/nheko-dark.qss b/resources/styles/nheko-dark.qss index 7caa7ef..5c8fc97 100644 --- a/resources/styles/nheko-dark.qss +++ b/resources/styles/nheko-dark.qss @@ -233,3 +233,8 @@ Toggle { qproperty-inactiveColor: gray; qproperty-trackColor: rgb(240, 240, 240); } + +SnackBar { + qproperty-textColor: #caccd1; + qproperty-bgColor: #202228; +} diff --git a/resources/styles/nheko.qss b/resources/styles/nheko.qss index 3f06f79..7184dbf 100644 --- a/resources/styles/nheko.qss +++ b/resources/styles/nheko.qss @@ -221,3 +221,8 @@ Toggle { qproperty-inactiveColor: gray; qproperty-trackColor: rgb(240, 240, 240); } + +SnackBar { + qproperty-textColor: white; + qproperty-bgColor: #495057; +} diff --git a/resources/styles/system.qss b/resources/styles/system.qss index 7a90e03..7dc3741 100644 --- a/resources/styles/system.qss +++ b/resources/styles/system.qss @@ -14,6 +14,11 @@ OverlayWidget > * { border-left: 1px solid palette(text); } +TopRoomBar { + qproperty-borderColor: palette(text); + border: none; +} + TimelineView, TimelineView > *, TimelineItem, @@ -150,3 +155,8 @@ QListWidget { background-color: palette(window); color: palette(text); } + +SnackBar { + qproperty-textColor: palette(text); + qproperty-bgColor: palette(base); +} diff --git a/src/TopRoomBar.h b/src/TopRoomBar.h index 1c42e25..994486e 100644 --- a/src/TopRoomBar.h +++ b/src/TopRoomBar.h @@ -79,8 +79,7 @@ protected: style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); p.setPen(QPen(borderColor())); - p.drawLine(QPointF(0, height() - p.pen().widthF()), - QPointF(width(), height() - p.pen().widthF())); + p.drawLine(QPointF(0, height()), QPointF(width(), height())); } private: diff --git a/src/ui/SnackBar.cpp b/src/ui/SnackBar.cpp index 43a4c85..8a05d93 100644 --- a/src/ui/SnackBar.cpp +++ b/src/ui/SnackBar.cpp @@ -1,40 +1,37 @@ -#include #include #include #include "SnackBar.h" -constexpr int STARTING_OFFSET = 1; +constexpr int STARTING_OFFSET = 1; +constexpr int ANIMATION_DURATION = 6'000; +constexpr int BOX_PADDING = 10; +constexpr double MIN_WIDTH = 400.0; +constexpr double MIN_WIDTH_PERCENTAGE = 0.3; SnackBar::SnackBar(QWidget *parent) : OverlayWidget(parent) { - bgOpacity_ = 0.9; - duration_ = 6000; - boxWidth_ = 400; - boxHeight_ = 40; - boxPadding_ = 10; - textColor_ = QColor("white"); - bgColor_ = QColor("#333"); - offset_ = STARTING_OFFSET; - position_ = SnackBarPosition::Top; - - QFont font("Open Sans"); - font.setPixelSize(14); + QFont font; + font.setPointSizeF(font.pointSizeF() * 1.2); font.setWeight(50); setFont(font); + boxHeight_ = QFontMetrics(font).height() * 2; + offset_ = STARTING_OFFSET; + position_ = SnackBarPosition::Top; + hideTimer_.setSingleShot(true); auto offset_anim = tweeny::from(1.0f).to(0.0f).during(100).via(tweeny::easing::cubicOut); connect(&showTimer_, &QTimer::timeout, this, [this, offset_anim]() mutable { if (offset_anim.progress() < 1.0f) { offset_ = offset_anim.step(0.07f); - update(); + repaint(); } else { showTimer_.stop(); - hideTimer_.start(duration_); + hideTimer_.start(ANIMATION_DURATION); offset_anim.seek(0.0f); } }); @@ -115,27 +112,26 @@ SnackBar::paintEvent(QPaintEvent *event) brush.setStyle(Qt::SolidPattern); brush.setColor(bgColor_); p.setBrush(brush); - p.setOpacity(bgOpacity_); - QRect r(0, 0, boxWidth_, boxHeight_); + QRect r(0, 0, std::max(MIN_WIDTH, width() * MIN_WIDTH_PERCENTAGE), boxHeight_); p.setPen(Qt::white); QRect br = p.boundingRect(r, Qt::AlignHCenter | Qt::AlignTop | Qt::TextWordWrap, message_); p.setPen(Qt::NoPen); - r = br.united(r).adjusted(-boxPadding_, -boxPadding_, boxPadding_, boxPadding_); + r = br.united(r).adjusted(-BOX_PADDING, -BOX_PADDING, BOX_PADDING, BOX_PADDING); const qreal s = 1 - offset_; if (position_ == SnackBarPosition::Bottom) - p.translate((width() - (r.width() - 2 * boxPadding_)) / 2, - height() - boxPadding_ - s * (r.height())); + p.translate((width() - (r.width() - 2 * BOX_PADDING)) / 2, + height() - BOX_PADDING - s * (r.height())); else - p.translate((width() - (r.width() - 2 * boxPadding_)) / 2, - s * (r.height()) - 2 * boxPadding_); + p.translate((width() - (r.width() - 2 * BOX_PADDING)) / 2, + s * (r.height()) - 2 * BOX_PADDING); br.moveCenter(r.center()); - p.drawRoundedRect(r.adjusted(0, 0, 0, 3), 3, 3); + p.drawRoundedRect(r.adjusted(0, 0, 0, 4), 4, 4); p.setPen(textColor_); p.drawText(br, Qt::AlignHCenter | Qt::AlignTop | Qt::TextWordWrap, message_); } diff --git a/src/ui/SnackBar.h b/src/ui/SnackBar.h index eed59c8..15cbf62 100644 --- a/src/ui/SnackBar.h +++ b/src/ui/SnackBar.h @@ -17,12 +17,30 @@ class SnackBar : public OverlayWidget { Q_OBJECT + Q_PROPERTY(QColor bgColor READ backgroundColor WRITE setBackgroundColor) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + public: explicit SnackBar(QWidget *parent); - inline void setBackgroundColor(const QColor &color); - inline void setTextColor(const QColor &color); - inline void setPosition(SnackBarPosition pos); + QColor backgroundColor() const { return bgColor_; } + void setBackgroundColor(const QColor &color) + { + bgColor_ = color; + update(); + } + + QColor textColor() const { return textColor_; } + void setTextColor(const QColor &color) + { + textColor_ = color; + update(); + } + void setPosition(SnackBarPosition pos) + { + position_ = pos; + update(); + } public slots: void showMessage(const QString &msg); @@ -49,31 +67,7 @@ private: QTimer showTimer_; QTimer hideTimer_; - int duration_; - int boxWidth_; - int boxHeight_; - int boxPadding_; + double boxHeight_; SnackBarPosition position_; }; - -inline void -SnackBar::setPosition(SnackBarPosition pos) -{ - position_ = pos; - update(); -} - -inline void -SnackBar::setBackgroundColor(const QColor &color) -{ - bgColor_ = color; - update(); -} - -inline void -SnackBar::setTextColor(const QColor &color) -{ - textColor_ = color; - update(); -}