|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Assistant of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "fontsettingsdialog.h" |
|
43 #include "fontpanel.h" |
|
44 #include "config.h" |
|
45 |
|
46 #include <QtGui/QLabel> |
|
47 #include <QtGui/QComboBox> |
|
48 #include <QtGui/QHBoxLayout> |
|
49 #include <QtGui/QVBoxLayout> |
|
50 #include <QtGui/QApplication> |
|
51 #include <QtGui/QStackedWidget> |
|
52 #include <QtGui/QDialogButtonBox> |
|
53 |
|
54 QT_BEGIN_NAMESPACE |
|
55 |
|
56 FontSettingsDialog::FontSettingsDialog(QWidget *parent) |
|
57 : QDialog(parent) |
|
58 , m_windowFontPanel(new FontPanel(this)) |
|
59 , m_browserFontPanel(new FontPanel(this)) |
|
60 , m_dialogButtonBox(new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel)) |
|
61 { |
|
62 setModal(true); |
|
63 setWindowTitle(tr("Font Settings")); |
|
64 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
|
65 |
|
66 QVBoxLayout *mainVLayout = new QVBoxLayout(this); |
|
67 QHBoxLayout *hboxLayout = new QHBoxLayout; |
|
68 mainVLayout->addLayout(hboxLayout); |
|
69 |
|
70 QLabel *label = new QLabel(tr("Font settings for:"), this); |
|
71 label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); |
|
72 hboxLayout->addWidget(label); |
|
73 QComboBox *comboBox = new QComboBox(this); |
|
74 comboBox->addItem(tr("Browser")); |
|
75 comboBox->addItem(tr("Application")); |
|
76 hboxLayout->addWidget(comboBox); |
|
77 |
|
78 m_windowFontPanel->setCheckable(true); |
|
79 m_browserFontPanel->setCheckable(true); |
|
80 |
|
81 const QString customSettings(tr("Use custom settings")); |
|
82 m_windowFontPanel->setTitle(customSettings); |
|
83 m_browserFontPanel->setTitle(customSettings); |
|
84 |
|
85 QStackedWidget *stackWidget = new QStackedWidget(this); |
|
86 stackWidget->addWidget(m_browserFontPanel); |
|
87 stackWidget->addWidget(m_windowFontPanel); |
|
88 |
|
89 mainVLayout->addWidget(stackWidget); |
|
90 mainVLayout->addWidget(m_dialogButtonBox); |
|
91 |
|
92 connect(m_dialogButtonBox , SIGNAL(rejected()), this, SLOT(reject())); |
|
93 connect(m_dialogButtonBox , SIGNAL(accepted()), this, SLOT(accept())); |
|
94 connect(comboBox, SIGNAL(activated(int)), stackWidget, SLOT(setCurrentIndex(int))); |
|
95 } |
|
96 |
|
97 FontSettingsDialog::~FontSettingsDialog() |
|
98 { |
|
99 // nothing todo |
|
100 } |
|
101 |
|
102 bool FontSettingsDialog::showDialog(FontSettings *settings) |
|
103 { |
|
104 setupFontSettingsDialog(settings); |
|
105 |
|
106 if (exec() != Accepted) |
|
107 return false; |
|
108 |
|
109 updateFontSettings(settings); |
|
110 return true; |
|
111 } |
|
112 |
|
113 void FontSettingsDialog::updateFontSettings(FontSettings *settings) |
|
114 { |
|
115 settings->useWindowFont = m_windowFontPanel->isChecked(); |
|
116 settings->useBrowserFont = m_browserFontPanel->isChecked(); |
|
117 |
|
118 settings->windowFont = settings->useWindowFont ? m_windowFontPanel->selectedFont() : qApp->font(); |
|
119 settings->browserFont = settings->useBrowserFont ? m_browserFontPanel->selectedFont() : qApp->font(); |
|
120 |
|
121 settings->windowWritingSystem = settings->useWindowFont ? m_windowFontPanel->writingSystem() : QFontDatabase::Latin; |
|
122 settings->browserWritingSystem = settings->useBrowserFont ? m_browserFontPanel->writingSystem() : QFontDatabase::Latin; |
|
123 } |
|
124 |
|
125 void FontSettingsDialog::setupFontSettingsDialog(const FontSettings *settings) |
|
126 { |
|
127 m_windowFontPanel->setSelectedFont(settings->windowFont); |
|
128 m_browserFontPanel->setSelectedFont(settings->browserFont); |
|
129 |
|
130 m_windowFontPanel->setWritingSystem(settings->windowWritingSystem); |
|
131 m_browserFontPanel->setWritingSystem(settings->browserWritingSystem); |
|
132 |
|
133 m_windowFontPanel->setChecked(settings->useWindowFont); |
|
134 m_browserFontPanel->setChecked(settings->useBrowserFont); |
|
135 } |
|
136 |
|
137 QT_END_NAMESPACE |