source: trunk/tools/assistant/compat/fontsettingsdialog.cpp@ 280

Last change on this file since 280 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt Assistant of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
54QT_BEGIN_NAMESPACE
55
56FontSettingsDialog::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
97FontSettingsDialog::~FontSettingsDialog()
98{
99 // nothing todo
100}
101
102bool 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
113void 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
125void 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
137QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.