Changeset View
Changeset View
Standalone View
Standalone View
src/widget/utils/kexirecordnavigator.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | |||||
98 | 98 | | |||
99 | //! @internal | 99 | //! @internal | ||
100 | class Q_DECL_HIDDEN KexiRecordNavigator::Private | 100 | class Q_DECL_HIDDEN KexiRecordNavigator::Private | ||
101 | { | 101 | { | ||
102 | public: | 102 | public: | ||
103 | Private(KexiRecordNavigator *navigator) | 103 | Private(KexiRecordNavigator *navigator) | ||
104 | : q(navigator) | 104 | : q(navigator) | ||
105 | , handler(0) | 105 | , handler(0) | ||
106 | , offsetAccumulated(0.0f) | ||||
106 | , view(0) | 107 | , view(0) | ||
107 | , editingIndicatorLabel(0) | 108 | , editingIndicatorLabel(0) | ||
108 | , editingIndicatorEnabled(false) | 109 | , editingIndicatorEnabled(false) | ||
109 | , editingIndicatorVisible(false) | 110 | , editingIndicatorVisible(false) | ||
110 | , isInsertingEnabled(true) | 111 | , isInsertingEnabled(true) | ||
111 | { | 112 | { | ||
112 | } | 113 | } | ||
113 | 114 | | |||
Show All 21 Lines | |||||
135 | QToolButton *navBtnLast; | 136 | QToolButton *navBtnLast; | ||
136 | QToolButton *navBtnNew; | 137 | QToolButton *navBtnNew; | ||
137 | QWidget *navRecordNumberParent; | 138 | QWidget *navRecordNumberParent; | ||
138 | QLineEdit *navRecordNumber; | 139 | QLineEdit *navRecordNumber; | ||
139 | QIntValidator *navRecordNumberValidator; | 140 | QIntValidator *navRecordNumberValidator; | ||
140 | QWidget *navRecordCountParent; | 141 | QWidget *navRecordCountParent; | ||
141 | QLineEdit *navRecordCount; //!< readonly counter | 142 | QLineEdit *navRecordCount; //!< readonly counter | ||
142 | int nav1DigitWidth; | 143 | int nav1DigitWidth; | ||
144 | float offsetAccumulated; | ||||
143 | QAbstractScrollArea *view; | 145 | QAbstractScrollArea *view; | ||
144 | 146 | | |||
145 | QLabel *editingIndicatorLabel; | 147 | QLabel *editingIndicatorLabel; | ||
146 | QList<QWidget*> widgetsToResize; | 148 | QList<QWidget*> widgetsToResize; | ||
147 | bool editingIndicatorEnabled; | 149 | bool editingIndicatorEnabled; | ||
148 | bool editingIndicatorVisible; | 150 | bool editingIndicatorVisible; | ||
149 | bool isInsertingEnabled; | 151 | bool isInsertingEnabled; | ||
150 | }; | 152 | }; | ||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Line(s) | 341 | } else if ((bar = d->view->horizontalScrollBar()) == o) { | |||
349 | } | 351 | } | ||
350 | } | 352 | } | ||
351 | return false; | 353 | return false; | ||
352 | } | 354 | } | ||
353 | 355 | | |||
354 | void KexiRecordNavigator::wheelEvent(QWheelEvent* wheelEvent) | 356 | void KexiRecordNavigator::wheelEvent(QWheelEvent* wheelEvent) | ||
355 | { | 357 | { | ||
356 | const int delta = wheelEvent->delta(); | 358 | const int delta = wheelEvent->delta(); | ||
359 | float offset = float(delta) / 120.0f; | ||||
staniek: It would be nice to have this algorithm explained briefly here as well as the 120 constant (it… | |||||
Quite frankly, i do not know what this 120 means. As i tried to imply in the summary, i copied this code from QAbstractSlider, the base for Qt scrollbars, so that it would work and feel like a QScrollArea. The most relevant change in Qt’s repository related to this value, from the days of Qt 4, does not provide any insight to me as to where this value comes from. Would a comment saying “code copied from QAbstractSlider” or the like be sufficient? jfita: Quite frankly, i do not know what this 120 means. As i tried to imply in the summary, i copied… | |||||
360 | if (d->offsetAccumulated != 0.0f && (offset / d->offsetAccumulated) < 0) { | ||||
361 | d->offsetAccumulated = 0.0f; | ||||
362 | } | ||||
363 | d->offsetAccumulated += offset; | ||||
364 | int recordsToScroll = int(d->offsetAccumulated); | ||||
365 | d->offsetAccumulated -= int(d->offsetAccumulated); | ||||
357 | 366 | | |||
358 | // trigger the respective button slots | 367 | // trigger the respective button slots | ||
359 | if (delta > 0) { | 368 | if (recordsToScroll > 0) { | ||
360 | if (d->navBtnPrev->isEnabled()) { | 369 | if (d->navBtnPrev->isEnabled()) { | ||
361 | slotPrevButtonClicked(); | 370 | slotPrevButtonClicked(); | ||
362 | } | 371 | } | ||
363 | } else if (delta < 0) { | 372 | } else if (recordsToScroll < 0) { | ||
364 | if (d->navBtnNext->isEnabled()) { | 373 | if (d->navBtnNext->isEnabled()) { | ||
365 | slotNextButtonClicked(); | 374 | slotNextButtonClicked(); | ||
366 | } | 375 | } | ||
367 | } | 376 | } | ||
368 | 377 | | |||
369 | // scroll wheel events also cancel the editing, | 378 | // scroll wheel events also cancel the editing, | ||
370 | // so move focus out of the navRecordNumber | 379 | // so move focus out of the navRecordNumber | ||
371 | if (d->navRecordNumber->hasFocus()) { | 380 | if (d->navRecordNumber->hasFocus()) { | ||
▲ Show 20 Lines • Show All 320 Lines • Show Last 20 Lines |
It would be nice to have this algorithm explained briefly here as well as the 120 constant (it can be named too).