TimerPage.qml 2.22 KB
Newer Older
Nick Reitemeyer's avatar
Nick Reitemeyer committed
1
/*
Devin Lin's avatar
Devin Lin committed
2
 * Copyright 2020 Devin Lin <espidev@gmail.com>
Devin Lin's avatar
Devin Lin committed
3
 * Copyright 2019 Nick Reitemeyer <nick.reitemeyer@web.de>
4
 * Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
Nick Reitemeyer's avatar
Nick Reitemeyer committed
5
 *
Devin Lin's avatar
Devin Lin committed
6
 * SPDX-License-Identifier: GPL-2.0-or-later
Nick Reitemeyer's avatar
Nick Reitemeyer committed
7
8
 */

Devin Lin's avatar
Devin Lin committed
9
10
11
import QtQuick 2.12
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.2
Devin Lin's avatar
Devin Lin committed
12
import org.kde.kirigami 2.11 as Kirigami
Devin Lin's avatar
Devin Lin committed
13
import kclock 1.0
Nick Reitemeyer's avatar
Nick Reitemeyer committed
14
15
16

Kirigami.Page {
    
Devin Lin's avatar
Devin Lin committed
17
    property Timer timer
Devin Lin's avatar
Devin Lin committed
18
    property int timerIndex
Devin Lin's avatar
Devin Lin committed
19
    
Devin Lin's avatar
Devin Lin committed
20
    id: timerpage
Devin Lin's avatar
Devin Lin committed
21
    title: timer && timer.label !== "" ? timer.label : i18n("New timer")
Devin Lin's avatar
Devin Lin committed
22
    
Devin Lin's avatar
Devin Lin committed
23
    property bool showFullscreen: false
Devin Lin's avatar
Devin Lin committed
24
    
Devin Lin's avatar
Devin Lin committed
25
    property int elapsed: timer == null ? 0 : timer.elapsed
26
    property int duration: timer == null ? 0 : timer.length
Devin Lin's avatar
Devin Lin committed
27
    property bool running: timer == null ? 0 : timer.running
28
    property bool isCommandTimeout: timer == null ? 0 : timer.commandTimeout.length > 0
Devin Lin's avatar
Devin Lin committed
29

30
31
32
33
    // keyboard controls
    Keys.onSpacePressed: timer.toggleRunning();
    Keys.onReturnPressed: timer.toggleRunning();
    
Devin Lin's avatar
Devin Lin committed
34
    // topbar action
Han Young's avatar
Han Young committed
35
36
37
38
39
    actions {
        main: Kirigami.Action {
            text: running ? i18n("Pause") : i18n("Start")
            iconName: running ? "chronometer-pause" : "chronometer-start"
            onTriggered: timer.toggleRunning()
Nicolas Fella's avatar
Nicolas Fella committed
40
        }
Han Young's avatar
Han Young committed
41
42
43
44
45
46
47
48
49
50

        contextualActions: [
            Kirigami.Action {
                icon.name: "chronometer-reset"
                text: i18n("Reset")
                onTriggered: timer.reset();
            },
            Kirigami.Action {
                icon.name: "delete"
                text: i18n("Delete")
51
52
53
54
                onTriggered: {
                    pageStack.pop();
                    timerModel.remove(timerIndex);
                }
Han Young's avatar
Han Young committed
55
56
57
            }
        ]
    }
Nicolas Fella's avatar
Nicolas Fella committed
58

Devin Lin's avatar
Devin Lin committed
59
60
61
    TimerComponent {
        timerDuration: duration
        timerElapsed: elapsed
62
        timerRunning: running
Devin Lin's avatar
Devin Lin committed
63
    }
64
65
66
67
68
69
70
    RowLayout {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
        Kirigami.Icon {
            source: "dialog-scripts"
            visible: isCommandTimeout
        }
71
        Label {
72
73
74
75
76
77
            visible: isCommandTimeout
            font.family: "Monospace"
            text: timerDelegate.commandTimeout
            color: timerDelegate && Kirigami.Theme.disabledTextColor
        }
    }
Nick Reitemeyer's avatar
Nick Reitemeyer committed
78
}