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 "qdesigner_appearanceoptions.h"
30#include "ui_qdesigner_appearanceoptions.h"
31
32#include "qdesigner_settings.h"
33#include "qdesigner_toolwindow.h"
34
35#include <QtDesigner/abstractformeditor.h>
36#include <QtCore/qtimer.h>
37#include <QtCore/qdebug.h>
38
39QT_BEGIN_NAMESPACE
40
41// ---------------- AppearanceOptions
42bool AppearanceOptions::equals(const AppearanceOptions &rhs) const
43{
44 return uiMode == rhs.uiMode && toolWindowFontSettings == rhs.toolWindowFontSettings;
45}
46
47void AppearanceOptions::toSettings(QDesignerSettings &settings) const
48{
49 settings.setUiMode(uiMode);
50 settings.setToolWindowFont(toolWindowFontSettings);
51}
52
53void AppearanceOptions::fromSettings(const QDesignerSettings &settings)
54{
55 uiMode = settings.uiMode();
56 toolWindowFontSettings = settings.toolWindowFont();
57}
58
59// ---------------- QDesignerAppearanceOptionsWidget
60QDesignerAppearanceOptionsWidget::QDesignerAppearanceOptionsWidget(QWidget *parent) :
61 QWidget(parent),
62 m_ui(new Ui::AppearanceOptionsWidget)
63{
64 m_ui->setupUi(this);
65
66 m_ui->m_uiModeCombo->addItem(atext: tr(s: "Docked Window"), auserData: QVariant(DockedMode));
67 m_ui->m_uiModeCombo->addItem(atext: tr(s: "Multiple Top-Level Windows"), auserData: QVariant(TopLevelMode));
68 connect(sender: m_ui->m_uiModeCombo, signal: QOverload<int>::of(ptr: &QComboBox::currentIndexChanged),
69 receiver: this, slot: &QDesignerAppearanceOptionsWidget::slotUiModeComboChanged);
70
71 m_ui->m_fontPanel->setCheckable(true);
72 m_ui->m_fontPanel->setTitle(tr(s: "Toolwindow Font"));
73
74}
75
76QDesignerAppearanceOptionsWidget::~QDesignerAppearanceOptionsWidget()
77{
78 delete m_ui;
79}
80
81UIMode QDesignerAppearanceOptionsWidget::uiMode() const
82{
83 return static_cast<UIMode>(m_ui->m_uiModeCombo->itemData(index: m_ui->m_uiModeCombo->currentIndex()).toInt());
84}
85
86AppearanceOptions QDesignerAppearanceOptionsWidget::appearanceOptions() const
87{
88 AppearanceOptions rc;
89 rc.uiMode = uiMode();
90 rc.toolWindowFontSettings.m_font = m_ui->m_fontPanel->selectedFont();
91 rc.toolWindowFontSettings.m_useFont = m_ui->m_fontPanel->isChecked();
92 rc.toolWindowFontSettings.m_writingSystem = m_ui->m_fontPanel->writingSystem();
93 return rc;
94}
95
96void QDesignerAppearanceOptionsWidget::setAppearanceOptions(const AppearanceOptions &ao)
97{
98 m_initialUIMode = ao.uiMode;
99 m_ui->m_uiModeCombo->setCurrentIndex(m_ui->m_uiModeCombo->findData(data: QVariant(ao.uiMode)));
100 m_ui->m_fontPanel->setWritingSystem(ao.toolWindowFontSettings.m_writingSystem);
101 m_ui->m_fontPanel->setSelectedFont(ao.toolWindowFontSettings.m_font);
102 m_ui->m_fontPanel->setChecked(ao.toolWindowFontSettings.m_useFont);
103}
104
105void QDesignerAppearanceOptionsWidget::slotUiModeComboChanged()
106{
107 emit uiModeChanged(modified: m_initialUIMode != uiMode());
108}
109
110// ----------- QDesignerAppearanceOptionsPage
111QDesignerAppearanceOptionsPage::QDesignerAppearanceOptionsPage(QDesignerFormEditorInterface *core) :
112 m_core(core)
113{
114}
115
116QString QDesignerAppearanceOptionsPage::name() const
117{
118 //: Tab in preferences dialog
119 return QCoreApplication::translate(context: "QDesignerAppearanceOptionsPage", key: "Appearance");
120}
121
122QWidget *QDesignerAppearanceOptionsPage::createPage(QWidget *parent)
123{
124 m_widget = new QDesignerAppearanceOptionsWidget(parent);
125 m_initialOptions.fromSettings(settings: QDesignerSettings(m_core));
126 m_widget->setAppearanceOptions(m_initialOptions);
127 return m_widget;
128}
129
130void QDesignerAppearanceOptionsPage::apply()
131{
132 if (m_widget) {
133 const AppearanceOptions newOptions = m_widget->appearanceOptions();
134 if (newOptions != m_initialOptions) {
135 QDesignerSettings settings(m_core);
136 newOptions.toSettings(settings);
137 m_initialOptions = newOptions;
138 emit settingsChanged();
139 }
140 }
141}
142
143void QDesignerAppearanceOptionsPage::finish()
144{
145}
146
147QT_END_NAMESPACE
148
149

source code of qttools/src/designer/src/designer/qdesigner_appearanceoptions.cpp