From bde7af8a5a1a8080a1397ca8b6b1f8bfdb41c715 Mon Sep 17 00:00:00 2001 From: vslg Date: Sat, 5 Sep 2020 13:06:47 -0300 Subject: [PATCH] Move system tray icon code to its file --- src/gui/Base/HTrayIcon.qml | 52 ++++++++++++++++++++++++++++++++++++++ src/gui/Window.qml | 52 +++----------------------------------- 2 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 src/gui/Base/HTrayIcon.qml diff --git a/src/gui/Base/HTrayIcon.qml b/src/gui/Base/HTrayIcon.qml new file mode 100644 index 00000000..74c6aeed --- /dev/null +++ b/src/gui/Base/HTrayIcon.qml @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +import Qt.labs.platform 1.1 +import Qt.labs.folderlistmodel 2.12 + +SystemTrayIcon { + property string iconPack: theme ? theme.icons.preferredPack : "thin" + property alias settingsFolder: showUpWatcher.folder + + property var window + + property FolderListModel showUpWatcher: FolderListModel { + id: showUpWatcher + showDirs: false + showHidden: true + nameFilters: [".show"] + + onCountChanged: { + if (count) { + window.drawAttention() + py.importModule("os", () => { + py.call("os.remove", [get(0, "filePath")]) + }) + } + } + } + + + visible: true + tooltip: qsTr("Mirage") + icon.source: `../../icons/${iconPack}/tray-icon.png` + + onActivated: + if (reason !== SystemTrayIcon.Context) + window.drawAttention() + + + menu: Menu { + MenuItem { + text: window.visible ? "Hide Mirage" : "Show Mirage" + onTriggered: + window.visible ? + window.hide() : + window.drawAttention() + } + + MenuItem { + text: qsTr("Quit Mirage") + onTriggered: Qt.quit() + } + } +} diff --git a/src/gui/Window.qml b/src/gui/Window.qml index 3887b98c..783b4546 100644 --- a/src/gui/Window.qml +++ b/src/gui/Window.qml @@ -2,8 +2,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 -import Qt.labs.platform 1.1 -import Qt.labs.folderlistmodel 2.12 import "Base" import "PythonBridge" @@ -90,7 +88,7 @@ ApplicationWindow { onClosing: { close.accepted = ! settings.closeMinimizesToTray - onTriggered: if (settings.closeMinimizesToTray) hide() + if (settings.closeMinimizesToTray) hide() } PythonRootBridge { id: py } @@ -114,50 +112,8 @@ ApplicationWindow { Behavior on scale { HNumberAnimation { overshoot: 3; factor: 1.2 } } } - SystemTrayIcon { - property string iconPack: theme ? theme.icons.preferredPack : "thin" - - visible: true - tooltip: qsTr("Mirage") - icon.source: `../icons/${iconPack}/tray-icon.png` - - onActivated: - if (reason !== SystemTrayIcon.Context) - window.drawAttention() - - - menu: Menu { - MenuItem { - text: window.visible ? "Hide Mirage" : "Show Mirage" - onTriggered: - window.visible ? - window.hide() : - window.drawAttention() - } - - MenuItem { - text: qsTr("Quit Mirage") - onTriggered: { - Qt.quit() - } - } - } - } - - FolderListModel { - id: showUpWatcher - folder: window.configDir - showDirs: false - showHidden: true - nameFilters: [".show"] - - onCountChanged: { - if (count) { - window.drawAttention() - py.importModule("os", () => { - py.call("os.remove", [get(0, "filePath")]) - }) - } - } + HTrayIcon { + window: window + settingsFolder: configDir } }