Added ability to provide custom style of context menu to flat labels.

This commit is contained in:
23rd 2022-03-01 08:35:05 +03:00
parent 5f3e04a319
commit 1ba9270234
2 changed files with 29 additions and 12 deletions

View file

@ -191,20 +191,26 @@ void LabelSimple::paintEvent(QPaintEvent *e) {
p.drawTextLeft(0, 0, width(), _text, _textWidth); 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) : RpWidget(parent)
, _text(st.minWidth ? st.minWidth : QFIXED_MAX) , _text(st.minWidth ? st.minWidth : QFIXED_MAX)
, _st(st) { , _st(st)
, _stMenu(stMenu) {
init(); init();
} }
FlatLabel::FlatLabel( FlatLabel::FlatLabel(
QWidget *parent, QWidget *parent,
const QString &text, const QString &text,
const style::FlatLabel &st) const style::FlatLabel &st,
const style::PopupMenu &stMenu)
: RpWidget(parent) : RpWidget(parent)
, _text(st.minWidth ? st.minWidth : QFIXED_MAX) , _text(st.minWidth ? st.minWidth : QFIXED_MAX)
, _st(st) { , _st(st)
, _stMenu(stMenu) {
setText(text); setText(text);
init(); init();
} }
@ -212,10 +218,12 @@ FlatLabel::FlatLabel(
FlatLabel::FlatLabel( FlatLabel::FlatLabel(
QWidget *parent, QWidget *parent,
rpl::producer<QString> &&text, rpl::producer<QString> &&text,
const style::FlatLabel &st) const style::FlatLabel &st,
const style::PopupMenu &stMenu)
: RpWidget(parent) : RpWidget(parent)
, _text(st.minWidth ? st.minWidth : QFIXED_MAX) , _text(st.minWidth ? st.minWidth : QFIXED_MAX)
, _st(st) { , _st(st)
, _stMenu(stMenu) {
textUpdated(); textUpdated();
std::move( std::move(
text text
@ -228,10 +236,12 @@ FlatLabel::FlatLabel(
FlatLabel::FlatLabel( FlatLabel::FlatLabel(
QWidget *parent, QWidget *parent,
rpl::producer<TextWithEntities> &&text, rpl::producer<TextWithEntities> &&text,
const style::FlatLabel &st) const style::FlatLabel &st,
const style::PopupMenu &stMenu)
: RpWidget(parent) : RpWidget(parent)
, _text(st.minWidth ? st.minWidth : QFIXED_MAX) , _text(st.minWidth ? st.minWidth : QFIXED_MAX)
, _st(st) , _st(st)
, _stMenu(stMenu)
, _touchSelectTimer([=] { touchSelect(); }) { , _touchSelectTimer([=] { touchSelect(); }) {
textUpdated(); textUpdated();
std::move( std::move(
@ -629,7 +639,7 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
const auto fullSelection = _selectable const auto fullSelection = _selectable
&& _text.isFullSelection(_selection); && _text.isFullSelection(_selection);
_contextMenu = base::make_unique_q<PopupMenu>(this); _contextMenu = base::make_unique_q<PopupMenu>(this, _stMenu);
if (fullSelection && !_contextCopyText.isEmpty()) { if (fullSelection && !_contextCopyText.isEmpty()) {
_contextMenu->addAction( _contextMenu->addAction(

View file

@ -96,21 +96,27 @@ private:
class FlatLabel : public RpWidget, public ClickHandlerHost { class FlatLabel : public RpWidget, public ClickHandlerHost {
public: 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( FlatLabel(
QWidget *parent, QWidget *parent,
const QString &text, const QString &text,
const style::FlatLabel &st = st::defaultFlatLabel); const style::FlatLabel &st = st::defaultFlatLabel,
const style::PopupMenu &stMenu = st::defaultPopupMenu);
FlatLabel( FlatLabel(
QWidget *parent, QWidget *parent,
rpl::producer<QString> &&text, rpl::producer<QString> &&text,
const style::FlatLabel &st = st::defaultFlatLabel); const style::FlatLabel &st = st::defaultFlatLabel,
const style::PopupMenu &stMenu = st::defaultPopupMenu);
FlatLabel( FlatLabel(
QWidget *parent, QWidget *parent,
rpl::producer<TextWithEntities> &&text, rpl::producer<TextWithEntities> &&text,
const style::FlatLabel &st = st::defaultFlatLabel); const style::FlatLabel &st = st::defaultFlatLabel,
const style::PopupMenu &stMenu = st::defaultPopupMenu);
void setOpacity(float64 o); void setOpacity(float64 o);
void setTextColorOverride(std::optional<QColor> color); void setTextColorOverride(std::optional<QColor> color);
@ -194,6 +200,7 @@ private:
Text::String _text; Text::String _text;
const style::FlatLabel &_st; const style::FlatLabel &_st;
const style::PopupMenu &_stMenu;
std::optional<QColor> _textColorOverride; std::optional<QColor> _textColorOverride;
float64 _opacity = 1.; float64 _opacity = 1.;