Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qfontdialog.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qwindowdefs.h" | - | ||||||||||||
35 | - | |||||||||||||
36 | #ifndef QT_NO_FONTDIALOG | - | ||||||||||||
37 | - | |||||||||||||
38 | #include "qfontdialog.h" | - | ||||||||||||
39 | #include "qfontdialog_p.h" | - | ||||||||||||
40 | - | |||||||||||||
41 | #include <qapplication.h> | - | ||||||||||||
42 | #include <qcheckbox.h> | - | ||||||||||||
43 | #include <qcombobox.h> | - | ||||||||||||
44 | #include <qevent.h> | - | ||||||||||||
45 | #include <qfontdatabase.h> | - | ||||||||||||
46 | #include <qgroupbox.h> | - | ||||||||||||
47 | #include <qlabel.h> | - | ||||||||||||
48 | #include <qlayout.h> | - | ||||||||||||
49 | #include <qlineedit.h> | - | ||||||||||||
50 | #include <qpushbutton.h> | - | ||||||||||||
51 | #include <qstyle.h> | - | ||||||||||||
52 | #include <qdialogbuttonbox.h> | - | ||||||||||||
53 | #include <qheaderview.h> | - | ||||||||||||
54 | #include <qlistview.h> | - | ||||||||||||
55 | #include <qstringlistmodel.h> | - | ||||||||||||
56 | #include <qvalidator.h> | - | ||||||||||||
57 | #include <private/qdialog_p.h> | - | ||||||||||||
58 | #include <private/qfont_p.h> | - | ||||||||||||
59 | - | |||||||||||||
60 | QT_BEGIN_NAMESPACE | - | ||||||||||||
61 | - | |||||||||||||
62 | class QFontListView : public QListView | - | ||||||||||||
63 | { | - | ||||||||||||
64 | Q_OBJECT | - | ||||||||||||
65 | public: | - | ||||||||||||
66 | QFontListView(QWidget *parent); | - | ||||||||||||
67 | inline QStringListModel *model() const { | - | ||||||||||||
68 | return static_cast<QStringListModel *>(QListView::model()); never executed: return static_cast<QStringListModel *>(QListView::model()); | 0 | ||||||||||||
69 | } | - | ||||||||||||
70 | inline void setCurrentItem(int item) { | - | ||||||||||||
71 | QListView::setCurrentIndex(static_cast<QAbstractListModel*>(model())->index(item)); | - | ||||||||||||
72 | } never executed: end of block | 0 | ||||||||||||
73 | inline int currentItem() const { | - | ||||||||||||
74 | return QListView::currentIndex().row(); never executed: return QListView::currentIndex().row(); | 0 | ||||||||||||
75 | } | - | ||||||||||||
76 | inline int count() const { | - | ||||||||||||
77 | return model()->rowCount(); never executed: return model()->rowCount(); | 0 | ||||||||||||
78 | } | - | ||||||||||||
79 | inline QString currentText() const { | - | ||||||||||||
80 | int row = QListView::currentIndex().row(); | - | ||||||||||||
81 | return row < 0 ? QString() : model()->stringList().at(row); never executed: return row < 0 ? QString() : model()->stringList().at(row);
| 0 | ||||||||||||
82 | } | - | ||||||||||||
83 | void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) Q_DECL_OVERRIDE { | - | ||||||||||||
84 | QListView::currentChanged(current, previous); | - | ||||||||||||
85 | if (current.isValid())
| 0 | ||||||||||||
86 | emit highlighted(current.row()); never executed: highlighted(current.row()); | 0 | ||||||||||||
87 | } never executed: end of block | 0 | ||||||||||||
88 | QString text(int i) const { | - | ||||||||||||
89 | return model()->stringList().at(i); never executed: return model()->stringList().at(i); | 0 | ||||||||||||
90 | } | - | ||||||||||||
91 | signals: | - | ||||||||||||
92 | void highlighted(int); | - | ||||||||||||
93 | }; | - | ||||||||||||
94 | - | |||||||||||||
95 | QFontListView::QFontListView(QWidget *parent) | - | ||||||||||||
96 | : QListView(parent) | - | ||||||||||||
97 | { | - | ||||||||||||
98 | setModel(new QStringListModel(parent)); | - | ||||||||||||
99 | setEditTriggers(NoEditTriggers); | - | ||||||||||||
100 | } never executed: end of block | 0 | ||||||||||||
101 | - | |||||||||||||
102 | static const Qt::WindowFlags DefaultWindowFlags = | - | ||||||||||||
103 | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; | - | ||||||||||||
104 | - | |||||||||||||
105 | QFontDialogPrivate::QFontDialogPrivate() | - | ||||||||||||
106 | : writingSystem(QFontDatabase::Any), | - | ||||||||||||
107 | options(QSharedPointer<QFontDialogOptions>::create()) | - | ||||||||||||
108 | { | - | ||||||||||||
109 | } never executed: end of block | 0 | ||||||||||||
110 | - | |||||||||||||
111 | QFontDialogPrivate::~QFontDialogPrivate() | - | ||||||||||||
112 | { | - | ||||||||||||
113 | } | - | ||||||||||||
114 | - | |||||||||||||
115 | /*! | - | ||||||||||||
116 | \class QFontDialog | - | ||||||||||||
117 | \ingroup standard-dialogs | - | ||||||||||||
118 | \inmodule QtWidgets | - | ||||||||||||
119 | - | |||||||||||||
120 | \brief The QFontDialog class provides a dialog widget for selecting a font. | - | ||||||||||||
121 | - | |||||||||||||
122 | A font dialog is created through one of the static getFont() | - | ||||||||||||
123 | functions. | - | ||||||||||||
124 | - | |||||||||||||
125 | Examples: | - | ||||||||||||
126 | - | |||||||||||||
127 | \snippet code/src_gui_dialogs_qfontdialog.cpp 0 | - | ||||||||||||
128 | - | |||||||||||||
129 | The dialog can also be used to set a widget's font directly: | - | ||||||||||||
130 | \snippet code/src_gui_dialogs_qfontdialog.cpp 1 | - | ||||||||||||
131 | If the user clicks OK the font they chose will be used for myWidget, | - | ||||||||||||
132 | and if they click Cancel the original font is used. | - | ||||||||||||
133 | - | |||||||||||||
134 | \image fusion-fontdialog.png A font dialog in the Fusion widget style. | - | ||||||||||||
135 | - | |||||||||||||
136 | \sa QFont, QFontInfo, QFontMetrics, QColorDialog, QFileDialog, | - | ||||||||||||
137 | {Standard Dialogs Example} | - | ||||||||||||
138 | */ | - | ||||||||||||
139 | - | |||||||||||||
140 | /*! | - | ||||||||||||
141 | \since 4.5 | - | ||||||||||||
142 | - | |||||||||||||
143 | Constructs a standard font dialog. | - | ||||||||||||
144 | - | |||||||||||||
145 | Use setCurrentFont() to set the initial font attributes. | - | ||||||||||||
146 | - | |||||||||||||
147 | The \a parent parameter is passed to the QDialog constructor. | - | ||||||||||||
148 | - | |||||||||||||
149 | \sa getFont() | - | ||||||||||||
150 | */ | - | ||||||||||||
151 | QFontDialog::QFontDialog(QWidget *parent) | - | ||||||||||||
152 | : QDialog(*new QFontDialogPrivate, parent, DefaultWindowFlags) | - | ||||||||||||
153 | { | - | ||||||||||||
154 | Q_D(QFontDialog); | - | ||||||||||||
155 | d->init(); | - | ||||||||||||
156 | } never executed: end of block | 0 | ||||||||||||
157 | - | |||||||||||||
158 | /*! | - | ||||||||||||
159 | \since 4.5 | - | ||||||||||||
160 | - | |||||||||||||
161 | Constructs a standard font dialog with the given \a parent and specified | - | ||||||||||||
162 | \a initial color. | - | ||||||||||||
163 | */ | - | ||||||||||||
164 | QFontDialog::QFontDialog(const QFont &initial, QWidget *parent) | - | ||||||||||||
165 | : QDialog(*new QFontDialogPrivate, parent, DefaultWindowFlags) | - | ||||||||||||
166 | { | - | ||||||||||||
167 | Q_D(QFontDialog); | - | ||||||||||||
168 | d->init(); | - | ||||||||||||
169 | setCurrentFont(initial); | - | ||||||||||||
170 | } never executed: end of block | 0 | ||||||||||||
171 | - | |||||||||||||
172 | void QFontDialogPrivate::init() | - | ||||||||||||
173 | { | - | ||||||||||||
174 | Q_Q(QFontDialog); | - | ||||||||||||
175 | - | |||||||||||||
176 | q->setSizeGripEnabled(true); | - | ||||||||||||
177 | q->setWindowTitle(QFontDialog::tr("Select Font")); | - | ||||||||||||
178 | - | |||||||||||||
179 | // grid | - | ||||||||||||
180 | familyEdit = new QLineEdit(q); | - | ||||||||||||
181 | familyEdit->setReadOnly(true); | - | ||||||||||||
182 | familyList = new QFontListView(q); | - | ||||||||||||
183 | familyEdit->setFocusProxy(familyList); | - | ||||||||||||
184 | - | |||||||||||||
185 | familyAccel = new QLabel(q); | - | ||||||||||||
186 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||
187 | familyAccel->setBuddy(familyList); | - | ||||||||||||
188 | #endif | - | ||||||||||||
189 | familyAccel->setIndent(2); | - | ||||||||||||
190 | - | |||||||||||||
191 | styleEdit = new QLineEdit(q); | - | ||||||||||||
192 | styleEdit->setReadOnly(true); | - | ||||||||||||
193 | styleList = new QFontListView(q); | - | ||||||||||||
194 | styleEdit->setFocusProxy(styleList); | - | ||||||||||||
195 | - | |||||||||||||
196 | styleAccel = new QLabel(q); | - | ||||||||||||
197 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||
198 | styleAccel->setBuddy(styleList); | - | ||||||||||||
199 | #endif | - | ||||||||||||
200 | styleAccel->setIndent(2); | - | ||||||||||||
201 | - | |||||||||||||
202 | sizeEdit = new QLineEdit(q); | - | ||||||||||||
203 | sizeEdit->setFocusPolicy(Qt::ClickFocus); | - | ||||||||||||
204 | QIntValidator *validator = new QIntValidator(1, 512, q); | - | ||||||||||||
205 | sizeEdit->setValidator(validator); | - | ||||||||||||
206 | sizeList = new QFontListView(q); | - | ||||||||||||
207 | - | |||||||||||||
208 | sizeAccel = new QLabel(q); | - | ||||||||||||
209 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||
210 | sizeAccel->setBuddy(sizeEdit); | - | ||||||||||||
211 | #endif | - | ||||||||||||
212 | sizeAccel->setIndent(2); | - | ||||||||||||
213 | - | |||||||||||||
214 | // effects box | - | ||||||||||||
215 | effects = new QGroupBox(q); | - | ||||||||||||
216 | QVBoxLayout *vbox = new QVBoxLayout(effects); | - | ||||||||||||
217 | strikeout = new QCheckBox(effects); | - | ||||||||||||
218 | vbox->addWidget(strikeout); | - | ||||||||||||
219 | underline = new QCheckBox(effects); | - | ||||||||||||
220 | vbox->addWidget(underline); | - | ||||||||||||
221 | - | |||||||||||||
222 | sample = new QGroupBox(q); | - | ||||||||||||
223 | QHBoxLayout *hbox = new QHBoxLayout(sample); | - | ||||||||||||
224 | sampleEdit = new QLineEdit(sample); | - | ||||||||||||
225 | sampleEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored)); | - | ||||||||||||
226 | sampleEdit->setAlignment(Qt::AlignCenter); | - | ||||||||||||
227 | // Note that the sample text is *not* translated with tr(), as the | - | ||||||||||||
228 | // characters used depend on the charset encoding. | - | ||||||||||||
229 | sampleEdit->setText(QLatin1String("AaBbYyZz")); | - | ||||||||||||
230 | hbox->addWidget(sampleEdit); | - | ||||||||||||
231 | - | |||||||||||||
232 | writingSystemCombo = new QComboBox(q); | - | ||||||||||||
233 | - | |||||||||||||
234 | writingSystemAccel = new QLabel(q); | - | ||||||||||||
235 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||
236 | writingSystemAccel->setBuddy(writingSystemCombo); | - | ||||||||||||
237 | #endif | - | ||||||||||||
238 | writingSystemAccel->setIndent(2); | - | ||||||||||||
239 | - | |||||||||||||
240 | size = 0; | - | ||||||||||||
241 | smoothScalable = false; | - | ||||||||||||
242 | - | |||||||||||||
243 | QObject::connect(writingSystemCombo, SIGNAL(activated(int)), q, SLOT(_q_writingSystemHighlighted(int))); | - | ||||||||||||
244 | QObject::connect(familyList, SIGNAL(highlighted(int)), q, SLOT(_q_familyHighlighted(int))); | - | ||||||||||||
245 | QObject::connect(styleList, SIGNAL(highlighted(int)), q, SLOT(_q_styleHighlighted(int))); | - | ||||||||||||
246 | QObject::connect(sizeList, SIGNAL(highlighted(int)), q, SLOT(_q_sizeHighlighted(int))); | - | ||||||||||||
247 | QObject::connect(sizeEdit, SIGNAL(textChanged(QString)), q, SLOT(_q_sizeChanged(QString))); | - | ||||||||||||
248 | - | |||||||||||||
249 | QObject::connect(strikeout, SIGNAL(clicked()), q, SLOT(_q_updateSample())); | - | ||||||||||||
250 | QObject::connect(underline, SIGNAL(clicked()), q, SLOT(_q_updateSample())); | - | ||||||||||||
251 | - | |||||||||||||
252 | for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
| 0 | ||||||||||||
253 | QFontDatabase::WritingSystem ws = QFontDatabase::WritingSystem(i); | - | ||||||||||||
254 | QString writingSystemName = QFontDatabase::writingSystemName(ws); | - | ||||||||||||
255 | if (writingSystemName.isEmpty())
| 0 | ||||||||||||
256 | break; never executed: break; | 0 | ||||||||||||
257 | writingSystemCombo->addItem(writingSystemName); | - | ||||||||||||
258 | } never executed: end of block | 0 | ||||||||||||
259 | - | |||||||||||||
260 | updateFamilies(); | - | ||||||||||||
261 | if (familyList->count() != 0) {
| 0 | ||||||||||||
262 | familyList->setCurrentItem(0); | - | ||||||||||||
263 | sizeList->setCurrentItem(0); | - | ||||||||||||
264 | } never executed: end of block | 0 | ||||||||||||
265 | - | |||||||||||||
266 | // grid layout | - | ||||||||||||
267 | QGridLayout *mainGrid = new QGridLayout(q); | - | ||||||||||||
268 | - | |||||||||||||
269 | int spacing = mainGrid->spacing(); | - | ||||||||||||
270 | if (spacing >= 0) { // uniform spacing
| 0 | ||||||||||||
271 | mainGrid->setSpacing(0); | - | ||||||||||||
272 | - | |||||||||||||
273 | mainGrid->setColumnMinimumWidth(1, spacing); | - | ||||||||||||
274 | mainGrid->setColumnMinimumWidth(3, spacing); | - | ||||||||||||
275 | - | |||||||||||||
276 | int margin = 0; | - | ||||||||||||
277 | mainGrid->getContentsMargins(0, 0, 0, &margin); | - | ||||||||||||
278 | - | |||||||||||||
279 | mainGrid->setRowMinimumHeight(3, margin); | - | ||||||||||||
280 | mainGrid->setRowMinimumHeight(6, 2); | - | ||||||||||||
281 | mainGrid->setRowMinimumHeight(8, margin); | - | ||||||||||||
282 | } never executed: end of block | 0 | ||||||||||||
283 | - | |||||||||||||
284 | mainGrid->addWidget(familyAccel, 0, 0); | - | ||||||||||||
285 | mainGrid->addWidget(familyEdit, 1, 0); | - | ||||||||||||
286 | mainGrid->addWidget(familyList, 2, 0); | - | ||||||||||||
287 | - | |||||||||||||
288 | mainGrid->addWidget(styleAccel, 0, 2); | - | ||||||||||||
289 | mainGrid->addWidget(styleEdit, 1, 2); | - | ||||||||||||
290 | mainGrid->addWidget(styleList, 2, 2); | - | ||||||||||||
291 | - | |||||||||||||
292 | mainGrid->addWidget(sizeAccel, 0, 4); | - | ||||||||||||
293 | mainGrid->addWidget(sizeEdit, 1, 4); | - | ||||||||||||
294 | mainGrid->addWidget(sizeList, 2, 4); | - | ||||||||||||
295 | - | |||||||||||||
296 | mainGrid->setColumnStretch(0, 38); | - | ||||||||||||
297 | mainGrid->setColumnStretch(2, 24); | - | ||||||||||||
298 | mainGrid->setColumnStretch(4, 10); | - | ||||||||||||
299 | - | |||||||||||||
300 | mainGrid->addWidget(effects, 4, 0); | - | ||||||||||||
301 | - | |||||||||||||
302 | mainGrid->addWidget(sample, 4, 2, 4, 3); | - | ||||||||||||
303 | - | |||||||||||||
304 | mainGrid->addWidget(writingSystemAccel, 5, 0); | - | ||||||||||||
305 | mainGrid->addWidget(writingSystemCombo, 7, 0); | - | ||||||||||||
306 | - | |||||||||||||
307 | buttonBox = new QDialogButtonBox(q); | - | ||||||||||||
308 | mainGrid->addWidget(buttonBox, 9, 0, 1, 5); | - | ||||||||||||
309 | - | |||||||||||||
310 | QPushButton *button | - | ||||||||||||
311 | = static_cast<QPushButton *>(buttonBox->addButton(QDialogButtonBox::Ok)); | - | ||||||||||||
312 | QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept())); | - | ||||||||||||
313 | button->setDefault(true); | - | ||||||||||||
314 | - | |||||||||||||
315 | buttonBox->addButton(QDialogButtonBox::Cancel); | - | ||||||||||||
316 | QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject())); | - | ||||||||||||
317 | - | |||||||||||||
318 | #if defined(Q_OS_WINCE) | - | ||||||||||||
319 | q->resize(180, 120); | - | ||||||||||||
320 | #else | - | ||||||||||||
321 | q->resize(500, 360); | - | ||||||||||||
322 | #endif // Q_OS_WINCE | - | ||||||||||||
323 | - | |||||||||||||
324 | sizeEdit->installEventFilter(q); | - | ||||||||||||
325 | familyList->installEventFilter(q); | - | ||||||||||||
326 | styleList->installEventFilter(q); | - | ||||||||||||
327 | sizeList->installEventFilter(q); | - | ||||||||||||
328 | - | |||||||||||||
329 | familyList->setFocus(); | - | ||||||||||||
330 | retranslateStrings(); | - | ||||||||||||
331 | sampleEdit->setObjectName(QLatin1String("qt_fontDialog_sampleEdit")); | - | ||||||||||||
332 | } never executed: end of block | 0 | ||||||||||||
333 | - | |||||||||||||
334 | /*! | - | ||||||||||||
335 | \internal | - | ||||||||||||
336 | Destroys the font dialog and frees up its storage. | - | ||||||||||||
337 | */ | - | ||||||||||||
338 | - | |||||||||||||
339 | QFontDialog::~QFontDialog() | - | ||||||||||||
340 | { | - | ||||||||||||
341 | } | - | ||||||||||||
342 | - | |||||||||||||
343 | /*! | - | ||||||||||||
344 | Executes a modal font dialog and returns a font. | - | ||||||||||||
345 | - | |||||||||||||
346 | If the user clicks \uicontrol OK, the selected font is returned. If the user | - | ||||||||||||
347 | clicks \uicontrol Cancel, the \a initial font is returned. | - | ||||||||||||
348 | - | |||||||||||||
349 | The dialog is constructed with the given \a parent and the options specified | - | ||||||||||||
350 | in \a options. \a title is shown as the window title of the dialog and \a | - | ||||||||||||
351 | initial is the initially selected font. If the \a ok parameter is not-null, | - | ||||||||||||
352 | the value it refers to is set to true if the user clicks \uicontrol OK, and set to | - | ||||||||||||
353 | false if the user clicks \uicontrol Cancel. | - | ||||||||||||
354 | - | |||||||||||||
355 | Examples: | - | ||||||||||||
356 | \snippet code/src_gui_dialogs_qfontdialog.cpp 2 | - | ||||||||||||
357 | - | |||||||||||||
358 | The dialog can also be used to set a widget's font directly: | - | ||||||||||||
359 | \snippet code/src_gui_dialogs_qfontdialog.cpp 3 | - | ||||||||||||
360 | In this example, if the user clicks OK the font they chose will be | - | ||||||||||||
361 | used, and if they click Cancel the original font is used. | - | ||||||||||||
362 | - | |||||||||||||
363 | \warning Do not delete \a parent during the execution of the dialog. | - | ||||||||||||
364 | If you want to do this, you should create the dialog | - | ||||||||||||
365 | yourself using one of the QFontDialog constructors. | - | ||||||||||||
366 | */ | - | ||||||||||||
367 | QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title, | - | ||||||||||||
368 | FontDialogOptions options) | - | ||||||||||||
369 | { | - | ||||||||||||
370 | return QFontDialogPrivate::getFont(ok, initial, parent, title, options); never executed: return QFontDialogPrivate::getFont(ok, initial, parent, title, options); | 0 | ||||||||||||
371 | } | - | ||||||||||||
372 | - | |||||||||||||
373 | /*! | - | ||||||||||||
374 | \overload | - | ||||||||||||
375 | - | |||||||||||||
376 | Executes a modal font dialog and returns a font. | - | ||||||||||||
377 | - | |||||||||||||
378 | If the user clicks \uicontrol OK, the selected font is returned. If the user | - | ||||||||||||
379 | clicks \uicontrol Cancel, the Qt default font is returned. | - | ||||||||||||
380 | - | |||||||||||||
381 | The dialog is constructed with the given \a parent. | - | ||||||||||||
382 | If the \a ok parameter is not-null, the value it refers to is set | - | ||||||||||||
383 | to true if the user clicks \uicontrol OK, and false if the user clicks | - | ||||||||||||
384 | \uicontrol Cancel. | - | ||||||||||||
385 | - | |||||||||||||
386 | Example: | - | ||||||||||||
387 | \snippet code/src_gui_dialogs_qfontdialog.cpp 4 | - | ||||||||||||
388 | - | |||||||||||||
389 | \warning Do not delete \a parent during the execution of the dialog. | - | ||||||||||||
390 | If you want to do this, you should create the dialog | - | ||||||||||||
391 | yourself using one of the QFontDialog constructors. | - | ||||||||||||
392 | */ | - | ||||||||||||
393 | QFont QFontDialog::getFont(bool *ok, QWidget *parent) | - | ||||||||||||
394 | { | - | ||||||||||||
395 | QFont initial; | - | ||||||||||||
396 | return QFontDialogPrivate::getFont(ok, initial, parent, QString(), 0); never executed: return QFontDialogPrivate::getFont(ok, initial, parent, QString(), 0); | 0 | ||||||||||||
397 | } | - | ||||||||||||
398 | - | |||||||||||||
399 | QFont QFontDialogPrivate::getFont(bool *ok, const QFont &initial, QWidget *parent, | - | ||||||||||||
400 | const QString &title, QFontDialog::FontDialogOptions options) | - | ||||||||||||
401 | { | - | ||||||||||||
402 | QFontDialog dlg(parent); | - | ||||||||||||
403 | dlg.setOptions(options); | - | ||||||||||||
404 | dlg.setCurrentFont(initial); | - | ||||||||||||
405 | if (!title.isEmpty())
| 0 | ||||||||||||
406 | dlg.setWindowTitle(title); never executed: dlg.setWindowTitle(title); | 0 | ||||||||||||
407 | - | |||||||||||||
408 | int ret = (dlg.exec() || (options & QFontDialog::NoButtons));
| 0 | ||||||||||||
409 | if (ok)
| 0 | ||||||||||||
410 | *ok = !!ret; never executed: *ok = !!ret; | 0 | ||||||||||||
411 | if (ret) {
| 0 | ||||||||||||
412 | return dlg.selectedFont(); never executed: return dlg.selectedFont(); | 0 | ||||||||||||
413 | } else { | - | ||||||||||||
414 | return initial; never executed: return initial; | 0 | ||||||||||||
415 | } | - | ||||||||||||
416 | } | - | ||||||||||||
417 | - | |||||||||||||
418 | /*! | - | ||||||||||||
419 | \internal | - | ||||||||||||
420 | An event filter to make the Up, Down, PageUp and PageDown keys work | - | ||||||||||||
421 | correctly in the line edits. The source of the event is the object | - | ||||||||||||
422 | \a o and the event is \a e. | - | ||||||||||||
423 | */ | - | ||||||||||||
424 | - | |||||||||||||
425 | bool QFontDialog::eventFilter(QObject *o , QEvent *e) | - | ||||||||||||
426 | { | - | ||||||||||||
427 | Q_D(QFontDialog); | - | ||||||||||||
428 | if (e->type() == QEvent::KeyPress) {
| 0 | ||||||||||||
429 | QKeyEvent *k = (QKeyEvent *)e; | - | ||||||||||||
430 | if (o == d->sizeEdit &&
| 0 | ||||||||||||
431 | (k->key() == Qt::Key_Up ||
| 0 | ||||||||||||
432 | k->key() == Qt::Key_Down ||
| 0 | ||||||||||||
433 | k->key() == Qt::Key_PageUp ||
| 0 | ||||||||||||
434 | k->key() == Qt::Key_PageDown)) {
| 0 | ||||||||||||
435 | - | |||||||||||||
436 | int ci = d->sizeList->currentItem(); | - | ||||||||||||
437 | (void)QApplication::sendEvent(d->sizeList, k); | - | ||||||||||||
438 | - | |||||||||||||
439 | if (ci != d->sizeList->currentItem()
| 0 | ||||||||||||
440 | && style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, this))
| 0 | ||||||||||||
441 | d->sizeEdit->selectAll(); never executed: d->sizeEdit->selectAll(); | 0 | ||||||||||||
442 | return true; never executed: return true; | 0 | ||||||||||||
443 | } else if ((o == d->familyList || o == d->styleList) &&
| 0 | ||||||||||||
444 | (k->key() == Qt::Key_Return || k->key() == Qt::Key_Enter)) {
| 0 | ||||||||||||
445 | k->accept(); | - | ||||||||||||
446 | accept(); | - | ||||||||||||
447 | return true; never executed: return true; | 0 | ||||||||||||
448 | } | - | ||||||||||||
449 | } else if (e->type() == QEvent::FocusIn never executed: end of block
| 0 | ||||||||||||
450 | && style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, this)) {
| 0 | ||||||||||||
451 | if (o == d->familyList)
| 0 | ||||||||||||
452 | d->familyEdit->selectAll(); never executed: d->familyEdit->selectAll(); | 0 | ||||||||||||
453 | else if (o == d->styleList)
| 0 | ||||||||||||
454 | d->styleEdit->selectAll(); never executed: d->styleEdit->selectAll(); | 0 | ||||||||||||
455 | else if (o == d->sizeList)
| 0 | ||||||||||||
456 | d->sizeEdit->selectAll(); never executed: d->sizeEdit->selectAll(); | 0 | ||||||||||||
457 | } else if (e->type() == QEvent::MouseButtonPress && o == d->sizeList) { never executed: end of block
| 0 | ||||||||||||
458 | d->sizeEdit->setFocus(); | - | ||||||||||||
459 | } never executed: end of block | 0 | ||||||||||||
460 | return QDialog::eventFilter(o, e); never executed: return QDialog::eventFilter(o, e); | 0 | ||||||||||||
461 | } | - | ||||||||||||
462 | - | |||||||||||||
463 | void QFontDialogPrivate::initHelper(QPlatformDialogHelper *h) | - | ||||||||||||
464 | { | - | ||||||||||||
465 | QFontDialog *d = q_func(); | - | ||||||||||||
466 | QObject::connect(h, SIGNAL(currentFontChanged(QFont)), d, SIGNAL(currentFontChanged(QFont))); | - | ||||||||||||
467 | QObject::connect(h, SIGNAL(fontSelected(QFont)), d, SIGNAL(fontSelected(QFont))); | - | ||||||||||||
468 | static_cast<QPlatformFontDialogHelper *>(h)->setOptions(options); | - | ||||||||||||
469 | } never executed: end of block | 0 | ||||||||||||
470 | - | |||||||||||||
471 | void QFontDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) | - | ||||||||||||
472 | { | - | ||||||||||||
473 | options->setWindowTitle(q_func()->windowTitle()); | - | ||||||||||||
474 | } never executed: end of block | 0 | ||||||||||||
475 | - | |||||||||||||
476 | /* | - | ||||||||||||
477 | Updates the contents of the "font family" list box. This | - | ||||||||||||
478 | function can be reimplemented if you have special requirements. | - | ||||||||||||
479 | */ | - | ||||||||||||
480 | - | |||||||||||||
481 | void QFontDialogPrivate::updateFamilies() | - | ||||||||||||
482 | { | - | ||||||||||||
483 | Q_Q(QFontDialog); | - | ||||||||||||
484 | - | |||||||||||||
485 | enum match_t { MATCH_NONE = 0, MATCH_LAST_RESORT = 1, MATCH_APP = 2, MATCH_FAMILY = 3 }; | - | ||||||||||||
486 | - | |||||||||||||
487 | const QFontDialog::FontDialogOptions scalableMask = (QFontDialog::ScalableFonts | QFontDialog::NonScalableFonts); | - | ||||||||||||
488 | const QFontDialog::FontDialogOptions spacingMask = (QFontDialog::ProportionalFonts | QFontDialog::MonospacedFonts); | - | ||||||||||||
489 | const QFontDialog::FontDialogOptions options = q->options(); | - | ||||||||||||
490 | - | |||||||||||||
491 | QFontDatabase fdb; | - | ||||||||||||
492 | - | |||||||||||||
493 | QStringList familyNames; | - | ||||||||||||
494 | foreach (const QString &family, fdb.families(writingSystem)) { | - | ||||||||||||
495 | if (fdb.isPrivateFamily(family))
| 0 | ||||||||||||
496 | continue; never executed: continue; | 0 | ||||||||||||
497 | - | |||||||||||||
498 | if ((options & scalableMask) && (options & scalableMask) != scalableMask) {
| 0 | ||||||||||||
499 | if (bool(options & QFontDialog::ScalableFonts) != fdb.isSmoothlyScalable(family))
| 0 | ||||||||||||
500 | continue; never executed: continue; | 0 | ||||||||||||
501 | } never executed: end of block | 0 | ||||||||||||
502 | if ((options & spacingMask) && (options & spacingMask) != spacingMask) {
| 0 | ||||||||||||
503 | if (bool(options & QFontDialog::MonospacedFonts) != fdb.isFixedPitch(family))
| 0 | ||||||||||||
504 | continue; never executed: continue; | 0 | ||||||||||||
505 | } never executed: end of block | 0 | ||||||||||||
506 | familyNames << family; | - | ||||||||||||
507 | } never executed: end of block | 0 | ||||||||||||
508 | - | |||||||||||||
509 | familyList->model()->setStringList(familyNames); | - | ||||||||||||
510 | - | |||||||||||||
511 | QString foundryName1, familyName1, foundryName2, familyName2; | - | ||||||||||||
512 | int bestFamilyMatch = -1; | - | ||||||||||||
513 | match_t bestFamilyType = MATCH_NONE; | - | ||||||||||||
514 | - | |||||||||||||
515 | QFont f; | - | ||||||||||||
516 | - | |||||||||||||
517 | // ##### do the right thing for a list of family names in the font. | - | ||||||||||||
518 | QFontDatabase::parseFontName(family, foundryName1, familyName1); | - | ||||||||||||
519 | - | |||||||||||||
520 | QStringList::const_iterator it = familyNames.constBegin(); | - | ||||||||||||
521 | int i = 0; | - | ||||||||||||
522 | for(; it != familyNames.constEnd(); ++it, ++i) {
| 0 | ||||||||||||
523 | QFontDatabase::parseFontName(*it, foundryName2, familyName2); | - | ||||||||||||
524 | - | |||||||||||||
525 | //try to match... | - | ||||||||||||
526 | if (familyName1 == familyName2) {
| 0 | ||||||||||||
527 | bestFamilyType = MATCH_FAMILY; | - | ||||||||||||
528 | if (foundryName1 == foundryName2) {
| 0 | ||||||||||||
529 | bestFamilyMatch = i; | - | ||||||||||||
530 | break; never executed: break; | 0 | ||||||||||||
531 | } | - | ||||||||||||
532 | if (bestFamilyMatch < MATCH_FAMILY)
| 0 | ||||||||||||
533 | bestFamilyMatch = i; never executed: bestFamilyMatch = i; | 0 | ||||||||||||
534 | } never executed: end of block | 0 | ||||||||||||
535 | - | |||||||||||||
536 | //and try some fall backs | - | ||||||||||||
537 | match_t type = MATCH_NONE; | - | ||||||||||||
538 | if (bestFamilyType <= MATCH_NONE && familyName2 == f.lastResortFamily())
| 0 | ||||||||||||
539 | type = MATCH_LAST_RESORT; never executed: type = MATCH_LAST_RESORT; | 0 | ||||||||||||
540 | if (bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.family())
| 0 | ||||||||||||
541 | type = MATCH_APP; never executed: type = MATCH_APP; | 0 | ||||||||||||
542 | // ### add fallback for writingSystem | - | ||||||||||||
543 | if (type != MATCH_NONE) {
| 0 | ||||||||||||
544 | bestFamilyType = type; | - | ||||||||||||
545 | bestFamilyMatch = i; | - | ||||||||||||
546 | } never executed: end of block | 0 | ||||||||||||
547 | } never executed: end of block | 0 | ||||||||||||
548 | - | |||||||||||||
549 | if (i != -1 && bestFamilyType != MATCH_NONE)
| 0 | ||||||||||||
550 | familyList->setCurrentItem(bestFamilyMatch); never executed: familyList->setCurrentItem(bestFamilyMatch); | 0 | ||||||||||||
551 | else | - | ||||||||||||
552 | familyList->setCurrentItem(0); never executed: familyList->setCurrentItem(0); | 0 | ||||||||||||
553 | familyEdit->setText(familyList->currentText()); | - | ||||||||||||
554 | if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
| 0 | ||||||||||||
555 | && familyList->hasFocus())
| 0 | ||||||||||||
556 | familyEdit->selectAll(); never executed: familyEdit->selectAll(); | 0 | ||||||||||||
557 | - | |||||||||||||
558 | updateStyles(); | - | ||||||||||||
559 | } never executed: end of block | 0 | ||||||||||||
560 | - | |||||||||||||
561 | /* | - | ||||||||||||
562 | Updates the contents of the "font style" list box. This | - | ||||||||||||
563 | function can be reimplemented if you have special requirements. | - | ||||||||||||
564 | */ | - | ||||||||||||
565 | void QFontDialogPrivate::updateStyles() | - | ||||||||||||
566 | { | - | ||||||||||||
567 | Q_Q(QFontDialog); | - | ||||||||||||
568 | QStringList styles = fdb.styles(familyList->currentText()); | - | ||||||||||||
569 | styleList->model()->setStringList(styles); | - | ||||||||||||
570 | - | |||||||||||||
571 | if (styles.isEmpty()) {
| 0 | ||||||||||||
572 | styleEdit->clear(); | - | ||||||||||||
573 | smoothScalable = false; | - | ||||||||||||
574 | } else { never executed: end of block | 0 | ||||||||||||
575 | if (!style.isEmpty()) {
| 0 | ||||||||||||
576 | bool found = false; | - | ||||||||||||
577 | bool first = true; | - | ||||||||||||
578 | QString cstyle = style; | - | ||||||||||||
579 | - | |||||||||||||
580 | redo: code before this statement never executed: redo: | 0 | ||||||||||||
581 | for (int i = 0; i < (int)styleList->count(); i++) {
| 0 | ||||||||||||
582 | if (cstyle == styleList->text(i)) {
| 0 | ||||||||||||
583 | styleList->setCurrentItem(i); | - | ||||||||||||
584 | found = true; | - | ||||||||||||
585 | break; never executed: break; | 0 | ||||||||||||
586 | } | - | ||||||||||||
587 | } never executed: end of block | 0 | ||||||||||||
588 | if (!found && first) {
| 0 | ||||||||||||
589 | if (cstyle.contains(QLatin1String("Italic"))) {
| 0 | ||||||||||||
590 | cstyle.replace(QLatin1String("Italic"), QLatin1String("Oblique")); | - | ||||||||||||
591 | first = false; | - | ||||||||||||
592 | goto redo; never executed: goto redo; | 0 | ||||||||||||
593 | } else if (cstyle.contains(QLatin1String("Oblique"))) {
| 0 | ||||||||||||
594 | cstyle.replace(QLatin1String("Oblique"), QLatin1String("Italic")); | - | ||||||||||||
595 | first = false; | - | ||||||||||||
596 | goto redo; never executed: goto redo; | 0 | ||||||||||||
597 | } | - | ||||||||||||
598 | } never executed: end of block | 0 | ||||||||||||
599 | if (!found)
| 0 | ||||||||||||
600 | styleList->setCurrentItem(0); never executed: styleList->setCurrentItem(0); | 0 | ||||||||||||
601 | } else { never executed: end of block | 0 | ||||||||||||
602 | styleList->setCurrentItem(0); | - | ||||||||||||
603 | } never executed: end of block | 0 | ||||||||||||
604 | - | |||||||||||||
605 | styleEdit->setText(styleList->currentText()); | - | ||||||||||||
606 | if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
| 0 | ||||||||||||
607 | && styleList->hasFocus())
| 0 | ||||||||||||
608 | styleEdit->selectAll(); never executed: styleEdit->selectAll(); | 0 | ||||||||||||
609 | - | |||||||||||||
610 | smoothScalable = fdb.isSmoothlyScalable(familyList->currentText(), styleList->currentText()); | - | ||||||||||||
611 | } never executed: end of block | 0 | ||||||||||||
612 | - | |||||||||||||
613 | updateSizes(); | - | ||||||||||||
614 | } never executed: end of block | 0 | ||||||||||||
615 | - | |||||||||||||
616 | /*! | - | ||||||||||||
617 | \internal | - | ||||||||||||
618 | Updates the contents of the "font size" list box. This | - | ||||||||||||
619 | function can be reimplemented if you have special requirements. | - | ||||||||||||
620 | */ | - | ||||||||||||
621 | - | |||||||||||||
622 | void QFontDialogPrivate::updateSizes() | - | ||||||||||||
623 | { | - | ||||||||||||
624 | Q_Q(QFontDialog); | - | ||||||||||||
625 | - | |||||||||||||
626 | if (!familyList->currentText().isEmpty()) {
| 0 | ||||||||||||
627 | QList<int> sizes = fdb.pointSizes(familyList->currentText(), styleList->currentText()); | - | ||||||||||||
628 | - | |||||||||||||
629 | int i = 0; | - | ||||||||||||
630 | int current = -1; | - | ||||||||||||
631 | QStringList str_sizes; | - | ||||||||||||
632 | str_sizes.reserve(sizes.size()); | - | ||||||||||||
633 | for(QList<int>::const_iterator it = sizes.constBegin(); it != sizes.constEnd(); ++it) {
| 0 | ||||||||||||
634 | str_sizes.append(QString::number(*it)); | - | ||||||||||||
635 | if (current == -1 && *it == size)
| 0 | ||||||||||||
636 | current = i; never executed: current = i; | 0 | ||||||||||||
637 | ++i; | - | ||||||||||||
638 | } never executed: end of block | 0 | ||||||||||||
639 | sizeList->model()->setStringList(str_sizes); | - | ||||||||||||
640 | if (current != -1)
| 0 | ||||||||||||
641 | sizeList->setCurrentItem(current); never executed: sizeList->setCurrentItem(current); | 0 | ||||||||||||
642 | - | |||||||||||||
643 | const QSignalBlocker blocker(sizeEdit); | - | ||||||||||||
644 | sizeEdit->setText((smoothScalable ? QString::number(size) : sizeList->currentText())); | - | ||||||||||||
645 | if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
| 0 | ||||||||||||
646 | && sizeList->hasFocus())
| 0 | ||||||||||||
647 | sizeEdit->selectAll(); never executed: sizeEdit->selectAll(); | 0 | ||||||||||||
648 | } else { never executed: end of block | 0 | ||||||||||||
649 | sizeEdit->clear(); | - | ||||||||||||
650 | } never executed: end of block | 0 | ||||||||||||
651 | - | |||||||||||||
652 | _q_updateSample(); | - | ||||||||||||
653 | } never executed: end of block | 0 | ||||||||||||
654 | - | |||||||||||||
655 | void QFontDialogPrivate::_q_updateSample() | - | ||||||||||||
656 | { | - | ||||||||||||
657 | // compute new font | - | ||||||||||||
658 | int pSize = sizeEdit->text().toInt(); | - | ||||||||||||
659 | QFont newFont(fdb.font(familyList->currentText(), style, pSize)); | - | ||||||||||||
660 | newFont.setStrikeOut(strikeout->isChecked()); | - | ||||||||||||
661 | newFont.setUnderline(underline->isChecked()); | - | ||||||||||||
662 | - | |||||||||||||
663 | if (familyList->currentText().isEmpty())
| 0 | ||||||||||||
664 | sampleEdit->clear(); never executed: sampleEdit->clear(); | 0 | ||||||||||||
665 | - | |||||||||||||
666 | updateSampleFont(newFont); | - | ||||||||||||
667 | } never executed: end of block | 0 | ||||||||||||
668 | - | |||||||||||||
669 | void QFontDialogPrivate::updateSampleFont(const QFont &newFont) | - | ||||||||||||
670 | { | - | ||||||||||||
671 | Q_Q(QFontDialog); | - | ||||||||||||
672 | if (newFont != sampleEdit->font()) {
| 0 | ||||||||||||
673 | sampleEdit->setFont(newFont); | - | ||||||||||||
674 | emit q->currentFontChanged(newFont); | - | ||||||||||||
675 | } never executed: end of block | 0 | ||||||||||||
676 | } never executed: end of block | 0 | ||||||||||||
677 | - | |||||||||||||
678 | /*! | - | ||||||||||||
679 | \internal | - | ||||||||||||
680 | */ | - | ||||||||||||
681 | void QFontDialogPrivate::_q_writingSystemHighlighted(int index) | - | ||||||||||||
682 | { | - | ||||||||||||
683 | writingSystem = QFontDatabase::WritingSystem(index); | - | ||||||||||||
684 | sampleEdit->setText(fdb.writingSystemSample(writingSystem)); | - | ||||||||||||
685 | updateFamilies(); | - | ||||||||||||
686 | } never executed: end of block | 0 | ||||||||||||
687 | - | |||||||||||||
688 | /*! | - | ||||||||||||
689 | \internal | - | ||||||||||||
690 | */ | - | ||||||||||||
691 | void QFontDialogPrivate::_q_familyHighlighted(int i) | - | ||||||||||||
692 | { | - | ||||||||||||
693 | Q_Q(QFontDialog); | - | ||||||||||||
694 | family = familyList->text(i); | - | ||||||||||||
695 | familyEdit->setText(family); | - | ||||||||||||
696 | if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
| 0 | ||||||||||||
697 | && familyList->hasFocus())
| 0 | ||||||||||||
698 | familyEdit->selectAll(); never executed: familyEdit->selectAll(); | 0 | ||||||||||||
699 | - | |||||||||||||
700 | updateStyles(); | - | ||||||||||||
701 | } never executed: end of block | 0 | ||||||||||||
702 | - | |||||||||||||
703 | - | |||||||||||||
704 | /*! | - | ||||||||||||
705 | \internal | - | ||||||||||||
706 | */ | - | ||||||||||||
707 | - | |||||||||||||
708 | void QFontDialogPrivate::_q_styleHighlighted(int index) | - | ||||||||||||
709 | { | - | ||||||||||||
710 | Q_Q(QFontDialog); | - | ||||||||||||
711 | QString s = styleList->text(index); | - | ||||||||||||
712 | styleEdit->setText(s); | - | ||||||||||||
713 | if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
| 0 | ||||||||||||
714 | && styleList->hasFocus())
| 0 | ||||||||||||
715 | styleEdit->selectAll(); never executed: styleEdit->selectAll(); | 0 | ||||||||||||
716 | - | |||||||||||||
717 | style = s; | - | ||||||||||||
718 | - | |||||||||||||
719 | updateSizes(); | - | ||||||||||||
720 | } never executed: end of block | 0 | ||||||||||||
721 | - | |||||||||||||
722 | - | |||||||||||||
723 | /*! | - | ||||||||||||
724 | \internal | - | ||||||||||||
725 | */ | - | ||||||||||||
726 | - | |||||||||||||
727 | void QFontDialogPrivate::_q_sizeHighlighted(int index) | - | ||||||||||||
728 | { | - | ||||||||||||
729 | Q_Q(QFontDialog); | - | ||||||||||||
730 | QString s = sizeList->text(index); | - | ||||||||||||
731 | sizeEdit->setText(s); | - | ||||||||||||
732 | if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
| 0 | ||||||||||||
733 | && sizeEdit->hasFocus())
| 0 | ||||||||||||
734 | sizeEdit->selectAll(); never executed: sizeEdit->selectAll(); | 0 | ||||||||||||
735 | - | |||||||||||||
736 | size = s.toInt(); | - | ||||||||||||
737 | _q_updateSample(); | - | ||||||||||||
738 | } never executed: end of block | 0 | ||||||||||||
739 | - | |||||||||||||
740 | /*! | - | ||||||||||||
741 | \internal | - | ||||||||||||
742 | This slot is called if the user changes the font size. | - | ||||||||||||
743 | The size is passed in the \a s argument as a \e string. | - | ||||||||||||
744 | */ | - | ||||||||||||
745 | - | |||||||||||||
746 | void QFontDialogPrivate::_q_sizeChanged(const QString &s) | - | ||||||||||||
747 | { | - | ||||||||||||
748 | // no need to check if the conversion is valid, since we have an QIntValidator in the size edit | - | ||||||||||||
749 | int size = s.toInt(); | - | ||||||||||||
750 | if (this->size == size)
| 0 | ||||||||||||
751 | return; never executed: return; | 0 | ||||||||||||
752 | - | |||||||||||||
753 | this->size = size; | - | ||||||||||||
754 | if (sizeList->count() != 0) {
| 0 | ||||||||||||
755 | int i; | - | ||||||||||||
756 | for (i = 0; i < sizeList->count() - 1; i++) {
| 0 | ||||||||||||
757 | if (sizeList->text(i).toInt() >= this->size)
| 0 | ||||||||||||
758 | break; never executed: break; | 0 | ||||||||||||
759 | } never executed: end of block | 0 | ||||||||||||
760 | const QSignalBlocker blocker(sizeList); | - | ||||||||||||
761 | if (sizeList->text(i).toInt() == this->size)
| 0 | ||||||||||||
762 | sizeList->setCurrentItem(i); never executed: sizeList->setCurrentItem(i); | 0 | ||||||||||||
763 | else | - | ||||||||||||
764 | sizeList->clearSelection(); never executed: sizeList->clearSelection(); | 0 | ||||||||||||
765 | } | - | ||||||||||||
766 | _q_updateSample(); | - | ||||||||||||
767 | } never executed: end of block | 0 | ||||||||||||
768 | - | |||||||||||||
769 | void QFontDialogPrivate::retranslateStrings() | - | ||||||||||||
770 | { | - | ||||||||||||
771 | familyAccel->setText(QFontDialog::tr("&Font")); | - | ||||||||||||
772 | styleAccel->setText(QFontDialog::tr("Font st&yle")); | - | ||||||||||||
773 | sizeAccel->setText(QFontDialog::tr("&Size")); | - | ||||||||||||
774 | effects->setTitle(QFontDialog::tr("Effects")); | - | ||||||||||||
775 | strikeout->setText(QFontDialog::tr("Stri&keout")); | - | ||||||||||||
776 | underline->setText(QFontDialog::tr("&Underline")); | - | ||||||||||||
777 | sample->setTitle(QFontDialog::tr("Sample")); | - | ||||||||||||
778 | writingSystemAccel->setText(QFontDialog::tr("Wr&iting System")); | - | ||||||||||||
779 | } never executed: end of block | 0 | ||||||||||||
780 | - | |||||||||||||
781 | /*! | - | ||||||||||||
782 | \reimp | - | ||||||||||||
783 | */ | - | ||||||||||||
784 | void QFontDialog::changeEvent(QEvent *e) | - | ||||||||||||
785 | { | - | ||||||||||||
786 | Q_D(QFontDialog); | - | ||||||||||||
787 | if (e->type() == QEvent::LanguageChange) {
| 0 | ||||||||||||
788 | d->retranslateStrings(); | - | ||||||||||||
789 | } never executed: end of block | 0 | ||||||||||||
790 | QDialog::changeEvent(e); | - | ||||||||||||
791 | } never executed: end of block | 0 | ||||||||||||
792 | - | |||||||||||||
793 | /*! | - | ||||||||||||
794 | \since 4.5 | - | ||||||||||||
795 | - | |||||||||||||
796 | \property QFontDialog::currentFont | - | ||||||||||||
797 | \brief the current font of the dialog. | - | ||||||||||||
798 | */ | - | ||||||||||||
799 | - | |||||||||||||
800 | /*! | - | ||||||||||||
801 | \since 4.5 | - | ||||||||||||
802 | - | |||||||||||||
803 | Sets the font highlighted in the QFontDialog to the given \a font. | - | ||||||||||||
804 | - | |||||||||||||
805 | \sa selectedFont() | - | ||||||||||||
806 | */ | - | ||||||||||||
807 | void QFontDialog::setCurrentFont(const QFont &font) | - | ||||||||||||
808 | { | - | ||||||||||||
809 | Q_D(QFontDialog); | - | ||||||||||||
810 | d->family = font.family(); | - | ||||||||||||
811 | d->style = d->fdb.styleString(font); | - | ||||||||||||
812 | d->size = font.pointSize(); | - | ||||||||||||
813 | if (d->size == -1) {
| 0 | ||||||||||||
814 | QFontInfo fi(font); | - | ||||||||||||
815 | d->size = fi.pointSize(); | - | ||||||||||||
816 | } never executed: end of block | 0 | ||||||||||||
817 | d->strikeout->setChecked(font.strikeOut()); | - | ||||||||||||
818 | d->underline->setChecked(font.underline()); | - | ||||||||||||
819 | d->updateFamilies(); | - | ||||||||||||
820 | if (d->canBeNativeDialog()) {
| 0 | ||||||||||||
821 | if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
| 0 | ||||||||||||
822 | helper->setCurrentFont(font); never executed: helper->setCurrentFont(font); | 0 | ||||||||||||
823 | } never executed: end of block | 0 | ||||||||||||
824 | } never executed: end of block | 0 | ||||||||||||
825 | - | |||||||||||||
826 | /*! | - | ||||||||||||
827 | \since 4.5 | - | ||||||||||||
828 | - | |||||||||||||
829 | Returns the current font. | - | ||||||||||||
830 | - | |||||||||||||
831 | \sa selectedFont() | - | ||||||||||||
832 | */ | - | ||||||||||||
833 | QFont QFontDialog::currentFont() const | - | ||||||||||||
834 | { | - | ||||||||||||
835 | Q_D(const QFontDialog); | - | ||||||||||||
836 | if (d->canBeNativeDialog()) {
| 0 | ||||||||||||
837 | if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
| 0 | ||||||||||||
838 | return helper->currentFont(); never executed: return helper->currentFont(); | 0 | ||||||||||||
839 | } never executed: end of block | 0 | ||||||||||||
840 | return d->sampleEdit->font(); never executed: return d->sampleEdit->font(); | 0 | ||||||||||||
841 | } | - | ||||||||||||
842 | - | |||||||||||||
843 | /*! | - | ||||||||||||
844 | Returns the font that the user selected by clicking the \uicontrol{OK} | - | ||||||||||||
845 | or equivalent button. | - | ||||||||||||
846 | - | |||||||||||||
847 | \note This font is not always the same as the font held by the | - | ||||||||||||
848 | \l currentFont property since the user can choose different fonts | - | ||||||||||||
849 | before finally selecting the one to use. | - | ||||||||||||
850 | */ | - | ||||||||||||
851 | QFont QFontDialog::selectedFont() const | - | ||||||||||||
852 | { | - | ||||||||||||
853 | Q_D(const QFontDialog); | - | ||||||||||||
854 | return d->selectedFont; never executed: return d->selectedFont; | 0 | ||||||||||||
855 | } | - | ||||||||||||
856 | - | |||||||||||||
857 | /*! | - | ||||||||||||
858 | \enum QFontDialog::FontDialogOption | - | ||||||||||||
859 | \since 4.5 | - | ||||||||||||
860 | - | |||||||||||||
861 | This enum specifies various options that affect the look and feel | - | ||||||||||||
862 | of a font dialog. | - | ||||||||||||
863 | - | |||||||||||||
864 | For instance, it allows to specify which type of font should be | - | ||||||||||||
865 | displayed. If none are specified all fonts available will be listed. | - | ||||||||||||
866 | - | |||||||||||||
867 | Note that the font filtering options might not be supported on some | - | ||||||||||||
868 | platforms (e.g. Mac). They are always supported by the non native | - | ||||||||||||
869 | dialog (used on Windows or Linux). | - | ||||||||||||
870 | - | |||||||||||||
871 | \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".) | - | ||||||||||||
872 | \value DontUseNativeDialog Use Qt's standard font dialog on the Mac instead of Apple's | - | ||||||||||||
873 | native font panel. (Currently, the native dialog is never used, | - | ||||||||||||
874 | but this is likely to change in future Qt releases.) | - | ||||||||||||
875 | \value ScalableFonts Show scalable fonts | - | ||||||||||||
876 | \value NonScalableFonts Show non scalable fonts | - | ||||||||||||
877 | \value MonospacedFonts Show monospaced fonts | - | ||||||||||||
878 | \value ProportionalFonts Show proportional fonts | - | ||||||||||||
879 | - | |||||||||||||
880 | \sa options, setOption(), testOption() | - | ||||||||||||
881 | */ | - | ||||||||||||
882 | - | |||||||||||||
883 | /*! | - | ||||||||||||
884 | Sets the given \a option to be enabled if \a on is true; | - | ||||||||||||
885 | otherwise, clears the given \a option. | - | ||||||||||||
886 | - | |||||||||||||
887 | \sa options, testOption() | - | ||||||||||||
888 | */ | - | ||||||||||||
889 | void QFontDialog::setOption(FontDialogOption option, bool on) | - | ||||||||||||
890 | { | - | ||||||||||||
891 | const QFontDialog::FontDialogOptions previousOptions = options(); | - | ||||||||||||
892 | if (!(previousOptions & option) != !on)
| 0 | ||||||||||||
893 | setOptions(previousOptions ^ option); never executed: setOptions(previousOptions ^ option); | 0 | ||||||||||||
894 | } never executed: end of block | 0 | ||||||||||||
895 | - | |||||||||||||
896 | /*! | - | ||||||||||||
897 | Returns \c true if the given \a option is enabled; otherwise, returns | - | ||||||||||||
898 | false. | - | ||||||||||||
899 | - | |||||||||||||
900 | \sa options, setOption() | - | ||||||||||||
901 | */ | - | ||||||||||||
902 | bool QFontDialog::testOption(FontDialogOption option) const | - | ||||||||||||
903 | { | - | ||||||||||||
904 | Q_D(const QFontDialog); | - | ||||||||||||
905 | return d->options->testOption(static_cast<QFontDialogOptions::FontDialogOption>(option)); never executed: return d->options->testOption(static_cast<QFontDialogOptions::FontDialogOption>(option)); | 0 | ||||||||||||
906 | } | - | ||||||||||||
907 | - | |||||||||||||
908 | /*! | - | ||||||||||||
909 | \property QFontDialog::options | - | ||||||||||||
910 | \brief the various options that affect the look and feel of the dialog | - | ||||||||||||
911 | \since 4.5 | - | ||||||||||||
912 | - | |||||||||||||
913 | By default, all options are disabled. | - | ||||||||||||
914 | - | |||||||||||||
915 | Options should be set before showing the dialog. Setting them while the | - | ||||||||||||
916 | dialog is visible is not guaranteed to have an immediate effect on the | - | ||||||||||||
917 | dialog (depending on the option and on the platform). | - | ||||||||||||
918 | - | |||||||||||||
919 | \sa setOption(), testOption() | - | ||||||||||||
920 | */ | - | ||||||||||||
921 | void QFontDialog::setOptions(FontDialogOptions options) | - | ||||||||||||
922 | { | - | ||||||||||||
923 | Q_D(QFontDialog); | - | ||||||||||||
924 | - | |||||||||||||
925 | if (QFontDialog::options() == options)
| 0 | ||||||||||||
926 | return; never executed: return; | 0 | ||||||||||||
927 | - | |||||||||||||
928 | d->options->setOptions(QFontDialogOptions::FontDialogOptions(int(options))); | - | ||||||||||||
929 | d->buttonBox->setVisible(!(options & NoButtons)); | - | ||||||||||||
930 | } never executed: end of block | 0 | ||||||||||||
931 | - | |||||||||||||
932 | QFontDialog::FontDialogOptions QFontDialog::options() const | - | ||||||||||||
933 | { | - | ||||||||||||
934 | Q_D(const QFontDialog); | - | ||||||||||||
935 | return QFontDialog::FontDialogOptions(int(d->options->options())); never executed: return QFontDialog::FontDialogOptions(int(d->options->options())); | 0 | ||||||||||||
936 | } | - | ||||||||||||
937 | - | |||||||||||||
938 | /*! | - | ||||||||||||
939 | \since 4.5 | - | ||||||||||||
940 | \overload | - | ||||||||||||
941 | - | |||||||||||||
942 | Opens the dialog and connects its fontSelected() signal to the slot specified | - | ||||||||||||
943 | by \a receiver and \a member. | - | ||||||||||||
944 | - | |||||||||||||
945 | The signal will be disconnected from the slot when the dialog is closed. | - | ||||||||||||
946 | */ | - | ||||||||||||
947 | void QFontDialog::open(QObject *receiver, const char *member) | - | ||||||||||||
948 | { | - | ||||||||||||
949 | Q_D(QFontDialog); | - | ||||||||||||
950 | connect(this, SIGNAL(fontSelected(QFont)), receiver, member); | - | ||||||||||||
951 | d->receiverToDisconnectOnClose = receiver; | - | ||||||||||||
952 | d->memberToDisconnectOnClose = member; | - | ||||||||||||
953 | QDialog::open(); | - | ||||||||||||
954 | } never executed: end of block | 0 | ||||||||||||
955 | - | |||||||||||||
956 | /*! | - | ||||||||||||
957 | \since 4.5 | - | ||||||||||||
958 | - | |||||||||||||
959 | \fn void QFontDialog::currentFontChanged(const QFont &font) | - | ||||||||||||
960 | - | |||||||||||||
961 | This signal is emitted when the current font is changed. The new font is | - | ||||||||||||
962 | specified in \a font. | - | ||||||||||||
963 | - | |||||||||||||
964 | The signal is emitted while a user is selecting a font. Ultimately, the | - | ||||||||||||
965 | chosen font may differ from the font currently selected. | - | ||||||||||||
966 | - | |||||||||||||
967 | \sa currentFont, fontSelected(), selectedFont() | - | ||||||||||||
968 | */ | - | ||||||||||||
969 | - | |||||||||||||
970 | /*! | - | ||||||||||||
971 | \since 4.5 | - | ||||||||||||
972 | - | |||||||||||||
973 | \fn void QFontDialog::fontSelected(const QFont &font) | - | ||||||||||||
974 | - | |||||||||||||
975 | This signal is emitted when a font has been selected. The selected font is | - | ||||||||||||
976 | specified in \a font. | - | ||||||||||||
977 | - | |||||||||||||
978 | The signal is only emitted when a user has chosen the final font to be | - | ||||||||||||
979 | used. It is not emitted while the user is changing the current font in the | - | ||||||||||||
980 | font dialog. | - | ||||||||||||
981 | - | |||||||||||||
982 | \sa selectedFont(), currentFontChanged(), currentFont | - | ||||||||||||
983 | */ | - | ||||||||||||
984 | - | |||||||||||||
985 | /*! | - | ||||||||||||
986 | \reimp | - | ||||||||||||
987 | */ | - | ||||||||||||
988 | void QFontDialog::setVisible(bool visible) | - | ||||||||||||
989 | { | - | ||||||||||||
990 | if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) != visible)
| 0 | ||||||||||||
991 | return; never executed: return; | 0 | ||||||||||||
992 | Q_D(QFontDialog); | - | ||||||||||||
993 | if (d->canBeNativeDialog())
| 0 | ||||||||||||
994 | d->setNativeDialogVisible(visible); never executed: d->setNativeDialogVisible(visible); | 0 | ||||||||||||
995 | if (d->nativeDialogInUse) {
| 0 | ||||||||||||
996 | // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below | - | ||||||||||||
997 | // updates the state correctly, but skips showing the non-native version: | - | ||||||||||||
998 | setAttribute(Qt::WA_DontShowOnScreen, true); | - | ||||||||||||
999 | } else { never executed: end of block | 0 | ||||||||||||
1000 | d->nativeDialogInUse = false; | - | ||||||||||||
1001 | setAttribute(Qt::WA_DontShowOnScreen, false); | - | ||||||||||||
1002 | } never executed: end of block | 0 | ||||||||||||
1003 | QDialog::setVisible(visible); | - | ||||||||||||
1004 | } never executed: end of block | 0 | ||||||||||||
1005 | - | |||||||||||||
1006 | /*! | - | ||||||||||||
1007 | Closes the dialog and sets its result code to \a result. If this dialog | - | ||||||||||||
1008 | is shown with exec(), done() causes the local event loop to finish, | - | ||||||||||||
1009 | and exec() to return \a result. | - | ||||||||||||
1010 | - | |||||||||||||
1011 | \sa QDialog::done() | - | ||||||||||||
1012 | */ | - | ||||||||||||
1013 | void QFontDialog::done(int result) | - | ||||||||||||
1014 | { | - | ||||||||||||
1015 | Q_D(QFontDialog); | - | ||||||||||||
1016 | QDialog::done(result); | - | ||||||||||||
1017 | if (result == Accepted) {
| 0 | ||||||||||||
1018 | // We check if this is the same font we had before, if so we emit currentFontChanged | - | ||||||||||||
1019 | QFont selectedFont = currentFont(); | - | ||||||||||||
1020 | if(selectedFont != d->selectedFont)
| 0 | ||||||||||||
1021 | emit(currentFontChanged(selectedFont)); never executed: (currentFontChanged(selectedFont)); | 0 | ||||||||||||
1022 | d->selectedFont = selectedFont; | - | ||||||||||||
1023 | emit fontSelected(d->selectedFont); | - | ||||||||||||
1024 | } else never executed: end of block | 0 | ||||||||||||
1025 | d->selectedFont = QFont(); never executed: d->selectedFont = QFont(); | 0 | ||||||||||||
1026 | if (d->receiverToDisconnectOnClose) {
| 0 | ||||||||||||
1027 | disconnect(this, SIGNAL(fontSelected(QFont)), | - | ||||||||||||
1028 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - | ||||||||||||
1029 | d->receiverToDisconnectOnClose = 0; | - | ||||||||||||
1030 | } never executed: end of block | 0 | ||||||||||||
1031 | d->memberToDisconnectOnClose.clear(); | - | ||||||||||||
1032 | } never executed: end of block | 0 | ||||||||||||
1033 | - | |||||||||||||
1034 | bool QFontDialogPrivate::canBeNativeDialog() const | - | ||||||||||||
1035 | { | - | ||||||||||||
1036 | // Don't use Q_Q here! This function is called from ~QDialog, | - | ||||||||||||
1037 | // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). | - | ||||||||||||
1038 | const QDialog * const q = static_cast<const QDialog*>(q_ptr); | - | ||||||||||||
1039 | if (nativeDialogInUse)
| 0 | ||||||||||||
1040 | return true; never executed: return true; | 0 | ||||||||||||
1041 | if (q->testAttribute(Qt::WA_DontShowOnScreen))
| 0 | ||||||||||||
1042 | return false; never executed: return false; | 0 | ||||||||||||
1043 | if (options->options() & QFontDialog::DontUseNativeDialog)
| 0 | ||||||||||||
1044 | return false; never executed: return false; | 0 | ||||||||||||
1045 | - | |||||||||||||
1046 | QLatin1String staticName(QFontDialog::staticMetaObject.className()); | - | ||||||||||||
1047 | QLatin1String dynamicName(q->metaObject()->className()); | - | ||||||||||||
1048 | return (staticName == dynamicName); never executed: return (staticName == dynamicName); | 0 | ||||||||||||
1049 | } | - | ||||||||||||
1050 | - | |||||||||||||
1051 | QT_END_NAMESPACE | - | ||||||||||||
1052 | - | |||||||||||||
1053 | #include "qfontdialog.moc" | - | ||||||||||||
1054 | #include "moc_qfontdialog.cpp" | - | ||||||||||||
1055 | - | |||||||||||||
1056 | #endif // QT_NO_FONTDIALOG | - | ||||||||||||
Source code | Switch to Preprocessed file |