Fix initial dialog's positioning when it's done by Qt
ClosedPublic

Authored by volkov on Dec 20 2017, 5:41 PM.

Details

Summary

If a window manager doesn't position dialog windows, then
they are centered on a parent window by Qt.
DialogStateSaver::restoreWindowState() is called before
a layout is set for DialogBase and thus it resizes
DialogBase to (-1, -1) returned by DialogBase::sizeHint().
Qt centers the dialog with such size on its parent,
but the dialog changes its size in DialogBase::showEvent()
and becomes uncentered.

Setup the layout before DialogBase::showEvent() to fix it.

Diff Detail

Repository
R345 KMix
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
volkov requested review of this revision.Dec 20 2017, 5:41 PM
volkov created this revision.

Another option is to emit a signal in DialogBase::showEvent() after setting the layout and process it in DialogStateSaver instead of filtering events.

marten accepted this revision.Jan 1 2018, 9:42 AM

Thanks volkov for your investigations and comments - this code that previously I've only used for my personal stuff, so it's good to have someone else look at it.

It's not mandated in the KDE coding style, but I'd prefer to stick to the existing style in this file and do explicit pointer checks against nullptr (see inline comments).

Assuming that you've tested this with KMix master then please commit (with changes as marked inline) - I can merge your changes and check that everything else works properly.

Regarding your last comment, the intention of filtering events in DialogStateSaver was that it could also be used for saving/restoring the size where the dialogue is not based on DialogBase - e.g. a QFontDialog or a KPageDialog. You haven't needed to make any changes to DialogStateSaver, though, so it will still work in these use cases.

gui/dialogbase.cpp
64

w==nullptr

65

!=nullptr

72

!=nullptr

78

Also needs the mMainLayout->setStretchFactor(mMainWidget, 1); here
(gives all vertical stretch space to the main widget if the dialogue is enlarged).

This revision is now accepted and ready to land.Jan 1 2018, 9:42 AM
volkov added a comment.Jan 3 2018, 1:58 PM

Is it ok to push it to Applications/17.12?

ngraham added a subscriber: ngraham.Jan 3 2018, 5:13 PM
marten added a comment.Jan 4 2018, 1:35 PM

Is it ok to push it to Applications/17.12?

Yes please (with fixes as per inline comments).

volkov closed this revision.Jan 4 2018, 7:13 PM