qfontdialog.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qfontdialog.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8class QFontListView : public QListView-
9{-
10 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
11#pragma GCC diagnostic push-
12 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
13#pragma GCC diagnostic pop-
14 struct QPrivateSignal {};-
15public:-
16 QFontListView(QWidget *parent);-
17 inline QStringListModel *model() const {-
18 return static_cast<QStringListModel *>(QListView::model());-
19 }-
20 inline void setCurrentItem(int item) {-
21 QListView::setCurrentIndex(static_cast<QAbstractListModel*>(model())->index(item));-
22 }-
23 inline int currentItem() const {-
24 return QListView::currentIndex().row();-
25 }-
26 inline int count() const {-
27 return model()->rowCount();-
28 }-
29 inline QString currentText() const {-
30 int row = QListView::currentIndex().row();-
31 return row < 0 ? QString() : model()->stringList().at(row);-
32 }-
33 void currentChanged(const QModelIndex &current, const QModelIndex &previous) override {-
34 QListView::currentChanged(current, previous);-
35 if (current.isValid())-
36 highlighted(current.row());-
37 }-
38 QString text(int i) const {-
39 return model()->stringList().at(i);-
40 }-
41public :-
42 void highlighted(int);-
43};-
44-
45QFontListView::QFontListView(QWidget *parent)-
46 : QListView(parent)-
47{-
48 setModel(new QStringListModel(parent));-
49 setEditTriggers(NoEditTriggers);-
50}-
51-
52static const Qt::WindowFlags DefaultWindowFlags =-
53 Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;-
54-
55QFontDialogPrivate::QFontDialogPrivate()-
56 : writingSystem(QFontDatabase::Any),-
57 options(QSharedPointer<QFontDialogOptions>::create())-
58{-
59}-
60-
61QFontDialogPrivate::~QFontDialogPrivate()-
62{-
63}-
64QFontDialog::QFontDialog(QWidget *parent)-
65 : QDialog(*new QFontDialogPrivate, parent, DefaultWindowFlags)-
66{-
67 QFontDialogPrivate * const d = d_func();-
68 d->init();-
69}-
70-
71-
72-
73-
74-
75-
76-
77QFontDialog::QFontDialog(const QFont &initial, QWidget *parent)-
78 : QDialog(*new QFontDialogPrivate, parent, DefaultWindowFlags)-
79{-
80 QFontDialogPrivate * const d = d_func();-
81 d->init();-
82 setCurrentFont(initial);-
83}-
84-
85void QFontDialogPrivate::init()-
86{-
87 QFontDialog * const q = q_func();-
88-
89 q->setSizeGripEnabled(true);-
90 q->setWindowTitle(QFontDialog::tr("Select Font"));-
91-
92-
93 familyEdit = new QLineEdit(q);-
94 familyEdit->setReadOnly(true);-
95 familyList = new QFontListView(q);-
96 familyEdit->setFocusProxy(familyList);-
97-
98 familyAccel = new QLabel(q);-
99-
100 familyAccel->setBuddy(familyList);-
101-
102 familyAccel->setIndent(2);-
103-
104 styleEdit = new QLineEdit(q);-
105 styleEdit->setReadOnly(true);-
106 styleList = new QFontListView(q);-
107 styleEdit->setFocusProxy(styleList);-
108-
109 styleAccel = new QLabel(q);-
110-
111 styleAccel->setBuddy(styleList);-
112-
113 styleAccel->setIndent(2);-
114-
115 sizeEdit = new QLineEdit(q);-
116 sizeEdit->setFocusPolicy(Qt::ClickFocus);-
117 QIntValidator *validator = new QIntValidator(1, 512, q);-
118 sizeEdit->setValidator(validator);-
119 sizeList = new QFontListView(q);-
120-
121 sizeAccel = new QLabel(q);-
122-
123 sizeAccel->setBuddy(sizeEdit);-
124-
125 sizeAccel->setIndent(2);-
126-
127-
128 effects = new QGroupBox(q);-
129 QVBoxLayout *vbox = new QVBoxLayout(effects);-
130 strikeout = new QCheckBox(effects);-
131 vbox->addWidget(strikeout);-
132 underline = new QCheckBox(effects);-
133 vbox->addWidget(underline);-
134-
135 sample = new QGroupBox(q);-
136 QHBoxLayout *hbox = new QHBoxLayout(sample);-
137 sampleEdit = new QLineEdit(sample);-
138 sampleEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));-
139 sampleEdit->setAlignment(Qt::AlignCenter);-
140-
141-
142 sampleEdit->setText(QLatin1String("AaBbYyZz"));-
143 hbox->addWidget(sampleEdit);-
144-
145 writingSystemCombo = new QComboBox(q);-
146-
147 writingSystemAccel = new QLabel(q);-
148-
149 writingSystemAccel->setBuddy(writingSystemCombo);-
150-
151 writingSystemAccel->setIndent(2);-
152-
153 size = 0;-
154 smoothScalable = false;-
155-
156 QObject::connect(writingSystemCombo, qFlagLocation("2""activated(int)" "\0" __FILE__ ":" "243""249"), q, qFlagLocation("1""_q_writingSystemHighlighted(int)" "\0" __FILE__ ":" "243""249"));-
157 QObject::connect(familyList, qFlagLocation("2""highlighted(int)" "\0" __FILE__ ":" "244""250"), q, qFlagLocation("1""_q_familyHighlighted(int)" "\0" __FILE__ ":" "244""250"));-
158 QObject::connect(styleList, qFlagLocation("2""highlighted(int)" "\0" __FILE__ ":" "245""251"), q, qFlagLocation("1""_q_styleHighlighted(int)" "\0" __FILE__ ":" "245""251"));-
159 QObject::connect(sizeList, qFlagLocation("2""highlighted(int)" "\0" __FILE__ ":" "246""252"), q, qFlagLocation("1""_q_sizeHighlighted(int)" "\0" __FILE__ ":" "246""252"));-
160 QObject::connect(sizeEdit, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "247""253"), q, qFlagLocation("1""_q_sizeChanged(QString)" "\0" __FILE__ ":" "247""253"));-
161-
162 QObject::connect(strikeout, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "249""255"), q, qFlagLocation("1""_q_updateSample()" "\0" __FILE__ ":" "249""255"));-
163 QObject::connect(underline, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "250""256"), q, qFlagLocation("1""_q_updateSample()" "\0" __FILE__ ":" "250""256"));-
164-
165 for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {-
166 QFontDatabase::WritingSystem ws = QFontDatabase::WritingSystem(i);-
167 QString writingSystemName = QFontDatabase::writingSystemName(ws);-
168 if (writingSystemName.isEmpty())-
169 break;-
170 writingSystemCombo->addItem(writingSystemName);-
171 }-
172-
173 updateFamilies();-
174 if (familyList->count() != 0) {-
175 familyList->setCurrentItem(0);-
176 sizeList->setCurrentItem(0);-
177 }-
178-
179-
180 QGridLayout *mainGrid = new QGridLayout(q);-
181-
182 int spacing = mainGrid->spacing();-
183 if (spacing >= 0) {-
184 mainGrid->setSpacing(0);-
185-
186 mainGrid->setColumnMinimumWidth(1, spacing);-
187 mainGrid->setColumnMinimumWidth(3, spacing);-
188-
189 int margin = 0;-
190 mainGrid->getContentsMargins(0, 0, 0, &margin);-
191-
192 mainGrid->setRowMinimumHeight(3, margin);-
193 mainGrid->setRowMinimumHeight(6, 2);-
194 mainGrid->setRowMinimumHeight(8, margin);-
195 }-
196-
197 mainGrid->addWidget(familyAccel, 0, 0);-
198 mainGrid->addWidget(familyEdit, 1, 0);-
199 mainGrid->addWidget(familyList, 2, 0);-
200-
201 mainGrid->addWidget(styleAccel, 0, 2);-
202 mainGrid->addWidget(styleEdit, 1, 2);-
203 mainGrid->addWidget(styleList, 2, 2);-
204-
205 mainGrid->addWidget(sizeAccel, 0, 4);-
206 mainGrid->addWidget(sizeEdit, 1, 4);-
207 mainGrid->addWidget(sizeList, 2, 4);-
208-
209 mainGrid->setColumnStretch(0, 38);-
210 mainGrid->setColumnStretch(2, 24);-
211 mainGrid->setColumnStretch(4, 10);-
212-
213 mainGrid->addWidget(effects, 4, 0);-
214-
215 mainGrid->addWidget(sample, 4, 2, 4, 3);-
216-
217 mainGrid->addWidget(writingSystemAccel, 5, 0);-
218 mainGrid->addWidget(writingSystemCombo, 7, 0);-
219-
220 buttonBox = new QDialogButtonBox(q);-
221 mainGrid->addWidget(buttonBox, 9, 0, 1, 5);-
222-
223 QPushButton *button-
224 = static_cast<QPushButton *>(buttonBox->addButton(QDialogButtonBox::Ok));-
225 QObject::connect(buttonBox, qFlagLocation("2""accepted()" "\0" __FILE__ ":" "312""318"), q, qFlagLocation("1""accept()" "\0" __FILE__ ":" "312""318"));-
226 button->setDefault(true);-
227-
228 buttonBox->addButton(QDialogButtonBox::Cancel);-
229 QObject::connect(buttonBox, qFlagLocation("2""rejected()" "\0" __FILE__ ":" "316""322"), q, qFlagLocation("1""reject()" "\0" __FILE__ ":" "316""322"));-
230-
231-
232-
233-
234 q->resize(500, 360);-
235-
236-
237 sizeEdit->installEventFilter(q);-
238 familyList->installEventFilter(q);-
239 styleList->installEventFilter(q);-
240 sizeList->installEventFilter(q);-
241-
242 familyList->setFocus();-
243 retranslateStrings();-
244 sampleEdit->setObjectName(QLatin1String("qt_fontDialog_sampleEdit"));-
245}-
246-
247-
248-
249-
250-
251-
252QFontDialog::~QFontDialog()-
253{-
254}-
255QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title,-
256 FontDialogOptions options)-
257{-
258 return QFontDialogPrivate::getFont(ok, initial, parent, title, options);-
259}-
260QFont QFontDialog::getFont(bool *ok, QWidget *parent)-
261{-
262 QFont initial;-
263 return QFontDialogPrivate::getFont(ok, initial, parent, QString(), 0);-
264}-
265-
266QFont QFontDialogPrivate::getFont(bool *ok, const QFont &initial, QWidget *parent,-
267 const QString &title, QFontDialog::FontDialogOptions options)-
268{-
269 QFontDialog dlg(parent);-
270 dlg.setOptions(options);-
271 dlg.setCurrentFont(initial);-
272 if (!title.isEmpty())-
273 dlg.setWindowTitle(title);-
274-
275 int ret = (dlg.exec() || (options & QFontDialog::NoButtons));-
276 if (ok)-
277 *ok = !!ret;-
278 if (ret) {-
279 return dlg.selectedFont();-
280 } else {-
281 return initial;-
282 }-
283}-
284bool QFontDialog::eventFilter(QObject *o , QEvent *e)-
285{-
286 QFontDialogPrivate * const d = d_func();-
287 if (e->type() == QEvent::KeyPress) {-
288 QKeyEvent *k = (QKeyEvent *)e;-
289 if (o == d->sizeEdit &&-
290 (k->key() == Qt::Key_Up ||-
291 k->key() == Qt::Key_Down ||-
292 k->key() == Qt::Key_PageUp ||-
293 k->key() == Qt::Key_PageDown)) {-
294-
295 int ci = d->sizeList->currentItem();-
296 (void)QApplication::sendEvent(d->sizeList, k);-
297-
298 if (ci != d->sizeList->currentItem()-
299 && style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, this))-
300 d->sizeEdit->selectAll();-
301 return true;-
302 } else if ((o == d->familyList || o == d->styleList) &&-
303 (k->key() == Qt::Key_Return || k->key() == Qt::Key_Enter)) {-
304 k->accept();-
305 accept();-
306 return true;-
307 }-
308 } else if (e->type() == QEvent::FocusIn-
309 && style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, this)) {-
310 if (o == d->familyList)-
311 d->familyEdit->selectAll();-
312 else if (o == d->styleList)-
313 d->styleEdit->selectAll();-
314 else if (o == d->sizeList)-
315 d->sizeEdit->selectAll();-
316 } else if (e->type() == QEvent::MouseButtonPress && o == d->sizeList) {-
317 d->sizeEdit->setFocus();-
318 }-
319 return QDialog::eventFilter(o, e);-
320}-
321-
322void QFontDialogPrivate::initHelper(QPlatformDialogHelper *h)-
323{-
324 QFontDialog *d = q_func();-
325 QObject::connect(h, qFlagLocation("2""currentFontChanged(QFont)" "\0" __FILE__ ":" "466""472"), d, qFlagLocation("2""currentFontChanged(QFont)" "\0" __FILE__ ":" "466""472"));-
326 QObject::connect(h, qFlagLocation("2""fontSelected(QFont)" "\0" __FILE__ ":" "467""473"), d, qFlagLocation("2""fontSelected(QFont)" "\0" __FILE__ ":" "467""473"));-
327 static_cast<QPlatformFontDialogHelper *>(h)->setOptions(options);-
328}-
329-
330void QFontDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)-
331{-
332 options->setWindowTitle(q_func()->windowTitle());-
333}-
334-
335-
336-
337-
338-
339-
340void QFontDialogPrivate::updateFamilies()-
341{-
342 QFontDialog * const q = q_func();-
343-
344 enum match_t { MATCH_NONE = 0, MATCH_LAST_RESORT = 1, MATCH_APP = 2, MATCH_FAMILY = 3 };-
345-
346 const QFontDialog::FontDialogOptions scalableMask = (QFontDialog::ScalableFonts | QFontDialog::NonScalableFonts);-
347 const QFontDialog::FontDialogOptions spacingMask = (QFontDialog::ProportionalFonts | QFontDialog::MonospacedFonts);-
348 const QFontDialog::FontDialogOptions options = q->options();-
349-
350 QFontDatabase fdb;-
351-
352 QStringList familyNames;-
353 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(fdb.const auto families (writingSystem))>::type> _container_((= fdb.families(writingSystem))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1));-
354 for (const QString &family = *_container_.i; _container_.control; _container_.control = 0: families) {-
355 if (fdb.isPrivateFamily(family)
fdb.isPrivateFamily(family)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
356 continue;
never executed: continue;
0
357-
358 if ((
(options & scalableMask)Description
TRUEnever evaluated
FALSEnever evaluated
options & scalableMask)
(options & scalableMask)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(options & sca...= scalableMaskDescription
TRUEnever evaluated
FALSEnever evaluated
options & scalableMask) != scalableMask
(options & sca...= scalableMaskDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
359 if (bool(options & QFontDialog::ScalableFonts) != fdb.isSmoothlyScalable(family)
bool(options &...alable(family)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
360 continue;
never executed: continue;
0
361 }
never executed: end of block
0
362 if ((
(options & spacingMask)Description
TRUEnever evaluated
FALSEnever evaluated
options & spacingMask)
(options & spacingMask)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(options & spa...!= spacingMaskDescription
TRUEnever evaluated
FALSEnever evaluated
options & spacingMask) != spacingMask
(options & spa...!= spacingMaskDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
363 if (bool(options & QFontDialog::MonospacedFonts) != fdb.isFixedPitch(family)
bool(options &...dPitch(family)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
364 continue;
never executed: continue;
0
365 }
never executed: end of block
0
366 familyNames << family;-
367 }
never executed: end of block
0
368-
369 familyList->model()->setStringList(familyNames);-
370-
371 QString foundryName1, familyName1, foundryName2, familyName2;-
372 int bestFamilyMatch = -1;-
373 match_t bestFamilyType = MATCH_NONE;-
374-
375 QFont f;-
376-
377-
378 QFontDatabase::parseFontName(family, foundryName1, familyName1);-
379-
380 QStringList::const_iterator it = familyNames.constBegin();-
381 int i = 0;-
382 for(; it != familyNames.constEnd()
it != familyNames.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
; ++it, ++i) {
0
383 QFontDatabase::parseFontName(*it, foundryName2, familyName2);-
384-
385-
386 if (familyName1 == familyName2
familyName1 == familyName2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
387 bestFamilyType = MATCH_FAMILY;-
388 if (foundryName1 == foundryName2
foundryName1 == foundryName2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
389 bestFamilyMatch = i;-
390 break;
never executed: break;
0
391 }-
392 if (bestFamilyMatch < MATCH_FAMILY
bestFamilyMatch < MATCH_FAMILYDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
393 bestFamilyMatch = i;
never executed: bestFamilyMatch = i;
0
394 }
never executed: end of block
0
395-
396-
397 match_t type = MATCH_NONE;-
398 if (bestFamilyType <= MATCH_NONE
bestFamilyType <= MATCH_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
&& familyName2 == f.lastResortFamily()
familyName2 ==...ResortFamily()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
399 type = MATCH_LAST_RESORT;
never executed: type = MATCH_LAST_RESORT;
0
400 if (bestFamilyType <= MATCH_LAST_RESORT
bestFamilyType...CH_LAST_RESORTDescription
TRUEnever evaluated
FALSEnever evaluated
&& familyName2 == f.family()
familyName2 == f.family()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
401 type = MATCH_APP;
never executed: type = MATCH_APP;
0
402-
403 if (type != MATCH_NONE
type != MATCH_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
404 bestFamilyType = type;-
405 bestFamilyMatch = i;-
406 }
never executed: end of block
0
407 }
never executed: end of block
0
408-
409 if (i != -1
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
&& bestFamilyType != MATCH_NONE
bestFamilyType != MATCH_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
410 familyList->setCurrentItem(bestFamilyMatch);
never executed: familyList->setCurrentItem(bestFamilyMatch);
0
411 else-
412 familyList->setCurrentItem(0);
never executed: familyList->setCurrentItem(0);
0
413 familyEdit->setText(familyList->currentText());-
414 if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
q->style()->st...tedText, 0, q)Description
TRUEnever evaluated
FALSEnever evaluated
0
415 && familyList->hasFocus()
familyList->hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
416 familyEdit->selectAll();
never executed: familyEdit->selectAll();
0
417-
418 updateStyles();-
419}
never executed: end of block
0
420-
421-
422-
423-
424-
425void QFontDialogPrivate::updateStyles()-
426{-
427 QFontDialog * const q = q_func();-
428 QStringList styles = fdb.styles(familyList->currentText());-
429 styleList->model()->setStringList(styles);-
430-
431 if (styles.isEmpty()) {-
432 styleEdit->clear();-
433 smoothScalable = false;-
434 } else {-
435 if (!style.isEmpty()) {-
436 bool found = false;-
437 bool first = true;-
438 QString cstyle = style;-
439-
440 redo:-
441 for (int i = 0; i < (int)styleList->count(); i++) {-
442 if (cstyle == styleList->text(i)) {-
443 styleList->setCurrentItem(i);-
444 found = true;-
445 break;-
446 }-
447 }-
448 if (!found && first) {-
449 if (cstyle.contains(QLatin1String("Italic"))) {-
450 cstyle.replace(QLatin1String("Italic"), QLatin1String("Oblique"));-
451 first = false;-
452 goto redo;-
453 } else if (cstyle.contains(QLatin1String("Oblique"))) {-
454 cstyle.replace(QLatin1String("Oblique"), QLatin1String("Italic"));-
455 first = false;-
456 goto redo;-
457 }-
458 }-
459 if (!found)-
460 styleList->setCurrentItem(0);-
461 } else {-
462 styleList->setCurrentItem(0);-
463 }-
464-
465 styleEdit->setText(styleList->currentText());-
466 if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)-
467 && styleList->hasFocus())-
468 styleEdit->selectAll();-
469-
470 smoothScalable = fdb.isSmoothlyScalable(familyList->currentText(), styleList->currentText());-
471 }-
472-
473 updateSizes();-
474}-
475-
476-
477-
478-
479-
480-
481-
482void QFontDialogPrivate::updateSizes()-
483{-
484 QFontDialog * const q = q_func();-
485-
486 if (!familyList->currentText().isEmpty()) {-
487 QList<int> sizes = fdb.pointSizes(familyList->currentText(), styleList->currentText());-
488-
489 int i = 0;-
490 int current = -1;-
491 QStringList str_sizes;-
492 str_sizes.reserve(sizes.size());-
493 for(QList<int>::const_iterator it = sizes.constBegin(); it != sizes.constEnd(); ++it) {-
494 str_sizes.append(QString::number(*it));-
495 if (current == -1 && *it == size)-
496 current = i;-
497 ++i;-
498 }-
499 sizeList->model()->setStringList(str_sizes);-
500 if (current != -1)-
501 sizeList->setCurrentItem(current);-
502-
503 const QSignalBlocker blocker(sizeEdit);-
504 sizeEdit->setText((smoothScalable ? QString::number(size) : sizeList->currentText()));-
505 if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)-
506 && sizeList->hasFocus())-
507 sizeEdit->selectAll();-
508 } else {-
509 sizeEdit->clear();-
510 }-
511-
512 _q_updateSample();-
513}-
514-
515void QFontDialogPrivate::_q_updateSample()-
516{-
517-
518 int pSize = sizeEdit->text().toInt();-
519 QFont newFont(fdb.font(familyList->currentText(), style, pSize));-
520 newFont.setStrikeOut(strikeout->isChecked());-
521 newFont.setUnderline(underline->isChecked());-
522-
523 if (familyList->currentText().isEmpty())-
524 sampleEdit->clear();-
525-
526 updateSampleFont(newFont);-
527}-
528-
529void QFontDialogPrivate::updateSampleFont(const QFont &newFont)-
530{-
531 QFontDialog * const q = q_func();-
532 if (newFont != sampleEdit->font()) {-
533 sampleEdit->setFont(newFont);-
534 q->currentFontChanged(newFont);-
535 }-
536}-
537-
538-
539-
540-
541void QFontDialogPrivate::_q_writingSystemHighlighted(int index)-
542{-
543 writingSystem = QFontDatabase::WritingSystem(index);-
544 sampleEdit->setText(fdb.writingSystemSample(writingSystem));-
545 updateFamilies();-
546}-
547-
548-
549-
550-
551void QFontDialogPrivate::_q_familyHighlighted(int i)-
552{-
553 QFontDialog * const q = q_func();-
554 family = familyList->text(i);-
555 familyEdit->setText(family);-
556 if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)-
557 && familyList->hasFocus())-
558 familyEdit->selectAll();-
559-
560 updateStyles();-
561}-
562-
563-
564-
565-
566-
567-
568void QFontDialogPrivate::_q_styleHighlighted(int index)-
569{-
570 QFontDialog * const q = q_func();-
571 QString s = styleList->text(index);-
572 styleEdit->setText(s);-
573 if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)-
574 && styleList->hasFocus())-
575 styleEdit->selectAll();-
576-
577 style = s;-
578-
579 updateSizes();-
580}-
581-
582-
583-
584-
585-
586-
587void QFontDialogPrivate::_q_sizeHighlighted(int index)-
588{-
589 QFontDialog * const q = q_func();-
590 QString s = sizeList->text(index);-
591 sizeEdit->setText(s);-
592 if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)-
593 && sizeEdit->hasFocus())-
594 sizeEdit->selectAll();-
595-
596 size = s.toInt();-
597 _q_updateSample();-
598}-
599-
600-
601-
602-
603-
604-
605-
606void QFontDialogPrivate::_q_sizeChanged(const QString &s)-
607{-
608-
609 int size = s.toInt();-
610 if (this->size == size)-
611 return;-
612-
613 this->size = size;-
614 if (sizeList->count() != 0) {-
615 int i;-
616 for (i = 0; i < sizeList->count() - 1; i++) {-
617 if (sizeList->text(i).toInt() >= this->size)-
618 break;-
619 }-
620 const QSignalBlocker blocker(sizeList);-
621 if (sizeList->text(i).toInt() == this->size)-
622 sizeList->setCurrentItem(i);-
623 else-
624 sizeList->clearSelection();-
625 }-
626 _q_updateSample();-
627}-
628-
629void QFontDialogPrivate::retranslateStrings()-
630{-
631 familyAccel->setText(QFontDialog::tr("&Font"));-
632 styleAccel->setText(QFontDialog::tr("Font st&yle"));-
633 sizeAccel->setText(QFontDialog::tr("&Size"));-
634 effects->setTitle(QFontDialog::tr("Effects"));-
635 strikeout->setText(QFontDialog::tr("Stri&keout"));-
636 underline->setText(QFontDialog::tr("&Underline"));-
637 sample->setTitle(QFontDialog::tr("Sample"));-
638 writingSystemAccel->setText(QFontDialog::tr("Wr&iting System"));-
639}-
640-
641-
642-
643-
644void QFontDialog::changeEvent(QEvent *e)-
645{-
646 QFontDialogPrivate * const d = d_func();-
647 if (e->type() == QEvent::LanguageChange) {-
648 d->retranslateStrings();-
649 }-
650 QDialog::changeEvent(e);-
651}-
652void QFontDialog::setCurrentFont(const QFont &font)-
653{-
654 QFontDialogPrivate * const d = d_func();-
655 d->family = font.family();-
656 d->style = d->fdb.styleString(font);-
657 d->size = font.pointSize();-
658 if (d->size == -1
d->size == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
659 QFontInfo fi(font);-
660 d->size = fi.pointSize();-
661 }
never executed: end of block
0
662 d->strikeout->setChecked(font.strikeOut());-
663 d->underline->setChecked(font.underline());-
664 d->updateFamilies();-
665 if (d->canBeNativeDialog()) {if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()
QPlatformFontD...DialogHelper()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
666 helper->setCurrentFont(font);
never executed: helper->setCurrentFont(font);
0
}}
never executed: end of block
668QFont QFontDialog::currentFont() const-
669{-
670 const QFontDialogPrivate * const d = d_func();-
671 if (d->canBeNativeDialog()) {if (const
const QPlatfor...DialogHelper()Description
TRUEnever evaluated
FALSEnever evaluated
QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()
const QPlatfor...DialogHelper()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
672 return
never executed: return helper->currentFont();
helper->currentFont();
never executed: return helper->currentFont();
0
673 }return
never executed: return d->sampleEdit->font();
d->sampleEdit->font();
never executed: return d->sampleEdit->font();
0
674}-
675QFont QFontDialog::selectedFont() const-
676{-
677 const QFontDialogPrivate * const d = d_func();-
678 return d->selectedFont;-
679}-
680void QFontDialog::setOption(FontDialogOption option, bool on)-
681{-
682 const QFontDialog::FontDialogOptions previousOptions = options();-
683 if (!(previousOptions & option) != !on)-
684 setOptions(previousOptions ^ option);-
685}-
686-
687-
688-
689-
690-
691-
692-
693bool QFontDialog::testOption(FontDialogOption option) const-
694{-
695 const QFontDialogPrivate * const d = d_func();-
696 return d->options->testOption(static_cast<QFontDialogOptions::FontDialogOption>(option));-
697}-
698void QFontDialog::setOptions(FontDialogOptions options)-
699{-
700 QFontDialogPrivate * const d = d_func();-
701-
702 if (QFontDialog::options() == options)-
703 return;-
704-
705 d->options->setOptions(QFontDialogOptions::FontDialogOptions(int(options)));-
706 d->buttonBox->setVisible(!(options & NoButtons));-
707}-
708-
709QFontDialog::FontDialogOptions QFontDialog::options() const-
710{-
711 const QFontDialogPrivate * const d = d_func();-
712 return QFontDialog::FontDialogOptions(int(d->options->options()));-
713}-
714void QFontDialog::open(QObject *receiver, const char *member)-
715{-
716 QFontDialogPrivate * const d = d_func();-
717 connect(this, qFlagLocation("2""fontSelected(QFont)" "\0" __FILE__ ":" "950""953"), receiver, member);-
718 d->receiverToDisconnectOnClose = receiver;-
719 d->memberToDisconnectOnClose = member;-
720 QDialog::open();-
721}-
722void QFontDialog::setVisible(bool visible)-
723{-
724 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) != visible)-
725 return;-
726 QFontDialogPrivate * const d = d_func();-
727 if (d->canBeNativeDialog())-
728 d->setNativeDialogVisible(visible);-
729 if (d->nativeDialogInUse) {-
730-
731-
732 setAttribute(Qt::WA_DontShowOnScreen, true);-
733 } else {-
734 d->nativeDialogInUse = false;-
735 setAttribute(Qt::WA_DontShowOnScreen, false);-
736 }-
737 QDialog::setVisible(visible);-
738}-
739void QFontDialog::done(int result)-
740{-
741 QFontDialogPrivate * const d = d_func();-
742 QDialog::done(result);-
743 if (result == Accepted) {-
744-
745 QFont selectedFont = currentFont();-
746 if(selectedFont != d->selectedFont)-
747 (currentFontChanged(selectedFont));-
748 d->selectedFont = selectedFont;-
749 fontSelected(d->selectedFont);-
750 } else-
751 d->selectedFont = QFont();-
752 if (d->receiverToDisconnectOnClose) {-
753 disconnect(this, qFlagLocation("2""fontSelected(QFont)" "\0" __FILE__ ":" "1027""1030"),-
754 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);-
755 d->receiverToDisconnectOnClose = 0;-
756 }-
757 d->memberToDisconnectOnClose.clear();-
758}-
759-
760bool QFontDialogPrivate::canBeNativeDialog() const-
761{-
762-
763-
764 const QDialog * const q = static_cast<const QDialog*>(q_ptr);-
765 if (nativeDialogInUse
nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
766 return
never executed: return true;
true;
never executed: return true;
0
767 if (QCoreApplication::testAttribute
QCoreApplicati...NativeDialogs)Description
TRUEnever evaluated
FALSEnever evaluated
(Qt::AA_DontUseNativeDialogs)
QCoreApplicati...NativeDialogs)Description
TRUEnever evaluated
FALSEnever evaluated
0
768 || q->testAttribute(Qt::WA_DontShowOnScreen))
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
0
return false;
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
if
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
)
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
769 || (
(options->opti...eNativeDialog)Description
TRUEnever evaluated
FALSEnever evaluated
options->options() & QFontDialog::DontUseNativeDialog))
(options->opti...eNativeDialog)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
770 return
never executed: return false;
false;
never executed: return false;
0
771 }-
772-
773 QLatin1String staticName(QFontDialog::staticMetaObject.className());-
774 QLatin1String dynamicName(q->metaObject()->className());-
775 return
never executed: return (staticName == dynamicName);
(staticName == dynamicName);
never executed: return (staticName == dynamicName);
0
776}-
777-
778-
779-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9