last 7 months of qs changes

This commit is contained in:
outfoxxed 2025-01-06 00:13:19 -08:00
parent 2c64563ade
commit 4b90113a54
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
103 changed files with 3467 additions and 1415 deletions

View file

@ -0,0 +1,90 @@
import QtQuick
import Quickshell
Scope {
id: root
required property MouseArea target;
property real velocityX: 0;
property real velocityY: 0;
signal flickStarted();
signal flickCompleted();
property real dragStartX: 0;
property real dragStartY: 0;
property real dragDeltaX: 0;
property real dragDeltaY: 0;
property real dragEndX: 0;
property real dragEndY: 0;
property var sampleIdx: -1
property var tSamples: []
property var xSamples: []
property var ySamples: []
ElapsedTimer { id: velocityTimer }
function resetSamples() {
velocityTimer.restart();
sampleIdx = -1;
tSamples = [];
xSamples = [];
ySamples = [];
}
function sample() {
const deltaT = velocityTimer.elapsed();
sampleIdx++;
if (sampleIdx > 5) {
sampleIdx = 0;
}
tSamples[sampleIdx] = deltaT;
xSamples[sampleIdx] = dragDeltaX;
ySamples[sampleIdx] = dragDeltaY;
}
function updateVelocity() {
let firstIdx = sampleIdx + 1;
if (firstIdx > tSamples.length - 1) firstIdx = 0;
const deltaT = tSamples[sampleIdx] - tSamples[firstIdx];
const deltaX = xSamples[sampleIdx] - xSamples[firstIdx];
const deltaY = ySamples[sampleIdx] - ySamples[firstIdx];
root.velocityX = deltaX / deltaT;
root.velocityY = deltaY / deltaT;
}
Connections {
target: root.target;
function onPressed(event: MouseEvent) {
root.resetSamples();
root.dragDeltaX = 0;
root.dragDeltaY = 0;
root.dragStartX = event.x;
root.dragStartY = event.y;
root.flickStarted();
}
function onReleased(event: MouseEvent) {
root.dragDeltaX = event.x - root.dragStartX;
root.dragDeltaY = event.y - root.dragStartY;
root.dragEndX = event.x;
root.dragEndY = event.y;
root.sample();
root.updateVelocity();
root.flickCompleted();
}
function onPositionChanged(event: MouseEvent) {
root.dragDeltaX = event.x - root.dragStartX;
root.dragDeltaY = event.y - root.dragStartY;
root.sample();
}
}
}

View file

@ -0,0 +1,99 @@
pragma ComponentBehavior: Bound;
import QtQuick
Item {
id: root
property list<string> values;
property int index: 0;
implicitWidth: 300
implicitHeight: 40
MouseArea {
id: mouseArea
anchors.fill: parent
property real halfHandle: handle.width / 2;
property real activeWidth: groove.width - handle.width;
property real valueOffset: mouseArea.halfHandle + (root.index / (root.values.length - 1)) * mouseArea.activeWidth;
Repeater {
model: root.values
Item {
id: delegate
required property int index;
required property string modelData;
anchors.top: groove.bottom
anchors.topMargin: 2
x: mouseArea.halfHandle + (delegate.index / (root.values.length - 1)) * mouseArea.activeWidth
Rectangle {
id: mark
color: "#60eeffff"
width: 1
height: groove.height
}
Text {
anchors.top: mark.bottom
x: delegate.index === 0 ? -4
: delegate.index === root.values.length - 1 ? -this.width + 4
: -(this.width / 2);
text: delegate.modelData
color: "#a0eeffff"
}
}
}
Rectangle {
id: grooveFill
anchors {
left: groove.left
top: groove.top
bottom: groove.bottom
}
radius: 5
color: "#80ceffff"
width: mouseArea.valueOffset
}
Rectangle {
id: groove
anchors {
left: parent.left
right: parent.right
}
y: 5
implicitHeight: 7
color: "transparent"
border.color: "#20eeffff"
border.width: 1
radius: 5
}
Rectangle {
id: handle
anchors.verticalCenter: groove.verticalCenter
height: 15
width: height
radius: height * 0.5
x: mouseArea.valueOffset - width * 0.5
}
}
Binding {
when: mouseArea.pressed
root.index: Math.max(0, Math.min(root.values.length - 1, Math.round((mouseArea.mouseX / root.width) * (root.values.length - 1))));
restoreMode: Binding.RestoreBinding
}
}

View file

@ -0,0 +1,42 @@
import QtQuick
Item {
id: root
property real from: 0.0
property real to: 1.0
property real value: 0.0
implicitHeight: 7
implicitWidth: 200
Rectangle {
id: grooveFill
anchors {
left: groove.left
top: groove.top
bottom: groove.bottom
}
radius: 5
color: "#80ceffff"
width: root.width * ((root.value - root.from) / (root.to - root.from))
}
Rectangle {
id: groove
anchors {
left: parent.left
right: parent.right
verticalCenter: parent.verticalCenter
}
height: 7
color: "transparent"
border.color: "#20eeffff"
border.width: 1
radius: 5
}
}

View file

@ -0,0 +1,36 @@
import QtQuick
Item {
id: root
onChildrenChanged: recalc();
Instantiator {
model: root.children
Connections {
required property Item modelData;
target: modelData;
function onImplicitHeightChanged() {
root.recalc();
}
function onImplicitWidthChanged() {
root.recalc();
}
}
}
function recalc() {
let y = 0
let w = 0
for (const child of this.children) {
child.y = y;
y += child.implicitHeight
if (child.implicitWidth > w) w = child.implicitWidth;
}
this.implicitHeight = y;
this.implicitWidth = w;
}
}