The kfontrequestertest app still works
Details
- Reviewers
dfaure cfeck - Group Reviewers
Frameworks - Commits
- R236:56090c8f380e: [KFontRequester] Port from QFontDialog to KFontChooserDialog
Diff Detail
- Repository
- R236 KWidgetsAddons
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
src/kfontrequester.cpp | ||
---|---|---|
188 | It's really not obvious from the above that this modifies m_selFont. But I see QFont has no isValid() so we can't adopt an API like QColorDialog::getColor (plus KFontChooserDialog has been released now). Oh well. |
src/kfontrequester.cpp | ||
---|---|---|
188 | Plus we can't end up with a non-valid QFont, the dialog is filled from QFontDataBase; so unless the user went and uninstalled the font while the dialog was open, it should be OK. Also, font substitution will take care of a font-gone-MIA (I am sure of that on Linux, and most likely other OS's have similar solutions). I was curious so I looked at QColorDialog::getColor() and it looks like they changed it (or you meant getRgba?). |
src/kfontrequester.cpp | ||
---|---|---|
188 | And yes, it's not obvious that m_selFont is modified, I had to go read the API docs KFontChooser multiple times... but I got used to it. |
I mean, the user can press cancel, that's when QColorDialog returns an invalid color.
If there was a concept like an invalid font we could do the same here, but there's no such concept in QFont.
So yep, no better way.
Looking at the code, if the user presses cancel, "theFont" is returned unchanged; seems pretty good to me:
int KFontChooserDialog::getFont(QFont &theFont, const KFontChooser::DisplayFlags &flags, QWidget *parent) { KFontChooserDialog dlg(flags, parent); dlg.setObjectName(QStringLiteral("Font Selector")); dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly); const int result = dlg.exec(); if (result == Accepted) { theFont = dlg.d->chooser->font(); stripRegularStyleName(theFont); } return result; }
QFontDialog::getFont() returns a QFont, and one may pass a bool * to check the dialog result code:
QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title, FontDialogOptions options)
which is standard Qt behaviour from other dialogs/widgets that handle user yes/no use cases, IIRC.
The KFontChooer* approach is more "economical", the "initial" font and the font you get from the dialog if you press OK, are the same object, and the function returns the dialog result code. As some wise old builder once said "there's no right or wrong way to lay bricks, as long as it works".
Why not add support for QPlatformTheme::FontDialog in KdePlatformTheme::createPlatformDialogHelper()?
Sorry about the late reply; I had looked into the platformtheme integration stuff, but at the time I didn't think it was a viable solution (nor was it easy for me to port); see https://phabricator.kde.org/D27808 for more details.