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);
}
const style::color &RoundRect::color() const {
return _color;
}
void RoundRect::paint(
QPainter &p,
const QRect &rect,

View file

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

View file

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

View file

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