Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
label_taskmenu.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
6
7#include <QtDesigner/abstractformwindow.h>
8
9#include <QtWidgets/qstyle.h>
10#include <QtWidgets/qstyleoption.h>
11
12#include <QtGui/qaction.h>
13#include <QtGui/qtextdocument.h>
14
16
17using namespace Qt::StringLiterals;
18
19static constexpr auto textPropertyC = "text"_L1;
20
21namespace qdesigner_internal {
22
23// -------- LabelTaskMenuInlineEditor
25{
26public:
27 LabelTaskMenuInlineEditor(QLabel *button, QObject *parent);
28
29protected:
30 QRect editRectangle() const override;
31};
32
34 TaskMenuInlineEditor(w, ValidationRichText, textPropertyC, parent)
35{
36}
37
39{
40 QStyleOptionButton opt;
41 opt.initFrom(widget());
42 return opt.rect;
43}
44
45// --------------- LabelTaskMenu
46
47LabelTaskMenu::LabelTaskMenu(QLabel *label, QObject *parent)
48 : QDesignerTaskMenu(label, parent),
49 m_label(label),
50 m_editRichTextAction(new QAction(tr("Change rich text..."), this)),
51 m_editPlainTextAction(new QAction(tr("Change plain text..."), this))
52{
54 connect(m_editPlainTextAction, &QAction::triggered, editor, &LabelTaskMenuInlineEditor::editText);
55 m_taskActions.append(m_editPlainTextAction);
56
57 connect(m_editRichTextAction, &QAction::triggered, this, &LabelTaskMenu::editRichText);
58 m_taskActions.append(m_editRichTextAction);
59
60 QAction *sep = new QAction(this);
61 sep->setSeparator(true);
62 m_taskActions.append(sep);
63}
64
66{
67 if (m_label->textFormat () == Qt::PlainText) return m_editPlainTextAction;
68 return Qt::mightBeRichText(m_label->text()) ? m_editRichTextAction : m_editPlainTextAction;
69}
70
72{
73 return m_taskActions + QDesignerTaskMenu::taskActions();
74}
75
76void LabelTaskMenu::editRichText()
77{
78 changeTextProperty(textPropertyC, QString(), MultiSelectionMode, m_label->textFormat());
79}
80
81}
82QT_END_NAMESPACE
LabelTaskMenuInlineEditor(QLabel *button, QObject *parent)
QList< QAction * > taskActions() const override
QAction * preferredEditAction() const override
static constexpr auto textPropertyC
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.