mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-01 12:00:48 +00:00
Divided TopBar in Premium Settings into abstract and main classes.
This commit is contained in:
parent
90ef0e4969
commit
56cbde93da
@ -299,7 +299,60 @@ void SendScreenAccept(not_null<Window::SessionController*> controller) {
|
|||||||
MTP_jsonNull());
|
MTP_jsonNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
class TopBar final : public Ui::RpWidget {
|
class TopBarAbstract : public Ui::RpWidget {
|
||||||
|
public:
|
||||||
|
using Ui::RpWidget::RpWidget;
|
||||||
|
|
||||||
|
void setRoundEdges(bool value);
|
||||||
|
|
||||||
|
virtual void setPaused(bool paused) = 0;
|
||||||
|
virtual void setTextPosition(int x, int y) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEdges(QPainter &p, const QBrush &brush) const;
|
||||||
|
|
||||||
|
[[nodiscard]] QRectF starRect(
|
||||||
|
float64 topProgress,
|
||||||
|
float64 sizeProgress) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _roundEdges = true;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void TopBarAbstract::setRoundEdges(bool value) {
|
||||||
|
_roundEdges = value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TopBarAbstract::paintEdges(QPainter &p, const QBrush &brush) const {
|
||||||
|
const auto r = rect();
|
||||||
|
if (_roundEdges) {
|
||||||
|
PainterHighQualityEnabler hq(p);
|
||||||
|
const auto radius = st::boxRadius;
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
p.setBrush(brush);
|
||||||
|
p.drawRoundedRect(
|
||||||
|
r + QMargins{ 0, 0, 0, radius + 1 },
|
||||||
|
radius,
|
||||||
|
radius);
|
||||||
|
} else {
|
||||||
|
p.fillRect(r, brush);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF TopBarAbstract::starRect(
|
||||||
|
float64 topProgress,
|
||||||
|
float64 sizeProgress) const {
|
||||||
|
const auto starSize = st::settingsPremiumStarSize * sizeProgress;
|
||||||
|
return QRectF(
|
||||||
|
QPointF(
|
||||||
|
(width() - starSize.width()) / 2,
|
||||||
|
st::settingsPremiumStarTopSkip * topProgress),
|
||||||
|
starSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
class TopBar final : public TopBarAbstract {
|
||||||
public:
|
public:
|
||||||
TopBar(
|
TopBar(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
@ -307,19 +360,14 @@ public:
|
|||||||
rpl::producer<QString> title,
|
rpl::producer<QString> title,
|
||||||
rpl::producer<TextWithEntities> about);
|
rpl::producer<TextWithEntities> about);
|
||||||
|
|
||||||
void setPaused(bool paused);
|
void setPaused(bool paused) override;
|
||||||
void setRoundEdges(bool value);
|
void setTextPosition(int x, int y) override;
|
||||||
void setTextPosition(int x, int y);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] QRectF starRect(
|
|
||||||
float64 topProgress,
|
|
||||||
float64 sizeProgress) const;
|
|
||||||
|
|
||||||
const style::font &_titleFont;
|
const style::font &_titleFont;
|
||||||
const style::margins &_titlePadding;
|
const style::margins &_titlePadding;
|
||||||
object_ptr<Ui::FlatLabel> _about;
|
object_ptr<Ui::FlatLabel> _about;
|
||||||
@ -338,7 +386,6 @@ private:
|
|||||||
|
|
||||||
QPoint _titlePosition;
|
QPoint _titlePosition;
|
||||||
QPainterPath _titlePath;
|
QPainterPath _titlePath;
|
||||||
bool _roundEdges = true;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -347,7 +394,7 @@ TopBar::TopBar(
|
|||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
rpl::producer<QString> title,
|
rpl::producer<QString> title,
|
||||||
rpl::producer<TextWithEntities> about)
|
rpl::producer<TextWithEntities> about)
|
||||||
: Ui::RpWidget(parent)
|
: TopBarAbstract(parent)
|
||||||
, _titleFont(st::boxTitle.style.font)
|
, _titleFont(st::boxTitle.style.font)
|
||||||
, _titlePadding(st::settingsPremiumTitlePadding)
|
, _titlePadding(st::settingsPremiumTitlePadding)
|
||||||
, _about(this, std::move(about), st::settingsPremiumAbout)
|
, _about(this, std::move(about), st::settingsPremiumAbout)
|
||||||
@ -379,24 +426,10 @@ void TopBar::setPaused(bool paused) {
|
|||||||
_ministars.setPaused(paused);
|
_ministars.setPaused(paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBar::setRoundEdges(bool value) {
|
|
||||||
_roundEdges = value;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TopBar::setTextPosition(int x, int y) {
|
void TopBar::setTextPosition(int x, int y) {
|
||||||
_titlePosition = { x, y };
|
_titlePosition = { x, y };
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF TopBar::starRect(float64 topProgress, float64 sizeProgress) const {
|
|
||||||
const auto starSize = st::settingsPremiumStarSize * sizeProgress;
|
|
||||||
return QRectF(
|
|
||||||
QPointF(
|
|
||||||
(width() - starSize.width()) / 2,
|
|
||||||
st::settingsPremiumStarTopSkip * topProgress),
|
|
||||||
starSize);
|
|
||||||
};
|
|
||||||
|
|
||||||
void TopBar::resizeEvent(QResizeEvent *e) {
|
void TopBar::resizeEvent(QResizeEvent *e) {
|
||||||
const auto progress = (e->size().height() - minimumHeight())
|
const auto progress = (e->size().height() - minimumHeight())
|
||||||
/ float64(maximumHeight() - minimumHeight());
|
/ float64(maximumHeight() - minimumHeight());
|
||||||
@ -443,18 +476,7 @@ void TopBar::paintEvent(QPaintEvent *e) {
|
|||||||
gradient.setColorAt(.6, st::premiumButtonBg2->c);
|
gradient.setColorAt(.6, st::premiumButtonBg2->c);
|
||||||
gradient.setColorAt(1., st::premiumButtonBg3->c);
|
gradient.setColorAt(1., st::premiumButtonBg3->c);
|
||||||
|
|
||||||
PainterHighQualityEnabler hq(p);
|
TopBarAbstract::paintEdges(p, gradient);
|
||||||
if (_roundEdges) {
|
|
||||||
const auto radius = st::boxRadius;
|
|
||||||
p.setPen(Qt::NoPen);
|
|
||||||
p.setBrush(gradient);
|
|
||||||
p.drawRoundedRect(
|
|
||||||
r + QMargins{ 0, 0, 0, radius + 1 },
|
|
||||||
radius,
|
|
||||||
radius);
|
|
||||||
} else {
|
|
||||||
p.fillRect(r, gradient);
|
|
||||||
}
|
|
||||||
|
|
||||||
p.setOpacity(_progress.body);
|
p.setOpacity(_progress.body);
|
||||||
p.translate(_starRect.center());
|
p.translate(_starRect.center());
|
||||||
|
Loading…
Reference in New Issue
Block a user