|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Designer of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "newactiondialog_p.h" |
|
43 #include "ui_newactiondialog.h" |
|
44 #include "richtexteditor_p.h" |
|
45 #include "actioneditor_p.h" |
|
46 #include "formwindowbase_p.h" |
|
47 #include "qdesigner_utils_p.h" |
|
48 #include "iconloader_p.h" |
|
49 |
|
50 #include <QtDesigner/abstractformwindow.h> |
|
51 #include <QtDesigner/abstractformeditor.h> |
|
52 |
|
53 #include <QtGui/QPushButton> |
|
54 #include <QtCore/QRegExp> |
|
55 |
|
56 QT_BEGIN_NAMESPACE |
|
57 |
|
58 namespace qdesigner_internal { |
|
59 // -------------------- ActionData |
|
60 |
|
61 ActionData::ActionData() : |
|
62 checkable(false) |
|
63 { |
|
64 } |
|
65 |
|
66 // Returns a combination of ChangeMask flags |
|
67 unsigned ActionData::compare(const ActionData &rhs) const |
|
68 { |
|
69 unsigned rc = 0; |
|
70 if (text != rhs.text) |
|
71 rc |= TextChanged; |
|
72 if (name != rhs.name) |
|
73 rc |= NameChanged; |
|
74 if (toolTip != rhs.toolTip) |
|
75 rc |= ToolTipChanged ; |
|
76 if (icon != rhs.icon) |
|
77 rc |= IconChanged ; |
|
78 if (checkable != rhs.checkable) |
|
79 rc |= CheckableChanged; |
|
80 if (keysequence != rhs.keysequence) |
|
81 rc |= KeysequenceChanged ; |
|
82 return rc; |
|
83 } |
|
84 |
|
85 // -------------------- NewActionDialog |
|
86 NewActionDialog::NewActionDialog(ActionEditor *parent) : |
|
87 QDialog(parent, Qt::Sheet), |
|
88 m_ui(new Ui::NewActionDialog), |
|
89 m_actionEditor(parent) |
|
90 { |
|
91 m_ui->setupUi(this); |
|
92 |
|
93 m_ui->tooltipEditor->setTextPropertyValidationMode(ValidationRichText); |
|
94 connect(m_ui->toolTipToolButton, SIGNAL(clicked()), this, SLOT(slotEditToolTip())); |
|
95 |
|
96 m_ui->keysequenceResetToolButton->setIcon(createIconSet(QLatin1String("resetproperty.png"))); |
|
97 connect(m_ui->keysequenceResetToolButton, SIGNAL(clicked()), this, SLOT(slotResetKeySequence())); |
|
98 |
|
99 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
|
100 m_ui->editActionText->setFocus(); |
|
101 m_auto_update_object_name = true; |
|
102 updateButtons(); |
|
103 |
|
104 QDesignerFormWindowInterface *form = parent->formWindow(); |
|
105 m_ui->iconSelector->setFormEditor(form->core()); |
|
106 FormWindowBase *formBase = qobject_cast<FormWindowBase *>(form); |
|
107 |
|
108 if (formBase) { |
|
109 m_ui->iconSelector->setPixmapCache(formBase->pixmapCache()); |
|
110 m_ui->iconSelector->setIconCache(formBase->iconCache()); |
|
111 } |
|
112 } |
|
113 |
|
114 NewActionDialog::~NewActionDialog() |
|
115 { |
|
116 delete m_ui; |
|
117 } |
|
118 |
|
119 QString NewActionDialog::actionText() const |
|
120 { |
|
121 return m_ui->editActionText->text(); |
|
122 } |
|
123 |
|
124 QString NewActionDialog::actionName() const |
|
125 { |
|
126 return m_ui->editObjectName->text(); |
|
127 } |
|
128 |
|
129 ActionData NewActionDialog::actionData() const |
|
130 { |
|
131 ActionData rc; |
|
132 rc.text = actionText(); |
|
133 rc.name = actionName(); |
|
134 rc.toolTip = m_ui->tooltipEditor->text(); |
|
135 rc.icon = m_ui->iconSelector->icon(); |
|
136 rc.checkable = m_ui->checkableCheckBox->checkState() == Qt::Checked; |
|
137 rc.keysequence = PropertySheetKeySequenceValue(m_ui->keySequenceEdit->keySequence()); |
|
138 return rc; |
|
139 } |
|
140 |
|
141 void NewActionDialog::setActionData(const ActionData &d) |
|
142 { |
|
143 m_ui->editActionText->setText(d.text); |
|
144 m_ui->editObjectName->setText(d.name); |
|
145 m_ui->iconSelector->setIcon(d.icon); |
|
146 m_ui->tooltipEditor->setText(d.toolTip); |
|
147 m_ui->keySequenceEdit->setKeySequence(d.keysequence.value()); |
|
148 m_ui->checkableCheckBox->setCheckState(d.checkable ? Qt::Checked : Qt::Unchecked); |
|
149 |
|
150 m_auto_update_object_name = false; |
|
151 updateButtons(); |
|
152 } |
|
153 |
|
154 void NewActionDialog::on_editActionText_textEdited(const QString &text) |
|
155 { |
|
156 if (text.isEmpty()) |
|
157 m_auto_update_object_name = true; |
|
158 |
|
159 if (m_auto_update_object_name) |
|
160 m_ui->editObjectName->setText(ActionEditor::actionTextToName(text)); |
|
161 |
|
162 updateButtons(); |
|
163 } |
|
164 |
|
165 void NewActionDialog::on_editObjectName_textEdited(const QString&) |
|
166 { |
|
167 updateButtons(); |
|
168 m_auto_update_object_name = false; |
|
169 } |
|
170 |
|
171 void NewActionDialog::slotEditToolTip() |
|
172 { |
|
173 const QString oldToolTip = m_ui->tooltipEditor->text(); |
|
174 RichTextEditorDialog richTextDialog(m_actionEditor->core(), this); |
|
175 richTextDialog.setText(oldToolTip); |
|
176 if (richTextDialog.showDialog() == QDialog::Rejected) |
|
177 return; |
|
178 const QString newToolTip = richTextDialog.text(); |
|
179 if (newToolTip != oldToolTip) |
|
180 m_ui->tooltipEditor->setText(newToolTip); |
|
181 } |
|
182 |
|
183 void NewActionDialog::slotResetKeySequence() |
|
184 { |
|
185 m_ui->keySequenceEdit->setKeySequence(QKeySequence()); |
|
186 m_ui->keySequenceEdit->setFocus(Qt::MouseFocusReason); |
|
187 } |
|
188 |
|
189 void NewActionDialog::updateButtons() |
|
190 { |
|
191 QPushButton *okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok); |
|
192 okButton->setEnabled(!actionText().isEmpty() && !actionName().isEmpty()); |
|
193 } |
|
194 |
|
195 } // namespace qdesigner_internal |
|
196 |
|
197 QT_END_NAMESPACE |