From kde-commits Fri Feb 03 15:30:28 2012 From: Matthias Kretz Date: Fri, 03 Feb 2012 15:30:28 +0000 To: kde-commits Subject: [zanshin] src: allow setting a due date via mousewheel Message-Id: <20120203153028.BDFA3A60C6 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=132828323519786 Git commit 3d876f8d6dbe138378026d9f3ee7a07ef0b4135a by Matthias Kretz. Committed on 01/02/2012 at 23:51. Pushed by mkretz into branch 'master'. allow setting a due date via mousewheel Setting the due date with the mouse is easier now (for me). Double-click the cell and use the mousewheel to select the date. The mousewheel thus does the same as the up/down cursor keys. M +22 -0 src/kdateedit.cpp M +1 -0 src/kdateedit.h http://commits.kde.org/zanshin/3d876f8d6dbe138378026d9f3ee7a07ef0b4135a diff --git a/src/kdateedit.cpp b/src/kdateedit.cpp index 41f942b..440c9b5 100644 --- a/src/kdateedit.cpp +++ b/src/kdateedit.cpp @@ -278,6 +278,28 @@ void KDateEdit::focusOutEvent( QFocusEvent *e ) QComboBox::focusOutEvent( e ); } = +void KDateEdit::wheelEvent( QWheelEvent *e ) +{ + if ( mReadOnly || e->delta() =3D=3D 0 ) { + return; + } + QDate date =3D parseDate(); + if ( !date.isValid() ) { + return; + } + // QWheelEvent::delta reports +/-120 per step on most mice, but accordin= g to the documentation some + // mice may send smaller deltas. We're just interested in the direction,= though... + date =3D date.addDays( e->delta() > 0 ? 1 : -1 ); + if ( assignDate( date ) ) { + e->accept(); + updateView(); + emit dateChanged( date ); + emit dateEntered( date ); + return; + } + QComboBox::wheelEvent( e ); +} + void KDateEdit::keyPressEvent(QKeyEvent* e) { QDate date; diff --git a/src/kdateedit.h b/src/kdateedit.h index 7a805a5..eb337ea 100644 --- a/src/kdateedit.h +++ b/src/kdateedit.h @@ -116,6 +116,7 @@ class KDateEdit : public QComboBox virtual bool eventFilter( QObject *, QEvent * ); virtual void mousePressEvent( QMouseEvent * ); virtual void focusOutEvent( QFocusEvent * ); + virtual void wheelEvent( QWheelEvent * ); virtual void keyPressEvent( QKeyEvent * ); = /**