Changeset 109019 in vbox
- Timestamp:
- Apr 17, 2025 3:57:03 PM (3 weeks ago)
- svn:sync-xref-src-repo-rev:
- 168548
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r108978 r109019 980 980 src/manager/UIVirtualMachineItemCloud.cpp \ 981 981 src/manager/chooser/UIChooserAbstractModel.cpp \ 982 src/manager/tools/UIToolsItem.cpp \ 982 983 src/manager/tools/UIToolsModel.cpp \ 983 984 src/activity/overview/UIVMActivityOverviewWidget.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.cpp
r109016 r109019 31 31 #include <QGraphicsScene> 32 32 #include <QPainter> 33 #include <QPropertyAnimation> 34 #include <QSignalTransition> 35 #include <QStateMachine> 33 36 #include <QStyle> 34 37 #include <QStyleOptionGraphicsItem> … … 175 178 UIToolsItem *item() const { return qobject_cast<UIToolsItem*>(object()); } 176 179 }; 180 181 182 /** QObject extension used as animation engine object. */ 183 class UIToolsItemAnimationEngine : public QObject 184 { 185 Q_OBJECT; 186 187 signals: 188 189 /** Initiates transition to hovered state. */ 190 void sigHovered(); 191 /** Initiates transition to unhovered state. */ 192 void sigUnhovered(); 193 194 public: 195 196 /** Constructs animation engine passing @a pParent to the base-class. */ 197 UIToolsItemAnimationEngine(UIToolsItem *pParent); 198 199 private: 200 201 /** Prepares everything. */ 202 void prepare(); 203 /** Prepares machine. */ 204 void prepareMachine(); 205 /** Prepares connections. */ 206 void prepareConnections(); 207 208 /** Inits engine. */ 209 void init(); 210 211 /** Holds the parent item reference. */ 212 UIToolsItem *m_pParent; 213 214 /** Holds the state-machine instance. */ 215 QStateMachine *m_pMachine; 216 217 /** Holds the Unhovered state instance. */ 218 QState *m_pStateUnhovered; 219 /** Holds the Hovered state instance. */ 220 QState *m_pStateHovered; 221 }; 222 223 224 /** QPropertyAnimation extension used as tool-item animation wrapper. */ 225 class UIToolsItemAnimation : public QPropertyAnimation 226 { 227 Q_OBJECT; 228 229 public: 230 231 /** Constructs tool-item animation passing @a pParent to the base-class. 232 * @param pTarget Brings the object animation alters property for. 233 * @param propertyName Brings the name of property inside the @a pTarget. 234 * @param fForward Brings whether animation goes to iValue or from it. */ 235 UIToolsItemAnimation(QObject *pTarget, const QByteArray &propertyName, QObject *pParent, bool fForward); 236 }; 237 238 239 /********************************************************************************************************************************* 240 * Class UIToolsItemAnimationEngine implementation. * 241 *********************************************************************************************************************************/ 242 243 UIToolsItemAnimationEngine::UIToolsItemAnimationEngine(UIToolsItem *pParent) 244 : QObject(pParent) 245 , m_pParent(pParent) 246 , m_pMachine(0) 247 , m_pStateUnhovered(0) 248 , m_pStateHovered(0) 249 { 250 prepare(); 251 } 252 253 void UIToolsItemAnimationEngine::prepare() 254 { 255 /* Prepare everything: */ 256 prepareMachine(); 257 prepareConnections(); 258 259 /* Init can be async, 260 * but for now it's Ok that way. */ 261 init(); 262 } 263 264 void UIToolsItemAnimationEngine::prepareMachine() 265 { 266 /* Prepare animation machine: */ 267 m_pMachine = new QStateMachine(this); 268 if (m_pMachine) 269 { 270 /* Prepare states: */ 271 m_pStateUnhovered = new QState(m_pMachine); 272 m_pStateHovered = new QState(m_pMachine); 273 274 /* Configure Unhovered state: */ 275 if (m_pStateUnhovered) 276 { 277 m_pStateUnhovered->assignProperty(m_pParent, "hoveringProgress", 0); 278 279 /* Add Unhovered=>Hovered state transition: */ 280 QSignalTransition *pTrnUnhoveredToHovered = 281 m_pStateUnhovered->addTransition(this, SIGNAL(sigHovered()), m_pStateHovered); 282 if (pTrnUnhoveredToHovered) 283 { 284 /* Create animation for hoveringProgress: */ 285 UIToolsItemAnimation *pAnmUnhoveredToHovered = 286 new UIToolsItemAnimation(m_pParent, "hoveringProgress", this, true); 287 pTrnUnhoveredToHovered->addAnimation(pAnmUnhoveredToHovered); 288 } 289 } 290 291 /* Configure Hovered state: */ 292 if (m_pStateHovered) 293 { 294 m_pStateHovered->assignProperty(m_pParent, "hoveringProgress", 100); 295 296 /* Add Hovered=>Unhovered state transition: */ 297 QSignalTransition *pTrnHoveredToUnhovered = 298 m_pStateHovered->addTransition(this, SIGNAL(sigUnhovered()), m_pStateUnhovered); 299 if (pTrnHoveredToUnhovered) 300 { 301 /* Create animation for hoveringProgress: */ 302 UIToolsItemAnimation *pAnmHoveredToUnhovered = 303 new UIToolsItemAnimation(m_pParent, "hoveringProgress", this, false); 304 pTrnHoveredToUnhovered->addAnimation(pAnmHoveredToUnhovered); 305 } 306 } 307 } 308 } 309 310 void UIToolsItemAnimationEngine::prepareConnections() 311 { 312 connect(m_pParent, &UIToolsItem::sigHovered, this, &UIToolsItemAnimationEngine::sigHovered); 313 connect(m_pParent, &UIToolsItem::sigUnhovered, this, &UIToolsItemAnimationEngine::sigUnhovered); 314 } 315 316 void UIToolsItemAnimationEngine::init() 317 { 318 /* Define initial animation state: */ 319 m_pMachine->setInitialState(m_pParent->isHovered() ? m_pStateHovered : m_pStateUnhovered); 320 m_pMachine->start(); 321 } 322 323 324 /********************************************************************************************************************************* 325 * Class UIToolsItemAnimation implementation. * 326 *********************************************************************************************************************************/ 327 328 UIToolsItemAnimation::UIToolsItemAnimation(QObject *pTarget, const QByteArray &propertyName, QObject *pParent, bool fForward) 329 : QPropertyAnimation(pTarget, propertyName, pParent) 330 { 331 setEasingCurve(QEasingCurve(QEasingCurve::OutQuart)); 332 setStartValue(fForward ? 0 : 100); 333 setEndValue(fForward ? 100 : 0); 334 setDuration(300); 335 } 177 336 178 337 … … 190 349 , m_iPreviousMinimumWidthHint(0) 191 350 , m_iPreviousMinimumHeightHint(0) 351 , m_pAnimationEngine(0) 352 , m_iHoveringProgress(0) 192 353 { 193 354 prepare(); … … 360 521 QToolTip::showText(posAtScreen, name()); 361 522 } 523 524 /* Notify listeners: */ 525 emit sigHovered(); 362 526 } 363 527 … … 374 538 /* Hide tooltip for good: */ 375 539 QToolTip::hideText(); 540 541 /* Notify listeners: */ 542 emit sigUnhovered(); 376 543 } 377 544 } … … 415 582 updatePixmap(); 416 583 updateNameSize(); 584 585 /* Create animation engine: */ 586 m_pAnimationEngine = new UIToolsItemAnimationEngine(this); 417 587 } 418 588 … … 698 868 || model()->currentItem(itemClass()) == this); 699 869 if (fCondition1 || fCondition2) 870 { 871 /* Acquire font: */ 872 const QFont fnt = data(Qt::FontRole).value<QFont>(); 873 874 /* Paint text: */ 700 875 paintText(/* Painter: */ 701 876 pPainter, … … 703 878 QPoint(iNameX, iNameY), 704 879 /* Font to paint text: */ 705 data(Qt::FontRole).value<QFont>(),880 fnt, 706 881 /* Paint device: */ 707 882 model()->paintDevice(), 708 883 /* Text to paint: */ 709 884 m_strName); 885 886 /* Paint animated underline: */ 887 if (hoveringProgress()) 888 { 889 QFontMetrics fm(fnt); 890 const double fRatio = (double)hoveringProgress() / 100; 891 const int iLength = fRatio * fm.horizontalAdvance(m_strName); 892 pPainter->drawLine(QPoint(iNameX, iNameY + fm.height()), 893 QPoint(iNameX + iLength, iNameY + fm.height())); 894 } 895 } 710 896 } 711 897 } … … 786 972 pPainter->restore(); 787 973 } 974 975 void UIToolsItem::setHoveringProgress(int iProgress) 976 { 977 m_iHoveringProgress = iProgress; 978 update(); 979 } 980 981 982 #include "UIToolsItem.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.h
r109005 r109019 44 44 class QGraphicsScene; 45 45 class QGraphicsSceneHoverEvent; 46 class UIToolsItemAnimationEngine; 46 47 class UIToolsModel; 47 48 … … 51 52 { 52 53 Q_OBJECT; 54 Q_PROPERTY(int hoveringProgress READ hoveringProgress WRITE setHoveringProgress); 53 55 54 56 signals: 57 58 /** @name Item stuff. 59 * @{ */ 60 /** Notifies listeners about item hovered. */ 61 void sigHovered(); 62 /** Notifies listeners about item unhovered. */ 63 void sigUnhovered(); 64 /** @} */ 55 65 56 66 /** @name Layout stuff. … … 102 112 /** Defines whether item is @a fHidden by the @a enmReason. */ 103 113 void setHiddenByReason(bool fHidden, HidingReason enmReason); 114 115 /** Returns whether item is hovered. */ 116 bool isHovered() const { return m_fHovered; } 104 117 /** @} */ 105 118 … … 210 223 const QColor &color, 211 224 int iPadding); 225 /** @} */ 226 227 /** @name Animation stuff. 228 * @{ */ 229 /** Returns hovering progress. */ 230 int hoveringProgress() const { return m_iHoveringProgress; } 231 /** Defines hovering @a iProgress. */ 232 void setHoveringProgress(int iProgress); 212 233 /** @} */ 213 234 … … 247 268 QSize m_nameSize; 248 269 /** @} */ 270 271 /** @name Animation stuff. 272 * @{ */ 273 /** Holds the animation engine instance. */ 274 UIToolsItemAnimationEngine *m_pAnimationEngine; 275 276 /** Holds the hovering progress. */ 277 int m_iHoveringProgress; 278 /** @} */ 249 279 }; 250 280
Note:
See TracChangeset
for help on using the changeset viewer.