Visibility service for handling active popups
This commit is contained in:
parent
89cf6f315b
commit
9873324823
4 changed files with 24 additions and 11 deletions
|
|
@ -5,9 +5,7 @@ import qs.widgets
|
||||||
StyledButton {
|
StyledButton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
onClicked: {
|
onClicked: popup.toggle()
|
||||||
popup.opened = !popup.opened;
|
|
||||||
}
|
|
||||||
|
|
||||||
content: StyledText {
|
content: StyledText {
|
||||||
id: text
|
id: text
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,8 @@ StyledButton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property SystemTrayItem trayItem
|
property SystemTrayItem trayItem
|
||||||
property bool menuOpened: false
|
|
||||||
|
|
||||||
onClicked: toggleMenu()
|
onClicked: menu.toggle()
|
||||||
|
|
||||||
function toggleMenu() {
|
|
||||||
menuOpened = !menuOpened;
|
|
||||||
}
|
|
||||||
|
|
||||||
content: IconImage {
|
content: IconImage {
|
||||||
id: icon
|
id: icon
|
||||||
|
|
@ -36,8 +31,6 @@ StyledButton {
|
||||||
Menu {
|
Menu {
|
||||||
id: menu
|
id: menu
|
||||||
|
|
||||||
opened: root.menuOpened
|
|
||||||
|
|
||||||
anchor.item: root
|
anchor.item: root
|
||||||
anchor.rect.x: root.width / 2 - width / 2
|
anchor.rect.x: root.width / 2 - width / 2
|
||||||
anchor.rect.y: root.height + 8
|
anchor.rect.y: root.height + 8
|
||||||
|
|
|
||||||
16
services/Visibility.qml
Normal file
16
services/Visibility.qml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
import qs.widgets
|
||||||
|
import Quickshell
|
||||||
|
|
||||||
|
Singleton {
|
||||||
|
property StyledPopupWindow activePopup
|
||||||
|
|
||||||
|
function togglePopup(popup: StyledPopupWindow) {
|
||||||
|
if (activePopup && popup != activePopup) {
|
||||||
|
activePopup.state = "";
|
||||||
|
}
|
||||||
|
popup.state = popup.state == "opened" ? "" : "opened";
|
||||||
|
activePopup = popup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import qs.services
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Widgets
|
import Quickshell.Widgets
|
||||||
|
|
@ -9,10 +10,15 @@ PopupWindow {
|
||||||
property alias margins: background.margin
|
property alias margins: background.margin
|
||||||
property alias backgroundColor: background.color
|
property alias backgroundColor: background.color
|
||||||
property alias radius: background.radius
|
property alias radius: background.radius
|
||||||
|
property alias state: background.state
|
||||||
required property Component content
|
required property Component content
|
||||||
|
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
|
||||||
|
function toggle() {
|
||||||
|
Visibility.togglePopup(this);
|
||||||
|
}
|
||||||
|
|
||||||
implicitWidth: background.width
|
implicitWidth: background.width
|
||||||
Behavior on implicitWidth {
|
Behavior on implicitWidth {
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue