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
formeditor_optionspage.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
6
7// shared
9#include "gridpanel_p.h"
10#include "grid_p.h"
13#include "zoomwidget_p.h"
14#include <private/actioneditor_p.h>
15
16// SDK
17#include <QtDesigner/abstractformeditor.h>
18#include <QtDesigner/abstractformwindowmanager.h>
19
20#include <QtCore/qstring.h>
21#include <QtCore/qcoreapplication.h>
22#include <QtWidgets/qgroupbox.h>
23#include <QtWidgets/qboxlayout.h>
24#include <QtWidgets/qformlayout.h>
25#include <QtWidgets/qcombobox.h>
26
28
29namespace qdesigner_internal {
30
31// Zoom, currently for preview only
34public:
35 explicit ZoomSettingsWidget(QWidget *parent = nullptr);
36
37 void fromSettings(const QDesignerSharedSettings &s);
38 void toSettings(QDesignerSharedSettings &s) const;
39
40private:
41 QComboBox *m_zoomCombo;
42};
43
44ZoomSettingsWidget::ZoomSettingsWidget(QWidget *parent) :
45 QGroupBox(parent),
46 m_zoomCombo(new QComboBox)
47{
48 m_zoomCombo->setEditable(false);
49 const QList<int> &zoomValues = ZoomMenu::zoomValues();
50 for (int z : zoomValues) {
51 //: Zoom percentage
52 m_zoomCombo->addItem(QCoreApplication::translate("FormEditorOptionsPage", "%1 %").arg(z), QVariant(z));
53 }
54
55 // Layout
56 setCheckable(true);
57 setTitle(QCoreApplication::translate("FormEditorOptionsPage", "Preview Zoom"));
58 QFormLayout *lt = new QFormLayout;
59 lt->addRow(QCoreApplication::translate("FormEditorOptionsPage", "Default Zoom"), m_zoomCombo);
60 setLayout(lt);
61}
62
63void ZoomSettingsWidget::fromSettings(const QDesignerSharedSettings &s)
64{
65 setChecked(s.zoomEnabled());
66 const int idx = m_zoomCombo->findData(QVariant(s.zoom()));
67 m_zoomCombo->setCurrentIndex(qMax(0, idx));
68}
69
76
77
78
79// FormEditorOptionsPage:
80FormEditorOptionsPage::FormEditorOptionsPage(QDesignerFormEditorInterface *core)
81 : m_core(core)
82{
83}
84
86{
87 //: Tab in preferences dialog
88 return QCoreApplication::translate("FormEditorOptionsPage", "Forms");
89}
90
92{
93 QWidget *optionsWidget = new QWidget(parent);
94
95 const QDesignerSharedSettings settings(m_core);
96 m_previewConf = new PreviewConfigurationWidget(m_core);
97 m_zoomSettingsWidget = new ZoomSettingsWidget;
98 m_zoomSettingsWidget->fromSettings(settings);
99
100 m_defaultGridConf = new GridPanel();
101 m_defaultGridConf->setTitle(QCoreApplication::translate("FormEditorOptionsPage", "Default Grid"));
102 m_defaultGridConf->setGrid(settings.defaultGrid());
103
104 const QString namingTitle =
105 QCoreApplication::translate("FormEditorOptionsPage", "Object Naming Convention");
106 QGroupBox *namingGroupBox = new QGroupBox(namingTitle);
107 const QString namingToolTip =
108 QCoreApplication::translate("FormEditorOptionsPage",
109 "Naming convention used for generating action object names from their text");
110 namingGroupBox->setToolTip(namingToolTip);
111 QHBoxLayout *namingHLayout = new QHBoxLayout(namingGroupBox);
112 m_namingComboBox = new QComboBox;
113 m_namingComboBox->setToolTip(namingToolTip);
114 QStringList items; // matching ActionEditor::NamingMode
115 items << QCoreApplication::translate("FormEditorOptionsPage", "Camel Case")
116 << QCoreApplication::translate("FormEditorOptionsPage", "Underscore");
117 m_namingComboBox->addItems(items);
118 m_namingComboBox->setCurrentIndex(settings.objectNamingMode());
119 namingHLayout->addWidget(m_namingComboBox.data());
120
121 QVBoxLayout *optionsVLayout = new QVBoxLayout();
122 optionsVLayout->addWidget(m_defaultGridConf);
123 optionsVLayout->addWidget(m_previewConf);
124 optionsVLayout->addWidget(m_zoomSettingsWidget);
125 optionsVLayout->addWidget(namingGroupBox);
126 optionsVLayout->addStretch(1);
127
128 // Outer layout to give it horizontal stretch
129 QHBoxLayout *optionsHLayout = new QHBoxLayout();
130 optionsHLayout->addLayout(optionsVLayout);
131 optionsHLayout->addStretch(1);
132 optionsWidget->setLayout(optionsHLayout);
133
134 return optionsWidget;
135}
136
138{
139 QDesignerSharedSettings settings(m_core);
140 if (m_defaultGridConf) {
141 const Grid defaultGrid = m_defaultGridConf->grid();
142 settings.setDefaultGrid(defaultGrid);
143
144 FormWindowBase::setDefaultDesignerGrid(defaultGrid);
145 // Update grid settings in all existing form windows
146 QDesignerFormWindowManagerInterface *fwm = m_core->formWindowManager();
147 if (const int numWindows = fwm->formWindowCount()) {
148 for (int i = 0; i < numWindows; i++)
149 if (qdesigner_internal::FormWindowBase *fwb
150 = qobject_cast<qdesigner_internal::FormWindowBase *>( fwm->formWindow(i)))
151 if (!fwb->hasFormGrid())
152 fwb->setDesignerGrid(defaultGrid);
153 }
154 }
155 if (m_previewConf) {
156 m_previewConf->saveState();
157 }
158
159 if (m_zoomSettingsWidget)
160 m_zoomSettingsWidget->toSettings(settings);
161
162 if (m_namingComboBox) {
163 const ObjectNamingMode namingMode
164 = static_cast<ObjectNamingMode>(m_namingComboBox->currentIndex());
165 settings.setObjectNamingMode(namingMode);
166 ActionEditor::setObjectNamingMode(namingMode);
167 }
168}
169
173
174}
175
176QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:432
FormEditorOptionsPage(QDesignerFormEditorInterface *core)
void fromSettings(const QDesignerSharedSettings &s)
void toSettings(QDesignerSharedSettings &s) const
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.