Changeset 71407 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 20, 2018 2:55:53 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/extensions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.cpp
r71027 r71407 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 33 33 34 /* A simple shaded line:*/35 class QIShadeSplitterHandle : public QSplitterHandle34 /** QSplitterHandle subclass representing shaded line. */ 35 class QIShadeSplitterHandle : public QSplitterHandle 36 36 { 37 37 Q_OBJECT; … … 39 39 public: 40 40 41 QIShadeSplitterHandle(Qt::Orientation orientation, QISplitter *pParent) 42 : QSplitterHandle(orientation, pParent) 43 { 44 QPalette pal = qApp->palette(); 45 QColor windowColor = pal.color(QPalette::Active, QPalette::Window); 46 QColor darkColor = pal.color(QPalette::Active, QPalette::Dark); 47 m_color1 = windowColor; 48 m_color2 = windowColor; 49 m_color = darkColor; 50 } 51 52 void configureColors(const QColor &color1, const QColor &color2) 53 { 54 m_color1 = color1; 55 m_color2 = color2; 56 update(); 57 } 41 /** Constructs shaded splitter handle passing @a enmOrientation and @a pParent to the base-class. */ 42 QIShadeSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent); 43 44 /** Defines colors to passed @a color1 and @a color2. */ 45 void configureColors(const QColor &color1, const QColor &color2); 58 46 59 47 protected: 60 48 61 void paintEvent(QPaintEvent *pEvent) 62 { 63 QPainter painter(this); 64 QLinearGradient gradient; 65 QGradientStop point1(0, m_color1); 66 QGradientStop point2(0.5, m_color); 67 QGradientStop point3(1, m_color2); 68 QGradientStops stops; 69 stops << point1 << point2 << point3; 70 gradient.setStops(stops); 71 if (orientation() == Qt::Horizontal) 72 { 73 gradient.setStart(rect().left() + 1, 0); 74 gradient.setFinalStop(rect().right(), 0); 75 } 76 else 77 { 78 gradient.setStart(0, rect().top() + 1); 79 gradient.setFinalStop(0, rect().bottom()); 80 } 81 painter.fillRect(pEvent->rect(), gradient); 82 } 49 /** Handles paint @a pEvent. */ 50 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 83 51 84 52 private: 85 53 54 /** Holds the main color. */ 86 55 QColor m_color; 56 /** Holds the color1. */ 87 57 QColor m_color1; 58 /** Holds the color2. */ 88 59 QColor m_color2; 89 60 }; 90 61 91 #ifdef RT_OS_DARWIN 92 /* The Mac OS X version. */ 93 class QIDarwinSplitterHandle: public QSplitterHandle 62 63 #ifdef VBOX_WS_MAC 64 /** QSplitterHandle subclass representing shaded line for macOS. */ 65 class QIDarwinSplitterHandle : public QSplitterHandle 94 66 { 95 67 Q_OBJECT; … … 97 69 public: 98 70 99 QIDarwinSplitterHandle(Qt::Orientation orientation, QISplitter *pParent) 100 : QSplitterHandle(orientation, pParent) 101 {} 102 103 QSize sizeHint() const 104 { 105 QSize parent = QSplitterHandle::sizeHint(); 106 if (orientation() == Qt::Vertical) 107 return parent + QSize(0, 3); 108 else 109 return QSize(1, parent.height()); 110 } 71 /** Constructs shaded splitter handle passing @a enmOrientation and @a pParent to the base-class. */ 72 QIDarwinSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent); 73 74 /** Returns size-hint. */ 75 QSize sizeHint() const; 111 76 112 77 protected: 113 78 114 void paintEvent(QPaintEvent*) 115 { 116 QPainter painter(this); 117 118 QColor topColor(145, 145, 145); 119 QColor bottomColor(142, 142, 142); 120 QColor gradientStart(252, 252, 252); 121 QColor gradientStop(223, 223, 223); 122 123 if (orientation() == Qt::Vertical) 124 { 125 painter.setPen(topColor); 126 painter.drawLine(0, 0, width(), 0); 127 painter.setPen(bottomColor); 128 painter.drawLine(0, height() - 1, width(), height() - 1); 129 130 QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, height() -3)); 131 linearGrad.setColorAt(0, gradientStart); 132 linearGrad.setColorAt(1, gradientStop); 133 painter.fillRect(QRect(QPoint(0,1), size() - QSize(0, 2)), QBrush(linearGrad)); 134 } 135 else 136 { 137 painter.setPen(topColor); 138 painter.drawLine(0, 0, 0, height()); 139 } 140 } 79 /** Handles paint @a pEvent. */ 80 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 141 81 }; 142 #endif /* RT_OS_DARWIN */ 82 #endif /* VBOX_WS_MAC */ 83 84 85 /********************************************************************************************************************************* 86 * Class QIShadeSplitterHandle implementation. * 87 *********************************************************************************************************************************/ 88 89 QIShadeSplitterHandle::QIShadeSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent) 90 : QSplitterHandle(enmOrientation, pParent) 91 { 92 QPalette pal = qApp->palette(); 93 QColor windowColor = pal.color(QPalette::Active, QPalette::Window); 94 QColor darkColor = pal.color(QPalette::Active, QPalette::Dark); 95 m_color1 = windowColor; 96 m_color2 = windowColor; 97 m_color = darkColor; 98 } 99 100 void QIShadeSplitterHandle::configureColors(const QColor &color1, const QColor &color2) 101 { 102 m_color1 = color1; 103 m_color2 = color2; 104 update(); 105 } 106 107 void QIShadeSplitterHandle::paintEvent(QPaintEvent *pEvent) 108 { 109 QPainter painter(this); 110 QLinearGradient gradient; 111 QGradientStop point1(0, m_color1); 112 QGradientStop point2(0.5, m_color); 113 QGradientStop point3(1, m_color2); 114 QGradientStops stops; 115 stops << point1 << point2 << point3; 116 gradient.setStops(stops); 117 if (orientation() == Qt::Horizontal) 118 { 119 gradient.setStart(rect().left() + 1, 0); 120 gradient.setFinalStop(rect().right(), 0); 121 } 122 else 123 { 124 gradient.setStart(0, rect().top() + 1); 125 gradient.setFinalStop(0, rect().bottom()); 126 } 127 painter.fillRect(pEvent->rect(), gradient); 128 } 129 130 131 #ifdef VBOX_WS_MAC 132 133 /********************************************************************************************************************************* 134 * Class QIDarwinSplitterHandle implementation. * 135 *********************************************************************************************************************************/ 136 137 QIDarwinSplitterHandle::QIDarwinSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent) 138 : QSplitterHandle(enmOrientation, pParent) 139 { 140 } 141 142 QSize QIDarwinSplitterHandle::sizeHint() const 143 { 144 QSize parent = QSplitterHandle::sizeHint(); 145 if (orientation() == Qt::Vertical) 146 return parent + QSize(0, 3); 147 else 148 return QSize(1, parent.height()); 149 } 150 151 void QIDarwinSplitterHandle::paintEvent(QPaintEvent *) 152 { 153 QPainter painter(this); 154 155 QColor topColor(145, 145, 145); 156 QColor bottomColor(142, 142, 142); 157 QColor gradientStart(252, 252, 252); 158 QColor gradientStop(223, 223, 223); 159 160 if (orientation() == Qt::Vertical) 161 { 162 painter.setPen(topColor); 163 painter.drawLine(0, 0, width(), 0); 164 painter.setPen(bottomColor); 165 painter.drawLine(0, height() - 1, width(), height() - 1); 166 167 QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, height() -3)); 168 linearGrad.setColorAt(0, gradientStart); 169 linearGrad.setColorAt(1, gradientStop); 170 painter.fillRect(QRect(QPoint(0,1), size() - QSize(0, 2)), QBrush(linearGrad)); 171 } 172 else 173 { 174 painter.setPen(topColor); 175 painter.drawLine(0, 0, 0, height()); 176 } 177 } 178 179 #endif /* VBOX_WS_MAC */ 180 181 182 /********************************************************************************************************************************* 183 * Class QISplitter implementation. * 184 *********************************************************************************************************************************/ 143 185 144 186 QISplitter::QISplitter(QWidget *pParent /* = 0 */) 145 187 : QSplitter(pParent) 188 , m_type(Shade) 146 189 , m_fPolished(false) 190 #ifdef VBOX_WS_MAC 191 , m_fHandleGrabbed(false) 192 #endif /* VBOX_WS_MAC */ 193 { 194 qApp->installEventFilter(this); 195 } 196 197 QISplitter::QISplitter(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */) 198 : QSplitter(enmOrientation, pParent) 147 199 , m_type(Shade) 200 , m_fPolished(false) 148 201 #ifdef VBOX_WS_MAC 149 202 , m_fHandleGrabbed(false) 150 203 #endif /* VBOX_WS_MAC */ 151 204 { 152 qApp->installEventFilter(this);153 }154 155 QISplitter::QISplitter(Qt::Orientation orientation, QWidget *pParent /* = 0 */)156 : QSplitter(orientation, pParent)157 , m_fPolished(false)158 , m_type(Shade)159 #ifdef VBOX_WS_MAC160 , m_fHandleGrabbed(false)161 #endif /* VBOX_WS_MAC */162 {163 205 qApp->installEventFilter (this); 164 206 } … … 166 208 bool QISplitter::eventFilter(QObject *pWatched, QEvent *pEvent) 167 209 { 210 /* Handles events for handle: */ 168 211 if (pWatched == handle(1)) 169 212 { 170 213 switch (pEvent->type()) 171 214 { 215 /* Restore default position on double-click: */ 172 216 case QEvent::MouseButtonDblClick: 173 217 restoreState(m_baseState); … … 177 221 } 178 222 } 179 #ifdef VBOX_WS_MAC 180 /* Special handling on the Mac. Cause there the horizontal handle is only 1 181 * pixel wide, its hard to catch. Therefor we make some invisible area 182 * around the handle and forwarding the mouse events to the handle, if the 183 * user presses the left mouse button. */ 223 224 #ifdef VBOX_WS_MAC 225 // WORKAROUND: 226 // Special handling on the Mac. Cause there the horizontal handle is only 1 227 // pixel wide, its hard to catch. Therefor we make some invisible area 228 // around the handle and forwarding the mouse events to the handle, if the 229 // user presses the left mouse button. 184 230 else if ( m_type == Native 185 231 && orientation() == Qt::Horizontal … … 210 256 if (pEvent->type() == QEvent::MouseButtonPress) 211 257 { 212 /* If we have a handle position hit and the left 213 * button is pressed, start the grabbing. */ 258 /* If we have a handle position hit and the left button is pressed, start the grabbing. */ 214 259 if ( fMarginHit 215 260 && pMouseEvent->buttons().testFlag(Qt::LeftButton)) … … 223 268 else if (pEvent->type() == QEvent::MouseMove) 224 269 { 225 /* If we are in the near of the handle or currently 226 * dragging, forward the mouse event. */ 270 /* If we are in the near of the handle or currently dragging, forward the mouse event. */ 227 271 if ( fMarginHit 228 272 || ( m_fHandleGrabbed … … 257 301 #endif /* VBOX_WS_MAC */ 258 302 303 /* Call to base-class: */ 259 304 return QSplitter::eventFilter(pWatched, pEvent); 260 305 } … … 262 307 void QISplitter::showEvent(QShowEvent *pEvent) 263 308 { 309 /* Remember default position: */ 264 310 if (!m_fPolished) 265 311 { … … 268 314 } 269 315 316 /* Call to base-class: */ 270 317 return QSplitter::showEvent(pEvent); 271 318 } 272 319 273 QSplitterHandle* QISplitter::createHandle() 274 { 320 QSplitterHandle *QISplitter::createHandle() 321 { 322 /* Create native handle: */ 275 323 if (m_type == Native) 276 324 { 277 #ifdef RT_OS_DARWIN325 #ifdef VBOX_WS_MAC 278 326 return new QIDarwinSplitterHandle(orientation(), this); 279 #else /* RT_OS_DARWIN */327 #else 280 328 return new QSplitterHandle(orientation(), this); 281 #endif /* RT_OS_DARWIN */ 282 } 329 #endif 330 } 331 /* Create our own handle: */ 283 332 else 284 333 { … … 291 340 292 341 #include "QISplitter.moc" 342 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.h
r71027 r71407 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef _ QISplitter_h_19 #define _ QISplitter_h_18 #ifndef ___QISplitter_h___ 19 #define ___QISplitter_h___ 20 20 21 /* Global includes*/21 /* Qt includes: */ 22 22 #include <QSplitter> 23 23 24 /* Forward declarations: */ 25 class QSplitterHandle; 26 27 /** QSplitter subclass with extended functionality. */ 24 28 class QISplitter : public QSplitter 25 29 { … … 28 32 public: 29 33 34 /** Handle types. */ 30 35 enum Type { Native, Shade }; 31 36 37 /** Constructs splitter passing @a pParent to the base-class. */ 32 38 QISplitter(QWidget *pParent = 0); 39 /** Constructs splitter passing @a orientation and @a pParent to the base-class. */ 33 40 QISplitter(Qt::Orientation orientation, QWidget *pParent = 0); 34 41 42 /** Defines handle @a type. */ 35 43 void setHandleType(Type type) { m_type = type; } 44 /** Returns handle type. */ 36 45 Type handleType() const { return m_type; } 37 46 47 /** Configure custom colors defined as @a color1 and @a color2. */ 38 48 void configureColors(const QColor &color1, const QColor &color2) { m_color1 = color1; m_color2 = color2; } 39 49 40 50 protected: 41 51 42 bool eventFilter(QObject *pWatched, QEvent *pEvent); 52 /** Preprocesses Qt @a pEvent for passed @a pObject. */ 53 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */; 54 55 /** Handles show @a pEvent. */ 43 56 void showEvent(QShowEvent *pEvent); 44 57 45 QSplitterHandle* createHandle(); 58 /** Creates handle. */ 59 QSplitterHandle *createHandle(); 46 60 47 61 private: 48 62 63 /** Holds the serialized base-state. */ 49 64 QByteArray m_baseState; 50 65 51 bool m_fPolished;66 /** Holds the handle type. */ 52 67 Type m_type; 68 69 /** Holds whether the splitter is polished. */ 70 bool m_fPolished : 1; 53 71 #ifdef VBOX_WS_MAC 54 bool m_fHandleGrabbed; 72 /** Holds whether handle is grabbed. */ 73 bool m_fHandleGrabbed : 1; 55 74 #endif /* VBOX_WS_MAC */ 56 75 76 /** Holds color1. */ 57 77 QColor m_color1; 78 /** Holds color2. */ 58 79 QColor m_color2; 59 80 }; 60 81 61 #endif /* _QISplitter_h_ */82 #endif /* !___QISplitter_h___ */ 62 83
Note:
See TracChangeset
for help on using the changeset viewer.