diff options
-rw-r--r-- | src/controls/Styles/Base/CalendarStyle.qml | 9 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_calendar.qml | 26 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/controls/Styles/Base/CalendarStyle.qml b/src/controls/Styles/Base/CalendarStyle.qml index d93c8325..5f391b37 100644 --- a/src/controls/Styles/Base/CalendarStyle.qml +++ b/src/controls/Styles/Base/CalendarStyle.qml @@ -518,10 +518,15 @@ Style { if (hoveredCellIndex !== previousHoveredCellIndex) control.hovered(date); + // The date must be different for the pressed signal to be emitted. if (pressed && date.getTime() !== control.selectedDate.getTime()) { - control.selectedDate = date; - pressedCellIndex = indexOfCell; control.pressed(date); + + // You can't select dates in a different month while dragging. + if (date.getMonth() === control.selectedDate.getMonth()) { + control.selectedDate = date; + pressedCellIndex = indexOfCell; + } } } } diff --git a/tests/auto/controls/data/tst_calendar.qml b/tests/auto/controls/data/tst_calendar.qml index e4edf725..f2002844 100644 --- a/tests/auto/controls/data/tst_calendar.qml +++ b/tests/auto/controls/data/tst_calendar.qml @@ -642,13 +642,27 @@ Item { dragTo(x, Math.floor(index / CalendarUtils.daysInAWeek), index, new Date(2014, 1, 24 + x)); } - // Dragging into the next month should work. - var firstDateInNextMonth = new Date(2014, 2, 1); - dragTo(5, 4, 33, firstDateInNextMonth); + // Dragging into the next month shouldn't work, as it can lead to + // unwanted month changes if moving within a bunch of "next month" cells. + // We still emit the signals as usual, though. + var oldDate = calendar.selectedDate; + mouseMove(calendar, toPixelsX(5), toPixelsY(4), Qt.LeftButton); + compare(calendar.selectedDate, oldDate); + compare(calendar.__panel.pressedCellIndex, 32); + compare(calendar.__panel.hoveredCellIndex, 33); + compare(hoveredSignalSpy.count, 1); + compare(pressedSignalSpy.count, 1); + compare(releasedSignalSpy.count, 0); + compare(clickedSignalSpy.count, 0); + + hoveredSignalSpy.clear(); + pressedSignalSpy.clear(); + releasedSignalSpy.clear(); + clickedSignalSpy.clear(); - // Finish the drag. - mouseRelease(calendar, toPixelsX(5), toPixelsY(0), Qt.LeftButton); - compare(calendar.selectedDate, firstDateInNextMonth); + // Finish the drag over the day in the next month. + mouseRelease(calendar, toPixelsX(5), toPixelsY(4), Qt.LeftButton); + compare(calendar.selectedDate, oldDate); compare(calendar.__panel.pressedCellIndex, -1); compare(hoveredSignalSpy.count, 0); compare(pressedSignalSpy.count, 0); |