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);
}
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<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) {
textUpdated();
std::move(
text
@ -228,10 +236,12 @@ FlatLabel::FlatLabel(
FlatLabel::FlatLabel(
QWidget *parent,
rpl::producer<TextWithEntities> &&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<PopupMenu>(this);
_contextMenu = base::make_unique_q<PopupMenu>(this, _stMenu);
if (fullSelection && !_contextCopyText.isEmpty()) {
_contextMenu->addAction(

View file

@ -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<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<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 setTextColorOverride(std::optional<QColor> color);
@ -194,6 +200,7 @@ private:
Text::String _text;
const style::FlatLabel &_st;
const style::PopupMenu &_stMenu;
std::optional<QColor> _textColorOverride;
float64 _opacity = 1.;