diff --git a/src/kfontchooser.h b/src/kfontchooser.h --- a/src/kfontchooser.h +++ b/src/kfontchooser.h @@ -267,7 +267,6 @@ Q_DISABLE_COPY(KFontChooser) - Q_PRIVATE_SLOT(d, void _k_toggled_checkbox()) Q_PRIVATE_SLOT(d, void _k_family_chosen_slot(const QString &)) Q_PRIVATE_SLOT(d, void _k_size_chosen_slot(const QString &)) Q_PRIVATE_SLOT(d, void _k_style_chosen_slot(const QString &)) diff --git a/src/kfontchooser.cpp b/src/kfontchooser.cpp --- a/src/kfontchooser.cpp +++ b/src/kfontchooser.cpp @@ -89,10 +89,6 @@ customSizeRow = -1; } - // pointer to an optinally supplied list of fonts to - // inserted into the fontdialog font-family combo-box -// QStringList fontList; - void setFamilyBoxItems(const QStringList &fonts); void fillFamilyListBox(bool onlyFixedFonts = false); int nearestSizeRow(qreal val, bool customize); @@ -102,7 +98,6 @@ void setupDisplay(); QString styleIdentifier(const QFont &font); - void _k_toggled_checkbox(); void _k_family_chosen_slot(const QString &); void _k_size_chosen_slot(const QString &); void _k_style_chosen_slot(const QString &); @@ -113,20 +108,25 @@ QPalette m_palette; + QFontDatabase fdb; + + QLabel *familyLabel = nullptr; + QLabel *styleLabel = nullptr; + QLabel *sizeLabel = nullptr; + + QCheckBox *familyCheckbox = nullptr; + QCheckBox *styleCheckbox = nullptr; + QCheckBox *sizeCheckbox = nullptr; + + QListWidget *familyListBox = nullptr; + QListWidget *styleListBox = nullptr; + QListWidget *sizeListBox = nullptr; + QDoubleSpinBox *sizeOfFont = nullptr; - QTextEdit *sampleEdit = nullptr; + QCheckBox *sizeIsRelativeCheckBox = nullptr; - QLabel *familyLabel = nullptr; - QLabel *styleLabel = nullptr; - QCheckBox *familyCheckbox = nullptr; - QCheckBox *styleCheckbox = nullptr; - QCheckBox *sizeCheckbox = nullptr; - QLabel *sizeLabel = nullptr; - QListWidget *familyListBox = nullptr; - QListWidget *styleListBox = nullptr; - QListWidget *sizeListBox = nullptr; - QCheckBox *sizeIsRelativeCheckBox = nullptr; + QTextEdit *sampleEdit = nullptr; QFont selFont; @@ -197,8 +197,8 @@ familyLayout->addSpacing(checkBoxGap); if (flags & ShowDifferences) { d->familyCheckbox = new QCheckBox(KFontChooser::tr("Font", "@option:check"), page); - connect(d->familyCheckbox, SIGNAL(toggled(bool)), - this, SLOT(_k_toggled_checkbox())); + connect(d->familyCheckbox, &QAbstractButton::toggled, + this, [this](const bool state) { d->familyListBox->setEnabled(state); }); familyLayout->addWidget(d->familyCheckbox, 0, Qt::AlignLeft); d->familyCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font family settings.", "@info:whatsthis")); d->familyCheckbox->setToolTip(KFontChooser::tr("Change font family?", "@info:tooltip")); @@ -213,8 +213,8 @@ QHBoxLayout *styleLayout = new QHBoxLayout(); if (flags & ShowDifferences) { d->styleCheckbox = new QCheckBox(KFontChooser::tr("Font style", "@option:check"), page); - connect(d->styleCheckbox, SIGNAL(toggled(bool)), - this, SLOT(_k_toggled_checkbox())); + connect(d->styleCheckbox, &QAbstractButton::toggled, + this, [this](const bool state) { d->styleListBox->setEnabled(state); }); styleLayout->addWidget(d->styleCheckbox, 0, Qt::AlignLeft); d->styleCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font style settings.", "@info:whatsthis")); d->styleCheckbox->setToolTip(KFontChooser::tr("Change font style?", "@info:tooltip")); @@ -230,8 +230,12 @@ QHBoxLayout *sizeLayout = new QHBoxLayout(); if (flags & ShowDifferences) { d->sizeCheckbox = new QCheckBox(KFontChooser::tr("Size", "@option:check"), page); - connect(d->sizeCheckbox, SIGNAL(toggled(bool)), - this, SLOT(_k_toggled_checkbox())); + + connect(d->sizeCheckbox, &QAbstractButton::toggled, this, [this](const bool state) { + d->sizeListBox->setEnabled(state); + d->sizeOfFont->setEnabled(state); + }); + sizeLayout->addWidget(d->sizeCheckbox, 0, Qt::AlignLeft); d->sizeCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font size settings.", "@info:whatsthis")); d->sizeCheckbox->setToolTip(KFontChooser::tr("Change font size?", "@info:tooltip")); @@ -245,7 +249,7 @@ sizeLayout->addSpacing(checkBoxGap); // prevent label from eating border gridLayout->addLayout(sizeLayout, row, 2); - row ++; + ++row; // // now create the actual boxes that hold the info @@ -263,17 +267,17 @@ d->familyLabel->setWhatsThis(fontFamilyWhatsThisText); } - connect(d->familyListBox, SIGNAL(currentTextChanged(QString)), - this, SLOT(_k_family_chosen_slot(QString))); + connect(d->familyListBox, &QListWidget::currentTextChanged, + this, [this](const QString &family) { d->_k_family_chosen_slot(family); }); + if (!fontList.isEmpty()) { d->setFamilyBoxItems(fontList); } else { d->fillFamilyListBox(flags & FixedFontsOnly); } d->familyListBox->setMinimumWidth(minimumListWidth(d->familyListBox)); - d->familyListBox->setMinimumHeight( - minimumListHeight(d->familyListBox, visibleListSize)); + d->familyListBox->setMinimumHeight(minimumListHeight(d->familyListBox, visibleListSize)); d->styleListBox = new QListWidget(page); d->styleListBox->setEnabled(flags ^ ShowDifferences); @@ -292,11 +296,10 @@ d->styleListBox->addItem(KFontChooser::tr("Bold", "@item font")); d->styleListBox->addItem(KFontChooser::tr("Bold Italic", "@item font")); d->styleListBox->setMinimumWidth(minimumListWidth(d->styleListBox)); - d->styleListBox->setMinimumHeight( - minimumListHeight(d->styleListBox, visibleListSize)); + d->styleListBox->setMinimumHeight(minimumListHeight(d->styleListBox, visibleListSize)); - connect(d->styleListBox, SIGNAL(currentTextChanged(QString)), - this, SLOT(_k_style_chosen_slot(QString))); + connect(d->styleListBox, &QListWidget::currentTextChanged, + this, [this](const QString &style) { d->_k_style_chosen_slot(style); }); d->sizeListBox = new QListWidget(page); d->sizeOfFont = new QDoubleSpinBox(page); @@ -349,18 +352,17 @@ // Populate with usual sizes, to determine minimum list width; // will be replaced later with correct sizes. d->fillSizeList(); - d->sizeListBox->setMinimumWidth(minimumListWidth(d->sizeListBox) + - d->sizeListBox->fontMetrics().maxWidth()); - d->sizeListBox->setMinimumHeight( - minimumListHeight(d->sizeListBox, visibleListSize)); + d->sizeListBox->setMinimumWidth(minimumListWidth(d->sizeListBox) + + d->sizeListBox->fontMetrics().maxWidth()); + d->sizeListBox->setMinimumHeight(minimumListHeight(d->sizeListBox, visibleListSize)); - connect(d->sizeOfFont, SIGNAL(valueChanged(double)), - this, SLOT(_k_size_value_slot(double))); + connect(d->sizeOfFont, QOverload::of(&QDoubleSpinBox::valueChanged), + this, [this](const double size) { d->_k_size_value_slot(size); }); - connect(d->sizeListBox, SIGNAL(currentTextChanged(QString)), - this, SLOT(_k_size_chosen_slot(QString))); + connect(d->sizeListBox, &QListWidget::currentTextChanged, + this, [this](const QString &size) { d->_k_size_chosen_slot(size); }); - row ++; + ++row; // // Completed the font attribute grid. @@ -382,8 +384,8 @@ "You may edit it to test special characters."); d->sampleEdit->setWhatsThis(sampleEditWhatsThisText); - connect(this, SIGNAL(fontSelected(QFont)), - this, SLOT(_k_displaySample(QFont))); + connect(this, &KFontChooser::fontSelected, + this, [this](const QFont &font) { d->_k_displaySample(font); }); splitter->addWidget(d->sampleEdit); // @@ -535,14 +537,6 @@ return d->selFont; } -void KFontChooser::Private::_k_toggled_checkbox() -{ - familyListBox->setEnabled(familyCheckbox->isChecked()); - styleListBox->setEnabled(styleCheckbox->isChecked()); - sizeListBox->setEnabled(sizeCheckbox->isChecked()); - sizeOfFont->setEnabled(sizeCheckbox->isChecked()); -} - void KFontChooser::Private::_k_family_chosen_slot(const QString &family) { if (!signalsAllowed) { @@ -561,8 +555,7 @@ } // Get the list of styles available in this family. - QFontDatabase dbase; - QStringList styles = dbase.styles(currentFamily); + QStringList styles = fdb.styles(currentFamily); if (styles.isEmpty()) { // Avoid extraction, it is in kdeqt.po styles.append(TR_NOX("Normal", "QFontDatabase")); @@ -574,12 +567,14 @@ QStringList filteredStyles; qtStyles.clear(); styleIDs.clear(); - Q_FOREACH (const QString &style, styles) { + + const QStringList origStyles = styles; + for (const QString &style : origStyles) { // Sometimes the font database will report an invalid style, // that falls back back to another when set. // Remove such styles, by checking set/get round-trip. - QFont testFont = dbase.font(currentFamily, style, 10); - if (dbase.styleString(testFont) != style) { + QFont testFont = fdb.font(currentFamily, style, 10); + if (fdb.styleString(testFont) != style) { styles.removeAll(style); continue; } @@ -621,8 +616,8 @@ qreal currentSize = setupSizeListBox(currentFamily, currentStyle); sizeOfFont->setValue(currentSize); - selFont = dbase.font(currentFamily, currentStyle, int(currentSize)); - if (dbase.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { + selFont = fdb.font(currentFamily, currentStyle, int(currentSize)); + if (fdb.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { selFont.setPointSizeF(currentSize); } emit q->fontSelected(selFont); @@ -637,7 +632,6 @@ } signalsAllowed = false; - QFontDatabase dbase; QString currentFamily = qtFamilies[familyListBox->currentItem()->text()]; QString currentStyle; if (style.isEmpty()) { @@ -650,8 +644,8 @@ qreal currentSize = setupSizeListBox(currentFamily, currentStyle); sizeOfFont->setValue(currentSize); - selFont = dbase.font(currentFamily, currentStyle, int(currentSize)); - if (dbase.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { + selFont = fdb.font(currentFamily, currentStyle, int(currentSize)); + if (fdb.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { selFont.setPointSizeF(currentSize); } emit q->fontSelected(selFont); @@ -705,7 +699,6 @@ // We compare with qreal, so convert for platforms where qreal != double. qreal val = qreal(dval); - QFontDatabase dbase; QString family = qtFamilies[familyListBox->currentItem()->text()]; QString style = qtStyles[styleListBox->currentItem()->text()]; @@ -718,7 +711,7 @@ bool canCustomize = true; // For Qt-bad-sizes workaround: skip this block unconditionally - if (!dbase.isSmoothlyScalable(family, style)) { + if (!fdb.isSmoothlyScalable(family, style)) { // Bitmap font, allow only discrete sizes. // Determine the nearest in the direction of change. canCustomize = false; @@ -830,15 +823,10 @@ qreal KFontChooser::Private::setupSizeListBox(const QString &family, const QString &style) { - QFontDatabase dbase; QList sizes; - if (dbase.isSmoothlyScalable(family, style)) { - // A vector font. - //>sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO - } else { - // A bitmap font. - //sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO - const QList smoothSizes = dbase.smoothSizes(family, style); + const bool smoothlyScalable = fdb.isSmoothlyScalable(family, style); + if (!smoothlyScalable) { + const QList smoothSizes = fdb.smoothSizes(family, style); for (int size : smoothSizes) { sizes.append(size); } @@ -849,9 +837,8 @@ qreal bestFitSize = fillSizeList(sizes); // Set the best fit size as current in the listbox if available. - const QList selectedSizeList = - sizeListBox->findItems(formatFontSize(bestFitSize), - Qt::MatchExactly); + const QList selectedSizeList = sizeListBox->findItems( + formatFontSize(bestFitSize), Qt::MatchExactly); if (!selectedSizeList.isEmpty()) { sizeListBox->setCurrentItem(selectedSizeList.first()); } @@ -861,7 +848,6 @@ void KFontChooser::Private::setupDisplay() { - QFontDatabase dbase; QString family = selFont.family().toLower(); QString styleID = styleIdentifier(selFont); qreal size = selFont.pointSizeF(); @@ -942,7 +928,7 @@ // otherwise just select the nearest available size. QString currentFamily = qtFamilies[familyListBox->currentItem()->text()]; QString currentStyle = qtStyles[styleListBox->currentItem()->text()]; - bool canCustomize = dbase.isSmoothlyScalable(currentFamily, currentStyle); + bool canCustomize = fdb.isSmoothlyScalable(currentFamily, currentStyle); sizeListBox->setCurrentRow(nearestSizeRow(size, canCustomize)); // Set current size in the spinbox. @@ -957,18 +943,18 @@ // if we have criteria; then check fonts before adding if (fontListCriteria) { QStringList lstFonts; - for (QStringList::const_iterator it = lstSys.constBegin(); it != lstSys.constEnd(); ++it) { - if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) { + for (const QString &family : qAsConst(lstSys)) { + if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(family)) { continue; } if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) && - !dbase.isBitmapScalable(*it)) { + !dbase.isBitmapScalable(family)) { continue; } - if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) { + if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(family)) { continue; } - lstFonts.append(*it); + lstFonts.append(family); } if ((fontListCriteria & FixedWidthFonts) > 0) {