diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2014-05-13 13:32:30 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-13 17:39:24 +0200 |
commit | efbaa82fc79f3bee5486c12acf21e71cfaaed093 (patch) | |
tree | 6ecb55f76a01a19bddd7deb281ba2e44f57de061 | |
parent | 8c7ca2d9139c767e3b950850274d4d69eea664e9 (diff) | |
download | qtquickcontrols-efbaa82fc79f3bee5486c12acf21e71cfaaed093.tar.gz |
Don't allow navigation to previous/next month when dragging mouse.
When dragging the mouse over the calendar and a date from a previous
month is hit, it will change the visible month to that month.
This becomes worse when dragging the mouse between in the start/end of
the calendar, because there are usually several days shown from the
previous month, and the calendar quickly goes back several months.
[ChangeLog][Calendar] Calendar no longer selects dates
in the next/previous month when dragging the mouse.
Task-number: QTBUG-38848
Change-Id: I0b9bc727a05397a8e4f1280e16c91e39e160bf4a
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-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); |