initial commit for settings revamp
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import QtQuick
|
||||
import qs.Components
|
||||
import qs.Config
|
||||
|
||||
CustomRect {
|
||||
property bool first
|
||||
property bool last
|
||||
|
||||
bottomLeftRadius: last ? Appearance.rounding.large : Appearance.rounding.extraSmall
|
||||
bottomRightRadius: last ? Appearance.rounding.large : Appearance.rounding.extraSmall
|
||||
color: DynamicColors.tPalette.m3surfaceContainer
|
||||
topLeftRadius: first ? Appearance.rounding.large : Appearance.rounding.extraSmall
|
||||
topRightRadius: first ? Appearance.rounding.large : Appearance.rounding.extraSmall
|
||||
}
|
||||
@@ -0,0 +1,659 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Config
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
readonly property string endTime: {
|
||||
var d = new Date(0, 0, 0, 0, 0, 0, 0);
|
||||
d.setMinutes(object[settings[2]]);
|
||||
return Qt.formatTime(d, "hh:mm AP");
|
||||
}
|
||||
readonly property bool highlighted: SettingsHighlight.highlightedSetting === name
|
||||
required property string name
|
||||
required property var object
|
||||
required property list<string> settings
|
||||
property bool shouldBeActive: true
|
||||
readonly property string startTime: {
|
||||
var d = new Date(0, 0, 0, 0, 0, 0, 0);
|
||||
d.setMinutes(object[settings[1]]);
|
||||
return Qt.formatTime(d, "hh:mm AP");
|
||||
}
|
||||
|
||||
function commitChoice(choice: int, setting: string): void {
|
||||
root.object[setting] = choice;
|
||||
Config.save();
|
||||
Hyprsunset.checkStartup();
|
||||
}
|
||||
|
||||
function convertHour(timeValue: int): int {
|
||||
return Math.floor(timeValue / 60);
|
||||
}
|
||||
|
||||
function convertMinute(timeValue: int): int {
|
||||
return timeValue % 60;
|
||||
}
|
||||
|
||||
function convertToMinutes(hour: int, minute: int): int {
|
||||
return hour * 60 + minute;
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: shouldBeActive ? row.implicitHeight + Appearance.padding.smaller * 2 : 0
|
||||
opacity: shouldBeActive ? 1 : 0
|
||||
scale: shouldBeActive ? 1 : 0.8
|
||||
visible: opacity > 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on scale {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on y {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: -Appearance.padding.smaller
|
||||
color: DynamicColors.palette.m3primaryContainer
|
||||
opacity: root.highlighted ? 0.5 : 0
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
duration: Appearance.anim.durations.normal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: row
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.margins: Appearance.padding.small
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
CustomText {
|
||||
id: text
|
||||
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
Layout.fillWidth: true
|
||||
font.pointSize: Appearance.font.size.larger
|
||||
text: root.name
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
Layout.preferredWidth: Math.min(contentWidth, optionLayout.x - Appearance.spacing.normal)
|
||||
color: DynamicColors.palette.m3onSurfaceVariant
|
||||
font.pointSize: Appearance.font.size.normal
|
||||
text: qsTr("Hyprsunset will turn on at %1, and turn off at %2.").arg(root.startTime).arg(root.endTime)
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: optionLayout
|
||||
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
RowLayout {
|
||||
CustomText {
|
||||
Layout.preferredWidth: spacer.x + spacer.width
|
||||
text: qsTr("Start")
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.preferredWidth: endMinuteRect.width + endHourRect.width
|
||||
text: qsTr("End")
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignLeft | Qt.AlignHCenter
|
||||
text: qsTr("Enabled: ")
|
||||
}
|
||||
|
||||
CustomSwitch {
|
||||
id: enabledSwitch
|
||||
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignHCenter
|
||||
checked: root.object[root.settings[0]]
|
||||
|
||||
onToggled: {
|
||||
root.object[root.settings[0]] = checked;
|
||||
Config.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillHeight: true
|
||||
|
||||
CustomRect {
|
||||
id: startHourRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: startHourField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: startHourField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: startHourField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: startHourField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertHour(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[1])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (startHourField.text.length >= 2) {
|
||||
startHourField.text = "0" + startHourField.text[0];
|
||||
} else if (startHourField.text.length === 1) {
|
||||
startHourField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
startHourField.text = setConfigText(root.settings[1]);
|
||||
startHourField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
startHourField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
startMinuteField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
endMinuteField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = startHourField.text.length;
|
||||
|
||||
if (textLen >= 2 && startHourField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(startHourField.text + digit);
|
||||
} else {
|
||||
val = parseInt(startHourField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
startHourField.text = "0" + val;
|
||||
} else {
|
||||
startHourField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onEditingFinished: {
|
||||
root.commitChoice(root.convertToMinutes(parseInt(startHourField.text), parseInt(startMinuteField.text)), root.settings[1]);
|
||||
}
|
||||
onTextEdited: {
|
||||
if (startHourField.text === "")
|
||||
return;
|
||||
var val = parseInt(startHourField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== startHourField.text)
|
||||
startHourField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: startSeparator
|
||||
|
||||
font.pointSize: Appearance.font.size.extraLarge
|
||||
text: ":"
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: startMinuteRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: startMinuteField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: startMinuteField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: startMinuteField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: startMinuteField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertMinute(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[1])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (startMinuteField.text.length >= 2) {
|
||||
startMinuteField.text = "0" + startMinuteField.text[0];
|
||||
} else if (startMinuteField.text.length === 1) {
|
||||
startMinuteField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
startMinuteField.text = setConfigText(root.settings[1]);
|
||||
startMinuteField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
startMinuteField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
endHourField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
startHourField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = startMinuteField.text.length;
|
||||
|
||||
if (textLen >= 2 && startMinuteField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(startMinuteField.text + digit);
|
||||
} else {
|
||||
val = parseInt(startMinuteField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(59, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
startMinuteField.text = "0" + val;
|
||||
} else {
|
||||
startMinuteField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onEditingFinished: {
|
||||
root.commitChoice(root.convertToMinutes(parseInt(startHourField.text), parseInt(startMinuteField.text)), root.settings[1]);
|
||||
}
|
||||
onTextEdited: {
|
||||
if (startMinuteField.text === "")
|
||||
return;
|
||||
var val = parseInt(startMinuteField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== startMinuteField.text)
|
||||
startMinuteField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: spacer
|
||||
|
||||
Layout.preferredWidth: Appearance.spacing.large
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: endHourRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: endHourField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: endHourField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: endHourField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: endHourField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertHour(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[2])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (endHourField.text.length >= 2) {
|
||||
endHourField.text = "0" + endHourField.text[0];
|
||||
} else if (endHourField.text.length === 1) {
|
||||
endHourField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
endHourField.text = setConfigText(root.settings[2]);
|
||||
endHourField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
endHourField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
endMinuteField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
startMinuteField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = endHourField.text.length;
|
||||
|
||||
if (textLen >= 2 && endHourField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(endHourField.text + digit);
|
||||
} else {
|
||||
val = parseInt(endHourField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
endHourField.text = "0" + val;
|
||||
} else {
|
||||
endHourField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onEditingFinished: {
|
||||
root.commitChoice(root.convertToMinutes(parseInt(endHourField.text), parseInt(endMinuteField.text)), root.settings[2]);
|
||||
}
|
||||
onTextEdited: {
|
||||
if (endHourField.text === "")
|
||||
return;
|
||||
var val = parseInt(endHourField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== endHourField.text)
|
||||
endHourField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: endSeparator
|
||||
|
||||
font.pointSize: Appearance.font.size.extraLarge
|
||||
text: ":"
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: endMinuteRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: endMinuteField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: endMinuteField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: endMinuteField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: endMinuteField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertMinute(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[2])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (endMinuteField.text.length >= 2) {
|
||||
endMinuteField.text = "0" + endMinuteField.text[0];
|
||||
} else if (endMinuteField.text.length === 1) {
|
||||
endMinuteField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
endMinuteField.text = setConfigText(root.settings[2]);
|
||||
endMinuteField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
endMinuteField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
startHourField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
endHourField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = endMinuteField.text.length;
|
||||
|
||||
if (textLen >= 2 && endMinuteField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(endMinuteField.text + digit);
|
||||
} else {
|
||||
val = parseInt(endMinuteField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(59, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
endMinuteField.text = "0" + val;
|
||||
} else {
|
||||
endMinuteField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onEditingFinished: {
|
||||
root.commitChoice(root.convertToMinutes(parseInt(endHourField.text), parseInt(endMinuteField.text)), root.settings[2]);
|
||||
}
|
||||
onTextEdited: {
|
||||
if (endMinuteField.text === "")
|
||||
return;
|
||||
var val = parseInt(endMinuteField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== endMinuteField.text)
|
||||
endMinuteField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
CustomText {
|
||||
id: startHour
|
||||
|
||||
Layout.preferredWidth: startSeparator.x + startSeparator.width
|
||||
text: qsTr("Hour")
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: startMinute
|
||||
|
||||
Layout.preferredWidth: spacer.x + spacer.width - x
|
||||
text: qsTr("Minute")
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.preferredWidth: endSeparator.x + endSeparator.width - x
|
||||
text: qsTr("Hour")
|
||||
}
|
||||
|
||||
CustomText {
|
||||
text: qsTr("Minute")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Modules.SettingsNew
|
||||
import qs.Components
|
||||
import qs.Config
|
||||
|
||||
ColumnLayout {
|
||||
id: root
|
||||
|
||||
readonly property int cappedWidth: Math.min(800, width)
|
||||
default property Item contentChild
|
||||
readonly property alias flickable: flickable
|
||||
property bool isSubPage
|
||||
required property SettingsState sState
|
||||
required property string title
|
||||
|
||||
spacing: Appearance.spacing.large
|
||||
|
||||
MouseArea { // Prevent clicks from reaching flickable
|
||||
Layout.bottomMargin: -flickable.topMargin // Extra height to block clicks on flickable top margin
|
||||
|
||||
implicitHeight: header.implicitHeight - Layout.bottomMargin
|
||||
implicitWidth: header.implicitWidth
|
||||
z: 1
|
||||
|
||||
RowLayout {
|
||||
id: header
|
||||
|
||||
spacing: Appearance.spacing.large
|
||||
|
||||
Loader {
|
||||
active: root.isSubPage
|
||||
asynchronous: true
|
||||
visible: active
|
||||
|
||||
sourceComponent: IconButton {
|
||||
icon: "arrow_back"
|
||||
inactiveColor: DynamicColors.tPalette.m3surfaceContainerHigh
|
||||
inactiveOnColor: DynamicColors.palette.m3onSurfaceVariant
|
||||
isRound: true
|
||||
type: IconButton.Tonal
|
||||
|
||||
onClicked: root.sState.closeSubPage()
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Appearance.font.size.large
|
||||
text: root.title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VerticalFadeFlickable {
|
||||
id: flickable
|
||||
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: -topMargin
|
||||
bottomMargin: Appearance.padding.extraLarge
|
||||
contentHeight: root.contentChild?.implicitHeight ?? 0
|
||||
contentItem.children: [root.contentChild]
|
||||
topMargin: Appearance.padding.large
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Config
|
||||
import qs.Components
|
||||
import qs.Modules.SettingsNew
|
||||
|
||||
ConnectedRect {
|
||||
id: root
|
||||
|
||||
property alias checked: switchButton.checked
|
||||
property int horizontalPadding: Appearance.padding.largeIncreased
|
||||
required property Component popup
|
||||
property alias subtext: subtext.text
|
||||
property alias text: text.text
|
||||
property int verticalPadding: Appearance.padding.normal
|
||||
|
||||
signal clicked(checked: bool)
|
||||
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: layout.implicitHeight + verticalPadding * 2
|
||||
|
||||
Column {
|
||||
id: layout
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: root.horizontalPadding
|
||||
anchors.right: icon.left
|
||||
anchors.rightMargin: Appearance.padding.normal
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
CustomText {
|
||||
id: text
|
||||
|
||||
font.pointSize: Appearance.font.size.smaller
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
color: DynamicColors.palette.m3outline
|
||||
font.pointSize: Appearance.font.size.small
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
|
||||
MaterialIcon {
|
||||
id: icon
|
||||
|
||||
anchors.right: switchButton.left
|
||||
anchors.rightMargin: Appearance.spacing.normal
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "open_in_new"
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
onClicked: PopupManager.requestOpen(root.popup)
|
||||
}
|
||||
|
||||
CustomSwitch {
|
||||
id: switchButton
|
||||
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: root.horizontalPadding
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
onClicked: root.clicked(checked)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Components
|
||||
import qs.Config
|
||||
|
||||
ConnectedRect {
|
||||
id: root
|
||||
|
||||
property alias active: splitButton.active
|
||||
property alias fallbackIcon: splitButton.fallbackIcon
|
||||
property alias fallbackText: splitButton.fallbackText
|
||||
property alias menuItems: splitButton.menuItems
|
||||
property alias menuOnTop: splitButton.menuOnTop
|
||||
property string subtext
|
||||
property alias text: label.text
|
||||
|
||||
signal selected(item: MenuItem)
|
||||
|
||||
Layout.fillWidth: true
|
||||
clip: false
|
||||
implicitHeight: rowLayout.implicitHeight + rowLayout.anchors.margins * 2
|
||||
z: splitButton.expanded ? 1 : 0
|
||||
|
||||
RowLayout {
|
||||
id: rowLayout
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.largeIncreased
|
||||
anchors.margins: Appearance.padding.normal
|
||||
anchors.rightMargin: Appearance.padding.largeIncreased
|
||||
spacing: Appearance.spacing.small
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 0
|
||||
|
||||
CustomText {
|
||||
id: label
|
||||
|
||||
Layout.fillWidth: true
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Appearance.font.size.smaller
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
color: DynamicColors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Appearance.font.size.small
|
||||
text: root.subtext
|
||||
visible: root.subtext
|
||||
}
|
||||
}
|
||||
|
||||
CustomSplitButton {
|
||||
id: splitButton
|
||||
|
||||
type: CustomSplitButton.Tonal
|
||||
|
||||
menu.onItemSelected: item => root.selected(item)
|
||||
stateLayer.onClicked: splitButton.expanded = !splitButton.expanded
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Components
|
||||
import qs.Config
|
||||
import qs.Helpers
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
readonly property bool highlighted: SettingsHighlight.highlightedSetting === name
|
||||
required property string name
|
||||
required property var object
|
||||
required property list<string> settings
|
||||
property bool shouldBeActive: true
|
||||
|
||||
function commitChoice(choice: int, setting: string): void {
|
||||
root.object[setting] = choice;
|
||||
Config.save();
|
||||
}
|
||||
|
||||
function formattedValue(setting: string): string {
|
||||
const value = root.object[setting];
|
||||
|
||||
if (value === null || value === undefined)
|
||||
return "";
|
||||
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function hourToAmPm(hour) {
|
||||
var h = Number(hour) % 24;
|
||||
var d = new Date(2000, 0, 1, h, 0, 0);
|
||||
return Qt.formatTime(d, "h AP");
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
implicitHeight: shouldBeActive ? row.implicitHeight + Appearance.padding.smaller * 2 : 0
|
||||
opacity: shouldBeActive ? 1 : 0
|
||||
scale: shouldBeActive ? 1 : 0.8
|
||||
visible: opacity > 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on scale {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on y {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: -Appearance.padding.smaller
|
||||
color: DynamicColors.palette.m3primaryContainer
|
||||
opacity: root.highlighted ? 0.5 : 0
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
duration: Appearance.anim.durations.normal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: row
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.margins: Appearance.padding.small
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
CustomText {
|
||||
id: text
|
||||
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
Layout.fillWidth: true
|
||||
font.pointSize: Appearance.font.size.larger
|
||||
text: root.name
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
color: DynamicColors.palette.m3onSurfaceVariant
|
||||
font.pointSize: Appearance.font.size.normal
|
||||
text: qsTr("Hyprsunset will turn on at %1, and turn off at %2.").arg(root.hourToAmPm(root.object[root.settings[0]])).arg(root.hourToAmPm(root.object[root.settings[1]]))
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: optionLayout
|
||||
|
||||
Layout.fillHeight: true
|
||||
Layout.preferredWidth: 100
|
||||
|
||||
RowLayout {
|
||||
Layout.preferredWidth: optionLayout.width
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignLeft | Qt.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Enabled: ")
|
||||
}
|
||||
|
||||
CustomSwitch {
|
||||
id: enabledSwitch
|
||||
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignHCenter
|
||||
checked: root.object[root.settings[2]]
|
||||
|
||||
onToggled: {
|
||||
root.object[root.settings[2]] = checked;
|
||||
Config.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.preferredWidth: optionLayout.width
|
||||
z: setting2.expanded ? -1 : 1
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignLeft | Qt.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Start: ")
|
||||
}
|
||||
|
||||
SpinnerButton {
|
||||
id: setting1
|
||||
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignHCenter
|
||||
Layout.preferredHeight: Appearance.font.size.large + Appearance.padding.smaller * 2
|
||||
Layout.preferredWidth: height * 2
|
||||
currentIndex: root.object[root.settings[0]]
|
||||
enabled: enabledSwitch.checked
|
||||
text: root.formattedValue(root.settings[0])
|
||||
|
||||
menu.onItemSelected: item => {
|
||||
root.commitChoice(item, root.settings[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.preferredWidth: optionLayout.width
|
||||
z: setting1.expanded ? -1 : 1
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignLeft | Qt.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("End: ")
|
||||
}
|
||||
|
||||
SpinnerButton {
|
||||
id: setting2
|
||||
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignHCenter
|
||||
Layout.preferredHeight: Appearance.font.size.large + Appearance.padding.smaller * 2
|
||||
Layout.preferredWidth: height * 2
|
||||
currentIndex: root.object[root.settings[1]]
|
||||
enabled: enabledSwitch.checked
|
||||
text: root.formattedValue(root.settings[1])
|
||||
|
||||
menu.onItemSelected: item => {
|
||||
root.commitChoice(item, root.settings[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.preferredWidth: optionLayout.width
|
||||
z: -2
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignLeft | Qt.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Temp: ")
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: rect
|
||||
|
||||
Layout.preferredHeight: 33
|
||||
Layout.preferredWidth: Math.max(Math.min(textField.contentWidth + Appearance.padding.normal * 2, 200), 50)
|
||||
color: DynamicColors.tPalette.m3surfaceContainerHigh
|
||||
radius: Appearance.rounding.full
|
||||
|
||||
CustomTextField {
|
||||
id: textField
|
||||
|
||||
anchors.centerIn: parent
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
implicitWidth: Math.min(contentWidth + Appearance.padding.normal * 2, 200)
|
||||
text: root.formattedValue(root.settings[3])
|
||||
|
||||
onEditingFinished: {
|
||||
root.object[root.settings[3]] = textField.text;
|
||||
Config.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Components
|
||||
import qs.Config
|
||||
|
||||
ConnectedRect {
|
||||
id: root
|
||||
|
||||
property real from: 0
|
||||
property real stepSize: 1
|
||||
property string subtext
|
||||
property alias text: label.text
|
||||
property real to: 99
|
||||
property real value
|
||||
|
||||
signal moved(value: real)
|
||||
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: rowLayout.implicitHeight + rowLayout.anchors.margins * 2
|
||||
|
||||
RowLayout {
|
||||
id: rowLayout
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.largeIncreased
|
||||
anchors.margins: Appearance.padding.normal
|
||||
anchors.rightMargin: Appearance.padding.largeIncreased
|
||||
spacing: Appearance.spacing.small
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 0
|
||||
|
||||
CustomText {
|
||||
id: label
|
||||
|
||||
Layout.fillWidth: true
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Appearance.font.size.smaller
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
color: DynamicColors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Appearance.font.size.small
|
||||
text: root.subtext
|
||||
visible: root.subtext
|
||||
}
|
||||
}
|
||||
|
||||
CustomSpinBox {
|
||||
max: root.to
|
||||
min: root.from
|
||||
step: root.stepSize
|
||||
value: root.value
|
||||
|
||||
onValueModified: v => root.moved(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Components
|
||||
import qs.Modules.SettingsNew
|
||||
import qs.Config
|
||||
|
||||
StackView {
|
||||
id: root
|
||||
|
||||
readonly property int animMovement: Appearance.padding.extraLarge * 2
|
||||
default property list<Component> pages
|
||||
required property SettingsState sState
|
||||
|
||||
function openSubPage(idx: int, immediate: bool): void {
|
||||
const page = pages[idx];
|
||||
if (page) {
|
||||
push(page, {
|
||||
sState
|
||||
}, immediate ? StackView.Immediate : StackView.PushTransition);
|
||||
} else {
|
||||
console.warn(logCat, "Attempted to open invalid sub-page index", idx);
|
||||
sState.closeSubPage();
|
||||
}
|
||||
}
|
||||
|
||||
clip: busy
|
||||
|
||||
popEnter: Transition {
|
||||
SequentialAnimation {
|
||||
PropertyAction {
|
||||
property: "opacity"
|
||||
value: 0
|
||||
}
|
||||
|
||||
PauseAnimation {
|
||||
duration: Appearance.anim.durations.expressiveEffects
|
||||
}
|
||||
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
property: "opacity"
|
||||
to: 1
|
||||
type: Anim.SlowEffects
|
||||
}
|
||||
|
||||
Anim {
|
||||
from: -root.animMovement
|
||||
property: "x"
|
||||
to: 0
|
||||
type: Anim.SlowEffects
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
popExit: Transition {
|
||||
Anim {
|
||||
property: "opacity"
|
||||
to: 0
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
pushEnter: Transition {
|
||||
SequentialAnimation {
|
||||
PropertyAction {
|
||||
property: "opacity"
|
||||
value: 0
|
||||
}
|
||||
|
||||
PauseAnimation {
|
||||
duration: Appearance.anim.durations.expressiveEffects
|
||||
}
|
||||
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
property: "opacity"
|
||||
to: 1
|
||||
type: Anim.SlowEffects
|
||||
}
|
||||
|
||||
Anim {
|
||||
from: root.animMovement
|
||||
property: "x"
|
||||
to: 0
|
||||
type: Anim.SlowEffects
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pushExit: Transition {
|
||||
Anim {
|
||||
property: "opacity"
|
||||
to: 0
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
openSubPage(0, true);
|
||||
for (const page of sState.subPageIdxStack)
|
||||
openSubPage(page, true);
|
||||
}
|
||||
|
||||
LoggingCategory {
|
||||
id: logCat
|
||||
|
||||
defaultLogLevel: LoggingCategory.Info
|
||||
name: "caelestia.nexus"
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onSubPageClosed(): void {
|
||||
if (root.depth < root.sState.subPageIdxStack.length) {
|
||||
console.log(logCat, "Attempted to close page while depth < stack depth. Ignoring.");
|
||||
return;
|
||||
}
|
||||
root.pop();
|
||||
}
|
||||
|
||||
function onSubPageOpened(idx: int): void {
|
||||
root.openSubPage(idx, false);
|
||||
}
|
||||
|
||||
target: root.sState
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,595 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import ZShell.Components
|
||||
import qs.Config
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
CustomClippingRect {
|
||||
id: root
|
||||
|
||||
readonly property string endTime: {
|
||||
var d = new Date(0, 0, 0, 0, 0, 0, 0);
|
||||
d.setMinutes(object[settings[2]]);
|
||||
return Qt.formatTime(d, "hh:mm AP");
|
||||
}
|
||||
required property var object
|
||||
required property list<string> settings
|
||||
property bool shouldBeActive: true
|
||||
readonly property string startTime: {
|
||||
var d = new Date(0, 0, 0, 0, 0, 0, 0);
|
||||
d.setMinutes(object[settings[1]]);
|
||||
return Qt.formatTime(d, "hh:mm AP");
|
||||
}
|
||||
|
||||
signal applySettings(startTime: int, endTime: int)
|
||||
signal close
|
||||
|
||||
function convertHour(timeValue: int): int {
|
||||
return Math.floor(timeValue / 60);
|
||||
}
|
||||
|
||||
function convertMinute(timeValue: int): int {
|
||||
return timeValue % 60;
|
||||
}
|
||||
|
||||
function convertToMinutes(hour: int, minute: int): int {
|
||||
return hour * 60 + minute;
|
||||
}
|
||||
|
||||
color: DynamicColors.palette.m3surfaceContainer
|
||||
implicitHeight: column.implicitHeight + column.anchors.margins * 2 + buttonRow.implicitHeight + buttonRow.anchors.topMargin
|
||||
implicitWidth: column.implicitWidth + column.anchors.margins * 2
|
||||
radius: Appearance.rounding.large
|
||||
|
||||
ColumnLayout {
|
||||
id: column
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.margins: Appearance.padding.largeIncreased
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
spacing: Appearance.spacing.normal
|
||||
|
||||
CustomText {
|
||||
text: qsTr("Select time")
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
CustomRect {
|
||||
id: startHourRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: startHourField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: startHourField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: startHourField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: startHourField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertHour(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[1])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (startHourField.text.length >= 2) {
|
||||
startHourField.text = "0" + startHourField.text[0];
|
||||
} else if (startHourField.text.length === 1) {
|
||||
startHourField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
startHourField.text = setConfigText(root.settings[1]);
|
||||
startHourField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
startHourField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
startMinuteField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
endMinuteField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = startHourField.text.length;
|
||||
|
||||
if (textLen >= 2 && startHourField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(startHourField.text + digit);
|
||||
} else {
|
||||
val = parseInt(startHourField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
startHourField.text = "0" + val;
|
||||
} else {
|
||||
startHourField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onTextEdited: {
|
||||
if (startHourField.text === "")
|
||||
return;
|
||||
var val = parseInt(startHourField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== startHourField.text)
|
||||
startHourField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: startSeparator
|
||||
|
||||
font.pointSize: Appearance.font.size.extraLarge
|
||||
text: ":"
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: startMinuteRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: startMinuteField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: startMinuteField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: startMinuteField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: startMinuteField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertMinute(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[1])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (startMinuteField.text.length >= 2) {
|
||||
startMinuteField.text = "0" + startMinuteField.text[0];
|
||||
} else if (startMinuteField.text.length === 1) {
|
||||
startMinuteField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
startMinuteField.text = setConfigText(root.settings[1]);
|
||||
startMinuteField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
startMinuteField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
endHourField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
startHourField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = startMinuteField.text.length;
|
||||
|
||||
if (textLen >= 2 && startMinuteField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(startMinuteField.text + digit);
|
||||
} else {
|
||||
val = parseInt(startMinuteField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(59, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
startMinuteField.text = "0" + val;
|
||||
} else {
|
||||
startMinuteField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onTextEdited: {
|
||||
if (startMinuteField.text === "")
|
||||
return;
|
||||
var val = parseInt(startMinuteField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== startMinuteField.text)
|
||||
startMinuteField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: spacer
|
||||
|
||||
Layout.preferredWidth: Appearance.spacing.large
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: endHourRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: endHourField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: endHourField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: endHourField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: endHourField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertHour(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[2])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (endHourField.text.length >= 2) {
|
||||
endHourField.text = "0" + endHourField.text[0];
|
||||
} else if (endHourField.text.length === 1) {
|
||||
endHourField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
endHourField.text = setConfigText(root.settings[2]);
|
||||
endHourField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
endHourField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
endMinuteField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
startMinuteField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = endHourField.text.length;
|
||||
|
||||
if (textLen >= 2 && endHourField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(endHourField.text + digit);
|
||||
} else {
|
||||
val = parseInt(endHourField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
endHourField.text = "0" + val;
|
||||
} else {
|
||||
endHourField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onTextEdited: {
|
||||
if (endHourField.text === "")
|
||||
return;
|
||||
var val = parseInt(endHourField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== endHourField.text)
|
||||
endHourField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: endSeparator
|
||||
|
||||
font.pointSize: Appearance.font.size.extraLarge
|
||||
text: ":"
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: endMinuteRect
|
||||
|
||||
Layout.preferredHeight: 72
|
||||
Layout.preferredWidth: 96
|
||||
color: endMinuteField.focus ? DynamicColors.palette.m3onPrimaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
implicitHeight: 72
|
||||
implicitWidth: 96
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
CustomRect {
|
||||
anchors.fill: parent
|
||||
border.color: endMinuteField.focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3surfaceContainerHighest
|
||||
border.width: endMinuteField.focus ? 2 : 0
|
||||
radius: parent.radius - border.width
|
||||
|
||||
Behavior on border.width {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: endMinuteField
|
||||
|
||||
function setConfigText(setting: string): string {
|
||||
var val = root.convertMinute(root.object[setting]);
|
||||
if (val === 0) {
|
||||
return "00";
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clip: true
|
||||
color: focus ? DynamicColors.palette.m3primaryContainer : DynamicColors.palette.m3onSurface
|
||||
cursorHeight: height - Appearance.padding.normal * 2
|
||||
font.family: "Roboto"
|
||||
font.letterSpacing: -0.25
|
||||
font.pixelSize: 56
|
||||
font.weight: 400
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
text: setConfigText(root.settings[2])
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
event.accepted = true;
|
||||
if (endMinuteField.text.length >= 2) {
|
||||
endMinuteField.text = "0" + endMinuteField.text[0];
|
||||
} else if (endMinuteField.text.length === 1) {
|
||||
endMinuteField.text = "0";
|
||||
}
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
event.accepted = true;
|
||||
endMinuteField.text = setConfigText(root.settings[2]);
|
||||
endMinuteField.focus = false;
|
||||
} else if (event.key === Qt.Key_Return) {
|
||||
endMinuteField.focus = false;
|
||||
return;
|
||||
} else if (event.key === Qt.Key_Tab) {
|
||||
startHourField.focus = true;
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
endHourField.focus = true;
|
||||
}
|
||||
|
||||
if (event.text.length === 1 && event.text >= "0" && event.text <= "9") {
|
||||
event.accepted = true;
|
||||
var digit = event.text;
|
||||
var textLen = endMinuteField.text.length;
|
||||
|
||||
if (textLen >= 2 && endMinuteField.text[0] !== '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = 0;
|
||||
if (textLen === 0) {
|
||||
val = parseInt(digit);
|
||||
} else if (textLen === 1) {
|
||||
val = parseInt(endMinuteField.text + digit);
|
||||
} else {
|
||||
val = parseInt(endMinuteField.text[1] + digit);
|
||||
}
|
||||
|
||||
val = Math.max(0, Math.min(59, val));
|
||||
|
||||
if (textLen >= 2 && val < 10) {
|
||||
endMinuteField.text = "0" + val;
|
||||
} else {
|
||||
endMinuteField.text = val.toString();
|
||||
}
|
||||
}
|
||||
|
||||
event.accepted = true;
|
||||
}
|
||||
onCursorPositionChanged: cursorPosition = 2
|
||||
onTextEdited: {
|
||||
if (endMinuteField.text === "")
|
||||
return;
|
||||
var val = parseInt(endMinuteField.text);
|
||||
if (isNaN(val))
|
||||
return;
|
||||
val = Math.max(0, Math.min(23, val));
|
||||
var newText = val.toString();
|
||||
if (newText !== endMinuteField.text)
|
||||
endMinuteField.text = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
CustomText {
|
||||
Layout.preferredWidth: spacer.x + spacer.width
|
||||
text: qsTr("Start")
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.preferredWidth: endMinuteRect.width + endHourRect.width
|
||||
text: qsTr("End")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: buttonRow
|
||||
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.margins: Appearance.padding.largeIncreased
|
||||
anchors.right: parent.right
|
||||
anchors.top: column.bottom
|
||||
anchors.topMargin: Appearance.spacing.normal
|
||||
|
||||
Item {
|
||||
id: buttonSpacer
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
ButtonRow {
|
||||
spacing: Appearance.spacing.normal
|
||||
|
||||
IconTextButton {
|
||||
font.pointSize: Appearance.font.size.normal
|
||||
icon: "close"
|
||||
inactiveColor: DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHighest, 2)
|
||||
inactiveOnColor: DynamicColors.palette.m3onSurfaceVariant
|
||||
isRound: true
|
||||
isToggle: false
|
||||
shapeMorph: true
|
||||
shapeMorphExpansion: pressed ? 12 : 0
|
||||
text: "Cancel"
|
||||
|
||||
onClicked: root.close()
|
||||
}
|
||||
|
||||
IconTextButton {
|
||||
font.pointSize: Appearance.font.size.normal
|
||||
icon: "check"
|
||||
isRound: true
|
||||
isToggle: false
|
||||
shapeMorph: true
|
||||
shapeMorphExpansion: pressed ? 12 : 0
|
||||
text: "Apply"
|
||||
|
||||
onClicked: {
|
||||
const start = root.convertToMinutes(parseInt(startHourField.text)) + parseInt(startMinuteField.text);
|
||||
const end = root.convertToMinutes(parseInt(endHourField.text)) + parseInt(endMinuteField.text);
|
||||
root.applySettings(start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Components
|
||||
import qs.Config
|
||||
|
||||
CustomSwitch {
|
||||
id: root
|
||||
|
||||
readonly property alias bg: bg
|
||||
property alias first: bg.first
|
||||
property alias last: bg.last
|
||||
property string subtext
|
||||
|
||||
Layout.fillWidth: true
|
||||
cLayer: 2
|
||||
horizontalPadding: Appearance.padding.largeIncreased
|
||||
implicitHeight: Math.max(implicitContentHeight, implicitIndicatorHeight) + verticalPadding * 2
|
||||
implicitWidth: implicitContentWidth + implicitIndicatorWidth + horizontalPadding * 2
|
||||
indicator.anchors.right: right
|
||||
indicator.anchors.rightMargin: root.horizontalPadding
|
||||
indicator.anchors.verticalCenter: verticalCenter
|
||||
verticalPadding: Appearance.padding.normal
|
||||
|
||||
background: ConnectedRect {
|
||||
id: bg
|
||||
|
||||
StateLayer {
|
||||
id: stateLayer
|
||||
|
||||
manualPressOverride: root.pressed
|
||||
}
|
||||
}
|
||||
contentItem: Item {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: root.horizontalPadding
|
||||
anchors.right: root.indicator.left
|
||||
anchors.rightMargin: Appearance.spacing.normal
|
||||
implicitHeight: column.implicitHeight
|
||||
implicitWidth: column.implicitWidth
|
||||
|
||||
Column {
|
||||
id: column
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 0
|
||||
|
||||
CustomText {
|
||||
id: label
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(label.font);
|
||||
f.pointSize = Appearance.font.size.smaller;
|
||||
return f;
|
||||
}
|
||||
text: root.text
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: DynamicColors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(subtext.font);
|
||||
f.pointSize = Appearance.font.size.small;
|
||||
return f;
|
||||
}
|
||||
text: root.subtext
|
||||
visible: root.subtext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPressed: stateLayer.press(stateLayer.mouseX, stateLayer.mouseY)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Components
|
||||
import qs.Config
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property alias imgHeight: imgWrapper.implicitHeight
|
||||
property alias radius: imgWrapper.radius
|
||||
property alias source: img.source
|
||||
|
||||
signal clicked
|
||||
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: layout.implicitHeight
|
||||
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
|
||||
anchors.fill: parent
|
||||
spacing: Appearance.spacing.small
|
||||
|
||||
CustomClippingRect {
|
||||
id: imgWrapper
|
||||
|
||||
Layout.fillWidth: true
|
||||
color: DynamicColors.tPalette.m3surfaceContainer
|
||||
implicitHeight: width
|
||||
radius: Appearance.rounding.large
|
||||
|
||||
Image {
|
||||
id: img
|
||||
|
||||
anchors.fill: parent
|
||||
asynchronous: true
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
opacity: status === Image.Ready ? 1 : 0
|
||||
retainWhileLoading: true
|
||||
sourceSize: {
|
||||
const dpr = (QsWindow.window as QsWindow)?.devicePixelRatio ?? 1;
|
||||
return Qt.size(width * dpr, height * dpr);
|
||||
}
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
type: Anim.SlowEffects
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
anchors.bottomMargin: layout.implicitHeight - imgWrapper.implicitHeight
|
||||
|
||||
onClicked: root.clicked()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Hyprland
|
||||
import ZShell.Internal
|
||||
import qs.Config
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
Item {
|
||||
id: wrapper
|
||||
|
||||
property bool changesMade: false
|
||||
property bool shouldBeActive: true
|
||||
|
||||
signal requestCrop
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
implicitHeight: shouldBeActive ? 400 : 0
|
||||
opacity: shouldBeActive ? 1 : 0
|
||||
scale: shouldBeActive ? 1 : 0.8
|
||||
visible: opacity > 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on scale {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on y {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
IconButton {
|
||||
anchors.margins: Appearance.padding.normal
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
icon: "check"
|
||||
opacity: wrapper.changesMade ? 1 : 0
|
||||
scale: wrapper.changesMade ? 1 : 0
|
||||
z: 2
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on scale {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
wrapper.requestCrop();
|
||||
wrapper.changesMade = false;
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: root
|
||||
|
||||
anchors.fill: parent
|
||||
spacing: Appearance.spacing.normal
|
||||
|
||||
Repeater {
|
||||
model: ScriptModel {
|
||||
values: [...Quickshell.screens].sort((a, b) => {
|
||||
return a.x - b.x;
|
||||
})
|
||||
}
|
||||
|
||||
Item {
|
||||
id: delegate
|
||||
|
||||
required property ShellScreen modelData
|
||||
|
||||
function applyCrop(): void {
|
||||
if (!cropRectLoader.item)
|
||||
return;
|
||||
const cropRect = cropRectLoader.item;
|
||||
|
||||
// We need to calculate the exact percentage coordinates that map perfectly
|
||||
// to our C++ backend, regardless of current display scaling
|
||||
const cropXPercent = (cropRect.x - cropRect.imageX) / scaledImg.paintedWidth;
|
||||
const cropYPercent = (cropRect.y - cropRect.imageY) / scaledImg.paintedHeight;
|
||||
const cropWidthPercent = cropRect.width / scaledImg.paintedWidth;
|
||||
const cropHeightPercent = cropRect.height / scaledImg.paintedHeight;
|
||||
|
||||
const finalRect = Qt.rect(cropXPercent, cropYPercent, cropWidthPercent, cropHeightPercent);
|
||||
|
||||
// We just pass the percentages directly to the backend
|
||||
Wallpapers.setCrop(delegate.modelData.name, finalRect, cropRect.zoom);
|
||||
}
|
||||
|
||||
function zoomClipRect(zoom: real): void {
|
||||
if (!cropRectLoader.item)
|
||||
return;
|
||||
const cropRect = cropRectLoader.item;
|
||||
|
||||
let oldCenterX = cropRect.x + cropRect.width * 0.5;
|
||||
let oldCenterY = cropRect.y + cropRect.height * 0.5;
|
||||
|
||||
cropRect.zoom = zoom;
|
||||
|
||||
cropRect.x = oldCenterX - cropRect.width * 0.5;
|
||||
cropRect.y = oldCenterY - cropRect.height * 0.5;
|
||||
|
||||
cropRect.clampToBounds();
|
||||
}
|
||||
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
Connections {
|
||||
function onRequestCrop(): void {
|
||||
delegate.applyCrop();
|
||||
}
|
||||
|
||||
target: wrapper
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: sliderLayout
|
||||
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
implicitHeight: 30
|
||||
|
||||
CustomSlider {
|
||||
id: zoomSlider
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: Appearance.padding.normal
|
||||
Layout.preferredHeight: Appearance.padding.larger * 3
|
||||
Layout.rightMargin: Appearance.padding.normal
|
||||
from: 1.0
|
||||
implicitHeight: Appearance.padding.larger * 3
|
||||
insetIcon: "crop"
|
||||
to: 5.0
|
||||
value: cropRectLoader.item ? cropRectLoader.item.zoom : 1.0
|
||||
|
||||
onInteraction: value => {
|
||||
delegate.zoomClipRect(1 + (value * 4));
|
||||
wrapper.changesMade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CachingImage {
|
||||
id: scaledImg
|
||||
|
||||
property var displayData
|
||||
property real monitorScale: 1.0
|
||||
|
||||
anchors.bottom: sliderLayout.top
|
||||
anchors.bottomMargin: Appearance.spacing.normal
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
asynchronous: true
|
||||
fillMode: Image.PreserveAspectFit
|
||||
retainWhileLoading: true
|
||||
source: Wallpapers.current
|
||||
sourceSize.height: parent.height
|
||||
sourceSize.width: parent.width
|
||||
|
||||
onPaintedWidthChanged: {
|
||||
if (paintedWidth > 0 && cropRectLoader.item) {
|
||||
cropRectLoader.item.restoreFromData();
|
||||
}
|
||||
}
|
||||
onSourceChanged: {
|
||||
if (cropRectLoader.item) {
|
||||
cropRectLoader.item.restoreFromData();
|
||||
}
|
||||
}
|
||||
onStatusChanged: {
|
||||
if (scaledImg.status == Image.Ready && cropRectLoader.item) {
|
||||
cropRectLoader.item.restoreFromData();
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: monitorId
|
||||
|
||||
anchors.centerIn: parent
|
||||
color: Qt.alpha(DynamicColors.palette.m3surface, 0.85)
|
||||
font.pointSize: Appearance.font.size.large * 4
|
||||
style: Text.Outline
|
||||
styleColor: DynamicColors.palette.m3onSurface
|
||||
text: delegate.modelData.name
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: cropRectLoader
|
||||
|
||||
active: scaledImg.paintedWidth > 0
|
||||
|
||||
sourceComponent: Component {
|
||||
CustomRect {
|
||||
id: cropRect
|
||||
|
||||
property real aspectRatio: delegate.modelData.width / delegate.modelData.height
|
||||
readonly property real baseHeight: baseWidth / aspectRatio
|
||||
readonly property real baseWidth: {
|
||||
let fittedHeight = scaledImg.paintedHeight;
|
||||
let fittedWidth = fittedHeight * aspectRatio;
|
||||
|
||||
if (fittedWidth > scaledImg.paintedWidth) {
|
||||
fittedWidth = scaledImg.paintedWidth;
|
||||
fittedHeight = fittedWidth / aspectRatio;
|
||||
}
|
||||
|
||||
return fittedWidth;
|
||||
}
|
||||
readonly property real imageX: (scaledImg.width - scaledImg.paintedWidth) / 2
|
||||
readonly property real imageY: (scaledImg.height - scaledImg.paintedHeight) / 2
|
||||
property real imgAspectRatio: scaledImg.paintedWidth / scaledImg.paintedHeight
|
||||
property real zoom: 1.0
|
||||
|
||||
function centerInImage() {
|
||||
x = imageX + (scaledImg.paintedWidth - width) / 2;
|
||||
y = imageY + (scaledImg.paintedHeight - height) / 2;
|
||||
}
|
||||
|
||||
function clampToBounds() {
|
||||
x = Math.max(imageX, Math.min(x, imageX + scaledImg.paintedWidth - width));
|
||||
|
||||
y = Math.max(imageY, Math.min(y, imageY + scaledImg.paintedHeight - height));
|
||||
}
|
||||
|
||||
function restoreFromData() {
|
||||
let data = Wallpapers.getCrop(delegate.modelData.name);
|
||||
|
||||
if (data && (Math.abs(data.x) > 0.001 || Math.abs(data.y) > 0.001 || Math.abs(data.width - 1.0) > 0.001 || Math.abs(data.height - 1.0) > 0.001)) {
|
||||
zoom = data.zoom > 0 ? data.zoom : 1.0;
|
||||
x = imageX + (data.x * scaledImg.paintedWidth);
|
||||
y = imageY + (data.y * scaledImg.paintedHeight);
|
||||
|
||||
clampToBounds();
|
||||
} else {
|
||||
zoom = 1.0;
|
||||
centerInImage();
|
||||
}
|
||||
}
|
||||
|
||||
border.color: DynamicColors.palette.m3primary
|
||||
border.width: 2
|
||||
height: baseHeight / zoom
|
||||
opacity: 1
|
||||
width: baseWidth / zoom
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
restoreFromData();
|
||||
}
|
||||
onHeightChanged: clampToBounds()
|
||||
onWidthChanged: clampToBounds()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouse
|
||||
|
||||
function updateCrop(mouseX, mouseY) {
|
||||
if (!cropRectLoader.item)
|
||||
return;
|
||||
const cropRect = cropRectLoader.item;
|
||||
|
||||
let nx = mouseX - cropRect.width * 0.5;
|
||||
let ny = mouseY - cropRect.height * 0.5;
|
||||
|
||||
nx = Math.max(cropRect.imageX, Math.min(nx, cropRect.imageX + scaledImg.paintedWidth - cropRect.width));
|
||||
|
||||
ny = Math.max(cropRect.imageY, Math.min(ny, cropRect.imageY + scaledImg.paintedHeight - cropRect.height));
|
||||
|
||||
cropRect.x = nx;
|
||||
cropRect.y = ny;
|
||||
}
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
preventStealing: true
|
||||
|
||||
onPositionChanged: mouse => {
|
||||
if (pressed) {
|
||||
updateCrop(mouse.x, mouse.y);
|
||||
wrapper.changesMade = true;
|
||||
}
|
||||
}
|
||||
onPressed: mouse => {
|
||||
updateCrop(mouse.x, mouse.y);
|
||||
wrapper.changesMade = true;
|
||||
}
|
||||
onReleased: {
|
||||
wrapper.changesMade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user