[Fonts KCM] Use KFontChooserDialog instead of QFontDialog
ClosedPublic

Authored by ahmadsamir on Mar 3 2020, 4:34 PM.

Details

Summary

Now all font selection dialogs use KFontChooserDialog (from KWidgetAddons),
bump KF5 minimum required version to 5.69.0.

KFontChooserDialog has some pros over QFontDialog:

    • If the font to pre-select in KFontChooser doesn't have the styleName property set, the dialog will try and select the correct style (usually that works); this is useful since we want to save/load fonts with "Regular"-like styles without setting that property so that setBold(true) can work properly
  • Fractional font sizes, e.g. 10.5 pt (QFontDialog only supports int)
  • KFontChooserDialog will discard "Regular"-like styleName prop. after the user has selected a font, which means less workarounds in the fonts KCM code.

Do not check for immutability:

  • The setters generated by KConfig already do that
  • The QML FontWidget check for immutability and disable the relevant font widget

adjustAllFonts() doesn't take any args, change the qml code accrodingly.

Test Plan

The fonts KCM still works.

Diff Detail

Repository
R119 Plasma Desktop
Branch
l-qfontdlg-track-nearest (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 23199
Build 23217: arc lint + arc unit
ahmadsamir created this revision.Mar 3 2020, 4:34 PM
Restricted Application added a project: Plasma. · View Herald TranscriptMar 3 2020, 4:34 PM
ahmadsamir requested review of this revision.Mar 3 2020, 4:34 PM
bport added a subscriber: bport.Mar 9 2020, 9:32 AM

With your change, we are not allowed anymore to change for example only font and keeping different size, style for each kind of font (window, menu, toolbar...), right ?

With your change, we are not allowed anymore to change for example only font and keeping different size, style for each kind of font (window, menu, toolbar...), right ?

IIUC, that is a feature of KFontDialog (from KDELibs4Support), not available in QFontDialog.

I probably should mention that in the commit message.

ahmadsamir edited the summary of this revision. (Show Details)Mar 9 2020, 10:12 AM
meven added inline comments.Mar 9 2020, 10:01 PM
kcms/fonts/fonts.cpp
678

s/monspace/monospace

meven added a comment.Mar 9 2020, 10:12 PM

Porting with such feature regression is hard to justify.

Perhaps we should port KFontDialog (it is ~150 lines of cpp) to kwidgetsaddons instead, KFontChooser is already there.
Or better perhaps implement here a simple QDialog embedding KFontChooser and providing equivalent features needed here that KFontDialog has.
This is a typical work we did for KF5 https://community.kde.org/Frameworks/Porting_Notes

ahmadsamir planned changes to this revision.Mar 9 2020, 10:39 PM

It seems I messed up the branches stuff (or phabricator works in a way I don't understand), so I think it's best to work at one diff at a time, instead of wasting time trying to make sense of this situation.... :/ (I will address all comments regardless).

It all starts with D27785.

Porting with such feature regression is hard to justify.

I honestly don't know how many users actually use that feature; if it's still widely used, then yeah, that would definitely be a feature regression.

Perhaps we should port KFontDialog (it is ~150 lines of cpp) to kwidgetsaddons instead, KFontChooser is already there.
Or better perhaps implement here a simple QDialog embedding KFontChooser and providing equivalent features needed here that KFontDialog has.
This is a typical work we did for KF5 https://community.kde.org/Frameworks/Porting_Notes

Since, AFAICS, only the fonts KCM uses that functionality, it might be better to move/copy KFontDialog to the KCM, and maybe rename it; it'd be a helper class of sorts.

And another question, "General", "Menu", "Toolbar", how many users actually set these three to individual font families/styles/sizes?

meven added a comment.EditedMar 10 2020, 8:43 AM

And another question, "General", "Menu", "Toolbar", how many users actually set these three to individual font families/styles/sizes?

If anything this is just not relevant here. Either you port things away from kde4support or you change the behavior but the two things should not be done together.
Generally the community has rarely removed any working features and this is a kind of feature plasma is known for : customization.

Porting with such feature regression is hard to justify.

I honestly don't know how many users actually use that feature; if it's still widely used, then yeah, that would definitely be a feature regression.

Perhaps we should port KFontDialog (it is ~150 lines of cpp) to kwidgetsaddons instead, KFontChooser is already there.
Or better perhaps implement here a simple QDialog embedding KFontChooser and providing equivalent features needed here that KFontDialog has.
This is a typical work we did for KF5 https://community.kde.org/Frameworks/Porting_Notes

Since, AFAICS, only the fonts KCM uses that functionality, it might be better to move/copy KFontDialog to the KCM, and maybe rename it; it'd be a helper class of sorts.

Moving KFontDialog would imply porting it to QDialog anyway.
But license might get in the way since kdelibs4support is LGPL and plasma is GPL.
It would mean the moved KFontDialog would stay LGPL in a GPL codebase. Which is possible but not recommendable at all.

> implement here a simple QDialog embedding KFontChooser and providing equivalent features needed here that KFontDialog has.

I would suggest you this simpler way to do it, but the code of this QDialog helper would be loosely inspired by KFontDialog anyway but not LGPL.
In the end that's pretty much the same thing as you suggested but better keep license potential issues at bay ;)

And another question, "General", "Menu", "Toolbar", how many users actually set these three to individual font families/styles/sizes?

If anything this is just not relevant here. Either you port things away from kde4support or you change the behavior but the two things should not be done together.
Generally the community has rarely removed any working features and this is a kind of feature plasma is known for : customization.

That wasn't my intention (I mean changing it in this diff), it was a BTW kind of thought/question "is this still needed/used nowadays?", I was thinking of posting the question to the frameworks ML... but was afraid it might start a flame/bike-shedding conundrum there, so I asked here instead :)

Porting with such feature regression is hard to justify.

I honestly don't know how many users actually use that feature; if it's still widely used, then yeah, that would definitely be a feature regression.

Perhaps we should port KFontDialog (it is ~150 lines of cpp) to kwidgetsaddons instead, KFontChooser is already there.
Or better perhaps implement here a simple QDialog embedding KFontChooser and providing equivalent features needed here that KFontDialog has.
This is a typical work we did for KF5 https://community.kde.org/Frameworks/Porting_Notes

Since, AFAICS, only the fonts KCM uses that functionality, it might be better to move/copy KFontDialog to the KCM, and maybe rename it; it'd be a helper class of sorts.

Moving KFontDialog would imply porting it to QDialog anyway.
But license might get in the way since kdelibs4support is LGPL and plasma is GPL.
It would mean the moved KFontDialog would stay LGPL in a GPL codebase. Which is possible but not recommendable at all.

> implement here a simple QDialog embedding KFontChooser and providing equivalent features needed here that KFontDialog has.

I would suggest you this simpler way to do it, but the code of this QDialog helper would be loosely inspired by KFontDialog anyway but not LGPL.
In the end that's pretty much the same thing as you suggested but better keep license potential issues at bay ;)

Good point(s). :D

cfeck added a subscriber: cfeck.Mar 10 2020, 9:47 AM

We already lost fractional point sizes when porting from KFontDialog to QFontDialog. Best approach is to add the KFontDialog to the platform plugin (and also the old KColorDialog while you are at it), or upstream our features to Qt.

Btw, I set Toolbar font to a "condensed" version, to have more horizontal room for toolbars with text aside icons.

We already lost fractional point sizes when porting from KFontDialog to QFontDialog.

Yeah, I never understood why they opted for integer values only (I will dig in upstream log history to find if there any rationale behind that, if I find nothing I will, FWIW, file a bug report upstream).

Best approach is to add the KFontDialog to the platform plugin (and also the old KColorDialog while you are at it), or upstream our features to Qt.

Now, that sounds like a good idea, sort of like how the open file dialog from KIO is used instead of the upstream vanilla one (I'll need to figure out how that works to begin with).

Btw, I set Toolbar font to a "condensed" version, to have more horizontal room for toolbars with text aside icons.

OK, message received. :)

We already lost fractional point sizes when porting from KFontDialog to QFontDialog.

Yeah, I never understood why they opted for integer values only (I will dig in upstream log history to find if there any rationale behind that, if I find nothing I will, FWIW, file a bug report upstream).

Best approach is to add the KFontDialog to the platform plugin (and also the old KColorDialog while you are at it), or upstream our features to Qt.

Now, that sounds like a good idea, sort of like how the open file dialog from KIO is used instead of the upstream vanilla one (I'll need to figure out how that works to begin with).

Repo is at https://cgit.kde.org/plasma-integration.git/
This is around : QPlatformFontDialogHelper https://code.woboq.org/qt5/qtbase/src/gui/kernel/qplatformdialoghelper.h.html
You can use https://cgit.kde.org/plasma-integration.git/tree/src/platformtheme/kdeplatformfiledialoghelper.cpp as base.

I spent some time looking (and hacking at a kdeplatformfontdialoghelper...) at the code in kdeplatformfiledialoghelper, KFontChooser and KFontDialog, and I am starting to think that moving KFontDialog to KWidgetAddons (where KFontChooser and KFontRequester live) is a better/more viable solution. Also the differences/features between KFonDialog/KFontChooser v.s. QFontDialog are numerous, unlike KIO open file dialog v.s. QFileDialog.

Are there examples of how to move/port a class from one repo to another?

meven added a comment.Mar 25 2020, 2:09 PM

With D28122 I think you can go ahead and port this code to it.
Unless you want to take care of the QPlatform integration for it first.

I am not so sure about the QPlatform integration bit, it looks easier/cleaner to just use KFontChooserDialog; QFontDialog isn't widely used in KDE code, so porting to KFontChooserDialog is doable (though that sounds like going back in time to using KFontDialog in KDE4, then porting to QFontDialog in KF5... now back to KFont* variant....).

For now I'll port the code here to KFontChooserDialog.

ahmadsamir updated this revision to Diff 78519.Mar 26 2020, 8:22 AM
ahmadsamir retitled this revision from [Fonts KCM] Port KFontDialog/KFontChooser to QFontDialog to [Fonts KCM] Use KFontChooserDialog instead of QFontDialog.
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir edited the test plan for this revision. (Show Details)
ahmadsamir edited reviewers, added: cfeck, bport; removed: ervin.
ahmadsamir removed subscribers: cfeck, bport.

Use KFontChooserDialog

meven added a comment.Mar 26 2020, 5:12 PM

Seems good to me
@bport should be the best reviewer here.

bport accepted this revision.Apr 9 2020, 7:01 AM

Thanks for your work

This revision is now accepted and ready to land.Apr 9 2020, 7:01 AM
This revision was automatically updated to reflect the committed changes.