parent
7b001b5099
commit
0417105a03
|
@ -7,12 +7,9 @@ const LAS_KEY_LOCALE* = "global/locale"
|
||||||
const DEFAULT_LOCALE = "en"
|
const DEFAULT_LOCALE = "en"
|
||||||
const LAS_KEY_THEME* = "global/theme"
|
const LAS_KEY_THEME* = "global/theme"
|
||||||
const DEFAULT_THEME = 2 #system theme, from qml
|
const DEFAULT_THEME = 2 #system theme, from qml
|
||||||
const LAS_KEY_APP_WIDTH = "global/app_width"
|
const LAS_KEY_GEOMETRY = "global/app_geometry"
|
||||||
const DEFAULT_APP_WIDTH = 1232
|
const LAS_KEY_VISIBILITY = "global/app_visibility"
|
||||||
const LAS_KEY_APP_HEIGHT = "global/app_height"
|
const DEFAULT_VISIBILITY = 2 #windowed visibility, from qml
|
||||||
const DEFAULT_APP_HEIGHT = 770
|
|
||||||
const LAS_KEY_APP_SIZE_INITIALIZED = "global/app_size_initialized"
|
|
||||||
const DEFAULT_APP_SIZE_INITIALIZED = false
|
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type LocalAppSettings* = ref object of QObject
|
type LocalAppSettings* = ref object of QObject
|
||||||
|
@ -58,41 +55,32 @@ QtObject:
|
||||||
write = setTheme
|
write = setTheme
|
||||||
notify = themeChanged
|
notify = themeChanged
|
||||||
|
|
||||||
proc appWidthChanged*(self: LocalAppSettings) {.signal.}
|
|
||||||
proc getAppWidth*(self: LocalAppSettings): int {.slot.} =
|
|
||||||
self.settings.value(LAS_KEY_APP_WIDTH, newQVariant(DEFAULT_APP_WIDTH)).intVal
|
|
||||||
proc setAppWidth*(self: LocalAppSettings, value: int) {.slot.} =
|
|
||||||
self.settings.setValue(LAS_KEY_APP_WIDTH, newQVariant(value))
|
|
||||||
self.appWidthChanged()
|
|
||||||
|
|
||||||
QtProperty[int] appWidth:
|
proc geometryChanged*(self: LocalAppSettings) {.signal.}
|
||||||
read = getAppWidth
|
proc getGeometry*(self: LocalAppSettings): QVariant {.slot.} =
|
||||||
write = setAppWidth
|
self.settings.value(LAS_KEY_GEOMETRY)
|
||||||
notify = appWidthChanged
|
proc setGeometry*(self: LocalAppSettings, value: QVariant) {.slot.} =
|
||||||
|
self.settings.setValue(LAS_KEY_GEOMETRY, newQVariant(value))
|
||||||
|
self.geometryChanged()
|
||||||
|
|
||||||
proc appHeightChanged*(self: LocalAppSettings) {.signal.}
|
QtProperty[QVariant] geometry:
|
||||||
proc getAppHeight*(self: LocalAppSettings): int {.slot.} =
|
read = getGeometry
|
||||||
self.settings.value(LAS_KEY_APP_HEIGHT, newQVariant(DEFAULT_APP_HEIGHT)).intVal
|
write = setGeometry
|
||||||
proc setAppHeight*(self: LocalAppSettings, value: int) {.slot.} =
|
notify = geometryChanged
|
||||||
self.settings.setValue(LAS_KEY_APP_HEIGHT, newQVariant(value))
|
|
||||||
self.appHeightChanged()
|
|
||||||
|
|
||||||
QtProperty[int] appHeight:
|
|
||||||
read = getAppHeight
|
|
||||||
write = setAppHeight
|
|
||||||
notify = appHeightChanged
|
|
||||||
|
|
||||||
proc appSizeInitializedChanged*(self: LocalAppSettings) {.signal.}
|
proc visibilityChanged*(self: LocalAppSettings) {.signal.}
|
||||||
proc isAppSizeInitialized*(self: LocalAppSettings): bool {.slot.} =
|
proc getVisibility*(self: LocalAppSettings): int {.slot.} =
|
||||||
self.settings.value(LAS_KEY_APP_SIZE_INITIALIZED, newQVariant(DEFAULT_APP_SIZE_INITIALIZED)).boolVal
|
self.settings.value(LAS_KEY_VISIBILITY, newQVariant(DEFAULT_VISIBILITY)).intVal
|
||||||
proc setAppSizeInitialized*(self: LocalAppSettings, value: bool) {.slot.} =
|
proc setVisibility*(self: LocalAppSettings, value: int) {.slot.} =
|
||||||
self.settings.setValue(LAS_KEY_APP_SIZE_INITIALIZED, newQVariant(value))
|
self.settings.setValue(LAS_KEY_VISIBILITY, newQVariant(value))
|
||||||
self.appSizeInitializedChanged()
|
self.visibilityChanged()
|
||||||
|
|
||||||
|
QtProperty[int] visibility:
|
||||||
|
read = getVisibility
|
||||||
|
write = setVisibility
|
||||||
|
notify = visibilityChanged
|
||||||
|
|
||||||
QtProperty[bool] appSizeInitialized:
|
|
||||||
read = isAppSizeInitialized
|
|
||||||
write = setAppSizeInitialized
|
|
||||||
notify = appSizeInitializedChanged
|
|
||||||
|
|
||||||
proc removeKey*(self: LocalAppSettings, key: string) =
|
proc removeKey*(self: LocalAppSettings, key: string) =
|
||||||
if(self.settings.isNil):
|
if(self.settings.isNil):
|
||||||
|
@ -102,4 +90,6 @@ QtObject:
|
||||||
|
|
||||||
case key:
|
case key:
|
||||||
of LAS_KEY_LOCALE: self.localeChanged()
|
of LAS_KEY_LOCALE: self.localeChanged()
|
||||||
of LAS_KEY_THEME: self.themeChanged()
|
of LAS_KEY_THEME: self.themeChanged()
|
||||||
|
of LAS_KEY_GEOMETRY: self.geometryChanged()
|
||||||
|
of LAS_KEY_VISIBILITY: self.visibilityChanged()
|
71
ui/main.qml
71
ui/main.qml
|
@ -28,8 +28,6 @@ StatusWindow {
|
||||||
objectName: "mainWindow"
|
objectName: "mainWindow"
|
||||||
minimumWidth: 900
|
minimumWidth: 900
|
||||||
minimumHeight: 600
|
minimumHeight: 600
|
||||||
width: localAppSettings.appWidth
|
|
||||||
height: localAppSettings.appHeight
|
|
||||||
color: Style.current.background
|
color: Style.current.background
|
||||||
title: {
|
title: {
|
||||||
// Set application settings
|
// Set application settings
|
||||||
|
@ -41,20 +39,51 @@ StatusWindow {
|
||||||
}
|
}
|
||||||
visible: true
|
visible: true
|
||||||
|
|
||||||
function storeWidth() {
|
function restoreAppState() {
|
||||||
if(!applicationWindow.appIsReady)
|
let geometry = localAppSettings.geometry;
|
||||||
return
|
let visibility = localAppSettings.visibility;
|
||||||
localAppSettings.appWidth = width
|
|
||||||
|
if (visibility !== Window.Windowed &&
|
||||||
|
visibility !== Window.Maximized &&
|
||||||
|
visibility !== Window.FullScreen) {
|
||||||
|
visibility = Window.Windowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geometry === undefined) {
|
||||||
|
let screen = Qt.application.screens[0];
|
||||||
|
|
||||||
|
geometry = Qt.rect(0,
|
||||||
|
0,
|
||||||
|
Math.min(Screen.desktopAvailableWidth - 125, 1400),
|
||||||
|
Math.min(Screen.desktopAvailableHeight - 125, 840));
|
||||||
|
geometry.x = (screen.width - geometry.width) / 2;
|
||||||
|
geometry.y = (screen.height - geometry.height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
applicationWindow.visibility = visibility;
|
||||||
|
if (visibility == Window.Windowed) {
|
||||||
|
applicationWindow.x = geometry.x;
|
||||||
|
applicationWindow.y = geometry.y;
|
||||||
|
applicationWindow.width = geometry.width;
|
||||||
|
applicationWindow.height = geometry.height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeHeight() {
|
function storeAppState() {
|
||||||
if(!applicationWindow.appIsReady)
|
if (!applicationWindow.appIsReady)
|
||||||
return
|
return;
|
||||||
localAppSettings.appHeight = height
|
|
||||||
|
localAppSettings.visibility = applicationWindow.visibility;
|
||||||
|
if (applicationWindow.visibility == Window.Windowed) {
|
||||||
|
localAppSettings.geometry = Qt.rect(applicationWindow.x, applicationWindow.y,
|
||||||
|
applicationWindow.width, applicationWindow.height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onWidthChanged: Qt.callLater(storeWidth)
|
onXChanged: Qt.callLater(storeAppState)
|
||||||
onHeightChanged: Qt.callLater(storeHeight)
|
onYChanged: Qt.callLater(storeAppState)
|
||||||
|
onWidthChanged: Qt.callLater(storeAppState)
|
||||||
|
onHeightChanged: Qt.callLater(storeAppState)
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
shortcut: StandardKey.FullScreen
|
shortcut: StandardKey.FullScreen
|
||||||
|
@ -98,9 +127,8 @@ StatusWindow {
|
||||||
target: startupModule
|
target: startupModule
|
||||||
|
|
||||||
onStartUpUIRaised: {
|
onStartUpUIRaised: {
|
||||||
applicationWindow.appIsReady = true
|
applicationWindow.appIsReady = true;
|
||||||
applicationWindow.storeWidth()
|
applicationWindow.storeAppState();
|
||||||
applicationWindow.storeHeight()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onAppStateChanged: {
|
onAppStateChanged: {
|
||||||
|
@ -184,18 +212,9 @@ StatusWindow {
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
Global.applicationWindow = this;
|
Global.applicationWindow = this;
|
||||||
Style.changeTheme(localAppSettings.theme, systemPalette.isCurrentSystemThemeDark())
|
Style.changeTheme(localAppSettings.theme, systemPalette.isCurrentSystemThemeDark());
|
||||||
|
|
||||||
if (!localAppSettings.appSizeInitialized) {
|
restoreAppState();
|
||||||
width = Math.min(Screen.desktopAvailableWidth - 125, 1400)
|
|
||||||
height = Math.min(Screen.desktopAvailableHeight - 125, 840)
|
|
||||||
localAppSettings.appSizeInitialized = true
|
|
||||||
}
|
|
||||||
|
|
||||||
setX(Qt.application.screens[0].width / 2 - width / 2);
|
|
||||||
setY(Qt.application.screens[0].height / 2 - height / 2);
|
|
||||||
|
|
||||||
applicationWindow.updatePosition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signal navigateTo(string path)
|
signal navigateTo(string path)
|
||||||
|
|
Loading…
Reference in New Issue