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// Qt-Security score:significant reason:default
4
7
8#include <QtDesigner/abstractformwindow.h>
9
10#include <QtWidgets/qstyle.h>
11#include <QtWidgets/qstyleoption.h>
12
13#include <QtGui/qaction.h>
14#include <QtGui/qtextdocument.h>
15
17
18using namespace Qt::StringLiterals;
19
20static constexpr auto textPropertyC = "text"_L1;
21
22namespace qdesigner_internal {
23
24// -------- LabelTaskMenuInlineEditor
26{
27public:
28 LabelTaskMenuInlineEditor(QLabel *button, QObject *parent);
29
30protected:
31 QRect editRectangle() const override;
32};
33
35 TaskMenuInlineEditor(w, ValidationRichText, textPropertyC, parent)
36{
37}
38
40{
41 QStyleOptionButton opt;
42 opt.initFrom(widget());
43 return opt.rect;
44}
45
46// --------------- LabelTaskMenu
47
48LabelTaskMenu::LabelTaskMenu(QLabel *label, QObject *parent)
49 : QDesignerTaskMenu(label, parent),
50 m_label(label),
51 m_editRichTextAction(new QAction(tr("Change rich text..."), this)),
52 m_editPlainTextAction(new QAction(tr("Change plain text..."), this))
53{
55 connect(m_editPlainTextAction, &QAction::triggered, editor, &LabelTaskMenuInlineEditor::editText);
56 m_taskActions.append(m_editPlainTextAction);
57
58 connect(m_editRichTextAction, &QAction::triggered, this, &LabelTaskMenu::editRichText);
59 m_taskActions.append(m_editRichTextAction);
60
61 QAction *sep = new QAction(this);
62 sep->setSeparator(true);
63 m_taskActions.append(sep);
64}
65
67{
68 if (m_label->textFormat () == Qt::PlainText) return m_editPlainTextAction;
69 return Qt::mightBeRichText(m_label->text()) ? m_editRichTextAction : m_editPlainTextAction;
70}
71
73{
74 return m_taskActions + QDesignerTaskMenu::taskActions();
75}
76
77void LabelTaskMenu::editRichText()
78{
79 changeTextProperty(textPropertyC, QString(), MultiSelectionMode, m_label->textFormat());
80}
81
82}
83QT_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.