aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/status/BreakRow.qml
blob: 70ad3ea11bd7e146a0576949a36c0bb8b82bf60b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

import QtQuick
import "../.."

// Breaktimer: the daemon's phase and countdown, a pause switch and a
// start/stop button. Every control is a verb; nothing here writes the
// daemon's files.
Item {
    id: row

    implicitHeight: Math.max(texts.implicitHeight, controls.implicitHeight) + 16

    readonly property string phaseLabel: {
        if (!Status.btRunning) return "Stopped";
        if (Status.btPaused) return "Paused";
        if (Status.btPhase === "breaking") return "Micro-pause";
        if (Status.btPhase === "longbreak") return "Long pause";
        return "Working";
    }

    // A paused countdown is frozen, and a frozen number reads as a bug, so
    // the paused state says what it is instead of showing one.
    readonly property string detail: {
        if (!Status.btRunning) return "Break reminders are not running.";
        if (Status.btPaused) return "Countdown frozen until resumed.";
        if (Status.btPhase === "breaking" || Status.btPhase === "longbreak")
            return "Back to work in " + Status.btCountdown() + ".";
        return "Next break in " + Status.btCountdown() + ".";
    }

    Column {
        id: texts
        anchors {
            left: parent.left
            right: controls.left
            rightMargin: 12
            verticalCenter: parent.verticalCenter
        }
        spacing: 2

        Text {
            text: "Breaktimer · " + row.phaseLabel
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
            color: Theme.text
        }

        Text {
            width: parent.width
            wrapMode: Text.WordWrap
            text: row.detail
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
            color: Theme.subtext
        }
    }

    Row {
        id: controls
        anchors { right: parent.right; verticalCenter: parent.verticalCenter }
        spacing: 8

        Button {
            text: Status.btRunning ? "Stop" : "Start"
            danger: Status.btRunning
            onClicked: Status.runBreaktimer(Status.btRunning ? "stop" : "start")
        }

        Switch {
            id: sw
            enabled: Status.btRunning
            checked: Status.btRunning && !Status.btPaused
            onToggled: Status.runBreaktimer(Status.btPaused ? "resume" : "pause")
        }
    }

    // The shared Switch writes `checked` on click and so drops the binding
    // above. Resync on any state change, which also covers a change made from
    // the waybar module's own bindings or from a terminal.
    Connections {
        target: Status
        function onBtStateChanged() {
            sw.checked = Status.btRunning && !Status.btPaused;
        }
    }
}