Save and restore window size

This commit is contained in:
Carl Schwan
2020-12-30 13:19:16 +00:00
parent 4463e3e3f2
commit 8224d3ae9f
4 changed files with 44 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
*/
import QtQuick 2.14
import QtQuick.Controls 2.14 as QQC2
import QtQuick.Window 2.2
import QtQuick.Layouts 1.14
import org.kde.kirigami 2.12 as Kirigami
@@ -34,6 +35,23 @@ Kirigami.ApplicationWindow {
}
}
onClosing: Controller.saveWindowGeometry(root)
// This timer allows to batch update the window size change to reduce
// the io load and also work around the fact that x/y/width/height are
// changed when loading the page and overwrite the saved geometry from
// the previous session.
Timer {
id: saveWindowGeometryTimer
interval: 1000
onTriggered: Controller.saveWindowGeometry(root)
}
onWidthChanged: saveWindowGeometryTimer.restart()
onHeightChanged: saveWindowGeometryTimer.restart()
onXChanged: saveWindowGeometryTimer.restart()
onYChanged: saveWindowGeometryTimer.restart()
/**
* Manage opening and close rooms
*/

View File

@@ -8,15 +8,16 @@
#ifndef Q_OS_ANDROID
#include <qt5keychain/keychain.h>
#else
#endif
#include <KConfig>
#include <KConfigGroup>
#endif
#include <KWindowConfig>
#include <KLocalizedString>
#include <QClipboard>
#include <QDebug>
#include <QQuickWindow>
#include <QDir>
#include <QElapsedTimer>
#include <QFile>
@@ -565,6 +566,15 @@ void Controller::setActiveConnection(Connection *connection)
Q_EMIT activeConnectionChanged();
}
void Controller::saveWindowGeometry(QQuickWindow *window)
{
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup windowGroup(&dataResource, "Window");
KWindowConfig::saveWindowPosition(window, windowGroup);
KWindowConfig::saveWindowSize(window, windowGroup);
dataResource.sync();
}
NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString &deviceId, const Omittable<QJsonObject> &auth)
: Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId))
{

View File

@@ -21,6 +21,7 @@ class QKeySequences;
#include "user.h"
class NeoChatRoom;
class QQuickWindow;
using namespace Quotient;
@@ -118,6 +119,7 @@ public Q_SLOTS:
static void playAudio(const QUrl &localFile);
void changeAvatar(Quotient::Connection *conn, const QUrl &localFile);
static void markAllMessagesAsRead(Quotient::Connection *conn);
void saveWindowGeometry(QQuickWindow *);
};
// TODO libQuotient 0.7: Drop

View File

@@ -19,6 +19,7 @@
#endif
#include <KLocalizedContext>
#include <KLocalizedString>
#include <KWindowConfig>
#include "neochat-version.h"
@@ -152,6 +153,17 @@ int main(int argc, char *argv[])
}
}
});
const auto rootObjects = engine.rootObjects();
for (auto obj : rootObjects) {
auto view = qobject_cast<QQuickWindow*>(obj);
if (view) {
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup windowGroup(&dataResource, "Window");
KWindowConfig::restoreWindowSize(view, windowGroup);
KWindowConfig::restoreWindowPosition(view, windowGroup);
break;
}
}
#endif
return QApplication::exec();
}