Qt 4.8
qfontdialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qwindowdefs.h"
43 
44 #ifndef QT_NO_FONTDIALOG
45 
46 #include "qfontdialog.h"
47 #include "qfontdialog_p.h"
48 
49 #include <qapplication.h>
50 #include <qcheckbox.h>
51 #include <qcombobox.h>
52 #include <qevent.h>
53 #include <qfontdatabase.h>
54 #include <qgroupbox.h>
55 #include <qlabel.h>
56 #include <qlayout.h>
57 #include <qlineedit.h>
58 #include <qpushbutton.h>
59 #include <qstyle.h>
60 #include <qdialogbuttonbox.h>
61 #include <qheaderview.h>
62 #include <qlistview.h>
63 #include <qstringlistmodel.h>
64 #include <qvalidator.h>
65 #include <private/qdialog_p.h>
66 #include <private/qfont_p.h>
67 
68 #if defined(Q_WS_S60)
69 #include <QtGui/qdesktopwidget.h>
70 #endif
71 
73 
74 class QFontListView : public QListView
75 {
76  Q_OBJECT
77 public:
79  inline QStringListModel *model() const {
80  return static_cast<QStringListModel *>(QListView::model());
81  }
82  inline void setCurrentItem(int item) {
83  QListView::setCurrentIndex(static_cast<QAbstractListModel*>(model())->index(item));
84  }
85  inline int currentItem() const {
86  return QListView::currentIndex().row();
87  }
88  inline int count() const {
89  return model()->rowCount();
90  }
91  inline QString currentText() const {
92  int row = QListView::currentIndex().row();
93  return row < 0 ? QString() : model()->stringList().at(row);
94  }
95  void currentChanged(const QModelIndex &current, const QModelIndex &previous) {
96  QListView::currentChanged(current, previous);
97  if (current.isValid())
98  emit highlighted(current.row());
99  }
100  QString text(int i) const {
101  return model()->stringList().at(i);
102  }
103 signals:
104  void highlighted(int);
105 };
106 
108  : QListView(parent)
109 {
110  setModel(new QStringListModel(parent));
112 }
113 
114 static const Qt::WindowFlags DefaultWindowFlags =
116 
160 {
161  Q_D(QFontDialog);
162  d->init();
163 }
164 
176 {
177  Q_D(QFontDialog);
178  d->init();
179  setCurrentFont(initial);
180 }
181 
183 {
184  Q_Q(QFontDialog);
185 
186 #ifdef Q_WS_MAC
187  nativeDialogInUse = false;
188  delegate = 0;
189 #endif
190 
191  q->setSizeGripEnabled(true);
192  q->setWindowTitle(QFontDialog::tr("Select Font"));
193 
194  // grid
195  familyEdit = new QLineEdit(q);
196  familyEdit->setReadOnly(true);
197  familyList = new QFontListView(q);
198  familyEdit->setFocusProxy(familyList);
199 
200  familyAccel = new QLabel(q);
201 #ifndef QT_NO_SHORTCUT
202  familyAccel->setBuddy(familyList);
203 #endif
204  familyAccel->setIndent(2);
205 
206  styleEdit = new QLineEdit(q);
207  styleEdit->setReadOnly(true);
208  styleList = new QFontListView(q);
209  styleEdit->setFocusProxy(styleList);
210 
211  styleAccel = new QLabel(q);
212 #ifndef QT_NO_SHORTCUT
213  styleAccel->setBuddy(styleList);
214 #endif
215  styleAccel->setIndent(2);
216 
217  sizeEdit = new QLineEdit(q);
218  sizeEdit->setFocusPolicy(Qt::ClickFocus);
219  QIntValidator *validator = new QIntValidator(1, 512, q);
220  sizeEdit->setValidator(validator);
221  sizeList = new QFontListView(q);
222 
223  sizeAccel = new QLabel(q);
224 #ifndef QT_NO_SHORTCUT
225  sizeAccel->setBuddy(sizeEdit);
226 #endif
227  sizeAccel->setIndent(2);
228 
229  // effects box
230  effects = new QGroupBox(q);
231  QVBoxLayout *vbox = new QVBoxLayout(effects);
232  strikeout = new QCheckBox(effects);
233  vbox->addWidget(strikeout);
234  underline = new QCheckBox(effects);
235  vbox->addWidget(underline);
236 
237  sample = new QGroupBox(q);
238  QHBoxLayout *hbox = new QHBoxLayout(sample);
239  sampleEdit = new QLineEdit(sample);
240  sampleEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
241  sampleEdit->setAlignment(Qt::AlignCenter);
242  // Note that the sample text is *not* translated with tr(), as the
243  // characters used depend on the charset encoding.
244  sampleEdit->setText(QLatin1String("AaBbYyZz"));
245  hbox->addWidget(sampleEdit);
246 
247  writingSystemCombo = new QComboBox(q);
248 
249  writingSystemAccel = new QLabel(q);
250 #ifndef QT_NO_SHORTCUT
251  writingSystemAccel->setBuddy(writingSystemCombo);
252 #endif
253  writingSystemAccel->setIndent(2);
254 
255  size = 0;
256  smoothScalable = false;
257 
258  QObject::connect(writingSystemCombo, SIGNAL(activated(int)), q, SLOT(_q_writingSystemHighlighted(int)));
259  QObject::connect(familyList, SIGNAL(highlighted(int)), q, SLOT(_q_familyHighlighted(int)));
260  QObject::connect(styleList, SIGNAL(highlighted(int)), q, SLOT(_q_styleHighlighted(int)));
261  QObject::connect(sizeList, SIGNAL(highlighted(int)), q, SLOT(_q_sizeHighlighted(int)));
262  QObject::connect(sizeEdit, SIGNAL(textChanged(QString)), q, SLOT(_q_sizeChanged(QString)));
263 
264  QObject::connect(strikeout, SIGNAL(clicked()), q, SLOT(_q_updateSample()));
265  QObject::connect(underline, SIGNAL(clicked()), q, SLOT(_q_updateSample()));
266 
267  for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
269  QString writingSystemName = QFontDatabase::writingSystemName(ws);
270  if (writingSystemName.isEmpty())
271  break;
272  writingSystemCombo->addItem(writingSystemName);
273  }
274 
275  updateFamilies();
276  if (familyList->count() != 0)
277  familyList->setCurrentItem(0);
278 
279  // grid layout
280  QGridLayout *mainGrid = new QGridLayout(q);
281 
282  int spacing = mainGrid->spacing();
283  if (spacing >= 0) { // uniform spacing
284  mainGrid->setSpacing(0);
285 
286  mainGrid->setColumnMinimumWidth(1, spacing);
287  mainGrid->setColumnMinimumWidth(3, spacing);
288 
289  int margin = 0;
290  mainGrid->getContentsMargins(0, 0, 0, &margin);
291 
292  mainGrid->setRowMinimumHeight(3, margin);
293  mainGrid->setRowMinimumHeight(6, 2);
294  mainGrid->setRowMinimumHeight(8, margin);
295  }
296 
297  mainGrid->addWidget(familyAccel, 0, 0);
298  mainGrid->addWidget(familyEdit, 1, 0);
299  mainGrid->addWidget(familyList, 2, 0);
300 
301  mainGrid->addWidget(styleAccel, 0, 2);
302  mainGrid->addWidget(styleEdit, 1, 2);
303  mainGrid->addWidget(styleList, 2, 2);
304 
305  mainGrid->addWidget(sizeAccel, 0, 4);
306  mainGrid->addWidget(sizeEdit, 1, 4);
307  mainGrid->addWidget(sizeList, 2, 4);
308 
309  mainGrid->setColumnStretch(0, 38);
310  mainGrid->setColumnStretch(2, 24);
311  mainGrid->setColumnStretch(4, 10);
312 
313  mainGrid->addWidget(effects, 4, 0);
314 
315  mainGrid->addWidget(sample, 4, 2, 4, 3);
316 
317  mainGrid->addWidget(writingSystemAccel, 5, 0);
318  mainGrid->addWidget(writingSystemCombo, 7, 0);
319 
320  buttonBox = new QDialogButtonBox(q);
321  mainGrid->addWidget(buttonBox, 9, 0, 1, 5);
322 
323  QPushButton *button
324  = static_cast<QPushButton *>(buttonBox->addButton(QDialogButtonBox::Ok));
325  QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept()));
326  button->setDefault(true);
327 
328  buttonBox->addButton(QDialogButtonBox::Cancel);
329  QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject()));
330 
331 #if defined(Q_WS_WINCE)
332  q->resize(180, 120);
333 #elif defined(Q_WS_S60)
334  q->resize(QApplication::desktop()->availableGeometry(QCursor::pos()).size());
335 #else
336  q->resize(500, 360);
337 #endif // Q_WS_WINCE
338 
339  sizeEdit->installEventFilter(q);
340  familyList->installEventFilter(q);
341  styleList->installEventFilter(q);
342  sizeList->installEventFilter(q);
343 
344  familyList->setFocus();
345  retranslateStrings();
346 }
347 
354 {
355 #ifdef Q_WS_MAC
356  Q_D(QFontDialog);
357  if (d->delegate) {
358  d->closeCocoaFontPanel();
359  return;
360  }
361 #endif
362 }
363 
388 QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title,
389  FontDialogOptions options)
390 {
391  return QFontDialogPrivate::getFont(ok, initial, parent, title, options);
392 }
393 
398 QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title)
399 {
400  return QFontDialogPrivate::getFont(ok, initial, parent, title, 0);
401 }
402 
406 QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent)
407 {
408  return QFontDialogPrivate::getFont(ok, initial, parent, QString(), 0);
409 }
410 
435 {
436  QFont initial;
437  return QFontDialogPrivate::getFont(ok, initial, parent, QString(), 0);
438 }
439 
441  const QString &title, QFontDialog::FontDialogOptions options)
442 {
443  QFontDialog dlg(parent);
444  dlg.setOptions(options);
445  dlg.setCurrentFont(initial);
446  if (!title.isEmpty())
447  dlg.setWindowTitle(title);
448 
449  int ret = (dlg.exec() || (options & QFontDialog::NoButtons));
450  if (ok)
451  *ok = !!ret;
452  if (ret) {
453  return dlg.selectedFont();
454  } else {
455  return initial;
456  }
457 }
458 
470 {
471  Q_D(QFontDialog);
472  if (e->type() == QEvent::KeyPress) {
473  QKeyEvent *k = (QKeyEvent *)e;
474  if (o == d->sizeEdit &&
475  (k->key() == Qt::Key_Up ||
476  k->key() == Qt::Key_Down ||
477  k->key() == Qt::Key_PageUp ||
478  k->key() == Qt::Key_PageDown)) {
479 
480  int ci = d->sizeList->currentItem();
481  (void)QApplication::sendEvent(d->sizeList, k);
482 
483  if (ci != d->sizeList->currentItem()
485  d->sizeEdit->selectAll();
486  return true;
487  } else if ((o == d->familyList || o == d->styleList) &&
488  (k->key() == Qt::Key_Return || k->key() == Qt::Key_Enter)) {
489  k->accept();
490  accept();
491  return true;
492  }
493  } else if (e->type() == QEvent::FocusIn
495  if (o == d->familyList)
496  d->familyEdit->selectAll();
497  else if (o == d->styleList)
498  d->styleEdit->selectAll();
499  else if (o == d->sizeList)
500  d->sizeEdit->selectAll();
501  } else if (e->type() == QEvent::MouseButtonPress && o == d->sizeList) {
502  d->sizeEdit->setFocus();
503  }
504  return QDialog::eventFilter(o, e);
505 }
506 
507 /*
508  Updates the contents of the "font family" list box. This
509  function can be reimplemented if you have special requirements.
510 */
511 
513 {
514  Q_Q(QFontDialog);
515 
516  enum match_t { MATCH_NONE = 0, MATCH_LAST_RESORT = 1, MATCH_APP = 2, MATCH_FAMILY = 3 };
517 
518  QStringList familyNames = fdb.families(writingSystem);
519 
520  familyList->model()->setStringList(familyNames);
521 
522  QString foundryName1, familyName1, foundryName2, familyName2;
523  int bestFamilyMatch = -1;
524  match_t bestFamilyType = MATCH_NONE;
525 
526  QFont f;
527 
528  // ##### do the right thing for a list of family names in the font.
529  QFontDatabase::parseFontName(family, foundryName1, familyName1);
530 
531  QStringList::const_iterator it = familyNames.constBegin();
532  int i = 0;
533  for(; it != familyNames.constEnd(); ++it, ++i) {
534  QFontDatabase::parseFontName(*it, foundryName2, familyName2);
535 
536  //try to match...
537  if (familyName1 == familyName2) {
538  bestFamilyType = MATCH_FAMILY;
539  if (foundryName1 == foundryName2) {
540  bestFamilyMatch = i;
541  break;
542  }
543  if (bestFamilyMatch < MATCH_FAMILY)
544  bestFamilyMatch = i;
545  }
546 
547  //and try some fall backs
548  match_t type = MATCH_NONE;
549  if (bestFamilyType <= MATCH_NONE && familyName2 == f.lastResortFamily())
550  type = MATCH_LAST_RESORT;
551  if (bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.family())
552  type = MATCH_APP;
553  // ### add fallback for writingSystem
554  if (type != MATCH_NONE) {
555  bestFamilyType = type;
556  bestFamilyMatch = i;
557  }
558  }
559 
560  if (i != -1 && bestFamilyType != MATCH_NONE)
561  familyList->setCurrentItem(bestFamilyMatch);
562  else
563  familyList->setCurrentItem(0);
564  familyEdit->setText(familyList->currentText());
565  if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
566  && familyList->hasFocus())
567  familyEdit->selectAll();
568 
569  updateStyles();
570 }
571 
572 /*
573  Updates the contents of the "font style" list box. This
574  function can be reimplemented if you have special requirements.
575 */
577 {
578  Q_Q(QFontDialog);
579  QStringList styles = fdb.styles(familyList->currentText());
580  styleList->model()->setStringList(styles);
581 
582  if (styles.isEmpty()) {
583  styleEdit->clear();
584  smoothScalable = false;
585  } else {
586  if (!style.isEmpty()) {
587  bool found = false;
588  bool first = true;
589  QString cstyle = style;
590 
591  redo:
592  for (int i = 0; i < (int)styleList->count(); i++) {
593  if (cstyle == styleList->text(i)) {
594  styleList->setCurrentItem(i);
595  found = true;
596  break;
597  }
598  }
599  if (!found && first) {
600  if (cstyle.contains(QLatin1String("Italic"))) {
601  cstyle.replace(QLatin1String("Italic"), QLatin1String("Oblique"));
602  first = false;
603  goto redo;
604  } else if (cstyle.contains(QLatin1String("Oblique"))) {
605  cstyle.replace(QLatin1String("Oblique"), QLatin1String("Italic"));
606  first = false;
607  goto redo;
608  }
609  }
610  if (!found)
611  styleList->setCurrentItem(0);
612  } else {
613  styleList->setCurrentItem(0);
614  }
615 
616  styleEdit->setText(styleList->currentText());
617  if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
618  && styleList->hasFocus())
619  styleEdit->selectAll();
620 
621  smoothScalable = fdb.isSmoothlyScalable(familyList->currentText(), styleList->currentText());
622  }
623 
624  updateSizes();
625 }
626 
637 {
638  Q_Q(QFontDialog);
639 
640  if (!familyList->currentText().isEmpty()) {
641  QList<int> sizes = fdb.pointSizes(familyList->currentText(), styleList->currentText());
642 
643  int i = 0;
644  int current = -1;
645  QStringList str_sizes;
646  for(QList<int>::const_iterator it = sizes.constBegin(); it != sizes.constEnd(); ++it) {
647  str_sizes.append(QString::number(*it));
648  if (current == -1 && *it >= size)
649  current = i;
650  ++i;
651  }
652  sizeList->model()->setStringList(str_sizes);
653  if (current == -1) {
654  // we request a size bigger than the ones in the list, select the biggest one
655  current = sizeList->count() - 1;
656  }
657  sizeList->setCurrentItem(current);
658 
659  sizeEdit->blockSignals(true);
660  sizeEdit->setText((smoothScalable ? QString::number(size) : sizeList->currentText()));
661  if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
662  && sizeList->hasFocus())
663  sizeEdit->selectAll();
664  sizeEdit->blockSignals(false);
665  } else {
666  sizeEdit->clear();
667  }
668 
669  _q_updateSample();
670 }
671 
673 {
674  // compute new font
675  int pSize = sizeEdit->text().toInt();
676  QFont newFont(fdb.font(familyList->currentText(), style, pSize));
677  newFont.setStrikeOut(strikeout->isChecked());
678  newFont.setUnderline(underline->isChecked());
679 
680  if (familyList->currentText().isEmpty())
681  sampleEdit->clear();
682 
683  updateSampleFont(newFont);
684 }
685 
687 {
688  Q_Q(QFontDialog);
689  if (newFont != sampleEdit->font()) {
690  sampleEdit->setFont(newFont);
691  emit q->currentFontChanged(newFont);
692  }
693 }
694 
699 {
700  writingSystem = QFontDatabase::WritingSystem(index);
701  sampleEdit->setText(fdb.writingSystemSample(writingSystem));
702  updateFamilies();
703 }
704 
709 {
710  Q_Q(QFontDialog);
711  family = familyList->text(i);
712  familyEdit->setText(family);
713  if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
714  && familyList->hasFocus())
715  familyEdit->selectAll();
716 
717  updateStyles();
718 }
719 
720 
726 {
727  Q_Q(QFontDialog);
728  QString s = styleList->text(index);
729  styleEdit->setText(s);
730  if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
731  && styleList->hasFocus())
732  styleEdit->selectAll();
733 
734  style = s;
735 
736  updateSizes();
737 }
738 
739 
745 {
746  Q_Q(QFontDialog);
747  QString s = sizeList->text(index);
748  sizeEdit->setText(s);
749  if (q->style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, q)
750  && sizeEdit->hasFocus())
751  sizeEdit->selectAll();
752 
753  size = s.toInt();
754  _q_updateSample();
755 }
756 
767 {
768  // no need to check if the conversion is valid, since we have an QIntValidator in the size edit
769  int size = s.toInt();
770  if (this->size == size)
771  return;
772 
773  this->size = size;
774  if (sizeList->count() != 0) {
775  int i;
776  for (i = 0; i < sizeList->count() - 1; i++) {
777  if (sizeList->text(i).toInt() >= this->size)
778  break;
779  }
780  sizeList->blockSignals(true);
781  sizeList->setCurrentItem(i);
782  sizeList->blockSignals(false);
783  }
784  _q_updateSample();
785 }
786 
788 {
789  familyAccel->setText(QFontDialog::tr("&Font"));
790  styleAccel->setText(QFontDialog::tr("Font st&yle"));
791  sizeAccel->setText(QFontDialog::tr("&Size"));
792 #ifndef Q_WS_S60
793  // Removed the title due to lack of screen estate in small S60 screen.
794  // The effects are descriptive without a title (strikeout, underline).
795  effects->setTitle(QFontDialog::tr("Effects"));
796 #endif
797  strikeout->setText(QFontDialog::tr("Stri&keout"));
798  underline->setText(QFontDialog::tr("&Underline"));
799  sample->setTitle(QFontDialog::tr("Sample"));
800  writingSystemAccel->setText(QFontDialog::tr("Wr&iting System"));
801 }
802 
807 {
808  Q_D(QFontDialog);
809  if (e->type() == QEvent::LanguageChange) {
810  d->retranslateStrings();
811  }
813 }
814 
836 {
837  Q_D(QFontDialog);
838  d->family = font.family();
839  d->style = d->fdb.styleString(font);
840  d->size = font.pointSize();
841  if (d->size == -1) {
842  QFontInfo fi(font);
843  d->size = fi.pointSize();
844  }
845  d->strikeout->setChecked(font.strikeOut());
846  d->underline->setChecked(font.underline());
847  d->updateFamilies();
848 
849 #ifdef Q_WS_MAC
850  if (d->delegate)
851  QFontDialogPrivate::setFont(d->delegate, font);
852 #endif
853 }
854 
866 {
867  Q_D(const QFontDialog);
868  return d->sampleEdit->font();
869 }
870 
880 {
881  Q_D(const QFontDialog);
882  return d->selectedFont;
883 }
884 
910 {
911  Q_D(QFontDialog);
912  if (!(d->opts & option) != !on)
913  setOptions(d->opts ^ option);
914 }
915 
923 {
924  Q_D(const QFontDialog);
925  return (d->opts & option) != 0;
926 }
927 
944 void QFontDialog::setOptions(FontDialogOptions options)
945 {
946  Q_D(QFontDialog);
947 
948  FontDialogOptions changed = (options ^ d->opts);
949  if (!changed)
950  return;
951 
952  d->opts = options;
953  d->buttonBox->setVisible(!(options & NoButtons));
954 }
955 
956 QFontDialog::FontDialogOptions QFontDialog::options() const
957 {
958  Q_D(const QFontDialog);
959  return d->opts;
960 }
961 
962 #ifdef Q_WS_MAC
963 // can only have one Cocoa font panel active
965 #endif
966 
979 void QFontDialog::open(QObject *receiver, const char *member)
980 {
981  Q_D(QFontDialog);
982  connect(this, SIGNAL(fontSelected(QFont)), receiver, member);
983  d->receiverToDisconnectOnClose = receiver;
984  d->memberToDisconnectOnClose = member;
985  QDialog::open();
986 }
987 
1027 {
1029  return;
1030 #ifdef Q_WS_MAC
1031  Q_D(QFontDialog);
1032  if (d->canBeNativeDialog()){
1033  if (d->setVisible_sys(visible)){
1034  d->nativeDialogInUse = true;
1035  // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
1036  // updates the state correctly, but skips showing the non-native version:
1038  } else {
1039  d->nativeDialogInUse = false;
1041  }
1042  }
1043 #endif // Q_WS_MAC
1044  QDialog::setVisible(visible);
1045 }
1046 
1055 {
1056  Q_D(QFontDialog);
1057  QDialog::done(result);
1058  if (result == Accepted) {
1059  // We check if this is the same font we had before, if so we emit currentFontChanged
1061  if(selectedFont != d->selectedFont)
1062  emit(currentFontChanged(selectedFont));
1063  d->selectedFont = selectedFont;
1064  emit fontSelected(d->selectedFont);
1065  } else
1066  d->selectedFont = QFont();
1067  if (d->receiverToDisconnectOnClose) {
1069  d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
1070  d->receiverToDisconnectOnClose = 0;
1071  }
1072  d->memberToDisconnectOnClose.clear();
1073 }
1074 
1075 #ifdef Q_WS_MAC
1077 {
1078  Q_Q(QFontDialog);
1079  if (nativeDialogInUse)
1080  return true;
1081  if (q->testAttribute(Qt::WA_DontShowOnScreen))
1082  return false;
1084  return false;
1085 
1087  QLatin1String dynamicName(q->metaObject()->className());
1088  return (staticName == dynamicName);
1089 }
1090 #endif // Q_WS_MAC
1091 
1118 
1119 #include "qfontdialog.moc"
1120 #include "moc_qfontdialog.cpp"
1121 
1122 #endif // QT_NO_FONTDIALOG
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QFontDialog(QWidget *parent=0)
Constructs a standard font dialog.
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
The QKeyEvent class describes a key event.
Definition: qevent.h:224
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QFontListView(QWidget *parent)
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
QSize size() const
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
void currentFontChanged(const QFont &font)
This signal is emitted when the current font is changed.
#define it(className, varName)
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition: qfont.cpp:1320
int exec()
Shows the dialog as a modal dialog, blocking until the user closes it.
Definition: qdialog.cpp:524
void setUnderline(bool)
If enable is true, sets underline on; otherwise sets underline off.
Definition: qfont.cpp:1331
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QStringListModel * model() const
Definition: qfontdialog.cpp:79
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition: qdialog.cpp:639
void setEditTriggers(EditTriggers triggers)
virtual void reject()
Hides the modal dialog and sets the result code to Rejected.
Definition: qdialog.cpp:650
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void setColumnMinimumWidth(int column, int minSize)
Sets the minimum width of column column to minSize pixels.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
void setDefault(bool)
QString lastResortFamily() const
Returns the "last resort" font family name.
Definition: qfont_mac.cpp:156
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
void _q_sizeHighlighted(int)
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QFont getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options)
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void fontSelected(const QFont &font)
This signal is emitted when a font has been selected.
The QStringListModel class provides a model that supplies strings to views.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
int count() const
Definition: qfontdialog.cpp:88
#define Q_D(Class)
Definition: qglobal.h:2482
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition: qvalidator.h:96
const char * className
Definition: qwizard.cpp:137
QStringList stringList() const
Returns the string list used by the model to store data.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QStyle * style() const
Definition: qwidget.cpp:2742
#define Q_Q(Class)
Definition: qglobal.h:2483
static bool sharedFontPanelAvailable
static QFont getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title, FontDialogOptions options)
Executes a modal font dialog and returns a font.
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
Reimplemented Function
Definition: qlistview.cpp:3242
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
friend class const_iterator
Definition: qlist.h:264
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QStringList familyList(const QFontDef &req)
bool visible
whether the widget is visible
Definition: qwidget.h:191
void setCurrentItem(int item)
Definition: qfontdialog.cpp:82
void _q_writingSystemHighlighted(int)
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setStrikeOut(bool)
If enable is true, sets strikeout on; otherwise sets strikeout off.
Definition: qfont.cpp:1378
FontDialogOptions options() const
int row() const
Returns the row this model index refers to.
void _q_styleHighlighted(int)
QFont currentFont() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
Definition: qfontdialog.cpp:95
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
void setOptions(FontDialogOptions options)
void setRowMinimumHeight(int row, int minSize)
Sets the minimum height of row row to minSize pixels.
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
void rejected()
This signal is emitted when the dialog has been rejected either by the user or by calling reject() or...
int currentItem() const
Definition: qfontdialog.cpp:85
int spacing() const
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwi...
void _q_familyHighlighted(int)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void changeEvent(QEvent *event)
Reimplemented Function
The QGroupBox widget provides a group box frame with a title.
Definition: qgroupbox.h:57
QModelIndex currentIndex() const
Returns the model index of the current item.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QFontDialog class provides a dialog widget for selecting a font.
Definition: qfontdialog.h:59
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
#define Q_OBJECT
Definition: qobjectdefs.h:157
void setVisible(bool visible)
Reimplemented Function
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
void done(int result)
Closes the dialog and sets its result code to result.
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
static void setFont(void *delegate, const QFont &font)
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void _q_sizeChanged(const QString &)
This slot is called if the user changes the font size.
void updateSizes()
Updates the contents of the "font size" list box.
FontDialogOption
This enum specifies various options that affect the look and feel of a font dialog.
Definition: qfontdialog.h:68
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows in the model.
The QListView class provides a list or icon view onto a model.
Definition: qlistview.h:57
void setColumnStretch(int column, int stretch)
Sets the stretch factor of column column to stretch.
void setCurrentFont(const QFont &font)
Sets the font highlighted in the QFontDialog to the given font.
bool testOption(FontDialogOption option) const
Returns true if the given option is enabled; otherwise, returns false.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Definition: qlayout.cpp:551
void highlighted(int)
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
bool eventFilter(QObject *, QEvent *)
Reimplemented Function
Definition: qdialog.cpp:656
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:60
The QModelIndex class is used to locate data in a data model.
QString currentText() const
Definition: qfontdialog.cpp:91
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
The QHBoxLayout class lines up widgets horizontally.
Definition: qboxlayout.h:129
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
static const Qt::WindowFlags DefaultWindowFlags
void accepted()
This signal is emitted when the dialog has been accepted either by the user or by calling accept() or...
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
int pointSize() const
Returns the point size of the font.
Definition: qfont.cpp:981
const QFont & font() const
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
bool eventFilter(QObject *object, QEvent *event)
An event filter to make the Up, Down, PageUp and PageDown keys work correctly in the line edits...
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qgridlayout.h:116
static QString writingSystemName(WritingSystem writingSystem)
Returns the names the writingSystem (e.g.
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
Definition: qfont.cpp:1367
#define signals
Definition: qobjectdefs.h:69
QAbstractItemModel * model() const
Returns the model that this view is presenting.
The QCheckBox widget provides a checkbox with a text label.
Definition: qcheckbox.h:56
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
void setSpacing(int spacing)
This function sets both the vertical and horizontal spacing to spacing.
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
QString text(int i) const
void setOption(FontDialogOption option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
int pointSize() const
Returns the point size of the matched window system font.
Definition: qfont.cpp:2698
void updateSampleFont(const QFont &newFont)
QFont selectedFont() const
Returns the font that the user selected by clicking the OK or equivalent button.