Files
bbedward ccbf1d38ad widgets: bump qml-common, rename Dank* prefixed widgets to D, add
deprecation notice to plugin compatibility shims

- When qml-common became a thing, we left qs.Widgets shims in place for
  plugin compatibility
- It's annoying to need to maintain them when qml-common has any change,
  add a warning so we can safely deprecate them in the future
- One shot rename the common stuff to D to make it shorter and nicer to
  write
2026-10-05 16:47:19 -04:00

101 lines
3.0 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Window
import qs.Common
import qs.DCommon.Widgets
Item {
id: root
readonly property bool isSettingsRow: true
readonly property bool transparentSlot: true
property string startTitle: ""
property int startHour: 7
property int startMinute: 0
property string endTitle: ""
property int endHour: 19
property int endMinute: 0
property bool is24Hour: false
property bool showEnd: true
signal startChanged(int hour, int minute)
signal endChanged(int hour, int minute)
property bool _editingStart: true
function formatTime(hour, minute) {
const m = (minute < 10 ? "0" : "") + minute;
if (is24Hour)
return (hour < 10 ? "0" : "") + hour + ":" + m;
const h = hour % 12 === 0 ? 12 : hour % 12;
return (h < 10 ? "0" : "") + h + ":" + m + " " + (hour >= 12 ? I18n.tr("PM", "12 hour clock suffix after noon in time setting") : I18n.tr("AM", "12 hour clock suffix before noon in time setting"));
}
function edit(start) {
_editingStart = start;
pickerLoader.active = true;
const picker = pickerLoader.item;
if (!picker)
return;
picker.hour = start ? startHour : endHour;
picker.minute = start ? startMinute : endMinute;
picker.title = start ? startTitle : endTitle;
picker.open();
}
width: parent?.width ?? 0
height: halves.implicitHeight
Row {
id: halves
width: parent.width
spacing: Theme.groupedListGap
Repeater {
model: root.showEnd ? 2 : 1
SettingsRow {
required property int index
readonly property bool isStart: index === 0
width: root.showEnd ? (root.width - Theme.groupedListGap) / 2 : root.width
paintBackground: true
topRadius: Theme.groupedListOuterRadius
bottomRadius: Theme.groupedListOuterRadius
title: isStart ? root.startTitle : root.endTitle
subtitle: root.formatTime(isStart ? root.startHour : root.endHour, isStart ? root.startMinute : root.endMinute)
subtitleColor: Theme.surfaceText
clickable: true
enabled: root.enabled
onClicked: root.edit(isStart)
DIcon {
name: "schedule"
size: Theme.iconSize
color: Theme.surfaceVariantText
anchors.verticalCenter: parent.verticalCenter
}
}
}
}
Loader {
id: pickerLoader
active: false
sourceComponent: DTimePicker {
parent: root.Window.contentItem
is24Hour: root.is24Hour
onAccepted: (hour, minute) => {
if (root._editingStart) {
root.startChanged(hour, minute);
return;
}
root.endChanged(hour, minute);
}
}
}
}