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
embeddedoptionspage.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
9
10#include <deviceprofile_p.h>
11#include <iconloader_p.h>
12#include <shared_settings_p.h>
13#include <abstractdialoggui_p.h>
14#include <formwindowbase_p.h>
15
16
17// SDK
18#include <QtDesigner/abstractformeditor.h>
19#include <QtDesigner/abstractformwindowmanager.h>
20
21#include <QtWidgets/qlabel.h>
22#include <QtWidgets/qboxlayout.h>
23#include <QtWidgets/qapplication.h>
24#include <QtWidgets/qcombobox.h>
25#include <QtWidgets/qtoolbutton.h>
26#include <QtWidgets/qmessagebox.h>
27#include <QtWidgets/qlabel.h>
28#include <QtWidgets/qgroupbox.h>
29
30#include <QtCore/qset.h>
31#include <QtCore/qlist.h>
32
33#include <algorithm>
34
35QT_BEGIN_NAMESPACE
36
37using namespace Qt::StringLiterals;
38
39namespace qdesigner_internal {
40
42
44
45// Sort by name. Used by template, do not make it static!
46bool deviceProfileLessThan(const DeviceProfile &d1, const DeviceProfile &d2)
47{
48 return d1.name().toLower() < d2.name().toLower();
49}
50
51static bool ask(QWidget *parent,
52 QDesignerDialogGuiInterface *dlgui,
53 const QString &title,
54 const QString &what)
55{
56 return dlgui->message(parent, QDesignerDialogGuiInterface::OtherMessage,
57 QMessageBox::Question, title, what,
58 QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes;
59}
60
61// ------------ EmbeddedOptionsControlPrivate
64public:
67
68 bool isDirty() const { return m_dirty; }
69
72 void slotAdd();
73 void slotEdit();
74 void slotDelete();
76
77private:
78 QStringList existingProfileNames() const;
79 void sortAndPopulateProfileCombo();
80 void updateState();
81 void updateDescriptionLabel();
82
83 QDesignerFormEditorInterface *m_core;
84 QComboBox *m_profileCombo;
85 QToolButton *m_addButton;
86 QToolButton *m_editButton;
87 QToolButton *m_deleteButton;
88 QLabel *m_descriptionLabel;
89
90 DeviceProfileList m_sortedProfiles;
91 EmbeddedOptionsControl *m_q = nullptr;
92 QSet<QString> m_usedProfiles;
93 bool m_dirty = false;
94};
95
96EmbeddedOptionsControlPrivate::EmbeddedOptionsControlPrivate(QDesignerFormEditorInterface *core) :
97 m_core(core),
103{
105 // Determine used profiles to lock them
107 if (const int fwCount = fwm->formWindowCount()) {
108 for (int i = 0; i < fwCount; i++)
109 if (const FormWindowBase *fwb = qobject_cast<const FormWindowBase *>(fwm->formWindow(i))) {
113 }
114 }
115}
116
118{
119 m_q = q;
128
129 m_addButton->setIcon(createIconSet("plus.png"_L1));
134
137 m_editButton->setIcon(createIconSet("edit.png"_L1));
138 m_editButton->setToolTip(EmbeddedOptionsControl::tr("Edit the selected profile"));
140
141 m_deleteButton->setIcon(createIconSet("minus.png"_L1));
142 m_deleteButton->setToolTip(EmbeddedOptionsControl::tr("Delete the selected profile"));
146
151}
152
154{
156 for (const auto &dp : m_sortedProfiles)
157 rc.append(dp.name());
158 return rc;
159}
160
162{
165 // Create a new profile with a new, unique name
169
171 const QString newNamePrefix = EmbeddedOptionsControl::tr("New profile");
173 for (int i = 2; names.contains(newName); i++) {
175 newName += QString::number(i);
176 }
177
180 if (dlg.showDialog(names)) {
183 // Maintain sorted order
187 m_dirty = true;
188 }
189}
190
192{
194 if (index < 0)
195 return;
196
197 // Edit the profile, compile a list of existing names
198 // excluding current one. re-insert if changed,
199 // re-sort if name changed.
201 const QString oldName = oldProfile.name();
204
208 if (dlg.showDialog(names)) {
210 if (newProfile != oldProfile) {
211 m_dirty = true;
213 if (newProfile.name() != oldName) {
217 } else {
219 }
220
221 }
222 }
223}
224
226{
228 if (index < 0)
229 return;
231 if (ask(m_q, m_core->dialogGui(),
232 EmbeddedOptionsControl::tr("Delete Profile"),
233 EmbeddedOptionsControl::tr("Would you like to delete the profile '%1'?").arg(name))) {
237 m_dirty = true;
238 }
239}
240
242{
243 // Clear items until only "None" is left
244 for (int i = m_profileCombo->count() - 1; i > 0; i--)
246 if (!m_sortedProfiles.isEmpty()) {
249 }
250}
251
264
273
274//: Format embedded device profile description
275static const char *descriptionFormat = QT_TRANSLATE_NOOP("EmbeddedOptionsControl",
276"<html>"
277"<table>"
278"<tr><td><b>Font</b></td><td>%1, %2</td></tr>"
279"<tr><td><b>Style</b></td><td>%3</td></tr>"
280"<tr><td><b>Resolution</b></td><td>%4 x %5</td></tr>"
281"</table>"
282"</html>");
283
284static inline QString description(const DeviceProfile& p)
285{
286 QString styleName = p.style();
287 if (styleName.isEmpty())
288 styleName = EmbeddedOptionsControl::tr("Default");
289 return EmbeddedOptionsControl::tr(descriptionFormat).
290 arg(p.fontFamily()).arg(p.fontPointSize()).arg(styleName).arg(p.dpiX()).arg(p.dpiY());
291}
292
293void EmbeddedOptionsControlPrivate::updateDescriptionLabel()
294{
295 const int profileIndex = m_profileCombo->currentIndex() - profileComboIndexOffset;
296 if (profileIndex >= 0) {
297 m_descriptionLabel->setText(description(m_sortedProfiles.at(profileIndex)));
298 } else {
299 m_descriptionLabel->clear();
300 }
301}
302
303void EmbeddedOptionsControlPrivate::updateState()
304{
305 const int profileIndex = m_profileCombo->currentIndex() - profileComboIndexOffset;
306 // Allow for changing/deleting only if it is not in use
307 bool modifyEnabled = false;
308 if (profileIndex >= 0)
309 modifyEnabled = !m_usedProfiles.contains(m_sortedProfiles.at(profileIndex).name());
310 m_editButton->setEnabled(modifyEnabled);
311 m_deleteButton->setEnabled(modifyEnabled);
312 updateDescriptionLabel();
313}
314
316{
317 updateState();
318 m_dirty = true;
319}
320
321// ------------- EmbeddedOptionsControl
322EmbeddedOptionsControl::EmbeddedOptionsControl(QDesignerFormEditorInterface *core, QWidget *parent) :
323 QWidget(parent),
324 m_d(new EmbeddedOptionsControlPrivate(core))
325{
326 m_d->init(this);
327}
328
330{
331 delete m_d;
332}
333
334void EmbeddedOptionsControl::slotAdd()
335{
336 m_d->slotAdd();
337}
338
339void EmbeddedOptionsControl::slotEdit()
340{
341 m_d->slotEdit();
342}
343
344void EmbeddedOptionsControl::slotDelete()
345{
347}
348
349void EmbeddedOptionsControl::loadSettings()
350{
352}
353
358
359void EmbeddedOptionsControl::slotProfileIndexChanged(int i)
360{
362}
363
365{
366 return m_d->isDirty();
367}
368
369// EmbeddedOptionsPage:
370EmbeddedOptionsPage::EmbeddedOptionsPage(QDesignerFormEditorInterface *core) :
371 m_core(core)
372{
373}
374
375QString EmbeddedOptionsPage::name() const
376{
377 //: Tab in preferences dialog
378 return QCoreApplication::translate("EmbeddedOptionsPage", "Embedded Design");
379}
380
382{
383 QWidget *optionsWidget = new QWidget(parent);
384
385 QVBoxLayout *optionsVLayout = new QVBoxLayout();
386
387 //: EmbeddedOptionsControl group box"
388 QGroupBox *gb = new QGroupBox(QCoreApplication::translate("EmbeddedOptionsPage", "Device Profiles"));
389 QVBoxLayout *gbVLayout = new QVBoxLayout();
390 m_embeddedOptionsControl = new EmbeddedOptionsControl(m_core);
391 m_embeddedOptionsControl->loadSettings();
392 gbVLayout->addWidget(m_embeddedOptionsControl);
393 gb->setLayout(gbVLayout);
394 optionsVLayout->addWidget(gb);
395
396 optionsVLayout->addStretch(1);
397
398 // Outer layout to give it horizontal stretch
399 QHBoxLayout *optionsHLayout = new QHBoxLayout();
400 optionsHLayout->addLayout(optionsVLayout);
401 optionsHLayout->addStretch(1);
402 optionsWidget->setLayout(optionsHLayout);
403 return optionsWidget;
404}
405
407{
408 if (!m_embeddedOptionsControl || !m_embeddedOptionsControl->isDirty())
409 return;
410
411 m_embeddedOptionsControl->saveSettings();
412 if (FormWindowManager *fw = qobject_cast<qdesigner_internal::FormWindowManager *>(m_core->formWindowManager()))
414}
415
417{
418}
419}
420
421QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:432
Auxiliary methods to store/retrieve settings.
bool deviceProfileLessThan(const DeviceProfile &d1, const DeviceProfile &d2)
static bool ask(QWidget *parent, QDesignerDialogGuiInterface *dlgui, const QString &title, const QString &what)
static QString description(const DeviceProfile &p)