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 "formeditor_optionspage.h"
30
31// shared
32#include "formwindowbase_p.h"
33#include "gridpanel_p.h"
34#include "grid_p.h"
35#include "previewconfigurationwidget_p.h"
36#include "shared_settings_p.h"
37#include "zoomwidget_p.h"
38#include <private/actioneditor_p.h>
39
40// SDK
41#include <QtDesigner/abstractformeditor.h>
42#include <QtDesigner/abstractformwindowmanager.h>
43
44#include <QtCore/qstring.h>
45#include <QtCore/qcoreapplication.h>
46#include <QtWidgets/qgroupbox.h>
47#include <QtWidgets/qboxlayout.h>
48#include <QtWidgets/qformlayout.h>
49#include <QtWidgets/qcombobox.h>
50
51QT_BEGIN_NAMESPACE
52
53namespace qdesigner_internal {
54
55// Zoom, currently for preview only
56class ZoomSettingsWidget : public QGroupBox {
57 Q_DISABLE_COPY_MOVE(ZoomSettingsWidget)
58public:
59 explicit ZoomSettingsWidget(QWidget *parent = nullptr);
60
61 void fromSettings(const QDesignerSharedSettings &s);
62 void toSettings(QDesignerSharedSettings &s) const;
63
64private:
65 QComboBox *m_zoomCombo;
66};
67
68ZoomSettingsWidget::ZoomSettingsWidget(QWidget *parent) :
69 QGroupBox(parent),
70 m_zoomCombo(new QComboBox)
71{
72 m_zoomCombo->setEditable(false);
73 const QVector<int> &zoomValues = ZoomMenu::zoomValues();
74 for (int z : zoomValues) {
75 //: Zoom percentage
76 m_zoomCombo->addItem(atext: QCoreApplication::translate(context: "FormEditorOptionsPage", key: "%1 %").arg(a: z), auserData: QVariant(z));
77 }
78
79 // Layout
80 setCheckable(true);
81 setTitle(QCoreApplication::translate(context: "FormEditorOptionsPage", key: "Preview Zoom"));
82 QFormLayout *lt = new QFormLayout;
83 lt->addRow(labelText: QCoreApplication::translate(context: "FormEditorOptionsPage", key: "Default Zoom"), field: m_zoomCombo);
84 setLayout(lt);
85}
86
87void ZoomSettingsWidget::fromSettings(const QDesignerSharedSettings &s)
88{
89 setChecked(s.zoomEnabled());
90 const int idx = m_zoomCombo->findData(data: QVariant(s.zoom()));
91 m_zoomCombo->setCurrentIndex(qMax(a: 0, b: idx));
92}
93
94void ZoomSettingsWidget::toSettings(QDesignerSharedSettings &s) const
95{
96 s.setZoomEnabled(isChecked());
97 const int zoom = m_zoomCombo->itemData(index: m_zoomCombo->currentIndex()).toInt();
98 s.setZoom(zoom);
99}
100
101
102
103// FormEditorOptionsPage:
104FormEditorOptionsPage::FormEditorOptionsPage(QDesignerFormEditorInterface *core)
105 : m_core(core)
106{
107}
108
109QString FormEditorOptionsPage::name() const
110{
111 //: Tab in preferences dialog
112 return QCoreApplication::translate(context: "FormEditorOptionsPage", key: "Forms");
113}
114
115QWidget *FormEditorOptionsPage::createPage(QWidget *parent)
116{
117 QWidget *optionsWidget = new QWidget(parent);
118
119 const QDesignerSharedSettings settings(m_core);
120 m_previewConf = new PreviewConfigurationWidget(m_core);
121 m_zoomSettingsWidget = new ZoomSettingsWidget;
122 m_zoomSettingsWidget->fromSettings(s: settings);
123
124 m_defaultGridConf = new GridPanel();
125 m_defaultGridConf->setTitle(QCoreApplication::translate(context: "FormEditorOptionsPage", key: "Default Grid"));
126 m_defaultGridConf->setGrid(settings.defaultGrid());
127
128 const QString namingTitle =
129 QCoreApplication::translate(context: "FormEditorOptionsPage", key: "Object Naming Convention");
130 QGroupBox *namingGroupBox = new QGroupBox(namingTitle);
131 const QString namingToolTip =
132 QCoreApplication::translate(context: "FormEditorOptionsPage",
133 key: "Naming convention used for generating action object names from their text");
134 namingGroupBox->setToolTip(namingToolTip);
135 QHBoxLayout *namingHLayout = new QHBoxLayout(namingGroupBox);
136 m_namingComboBox = new QComboBox;
137 m_namingComboBox->setToolTip(namingToolTip);
138 QStringList items; // matching ActionEditor::NamingMode
139 items << QCoreApplication::translate(context: "FormEditorOptionsPage", key: "Camel Case")
140 << QCoreApplication::translate(context: "FormEditorOptionsPage", key: "Underscore");
141 m_namingComboBox->addItems(texts: items);
142 m_namingComboBox->setCurrentIndex(settings.objectNamingMode());
143 namingHLayout->addWidget(m_namingComboBox.data());
144
145 QVBoxLayout *optionsVLayout = new QVBoxLayout();
146 optionsVLayout->addWidget(m_defaultGridConf);
147 optionsVLayout->addWidget(m_previewConf);
148 optionsVLayout->addWidget(m_zoomSettingsWidget);
149 optionsVLayout->addWidget(namingGroupBox);
150 optionsVLayout->addStretch(stretch: 1);
151
152 // Outer layout to give it horizontal stretch
153 QHBoxLayout *optionsHLayout = new QHBoxLayout();
154 optionsHLayout->addLayout(layout: optionsVLayout);
155 optionsHLayout->addStretch(stretch: 1);
156 optionsWidget->setLayout(optionsHLayout);
157
158 return optionsWidget;
159}
160
161void FormEditorOptionsPage::apply()
162{
163 QDesignerSharedSettings settings(m_core);
164 if (m_defaultGridConf) {
165 const Grid defaultGrid = m_defaultGridConf->grid();
166 settings.setDefaultGrid(defaultGrid);
167
168 FormWindowBase::setDefaultDesignerGrid(defaultGrid);
169 // Update grid settings in all existing form windows
170 QDesignerFormWindowManagerInterface *fwm = m_core->formWindowManager();
171 if (const int numWindows = fwm->formWindowCount()) {
172 for (int i = 0; i < numWindows; i++)
173 if (qdesigner_internal::FormWindowBase *fwb
174 = qobject_cast<qdesigner_internal::FormWindowBase *>( object: fwm->formWindow(index: i)))
175 if (!fwb->hasFormGrid())
176 fwb->setDesignerGrid(defaultGrid);
177 }
178 }
179 if (m_previewConf) {
180 m_previewConf->saveState();
181 }
182
183 if (m_zoomSettingsWidget)
184 m_zoomSettingsWidget->toSettings(s&: settings);
185
186 if (m_namingComboBox) {
187 const ObjectNamingMode namingMode
188 = static_cast<ObjectNamingMode>(m_namingComboBox->currentIndex());
189 settings.setObjectNamingMode(namingMode);
190 ActionEditor::setObjectNamingMode(namingMode);
191 }
192}
193
194void FormEditorOptionsPage::finish()
195{
196}
197
198}
199
200QT_END_NAMESPACE
201

source code of qttools/src/designer/src/components/formeditor/formeditor_optionspage.cpp