From 1ba9270234db8cbe8badbe6f6fbaea0a5869e28d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 1 Mar 2022 08:35:05 +0300 Subject: [PATCH] Added ability to provide custom style of context menu to flat labels. --- ui/widgets/labels.cpp | 26 ++++++++++++++++++-------- ui/widgets/labels.h | 15 +++++++++++---- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/ui/widgets/labels.cpp b/ui/widgets/labels.cpp index bb3ca84..99f2ddf 100644 --- a/ui/widgets/labels.cpp +++ b/ui/widgets/labels.cpp @@ -191,20 +191,26 @@ void LabelSimple::paintEvent(QPaintEvent *e) { p.drawTextLeft(0, 0, width(), _text, _textWidth); } -FlatLabel::FlatLabel(QWidget *parent, const style::FlatLabel &st) +FlatLabel::FlatLabel( + QWidget *parent, + const style::FlatLabel &st, + const style::PopupMenu &stMenu) : RpWidget(parent) , _text(st.minWidth ? st.minWidth : QFIXED_MAX) -, _st(st) { +, _st(st) +, _stMenu(stMenu) { init(); } FlatLabel::FlatLabel( QWidget *parent, const QString &text, - const style::FlatLabel &st) + const style::FlatLabel &st, + const style::PopupMenu &stMenu) : RpWidget(parent) , _text(st.minWidth ? st.minWidth : QFIXED_MAX) -, _st(st) { +, _st(st) +, _stMenu(stMenu) { setText(text); init(); } @@ -212,10 +218,12 @@ FlatLabel::FlatLabel( FlatLabel::FlatLabel( QWidget *parent, rpl::producer &&text, - const style::FlatLabel &st) + const style::FlatLabel &st, + const style::PopupMenu &stMenu) : RpWidget(parent) , _text(st.minWidth ? st.minWidth : QFIXED_MAX) -, _st(st) { +, _st(st) +, _stMenu(stMenu) { textUpdated(); std::move( text @@ -228,10 +236,12 @@ FlatLabel::FlatLabel( FlatLabel::FlatLabel( QWidget *parent, rpl::producer &&text, - const style::FlatLabel &st) + const style::FlatLabel &st, + const style::PopupMenu &stMenu) : RpWidget(parent) , _text(st.minWidth ? st.minWidth : QFIXED_MAX) , _st(st) +, _stMenu(stMenu) , _touchSelectTimer([=] { touchSelect(); }) { textUpdated(); std::move( @@ -629,7 +639,7 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) const auto fullSelection = _selectable && _text.isFullSelection(_selection); - _contextMenu = base::make_unique_q(this); + _contextMenu = base::make_unique_q(this, _stMenu); if (fullSelection && !_contextCopyText.isEmpty()) { _contextMenu->addAction( diff --git a/ui/widgets/labels.h b/ui/widgets/labels.h index 2821f66..a63db89 100644 --- a/ui/widgets/labels.h +++ b/ui/widgets/labels.h @@ -96,21 +96,27 @@ private: class FlatLabel : public RpWidget, public ClickHandlerHost { public: - FlatLabel(QWidget *parent, const style::FlatLabel &st = st::defaultFlatLabel); + FlatLabel( + QWidget *parent, + const style::FlatLabel &st = st::defaultFlatLabel, + const style::PopupMenu &stMenu = st::defaultPopupMenu); FlatLabel( QWidget *parent, const QString &text, - const style::FlatLabel &st = st::defaultFlatLabel); + const style::FlatLabel &st = st::defaultFlatLabel, + const style::PopupMenu &stMenu = st::defaultPopupMenu); FlatLabel( QWidget *parent, rpl::producer &&text, - const style::FlatLabel &st = st::defaultFlatLabel); + const style::FlatLabel &st = st::defaultFlatLabel, + const style::PopupMenu &stMenu = st::defaultPopupMenu); FlatLabel( QWidget *parent, rpl::producer &&text, - const style::FlatLabel &st = st::defaultFlatLabel); + const style::FlatLabel &st = st::defaultFlatLabel, + const style::PopupMenu &stMenu = st::defaultPopupMenu); void setOpacity(float64 o); void setTextColorOverride(std::optional color); @@ -194,6 +200,7 @@ private: Text::String _text; const style::FlatLabel &_st; + const style::PopupMenu &_stMenu; std::optional _textColorOverride; float64 _opacity = 1.;