Skip to content

Commit

Permalink
Window size is now saved and restored
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilInTheGaps committed Nov 14, 2023
1 parent d1baf55 commit f52de40
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
11 changes: 8 additions & 3 deletions app/ui/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ ApplicationWindow {
title: qsTr("GM-Companion")
visible: true

width: 1280
height: 720
width: SettingsManager.window.width
height: SettingsManager.window.height

minimumWidth: 640
minimumHeight: 480
Expand Down Expand Up @@ -83,6 +83,11 @@ ApplicationWindow {
}
}

onClosing: {
SettingsManager.window.width = root.width;
SettingsManager.window.height = root.height;
}

MessageDialog {
id: message_dialog
width: root.width - 100
Expand All @@ -96,7 +101,7 @@ ApplicationWindow {

Drawer {
id: drawer
width: SettingsManager.showToolNames ? Sizes.sidebarWidth : Sizes.toolbarWidth
width: SettingsManager.window.showToolNames ? Sizes.sidebarWidth : Sizes.toolbarWidth
height: parent.height
modal: false
interactive: false
Expand Down
4 changes: 2 additions & 2 deletions app/ui/main/SideMenuButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Button {
font.bold: false

ToolTip.delay: 1000
ToolTip.visible: root.hovered && !SettingsManager.showToolNames
ToolTip.visible: root.hovered && !SettingsManager.window.showToolNames
ToolTip.text: root.toolName

Row {
Expand All @@ -50,7 +50,7 @@ Button {
Text {
text: root.toolName
font.pixelSize: 16
visible: SettingsManager.showToolNames
visible: SettingsManager.window.showToolNames

width: parent.width - parent.spacing - parent.padding * 2 - parent.iconWidth
clip: true
Expand Down
4 changes: 2 additions & 2 deletions app/ui/tools/settings/GeneralPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ SplitView {
// Show Tool Names
CheckBox {
text: qsTr("Show tool names in menu")
checked: SettingsManager.showToolNames
onClicked: SettingsManager.showToolNames = checked
checked: SettingsManager.window.showToolNames
onClicked: SettingsManager.window.showToolNames = checked
}

Row {
Expand Down
1 change: 1 addition & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(SRC_SETTINGS
settings/quick/settingsmanager.cpp
settings/quick/services.h
settings/quick/colors.h
settings/quick/window.h
settings/quick/macros.h
settings/quick/spotify.h
settings/quick/google.h
Expand Down
9 changes: 8 additions & 1 deletion src/common/settings/quick/settingsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "qmlsingletonfactory.h"
#include "services.h"
#include "thirdparty/propertyhelper/PropertyHelper.h"
#include "window.h"
#include <QJSEngine>
#include <QObject>
#include <QQmlEngine>
Expand All @@ -26,9 +27,9 @@ class SettingsManager : public QObject

Q_PROPERTY(Common::Settings::Quick::Services *services READ services CONSTANT FINAL)
Q_PROPERTY(Common::Settings::Quick::Colors *colors READ colors CONSTANT FINAL)
Q_PROPERTY(Common::Settings::Quick::Window *window READ window CONSTANT FINAL)

// General Settings
SETTINGS_PROPERTY_VAL(bool, showToolNames, false)
SETTINGS_PROPERTY(QString, cloudMode, QStringLiteral("local"))
READ_PROPERTY2(QString, languageBcp47, Common::Settings::SettingsManager::instance()->getLanguageBcp47())

Expand Down Expand Up @@ -64,6 +65,11 @@ class SettingsManager : public QObject
return &m_colors;
}

auto window() -> Window *
{
return &m_window;
}

static auto instance() -> SettingsManager *;

signals:
Expand All @@ -74,6 +80,7 @@ class SettingsManager : public QObject

Services m_services;
Colors m_colors;
Window m_window;

inline static SettingsManager *m_instance = nullptr;
};
Expand Down
30 changes: 30 additions & 0 deletions src/common/settings/quick/window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "../settingsmanager.h"
#include "macros.h"
#include <QObject>
#include <QtQml/qqmlregistration.h>

namespace Common::Settings::Quick
{

class Window : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")

SETTINGS_PROPERTY_VAL(int, width, WIDTH_DEFAULT)
SETTINGS_PROPERTY_VAL(int, height, HEIGHT_DEFAULT)

SETTINGS_PROPERTY_VAL(bool, showToolNames, false)

public:
using QObject::QObject;

private:
static constexpr int WIDTH_DEFAULT = 1280;
static constexpr int HEIGHT_DEFAULT = 720;
};

} // namespace Common::Settings::Quick

0 comments on commit f52de40

Please sign in to comment.