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 "newactiondialog_p.h"
30#include "ui_newactiondialog.h"
31#include "richtexteditor_p.h"
32#include "actioneditor_p.h"
33#include "formwindowbase_p.h"
34#include "qdesigner_utils_p.h"
35#include "iconloader_p.h"
36
37#include <QtDesigner/abstractformwindow.h>
38#include <QtDesigner/abstractformeditor.h>
39
40#include <QtWidgets/qpushbutton.h>
41
42QT_BEGIN_NAMESPACE
43
44namespace qdesigner_internal {
45// Returns a combination of ChangeMask flags
46unsigned ActionData::compare(const ActionData &rhs) const
47{
48 unsigned rc = 0;
49 if (text != rhs.text)
50 rc |= TextChanged;
51 if (name != rhs.name)
52 rc |= NameChanged;
53 if (toolTip != rhs.toolTip)
54 rc |= ToolTipChanged ;
55 if (icon != rhs.icon)
56 rc |= IconChanged ;
57 if (checkable != rhs.checkable)
58 rc |= CheckableChanged;
59 if (keysequence != rhs.keysequence)
60 rc |= KeysequenceChanged ;
61 return rc;
62}
63
64// -------------------- NewActionDialog
65NewActionDialog::NewActionDialog(ActionEditor *parent) :
66 QDialog(parent, Qt::Sheet),
67 m_ui(new Ui::NewActionDialog),
68 m_actionEditor(parent),
69 m_autoUpdateObjectName(true)
70{
71 m_ui->setupUi(this);
72
73 m_ui->tooltipEditor->setTextPropertyValidationMode(ValidationRichText);
74 connect(sender: m_ui->toolTipToolButton, signal: &QAbstractButton::clicked, receiver: this, slot: &NewActionDialog::slotEditToolTip);
75
76 m_ui->keysequenceResetToolButton->setIcon(createIconSet(QStringLiteral("resetproperty.png")));
77 connect(sender: m_ui->keysequenceResetToolButton, signal: &QAbstractButton::clicked,
78 receiver: this, slot: &NewActionDialog::slotResetKeySequence);
79
80 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
81 focusText();
82 updateButtons();
83
84 QDesignerFormWindowInterface *form = parent->formWindow();
85 m_ui->iconSelector->setFormEditor(form->core());
86 FormWindowBase *formBase = qobject_cast<FormWindowBase *>(object: form);
87
88 if (formBase) {
89 m_ui->iconSelector->setPixmapCache(formBase->pixmapCache());
90 m_ui->iconSelector->setIconCache(formBase->iconCache());
91 }
92}
93
94NewActionDialog::~NewActionDialog()
95{
96 delete m_ui;
97}
98
99void NewActionDialog::focusName()
100{
101 m_ui->editObjectName->setFocus();
102}
103
104void NewActionDialog::focusText()
105{
106 m_ui->editActionText->setFocus();
107}
108
109void NewActionDialog::focusTooltip()
110{
111 m_ui->tooltipEditor->setFocus();
112}
113
114void NewActionDialog::focusShortcut()
115{
116 m_ui->keySequenceEdit->setFocus();
117}
118
119void NewActionDialog::focusCheckable()
120{
121 m_ui->checkableCheckBox->setFocus();
122}
123
124QString NewActionDialog::actionText() const
125{
126 return m_ui->editActionText->text();
127}
128
129QString NewActionDialog::actionName() const
130{
131 return m_ui->editObjectName->text();
132}
133
134ActionData NewActionDialog::actionData() const
135{
136 ActionData rc;
137 rc.text = actionText();
138 rc.name = actionName();
139 rc.toolTip = m_ui->tooltipEditor->text();
140 rc.icon = m_ui->iconSelector->icon();
141 rc.icon.setTheme(m_ui->iconThemeEditor->theme());
142 rc.checkable = m_ui->checkableCheckBox->checkState() == Qt::Checked;
143 rc.keysequence = PropertySheetKeySequenceValue(m_ui->keySequenceEdit->keySequence());
144 return rc;
145}
146
147void NewActionDialog::setActionData(const ActionData &d)
148{
149 m_ui->editActionText->setText(d.text);
150 m_ui->editObjectName->setText(d.name);
151 m_ui->iconSelector->setIcon(d.icon.unthemed());
152 m_ui->iconThemeEditor->setTheme(d.icon.theme());
153 m_ui->tooltipEditor->setText(d.toolTip);
154 m_ui->keySequenceEdit->setKeySequence(d.keysequence.value());
155 m_ui->checkableCheckBox->setCheckState(d.checkable ? Qt::Checked : Qt::Unchecked);
156
157 // Suppress updating of the object name from the text for existing actions.
158 m_autoUpdateObjectName = d.name.isEmpty();
159 updateButtons();
160}
161
162void NewActionDialog::on_editActionText_textEdited(const QString &text)
163{
164 if (m_autoUpdateObjectName)
165 m_ui->editObjectName->setText(ActionEditor::actionTextToName(text));
166
167 updateButtons();
168}
169
170void NewActionDialog::on_editObjectName_textEdited(const QString&)
171{
172 updateButtons();
173 m_autoUpdateObjectName = false;
174}
175
176void NewActionDialog::slotEditToolTip()
177{
178 const QString oldToolTip = m_ui->tooltipEditor->text();
179 RichTextEditorDialog richTextDialog(m_actionEditor->core(), this);
180 richTextDialog.setText(oldToolTip);
181 if (richTextDialog.showDialog() == QDialog::Rejected)
182 return;
183 const QString newToolTip = richTextDialog.text();
184 if (newToolTip != oldToolTip)
185 m_ui->tooltipEditor->setText(newToolTip);
186}
187
188void NewActionDialog::slotResetKeySequence()
189{
190 m_ui->keySequenceEdit->setKeySequence(QKeySequence());
191 m_ui->keySequenceEdit->setFocus(Qt::MouseFocusReason);
192}
193
194void NewActionDialog::updateButtons()
195{
196 QPushButton *okButton = m_ui->buttonBox->button(which: QDialogButtonBox::Ok);
197 okButton->setEnabled(!actionText().isEmpty() && !actionName().isEmpty());
198}
199
200} // namespace qdesigner_internal
201
202QT_END_NAMESPACE
203

source code of qttools/src/designer/src/lib/shared/newactiondialog.cpp