1 | /* $Id: QISplitter.cpp 103795 2024-03-11 19:36:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QISplitter class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QEvent>
|
---|
31 | #include <QPainter>
|
---|
32 | #include <QPaintEvent>
|
---|
33 |
|
---|
34 | /* GUI includes: */
|
---|
35 | #include "QISplitter.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | /** QSplitterHandle subclass representing flat line. */
|
---|
39 | class QIFlatSplitterHandle : public QSplitterHandle
|
---|
40 | {
|
---|
41 | Q_OBJECT;
|
---|
42 |
|
---|
43 | public:
|
---|
44 |
|
---|
45 | /** Constructs flat splitter handle passing @a enmOrientation and @a pParent to the base-class. */
|
---|
46 | QIFlatSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent);
|
---|
47 |
|
---|
48 | protected:
|
---|
49 |
|
---|
50 | /** Handles paint @a pEvent. */
|
---|
51 | virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
|
---|
52 | };
|
---|
53 |
|
---|
54 |
|
---|
55 | /*********************************************************************************************************************************
|
---|
56 | * Class QIFlatSplitterHandle implementation. *
|
---|
57 | *********************************************************************************************************************************/
|
---|
58 |
|
---|
59 | QIFlatSplitterHandle::QIFlatSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent)
|
---|
60 | : QSplitterHandle(enmOrientation, pParent)
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | void QIFlatSplitterHandle::paintEvent(QPaintEvent *pEvent)
|
---|
65 | {
|
---|
66 | /* Configure painter: */
|
---|
67 | QPainter painter(this);
|
---|
68 | painter.setClipRect(pEvent->rect());
|
---|
69 |
|
---|
70 | /* Choose color: */
|
---|
71 | const bool fActive = window() && window()->isActiveWindow();
|
---|
72 | QColor clr = QApplication::palette().color(fActive ? QPalette::Active : QPalette::Inactive, QPalette::Window).darker(130);
|
---|
73 |
|
---|
74 | /* Paint flat rect: */
|
---|
75 | painter.fillRect(rect(), clr);
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /*********************************************************************************************************************************
|
---|
80 | * Class QISplitter implementation. *
|
---|
81 | *********************************************************************************************************************************/
|
---|
82 |
|
---|
83 | QISplitter::QISplitter(Qt::Orientation enmOrientation /* = Qt::Horizontal */, QWidget *pParent /* = 0 */)
|
---|
84 | : QSplitter(enmOrientation, pParent)
|
---|
85 | , m_fPolished(false)
|
---|
86 | {
|
---|
87 | qApp->installEventFilter(this);
|
---|
88 | setHandleWidth(1);
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool QISplitter::eventFilter(QObject *pWatched, QEvent *pEvent)
|
---|
92 | {
|
---|
93 | /* Handles events for handle: */
|
---|
94 | if (pWatched == handle(1))
|
---|
95 | {
|
---|
96 | switch (pEvent->type())
|
---|
97 | {
|
---|
98 | /* Restore default position on double-click: */
|
---|
99 | case QEvent::MouseButtonDblClick:
|
---|
100 | restoreState(m_baseState);
|
---|
101 | break;
|
---|
102 | default:
|
---|
103 | break;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* Call to base-class: */
|
---|
108 | return QSplitter::eventFilter(pWatched, pEvent);
|
---|
109 | }
|
---|
110 |
|
---|
111 | void QISplitter::showEvent(QShowEvent *pEvent)
|
---|
112 | {
|
---|
113 | /* Remember default position: */
|
---|
114 | if (!m_fPolished)
|
---|
115 | {
|
---|
116 | m_fPolished = true;
|
---|
117 | m_baseState = saveState();
|
---|
118 | }
|
---|
119 |
|
---|
120 | /* Call to base-class: */
|
---|
121 | return QSplitter::showEvent(pEvent);
|
---|
122 | }
|
---|
123 |
|
---|
124 | QSplitterHandle *QISplitter::createHandle()
|
---|
125 | {
|
---|
126 | return new QIFlatSplitterHandle(orientation(), this);
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | #include "QISplitter.moc"
|
---|