Changeset 6193 for trunk/qt4-gui/src/views
- Timestamp:
- 05/11/08 19:17:12 (7 months ago)
- Location:
- trunk/qt4-gui/src/views
- Files:
-
- 2 modified
-
userviewbase.cpp (modified) (3 diffs)
-
userviewbase.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt4-gui/src/views/userviewbase.cpp
r6191 r6193 47 47 UserViewBase::UserViewBase(ContactListModel* contactList, QWidget* parent) 48 48 : QTreeView(parent), 49 myContactList(contactList) 49 myContactList(contactList), 50 myAllowScrollTo(false) 50 51 { 51 52 setItemDelegate(new ContactDelegate(this, this)); … … 84 85 setPalette(pal); 85 86 } 86 }87 88 void UserViewBase::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint hint)89 {90 if (Config::ContactList::instance()->autoScroll())91 QTreeView::scrollTo(index, hint);92 87 } 93 88 … … 330 325 } 331 326 } 327 328 void UserViewBase::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) 329 { 330 // Workaround for annoying auto scrolling, see comment in scrollTo() 331 myAllowScrollTo = true; 332 QTreeView::currentChanged(current, previous); 333 myAllowScrollTo = false; 334 } 335 336 void UserViewBase::timerEvent(QTimerEvent* event) 337 { 338 // Workaround for annoying auto scrolling, see comment in scrollTo() 339 myAllowScrollTo = true; 340 QTreeView::timerEvent(event); 341 myAllowScrollTo = false; 342 } 343 344 void UserViewBase::scrollTo(const QModelIndex& index, ScrollHint hint) 345 { 346 // scrollTo is called from the following functions: 347 // QAbstractItemView::setVerticalScrollMode 348 // QAbstractItemView::timerEvent 349 // QAbstractItemView::currentChanged 350 // QAbstractItemViewPrivate::_q_layoutChanged 351 // 352 // Since layoutChanged is emitted by the sort proxy whenever anything item 353 // in the list is changed this causes the list to scroll back to current item 354 // which can be annoying when trying to scroll the list manually. 355 // Since we cannot override a private function this is a ugly workaround to 356 // block scrollTo as default but allow it for timerEvent and currentChanged 357 // instead. (setVerticalScrollMode isn't used so we don't care for that one.) 358 if (myAllowScrollTo) 359 QTreeView::scrollTo(index, hint); 360 } 361 -
trunk/qt4-gui/src/views/userviewbase.h
r6192 r6193 62 62 63 63 /** 64 * Overloaded from base class to make scrolling conditional 64 * Make sure a specified index is visible 65 * Overloaded to stop annoying auto scrolling triggered by layoutChanged 65 66 * 66 * @param index Index of the itemto scroll to67 * @param hint Relative viewport position to maintain67 * @param index Index to scroll to 68 * @param hint Where to place the index 68 69 */ 69 70 virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible); … … 83 84 */ 84 85 virtual void applySkin(); 86 87 /** 88 * Current index has changed 89 * Overloaded as workaround for scrollTo() 90 * 91 * @param current New current index 92 * @param previous Previously current index 93 */ 94 virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous); 85 95 86 96 protected: … … 145 155 virtual void drawBranches(QPainter*, const QRect&, const QModelIndex&) const {} 146 156 157 /** 158 * A timer event happened 159 * Overloaded as workaround for scrollTo() 160 * 161 * @param event Timer event 162 */ 163 virtual void timerEvent(QTimerEvent* event); 164 147 165 private slots: 148 166 /** … … 155 173 private: 156 174 bool midEvent; 175 bool myAllowScrollTo; 157 176 }; 158 177
