25 #include "private/LayoutSaver_p.h"
26 #include "private/DockRegistry_p.h"
27 #include "private/DockWidgetBase_p.h"
28 #include "private/FloatingWindow_p.h"
29 #include "private/Frame_p.h"
30 #include "private/LayoutWidget_p.h"
31 #include "private/Logging_p.h"
32 #include "private/Position_p.h"
61 LayoutSaver::Layout *LayoutSaver::Layout::s_currentLayoutBeingRestored =
nullptr;
67 return InternalRestoreOption::None;
69 return InternalRestoreOptions(InternalRestoreOption::SkipMainWindowGeometry)
70 | InternalRestoreOption::RelativeFloatingWindowGeometry;
72 qWarning() << Q_FUNC_INFO <<
"Unknown options" << options;
77 bool LayoutSaver::Private::s_restoreInProgress =
false;
81 QVariantList variantList;
82 variantList.reserve(strs.
size());
84 variantList.push_back(str);
92 stringList.
reserve(variantList.size());
93 for (
const QVariant &variant : variantList)
100 : d(new Private(options))
113 QFile f(jsonFilename);
115 qWarning() << Q_FUNC_INFO <<
"Failed to open" << jsonFilename << f.
errorString();
125 QFile f(jsonFilename);
127 qWarning() << Q_FUNC_INFO <<
"Failed to open" << jsonFilename << f.
errorString();
139 if (!d->m_dockRegistry->isSane()) {
140 qWarning() << Q_FUNC_INFO <<
"Refusing to serialize this layout. Check previous warnings.";
144 LayoutSaver::Layout layout;
147 d->m_dockRegistry->ensureAllFloatingWidgetsAreMorphed();
150 layout.mainWindows.reserve(mainWindows.
size());
152 if (d->matchesAffinity(mainWindow->affinities()))
153 layout.mainWindows.push_back(mainWindow->serialize());
157 layout.floatingWindows.reserve(floatingWindows.
size());
158 for (KDDockWidgets::FloatingWindow *floatingWindow : floatingWindows) {
159 if (d->matchesAffinity(floatingWindow->affinities()))
160 layout.floatingWindows.push_back(floatingWindow->serialize());
165 layout.closedDockWidgets.reserve(closedDockWidgets.
size());
167 if (d->matchesAffinity(dockWidget->affinities()))
168 layout.closedDockWidgets.push_back(dockWidget->d->serialize());
175 layout.allDockWidgets.reserve(dockWidgets.
size());
177 if (d->matchesAffinity(dockWidget->affinities())) {
178 auto dw = dockWidget->d->serialize();
179 dw->lastPosition = dockWidget->d->lastPositions().serialize();
180 layout.allDockWidgets.push_back(dw);
184 return layout.toJson();
189 d->clearRestoredProperty();
202 m_saver->d->deleteEmptyFrames();
208 FrameCleanup cleanup(
this);
209 LayoutSaver::Layout layout;
210 if (!layout.fromJson(data)) {
211 qWarning() << Q_FUNC_INFO <<
"Failed to parse json data";
215 if (!layout.isValid()) {
219 layout.scaleSizes(d->m_restoreOptions);
221 d->floatWidgetsWhichSkipRestore(layout.mainWindowNames());
222 d->floatUnknownWidgets(layout);
224 Private::RAIIIsRestoring isRestoring;
229 d->m_dockRegistry->clear(d->m_dockRegistry->dockWidgets(layout.dockWidgetsToClose()),
230 d->m_dockRegistry->mainWindows(layout.mainWindowNames()),
234 for (
const LayoutSaver::MainWindow &mw : qAsConst(layout.mainWindows)) {
235 MainWindowBase *mainWindow = d->m_dockRegistry->mainWindowByName(mw.uniqueName);
237 if (
auto mwFunc =
Config::self().mainWindowFactoryFunc()) {
238 mainWindow = mwFunc(mw.uniqueName);
240 qWarning() <<
"Failed to restore layout create MainWindow with name" << mw.uniqueName <<
"first";
245 if (!d->matchesAffinity(mainWindow->
affinities()))
248 if (!(d->m_restoreOptions & InternalRestoreOption::SkipMainWindowGeometry)) {
249 d->deserializeWindowGeometry(mw, mainWindow->
window());
252 w->setWindowState(mw.windowState);
257 if (!mainWindow->deserialize(mw))
262 for (LayoutSaver::FloatingWindow &fw : layout.floatingWindows) {
263 if (!d->matchesAffinity(fw.affinities) || fw.skipsRestore())
267 : DockRegistry::self()->mainwindows().at(fw.parentIndex);
270 fw.floatingWindowInstance = floatingWindow;
271 d->deserializeWindowGeometry(fw, floatingWindow);
272 if (!floatingWindow->deserialize(fw)) {
273 qWarning() << Q_FUNC_INFO <<
"Failed to deserialize floating window";
279 for (
const auto &dw : qAsConst(layout.closedDockWidgets)) {
280 if (d->matchesAffinity(dw->affinities)) {
281 DockWidgetBase::deserialize(dw);
286 for (
const auto &dw : qAsConst(layout.allDockWidgets)) {
287 if (!d->matchesAffinity(dw->affinities))
291 d->m_dockRegistry->dockByName(dw->uniqueName, DockRegistry::DockByNameFlag::ConsultRemapping)) {
292 dockWidget->d->lastPositions().deserialize(dw->lastPosition);
294 qWarning() << Q_FUNC_INFO <<
"Couldn't find dock widget" << dw->uniqueName;
303 d->m_affinityNames = affinityNames;
306 d->m_affinityNames <<
QString();
321 if (dw->property(
"kddockwidget_was_restored").toBool())
328 void LayoutSaver::Private::clearRestoredProperty()
332 dw->setProperty(
"kddockwidget_was_restored",
QVariant());
337 void LayoutSaver::Private::deserializeWindowGeometry(
const T &saved,
QWidgetOrQuick *topLevel)
342 auto windowGeometry = saved.geometry;
343 ::FloatingWindow::ensureRectIsOnScreen(windowGeometry);
348 KDDockWidgets::Private::setTopLevelGeometry(windowGeometry, topLevel);
354 LayoutSaver::Private::Private(RestoreOptions options)
355 : m_dockRegistry(DockRegistry::self())
360 bool LayoutSaver::Private::matchesAffinity(
const QStringList &affinities)
const
362 return m_affinityNames.isEmpty() || affinities.
isEmpty()
363 || DockRegistry::self()->affinitiesMatch(m_affinityNames, affinities);
366 void LayoutSaver::Private::floatWidgetsWhichSkipRestore(
const QStringList &mainWindowNames)
373 for (
MainWindowBase *mw : DockRegistry::self()->mainWindows(mainWindowNames)) {
375 for (
auto dw : docks) {
376 if (dw->skipsRestore()) {
377 dw->setFloating(
true);
383 void LayoutSaver::Private::floatUnknownWidgets(
const LayoutSaver::Layout &layout)
389 for (
MainWindowBase *mw : DockRegistry::self()->mainWindows(layout.mainWindowNames())) {
392 if (!layout.containsDockWidget(dw->uniqueName())) {
393 dw->setFloating(
true);
399 void LayoutSaver::Private::deleteEmptyFrames()
404 for (
auto frame : m_dockRegistry->frames()) {
405 if (!frame->beingDeletedLater() && frame->isEmpty() && !frame->isCentralFrame())
410 std::unique_ptr<QSettings> LayoutSaver::Private::settings()
const
412 auto settings = std::unique_ptr<QSettings>(
new QSettings(qApp->organizationName(),
413 qApp->applicationName()));
414 settings->beginGroup(QStringLiteral(
"KDDockWidgets::LayoutSaver"));
421 return Private::s_restoreInProgress;
424 bool LayoutSaver::Layout::isValid()
const
426 if (serializationVersion != KDDOCKWIDGETS_SERIALIZATION_VERSION) {
427 qWarning() << Q_FUNC_INFO <<
"Serialization format is too old"
428 << serializationVersion <<
"current=" << KDDOCKWIDGETS_SERIALIZATION_VERSION;
432 for (
auto &m : mainWindows) {
437 for (
auto &m : floatingWindows) {
442 for (
auto &m : allDockWidgets) {
450 QByteArray LayoutSaver::Layout::toJson()
const
456 bool LayoutSaver::Layout::fromJson(
const QByteArray &jsonData)
468 QVariantMap LayoutSaver::Layout::toVariantMap()
const
471 map.insert(QStringLiteral(
"serializationVersion"), serializationVersion);
472 map.insert(QStringLiteral(
"mainWindows"), toVariantList<LayoutSaver::MainWindow>(mainWindows));
473 map.insert(QStringLiteral(
"floatingWindows"), toVariantList<LayoutSaver::FloatingWindow>(floatingWindows));
474 map.insert(QStringLiteral(
"closedDockWidgets"), ::dockWidgetNames(closedDockWidgets));
475 map.insert(QStringLiteral(
"allDockWidgets"), toVariantList(allDockWidgets));
476 map.insert(QStringLiteral(
"screenInfo"), toVariantList<LayoutSaver::ScreenInfo>(screenInfo));
481 void LayoutSaver::Layout::fromVariantMap(
const QVariantMap &map)
483 allDockWidgets.clear();
484 const QVariantList dockWidgetsV = map.value(QStringLiteral(
"allDockWidgets")).toList();
485 for (
const QVariant &v : dockWidgetsV) {
486 const QVariantMap dwV = v.toMap();
487 const QString name = dwV.value(QStringLiteral(
"uniqueName")).toString();
488 auto dw = LayoutSaver::DockWidget::dockWidgetForName(name);
489 dw->fromVariantMap(dwV);
490 allDockWidgets.push_back(dw);
493 closedDockWidgets.clear();
494 const QVariantList closedDockWidgetsV = map.value(QStringLiteral(
"closedDockWidgets")).toList();
495 closedDockWidgets.reserve(closedDockWidgetsV.size());
496 for (
const QVariant &v : closedDockWidgetsV) {
497 closedDockWidgets.push_back(LayoutSaver::DockWidget::dockWidgetForName(v.toString()));
500 serializationVersion = map.value(QStringLiteral(
"serializationVersion")).toInt();
501 mainWindows = fromVariantList<LayoutSaver::MainWindow>(map.value(QStringLiteral(
"mainWindows")).toList());
502 floatingWindows = fromVariantList<LayoutSaver::FloatingWindow>(map.value(QStringLiteral(
"floatingWindows")).toList());
503 screenInfo = fromVariantList<LayoutSaver::ScreenInfo>(map.value(QStringLiteral(
"screenInfo")).toList());
506 void LayoutSaver::Layout::scaleSizes(InternalRestoreOptions options)
508 if (mainWindows.isEmpty())
511 const bool skipsMainWindowGeometry = options & InternalRestoreOption::SkipMainWindowGeometry;
512 if (!skipsMainWindowGeometry) {
521 for (
auto &mw : mainWindows)
527 const bool useRelativeSizesForFloatingWidgets =
528 options & InternalRestoreOption::RelativeFloatingWindowGeometry;
530 if (useRelativeSizesForFloatingWidgets) {
531 for (
auto &fw : floatingWindows) {
532 LayoutSaver::MainWindow mw = mainWindowForIndex(fw.parentIndex);
533 if (mw.scalingInfo.isValid())
534 fw.scaleSizes(mw.scalingInfo);
538 const ScalingInfo firstScalingInfo = mainWindows.constFirst().scalingInfo;
539 if (firstScalingInfo.isValid()) {
540 for (
auto &dw : allDockWidgets) {
544 dw->scaleSizes(firstScalingInfo);
549 LayoutSaver::MainWindow LayoutSaver::Layout::mainWindowForIndex(
int index)
const
551 if (index < 0 || index >= mainWindows.size())
554 return mainWindows.at(index);
557 LayoutSaver::FloatingWindow LayoutSaver::Layout::floatingWindowForIndex(
int index)
const
559 if (index < 0 || index >= floatingWindows.size())
562 return floatingWindows.at(index);
565 QStringList LayoutSaver::Layout::mainWindowNames()
const
568 names.
reserve(mainWindows.size());
569 for (
const auto &mw : mainWindows) {
570 names << mw.uniqueName;
576 QStringList LayoutSaver::Layout::dockWidgetNames()
const
579 names.
reserve(allDockWidgets.size());
580 for (
const auto &dw : allDockWidgets) {
581 names << dw->uniqueName;
587 QStringList LayoutSaver::Layout::dockWidgetsToClose()
const
592 names.
reserve(allDockWidgets.size());
593 auto registry = DockRegistry::self();
594 for (
const auto &dw : allDockWidgets) {
595 if (
DockWidgetBase *dockWidget = registry->dockByName(dw->uniqueName)) {
599 if (dockWidget->skipsRestore()) {
600 if (
auto fw = dockWidget->floatingWindow()) {
609 names << dw->uniqueName;
616 bool LayoutSaver::Layout::containsDockWidget(
const QString &uniqueName)
const
618 return std::find_if(allDockWidgets.cbegin(), allDockWidgets.cend(), [uniqueName](
const std::shared_ptr<LayoutSaver::DockWidget> &dock) {
619 return dock->uniqueName == uniqueName;
621 != allDockWidgets.
cend();
624 bool LayoutSaver::Frame::isValid()
const
629 if (!geometry.isValid()) {
630 qWarning() << Q_FUNC_INFO <<
"Invalid geometry";
635 qWarning() << Q_FUNC_INFO <<
"Invalid id";
639 if (!dockWidgets.isEmpty()) {
640 if (currentTabIndex >= dockWidgets.size() || currentTabIndex < 0) {
641 qWarning() << Q_FUNC_INFO <<
"Invalid tab index" << currentTabIndex << dockWidgets.size();
646 for (
auto &dw : dockWidgets) {
654 bool LayoutSaver::Frame::hasSingleDockWidget()
const
656 return dockWidgets.size() == 1;
659 bool LayoutSaver::Frame::skipsRestore()
const
661 return std::all_of(dockWidgets.cbegin(), dockWidgets.cend(), [](LayoutSaver::DockWidget::Ptr dw) {
662 return dw->skipsRestore();
666 LayoutSaver::DockWidget::Ptr LayoutSaver::Frame::singleDockWidget()
const
668 if (!hasSingleDockWidget())
671 return dockWidgets.first();
674 QVariantMap LayoutSaver::Frame::toVariantMap()
const
677 map.insert(QStringLiteral(
"id"),
id);
678 map.insert(QStringLiteral(
"isNull"), isNull);
679 map.insert(QStringLiteral(
"objectName"), objectName);
680 map.insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
681 map.insert(QStringLiteral(
"options"), options);
682 map.insert(QStringLiteral(
"currentTabIndex"), currentTabIndex);
683 map.insert(QStringLiteral(
"mainWindowUniqueName"), mainWindowUniqueName);
684 map.insert(QStringLiteral(
"dockWidgets"), dockWidgetNames(dockWidgets));
689 void LayoutSaver::Frame::fromVariantMap(
const QVariantMap &map)
697 id = map.value(QStringLiteral(
"id")).toString();
698 isNull = map.value(QStringLiteral(
"isNull")).toBool();
699 objectName = map.value(QStringLiteral(
"objectName")).toString();
700 mainWindowUniqueName = map.value(QStringLiteral(
"mainWindowUniqueName")).toString();
701 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
703 currentTabIndex = map.value(QStringLiteral(
"currentTabIndex")).toInt();
705 const QVariantList dockWidgetsV = map.value(QStringLiteral(
"dockWidgets")).toList();
708 dockWidgets.reserve(dockWidgetsV.size());
709 for (
const auto &variant : dockWidgetsV) {
710 DockWidget::Ptr dw = DockWidget::dockWidgetForName(variant.toString());
711 dockWidgets.push_back(dw);
715 bool LayoutSaver::DockWidget::isValid()
const
720 void LayoutSaver::DockWidget::scaleSizes(
const ScalingInfo &scalingInfo)
722 lastPosition.scaleSizes(scalingInfo);
725 bool LayoutSaver::DockWidget::skipsRestore()
const
727 if (
DockWidgetBase *dw = DockRegistry::self()->dockByName(uniqueName))
728 return dw->skipsRestore();
733 QVariantMap LayoutSaver::DockWidget::toVariantMap()
const
738 map.insert(QStringLiteral(
"uniqueName"), uniqueName);
739 map.insert(QStringLiteral(
"lastPosition"), lastPosition.toVariantMap());
744 void LayoutSaver::DockWidget::fromVariantMap(
const QVariantMap &map)
749 const QString affinityName = map.value(QStringLiteral(
"affinityName")).toString();
754 uniqueName = map.value(QStringLiteral(
"uniqueName")).toString();
755 lastPosition.fromVariantMap(map.value(QStringLiteral(
"lastPosition")).toMap());
758 bool LayoutSaver::FloatingWindow::isValid()
const
760 if (!multiSplitterLayout.isValid())
763 if (!geometry.isValid()) {
764 qWarning() << Q_FUNC_INFO <<
"Invalid geometry";
771 bool LayoutSaver::FloatingWindow::hasSingleDockWidget()
const
773 return multiSplitterLayout.hasSingleDockWidget();
776 LayoutSaver::DockWidget::Ptr LayoutSaver::FloatingWindow::singleDockWidget()
const
778 return multiSplitterLayout.singleDockWidget();
781 bool LayoutSaver::FloatingWindow::skipsRestore()
const
783 return multiSplitterLayout.skipsRestore();
786 void LayoutSaver::FloatingWindow::scaleSizes(
const ScalingInfo &scalingInfo)
788 scalingInfo.applyFactorsTo( geometry);
791 QVariantMap LayoutSaver::FloatingWindow::toVariantMap()
const
794 map.
insert(QStringLiteral(
"multiSplitterLayout"), multiSplitterLayout.toVariantMap());
795 map.
insert(QStringLiteral(
"parentIndex"), parentIndex);
796 map.
insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
797 map.
insert(QStringLiteral(
"normalGeometry"), Layouting::rectToMap(normalGeometry));
798 map.
insert(QStringLiteral(
"screenIndex"), screenIndex);
799 map.
insert(QStringLiteral(
"screenSize"), Layouting::sizeToMap(screenSize));
800 map.
insert(QStringLiteral(
"isVisible"), isVisible);
801 map.
insert(QStringLiteral(
"windowState"), windowState);
809 void LayoutSaver::FloatingWindow::fromVariantMap(
const QVariantMap &map)
811 multiSplitterLayout.fromVariantMap(map.value(QStringLiteral(
"multiSplitterLayout")).toMap());
812 parentIndex = map.value(QStringLiteral(
"parentIndex")).
toInt();
813 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
814 normalGeometry = Layouting::mapToRect(map.value(QStringLiteral(
"normalGeometry")).toMap());
815 screenIndex = map.value(QStringLiteral(
"screenIndex")).toInt();
816 screenSize = Layouting::mapToSize(map.value(QStringLiteral(
"screenSize")).toMap());
817 isVisible = map.value(QStringLiteral(
"isVisible")).toBool();
822 const QString affinityName = map.value(QStringLiteral(
"affinityName")).toString();
828 bool LayoutSaver::MainWindow::isValid()
const
830 if (!multiSplitterLayout.isValid())
836 void LayoutSaver::MainWindow::scaleSizes()
838 if (scalingInfo.isValid()) {
844 scalingInfo = ScalingInfo(uniqueName, geometry, screenIndex);
847 QVariantMap LayoutSaver::MainWindow::toVariantMap()
const
850 map.insert(QStringLiteral(
"options"),
int(options));
851 map.insert(QStringLiteral(
"multiSplitterLayout"), multiSplitterLayout.toVariantMap());
852 map.insert(QStringLiteral(
"uniqueName"), uniqueName);
853 map.insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
854 map.insert(QStringLiteral(
"screenIndex"), screenIndex);
855 map.insert(QStringLiteral(
"screenSize"), Layouting::sizeToMap(screenSize));
856 map.insert(QStringLiteral(
"isVisible"), isVisible);
858 map.insert(QStringLiteral(
"windowState"), windowState);
869 void LayoutSaver::MainWindow::fromVariantMap(
const QVariantMap &map)
871 options = KDDockWidgets::MainWindowOptions(map.value(QStringLiteral(
"options")).toInt());
872 multiSplitterLayout.fromVariantMap(map.value(QStringLiteral(
"multiSplitterLayout")).toMap());
873 uniqueName = map.value(QStringLiteral(
"uniqueName")).toString();
874 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
875 screenIndex = map.value(QStringLiteral(
"screenIndex")).toInt();
876 screenSize = Layouting::mapToSize(map.value(QStringLiteral(
"screenSize")).toMap());
877 isVisible = map.value(QStringLiteral(
"isVisible")).toBool();
882 const QString affinityName = map.value(QStringLiteral(
"affinityName")).toString();
888 dockWidgetsPerSideBar.clear();
890 const QVariantList dockWidgets = map.
value(QStringLiteral(
"sidebar-%1").arg(
int(loc))).toList();
891 if (!dockWidgets.isEmpty())
896 bool LayoutSaver::MultiSplitter::isValid()
const
898 if (layout.isEmpty())
909 bool LayoutSaver::MultiSplitter::hasSingleDockWidget()
const
911 return frames.size() == 1 && frames.cbegin()->hasSingleDockWidget();
914 LayoutSaver::DockWidget::Ptr LayoutSaver::MultiSplitter::singleDockWidget()
const
916 if (!hasSingleDockWidget())
919 return frames.cbegin()->singleDockWidget();
922 bool LayoutSaver::MultiSplitter::skipsRestore()
const
924 return std::all_of(frames.cbegin(), frames.cend(), [](
const LayoutSaver::Frame &frame) {
925 return frame.skipsRestore();
929 QVariantMap LayoutSaver::MultiSplitter::toVariantMap()
const
932 result.insert(QStringLiteral(
"layout"), layout);
935 for (
auto &frame : frames)
936 framesV.insert(frame.id, frame.toVariantMap());
938 result.insert(QStringLiteral(
"frames"), framesV);
942 void LayoutSaver::MultiSplitter::fromVariantMap(
const QVariantMap &map)
944 layout = map.value(QStringLiteral(
"layout")).toMap();
945 const QVariantMap framesV = map.value(QStringLiteral(
"frames")).toMap();
947 for (
const QVariant &frameV : framesV) {
948 LayoutSaver::Frame frame;
949 frame.fromVariantMap(frameV.toMap());
950 frames.insert(frame.id, frame);
954 void LayoutSaver::Position::scaleSizes(
const ScalingInfo &scalingInfo)
956 scalingInfo.applyFactorsTo( lastFloatingGeometry);
959 QVariantMap LayoutSaver::Position::toVariantMap()
const
962 map.insert(QStringLiteral(
"lastFloatingGeometry"), Layouting::rectToMap(lastFloatingGeometry));
963 map.insert(QStringLiteral(
"tabIndex"), tabIndex);
964 map.insert(QStringLiteral(
"wasFloating"), wasFloating);
965 map.insert(QStringLiteral(
"placeholders"), toVariantList<LayoutSaver::Placeholder>(placeholders));
970 void LayoutSaver::Position::fromVariantMap(
const QVariantMap &map)
972 lastFloatingGeometry = Layouting::mapToRect(map.value(QStringLiteral(
"lastFloatingGeometry")).toMap());
973 tabIndex = map.value(QStringLiteral(
"tabIndex")).toInt();
974 wasFloating = map.value(QStringLiteral(
"wasFloating")).toBool();
975 placeholders = fromVariantList<LayoutSaver::Placeholder>(map.value(QStringLiteral(
"placeholders")).toList());
978 QVariantMap LayoutSaver::ScreenInfo::toVariantMap()
const
981 map.insert(QStringLiteral(
"index"), index);
982 map.insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
983 map.insert(QStringLiteral(
"name"), name);
984 map.insert(QStringLiteral(
"devicePixelRatio"), devicePixelRatio);
989 void LayoutSaver::ScreenInfo::fromVariantMap(
const QVariantMap &map)
991 index = map.value(QStringLiteral(
"index")).toInt();
992 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
993 name = map.value(QStringLiteral(
"name")).toString();
994 devicePixelRatio = map.value(QStringLiteral(
"devicePixelRatio")).
toDouble();
997 QVariantMap LayoutSaver::Placeholder::toVariantMap()
const
1000 map.insert(QStringLiteral(
"isFloatingWindow"), isFloatingWindow);
1001 map.insert(QStringLiteral(
"itemIndex"), itemIndex);
1003 if (isFloatingWindow)
1004 map.insert(QStringLiteral(
"indexOfFloatingWindow"), indexOfFloatingWindow);
1006 map.insert(QStringLiteral(
"mainWindowUniqueName"), mainWindowUniqueName);
1011 void LayoutSaver::Placeholder::fromVariantMap(
const QVariantMap &map)
1013 isFloatingWindow = map.value(QStringLiteral(
"isFloatingWindow")).toBool();
1014 indexOfFloatingWindow = map.value(QStringLiteral(
"indexOfFloatingWindow"), -1).toInt();
1015 itemIndex = map.value(QStringLiteral(
"itemIndex")).toInt();
1016 mainWindowUniqueName = map.value(QStringLiteral(
"mainWindowUniqueName")).toString();
1019 LayoutSaver::ScalingInfo::ScalingInfo(
const QString &mainWindowId,
QRect savedMainWindowGeo,
int screenIndex)
1021 auto mainWindow = DockRegistry::self()->mainWindowByName(mainWindowId);
1023 qWarning() << Q_FUNC_INFO <<
"Failed to find main window with name" << mainWindowName;
1027 if (!savedMainWindowGeo.
isValid() || savedMainWindowGeo.
isNull()) {
1028 qWarning() << Q_FUNC_INFO <<
"Invalid saved main window geometry" << savedMainWindowGeo;
1032 if (!mainWindow->geometry().isValid() || mainWindow->geometry().isNull()) {
1033 qWarning() << Q_FUNC_INFO <<
"Invalid main window geometry" << mainWindow->geometry();
1037 const int currentScreenIndex = qApp->screens().indexOf(mainWindow->screen());
1039 this->mainWindowName = mainWindowId;
1040 this->savedMainWindowGeometry = savedMainWindowGeo;
1041 realMainWindowGeometry = mainWindow->window()->geometry();
1042 widthFactor = double(realMainWindowGeometry.width()) / savedMainWindowGeo.
width();
1043 heightFactor = double(realMainWindowGeometry.height()) / savedMainWindowGeo.
height();
1044 mainWindowChangedScreen = currentScreenIndex != screenIndex;
1047 void LayoutSaver::ScalingInfo::translatePos(
QPoint &pt)
const
1049 const int deltaX = pt.
x() - savedMainWindowGeometry.x();
1050 const int deltaY = pt.
y() - savedMainWindowGeometry.y();
1052 const double newDeltaX = deltaX * widthFactor;
1053 const double newDeltaY = deltaY * heightFactor;
1055 pt.
setX(qCeil(savedMainWindowGeometry.x() + newDeltaX));
1056 pt.
setY(qCeil(savedMainWindowGeometry.y() + newDeltaY));
1059 void LayoutSaver::ScalingInfo::applyFactorsTo(
QPoint &pt)
const
1064 void LayoutSaver::ScalingInfo::applyFactorsTo(
QSize &sz)
const
1070 void LayoutSaver::ScalingInfo::applyFactorsTo(
QRect &rect)
const
1078 applyFactorsTo( size);
1081 if (!mainWindowChangedScreen) {
1086 applyFactorsTo( pos);
1093 LayoutSaver::Private::RAIIIsRestoring::RAIIIsRestoring()
1095 LayoutSaver::Private::s_restoreInProgress =
true;
1098 LayoutSaver::Private::RAIIIsRestoring::~RAIIIsRestoring()
1100 LayoutSaver::Private::s_restoreInProgress =
false;