- Timestamp:
- Aug 13, 2012 7:20:21 PM (12 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/UIGraphicsButton.cpp
r42795 r42797 21 21 #include <QPainter> 22 22 #include <QGraphicsSceneMouseEvent> 23 #include <QPropertyAnimation>24 23 25 24 /* GUI includes: */ … … 30 29 , m_icon(icon) 31 30 , m_buttonType(UIGraphicsButtonType_Iconified) 32 , m_pAnimation(0)33 31 , m_fParentSelected(false) 34 , m_fHovered(false)35 , m_iColor(-1)36 32 { 37 33 /* Refresh finally: */ … … 42 38 : QIGraphicsWidget(pParent) 43 39 , m_buttonType(buttonType) 44 , m_pAnimation(0)45 40 , m_fParentSelected(false) 46 , m_fHovered(false)47 , m_iColor(-1)48 41 { 49 42 /* Refresh finally: */ 50 43 refresh(); 51 52 /* Prepare animation: */53 setAcceptHoverEvents(true);54 m_pAnimation = new QPropertyAnimation(this, "color", this);55 m_pAnimation->setDuration(1000);56 m_pAnimation->setLoopCount(-1);57 reconfigureAnimation();58 44 } 59 45 … … 63 49 return; 64 50 m_fParentSelected = fParentSelected; 65 reconfigureAnimation();51 update(); 66 52 } 67 53 … … 115 101 /* Prepare variables: */ 116 102 QPalette pal = palette(); 117 QColor windowColor = pal.color(QPalette::Window); 103 QColor backgroundColor = pal.color(m_fParentSelected ? QPalette::Highlight : QPalette::Window); 104 QColor buttonColor = pal.color(QPalette::Window); 105 if (backgroundColor.black() > 128) 106 buttonColor = buttonColor.darker(95); 107 else 108 buttonColor = buttonColor.darker(160); 118 109 119 110 /* Setup: */ 120 111 pPainter->setRenderHint(QPainter::Antialiasing); 121 112 QPen pen = pPainter->pen(); 122 pen.setColor( windowColor.darker(color()));113 pen.setColor(buttonColor); 123 114 pen.setWidth(2); 124 115 pen.setCapStyle(Qt::RoundCap); … … 145 136 /* Prepare variables: */ 146 137 QPalette pal = palette(); 147 QColor windowColor = pal.color(QPalette::Window); 138 QColor backgroundColor = pal.color(m_fParentSelected ? QPalette::Highlight : QPalette::Window); 139 QColor buttonColor = pal.color(QPalette::Window); 140 if (backgroundColor.black() > 128) 141 buttonColor = buttonColor.darker(95); 142 else 143 buttonColor = buttonColor.darker(160); 148 144 149 145 /* Setup: */ 150 146 pPainter->setRenderHint(QPainter::Antialiasing); 151 147 QPen pen = pPainter->pen(); 152 pen.setColor( windowColor.darker(color()));148 pen.setColor(buttonColor); 153 149 pen.setWidth(2); 154 150 pen.setCapStyle(Qt::RoundCap); … … 171 167 } 172 168 173 void UIGraphicsButton::hideEvent(QHideEvent*)174 {175 setHovered(false);176 }177 178 169 void UIGraphicsButton::mousePressEvent(QGraphicsSceneMouseEvent *pEvent) 179 170 { … … 190 181 } 191 182 192 void UIGraphicsButton::hoverMoveEvent(QGraphicsSceneHoverEvent*)193 {194 setHovered(true);195 }196 197 void UIGraphicsButton::hoverLeaveEvent(QGraphicsSceneHoverEvent*)198 {199 setHovered(false);200 }201 202 183 void UIGraphicsButton::refresh() 203 184 { … … 208 189 } 209 190 210 void UIGraphicsButton::reconfigureAnimation()211 {212 setColor(m_fParentSelected ? 105 : 140);213 m_pAnimation->setStartValue(m_fParentSelected ? 105 : 140);214 m_pAnimation->setEndValue(m_fParentSelected ? 105 : 140);215 m_pAnimation->setKeyValueAt(0.5, m_fParentSelected ? 130 : 115);216 }217 218 bool UIGraphicsButton::hovered() const219 {220 return m_fHovered;221 }222 223 void UIGraphicsButton::setHovered(bool fHovered)224 {225 if (m_fHovered == fHovered)226 return;227 228 m_fHovered = fHovered;229 if (m_fHovered)230 {231 m_pAnimation->start();232 }233 else234 {235 m_pAnimation->stop();236 setColor(m_fParentSelected ? 105 : 140);237 }238 }239 240 int UIGraphicsButton::color() const241 {242 return m_iColor;243 }244 245 void UIGraphicsButton::setColor(int iColor)246 {247 m_iColor = iColor;248 update();249 }250 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.h
r42795 r42797 43 43 { 44 44 Q_OBJECT; 45 Q_PROPERTY(int color READ color WRITE setColor);46 45 47 46 signals: … … 78 77 virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = 0); 79 78 80 /* Hide event: */81 void hideEvent(QHideEvent *pEvent);82 83 79 /* Mouse handlers: */ 84 80 virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent); 85 81 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent); 86 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent);87 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent);88 82 89 83 /* Helpers: Update stuff: */ 90 84 virtual void refresh(); 91 92 /* Helpers: Hover animation stuff: */93 void reconfigureAnimation();94 bool hovered() const;95 void setHovered(bool fHovered);96 int color() const;97 void setColor(int iColor);98 85 99 86 private: … … 102 89 QIcon m_icon; 103 90 UIGraphicsButtonType m_buttonType; 104 QPropertyAnimation *m_pAnimation;105 91 bool m_fParentSelected; 106 bool m_fHovered;107 int m_iColor;108 92 }; 109 93
Note:
See TracChangeset
for help on using the changeset viewer.