Changeset 77205 in vbox for trunk/src/VBox
- Timestamp:
- Feb 7, 2019 7:04:50 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
r77203 r77205 21 21 #include <QGraphicsSceneMouseEvent> 22 22 #include <QPainter> 23 #include <QPropertyAnimation> 24 #include <QSignalTransition> 25 #include <QState> 26 #include <QStateMachine> 23 27 #include <QStyle> 24 28 #include <QStyleOptionGraphicsItem> 29 #include <QTimerEvent> 25 30 26 31 /* GUI includes: */ … … 148 153 , m_pButton2(0) 149 154 , m_pToken(0) 155 , m_fHovered(false) 156 , m_iHoverOffTimerId(0) 157 , m_iAnimatedValue(0) 150 158 { 151 159 pScene->addItem(this); … … 164 172 , m_pButton2(0) 165 173 , m_pToken(0) 174 , m_fHovered(false) 175 , m_iHoverOffTimerId(0) 176 , m_iAnimatedValue(0) 166 177 { 167 178 prepare(); … … 272 283 sltTokenMoved(pEvent->pos()); 273 284 layoutToken(); 285 } 286 287 void UIGraphicsScrollBar::hoverMoveEvent(QGraphicsSceneHoverEvent *) 288 { 289 /* Only if not yet hovered, that way we 290 * make sure trigger emitted just once: */ 291 if (!m_fHovered) 292 { 293 /* Emit hover-on trigger: */ 294 m_fHovered = true; 295 emit sigHoverEnter(); 296 } 297 /* Update in any case: */ 298 update(); 299 } 300 301 void UIGraphicsScrollBar::hoverLeaveEvent(QGraphicsSceneHoverEvent *) 302 { 303 /* Only if it's still hovered, that way we 304 * make sure trigger emitted just once: */ 305 if (m_fHovered) 306 { 307 /* Start hover-off timer, handled in timerEvent() below: */ 308 m_iHoverOffTimerId = startTimer(1000); 309 m_fHovered = false; 310 } 311 /* Update in any case: */ 312 update(); 313 } 314 315 void UIGraphicsScrollBar::timerEvent(QTimerEvent *pEvent) 316 { 317 /* Kill timer in any case: */ 318 const int iTimerId = pEvent->timerId(); 319 killTimer(iTimerId); 320 321 /* If that timer is the one we expecting: */ 322 if (m_iHoverOffTimerId != 0 && iTimerId == m_iHoverOffTimerId) 323 { 324 /* Wait for timer no more: */ 325 m_iHoverOffTimerId = 0; 326 /* Emit hover-off trigger if not hovered: */ 327 if (!m_fHovered) 328 emit sigHoverLeave(); 329 /* Update in any case: */ 330 update(); 331 } 274 332 } 275 333 … … 327 385 } 328 386 387 void UIGraphicsScrollBar::sltStateLeftDefault() 388 { 389 m_pButton1->hide(); 390 m_pButton2->hide(); 391 m_pToken->hide(); 392 } 393 394 void UIGraphicsScrollBar::sltStateLeftHovered() 395 { 396 m_pButton1->hide(); 397 m_pButton2->hide(); 398 m_pToken->hide(); 399 } 400 401 void UIGraphicsScrollBar::sltStateEnteredDefault() 402 { 403 m_pButton1->hide(); 404 m_pButton2->hide(); 405 m_pToken->hide(); 406 } 407 408 void UIGraphicsScrollBar::sltStateEnteredHovered() 409 { 410 m_pButton1->show(); 411 m_pButton2->show(); 412 m_pToken->show(); 413 } 414 329 415 void UIGraphicsScrollBar::prepare() 330 416 { 417 /* Configure self: */ 331 418 setAcceptHoverEvents(true); 332 419 … … 335 422 updateExtent(); 336 423 layoutWidgets(); 424 425 /* Prepare animation: */ 426 prepareAnimation(); 337 427 } 338 428 … … 384 474 } 385 475 476 void UIGraphicsScrollBar::prepareAnimation() 477 { 478 /* Create hovering animation machine: */ 479 QStateMachine *pHoveringMachine = new QStateMachine(this); 480 if (pHoveringMachine) 481 { 482 /* Create 'default' state: */ 483 QState *pStateDefault = new QState(pHoveringMachine); 484 /* Create 'hovered' state: */ 485 QState *pStateHovered = new QState(pHoveringMachine); 486 487 /* Configure 'default' state: */ 488 if (pStateDefault) 489 { 490 /* When we entering default state => we assigning animatedValue to 0: */ 491 pStateDefault->assignProperty(this, "animatedValue", 0); 492 connect(pStateDefault, &QState::propertiesAssigned, this, &UIGraphicsScrollBar::sltStateEnteredDefault); 493 494 /* Add state transitions: */ 495 QSignalTransition *pDefaultToHovered = pStateDefault->addTransition(this, SIGNAL(sigHoverEnter()), pStateHovered); 496 if (pDefaultToHovered) 497 { 498 connect(pDefaultToHovered, &QSignalTransition::triggered, this, &UIGraphicsScrollBar::sltStateLeftDefault); 499 500 /* Create forward animation: */ 501 QPropertyAnimation *pHoveringAnimationForward = new QPropertyAnimation(this, "animatedValue", this); 502 if (pHoveringAnimationForward) 503 { 504 pHoveringAnimationForward->setDuration(200); 505 pHoveringAnimationForward->setStartValue(0); 506 pHoveringAnimationForward->setEndValue(100); 507 508 /* Add to transition: */ 509 pDefaultToHovered->addAnimation(pHoveringAnimationForward); 510 } 511 } 512 } 513 514 /* Configure 'hovered' state: */ 515 if (pStateHovered) 516 { 517 /* When we entering hovered state => we assigning animatedValue to 100: */ 518 pStateHovered->assignProperty(this, "animatedValue", 100); 519 connect(pStateHovered, &QState::propertiesAssigned, this, &UIGraphicsScrollBar::sltStateEnteredHovered); 520 521 /* Add state transitions: */ 522 QSignalTransition *pHoveredToDefault = pStateHovered->addTransition(this, SIGNAL(sigHoverLeave()), pStateDefault); 523 if (pHoveredToDefault) 524 { 525 connect(pHoveredToDefault, &QSignalTransition::triggered, this, &UIGraphicsScrollBar::sltStateLeftHovered); 526 527 /* Create backward animation: */ 528 QPropertyAnimation *pHoveringAnimationBackward = new QPropertyAnimation(this, "animatedValue", this); 529 if (pHoveringAnimationBackward) 530 { 531 pHoveringAnimationBackward->setDuration(200); 532 pHoveringAnimationBackward->setStartValue(100); 533 pHoveringAnimationBackward->setEndValue(0); 534 535 /* Add to transition: */ 536 pHoveredToDefault->addAnimation(pHoveringAnimationBackward); 537 } 538 } 539 } 540 541 /* Initial state is 'default': */ 542 pHoveringMachine->setInitialState(pStateDefault); 543 /* Start state-machine: */ 544 pHoveringMachine->start(); 545 } 546 } 547 386 548 void UIGraphicsScrollBar::updateExtent() 387 549 { … … 455 617 456 618 /* Draw background: */ 457 pPainter->fillRect(rectangle, backgroundColor); 619 QRect actualRectangle = rectangle; 620 actualRectangle.setLeft(actualRectangle.left() + .8 * actualRectangle.width() * ((double)100 - m_iAnimatedValue) / 100); 621 pPainter->fillRect(actualRectangle, backgroundColor); 458 622 459 623 /* Restore painter: */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsScrollBar.h
r77203 r77205 34 34 { 35 35 Q_OBJECT; 36 Q_PROPERTY(int animatedValue READ animatedValue WRITE setAnimatedValue); 36 37 37 38 signals: 39 40 /** Notifies listeners about hover enter. */ 41 void sigHoverEnter(); 42 /** Notifies listeners about hover leave. */ 43 void sigHoverLeave(); 38 44 39 45 /** Notifies listeners about @a iValue has changed. */ … … 82 88 virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) /* override */; 83 89 90 /** Handles hover enter @a pEvent. */ 91 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */; 92 /** Handles hover leave @a pEvent. */ 93 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */; 94 95 /** Handles timer @a pEvent. */ 96 virtual void timerEvent(QTimerEvent *pEvent) /* override */; 97 84 98 private slots: 85 99 … … 92 106 void sltTokenMoved(const QPointF &pos); 93 107 108 /** Handles default state leaving. */ 109 void sltStateLeftDefault(); 110 /** Handles hovered state leaving. */ 111 void sltStateLeftHovered(); 112 /** Handles default state entering. */ 113 void sltStateEnteredDefault(); 114 /** Handles hovered state entering. */ 115 void sltStateEnteredHovered(); 116 94 117 private: 95 118 … … 98 121 /** Prepares widgets. */ 99 122 void prepareWidgets(); 123 /** Prepares animation. */ 124 void prepareAnimation(); 100 125 101 126 /** Updates scroll-bar extent value. */ … … 110 135 /** Paints background using specified @a pPainter and certain @a rectangle. */ 111 136 void paintBackground(QPainter *pPainter, const QRect &rectangle) const; 137 138 /** Defines item's animated @a iValue. */ 139 void setAnimatedValue(int iValue) { m_iAnimatedValue = iValue; update(); } 140 /** Returns item's animated value. */ 141 int animatedValue() const { return m_iAnimatedValue; } 112 142 113 143 /** Holds the orientation. */ … … 133 163 /** Holds the scroll-bar token instance. */ 134 164 UIGraphicsScrollBarToken *m_pToken; 165 166 /** Holds whether item is hovered. */ 167 bool m_fHovered; 168 /** Holds the hover-off timer id. */ 169 int m_iHoverOffTimerId; 170 /** Holds the animated value. */ 171 int m_iAnimatedValue; 135 172 }; 136 173
Note:
See TracChangeset
for help on using the changeset viewer.