small component patches + code cleanup
This commit is contained in:
68
components/ConfigWriter.qml
Normal file
68
components/ConfigWriter.qml
Normal file
@@ -0,0 +1,68 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property string configPath:
|
||||
Quickshell.env("HOME") + "/.config/quickshell/config/config.qml"
|
||||
|
||||
Process {
|
||||
id: writerProc
|
||||
running: false
|
||||
onExited: (code) => {
|
||||
if (code !== 0)
|
||||
console.warn("[ConfigWriter] Patch failed (exit " + code + ")")
|
||||
}
|
||||
property string _name: "ConfigWriter"
|
||||
}
|
||||
|
||||
function writeInt(key, value) {
|
||||
const n = Math.round(value).toString()
|
||||
const sh = "sed -i" +
|
||||
" -e 's/\\(property int[[:space:]]\\+\\b" + key + "\\b:[ ]*\\)[0-9.]\\+/\\1" + n + "/'" +
|
||||
" " + JSON.stringify(root.configPath)
|
||||
writerProc.command = ["/bin/sh", "-c", sh]
|
||||
writerProc.running = true
|
||||
}
|
||||
|
||||
function writeBool(key, value) {
|
||||
const v = value ? "true" : "false"
|
||||
const sh = "sed -i" +
|
||||
" -e 's/\\(property bool[[:space:]]\\+\\b" + key + "\\b:[ ]*\\)\\(true\\|false\\)/\\1" + v + "/'" +
|
||||
" " + JSON.stringify(root.configPath)
|
||||
writerProc.command = ["/bin/sh", "-c", sh]
|
||||
writerProc.running = true
|
||||
}
|
||||
|
||||
function writeInts(pairs) {
|
||||
let args = ""
|
||||
for (let i = 0; i < pairs.length; i++) {
|
||||
const n = Math.round(pairs[i].value).toString()
|
||||
args += " -e 's/\\(property int[[:space:]]\\+\\b" + pairs[i].key + "\\b:[ ]*\\)[0-9.]\\+/\\1" + n + "/'"
|
||||
}
|
||||
const sh = "sed -i" + args + " " + JSON.stringify(root.configPath)
|
||||
writerProc.command = ["/bin/sh", "-c", sh]
|
||||
writerProc.running = true
|
||||
}
|
||||
|
||||
function writeArray(key, pairsQml) {
|
||||
const sh =
|
||||
"CFG=" + JSON.stringify(root.configPath) + "\n" +
|
||||
"QS_PAIRS='" + pairsQml + "'\n" +
|
||||
"awk -v pairs=\"$QS_PAIRS\" '" +
|
||||
"/^[[:space:]]*property var[[:space:]]+" + key + ":[[:space:]]/{print \" property var " + key + ": \"pairs;sk=/\\]/?0:1;next}" +
|
||||
"sk&&/\\]/{sk=0;next}" +
|
||||
"sk{next}" +
|
||||
"{print}'" +
|
||||
" \"$CFG\" > \"${CFG}.tmp\" && mv \"${CFG}.tmp\" \"$CFG\"\n"
|
||||
writerProc.command = ["/bin/sh", "-c", sh]
|
||||
writerProc.running = true
|
||||
}
|
||||
|
||||
function writeScript(sh) {
|
||||
writerProc.command = ["/bin/sh", "-c", sh]
|
||||
writerProc.running = true
|
||||
}
|
||||
}
|
||||
34
components/HoverButton.qml
Normal file
34
components/HoverButton.qml
Normal file
@@ -0,0 +1,34 @@
|
||||
import QtQuick
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
property color idleColor: "transparent"
|
||||
property color hoverColor: "transparent"
|
||||
property color pressColor: "transparent"
|
||||
property color borderIdleColor: "transparent"
|
||||
property color borderHoverColor: "transparent"
|
||||
property real pressScale: 0.97
|
||||
property int animDuration: 150
|
||||
|
||||
readonly property bool hovered: _hover.hovered
|
||||
readonly property bool pressed: _tap.pressed
|
||||
|
||||
signal clicked()
|
||||
|
||||
color: pressed ? pressColor : (hovered ? hoverColor : idleColor)
|
||||
border.color: hovered ? borderHoverColor : borderIdleColor
|
||||
|
||||
scale: pressed ? pressScale : 1.0
|
||||
|
||||
Behavior on color { ColorAnimation { duration: root.animDuration } }
|
||||
Behavior on border.color { ColorAnimation { duration: root.animDuration } }
|
||||
Behavior on scale { NumberAnimation { duration: 100; easing.type: Easing.OutQuad } }
|
||||
|
||||
HoverHandler { id: _hover }
|
||||
TapHandler {
|
||||
id: _tap
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onTapped: root.clicked()
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,44 @@ Rectangle {
|
||||
readonly property var t: Cfg.Config.theme
|
||||
|
||||
property bool moduleEnabled: true
|
||||
|
||||
property bool hovered: false
|
||||
property bool popupOpen: false
|
||||
|
||||
property color chipColor: "transparent"
|
||||
property color chipColorHovered: "transparent"
|
||||
property color chipBorderColor: "transparent"
|
||||
property color chipBorderColorHovered: "transparent"
|
||||
property bool chipHoverEnabled: false
|
||||
property var chipTapAction: null
|
||||
|
||||
property int chipAnimDuration: 150
|
||||
property bool chipAnimWidth: false
|
||||
property bool chipAnimImplicitWidth: false
|
||||
|
||||
radius: panelRadius
|
||||
color: hovered ? chipColorHovered : chipColor
|
||||
border.color: (hovered || popupOpen) ? chipBorderColorHovered : chipBorderColor
|
||||
border.width: borderWidth
|
||||
|
||||
Behavior on color { ColorAnimation { duration: chip.chipAnimDuration } }
|
||||
Behavior on border.color { ColorAnimation { duration: chip.chipAnimDuration } }
|
||||
Behavior on width {
|
||||
NumberAnimation { duration: 250; easing.type: Easing.OutCubic }
|
||||
enabled: chipAnimWidth
|
||||
}
|
||||
Behavior on implicitWidth {
|
||||
NumberAnimation { duration: 250; easing.type: Easing.OutCubic }
|
||||
enabled: chipAnimImplicitWidth
|
||||
}
|
||||
|
||||
HoverHandler {
|
||||
id: hoverHandler
|
||||
cursorShape: chipHoverEnabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
onHoveredChanged: chip.hovered = hovered
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
onTapped: if (chip.chipTapAction) chip.chipTapAction()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ Rectangle {
|
||||
required property bool popupOpen
|
||||
required property bool isTop
|
||||
property bool animEnabled: true
|
||||
property bool showShadow: false
|
||||
|
||||
width: parent.width
|
||||
|
||||
@@ -27,6 +28,18 @@ Rectangle {
|
||||
opacity: popupOpen ? 1.0 : 0.0
|
||||
Behavior on opacity { NumberAnimation { duration: 200 } }
|
||||
|
||||
Rectangle {
|
||||
visible: card.showShadow && card.popupOpen
|
||||
anchors.fill: parent
|
||||
anchors.margins: -3
|
||||
radius: card.radius + 3
|
||||
color: "transparent"
|
||||
border.color: Qt.rgba(0, 0, 0, 0.35)
|
||||
border.width: 6
|
||||
opacity: card.showShadow && card.popupOpen ? 0.6 : 0
|
||||
Behavior on opacity { NumberAnimation { duration: 200 } }
|
||||
}
|
||||
|
||||
default property alias _popupCardContent: _content.data
|
||||
|
||||
Item {
|
||||
|
||||
31
components/StandardPopup.qml
Normal file
31
components/StandardPopup.qml
Normal file
@@ -0,0 +1,31 @@
|
||||
import QtQuick
|
||||
import "../config" as Cfg
|
||||
|
||||
PopupPanel {
|
||||
id: popup
|
||||
|
||||
property color cardColor: "transparent"
|
||||
property color cardBorderColor: "transparent"
|
||||
property alias cardHeight: card.height
|
||||
property alias showShadow: card.showShadow
|
||||
property bool layerEnabled: false
|
||||
property alias hasKeyboardFocus: popup.hasKeyboardFocus
|
||||
property alias card: card
|
||||
property int activeTab: 0
|
||||
|
||||
default property alias popupContent: card._popupCardContent
|
||||
|
||||
PopupCard {
|
||||
id: card
|
||||
popupOpen: popup.popupOpen
|
||||
isTop: popup.chipRoot ? popup.chipRoot.isTop : true
|
||||
animEnabled: popup.visible
|
||||
color: popup.cardColor
|
||||
radius: Cfg.Config.popupRadius
|
||||
border.color: popup.cardBorderColor
|
||||
border.width: Cfg.Config.popupBorderWidth
|
||||
layer.enabled: popup.layerEnabled
|
||||
|
||||
Behavior on height { NumberAnimation { duration: 220; easing.type: Easing.OutCubic } }
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ Item {
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 1800000
|
||||
interval: 300000
|
||||
running: root.tz !== ""
|
||||
repeat: true
|
||||
onTriggered: tzProc.running = true
|
||||
|
||||
Reference in New Issue
Block a user