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
preferencesdialog.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
4
6#include "fontpanel_p.h"
10
11#include <QtCore/QVersionNumber>
12
13#include <QtGui/QFontDatabase>
14
15#include <QtHelp/QHelpEngineCore>
16#include <QtHelp/QHelpFilterData>
17#include <QtHelp/QHelpFilterEngine>
18#include <QtHelp/QHelpFilterSettingsWidget>
19
20#include <QtDebug>
21
23
24using namespace Qt::StringLiterals;
25
26PreferencesDialog::PreferencesDialog(QWidget *parent)
27 : QDialog(parent)
28 , m_appFontChanged(false)
29 , m_browserFontChanged(false)
31 , m_hideFiltersTab(!helpEngine.filterFunctionalityEnabled())
32 , m_hideDocsTab(!helpEngine.documentationManagerEnabled())
33{
34 m_ui.setupUi(this);
35
36 connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked,
37 this, &PreferencesDialog::okClicked);
38 connect(m_ui.buttonBox->button(QDialogButtonBox::Apply), &QAbstractButton::clicked,
39 this, &PreferencesDialog::applyClicked);
40 connect(m_ui.buttonBox->button(QDialogButtonBox::Cancel), &QAbstractButton::clicked,
41 this, &QDialog::reject);
42
43 m_docSettings = HelpDocSettings::readSettings(helpEngine.helpEngine());
44
45 if (m_hideDocsTab) {
46 m_ui.tabWidget->removeTab(m_ui.tabWidget->indexOf(m_ui.docsTab));
47 } else {
48 connect(m_ui.docSettingsWidget, &HelpDocSettingsWidget::docSettingsChanged, this,
49 [this](const HelpDocSettings &settings) {
50 m_docSettings = settings;
51 if (m_hideFiltersTab)
52 return;
53
54 m_ui.filterSettingsWidget->setAvailableComponents(m_docSettings.components());
55 m_ui.filterSettingsWidget->setAvailableVersions(m_docSettings.versions());
56 });
57
58 m_ui.docSettingsWidget->setDocSettings(m_docSettings);
59 }
60
61 if (m_hideFiltersTab) {
62 m_ui.tabWidget->removeTab(m_ui.tabWidget->indexOf(m_ui.filtersTab));
63 } else {
64 m_ui.filterSettingsWidget->setAvailableComponents(m_docSettings.components());
65 m_ui.filterSettingsWidget->setAvailableVersions(m_docSettings.versions());
66 m_ui.filterSettingsWidget->readSettings(helpEngine.filterEngine());
67 }
68
69 updateFontSettingsPage();
70 updateOptionsPage();
71
72 if (helpEngine.usesAppFont())
73 setFont(helpEngine.appFont());
74}
75
76void PreferencesDialog::okClicked()
77{
78 applyChanges();
79 accept();
80}
81
82void PreferencesDialog::applyClicked()
83{
84 applyChanges();
85
86 m_docSettings = HelpDocSettings::readSettings(helpEngine.helpEngine());
87
88 if (!m_hideDocsTab)
89 m_ui.docSettingsWidget->setDocSettings(m_docSettings);
90 if (!m_hideFiltersTab) {
91 m_ui.filterSettingsWidget->setAvailableComponents(m_docSettings.components());
92 m_ui.filterSettingsWidget->setAvailableVersions(m_docSettings.versions());
93 m_ui.filterSettingsWidget->readSettings(helpEngine.filterEngine());
94 }
95}
96
97void PreferencesDialog::applyChanges()
98{
99 bool changed = false;
100 if (!m_hideDocsTab)
101 changed = HelpDocSettings::applySettings(helpEngine.helpEngine(), m_docSettings);
102 if (!m_hideFiltersTab)
103 changed = changed || m_ui.filterSettingsWidget->applySettings(helpEngine.filterEngine());
104
105 if (changed) {
106 // In order to update the filtercombobox and indexwidget
107 // according to the new filter configuration.
108 helpEngine.setupData();
109 }
110
111 helpEngine.setShowTabs(m_ui.showTabs->isChecked());
112 if (m_showTabs != m_ui.showTabs->isChecked())
113 emit updateUserInterface();
114
115 if (m_appFontChanged) {
116 helpEngine.setAppFont(m_appFontPanel->selectedFont());
117 helpEngine.setUseAppFont(m_appFontPanel->isChecked());
118 helpEngine.setAppWritingSystem(m_appFontPanel->writingSystem());
119 emit updateApplicationFont();
120 m_appFontChanged = false;
121 }
122
123 if (m_browserFontChanged) {
124 helpEngine.setBrowserFont(m_browserFontPanel->selectedFont());
125 helpEngine.setUseBrowserFont(m_browserFontPanel->isChecked());
126 helpEngine.setBrowserWritingSystem(m_browserFontPanel->writingSystem());
127 emit updateBrowserFont();
128 m_browserFontChanged = false;
129 }
130
131 QString homePage = m_ui.homePageLineEdit->text();
132 if (homePage.isEmpty())
133 homePage = "help"_L1;
134 helpEngine.setHomePage(homePage);
135
136 const int option = m_ui.helpStartComboBox->currentIndex();
137 helpEngine.setStartOption(option);
138}
139
140void PreferencesDialog::updateFontSettingsPage()
141{
142 m_browserFontPanel = new FontPanel(this);
143 m_browserFontPanel->setCheckable(true);
144 m_ui.stackedWidget_2->insertWidget(0, m_browserFontPanel);
145
146 m_appFontPanel = new FontPanel(this);
147 m_appFontPanel->setCheckable(true);
148 m_ui.stackedWidget_2->insertWidget(1, m_appFontPanel);
149
150 m_ui.stackedWidget_2->setCurrentIndex(0);
151
152 const QString customSettings(tr("Use custom settings"));
153 m_appFontPanel->setTitle(customSettings);
154
155 QFont font = helpEngine.appFont();
156 m_appFontPanel->setSelectedFont(font);
157
158 QFontDatabase::WritingSystem system = helpEngine.appWritingSystem();
159 m_appFontPanel->setWritingSystem(system);
160
161 m_appFontPanel->setChecked(helpEngine.usesAppFont());
162
163 m_browserFontPanel->setTitle(customSettings);
164
165 font = helpEngine.browserFont();
166 m_browserFontPanel->setSelectedFont(font);
167
168 system = helpEngine.browserWritingSystem();
169 m_browserFontPanel->setWritingSystem(system);
170
171 m_browserFontPanel->setChecked(helpEngine.usesBrowserFont());
172
173 connect(m_appFontPanel, &QGroupBox::toggled,
174 this, &PreferencesDialog::appFontSettingToggled);
175 connect(m_browserFontPanel, &QGroupBox::toggled,
176 this, &PreferencesDialog::browserFontSettingToggled);
177
178 const QList<QComboBox*> &appCombos = m_appFontPanel->findChildren<QComboBox*>();
179 for (QComboBox* box : appCombos) {
180 connect(box, &QComboBox::currentIndexChanged,
181 this, &PreferencesDialog::appFontSettingChanged);
182 }
183
184 const QList<QComboBox*> &browserCombos = m_browserFontPanel->findChildren<QComboBox*>();
185 for (QComboBox* box : browserCombos) {
186 connect(box, &QComboBox::currentIndexChanged,
187 this, &PreferencesDialog::browserFontSettingChanged);
188 }
189}
190
191void PreferencesDialog::appFontSettingToggled(bool on)
192{
193 Q_UNUSED(on);
194 m_appFontChanged = true;
195}
196
197void PreferencesDialog::appFontSettingChanged(int index)
198{
199 Q_UNUSED(index);
200 m_appFontChanged = true;
201}
202
203void PreferencesDialog::browserFontSettingToggled(bool on)
204{
205 Q_UNUSED(on);
206 m_browserFontChanged = true;
207}
208
209void PreferencesDialog::browserFontSettingChanged(int index)
210{
211 Q_UNUSED(index);
212 m_browserFontChanged = true;
213}
214
215void PreferencesDialog::updateOptionsPage()
216{
217 m_ui.homePageLineEdit->setText(helpEngine.homePage());
218
219 int option = helpEngine.startOption();
220 m_ui.helpStartComboBox->setCurrentIndex(option);
221
222 m_showTabs = helpEngine.showTabs();
223 m_ui.showTabs->setChecked(m_showTabs);
224
225 connect(m_ui.blankPageButton, &QAbstractButton::clicked,
226 this, &PreferencesDialog::setBlankPage);
227 connect(m_ui.currentPageButton, &QAbstractButton::clicked,
228 this, &PreferencesDialog::setCurrentPage);
229 connect(m_ui.defaultPageButton, &QAbstractButton::clicked,
230 this, &PreferencesDialog::setDefaultPage);
231}
232
233void PreferencesDialog::setBlankPage()
234{
235 m_ui.homePageLineEdit->setText("about:blank"_L1);
236}
237
238void PreferencesDialog::setCurrentPage()
239{
240 QString homepage = CentralWidget::instance()->currentSource().toString();
241 if (homepage.isEmpty())
242 homepage = "help"_L1;
243
244 m_ui.homePageLineEdit->setText(homepage);
245}
246
247void PreferencesDialog::setDefaultPage()
248{
249 m_ui.homePageLineEdit->setText(helpEngine.defaultHomePage());
250}
251
252QT_END_NAMESPACE
void setStartOption(int option)
static HelpEngineWrapper & instance()
void setUseBrowserFont(bool useBrowserFont)
bool documentationManagerEnabled() const
bool filterFunctionalityEnabled() const
void setUseAppFont(bool useAppFont)
Combined button and popup list for selecting options.