Commit Graph

88 Commits

Author SHA1 Message Date
Sergio Martins
addf436fd0 LayoutSaver: Don't load old serialization versions 2020-05-08 19:30:41 +01:00
Sergio Martins
97c1ca30fd Layouting engine rewrite
The layouting was becoming too complex to maintain and to introduce
new features. Was even buggy, the fuzzer was constantly finding
bugs, which took hours to workaround.

Problem with the old layout engine is that there was a catch 22, between
Items driving the separators, and separators driving the anchors.

The new layout is much simpler, both in implementation and conceptually.
There's simply a recursive hierarchy of Item elements. An Item can either
have a QWidget to show, or be a ItemContainer, which contains Item children,
and so forth. Each ItemContainer is either vertical or horizontal. That's enough
to represent the "nested multi-splitter" concept which KDDW uses.

After each item insertion/deletion/resize, the separators are regenerated. They
are essentially dumb now.

TODO:
- Separators are drawn, but are not interactive yet
- There's 5 tests failing
- LayoutSaver scalling functionality
2020-05-04 00:02:03 +01:00
Sergio Martins
b236d744e3 Fix calculating main window scale 2020-03-25 15:56:19 +00:00
Sergio Martins
dbd90b8a02 LayoutSaver: Clear by affinity too
When restoring windows of the specified affinity clear only
the ones of that affinity
2020-03-01 15:02:22 +00:00
Sergio Martins
9904d847f2 LayoutSaver now can save/restore a sub-set of windows
Each subset is identified by its "affinity name".
See DockWidget/MainWindow setAffinityName property.

Patch contributed by Andras Mantia, I've changed it to deal in
terms of affinity names instead of unique names.
2020-03-01 14:25:31 +00:00
Sergio Martins
dedda6cb14 LayoutSaver: Also store the affinity in the JSON 2020-03-01 14:13:02 +00:00
Sergio Martins
af5bb4a3e4 Also store the percentage position in the json
just for checking that the restore is sane, even though
that property is calculated at runtime
2020-02-26 22:45:40 +00:00
Sergio Martins
ee786f57c5 LayoutSaver: Fix rounding errors when doing a relative restore
After a restore with relative sizes the items might not be on a pixel
perfect position regarding to their anchors. Make sure they are after
the restore is complete.
2020-02-25 23:24:39 +00:00
Sergio Martins
1d7c0316ab LayoutSaver: Fix applying factor to position
Was adding instead of multiplying, typo...
2020-02-25 21:18:36 +00:00
Sergio Martins
564a7091e1 LayoutSaver: Fix off-by-ones case with relative-restoring
If the window didn't change size nothing should happen
2020-02-25 20:00:46 +00:00
Sergio Martins
ca211f2494 LayoutSaver: Add an option to restore in relative sizes
and not touching the main window geometry.

The option is not exposed yet, there's a layouting bug to fix first.
2020-02-25 19:06:43 +00:00
Sergio Martins
6fb0694aab LayoutSaver: Replace saveToDisk() with saveToFile(jsonFilename)
Same for restore.
This is better API as LayoutSaver shouldn't be concerned about
QSettings. It also assumed the user only had a single layout, which
is normally not the case.

And finally, storing escaped json in .ini files is not very elegant.
2020-02-24 15:10:12 +00:00
Sergio Martins
bab0ff085e LayoutSaver now saves/loads in JSON format
This makes it easier to extend the format without being worried
about adding version checks all over the code
2020-02-24 14:57:03 +00:00
Sergio Martins
5b0eb93cda LayoutSaver: Add a json to/from methods
Still not being used by public api though.
2020-02-24 14:45:06 +00:00
Sergio Martins
758b4de5cc LayoutSaver: Fix serializing QSize and QRect to json
Failed silently to null instead
2020-02-24 14:40:38 +00:00
Sergio Martins
b78becfc01 Fix typo in json serialization 2020-02-24 13:39:48 +00:00
Sergio Martins
15d9f074fa Fix converting Item to json 2020-02-24 13:38:54 +00:00
Sergio Martins
fdb95e344a Fix converting Placeholder to json
Only dump the floating window index if we're in a floating window
2020-02-24 13:31:38 +00:00
Sergio Martins
69ada1bdad LayoutSaver: Add to/from variant map methods
To make it easy to use json instead of QDataStream
2020-02-23 22:55:30 +00:00
Sergio Martins
21660d9fc5 Remove unused method 2020-02-20 18:19:41 +00:00
Sergio Martins
e7661cca91 LayoutSaver: serialize/deserialize the screenSize and layoutSize too 2020-02-20 15:41:00 +00:00
Sergio Martins
2458b1c0f8 Add a way for the intermediate format to know it's version
It's a pain to pass the Layout or the version all the way
down the chain, so just add a static method
2020-02-20 14:56:51 +00:00
Sergio Martins
27e53ca68d Add missing reserve 2020-02-20 13:39:25 +00:00
Sergio Martins
63da84e343 LayoutSaver: Accept serialization formats with lower version 2020-02-20 13:36:10 +00:00
Sergio Martins
59bb0d8e71 FloatingWindow now receives MainWindow as argument
Instead of a generic QWidget. Only works with main window so
let's just use the right type
2020-02-09 18:24:37 +00:00
Sergio Martins
6da1a65591 Fix build with gcc -Werror=type-limits 2020-01-29 15:27:11 +00:00
Sergio Martins
cfa1cc47b6 Rephrase the warning about the insane layout 2020-01-13 12:50:45 +00:00
Allen Winter
df692686e7 various - update copyright year 2020-01-07 11:36:56 -05:00
Sergio Martins
21579f2743 Minor method renames 2019-10-07 00:16:16 +01:00
Albert Astals Cid
262d57b890 Add a few const &
as suggested by clang-tidy
2019-09-30 15:57:03 +02:00
Sergio Martins
68a536bb67 Minor renaming, deserialize() no matches serialized() 2019-09-21 16:18:19 +01:00
Sergio Martins
c80a16d2c1 Also use the intermediate representation when serializing 2019-09-21 15:15:44 +01:00
Sergio Martins
65c9693a62 Restoring now reads from the intermediate representation
Only the intermediate representation is filled in from the stream
now. TODO: GUI->intermediate.
2019-09-20 17:24:22 +01:00
Sergio Martins
cde4bd9bbd LayoutSaver: Add more validation 2019-09-10 19:19:22 +01:00
Sergio Martins
5a3727deae LayoutSaver: Also validate anchors upper bound 2019-09-10 19:03:49 +01:00
Sergio Martins
4261e831d6 Fix build 2019-09-10 18:55:14 +01:00
Sergio Martins
a348274bc4 Add LayoutSaver::Layout::isValid() 2019-09-10 18:52:33 +01:00
Sergio Martins
21afb04555 Use LayoutSaver::DockWidget by pointer
As we're changing it's shared and we're changing its members.
This way the members changes everywhere, as there's only 1 instance
of each dock widget
2019-09-10 17:21:09 +01:00
Sergio Martins
5448c9655e Introduce an intermediate serialization format for save/restore
QDataStream is opaque and is not good for validation.
With this intermediate format we'll be able to:
- manipulate stuff
- validate that the saved layout is correct, before restoring it
- decide about some restore heuristics which would have been impossible
because before we needed to restore as we read the stream, now we can
look at the state before restoring it

LayoutSaver isn't using the new format yet, but the LayoutSaver::Layout
is already useful to debug some bogus saved states
2019-09-10 16:24:14 +01:00
Sergio Martins
cad7486907 Introduce MainWindowBase
MainWindow is widgets only. MainWindowBase will be used by QtQuick too.
2019-09-04 15:31:55 +01:00
Sergio Martins
46a5a580bc Add LayoutSaver::restoredDockWidgets()
Implemented as a property it's better that the LayoutSaver
doesn't carry state about this. Then we would need to remove dock
widgets from the list if they are deleted. Also not a important
enough feature to be on the DockWidget public interface.
2019-08-28 17:56:18 +01:00
Sergio Martins
c1ea98825e Improve includes 2019-08-12 16:41:00 +01:00
Sergio Martins
990e487fed rename name() to uniqueName() for readability 2019-08-08 22:30:29 +01:00
Sergio Martins
a8ac0412fa More build fixes without QtWidgets 2019-08-08 11:37:14 +01:00
Sergio Martins
fb837b7713 Move DockWidget.cpp into widgets/
As it's specific to QtWidgets. It's mostly empty now
and inheriting from DockWidgetBase, but we'll move a few stuff.
2019-08-05 23:35:44 +01:00
Sergio Martins
ae7934dd47 Abstract FloatingWindow too, introducing FloatingWindowWidget 2019-08-05 02:41:34 +01:00
Sergio Martins
8c8d6503f8 Don't delete the central frame when restoring
This one can be empty.

Caught by a failing unit-test
2019-08-01 17:09:03 +01:00
Sergio Martins
9fd4df484d Add test for DockWidgetFactoryFunc 2019-08-01 10:50:40 +01:00
Sergio Martins
c4e13cd949 Delete empty frames in case dock widget isn't found 2019-07-31 12:24:07 +01:00
Sergio Martins
fd0b594331 Save the geometry of the actual top-level window
In case we have a main window embedded in another widget
2019-07-27 18:56:29 +01:00