Use RoundRect in RoundButton.

This commit is contained in:
John Preston 2019-09-25 15:53:59 +03:00
parent c9990aee05
commit 3ef71f63b8
4 changed files with 17 additions and 12 deletions

View file

@ -74,6 +74,10 @@ RoundRect::RoundRect(
}, _lifetime); }, _lifetime);
} }
const style::color &RoundRect::color() const {
return _color;
}
void RoundRect::paint( void RoundRect::paint(
QPainter &p, QPainter &p,
const QRect &rect, const QRect &rect,

View file

@ -18,13 +18,14 @@ void DrawRoundedRect(
QPainter &p, QPainter &p,
const QRect &rect, const QRect &rect,
const QBrush &brush, const QBrush &brush,
const std::array<QImage, 4> & corners, const std::array<QImage, 4> &corners,
RectParts parts = RectPart::Full); RectParts parts = RectPart::Full);
class RoundRect final { class RoundRect final {
public: public:
RoundRect(ImageRoundRadius radius, const style::color &color); RoundRect(ImageRoundRadius radius, const style::color &color);
[[nodiscard]] const style::color &color() const;
void paint( void paint(
QPainter &p, QPainter &p,
const QRect &rect, const QRect &rect,

View file

@ -232,7 +232,9 @@ RoundButton::RoundButton(
const style::RoundButton &st) const style::RoundButton &st)
: RippleButton(parent, st.ripple) : RippleButton(parent, st.ripple)
, _textFull(std::move(text)) , _textFull(std::move(text))
, _st(st) { , _st(st)
, _roundRect(ImageRoundRadius::Small, _st.textBg)
, _roundRectOver(ImageRoundRadius::Small, _st.textBgOver) {
_textFull.value( _textFull.value(
) | rpl::start_with_next([=](const QString &text) { ) | rpl::start_with_next([=](const QString &text) {
resizeToText(text); resizeToText(text);
@ -336,29 +338,24 @@ void RoundButton::paintEvent(QPaintEvent *e) {
if (_fullWidthOverride < 0) { if (_fullWidthOverride < 0) {
rounded = QRect(0, rounded.top(), innerWidth - _fullWidthOverride, rounded.height()); rounded = QRect(0, rounded.top(), innerWidth - _fullWidthOverride, rounded.height());
} }
const auto drawRect = [&](const style::color &color) { const auto drawRect = [&](const RoundRect &rect) {
const auto fill = myrtlrect(rounded); const auto fill = myrtlrect(rounded);
if (_fullRadius) { if (_fullRadius) {
const auto radius = rounded.height() / 2; const auto radius = rounded.height() / 2;
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.setBrush(color); p.setBrush(rect.color());
p.drawRoundedRect(fill, radius, radius); p.drawRoundedRect(fill, radius, radius);
} else { } else {
PainterHighQualityEnabler hq(p); rect.paint(p, fill);
p.setPen(Qt::NoPen);
p.setBrush(color);
p.drawRoundedRect(fill, st::buttonRadius, st::buttonRadius);
// #TODO ui
//App::roundRect(p, fill, color, ImageRoundRadius::Small);
} }
}; };
drawRect(_st.textBg); drawRect(_roundRect);
auto over = isOver(); auto over = isOver();
auto down = isDown(); auto down = isDown();
if (over || down) { if (over || down) {
drawRect(_st.textBgOver); drawRect(_roundRectOver);
} }
paintRipple(p, rounded.x(), rounded.y()); paintRipple(p, rounded.x(), rounded.y());

View file

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "ui/abstract_button.h" #include "ui/abstract_button.h"
#include "ui/round_rect.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
@ -151,6 +152,8 @@ private:
int _fullWidthOverride = 0; int _fullWidthOverride = 0;
const style::RoundButton &_st; const style::RoundButton &_st;
RoundRect _roundRect;
RoundRect _roundRectOver;
TextTransform _transform = TextTransform::ToUpper; TextTransform _transform = TextTransform::ToUpper;
bool _fullRadius = false; bool _fullRadius = false;