forked from Shinonome/dots-hyprland
pomodoro: rename more for consistency
This commit is contained in:
@@ -50,6 +50,11 @@ Singleton {
|
|||||||
property bool running: false
|
property bool running: false
|
||||||
property int start: 0
|
property int start: 0
|
||||||
}
|
}
|
||||||
|
property JsonObject stopwatch: JsonObject {
|
||||||
|
property bool running: false
|
||||||
|
property int start: 0
|
||||||
|
property list<var> laps: []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ Item {
|
|||||||
implicitHeight: 35
|
implicitHeight: 35
|
||||||
implicitWidth: 90
|
implicitWidth: 90
|
||||||
|
|
||||||
onClicked: Pomodoro.pomodoroReset()
|
onClicked: Pomodoro.resetPomodoro()
|
||||||
enabled: (Pomodoro.pomodoroSecondsLeft < Pomodoro.focusTime)
|
enabled: (Pomodoro.pomodoroSecondsLeft < Pomodoro.focusTime)
|
||||||
|
|
||||||
font.pixelSize: Appearance.font.pixelSize.larger
|
font.pixelSize: Appearance.font.pixelSize.larger
|
||||||
@@ -95,82 +95,101 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The SpinBoxes for adjusting duration
|
// The SpinBoxes for adjusting duration
|
||||||
GridLayout {
|
// GridLayout {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
// Layout.alignment: Qt.AlignHCenter
|
||||||
columns: 2
|
// columns: 2
|
||||||
uniformCellWidths: true
|
// uniformCellWidths: true
|
||||||
columnSpacing: 20
|
// columnSpacing: 20
|
||||||
rowSpacing: 4
|
// rowSpacing: 4
|
||||||
|
|
||||||
StyledText {
|
// StyledText {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
// Layout.alignment: Qt.AlignHCenter
|
||||||
text: Translation.tr("Focus")
|
// text: Translation.tr("Focus")
|
||||||
}
|
// }
|
||||||
|
|
||||||
StyledText {
|
// StyledText {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
// Layout.alignment: Qt.AlignHCenter
|
||||||
text: Translation.tr("Break")
|
// text: Translation.tr("Break")
|
||||||
}
|
// }
|
||||||
|
|
||||||
ConfigSpinBox {
|
// ConfigSpinBox {
|
||||||
id: focusSpinBox
|
// id: focusSpinBox
|
||||||
spacing: 0
|
// spacing: 0
|
||||||
Layout.leftMargin: 0
|
// Layout.leftMargin: 0
|
||||||
Layout.rightMargin: 0
|
// Layout.rightMargin: 0
|
||||||
value: Config.options.time.pomodoro.focus / 60
|
// from: 0
|
||||||
onValueChanged: {
|
// to: 120
|
||||||
Config.options.time.pomodoro.focus = value * 60
|
// Connections {
|
||||||
if (Pomodoro.isPomodoroReset) { // Special case for Pomodoro in Reset state
|
// target: Config
|
||||||
Pomodoro.pomodoroSecondsLeft = Pomodoro.focusTime
|
// function onReadyChanged() {
|
||||||
Pomodoro.timeLeft = Pomodoro.focusTime
|
// focusSpinBox.valueChanged()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// value: {
|
||||||
|
// console.log("New focus time: " + (Config.options.time.pomodoro.focus / 60))
|
||||||
|
// return Config.options.time.pomodoro.focus / 60
|
||||||
|
// }
|
||||||
|
// onValueChanged: {
|
||||||
|
// console.log("New focus time is " + value + " minutes, Config is ready:", Config.ready)
|
||||||
|
// if (!Config.ready) return;
|
||||||
|
// console.log("Setting focus time to " + value + " minutes")
|
||||||
|
// Config.options.time.pomodoro.focus = value * 60
|
||||||
|
// if (Pomodoro.isPomodoroReset) { // Special case for Pomodoro in Reset state
|
||||||
|
// Pomodoro.pomodoroSecondsLeft = Pomodoro.focusTime
|
||||||
|
// Pomodoro.timeLeft = Pomodoro.focusTime
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
ConfigSpinBox {
|
// ConfigSpinBox {
|
||||||
id: breakSpinBox
|
// id: breakSpinBox
|
||||||
spacing: 0
|
// value: Config.options.time.pomodoro.breakTime / 60
|
||||||
Layout.leftMargin: 0
|
// spacing: 0
|
||||||
Layout.rightMargin: 0
|
// from: 0
|
||||||
value: Config.options.time.pomodoro.breakTime / 60
|
// to: 120
|
||||||
onValueChanged: {
|
// Layout.leftMargin: 0
|
||||||
Config.options.time.pomodoro.breakTime = value * 60
|
// Layout.rightMargin: 0
|
||||||
}
|
// onValueChanged: {
|
||||||
}
|
// Config.options.time.pomodoro.breakTime = value * 60
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
StyledText {
|
// StyledText {
|
||||||
Layout.topMargin: 6
|
// Layout.topMargin: 6
|
||||||
Layout.alignment: Qt.AlignHCenter
|
// Layout.alignment: Qt.AlignHCenter
|
||||||
text: Translation.tr("Cycle")
|
// text: Translation.tr("Cycle")
|
||||||
}
|
// }
|
||||||
StyledText {
|
// StyledText {
|
||||||
Layout.topMargin: 6
|
// Layout.topMargin: 6
|
||||||
Layout.alignment: Qt.AlignHCenter
|
// Layout.alignment: Qt.AlignHCenter
|
||||||
text: Translation.tr("Long break")
|
// text: Translation.tr("Long break")
|
||||||
}
|
// }
|
||||||
|
|
||||||
ConfigSpinBox {
|
// ConfigSpinBox {
|
||||||
id: cycleSpinBox
|
// id: cycleSpinBox
|
||||||
spacing: 0
|
// value: Config.options.time.pomodoro.cycle
|
||||||
from: 1
|
// spacing: 0
|
||||||
Layout.leftMargin: 0
|
// from: 1
|
||||||
Layout.rightMargin: 0
|
// to: 20
|
||||||
value: Config.options.time.pomodoro.cycle
|
// Layout.leftMargin: 0
|
||||||
onValueChanged: {
|
// Layout.rightMargin: 0
|
||||||
Config.options.time.pomodoro.cycle = value
|
// onValueChanged: {
|
||||||
}
|
// Config.options.time.pomodoro.cycle = value
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
ConfigSpinBox {
|
// ConfigSpinBox {
|
||||||
id: longBreakSpinBox
|
// id: longBreakSpinBox
|
||||||
spacing: 0
|
// spacing: 0
|
||||||
Layout.leftMargin: 0
|
// Layout.leftMargin: 0
|
||||||
Layout.rightMargin: 0
|
// Layout.rightMargin: 0
|
||||||
value: Config.options.time.pomodoro.longBreak / 60
|
// value: Config.options.time.pomodoro.longBreak / 60
|
||||||
onValueChanged: {
|
// from: 0
|
||||||
Config.options.time.pomodoro.longBreak = value * 60
|
// to: 120
|
||||||
}
|
// onValueChanged: {
|
||||||
}
|
// Config.options.time.pomodoro.longBreak = value * 60
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ Item {
|
|||||||
} else if (event.key === Qt.Key_R) {
|
} else if (event.key === Qt.Key_R) {
|
||||||
// Reset with R key
|
// Reset with R key
|
||||||
if (currentTab === 0) {
|
if (currentTab === 0) {
|
||||||
Pomodoro.pomodoroReset()
|
Pomodoro.resetPomodoro()
|
||||||
} else {
|
} else {
|
||||||
Pomodoro.stopwatchReset()
|
Pomodoro.stopwatchReset()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ Item {
|
|||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
spacing: 0
|
spacing: 0
|
||||||
StyledText {
|
StyledText {
|
||||||
Layout.preferredWidth: elapsedIndicator.width * 0.6 // Prevent shakiness
|
// Layout.preferredWidth: elapsedIndicator.width * 0.6 // Prevent shakiness
|
||||||
font.pixelSize: 40
|
font.pixelSize: 40
|
||||||
color: Appearance.m3colors.m3onSurface
|
color: Appearance.m3colors.m3onSurface
|
||||||
text: {
|
text: {
|
||||||
@@ -100,12 +100,12 @@ Item {
|
|||||||
id: lapsList
|
id: lapsList
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
spacing: lapsListItemSpacing
|
spacing: 4
|
||||||
clip: true
|
clip: true
|
||||||
popin: true
|
popin: true
|
||||||
|
|
||||||
model: ScriptModel {
|
model: ScriptModel {
|
||||||
values: Pomodoro.stopwatchLaps
|
values: Pomodoro.stopwatchLaps.map((v, i, arr) => arr[arr.length - 1 - i])
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
@@ -139,11 +139,11 @@ Item {
|
|||||||
StyledText {
|
StyledText {
|
||||||
font.pixelSize: Appearance.font.pixelSize.small
|
font.pixelSize: Appearance.font.pixelSize.small
|
||||||
text: {
|
text: {
|
||||||
let lapTime = lapItem.modelData
|
const lapTime = lapItem.modelData
|
||||||
let _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
const _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
||||||
let totalSeconds = Math.floor(lapTime) / 100
|
const totalSeconds = Math.floor(lapTime) / 100
|
||||||
let minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
const minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
||||||
let seconds = Math.floor(totalSeconds % 60).toString().padStart(2, '0')
|
const seconds = Math.floor(totalSeconds % 60).toString().padStart(2, '0')
|
||||||
return `${minutes}:${seconds}.${_10ms}`
|
return `${minutes}:${seconds}.${_10ms}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,12 +154,13 @@ Item {
|
|||||||
font.pixelSize: Appearance.font.pixelSize.smaller
|
font.pixelSize: Appearance.font.pixelSize.smaller
|
||||||
color: Appearance.colors.colPrimary
|
color: Appearance.colors.colPrimary
|
||||||
text: {
|
text: {
|
||||||
let lastTime = (lapItem.index != Pomodoro.stopwatchLaps.length - 1) ? Pomodoro.stopwatchLaps[lapItem.index + 1] : 0
|
const originalIndex = Pomodoro.stopwatchLaps.length - lapItem.index - 1
|
||||||
let lapTime = lapItem.modelData - lastTime
|
const lastTime = originalIndex > 0 ? Pomodoro.stopwatchLaps[originalIndex - 1] : 0
|
||||||
let _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
const lapTime = lapItem.modelData - lastTime
|
||||||
let totalSeconds = Math.floor(lapTime) / 100
|
const _10ms = (Math.floor(lapTime) % 100).toString().padStart(2, '0')
|
||||||
let minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
const totalSeconds = Math.floor(lapTime) / 100
|
||||||
let seconds = Math.floor(totalSeconds % 60).toString().padStart(2, '0')
|
const minutes = Math.floor(totalSeconds / 60).toString().padStart(2, '0')
|
||||||
|
const seconds = Math.floor(totalSeconds % 60).toString().padStart(2, '0')
|
||||||
return `+${minutes == "00" ? "" : minutes + ":"}${seconds}.${_10ms}`
|
return `+${minutes == "00" ? "" : minutes + ":"}${seconds}.${_10ms}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,13 +25,17 @@ Singleton {
|
|||||||
property bool isPomodoroReset: !isPomodoroRunning
|
property bool isPomodoroReset: !isPomodoroRunning
|
||||||
property int timeLeft: focusTime
|
property int timeLeft: focusTime
|
||||||
property int pomodoroSecondsLeft: focusTime
|
property int pomodoroSecondsLeft: focusTime
|
||||||
property int pomodoroStartTime: Persistent.states.timer.pomodoro.start
|
property int pomodoroStart: Persistent.states.timer.pomodoro.start
|
||||||
property int pomodoroCycle: 1
|
property int pomodoroCycle: 1
|
||||||
|
|
||||||
property bool isStopwatchRunning: false
|
property bool isStopwatchRunning: Persistent.states.timer.stopwatch.running
|
||||||
property int stopwatchTime: 0
|
property int stopwatchTime: 0
|
||||||
property int stopwatchStart: 0
|
property int stopwatchStart: Persistent.states.timer.stopwatch.start
|
||||||
property var stopwatchLaps: []
|
property var stopwatchLaps: Persistent.states.timer.stopwatch.laps
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
if (!isStopwatchRunning) stopwatchReset()
|
||||||
|
}
|
||||||
|
|
||||||
// Start and Stop button
|
// Start and Stop button
|
||||||
function togglePomodoro() {
|
function togglePomodoro() {
|
||||||
@@ -40,12 +44,12 @@ Singleton {
|
|||||||
if (isPomodoroRunning) { // Pressed Start button
|
if (isPomodoroRunning) { // Pressed Start button
|
||||||
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds()
|
Persistent.states.timer.pomodoro.start = getCurrentTimeInSeconds()
|
||||||
} else { // Pressed Stop button
|
} else { // Pressed Stop button
|
||||||
timeLeft -= (getCurrentTimeInSeconds() - pomodoroStartTime)
|
timeLeft -= (getCurrentTimeInSeconds() - pomodoroStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset button
|
// Reset button
|
||||||
function pomodoroReset() {
|
function resetPomodoro() {
|
||||||
Persistent.states.timer.pomodoro.running = false
|
Persistent.states.timer.pomodoro.running = false
|
||||||
isBreak = false
|
isBreak = false
|
||||||
isPomodoroReset = true
|
isPomodoroReset = true
|
||||||
@@ -56,7 +60,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refreshPomodoro() {
|
function refreshPomodoro() {
|
||||||
if (getCurrentTimeInSeconds() >= pomodoroStartTime + timeLeft) {
|
if (getCurrentTimeInSeconds() >= pomodoroStart + timeLeft) {
|
||||||
isBreak = !isBreak
|
isBreak = !isBreak
|
||||||
Persistent.states.timer.pomodoro.start += timeLeft
|
Persistent.states.timer.pomodoro.start += timeLeft
|
||||||
timeLeft = isBreak ? breakTime : focusTime
|
timeLeft = isBreak ? breakTime : focusTime
|
||||||
@@ -74,12 +78,12 @@ Singleton {
|
|||||||
|
|
||||||
Quickshell.execDetached(["notify-send", "Pomodoro", notificationMessage, "-a", "Shell"])
|
Quickshell.execDetached(["notify-send", "Pomodoro", notificationMessage, "-a", "Shell"])
|
||||||
if (alertSound) { // Play sound only if alertSound is explicitly specified
|
if (alertSound) { // Play sound only if alertSound is explicitly specified
|
||||||
Quickshell.execDetached(["bash", "-c", `ffplay -nodisp -autoexit ${alertSound}`])
|
Quickshell.execDetached(["ffplay", "-nodisp", "-autoexit", alertSound])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A nice abstraction for resume logic by updating the TimeStarted
|
// A nice abstraction for resume logic by updating the TimeStarted
|
||||||
pomodoroSecondsLeft = (pomodoroStartTime + timeLeft) - getCurrentTimeInSeconds()
|
pomodoroSecondsLeft = (pomodoroStart + timeLeft) - getCurrentTimeInSeconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentTimeInSeconds() { // Pomodoro uses Seconds
|
function getCurrentTimeInSeconds() { // Pomodoro uses Seconds
|
||||||
@@ -96,31 +100,31 @@ Singleton {
|
|||||||
|
|
||||||
// Stopwatch functions
|
// Stopwatch functions
|
||||||
function toggleStopwatch() {
|
function toggleStopwatch() {
|
||||||
isStopwatchRunning = !isStopwatchRunning
|
Persistent.states.timer.stopwatch.running = !isStopwatchRunning
|
||||||
if (isStopwatchRunning) {
|
if (isStopwatchRunning) {
|
||||||
// Resume from paused time by adjusting start time
|
// Resume from paused time by adjusting start time
|
||||||
stopwatchStart = getCurrentTimeIn10ms() - stopwatchTime
|
Persistent.states.timer.stopwatch.start = getCurrentTimeIn10ms() - stopwatchTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopwatchResetOrLaps() {
|
function stopwatchResetOrLaps() {
|
||||||
if (isStopwatchRunning) { // Clicked on Lap
|
if (isStopwatchRunning) {
|
||||||
recordLaps()
|
recordLaps()
|
||||||
} else { // Clicked on Reset
|
} else {
|
||||||
stopwatchReset()
|
stopwatchReset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopwatchReset() {
|
function stopwatchReset() {
|
||||||
isStopwatchRunning = false
|
Persistent.states.timer.stopwatch.running = false
|
||||||
stopwatchTime = 0
|
stopwatchTime = 0
|
||||||
stopwatchStart = 0
|
stopwatchStart = getCurrentTimeIn10ms()
|
||||||
stopwatchLaps = []
|
Persistent.states.timer.stopwatch.laps = []
|
||||||
}
|
}
|
||||||
|
|
||||||
function recordLaps() {
|
function recordLaps() {
|
||||||
stopwatchLaps.unshift(stopwatchTime) // Last lap goes first on list
|
Persistent.states.timer.stopwatch.laps.push(stopwatchTime)
|
||||||
// Reassign to trigger onListChanged, idk copied from Todo.qml
|
// Reassign to trigger change
|
||||||
root.stopwatchLaps = stopwatchLaps.slice(0)
|
// Persistent.states.timer.stopwatch.laps = Persistent.states.timer.stopwatch.laps.slice(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user