25 #include "private/multisplitter/Item_p.h"
26 #include "private/LayoutSaver_p.h"
27 #include "private/DockRegistry_p.h"
28 #include "private/DockWidgetBase_p.h"
29 #include "private/FloatingWindow_p.h"
30 #include "private/Frame_p.h"
31 #include "private/LayoutWidget_p.h"
32 #include "private/Logging_p.h"
33 #include "private/Position_p.h"
34 #include "private/Utils_p.h"
63 LayoutSaver::Layout *LayoutSaver::Layout::s_currentLayoutBeingRestored =
nullptr;
69 return InternalRestoreOption::None;
71 return InternalRestoreOptions(InternalRestoreOption::SkipMainWindowGeometry)
72 | InternalRestoreOption::RelativeFloatingWindowGeometry;
74 qWarning() << Q_FUNC_INFO <<
"Unknown options" << options;
79 bool LayoutSaver::Private::s_restoreInProgress =
false;
83 QVariantList variantList;
84 variantList.reserve(strs.
size());
86 variantList.push_back(str);
94 stringList.
reserve(variantList.size());
95 for (
const QVariant &variant : variantList)
102 : d(new Private(options))
115 QFile f(jsonFilename);
117 qWarning() << Q_FUNC_INFO <<
"Failed to open" << jsonFilename << f.
errorString();
127 QFile f(jsonFilename);
129 qWarning() << Q_FUNC_INFO <<
"Failed to open" << jsonFilename << f.
errorString();
141 if (!d->m_dockRegistry->isSane()) {
142 qWarning() << Q_FUNC_INFO <<
"Refusing to serialize this layout. Check previous warnings.";
146 LayoutSaver::Layout layout;
149 d->m_dockRegistry->ensureAllFloatingWidgetsAreMorphed();
152 layout.mainWindows.reserve(mainWindows.
size());
154 if (d->matchesAffinity(mainWindow->affinities()))
155 layout.mainWindows.push_back(mainWindow->serialize());
159 layout.floatingWindows.reserve(floatingWindows.
size());
160 for (KDDockWidgets::FloatingWindow *floatingWindow : floatingWindows) {
161 if (d->matchesAffinity(floatingWindow->affinities()))
162 layout.floatingWindows.push_back(floatingWindow->serialize());
167 layout.closedDockWidgets.reserve(closedDockWidgets.
size());
169 if (d->matchesAffinity(dockWidget->affinities()))
170 layout.closedDockWidgets.push_back(dockWidget->d->serialize());
177 layout.allDockWidgets.reserve(dockWidgets.
size());
179 if (d->matchesAffinity(dockWidget->affinities())) {
180 auto dw = dockWidget->d->serialize();
181 dw->lastPosition = dockWidget->d->lastPosition()->serialize();
182 layout.allDockWidgets.push_back(dw);
186 return layout.toJson();
191 d->clearRestoredProperty();
204 m_saver->d->deleteEmptyFrames();
210 FrameCleanup cleanup(
this);
211 LayoutSaver::Layout layout;
212 if (!layout.fromJson(data)) {
213 qWarning() << Q_FUNC_INFO <<
"Failed to parse json data";
217 if (!layout.isValid()) {
221 layout.scaleSizes(d->m_restoreOptions);
223 d->floatWidgetsWhichSkipRestore(layout.mainWindowNames());
224 d->floatUnknownWidgets(layout);
226 Private::RAIIIsRestoring isRestoring;
231 d->m_dockRegistry->clear(d->m_dockRegistry->dockWidgets(layout.dockWidgetsToClose()),
232 d->m_dockRegistry->mainWindows(layout.mainWindowNames()),
236 for (
const LayoutSaver::MainWindow &mw : qAsConst(layout.mainWindows)) {
237 MainWindowBase *mainWindow = d->m_dockRegistry->mainWindowByName(mw.uniqueName);
239 if (
auto mwFunc =
Config::self().mainWindowFactoryFunc()) {
240 mainWindow = mwFunc(mw.uniqueName);
242 qWarning() <<
"Failed to restore layout create MainWindow with name" << mw.uniqueName <<
"first";
247 if (!d->matchesAffinity(mainWindow->
affinities()))
250 if (!(d->m_restoreOptions & InternalRestoreOption::SkipMainWindowGeometry)) {
251 d->deserializeWindowGeometry(mw, mainWindow->
window());
254 w->setWindowState(mw.windowState);
259 if (!mainWindow->deserialize(mw))
264 for (LayoutSaver::FloatingWindow &fw : layout.floatingWindows) {
265 if (!d->matchesAffinity(fw.affinities) || fw.skipsRestore())
269 : DockRegistry::self()->mainwindows().at(fw.parentIndex);
272 fw.floatingWindowInstance = floatingWindow;
273 d->deserializeWindowGeometry(fw, floatingWindow);
274 if (!floatingWindow->deserialize(fw)) {
275 qWarning() << Q_FUNC_INFO <<
"Failed to deserialize floating window";
281 for (
const auto &dw : qAsConst(layout.closedDockWidgets)) {
282 if (d->matchesAffinity(dw->affinities)) {
283 DockWidgetBase::deserialize(dw);
288 for (
const auto &dw : qAsConst(layout.allDockWidgets)) {
289 if (!d->matchesAffinity(dw->affinities))
293 d->m_dockRegistry->dockByName(dw->uniqueName, DockRegistry::DockByNameFlag::ConsultRemapping)) {
294 dockWidget->d->lastPosition()->deserialize(dw->lastPosition);
296 qWarning() << Q_FUNC_INFO <<
"Couldn't find dock widget" << dw->uniqueName;
305 d->m_affinityNames = affinityNames;
308 d->m_affinityNames <<
QString();
323 if (dw->property(
"kddockwidget_was_restored").toBool())
330 void LayoutSaver::Private::clearRestoredProperty()
334 dw->setProperty(
"kddockwidget_was_restored",
QVariant());
339 void LayoutSaver::Private::deserializeWindowGeometry(
const T &saved,
QWidgetOrQuick *topLevel)
344 QRect geometry = saved.geometry;
345 if (!isNormalWindowState(saved.windowState)) {
348 geometry = saved.normalGeometry;
351 ::FloatingWindow::ensureRectIsOnScreen(geometry);
356 KDDockWidgets::Private::setTopLevelGeometry(geometry, topLevel);
362 LayoutSaver::Private::Private(RestoreOptions options)
363 : m_dockRegistry(DockRegistry::self())
368 bool LayoutSaver::Private::matchesAffinity(
const QStringList &affinities)
const
370 return m_affinityNames.isEmpty() || affinities.
isEmpty()
371 || DockRegistry::self()->affinitiesMatch(m_affinityNames, affinities);
374 void LayoutSaver::Private::floatWidgetsWhichSkipRestore(
const QStringList &mainWindowNames)
381 for (
MainWindowBase *mw : DockRegistry::self()->mainWindows(mainWindowNames)) {
383 for (
auto dw : docks) {
384 if (dw->skipsRestore()) {
385 dw->setFloating(
true);
391 void LayoutSaver::Private::floatUnknownWidgets(
const LayoutSaver::Layout &layout)
397 for (
MainWindowBase *mw : DockRegistry::self()->mainWindows(layout.mainWindowNames())) {
400 if (!layout.containsDockWidget(dw->uniqueName())) {
401 dw->setFloating(
true);
407 void LayoutSaver::Private::deleteEmptyFrames()
412 for (
auto frame : m_dockRegistry->frames()) {
413 if (!frame->beingDeletedLater() && frame->isEmpty() && !frame->isCentralFrame())
418 std::unique_ptr<QSettings> LayoutSaver::Private::settings()
const
420 auto settings = std::unique_ptr<QSettings>(
new QSettings(qApp->organizationName(),
421 qApp->applicationName()));
422 settings->beginGroup(QStringLiteral(
"KDDockWidgets::LayoutSaver"));
429 return Private::s_restoreInProgress;
432 bool LayoutSaver::Layout::isValid()
const
434 if (serializationVersion != KDDOCKWIDGETS_SERIALIZATION_VERSION) {
435 qWarning() << Q_FUNC_INFO <<
"Serialization format is too old"
436 << serializationVersion <<
"current=" << KDDOCKWIDGETS_SERIALIZATION_VERSION;
440 for (
auto &m : mainWindows) {
445 for (
auto &m : floatingWindows) {
450 for (
auto &m : allDockWidgets) {
458 QByteArray LayoutSaver::Layout::toJson()
const
464 bool LayoutSaver::Layout::fromJson(
const QByteArray &jsonData)
476 QVariantMap LayoutSaver::Layout::toVariantMap()
const
479 map.insert(QStringLiteral(
"serializationVersion"), serializationVersion);
480 map.insert(QStringLiteral(
"mainWindows"), toVariantList<LayoutSaver::MainWindow>(mainWindows));
481 map.insert(QStringLiteral(
"floatingWindows"), toVariantList<LayoutSaver::FloatingWindow>(floatingWindows));
482 map.insert(QStringLiteral(
"closedDockWidgets"), ::dockWidgetNames(closedDockWidgets));
483 map.insert(QStringLiteral(
"allDockWidgets"), toVariantList(allDockWidgets));
484 map.insert(QStringLiteral(
"screenInfo"), toVariantList<LayoutSaver::ScreenInfo>(screenInfo));
489 void LayoutSaver::Layout::fromVariantMap(
const QVariantMap &map)
491 allDockWidgets.clear();
492 const QVariantList dockWidgetsV = map.value(QStringLiteral(
"allDockWidgets")).toList();
493 for (
const QVariant &v : dockWidgetsV) {
494 const QVariantMap dwV = v.toMap();
495 const QString name = dwV.value(QStringLiteral(
"uniqueName")).toString();
496 auto dw = LayoutSaver::DockWidget::dockWidgetForName(name);
497 dw->fromVariantMap(dwV);
498 allDockWidgets.push_back(dw);
501 closedDockWidgets.clear();
502 const QVariantList closedDockWidgetsV = map.value(QStringLiteral(
"closedDockWidgets")).toList();
503 closedDockWidgets.reserve(closedDockWidgetsV.size());
504 for (
const QVariant &v : closedDockWidgetsV) {
505 closedDockWidgets.push_back(LayoutSaver::DockWidget::dockWidgetForName(v.toString()));
508 serializationVersion = map.value(QStringLiteral(
"serializationVersion")).toInt();
509 mainWindows = fromVariantList<LayoutSaver::MainWindow>(map.value(QStringLiteral(
"mainWindows")).toList());
510 floatingWindows = fromVariantList<LayoutSaver::FloatingWindow>(map.value(QStringLiteral(
"floatingWindows")).toList());
511 screenInfo = fromVariantList<LayoutSaver::ScreenInfo>(map.value(QStringLiteral(
"screenInfo")).toList());
514 void LayoutSaver::Layout::scaleSizes(InternalRestoreOptions options)
516 if (mainWindows.isEmpty())
519 const bool skipsMainWindowGeometry = options & InternalRestoreOption::SkipMainWindowGeometry;
520 if (!skipsMainWindowGeometry) {
529 for (
auto &mw : mainWindows)
535 const bool useRelativeSizesForFloatingWidgets =
536 options & InternalRestoreOption::RelativeFloatingWindowGeometry;
538 if (useRelativeSizesForFloatingWidgets) {
539 for (
auto &fw : floatingWindows) {
540 LayoutSaver::MainWindow mw = mainWindowForIndex(fw.parentIndex);
541 if (mw.scalingInfo.isValid())
542 fw.scaleSizes(mw.scalingInfo);
546 const ScalingInfo firstScalingInfo = mainWindows.constFirst().scalingInfo;
547 if (firstScalingInfo.isValid()) {
548 for (
auto &dw : allDockWidgets) {
552 dw->scaleSizes(firstScalingInfo);
557 LayoutSaver::MainWindow LayoutSaver::Layout::mainWindowForIndex(
int index)
const
559 if (index < 0 || index >= mainWindows.size())
562 return mainWindows.at(index);
565 LayoutSaver::FloatingWindow LayoutSaver::Layout::floatingWindowForIndex(
int index)
const
567 if (index < 0 || index >= floatingWindows.size())
570 return floatingWindows.at(index);
573 QStringList LayoutSaver::Layout::mainWindowNames()
const
576 names.
reserve(mainWindows.size());
577 for (
const auto &mw : mainWindows) {
578 names << mw.uniqueName;
584 QStringList LayoutSaver::Layout::dockWidgetNames()
const
587 names.
reserve(allDockWidgets.size());
588 for (
const auto &dw : allDockWidgets) {
589 names << dw->uniqueName;
595 QStringList LayoutSaver::Layout::dockWidgetsToClose()
const
600 names.
reserve(allDockWidgets.size());
601 auto registry = DockRegistry::self();
602 for (
const auto &dw : allDockWidgets) {
603 if (
DockWidgetBase *dockWidget = registry->dockByName(dw->uniqueName)) {
607 if (dockWidget->skipsRestore()) {
608 if (
auto fw = dockWidget->floatingWindow()) {
617 names << dw->uniqueName;
624 bool LayoutSaver::Layout::containsDockWidget(
const QString &uniqueName)
const
626 return std::find_if(allDockWidgets.cbegin(), allDockWidgets.cend(), [uniqueName](
const std::shared_ptr<LayoutSaver::DockWidget> &dock) {
627 return dock->uniqueName == uniqueName;
629 != allDockWidgets.
cend();
632 bool LayoutSaver::Frame::isValid()
const
638 qWarning() << Q_FUNC_INFO <<
"Invalid geometry";
643 qWarning() << Q_FUNC_INFO <<
"Invalid id";
647 if (!dockWidgets.isEmpty()) {
648 if (currentTabIndex >= dockWidgets.size() || currentTabIndex < 0) {
649 qWarning() << Q_FUNC_INFO <<
"Invalid tab index" << currentTabIndex << dockWidgets.size();
654 for (
auto &dw : dockWidgets) {
662 bool LayoutSaver::Frame::hasSingleDockWidget()
const
664 return dockWidgets.size() == 1;
667 bool LayoutSaver::Frame::skipsRestore()
const
669 return std::all_of(dockWidgets.cbegin(), dockWidgets.cend(), [](LayoutSaver::DockWidget::Ptr dw) {
670 return dw->skipsRestore();
674 LayoutSaver::DockWidget::Ptr LayoutSaver::Frame::singleDockWidget()
const
676 if (!hasSingleDockWidget())
679 return dockWidgets.first();
682 QVariantMap LayoutSaver::Frame::toVariantMap()
const
685 map.insert(QStringLiteral(
"id"),
id);
686 map.insert(QStringLiteral(
"isNull"), isNull);
687 map.insert(QStringLiteral(
"objectName"), objectName);
688 map.insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
689 map.insert(QStringLiteral(
"options"), options);
690 map.insert(QStringLiteral(
"currentTabIndex"), currentTabIndex);
691 map.insert(QStringLiteral(
"mainWindowUniqueName"), mainWindowUniqueName);
692 map.insert(QStringLiteral(
"dockWidgets"), dockWidgetNames(dockWidgets));
697 void LayoutSaver::Frame::fromVariantMap(
const QVariantMap &map)
705 id = map.value(QStringLiteral(
"id")).toString();
706 isNull = map.value(QStringLiteral(
"isNull")).toBool();
707 objectName = map.value(QStringLiteral(
"objectName")).toString();
708 mainWindowUniqueName = map.value(QStringLiteral(
"mainWindowUniqueName")).toString();
709 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
711 currentTabIndex = map.value(QStringLiteral(
"currentTabIndex")).toInt();
713 const QVariantList dockWidgetsV = map.value(QStringLiteral(
"dockWidgets")).toList();
716 dockWidgets.reserve(dockWidgetsV.size());
717 for (
const auto &variant : dockWidgetsV) {
718 DockWidget::Ptr dw = DockWidget::dockWidgetForName(variant.toString());
719 dockWidgets.push_back(dw);
723 bool LayoutSaver::DockWidget::isValid()
const
728 void LayoutSaver::DockWidget::scaleSizes(
const ScalingInfo &scalingInfo)
730 lastPosition.scaleSizes(scalingInfo);
733 bool LayoutSaver::DockWidget::skipsRestore()
const
735 if (
DockWidgetBase *dw = DockRegistry::self()->dockByName(uniqueName))
736 return dw->skipsRestore();
741 QVariantMap LayoutSaver::DockWidget::toVariantMap()
const
746 map.insert(QStringLiteral(
"uniqueName"), uniqueName);
747 map.insert(QStringLiteral(
"lastPosition"), lastPosition.toVariantMap());
752 void LayoutSaver::DockWidget::fromVariantMap(
const QVariantMap &map)
757 const QString affinityName = map.value(QStringLiteral(
"affinityName")).toString();
762 uniqueName = map.value(QStringLiteral(
"uniqueName")).toString();
763 lastPosition.fromVariantMap(map.value(QStringLiteral(
"lastPosition")).toMap());
766 bool LayoutSaver::FloatingWindow::isValid()
const
768 if (!multiSplitterLayout.isValid())
772 qWarning() << Q_FUNC_INFO <<
"Invalid geometry";
779 bool LayoutSaver::FloatingWindow::hasSingleDockWidget()
const
781 return multiSplitterLayout.hasSingleDockWidget();
784 LayoutSaver::DockWidget::Ptr LayoutSaver::FloatingWindow::singleDockWidget()
const
786 return multiSplitterLayout.singleDockWidget();
789 bool LayoutSaver::FloatingWindow::skipsRestore()
const
791 return multiSplitterLayout.skipsRestore();
794 void LayoutSaver::FloatingWindow::scaleSizes(
const ScalingInfo &scalingInfo)
796 scalingInfo.applyFactorsTo( geometry);
799 QVariantMap LayoutSaver::FloatingWindow::toVariantMap()
const
802 map.
insert(QStringLiteral(
"multiSplitterLayout"), multiSplitterLayout.toVariantMap());
803 map.
insert(QStringLiteral(
"parentIndex"), parentIndex);
804 map.
insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
805 map.
insert(QStringLiteral(
"normalGeometry"), Layouting::rectToMap(normalGeometry));
806 map.
insert(QStringLiteral(
"screenIndex"), screenIndex);
807 map.
insert(QStringLiteral(
"screenSize"), Layouting::sizeToMap(screenSize));
808 map.
insert(QStringLiteral(
"isVisible"), isVisible);
809 map.
insert(QStringLiteral(
"windowState"), windowState);
817 void LayoutSaver::FloatingWindow::fromVariantMap(
const QVariantMap &map)
819 multiSplitterLayout.fromVariantMap(map.value(QStringLiteral(
"multiSplitterLayout")).toMap());
820 parentIndex = map.value(QStringLiteral(
"parentIndex")).
toInt();
821 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
822 normalGeometry = Layouting::mapToRect(map.value(QStringLiteral(
"normalGeometry")).toMap());
823 screenIndex = map.value(QStringLiteral(
"screenIndex")).toInt();
824 screenSize = Layouting::mapToSize(map.value(QStringLiteral(
"screenSize")).toMap());
825 isVisible = map.value(QStringLiteral(
"isVisible")).toBool();
830 const QString affinityName = map.value(QStringLiteral(
"affinityName")).toString();
836 bool LayoutSaver::MainWindow::isValid()
const
838 if (!multiSplitterLayout.isValid())
844 void LayoutSaver::MainWindow::scaleSizes()
846 if (scalingInfo.isValid()) {
852 scalingInfo = ScalingInfo(uniqueName, geometry, screenIndex);
855 QVariantMap LayoutSaver::MainWindow::toVariantMap()
const
858 map.insert(QStringLiteral(
"options"),
int(options));
859 map.insert(QStringLiteral(
"multiSplitterLayout"), multiSplitterLayout.toVariantMap());
860 map.insert(QStringLiteral(
"uniqueName"), uniqueName);
861 map.insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
862 map.insert(QStringLiteral(
"normalGeometry"), Layouting::rectToMap(normalGeometry));
863 map.insert(QStringLiteral(
"screenIndex"), screenIndex);
864 map.insert(QStringLiteral(
"screenSize"), Layouting::sizeToMap(screenSize));
865 map.insert(QStringLiteral(
"isVisible"), isVisible);
867 map.insert(QStringLiteral(
"windowState"), windowState);
878 void LayoutSaver::MainWindow::fromVariantMap(
const QVariantMap &map)
880 options = KDDockWidgets::MainWindowOptions(map.value(QStringLiteral(
"options")).toInt());
881 multiSplitterLayout.fromVariantMap(map.value(QStringLiteral(
"multiSplitterLayout")).toMap());
882 uniqueName = map.value(QStringLiteral(
"uniqueName")).toString();
883 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
884 normalGeometry = Layouting::mapToRect(map.value(QStringLiteral(
"normalGeometry")).toMap());
885 screenIndex = map.value(QStringLiteral(
"screenIndex")).toInt();
886 screenSize = Layouting::mapToSize(map.value(QStringLiteral(
"screenSize")).toMap());
887 isVisible = map.value(QStringLiteral(
"isVisible")).toBool();
892 const QString affinityName = map.value(QStringLiteral(
"affinityName")).toString();
898 dockWidgetsPerSideBar.clear();
900 const QVariantList dockWidgets = map.
value(QStringLiteral(
"sidebar-%1").arg(
int(loc))).toList();
901 if (!dockWidgets.isEmpty())
906 bool LayoutSaver::MultiSplitter::isValid()
const
908 if (layout.isEmpty())
919 bool LayoutSaver::MultiSplitter::hasSingleDockWidget()
const
921 return frames.size() == 1 && frames.cbegin()->hasSingleDockWidget();
924 LayoutSaver::DockWidget::Ptr LayoutSaver::MultiSplitter::singleDockWidget()
const
926 if (!hasSingleDockWidget())
929 return frames.cbegin()->singleDockWidget();
932 bool LayoutSaver::MultiSplitter::skipsRestore()
const
934 return std::all_of(frames.cbegin(), frames.cend(), [](
const LayoutSaver::Frame &frame) {
935 return frame.skipsRestore();
939 QVariantMap LayoutSaver::MultiSplitter::toVariantMap()
const
942 result.insert(QStringLiteral(
"layout"), layout);
945 for (
auto &frame : frames)
946 framesV.insert(frame.id, frame.toVariantMap());
948 result.insert(QStringLiteral(
"frames"), framesV);
952 void LayoutSaver::MultiSplitter::fromVariantMap(
const QVariantMap &map)
954 layout = map.value(QStringLiteral(
"layout")).toMap();
955 const QVariantMap framesV = map.value(QStringLiteral(
"frames")).toMap();
957 for (
const QVariant &frameV : framesV) {
958 LayoutSaver::Frame frame;
959 frame.fromVariantMap(frameV.toMap());
960 frames.insert(frame.id, frame);
964 void LayoutSaver::Position::scaleSizes(
const ScalingInfo &scalingInfo)
966 scalingInfo.applyFactorsTo( lastFloatingGeometry);
969 QVariantMap LayoutSaver::Position::toVariantMap()
const
972 map.insert(QStringLiteral(
"lastFloatingGeometry"), Layouting::rectToMap(lastFloatingGeometry));
973 map.insert(QStringLiteral(
"tabIndex"), tabIndex);
974 map.insert(QStringLiteral(
"wasFloating"), wasFloating);
975 map.insert(QStringLiteral(
"placeholders"), toVariantList<LayoutSaver::Placeholder>(placeholders));
980 void LayoutSaver::Position::fromVariantMap(
const QVariantMap &map)
982 lastFloatingGeometry = Layouting::mapToRect(map.value(QStringLiteral(
"lastFloatingGeometry")).toMap());
983 tabIndex = map.value(QStringLiteral(
"tabIndex")).toInt();
984 wasFloating = map.value(QStringLiteral(
"wasFloating")).toBool();
985 placeholders = fromVariantList<LayoutSaver::Placeholder>(map.value(QStringLiteral(
"placeholders")).toList());
988 QVariantMap LayoutSaver::ScreenInfo::toVariantMap()
const
991 map.insert(QStringLiteral(
"index"), index);
992 map.insert(QStringLiteral(
"geometry"), Layouting::rectToMap(geometry));
993 map.insert(QStringLiteral(
"name"), name);
994 map.insert(QStringLiteral(
"devicePixelRatio"), devicePixelRatio);
999 void LayoutSaver::ScreenInfo::fromVariantMap(
const QVariantMap &map)
1001 index = map.value(QStringLiteral(
"index")).toInt();
1002 geometry = Layouting::mapToRect(map.value(QStringLiteral(
"geometry")).toMap());
1003 name = map.value(QStringLiteral(
"name")).toString();
1004 devicePixelRatio = map.value(QStringLiteral(
"devicePixelRatio")).
toDouble();
1007 QVariantMap LayoutSaver::Placeholder::toVariantMap()
const
1010 map.insert(QStringLiteral(
"isFloatingWindow"), isFloatingWindow);
1011 map.insert(QStringLiteral(
"itemIndex"), itemIndex);
1013 if (isFloatingWindow)
1014 map.insert(QStringLiteral(
"indexOfFloatingWindow"), indexOfFloatingWindow);
1016 map.insert(QStringLiteral(
"mainWindowUniqueName"), mainWindowUniqueName);
1021 void LayoutSaver::Placeholder::fromVariantMap(
const QVariantMap &map)
1023 isFloatingWindow = map.value(QStringLiteral(
"isFloatingWindow")).toBool();
1024 indexOfFloatingWindow = map.value(QStringLiteral(
"indexOfFloatingWindow"), -1).toInt();
1025 itemIndex = map.value(QStringLiteral(
"itemIndex")).toInt();
1026 mainWindowUniqueName = map.value(QStringLiteral(
"mainWindowUniqueName")).toString();
1033 #ifdef KDDOCKWIDGETS_QTQUICK
1037 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
1039 return window->screen();
1046 LayoutSaver::ScalingInfo::ScalingInfo(
const QString &mainWindowId,
QRect savedMainWindowGeo,
int screenIndex)
1048 auto mainWindow = DockRegistry::self()->mainWindowByName(mainWindowId);
1050 qWarning() << Q_FUNC_INFO <<
"Failed to find main window with name" << mainWindowName;
1054 if (!savedMainWindowGeo.
isValid() || savedMainWindowGeo.
isNull()) {
1055 qWarning() << Q_FUNC_INFO <<
"Invalid saved main window geometry" << savedMainWindowGeo;
1059 if (!mainWindow->geometry().isValid() || mainWindow->geometry().isNull()) {
1060 qWarning() << Q_FUNC_INFO <<
"Invalid main window geometry" << mainWindow->geometry();
1066 this->mainWindowName = mainWindowId;
1067 this->savedMainWindowGeometry = savedMainWindowGeo;
1068 realMainWindowGeometry = mainWindow->window()->geometry();
1069 widthFactor = double(realMainWindowGeometry.width()) / savedMainWindowGeo.
width();
1070 heightFactor = double(realMainWindowGeometry.height()) / savedMainWindowGeo.
height();
1071 mainWindowChangedScreen = currentScreenIndex != screenIndex;
1074 void LayoutSaver::ScalingInfo::translatePos(
QPoint &pt)
const
1076 const int deltaX = pt.
x() - savedMainWindowGeometry.x();
1077 const int deltaY = pt.
y() - savedMainWindowGeometry.y();
1079 const double newDeltaX = deltaX * widthFactor;
1080 const double newDeltaY = deltaY * heightFactor;
1082 pt.
setX(qCeil(savedMainWindowGeometry.x() + newDeltaX));
1083 pt.
setY(qCeil(savedMainWindowGeometry.y() + newDeltaY));
1086 void LayoutSaver::ScalingInfo::applyFactorsTo(
QPoint &pt)
const
1091 void LayoutSaver::ScalingInfo::applyFactorsTo(
QSize &sz)
const
1097 void LayoutSaver::ScalingInfo::applyFactorsTo(
QRect &rect)
const
1105 applyFactorsTo( size);
1108 if (!mainWindowChangedScreen) {
1113 applyFactorsTo( pos);
1120 LayoutSaver::Private::RAIIIsRestoring::RAIIIsRestoring()
1122 LayoutSaver::Private::s_restoreInProgress =
true;
1125 LayoutSaver::Private::RAIIIsRestoring::~RAIIIsRestoring()
1127 LayoutSaver::Private::s_restoreInProgress =
false;