Allow DividerLabel with only top / bottom part.

This commit is contained in:
John Preston 2022-06-02 17:25:56 +04:00
parent b9a702f6e0
commit b802516ca7
4 changed files with 33 additions and 11 deletions

View file

@ -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);
if (_parts & RectPart::Top) {
paintTop(p);
}
if (_parts & RectPart::Bottom) {
paintBottom(p);
}
}
void BoxContentDivider::paintTop(QPainter &p) {

View file

@ -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;
};

View file

@ -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 <QtWidgets/QApplication>
#include <QtGui/QClipboard>
@ -903,6 +905,15 @@ void FlatLabel::paintEvent(QPaintEvent *e) {
}
}
DividerLabel::DividerLabel(
QWidget *parent,
object_ptr<FlatLabel> &&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;
}

View file

@ -247,7 +247,11 @@ private:
class DividerLabel : public PaddingWrap<FlatLabel> {
public:
using PaddingWrap::PaddingWrap;
DividerLabel(
QWidget *parent,
object_ptr<FlatLabel> &&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<BoxContentDivider> _background
= object_ptr<BoxContentDivider>(this);
object_ptr<BoxContentDivider> _background;
};