Changeset 79414 in vbox
- Timestamp:
- Jun 28, 2019 1:44:34 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsScrollBar.cpp
r79389 r79414 27 27 #include <QStyle> 28 28 #include <QStyleOptionGraphicsItem> 29 #include <QTimer> 29 30 #include <QTimerEvent> 30 31 … … 33 34 #include "UIGraphicsScrollBar.h" 34 35 #include "UIIconPool.h" 36 37 38 /** Small functor for QTimer::singleShot worker to perform delayed scrolling. */ 39 class ScrollFunctor 40 { 41 public: 42 43 /** Performs delayed scrolling of specified @a pScrollBar to certain @a pos. */ 44 ScrollFunctor(UIGraphicsScrollBar *pScrollBar, const QPointF &pos) 45 : m_pScrollBar(pScrollBar) 46 , m_pos(pos) 47 {} 48 49 /** Contains functor's body. */ 50 void operator()() 51 { 52 m_pScrollBar->scrollTo(m_pos, 100); 53 } 54 55 private: 56 57 /** Holds the scroll-bar reference to scroll. */ 58 UIGraphicsScrollBar *m_pScrollBar; 59 /** Holds the position to scroll to. */ 60 QPointF m_pos; 61 }; 35 62 36 63 … … 218 245 , m_iHoverOffTimerId(0) 219 246 , m_iHoveringValue(0) 247 , m_fScrollInProgress(false) 220 248 #ifdef VBOX_WS_MAC 221 249 , m_fRevealed(false) … … 243 271 , m_iHoverOffTimerId(0) 244 272 , m_iHoveringValue(0) 273 , m_fScrollInProgress(false) 245 274 #ifdef VBOX_WS_MAC 246 275 , m_fRevealed(false) … … 269 298 { 270 299 return 2 * QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); 300 } 301 302 int UIGraphicsScrollBar::pageStep() const 303 { 304 return 3 * step(); 271 305 } 272 306 … … 323 357 } 324 358 359 void UIGraphicsScrollBar::scrollTo(const QPointF &desiredPos, int iDelay /* = 500 */) 360 { 361 /* Prepare current, desired and intermediate positions: */ 362 const QPointF currentPos = actualTokenPosition(); 363 const int iCurrentY = currentPos.y(); 364 const int iCurrentX = currentPos.x(); 365 const int iDesiredY = desiredPos.y(); 366 const int iDesiredX = desiredPos.x(); 367 QPointF intermediatePos; 368 369 /* Calculate intermediate position depending on orientation: */ 370 switch (m_enmOrientation) 371 { 372 case Qt::Horizontal: 373 { 374 if (iCurrentX < iDesiredX) 375 { 376 intermediatePos.setY(desiredPos.y()); 377 intermediatePos.setX(iCurrentX + pageStep() < iDesiredX ? iCurrentX + pageStep() : iDesiredX); 378 } 379 else if (iCurrentX > iDesiredX) 380 { 381 intermediatePos.setY(desiredPos.y()); 382 intermediatePos.setX(iCurrentX - pageStep() > iDesiredX ? iCurrentX - pageStep() : iDesiredX); 383 } 384 break; 385 } 386 case Qt::Vertical: 387 { 388 if (iCurrentY < iDesiredY) 389 { 390 intermediatePos.setX(desiredPos.x()); 391 intermediatePos.setY(iCurrentY + pageStep() < iDesiredY ? iCurrentY + pageStep() : iDesiredY); 392 } 393 else if (iCurrentY > iDesiredY) 394 { 395 intermediatePos.setX(desiredPos.x()); 396 intermediatePos.setY(iCurrentY - pageStep() > iDesiredY ? iCurrentY - pageStep() : iDesiredY); 397 } 398 break; 399 } 400 } 401 402 /* Move token to intermediate position: */ 403 if (!intermediatePos.isNull()) 404 sltTokenMoved(intermediatePos); 405 406 /* Continue, if we haven't reached required position: */ 407 if ((intermediatePos != desiredPos) && m_fScrollInProgress) 408 QTimer::singleShot(iDelay, ScrollFunctor(this, desiredPos)); 409 } 410 325 411 void UIGraphicsScrollBar::resizeEvent(QGraphicsSceneResizeEvent *pEvent) 326 412 { … … 349 435 pEvent->accept(); 350 436 351 /* Redirect to token move handler: */ 352 sltTokenMoved(pEvent->pos()); 437 /* Start scrolling sequence: */ 438 m_fScrollInProgress = true; 439 scrollTo(pEvent->pos()); 440 } 441 442 void UIGraphicsScrollBar::mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent) 443 { 444 /* Call to base-class: */ 445 QIGraphicsWidget::mousePressEvent(pEvent); 446 447 /* Mark event accepted so that it couldn't 448 * influence underlying widgets: */ 449 pEvent->accept(); 450 451 /* Stop scrolling if any: */ 452 m_fScrollInProgress = false; 353 453 } 354 454 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsScrollBar.h
r79389 r79414 69 69 /** Returns scrolling step. */ 70 70 int step() const; 71 /** Returns page scrolling step. */ 72 int pageStep() const; 71 73 72 74 /** Defines @a iMinimum scroll-bar value. */ … … 85 87 int value() const; 86 88 89 /** Performs scrolling to certain @a desiredPos with certain @a iDelay. */ 90 void scrollTo(const QPointF &desiredPos, int iDelay = 500); 91 87 92 protected: 88 93 … … 95 100 /** Handles mouse-press @a pEvent. */ 96 101 virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) /* override */; 102 /** Handles mouse-release @a pEvent. */ 103 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent) /* override */; 97 104 98 105 /** Handles hover enter @a pEvent. */ … … 207 214 int m_iHoveringValue; 208 215 216 /** Holds whether we are scrolling. */ 217 bool m_fScrollInProgress; 218 209 219 #ifdef VBOX_WS_MAC 210 220 /** Holds whether token is revealed. */
Note:
See TracChangeset
for help on using the changeset viewer.