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 "preferencesdialog.h"
30#include "ui_preferencesdialog.h"
31#include "qdesigner_appearanceoptions.h"
32
33#include <QtDesigner/abstractoptionspage.h>
34#include <QtDesigner/abstractformeditor.h>
35
36#include <QtWidgets/qfiledialog.h>
37#include <QtWidgets/qpushbutton.h>
38
39QT_BEGIN_NAMESPACE
40
41PreferencesDialog::PreferencesDialog(QDesignerFormEditorInterface *core, QWidget *parentWidget) :
42 QDialog(parentWidget),
43 m_ui(new Ui::PreferencesDialog()),
44 m_core(core)
45{
46 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
47 m_ui->setupUi(this);
48
49 m_optionsPages = core->optionsPages();
50
51 m_ui->m_optionTabWidget->clear();
52 for (QDesignerOptionsPageInterface *optionsPage : qAsConst(t&: m_optionsPages)) {
53 QWidget *page = optionsPage->createPage(parent: this);
54 m_ui->m_optionTabWidget->addTab(widget: page, optionsPage->name());
55 if (QDesignerAppearanceOptionsWidget *appearanceWidget = qobject_cast<QDesignerAppearanceOptionsWidget *>(object: page))
56 connect(sender: appearanceWidget, signal: &QDesignerAppearanceOptionsWidget::uiModeChanged,
57 receiver: this, slot: &PreferencesDialog::slotUiModeChanged);
58 }
59
60 connect(sender: m_ui->m_dialogButtonBox, signal: &QDialogButtonBox::rejected, receiver: this, slot: &PreferencesDialog::slotRejected);
61 connect(sender: m_ui->m_dialogButtonBox, signal: &QDialogButtonBox::accepted, receiver: this, slot: &PreferencesDialog::slotAccepted);
62 connect(sender: applyButton(), signal: &QAbstractButton::clicked, receiver: this, slot: &PreferencesDialog::slotApply);
63}
64
65PreferencesDialog::~PreferencesDialog()
66{
67 delete m_ui;
68}
69
70QPushButton *PreferencesDialog::applyButton() const
71{
72 return m_ui->m_dialogButtonBox->button(which: QDialogButtonBox::Apply);
73}
74
75void PreferencesDialog::slotApply()
76{
77 for (QDesignerOptionsPageInterface *optionsPage : qAsConst(t&: m_optionsPages))
78 optionsPage->apply();
79}
80
81void PreferencesDialog::slotAccepted()
82{
83 slotApply();
84 closeOptionPages();
85 accept();
86}
87
88void PreferencesDialog::slotRejected()
89{
90 closeOptionPages();
91 reject();
92}
93
94void PreferencesDialog::slotUiModeChanged(bool modified)
95{
96 // Cannot "apply" a ui mode change (destroy the dialogs parent)
97 applyButton()->setEnabled(!modified);
98}
99
100void PreferencesDialog::closeOptionPages()
101{
102 for (QDesignerOptionsPageInterface *optionsPage : qAsConst(t&: m_optionsPages))
103 optionsPage->finish();
104}
105
106QT_END_NAMESPACE
107

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