summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qfontdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dialogs/qfontdialog.cpp')
-rw-r--r--src/widgets/dialogs/qfontdialog.cpp116
1 files changed, 71 insertions, 45 deletions
diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp
index bec99b4df7..628297d22b 100644
--- a/src/widgets/dialogs/qfontdialog.cpp
+++ b/src/widgets/dialogs/qfontdialog.cpp
@@ -69,7 +69,7 @@ QFontListView::QFontListView(QWidget *parent)
setEditTriggers(NoEditTriggers);
}
-static const Qt::WindowFlags DefaultWindowFlags =
+static const Qt::WindowFlags qfd_DefaultWindowFlags =
Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
QFontDialogPrivate::QFontDialogPrivate()
@@ -119,7 +119,7 @@ QFontDialogPrivate::~QFontDialogPrivate()
\sa getFont()
*/
QFontDialog::QFontDialog(QWidget *parent)
- : QDialog(*new QFontDialogPrivate, parent, DefaultWindowFlags)
+ : QDialog(*new QFontDialogPrivate, parent, qfd_DefaultWindowFlags)
{
Q_D(QFontDialog);
d->init();
@@ -208,14 +208,21 @@ void QFontDialogPrivate::init()
size = 0;
smoothScalable = false;
- QObject::connect(writingSystemCombo, SIGNAL(activated(int)), q, SLOT(_q_writingSystemHighlighted(int)));
- QObject::connect(familyList, SIGNAL(highlighted(int)), q, SLOT(_q_familyHighlighted(int)));
- QObject::connect(styleList, SIGNAL(highlighted(int)), q, SLOT(_q_styleHighlighted(int)));
- QObject::connect(sizeList, SIGNAL(highlighted(int)), q, SLOT(_q_sizeHighlighted(int)));
- QObject::connect(sizeEdit, SIGNAL(textChanged(QString)), q, SLOT(_q_sizeChanged(QString)));
-
- QObject::connect(strikeout, SIGNAL(clicked()), q, SLOT(_q_updateSample()));
- QObject::connect(underline, SIGNAL(clicked()), q, SLOT(_q_updateSample()));
+ QObjectPrivate::connect(writingSystemCombo, &QComboBox::activated,
+ this, &QFontDialogPrivate::writingSystemHighlighted);
+ QObjectPrivate::connect(familyList, &QFontListView::highlighted,
+ this, &QFontDialogPrivate::familyHighlighted);
+ QObjectPrivate::connect(styleList, &QFontListView::highlighted,
+ this, &QFontDialogPrivate::styleHighlighted);
+ QObjectPrivate::connect(sizeList, &QFontListView::highlighted,
+ this, &QFontDialogPrivate::sizeHighlighted);
+ QObjectPrivate::connect(sizeEdit, &QLineEdit::textChanged,
+ this, &QFontDialogPrivate::sizeChanged);
+
+ QObjectPrivate::connect(strikeout, &QCheckBox::clicked,
+ this, &QFontDialogPrivate::updateSample);
+ QObjectPrivate::connect(underline, &QCheckBox::clicked, this,
+ &QFontDialogPrivate::updateSample);
for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
QFontDatabase::WritingSystem ws = QFontDatabase::WritingSystem(i);
@@ -277,11 +284,11 @@ void QFontDialogPrivate::init()
QPushButton *button
= static_cast<QPushButton *>(buttonBox->addButton(QDialogButtonBox::Ok));
- QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept()));
+ QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept);
button->setDefault(true);
buttonBox->addButton(QDialogButtonBox::Cancel);
- QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject()));
+ QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject);
q->resize(500, 360);
@@ -390,7 +397,7 @@ bool QFontDialog::eventFilter(QObject *o , QEvent *e)
{
Q_D(QFontDialog);
if (e->type() == QEvent::KeyPress) {
- QKeyEvent *k = (QKeyEvent *)e;
+ QKeyEvent *k = static_cast<QKeyEvent *>(e);
if (o == d->sizeEdit &&
(k->key() == Qt::Key_Up ||
k->key() == Qt::Key_Down ||
@@ -426,10 +433,14 @@ bool QFontDialog::eventFilter(QObject *o , QEvent *e)
void QFontDialogPrivate::initHelper(QPlatformDialogHelper *h)
{
- QFontDialog *d = q_func();
- QObject::connect(h, SIGNAL(currentFontChanged(QFont)), d, SIGNAL(currentFontChanged(QFont)));
- QObject::connect(h, SIGNAL(fontSelected(QFont)), d, SIGNAL(fontSelected(QFont)));
- static_cast<QPlatformFontDialogHelper *>(h)->setOptions(options);
+ Q_Q(QFontDialog);
+ auto *fontDialogHelper = static_cast<QPlatformFontDialogHelper *>(h);
+ fontDialogHelper->setOptions(options);
+ fontDialogHelper->setCurrentFont(q->currentFont());
+ QObject::connect(fontDialogHelper, &QPlatformFontDialogHelper::currentFontChanged,
+ q, &QFontDialog::currentFontChanged);
+ QObject::connect(fontDialogHelper, &QPlatformFontDialogHelper::fontSelected,
+ q, &QFontDialog::fontSelected);
}
void QFontDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
@@ -498,9 +509,9 @@ void QFontDialogPrivate::updateFamilies()
//and try some fall backs
match_t type = MATCH_NONE;
- if (bestFamilyType <= MATCH_NONE && familyName2 == QStringLiteral("helvetica"))
+ if (bestFamilyType <= MATCH_NONE && familyName2 == "helvetica"_L1)
type = MATCH_LAST_RESORT;
- if (bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.families().first())
+ if (bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.families().constFirst())
type = MATCH_APP;
// ### add fallback for writingSystem
if (type != MATCH_NONE) {
@@ -620,10 +631,10 @@ void QFontDialogPrivate::updateSizes()
sizeEdit->clear();
}
- _q_updateSample();
+ updateSample();
}
-void QFontDialogPrivate::_q_updateSample()
+void QFontDialogPrivate::updateSample()
{
// compute new font
int pSize = sizeEdit->text().toInt();
@@ -649,7 +660,7 @@ void QFontDialogPrivate::updateSampleFont(const QFont &newFont)
/*!
\internal
*/
-void QFontDialogPrivate::_q_writingSystemHighlighted(int index)
+void QFontDialogPrivate::writingSystemHighlighted(int index)
{
writingSystem = QFontDatabase::WritingSystem(index);
sampleEdit->setText(QFontDatabase::writingSystemSample(writingSystem));
@@ -659,7 +670,7 @@ void QFontDialogPrivate::_q_writingSystemHighlighted(int index)
/*!
\internal
*/
-void QFontDialogPrivate::_q_familyHighlighted(int i)
+void QFontDialogPrivate::familyHighlighted(int i)
{
Q_Q(QFontDialog);
family = familyList->text(i);
@@ -676,7 +687,7 @@ void QFontDialogPrivate::_q_familyHighlighted(int i)
\internal
*/
-void QFontDialogPrivate::_q_styleHighlighted(int index)
+void QFontDialogPrivate::styleHighlighted(int index)
{
Q_Q(QFontDialog);
QString s = styleList->text(index);
@@ -695,7 +706,7 @@ void QFontDialogPrivate::_q_styleHighlighted(int index)
\internal
*/
-void QFontDialogPrivate::_q_sizeHighlighted(int index)
+void QFontDialogPrivate::sizeHighlighted(int index)
{
Q_Q(QFontDialog);
QString s = sizeList->text(index);
@@ -705,7 +716,7 @@ void QFontDialogPrivate::_q_sizeHighlighted(int index)
sizeEdit->selectAll();
size = s.toInt();
- _q_updateSample();
+ updateSample();
}
/*!
@@ -714,7 +725,7 @@ void QFontDialogPrivate::_q_sizeHighlighted(int index)
The size is passed in the \a s argument as a \e string.
*/
-void QFontDialogPrivate::_q_sizeChanged(const QString &s)
+void QFontDialogPrivate::sizeChanged(const QString &s)
{
// no need to check if the conversion is valid, since we have an QIntValidator in the size edit
int size = s.toInt();
@@ -734,7 +745,7 @@ void QFontDialogPrivate::_q_sizeChanged(const QString &s)
else
sizeList->clearSelection();
}
- _q_updateSample();
+ updateSample();
}
void QFontDialogPrivate::retranslateStrings()
@@ -788,8 +799,11 @@ void QFontDialog::setCurrentFont(const QFont &font)
d->strikeout->setChecked(font.strikeOut());
d->underline->setChecked(font.underline());
d->updateFamilies();
- if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
- helper->setCurrentFont(font);
+
+ if (d->nativeDialogInUse) {
+ if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
+ helper->setCurrentFont(font);
+ }
}
/*!
@@ -802,8 +816,11 @@ void QFontDialog::setCurrentFont(const QFont &font)
QFont QFontDialog::currentFont() const
{
Q_D(const QFontDialog);
- if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
- return helper->currentFont();
+
+ if (d->nativeDialogInUse) {
+ if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
+ return helper->currentFont();
+ }
return d->sampleEdit->font();
}
@@ -952,20 +969,31 @@ void QFontDialog::open(QObject *receiver, const char *member)
*/
void QFontDialog::setVisible(bool visible)
{
- if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) != visible)
- return;
- Q_D(QFontDialog);
- if (d->canBeNativeDialog())
- d->setNativeDialogVisible(visible);
- if (d->nativeDialogInUse) {
+ // will call QFontDialogPrivate::setVisible
+ QDialog::setVisible(visible);
+}
+
+/*!
+ \internal
+
+ The implementation of QFontDialog::setVisible() has to live here so that the call
+ to hide() in ~QDialog calls this function; it wouldn't call the override of
+ QDialog::setVisible().
+*/
+void QFontDialogPrivate::setVisible(bool visible)
+{
+ Q_Q(QFontDialog);
+
+ if (canBeNativeDialog())
+ setNativeDialogVisible(visible);
+ if (nativeDialogInUse) {
// Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
// updates the state correctly, but skips showing the non-native version:
- setAttribute(Qt::WA_DontShowOnScreen, true);
+ q->setAttribute(Qt::WA_DontShowOnScreen, true);
} else {
- d->nativeDialogInUse = false;
- setAttribute(Qt::WA_DontShowOnScreen, false);
+ q->setAttribute(Qt::WA_DontShowOnScreen, false);
}
- QDialog::setVisible(visible);
+ QDialogPrivate::setVisible(visible);
}
/*!
@@ -1009,9 +1037,7 @@ bool QFontDialogPrivate::canBeNativeDialog() const
return false;
}
- QLatin1StringView staticName(QFontDialog::staticMetaObject.className());
- QLatin1StringView dynamicName(q->metaObject()->className());
- return (staticName == dynamicName);
+ return strcmp(QFontDialog::staticMetaObject.className(), q->metaObject()->className()) == 0;
}
QT_END_NAMESPACE