forked from Shinonome/dots-hyprland
hefty: bar: time: calendar
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQml
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs
|
||||
import qs.services
|
||||
import qs.modules.common
|
||||
import qs.modules.common.widgets
|
||||
import qs.modules.common.functions
|
||||
import qs.modules.waffle.looks
|
||||
|
||||
Item {
|
||||
id: root
|
||||
@@ -36,15 +31,23 @@ Item {
|
||||
const diffWeeks = Math.round(diffMillis / root.millisPerWeek);
|
||||
root.targetWeekDiff += diffWeeks;
|
||||
}
|
||||
function scrollToToday() {
|
||||
root.targetWeekDiff = 0;
|
||||
}
|
||||
property int weeksPerScroll: 1
|
||||
property real targetWeekDiff: 0
|
||||
property real weekDiff: targetWeekDiff
|
||||
property int contentWeekDiff: weekDiff // whole part of weekDiff
|
||||
property bool scrolling: false
|
||||
|
||||
property Animation scrollAnimation: NumberAnimation {
|
||||
duration: Config.options.calendar.animate ? Appearance.animation.scroll.duration : 0
|
||||
easing.type: Appearance.animation.scroll.type
|
||||
easing.bezierCurve: Appearance.animation.scroll.bezierCurve
|
||||
}
|
||||
Behavior on weekDiff {
|
||||
id: weekScrollBehavior
|
||||
animation: Looks.transition.scroll.createObject(this)
|
||||
animation: root.scrollAnimation
|
||||
}
|
||||
Timer {
|
||||
id: scrollAnimationCheckTimer
|
||||
@@ -56,12 +59,20 @@ Item {
|
||||
scrollAnimationCheckTimer.restart();
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onWheel: wheel => {
|
||||
root.targetWeekDiff += wheel.angleDelta.y / 120 * -root.weeksPerScroll; // Reverse cuz scrolling down should advance
|
||||
property var wheelAction: (wheel) => {
|
||||
// Reverse cuz scrolling down should advance
|
||||
const sign = wheel.angleDelta.y / 120 * -1;
|
||||
if (Config.options.calendar.weekScrollPrecision) {
|
||||
root.targetWeekDiff += sign * root.weeksPerScroll;
|
||||
} else {
|
||||
scrollMonthsAndSnap(sign);
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
anchors.fill: parent
|
||||
onWheel: (wheel) => root.wheelAction(wheel)
|
||||
}
|
||||
|
||||
// Date calculations
|
||||
readonly property int millisPerWeek: 7 * 24 * 60 * 60 * 1000
|
||||
@@ -82,14 +93,16 @@ Item {
|
||||
return DateUtils.getIthDayDateOfSameWeek(dateInTargetWeek, root.focusDayOfWeekIndex - root.locale.firstDayOfWeek, root.locale.firstdayOfWeek); // 4 = Thursday
|
||||
}
|
||||
property int focusedMonth: focusedDate.getMonth() + 1 // 0-indexed -> 1-indexed
|
||||
property string title: locale.toString(focusedDate, "MMMM yyyy")
|
||||
|
||||
// Sizes
|
||||
property real verticalPadding: 0
|
||||
property real horizontalPadding: 0
|
||||
property real buttonSize: 40
|
||||
property real buttonSpacing: 2
|
||||
property real buttonVerticalSpacing: buttonSpacing
|
||||
implicitHeight: (6 * buttonSize) + (5 * buttonVerticalSpacing) + (2 * verticalPadding)
|
||||
implicitWidth: weeksColumn.implicitWidth
|
||||
implicitWidth: weeksColumn.implicitWidth + (2 * horizontalPadding)
|
||||
clip: true
|
||||
|
||||
ColumnLayout {
|
||||
@@ -97,6 +110,8 @@ Item {
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
leftMargin: root.horizontalPadding
|
||||
rightMargin: root.horizontalPadding
|
||||
}
|
||||
y: {
|
||||
const spacePerExtraRow = root.buttonSize + root.buttonVerticalSpacing;
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ GridLayout {
|
||||
property real totalDuration: 250
|
||||
property real interval: totalDuration / count
|
||||
|
||||
default property list<AbstractChoreographable> choreographableChildren
|
||||
default property list<QtObject> choreographableChildren
|
||||
readonly property int count: choreographableChildren.length
|
||||
children: choreographableChildren
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import ".."
|
||||
import "../functions"
|
||||
|
||||
Button {
|
||||
id: root
|
||||
|
||||
property alias radius: bg.radius
|
||||
property alias contentLayer: bg.contentLayer
|
||||
|
||||
property color colFocusRing: Appearance.colors.colOnSecondaryContainer
|
||||
property color colBackground: checked ? colBackgroundChecked : colBackgroundUnchecked
|
||||
property color colForeground: checked ? colForegroundChecked : colForegroundUnchecked
|
||||
|
||||
property color colBackgroundUnchecked: ColorUtils.transparentize(Appearance.colors.colLayer4Base, 1)
|
||||
property color colBackgroundChecked: Appearance.colors.colPrimary
|
||||
property color colForegroundUnchecked: Appearance.colors.colOnLayer4
|
||||
property color colForegroundChecked: Appearance.colors.colOnPrimary
|
||||
|
||||
hoverEnabled: true
|
||||
opacity: root.enabled ? 1 : 0.5
|
||||
|
||||
HoverHandler {
|
||||
cursorShape: root.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
}
|
||||
|
||||
background: StyledRectangle {
|
||||
id: bg
|
||||
implicitHeight: root.contentItem.implicitHeight
|
||||
implicitWidth: root.contentItem.implicitWidth
|
||||
|
||||
radius: Math.min(width, height) / 2
|
||||
color: root.colBackground
|
||||
|
||||
StateOverlay {
|
||||
anchors.fill: parent
|
||||
hover: root.hovered && root.enabled
|
||||
press: root.pressed && root.enabled
|
||||
focus: false // We use a ring instead
|
||||
radius: bg.radius
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: focusRing
|
||||
radius: bg.radius - anchors.margins
|
||||
visible: root.visualFocus
|
||||
color: "transparent"
|
||||
anchors {
|
||||
fill: parent
|
||||
margins: -4
|
||||
}
|
||||
border {
|
||||
color: root.colFocusRing
|
||||
width: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: Item {
|
||||
implicitWidth: buttonText.implicitWidth
|
||||
implicitHeight: buttonText.implicitHeight
|
||||
VisuallyCenteredStyledText {
|
||||
id: buttonText
|
||||
anchors.centerIn: parent
|
||||
text: root.text
|
||||
color: root.colForeground
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
|
||||
StyledButton {
|
||||
id: root
|
||||
|
||||
property alias implicitSize: root.implicitHeight
|
||||
implicitWidth: implicitHeight
|
||||
property alias iconSize: icon.iconSize
|
||||
|
||||
contentItem: Item {
|
||||
MaterialSymbol {
|
||||
id: icon
|
||||
anchors.centerIn: parent
|
||||
color: root.colForeground
|
||||
text: root.text
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user