Skip to content

Commit 98b1220

Browse files
committed
click to open calendar fix and tooltip disabled in wayland.
1 parent 0afee2d commit 98b1220

File tree

4 files changed

+77
-79
lines changed

4 files changed

+77
-79
lines changed

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/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
}

tooltipmanager.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
#include "tooltipmanager.h"
22
#include <QToolTip>
33
#include <QGuiApplication>
4-
#include <QScreen>
4+
#include <QTimer>
55
#include <QQuickWindow>
66
#include <QFontMetrics>
7+
#include <QQmlContext>
8+
#include <QQuickView>
79

810
TooltipManager::TooltipManager(QObject *parent) : QObject(parent) {}
911

1012
void TooltipManager::showText(const QPoint &pos, const QString &text)
1113
{
12-
QToolTip::showText(pos, text);
14+
QQuickWindow *window = qobject_cast<QQuickWindow *>(QGuiApplication::focusWindow());
15+
if (!window) return;
16+
QQuickItem *tooltipItem = new QQuickItem(window->contentItem());
17+
tooltipItem->setParentItem(window->contentItem());
18+
tooltipItem->setWidth(200);
19+
tooltipItem->setHeight(50);
20+
21+
QQuickItem *textItem = new QQuickItem(tooltipItem);
22+
textItem->setParentItem(tooltipItem);
23+
textItem->setWidth(tooltipItem->width());
24+
textItem->setHeight(tooltipItem->height());
25+
textItem->setProperty("text", text);
26+
tooltipItem->setPosition(pos);
27+
tooltipItem->setParentItem(window->contentItem());
28+
tooltipItem->setProperty("transientParent", QVariant::fromValue(window));
1329
}
1430

1531
void TooltipManager::hide()

0 commit comments

Comments
 (0)