Changeset 76987 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jan 25, 2019 12:38:01 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 128399
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.cpp
r76983 r76987 19 19 #include <QApplication> 20 20 #include <QGraphicsScene> 21 #include <QGraphicsSceneMouseEvent> 21 22 #include <QGraphicsView> 22 23 #include <QPainter> 23 24 #include <QStyle> 24 #include <Q GraphicsSceneMouseEvent>25 #include <QTimerEvent> 25 26 26 27 /* GUI includes: */ … … 32 33 , m_icon(icon) 33 34 , m_fParentSelected(false) 35 , m_enmClickPolicy(ClickPolicy_OnRelease) 36 , m_iDelayId(0) 37 , m_iRepeatId(0) 34 38 , m_dIconScaleIndex(0) 35 39 { … … 55 59 { 56 60 return m_dIconScaleIndex; 61 } 62 63 void UIGraphicsButton::setClickPolicy(ClickPolicy enmPolicy) 64 { 65 m_enmClickPolicy = enmPolicy; 66 } 67 68 UIGraphicsButton::ClickPolicy UIGraphicsButton::clickPolicy() const 69 { 70 return m_enmClickPolicy; 57 71 } 58 72 … … 124 138 void UIGraphicsButton::mousePressEvent(QGraphicsSceneMouseEvent *pEvent) 125 139 { 140 /* Call to base-class: */ 141 QIGraphicsWidget::mousePressEvent(pEvent); 142 126 143 /* Accepting this event allows to get release-event: */ 127 144 pEvent->accept(); 145 146 /* For click-on-press policy: */ 147 if (m_enmClickPolicy == ClickPolicy_OnPress) 148 { 149 /* Notify listeners about button click: */ 150 emit sigButtonClicked(); 151 /* Start delay timer: */ 152 m_iDelayId = startTimer(500); 153 } 128 154 } 129 155 … … 132 158 /* Call to base-class: */ 133 159 QIGraphicsWidget::mouseReleaseEvent(pEvent); 134 /* Notify listeners about button click: */ 135 emit sigButtonClicked(); 160 161 /* Depending on click policy: */ 162 switch (m_enmClickPolicy) 163 { 164 /* For click-on-release policy: */ 165 case ClickPolicy_OnRelease: 166 { 167 /* Notify listeners about button click: */ 168 emit sigButtonClicked(); 169 break; 170 } 171 /* For click-on-press policy: */ 172 case ClickPolicy_OnPress: 173 { 174 /* We should stop all timers: */ 175 killTimer(m_iDelayId); 176 killTimer(m_iRepeatId); 177 m_iDelayId = 0; 178 m_iRepeatId = 0; 179 break; 180 } 181 } 182 } 183 184 void UIGraphicsButton::timerEvent(QTimerEvent *pEvent) 185 { 186 /* For click-on-press policy: */ 187 if (m_enmClickPolicy == ClickPolicy_OnPress) 188 { 189 /* We should auto-repeat button click: */ 190 emit sigButtonClicked(); 191 192 /* For delay timer: */ 193 if (pEvent->timerId() == m_iDelayId) 194 { 195 /* We should stop it and start repeat timer: */ 196 killTimer(m_iDelayId); 197 m_iDelayId = 0; 198 m_iRepeatId = startTimer(90); 199 } 200 } 136 201 } 137 202 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.h
r76983 r76987 45 45 public: 46 46 47 /** Click policy. */ 48 enum ClickPolicy { ClickPolicy_OnRelease, ClickPolicy_OnPress }; 49 47 50 /* Constructor: */ 48 51 UIGraphicsButton(QIGraphicsWidget *pParent, const QIcon &icon); … … 55 58 /** Returns icon scale index. */ 56 59 double iconScaleIndex() const; 60 61 /** Defines click @a enmPolicy. */ 62 void setClickPolicy(ClickPolicy enmPolicy); 63 /** Returns click policy. */ 64 ClickPolicy clickPolicy() const; 57 65 58 66 protected: … … 79 87 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent); 80 88 89 /** Handles timer @a pEvent. */ 90 virtual void timerEvent(QTimerEvent *pEvent) /* override */; 91 81 92 /* Helpers: Update stuff: */ 82 93 virtual void refresh(); … … 88 99 bool m_fParentSelected; 89 100 101 /** Holds the click policy. */ 102 ClickPolicy m_enmClickPolicy; 103 104 /** Holds the delay timer ID. */ 105 int m_iDelayId; 106 /** Holds the repeat timer ID. */ 107 int m_iRepeatId; 108 90 109 /** Holds the icon scale index. */ 91 110 double m_dIconScaleIndex;
Note:
See TracChangeset
for help on using the changeset viewer.