1 | /* $Id: UIMiniToolBar.h 100064 2023-06-04 09:10:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMiniToolBar class declaration.
|
---|
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 | #ifndef FEQT_INCLUDED_SRC_widgets_UIMiniToolBar_h
|
---|
29 | #define FEQT_INCLUDED_SRC_widgets_UIMiniToolBar_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* GUI includes: */
|
---|
35 | #include "QIToolBar.h"
|
---|
36 |
|
---|
37 | /* Forward declarations: */
|
---|
38 | class QMenu;
|
---|
39 | class QTimer;
|
---|
40 | class QLabel;
|
---|
41 | class UIAnimation;
|
---|
42 | class UIMiniToolBarPrivate;
|
---|
43 |
|
---|
44 | /** Geometry types. */
|
---|
45 | enum GeometryType
|
---|
46 | {
|
---|
47 | GeometryType_Available,
|
---|
48 | GeometryType_Full
|
---|
49 | };
|
---|
50 |
|
---|
51 |
|
---|
52 | /** QWidget reimplementation
|
---|
53 | * providing GUI with slideable mini-toolbar used in full-screen/seamless modes. */
|
---|
54 | class UIMiniToolBar : public QWidget
|
---|
55 | {
|
---|
56 | Q_OBJECT;
|
---|
57 | Q_PROPERTY(QPoint toolbarPosition READ toolbarPosition WRITE setToolbarPosition);
|
---|
58 | Q_PROPERTY(QPoint hiddenToolbarPosition READ hiddenToolbarPosition);
|
---|
59 | Q_PROPERTY(QPoint shownToolbarPosition READ shownToolbarPosition);
|
---|
60 |
|
---|
61 | signals:
|
---|
62 |
|
---|
63 | /** Notifies listeners about action triggered to minimize. */
|
---|
64 | void sigMinimizeAction();
|
---|
65 | /** Notifies listeners about action triggered to exit. */
|
---|
66 | void sigExitAction();
|
---|
67 | /** Notifies listeners about action triggered to close. */
|
---|
68 | void sigCloseAction();
|
---|
69 |
|
---|
70 | /** Notifies listeners about we are hovered. */
|
---|
71 | void sigHoverEnter();
|
---|
72 | /** Notifies listeners about we are unhovered. */
|
---|
73 | void sigHoverLeave();
|
---|
74 |
|
---|
75 | /** Notifies listeners about we stole window activation. */
|
---|
76 | void sigNotifyAboutWindowActivationStolen();
|
---|
77 |
|
---|
78 | /** Notifies listeners about auto-hide toggled.
|
---|
79 | * @param fEnabled Brings whether auto-hide is enabled. */
|
---|
80 | void sigAutoHideToggled(bool fEnabled);
|
---|
81 |
|
---|
82 | public:
|
---|
83 |
|
---|
84 | /** Proposes default set of window flags for particular platform. */
|
---|
85 | static Qt::WindowFlags defaultWindowFlags(GeometryType geometryType);
|
---|
86 |
|
---|
87 | /** Constructor, passes @a pParent to the QWidget constructor.
|
---|
88 | * @param geometryType determines the geometry type,
|
---|
89 | * @param alignment determines the alignment type,
|
---|
90 | * @param fAutoHide determines whether we should auto-hide.
|
---|
91 | * @param iWindowIndex determines the parent window index. */
|
---|
92 | UIMiniToolBar(QWidget *pParent,
|
---|
93 | GeometryType geometryType,
|
---|
94 | Qt::Alignment alignment,
|
---|
95 | bool fAutoHide = true,
|
---|
96 | int iWindowIndex = -1);
|
---|
97 | /** Destructor. */
|
---|
98 | ~UIMiniToolBar();
|
---|
99 |
|
---|
100 | /** Defines @a alignment. */
|
---|
101 | void setAlignment(Qt::Alignment alignment);
|
---|
102 |
|
---|
103 | /** Returns whether internal widget do auto-hide. */
|
---|
104 | bool autoHide() const { return m_fAutoHide; }
|
---|
105 | /** Defines whether internal widget do @a fAutoHide.
|
---|
106 | * @param fPropagateToChild determines should we propagate defined
|
---|
107 | * option value to internal widget. */
|
---|
108 | void setAutoHide(bool fAutoHide, bool fPropagateToChild = true);
|
---|
109 |
|
---|
110 | /** Defines @a strText for internal widget. */
|
---|
111 | void setText(const QString &strText);
|
---|
112 |
|
---|
113 | /** Adds @a menus to internal widget. */
|
---|
114 | void addMenus(const QList<QMenu*> &menus);
|
---|
115 |
|
---|
116 | /** Adjusts geometry. */
|
---|
117 | void adjustGeometry();
|
---|
118 |
|
---|
119 | protected:
|
---|
120 |
|
---|
121 | /** Filters @a pEvent if <i>this</i> object has been
|
---|
122 | * installed as an event-filter for the @a pWatched. */
|
---|
123 | virtual bool eventFilter(QObject *pWatched, QEvent *pEvent) RT_OVERRIDE;
|
---|
124 |
|
---|
125 | /** Resize @a pEvent handler. */
|
---|
126 | virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
|
---|
127 |
|
---|
128 | /** Mouse enter @a pEvent handler. */
|
---|
129 | #ifdef VBOX_IS_QT6_OR_LATER /* QWidget::enterEvent uses QEnterEvent since qt6 */
|
---|
130 | virtual void enterEvent(QEnterEvent *pEvent) RT_OVERRIDE;
|
---|
131 | #else
|
---|
132 | virtual void enterEvent(QEvent *pEvent) RT_OVERRIDE;
|
---|
133 | #endif
|
---|
134 | /** Mouse leave @a pEvent handler. */
|
---|
135 | virtual void leaveEvent(QEvent *pEvent) RT_OVERRIDE;
|
---|
136 |
|
---|
137 | private slots:
|
---|
138 |
|
---|
139 | /** Handles internal widget resize event. */
|
---|
140 | void sltHandleToolbarResize();
|
---|
141 |
|
---|
142 | /** Handles internal widget auto-hide toggling. */
|
---|
143 | void sltAutoHideToggled();
|
---|
144 |
|
---|
145 | /** Handles hovering. */
|
---|
146 | void sltHoverEnter();
|
---|
147 | /** Handles unhovering. */
|
---|
148 | void sltHoverLeave();
|
---|
149 |
|
---|
150 | /** Check whether we still have window activation token. */
|
---|
151 | void sltCheckWindowActivationSanity();
|
---|
152 |
|
---|
153 | /** Hides window. */
|
---|
154 | void sltHide();
|
---|
155 | /** Shows and adjusts window according to parent. */
|
---|
156 | void sltShow();
|
---|
157 | /** Adjusts window according to parent. */
|
---|
158 | void sltAdjust();
|
---|
159 | /** Adjusts window transience according to parent. */
|
---|
160 | void sltAdjustTransience();
|
---|
161 |
|
---|
162 | private:
|
---|
163 |
|
---|
164 | /** Prepare routine. */
|
---|
165 | void prepare();
|
---|
166 | /** Cleanup routine. */
|
---|
167 | void cleanup();
|
---|
168 |
|
---|
169 | /** Simulates auto-hide animation. */
|
---|
170 | void simulateToolbarAutoHiding();
|
---|
171 |
|
---|
172 | /** Defines internal widget @a position. */
|
---|
173 | void setToolbarPosition(QPoint position);
|
---|
174 | /** Returns internal widget position. */
|
---|
175 | QPoint toolbarPosition() const;
|
---|
176 | /** Returns internal widget position when it's hidden. */
|
---|
177 | QPoint hiddenToolbarPosition() const { return m_hiddenToolbarPosition; }
|
---|
178 | /** Returns internal widget position when it's shown. */
|
---|
179 | QPoint shownToolbarPosition() const { return m_shownToolbarPosition; }
|
---|
180 |
|
---|
181 | /** Returns whether the parent is currently minimized. */
|
---|
182 | bool isParentMinimized() const;
|
---|
183 |
|
---|
184 | /** Holds the parent reference. */
|
---|
185 | QWidget *m_pParent;
|
---|
186 |
|
---|
187 | /** Holds the geometry type. */
|
---|
188 | const GeometryType m_geometryType;
|
---|
189 | /** Holds the alignment type. */
|
---|
190 | Qt::Alignment m_alignment;
|
---|
191 | /** Holds whether we should auto-hide. */
|
---|
192 | bool m_fAutoHide;
|
---|
193 | /** Holds the parent window index. */
|
---|
194 | int m_iWindowIndex;
|
---|
195 |
|
---|
196 | /** Holds the area. */
|
---|
197 | QWidget *m_pArea;
|
---|
198 | /** Holds the internal widget. */
|
---|
199 | UIMiniToolBarPrivate *m_pToolbar;
|
---|
200 |
|
---|
201 | /** Holds whether we are hovered. */
|
---|
202 | bool m_fHovered;
|
---|
203 | /** Holds the hover timer. */
|
---|
204 | QTimer *m_pHoverEnterTimer;
|
---|
205 | /** Holds the unhover timer. */
|
---|
206 | QTimer *m_pHoverLeaveTimer;
|
---|
207 | /** Holds the internal widget position when it's hidden. */
|
---|
208 | QPoint m_hiddenToolbarPosition;
|
---|
209 | /** Holds the internal widget position when it's shown. */
|
---|
210 | QPoint m_shownToolbarPosition;
|
---|
211 | /** Holds the animation framework object. */
|
---|
212 | UIAnimation *m_pAnimation;
|
---|
213 |
|
---|
214 | #ifdef VBOX_WS_NIX
|
---|
215 | /** X11: Holds whether the parent is currently minimized.
|
---|
216 | * Used to restore the full-screen/maximized state
|
---|
217 | * when the parent restored again. */
|
---|
218 | bool m_fIsParentMinimized;
|
---|
219 | #endif
|
---|
220 | };
|
---|
221 |
|
---|
222 | #endif /* !FEQT_INCLUDED_SRC_widgets_UIMiniToolBar_h */
|
---|
223 |
|
---|