Skip to content

Commit 3d79283

Browse files
authored
changes in testing-qml branch (#45)
* test different layout of calendar * fix daycell overlapping with mouse hover effect * click to open calendar fix and tooltip disabled in wayland.
1 parent b07b284 commit 3d79283

File tree

7 files changed

+154
-110
lines changed

7 files changed

+154
-110
lines changed

qml/CalendarGrid.qml

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import "qrc:/qml/"
77
GridLayout {
88
id: calendarGrid
99
columns: 7
10-
rowSpacing: 8
11-
columnSpacing: 8
10+
rowSpacing: 0
11+
columnSpacing: 0
1212
Layout.fillWidth: true
1313
Layout.fillHeight: true
1414
Layout.margins: 20
@@ -26,13 +26,10 @@ GridLayout {
2626
Layout.fillHeight: modelData.type === "day" || modelData.type === "empty"
2727
Layout.preferredHeight: modelData.type === "header" ? 35 : -1
2828

29-
// Use a Loader to conditionally instantiate the correct component.
30-
// This is the key to fixing the "Unable to assign [undefined]" errors.
3129
Loader {
3230
id: delegateLoader
3331
anchors.fill: parent
3432

35-
// Set the source component based on the model data type
3633
sourceComponent: {
3734
if (modelData.type === "header") {
3835
return headerComponent;
@@ -43,7 +40,6 @@ GridLayout {
4340
}
4441
}
4542

46-
// After the correct component is loaded, set its specific properties.
4743
onLoaded: {
4844
if (modelData.type === "day") {
4945
item.bsDay = modelData.bsDay;
@@ -52,53 +48,104 @@ GridLayout {
5248
item.isToday = modelData.isToday;
5349
item.isSaturday = modelData.isSaturday;
5450
item.theme = calendarGrid.theme;
55-
// Connect the signal from the loaded DayCell to the CalendarGrid's signal
5651
item.clicked.connect(function() {
5752
calendarGrid.dayClicked(modelData.panchanga)
5853
});
5954
} else if (modelData.type === "header") {
6055
item.text = modelData.text;
6156
item.theme = calendarGrid.theme;
57+
item.cellIndex = index;
6258
}
6359
}
6460
}
6561
}
6662
}
6763

68-
// --- Component Definitions for the Loader ---
6964

7065
Component {
7166
id: headerComponent
72-
Rectangle {
73-
// These properties are set by the Loader
67+
Item {
68+
id: headerItemContainer
7469
property string text
7570
property var theme
71+
property int cellIndex: -1
72+
73+
Rectangle {
74+
id: headerBackground
75+
anchors.fill: parent
76+
radius: (cellIndex === 0 || cellIndex === 6) ? 6 : 0
77+
color: theme ? theme.secondaryBg : "#FFFFFF"
78+
border.color: theme.borderColor
79+
}
7680

77-
radius: 8
78-
color: theme && theme.isDark ? theme.secondaryBg : (theme ? theme.tertiaryBg : "lightgrey")
79-
border.width: 0
81+
Rectangle {
82+
visible: cellIndex === 0
83+
width: headerBackground.radius
84+
height: headerBackground.radius
85+
color: headerBackground.color
86+
anchors.top: parent.top
87+
anchors.right: parent.right
88+
}
89+
Rectangle {
90+
visible: cellIndex === 0
91+
width: headerBackground.radius
92+
height: headerBackground.radius
93+
color: headerBackground.color
94+
anchors.bottom: parent.bottom
95+
anchors.left: parent.left
96+
}
97+
Rectangle {
98+
visible: cellIndex === 6
99+
width: headerBackground.radius
100+
height: headerBackground.radius
101+
color: headerBackground.color
102+
anchors.top: parent.top
103+
anchors.left: parent.left
104+
}
105+
Rectangle {
106+
visible: cellIndex === 6
107+
width: headerBackground.radius
108+
height: headerBackground.radius
109+
color: headerBackground.color
110+
anchors.bottom: parent.bottom
111+
anchors.left: parent.left
112+
}
113+
Rectangle {
114+
visible: cellIndex === 0 || cellIndex === 6
115+
width: headerBackground.radius
116+
height: headerBackground.radius
117+
color: headerBackground.color
118+
anchors.bottom: parent.bottom
119+
anchors.right: parent.right
120+
}
80121

81122
Label {
82-
text: parent.text
83-
color: theme && theme.isDark ? theme.secondaryText : (theme ? theme.accentText : "blue")
123+
text: headerItemContainer.text
124+
color: {
125+
if (cellIndex === 6) {
126+
return "#E4080A"
127+
} else {
128+
return theme.accentText;
129+
}
130+
}
84131
font.bold: true
85-
font.pixelSize: 12
86-
anchors.fill: parent
87-
horizontalAlignment: Text.AlignHCenter
88-
verticalAlignment: Text.AlignVCenter
132+
font.pixelSize: 14
133+
anchors.centerIn: parent
89134
}
90135
}
91136
}
92137

93138
Component {
94139
id: dayComponent
95-
// The DayCell itself. Its properties will be set by the Loader's onLoaded handler.
96140
DayCell {}
97141
}
98142

99143
Component {
100144
id: emptyComponent
101-
// An empty item for the blank days at the start of the month.
102-
Item {}
145+
Rectangle {
146+
border.color: theme ? theme.borderColor : "grey"
147+
border.width: 1
148+
color: "transparent"
149+
}
103150
}
104151
}

qml/DayCell.qml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import "qrc:/qml/"
66
// DayCell.qml
77
Rectangle {
88
id: dayCell
9-
radius: 12
10-
scale: cellMouseArea.containsMouse ? 1.2 : 1.0
11-
z: cellMouseArea.containsMouse ? 1 : 0
12-
Behavior on scale {
13-
NumberAnimation { duration: 150; easing.type: Easing.InOutQuad }
14-
}
15-
9+
radius: 5
1610
property int bsDay: 0
1711
property int adDay: 0
1812
property string tithi: ""
@@ -42,6 +36,11 @@ Rectangle {
4236
text: Panchanga.toDevanagari(bsDay || 0)
4337
font.bold: true
4438
font.pixelSize: cellMouseArea.containsMouse ? 28 : 25
39+
scale: cellMouseArea.containsMouse ? 1.2 : 1.0
40+
z: cellMouseArea.containsMouse ? 1 : 0
41+
Behavior on scale {
42+
NumberAnimation { duration: 150; easing.type: Easing.InOutQuad }
43+
}
4544
color: {
4645
if (!theme) return "black";
4746
if (isToday) return theme.accentText;

qml/PanchangaDetailDialog.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Dialog {
212212

213213
onClosed: {
214214
clearPanchangaDetails();
215+
Panchanga.clearCache();
215216
debugVisible = false;
216217
}
217218

qml/Settings.qml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -275,26 +275,6 @@ ApplicationWindow {
275275
}
276276
}
277277

278-
// New Calendar Button (visible only on Wayland)
279-
Button {
280-
id: calendarButton
281-
Layout.fillWidth: true
282-
text: "Open Calendar"
283-
// Access the global 'platformName' context property directly
284-
visible: platformName === "wayland"
285-
286-
onClicked: {
287-
openCalendar();
288-
}
289-
290-
background: Rectangle { color: "#555"; radius: 3; }
291-
contentItem: Text {
292-
text: parent.text; color: "lightgreen"; font.pointSize: 12
293-
horizontalAlignment: Text.AlignHCenter
294-
verticalAlignment: Text.AlignVCenter
295-
}
296-
}
297-
298278
Button {
299279
text: "Exit Widget"
300280
Layout.fillWidth: true
@@ -352,31 +332,6 @@ ApplicationWindow {
352332
resetTimer.start();
353333
}
354334

355-
// Function to show the calendar
356-
function openCalendar() {
357-
if (calendarWindow) {
358-
calendarWindow.show();
359-
calendarWindow.raise();
360-
calendarWindow.requestActivate();
361-
return;
362-
}
363-
if (!calendarComponent) {
364-
calendarComponent = Qt.createComponent("main.qml");
365-
}
366-
if (calendarComponent.status === Component.Ready) {
367-
calendarWindow = calendarComponent.createObject(widgetWindow);
368-
if (calendarWindow) {
369-
calendarWindow.closing.connect(() => {
370-
Panchanga.clearCache();
371-
calendarWindow.destroy();
372-
calendarWindow = null;
373-
});
374-
calendarWindow.show();
375-
} else { console.error("Failed to create calendar window."); }
376-
} else { console.error("Error loading component:", calendarComponent.errorString()); }
377-
}
378-
379-
380335
// Window Closing Handler
381336
onClosing: {
382337
resetTimer.stop();

qml/Theme.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ QtObject {
3434
// === Borders ===
3535
readonly property color borderColor: isDark ? "#334155" : "#e2e8f0"
3636
readonly property color todayBorder: isDark ? "#0ea5e9" : "#0284c7"
37-
readonly property color saturdayBorder: isDark ? "#fb7185" : "#fda4af"
37+
readonly property color saturdayBorder: isDark ? "#334155" : "#fda4af"
3838

3939
// === Highlighted Days ===
4040
readonly property color todayBg: isDark ? "#082f49" : "#f0f9ff"
41-
readonly property color saturdayBg: isDark ? "#831843" : "#FEDDDF"
41+
readonly property color saturdayBg: isDark ? "#6E3233" : "#FEDDDF"
4242
readonly property color adDayText: isDark ? "#BBCFFA" : "#6E9BFD"
4343

4444
// === Modal / Dialogs ===

qml/widget.qml

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -100,69 +100,95 @@ ApplicationWindow {
100100
acceptedButtons: Qt.LeftButton | Qt.RightButton
101101
hoverEnabled: true
102102

103+
// Drag state
104+
property bool isPressed: false
105+
property bool dragStarted: false
106+
property bool wasDragged: false
107+
property point pressPos: Qt.point(0, 0)
103108
property int dragStartX: 0
104109
property int dragStartY: 0
105110
property int windowStartX: 0
106111
property int windowStartY: 0
107-
property bool wasDragged: false
108-
109-
Timer {
110-
id: resetDragTimer
111-
interval: 300
112-
repeat: false
113-
onTriggered: dragArea.wasDragged = false
114-
}
112+
property int dragThreshold: 8 // pixels
115113

114+
// Tooltip logic
116115
Timer {
117116
id: tooltipTimer
118117
interval: 500
119118
repeat: false
120119
onTriggered: showTooltip()
121120
}
122-
123-
onEntered: tooltipTimer.start()
124-
onExited: {
121+
// Ignore wayland for tooltip now. (REASON: tooltip position is over widget in buttom side of screen)
122+
onEntered: if (platformName !== "wayland") {
123+
tooltipTimer.start()
124+
}
125+
onExited: { if (platformName !== "wayland") {
125126
tooltipTimer.stop()
126127
hideTooltip()
128+
}
129+
}
130+
131+
// Drag reset timer
132+
Timer {
133+
id: resetDragTimer
134+
interval: 300
135+
repeat: false
136+
onTriggered: dragArea.wasDragged = false
127137
}
128138

129139
Item { id: globalMapper; anchors.fill: parent; visible: false }
130140

131141
onPressed: function(mouse) {
132142
if (mouse.button === Qt.LeftButton) {
133-
wasDragged = false;
134-
if (platformName === "wayland") {
135-
widgetWindow.startSystemMove()
136-
wasDragged = true; // Assume a drag will happen
137-
} else { // X11 and other platforms
138-
// Use the direct screen coordinates from the mouse event for reliability.
139-
var globalPos = globalMapper.mapToGlobal(Qt.point(mouse.x, mouse.y))
140-
dragStartX = globalPos.x
141-
dragStartY = globalPos.y
142-
windowStartX = widgetWindow.x
143-
windowStartY = widgetWindow.y
144-
143+
isPressed = true
144+
dragStarted = false
145+
wasDragged = false
146+
pressPos = Qt.point(mouse.x, mouse.y)
147+
148+
if (platformName !== "wayland") {
149+
var globalPos = globalMapper.mapToGlobal(pressPos)
150+
dragStartX = globalPos.x
151+
dragStartY = globalPos.y
152+
windowStartX = widgetWindow.x
153+
windowStartY = widgetWindow.y
145154
}
146155
}
147156
}
148157

149158
onPositionChanged: function(mouse) {
150-
if (platformName !== "wayland" && (mouse.buttons & Qt.LeftButton)) {
151-
var globalPos = globalMapper.mapToGlobal(Qt.point(mouse.x, mouse.y))
152-
widgetWindow.x = windowStartX + (globalPos.x - dragStartX)
153-
widgetWindow.y = windowStartY + (globalPos.y - dragStartY)
159+
if (!isPressed)
160+
return
154161

162+
var dx = mouse.x - pressPos.x
163+
var dy = mouse.y - pressPos.y
164+
var distance = Math.sqrt(dx * dx + dy * dy)
165+
166+
if (!dragStarted && distance > dragThreshold) {
167+
dragStarted = true
155168
wasDragged = true
169+
170+
if (platformName === "wayland") {
171+
widgetWindow.startSystemMove()
172+
}
173+
}
174+
175+
if (dragStarted && platformName !== "wayland") {
176+
var globalPos = globalMapper.mapToGlobal(Qt.point(mouse.x, mouse.y))
177+
widgetWindow.x = windowStartX + (globalPos.x - dragStartX)
178+
widgetWindow.y = windowStartY + (globalPos.y - dragStartY)
156179
resetDragTimer.stop()
157180
}
158181
}
159182

160183
onReleased: function(mouse) {
161-
if (mouse.button === Qt.LeftButton && wasDragged) {
162-
if (mouse.button === Qt.LeftButton && wasDragged) {
163-
appSettings.setValue("widgetPositionX", widgetWindow.x)
164-
appSettings.setValue("widgetPositionY", widgetWindow.y)
165-
resetDragTimer.start()
184+
if (mouse.button === Qt.LeftButton) {
185+
isPressed = false
186+
dragStarted = false
187+
188+
if (wasDragged) {
189+
appSettings.setValue("widgetPositionX", widgetWindow.x)
190+
appSettings.setValue("widgetPositionY", widgetWindow.y)
191+
resetDragTimer.start()
166192
}
167193
}
168194
}

0 commit comments

Comments
 (0)