- Timestamp:
- Dec 5, 2023 2:56:51 PM (10 months ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 4 edited
-
extensions/QISplitter.cpp (modified) (6 diffs)
-
extensions/QISplitter.h (modified) (2 diffs)
-
manager/UIVirtualBoxManagerWidget.cpp (modified) (2 diffs)
-
settings/editors/UIStorageSettingsEditor.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.cpp
r102478 r102479 49 49 QIFlatSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent); 50 50 51 /** Defines @a color. */52 void configureColor(const QColor &color);53 54 protected:55 56 /** Handles paint @a pEvent. */57 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;58 59 private:60 61 /** Holds the main color. */62 QColor m_color;63 };64 65 66 /** QSplitterHandle subclass representing shaded line. */67 class QIShadeSplitterHandle : public QSplitterHandle68 {69 Q_OBJECT;70 71 public:72 73 /** Constructs shaded splitter handle passing @a enmOrientation and @a pParent to the base-class. */74 QIShadeSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent);75 76 /** Defines colors to passed @a color1 and @a color2. */77 void configureColors(const QColor &color1, const QColor &color2);78 79 protected:80 81 /** Handles paint @a pEvent. */82 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;83 84 private:85 86 /** Holds the main color. */87 QColor m_color;88 /** Holds the color1. */89 QColor m_color1;90 /** Holds the color2. */91 QColor m_color2;92 };93 94 95 #ifdef VBOX_WS_MAC96 /** QSplitterHandle subclass representing shaded line for macOS. */97 class QIDarwinSplitterHandle : public QSplitterHandle98 {99 Q_OBJECT;100 101 public:102 103 /** Constructs shaded splitter handle passing @a enmOrientation and @a pParent to the base-class. */104 QIDarwinSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent);105 106 /** Returns size-hint. */107 QSize sizeHint() const;108 109 51 protected: 110 52 … … 112 54 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE; 113 55 }; 114 #endif /* VBOX_WS_MAC */115 56 116 57 … … 124 65 } 125 66 126 void QIFlatSplitterHandle::configureColor(const QColor &color)127 {128 m_color = color;129 update();130 }131 132 67 void QIFlatSplitterHandle::paintEvent(QPaintEvent *pEvent) 133 68 { 69 /* Configure painter: */ 134 70 QPainter painter(this); 135 painter.fillRect(pEvent->rect(), m_color); 71 painter.setClipRect(pEvent->rect()); 72 73 /* Choose color: */ 74 const bool fActive = window() && window()->isActiveWindow(); 75 QColor clr = QApplication::palette().color(fActive ? QPalette::Active : QPalette::Inactive, QPalette::Window).darker(130); 76 77 /* Paint flat rect: */ 78 painter.fillRect(rect(), clr); 136 79 } 137 138 139 /*********************************************************************************************************************************140 * Class QIShadeSplitterHandle implementation. *141 *********************************************************************************************************************************/142 143 QIShadeSplitterHandle::QIShadeSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent)144 : QSplitterHandle(enmOrientation, pParent)145 {146 QColor windowColor = QApplication::palette().color(QPalette::Active, QPalette::Window);147 QColor frameColor = QApplication::palette().color(QPalette::Active, QPalette::Text);148 frameColor.setAlpha(100);149 m_color1 = windowColor;150 m_color2 = windowColor;151 m_color = frameColor;152 }153 154 void QIShadeSplitterHandle::configureColors(const QColor &color1, const QColor &color2)155 {156 m_color1 = color1;157 m_color2 = color2;158 update();159 }160 161 void QIShadeSplitterHandle::paintEvent(QPaintEvent *pEvent)162 {163 QPainter painter(this);164 QLinearGradient gradient;165 QGradientStop point1(0, m_color1);166 QGradientStop point2(0.5, m_color);167 QGradientStop point3(1, m_color2);168 QGradientStops stops;169 stops << point1 << point2 << point3;170 gradient.setStops(stops);171 if (orientation() == Qt::Horizontal)172 {173 gradient.setStart(rect().left() + 1, 0);174 gradient.setFinalStop(rect().right(), 0);175 }176 else177 {178 gradient.setStart(0, rect().top() + 1);179 gradient.setFinalStop(0, rect().bottom());180 }181 painter.fillRect(pEvent->rect(), gradient);182 }183 184 185 /*********************************************************************************************************************************186 * Class QIDarwinSplitterHandle implementation. *187 *********************************************************************************************************************************/188 189 #ifdef VBOX_WS_MAC190 191 QIDarwinSplitterHandle::QIDarwinSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent)192 : QSplitterHandle(enmOrientation, pParent)193 {194 }195 196 QSize QIDarwinSplitterHandle::sizeHint() const197 {198 QSize parent = QSplitterHandle::sizeHint();199 if (orientation() == Qt::Vertical)200 return parent + QSize(0, 3);201 else202 return QSize(1, parent.height());203 }204 205 void QIDarwinSplitterHandle::paintEvent(QPaintEvent *)206 {207 QPainter painter(this);208 209 QColor topColor(145, 145, 145);210 QColor bottomColor(142, 142, 142);211 QColor gradientStart(252, 252, 252);212 QColor gradientStop(223, 223, 223);213 214 if (orientation() == Qt::Vertical)215 {216 painter.setPen(topColor);217 painter.drawLine(0, 0, width(), 0);218 painter.setPen(bottomColor);219 painter.drawLine(0, height() - 1, width(), height() - 1);220 221 QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, height() -3));222 linearGrad.setColorAt(0, gradientStart);223 linearGrad.setColorAt(1, gradientStop);224 painter.fillRect(QRect(QPoint(0,1), size() - QSize(0, 2)), QBrush(linearGrad));225 }226 else227 {228 painter.setPen(topColor);229 painter.drawLine(0, 0, 0, height());230 }231 }232 233 #endif /* VBOX_WS_MAC */234 80 235 81 … … 240 86 QISplitter::QISplitter(Qt::Orientation enmOrientation /* = Qt::Horizontal */, QWidget *pParent /* = 0 */) 241 87 : QSplitter(enmOrientation, pParent) 242 , m_enmType(Shade)243 88 , m_fPolished(false) 244 #ifdef VBOX_WS_MAC245 , m_fHandleGrabbed(false)246 #endif247 89 { 248 90 qApp->installEventFilter(this); 249 } 250 251 QISplitter::QISplitter(Type enmType, Qt::Orientation enmOrientation /* = Qt::Horizontal */, QWidget *pParent /* = 0 */) 252 : QSplitter(enmOrientation, pParent) 253 , m_enmType(enmType) 254 , m_fPolished(false) 255 #ifdef VBOX_WS_MAC 256 , m_fHandleGrabbed(false) 257 #endif 258 { 259 qApp->installEventFilter(this); 260 } 261 262 void QISplitter::configureColor(const QColor &color) 263 { 264 m_color = color; 265 for (int i = 1; i < count(); ++i) 266 { 267 QIFlatSplitterHandle *pHandle = qobject_cast<QIFlatSplitterHandle*>(handle(i)); 268 if (pHandle && m_color.isValid()) 269 pHandle->configureColor(m_color); 270 } 271 } 272 273 void QISplitter::configureColors(const QColor &color1, const QColor &color2) 274 { 275 m_color1 = color1; m_color2 = color2; 276 for (int i = 1; i < count(); ++i) 277 { 278 QIShadeSplitterHandle *pHandle = qobject_cast<QIShadeSplitterHandle*>(handle(i)); 279 if (pHandle && m_color1.isValid() && m_color2.isValid()) 280 pHandle->configureColors(m_color1, m_color2); 281 } 91 setHandleWidth(1); 282 92 } 283 93 … … 297 107 } 298 108 } 299 300 #ifdef VBOX_WS_MAC301 // WORKAROUND:302 // Special handling on the Mac. Cause there the horizontal handle is only 1303 // pixel wide, its hard to catch. Therefor we make some invisible area304 // around the handle and forwarding the mouse events to the handle, if the305 // user presses the left mouse button.306 else if ( m_enmType == Native307 && orientation() == Qt::Horizontal308 && count() > 1309 && qApp->activeWindow() == window())310 {311 switch (pEvent->type())312 {313 case QEvent::MouseButtonPress:314 case QEvent::MouseMove:315 {316 const int margin = 3;317 QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent);318 const QPoint gPos = pMouseEvent->globalPosition().toPoint();319 for (int i=1; i < count(); ++i)320 {321 QWidget *pHandle = handle(i);322 if ( pHandle323 && pHandle != pWatched)324 {325 /* Check if we hit the handle */326 bool fMarginHit = QRect(pHandle->mapToGlobal(QPoint(0, 0)), pHandle->size()).adjusted(-margin, 0, margin, 0).contains(gPos);327 if (pEvent->type() == QEvent::MouseButtonPress)328 {329 /* If we have a handle position hit and the left button is pressed, start the grabbing. */330 if ( fMarginHit331 && pMouseEvent->buttons().testFlag(Qt::LeftButton))332 {333 m_fHandleGrabbed = true;334 UICursor::setCursor(this, Qt::SplitHCursor);335 qApp->postEvent(pHandle, new QMouseEvent(pMouseEvent->type(),336 pHandle->mapFromGlobal(gPos),337 pMouseEvent->button(),338 pMouseEvent->buttons(),339 pMouseEvent->modifiers()));340 return true;341 }342 }343 else if (pEvent->type() == QEvent::MouseMove)344 {345 /* If we are in the near of the handle or currently dragging, forward the mouse event. */346 if ( fMarginHit347 || ( m_fHandleGrabbed348 && pMouseEvent->buttons().testFlag(Qt::LeftButton)))349 {350 UICursor::setCursor(this, Qt::SplitHCursor);351 qApp->postEvent(pHandle, new QMouseEvent(pMouseEvent->type(),352 pHandle->mapFromGlobal(gPos),353 pMouseEvent->button(),354 pMouseEvent->buttons(),355 pMouseEvent->modifiers()));356 return true;357 }358 359 /* If not, reset the state. */360 m_fHandleGrabbed = false;361 UICursor::setCursor(this, Qt::ArrowCursor);362 }363 }364 }365 break;366 }367 case QEvent::WindowDeactivate:368 case QEvent::MouseButtonRelease:369 {370 m_fHandleGrabbed = false;371 UICursor::setCursor(this, Qt::ArrowCursor);372 break;373 }374 default:375 break;376 }377 }378 #endif /* VBOX_WS_MAC */379 109 380 110 /* Call to base-class: */ … … 397 127 QSplitterHandle *QISplitter::createHandle() 398 128 { 399 /* Create native handle: */ 400 switch (m_enmType) 401 { 402 case Flat: 403 { 404 QIFlatSplitterHandle *pHandle = new QIFlatSplitterHandle(orientation(), this); 405 if (m_color.isValid()) 406 pHandle->configureColor(m_color); 407 return pHandle; 408 } 409 case Shade: 410 { 411 QIShadeSplitterHandle *pHandle = new QIShadeSplitterHandle(orientation(), this); 412 if (m_color1.isValid() && m_color2.isValid()) 413 pHandle->configureColors(m_color1, m_color2); 414 return pHandle; 415 } 416 case Native: 417 { 418 #ifdef VBOX_WS_MAC 419 return new QIDarwinSplitterHandle(orientation(), this); 420 #else 421 return new QSplitterHandle(orientation(), this); 422 #endif 423 } 424 } 425 return 0; 129 return new QIFlatSplitterHandle(orientation(), this); 426 130 } 427 131 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.h
r102478 r102479 48 48 public: 49 49 50 /** Handle types. */51 enum Type { Flat, Shade, Native };52 53 50 /** Constructs splitter passing @a enmOrientation and @a pParent to the base-class. */ 54 51 QISplitter(Qt::Orientation enmOrientation = Qt::Horizontal, QWidget *pParent = 0); 55 /** Constructs splitter passing @a enmOrientation and @a pParent to the base-class.56 * @param enmType Brings the splitter handle type. */57 QISplitter(Type enmType, Qt::Orientation enmOrientation = Qt::Horizontal, QWidget *pParent = 0);58 59 /** Configure custom color defined as @a color. */60 void configureColor(const QColor &color);61 /** Configure custom colors defined as @a color1 and @a color2. */62 void configureColors(const QColor &color1, const QColor &color2);63 52 64 53 protected: … … 68 57 69 58 /** Handles show @a pEvent. */ 70 v oid showEvent(QShowEvent *pEvent);59 virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE; 71 60 72 /** Creates handle. */73 QSplitterHandle *createHandle();61 /** Creates a handle. */ 62 virtual QSplitterHandle *createHandle() RT_OVERRIDE; 74 63 75 64 private: 76 65 77 66 /** Holds the serialized base-state. */ 78 QByteArray m_baseState; 79 80 /** Holds the handle type. */ 81 Type m_enmType; 67 QByteArray m_baseState; 82 68 83 69 /** Holds whether the splitter is polished. */ 84 bool m_fPolished : 1; 85 #ifdef VBOX_WS_MAC 86 /** Holds whether handle is grabbed. */ 87 bool m_fHandleGrabbed : 1; 88 #endif 70 bool m_fPolished; 89 71 90 /** Holds color. */ 91 QColor m_color; 92 /** Holds color1. */ 93 QColor m_color1; 94 /** Holds color2. */ 95 QColor m_color2; 72 /** Holds the handle color. */ 73 QColor m_color; 96 74 }; 97 75 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp
r102478 r102479 652 652 653 653 /* Create splitter: */ 654 m_pSplitter = new QISplitter (QISplitter::Flat);654 m_pSplitter = new QISplitter; 655 655 if (m_pSplitter) 656 656 { 657 /* Configure splitter: */658 m_pSplitter->setHandleWidth(1);659 660 657 /* Create Chooser-pane: */ 661 658 m_pPaneChooser = new UIChooser(this, actionPool()); … … 768 765 } 769 766 770 /* Adjust splitter colors according to main widgets it splits: */771 m_pSplitter->configureColor(QApplication::palette().color(QPalette::Active, QPalette::Window).darker(130));772 767 /* Set the initial distribution. The right site is bigger. */ 773 768 m_pSplitter->setStretchFactor(0, 2); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIStorageSettingsEditor.cpp
r102478 r102479 4387 4387 pLayout->setContentsMargins(0, 0, 0, 0); 4388 4388 4389 /* Create splitter: */4389 /* Prepare splitter: */ 4390 4390 m_pSplitter = new QISplitter; 4391 4391 if (m_pSplitter) 4392 4392 { 4393 4393 m_pSplitter->setChildrenCollapsible(false); 4394 m_pSplitter->setOrientation(Qt::Horizontal);4395 m_pSplitter->setHandleWidth(4);4396 4394 4397 4395 /* Prepare panes: */
Note:
See TracChangeset
for help on using the changeset viewer.

