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