VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.h@ 74942

Last change on this file since 74942 was 71630, checked in by vboxsync, 6 years ago

FE/Qt: bugref:9049: Initial commit for VBoxGlobal library (for now it works on X11 only).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/* $Id: UIDesktopWidgetWatchdog.h 71630 2018-04-03 16:37:08Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDesktopWidgetWatchdog class declaration.
4 */
5
6/*
7 * Copyright (C) 2015-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___UIDesktopWidgetWatchdog_h___
19#define ___UIDesktopWidgetWatchdog_h___
20
21/* Qt includes: */
22#include <QObject>
23#ifdef VBOX_WS_X11
24# include <QVector>
25# include <QRect>
26#endif
27
28/* GUI includes: */
29#include "UILibraryDefs.h"
30
31/* Forward declarations: */
32class QScreen;
33
34/** Singleton QObject extension used as desktop-widget
35 * watchdog aware of the host-screen geometry changes. */
36class SHARED_LIBRARY_STUFF UIDesktopWidgetWatchdog : public QObject
37{
38 Q_OBJECT;
39
40 /** Constructs desktop-widget watchdog. */
41 UIDesktopWidgetWatchdog();
42 /** Destructs desktop-widget watchdog. */
43 ~UIDesktopWidgetWatchdog();
44
45signals:
46
47 /** Notifies about host-screen count change to @a cHostScreenCount. */
48 void sigHostScreenCountChanged(int cHostScreenCount);
49
50 /** Notifies about resize for the host-screen with @a iHostScreenIndex. */
51 void sigHostScreenResized(int iHostScreenIndex);
52
53 /** Notifies about work-area resize for the host-screen with @a iHostScreenIndex. */
54 void sigHostScreenWorkAreaResized(int iHostScreenIndex);
55
56#ifdef VBOX_WS_X11
57 /** Notifies about work-area recalculated for the host-screen with @a iHostScreenIndex. */
58 void sigHostScreenWorkAreaRecalculated(int iHostScreenIndex);
59#endif
60
61public:
62
63 /** Returns the static instance of the desktop-widget watchdog. */
64 static UIDesktopWidgetWatchdog *instance() { return s_pInstance; }
65
66 /** Creates the static instance of the desktop-widget watchdog. */
67 static void create();
68 /** Destroys the static instance of the desktop-widget watchdog. */
69 static void destroy();
70
71 /** Returns overall desktop width. */
72 int overallDesktopWidth() const;
73 /** Returns overall desktop height. */
74 int overallDesktopHeight() const;
75
76 /** Returns the number of host-screens currently available on the system. */
77 int screenCount() const;
78
79 /** Returns the index of the screen which contains contains @a pWidget. */
80 int screenNumber(const QWidget *pWidget) const;
81 /** Returns the index of the screen which contains contains @a point. */
82 int screenNumber(const QPoint &point) const;
83
84 /** Returns the geometry of the host-screen with @a iHostScreenIndex.
85 * @note The default screen is used if @a iHostScreenIndex is -1. */
86 const QRect screenGeometry(int iHostScreenIndex = -1) const;
87 /** Returns the geometry of the host-screen which contains @a pWidget. */
88 const QRect screenGeometry(const QWidget *pWidget) const;
89 /** Returns the geometry of the host-screen which contains @a point. */
90 const QRect screenGeometry(const QPoint &point) const;
91
92 /** Returns the available-geometry of the host-screen with @a iHostScreenIndex.
93 * @note The default screen is used if @a iHostScreenIndex is -1. */
94 const QRect availableGeometry(int iHostScreenIndex = -1) const;
95 /** Returns the available-geometry of the host-screen which contains @a pWidget. */
96 const QRect availableGeometry(const QWidget *pWidget) const;
97 /** Returns the available-geometry of the host-screen which contains @a point. */
98 const QRect availableGeometry(const QPoint &point) const;
99
100 /** Returns overall region unifying all the host-screen geometries. */
101 const QRegion overallScreenRegion() const;
102 /** Returns overall region unifying all the host-screen available-geometries. */
103 const QRegion overallAvailableRegion() const;
104
105#ifdef VBOX_WS_X11
106 /** Qt5: X11: Returns whether no or fake screen detected. */
107 bool isFakeScreenDetected() const;
108#endif
109
110 /** Returns device-pixel-ratio of the host-screen with @a iHostScreenIndex. */
111 double devicePixelRatio(int iHostScreenIndex = -1);
112 /** Returns device-pixel-ratio of the host-screen which contains @a pWidget. */
113 double devicePixelRatio(QWidget *pWidget);
114
115 /** Returns actual device-pixel-ratio of the host-screen with @a iHostScreenIndex. */
116 double devicePixelRatioActual(int iHostScreenIndex = -1);
117 /** Returns actual device-pixel-ratio of the host-screen which contains @a pWidget. */
118 double devicePixelRatioActual(QWidget *pWidget);
119
120private slots:
121
122#if QT_VERSION == 0
123 /** Stupid moc does not warn if it cannot find headers! */
124 void QT_VERSION_NOT_DEFINED
125#else /* QT_VERSION != 0 */
126 /** Handles @a pHostScreen adding. */
127 void sltHostScreenAdded(QScreen *pHostScreen);
128 /** Handles @a pHostScreen removing. */
129 void sltHostScreenRemoved(QScreen *pHostScreen);
130 /** Handles host-screen resize to passed @a geometry. */
131 void sltHandleHostScreenResized(const QRect &geometry);
132 /** Handles host-screen work-area resize to passed @a availableGeometry. */
133 void sltHandleHostScreenWorkAreaResized(const QRect &availableGeometry);
134#endif /* QT_VERSION != 0 */
135
136#ifdef VBOX_WS_X11
137 /** Handles @a availableGeometry calculation result for the host-screen with @a iHostScreenIndex. */
138 void sltHandleHostScreenAvailableGeometryCalculated(int iHostScreenIndex, QRect availableGeometry);
139#endif
140
141private:
142
143 /** Prepare routine. */
144 void prepare();
145 /** Cleanup routine. */
146 void cleanup();
147
148 /** Holds the static instance of the desktop-widget watchdog. */
149 static UIDesktopWidgetWatchdog *s_pInstance;
150
151#ifdef VBOX_WS_X11
152 /** Updates host-screen configuration according to new @a cHostScreenCount.
153 * @note If cHostScreenCount is equal to -1 we have to acquire it ourselves. */
154 void updateHostScreenConfiguration(int cHostScreenCount = -1);
155
156 /** Update available-geometry for the host-screen with @a iHostScreenIndex. */
157 void updateHostScreenAvailableGeometry(int iHostScreenIndex);
158
159 /** Cleanups existing workers. */
160 void cleanupExistingWorkers();
161
162 /** Holds current host-screen available-geometries. */
163 QVector<QRect> m_availableGeometryData;
164 /** Holds current workers determining host-screen available-geometries. */
165 QVector<QWidget*> m_availableGeometryWorkers;
166#endif /* VBOX_WS_X11 */
167};
168
169/** 'Official' name for the desktop-widget watchdog singleton. */
170#define gpDesktop UIDesktopWidgetWatchdog::instance()
171
172#endif /* !___UIDesktopWidgetWatchdog_h___ */
173
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use