From b802516ca73c9b20103b5e98d940490dfcc7fea8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 2 Jun 2022 17:25:56 +0400 Subject: [PATCH] Allow DividerLabel with only top / bottom part. --- ui/widgets/box_content_divider.cpp | 15 +++++++++++---- ui/widgets/box_content_divider.h | 9 +++++---- ui/widgets/labels.cpp | 11 +++++++++++ ui/widgets/labels.h | 9 ++++++--- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ui/widgets/box_content_divider.cpp b/ui/widgets/box_content_divider.cpp index abb4acf..dcd1b4d 100644 --- a/ui/widgets/box_content_divider.cpp +++ b/ui/widgets/box_content_divider.cpp @@ -25,17 +25,24 @@ BoxContentDivider::BoxContentDivider(QWidget *parent, int height) BoxContentDivider::BoxContentDivider( QWidget *parent, int height, - const style::color &bg) + const style::color &bg, + RectParts parts) : RpWidget(parent) -, _bg(bg) { +, _bg(bg) +, _parts(parts) { resize(width(), height); } void BoxContentDivider::paintEvent(QPaintEvent *e) { QPainter p(this); + p.fillRect(e->rect(), _bg); - paintTop(p); - paintBottom(p); + if (_parts & RectPart::Top) { + paintTop(p); + } + if (_parts & RectPart::Bottom) { + paintBottom(p); + } } void BoxContentDivider::paintTop(QPainter &p) { diff --git a/ui/widgets/box_content_divider.h b/ui/widgets/box_content_divider.h index d46d09c..242d81d 100644 --- a/ui/widgets/box_content_divider.h +++ b/ui/widgets/box_content_divider.h @@ -7,19 +7,19 @@ #pragma once #include "ui/rp_widget.h" +#include "ui/rect_part.h" namespace Ui { class BoxContentDivider : public Ui::RpWidget { public: BoxContentDivider(QWidget *parent); - BoxContentDivider( - QWidget *parent, - int height); + BoxContentDivider(QWidget *parent, int height); BoxContentDivider( QWidget *parent, int height, - const style::color &bg); + const style::color &bg, + RectParts parts = RectPart::Top | RectPart::Bottom); [[nodiscard]] const style::color &color() const; @@ -31,6 +31,7 @@ protected: private: const style::color &_bg; + const RectParts _parts; }; diff --git a/ui/widgets/labels.cpp b/ui/widgets/labels.cpp index 99f2ddf..08d696e 100644 --- a/ui/widgets/labels.cpp +++ b/ui/widgets/labels.cpp @@ -14,6 +14,8 @@ #include "ui/basic_click_handlers.h" // UrlClickHandler #include "ui/inactive_press.h" #include "base/qt/qt_common_adapters.h" +#include "styles/style_layers.h" +#include "styles/palette.h" #include #include @@ -903,6 +905,15 @@ void FlatLabel::paintEvent(QPaintEvent *e) { } } +DividerLabel::DividerLabel( + QWidget *parent, + object_ptr &&child, + const style::margins &padding, + RectParts parts) +: PaddingWrap(parent, std::move(child), padding) +, _background(this, st::boxDividerHeight, st::boxDividerBg, parts) { +} + int DividerLabel::naturalWidth() const { return -1; } diff --git a/ui/widgets/labels.h b/ui/widgets/labels.h index a63db89..294101e 100644 --- a/ui/widgets/labels.h +++ b/ui/widgets/labels.h @@ -247,7 +247,11 @@ private: class DividerLabel : public PaddingWrap { public: - using PaddingWrap::PaddingWrap; + DividerLabel( + QWidget *parent, + object_ptr &&child, + const style::margins &padding, + RectParts parts = RectPart::Top | RectPart::Bottom); int naturalWidth() const override; @@ -255,8 +259,7 @@ protected: void resizeEvent(QResizeEvent *e) override; private: - object_ptr _background - = object_ptr(this); + object_ptr _background; };