1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include "label_taskmenu.h" |
30 | #include "inplace_editor.h" |
31 | |
32 | #include <QtDesigner/abstractformwindow.h> |
33 | |
34 | #include <QtWidgets/qaction.h> |
35 | #include <QtWidgets/qstyle.h> |
36 | #include <QtWidgets/qstyleoption.h> |
37 | #include <QtGui/qtextdocument.h> |
38 | |
39 | static const char *textPropertyC = "text" ; |
40 | |
41 | QT_BEGIN_NAMESPACE |
42 | |
43 | namespace qdesigner_internal { |
44 | |
45 | // -------- LabelTaskMenuInlineEditor |
46 | class : public TaskMenuInlineEditor |
47 | { |
48 | public: |
49 | LabelTaskMenuInlineEditor(QLabel *button, QObject *parent); |
50 | |
51 | protected: |
52 | QRect editRectangle() const override; |
53 | }; |
54 | |
55 | LabelTaskMenuInlineEditor::(QLabel *w, QObject *parent) : |
56 | TaskMenuInlineEditor(w, ValidationRichText, QLatin1String(textPropertyC), parent) |
57 | { |
58 | } |
59 | |
60 | QRect LabelTaskMenuInlineEditor::() const |
61 | { |
62 | QStyleOptionButton opt; |
63 | opt.init(w: widget()); |
64 | return opt.rect; |
65 | } |
66 | |
67 | // --------------- LabelTaskMenu |
68 | |
69 | LabelTaskMenu::(QLabel *label, QObject *parent) |
70 | : QDesignerTaskMenu(label, parent), |
71 | m_label(label), |
72 | m_editRichTextAction(new QAction(tr(s: "Change rich text..." ), this)), |
73 | m_editPlainTextAction(new QAction(tr(s: "Change plain text..." ), this)) |
74 | { |
75 | LabelTaskMenuInlineEditor *editor = new LabelTaskMenuInlineEditor(label, this); |
76 | connect(sender: m_editPlainTextAction, signal: &QAction::triggered, receiver: editor, slot: &LabelTaskMenuInlineEditor::editText); |
77 | m_taskActions.append(t: m_editPlainTextAction); |
78 | |
79 | connect(sender: m_editRichTextAction, signal: &QAction::triggered, receiver: this, slot: &LabelTaskMenu::editRichText); |
80 | m_taskActions.append(t: m_editRichTextAction); |
81 | |
82 | QAction *sep = new QAction(this); |
83 | sep->setSeparator(true); |
84 | m_taskActions.append(t: sep); |
85 | } |
86 | |
87 | QAction *LabelTaskMenu::() const |
88 | { |
89 | if (m_label->textFormat () == Qt::PlainText) return m_editPlainTextAction; |
90 | return Qt::mightBeRichText(m_label->text()) ? m_editRichTextAction : m_editPlainTextAction; |
91 | } |
92 | |
93 | QList<QAction*> LabelTaskMenu::() const |
94 | { |
95 | return m_taskActions + QDesignerTaskMenu::taskActions(); |
96 | } |
97 | |
98 | void LabelTaskMenu::() |
99 | { |
100 | changeTextProperty(propertyName: QLatin1String(textPropertyC), windowTitle: QString(), pm: MultiSelectionMode, desiredFormat: m_label->textFormat()); |
101 | } |
102 | |
103 | } |
104 | QT_END_NAMESPACE |
105 | |