1 | /* $Id: QIMainWindow.cpp 81255 2019-10-14 12:15:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - QIMainWindow class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2019 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 | /* Qt includes: */
|
---|
19 | #include <QResizeEvent>
|
---|
20 |
|
---|
21 | /* GUI includes: */
|
---|
22 | #include "QIMainWindow.h"
|
---|
23 | #ifdef VBOX_WS_MAC
|
---|
24 | # include "VBoxUtils-darwin.h"
|
---|
25 | #endif
|
---|
26 | #ifdef VBOX_WS_X11
|
---|
27 | # include "UICommon.h"
|
---|
28 | # include "UIDesktopWidgetWatchdog.h"
|
---|
29 | #endif
|
---|
30 |
|
---|
31 |
|
---|
32 | QIMainWindow::QIMainWindow(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = 0 */)
|
---|
33 | : QMainWindow(pParent, enmFlags)
|
---|
34 | {
|
---|
35 | }
|
---|
36 |
|
---|
37 | void QIMainWindow::moveEvent(QMoveEvent *pEvent)
|
---|
38 | {
|
---|
39 | /* Call to base-class: */
|
---|
40 | QMainWindow::moveEvent(pEvent);
|
---|
41 |
|
---|
42 | #ifdef VBOX_WS_X11
|
---|
43 | /* Prevent further handling if fake screen detected: */
|
---|
44 | if (gpDesktop->isFakeScreenDetected())
|
---|
45 | return;
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | /* Prevent handling for yet/already invisible window or if window is in minimized state: */
|
---|
49 | if (isVisible() && (windowState() & Qt::WindowMinimized) == 0)
|
---|
50 | {
|
---|
51 | #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
|
---|
52 | /* Use the old approach for OSX/Win: */
|
---|
53 | m_geometry.moveTo(frameGeometry().x(), frameGeometry().y());
|
---|
54 | #else
|
---|
55 | /* Use the new approach otherwise: */
|
---|
56 | m_geometry.moveTo(geometry().x(), geometry().y());
|
---|
57 | #endif
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | void QIMainWindow::resizeEvent(QResizeEvent *pEvent)
|
---|
62 | {
|
---|
63 | /* Call to base-class: */
|
---|
64 | QMainWindow::resizeEvent(pEvent);
|
---|
65 |
|
---|
66 | #ifdef VBOX_WS_X11
|
---|
67 | /* Prevent handling if fake screen detected: */
|
---|
68 | if (gpDesktop->isFakeScreenDetected())
|
---|
69 | return;
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | /* Prevent handling for yet/already invisible window or if window is in minimized state: */
|
---|
73 | if (isVisible() && (windowState() & Qt::WindowMinimized) == 0)
|
---|
74 | {
|
---|
75 | QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
|
---|
76 | m_geometry.setSize(pResizeEvent->size());
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | void QIMainWindow::restoreGeometry(const QRect &rect)
|
---|
81 | {
|
---|
82 | m_geometry = rect;
|
---|
83 | #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
|
---|
84 | /* Use the old approach for OSX/Win: */
|
---|
85 | move(m_geometry.topLeft());
|
---|
86 | resize(m_geometry.size());
|
---|
87 | #else
|
---|
88 | /* Use the new approach otherwise: */
|
---|
89 | UICommon::setTopLevelGeometry(this, m_geometry);
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | /* Maximize (if necessary): */
|
---|
93 | if (shouldBeMaximized())
|
---|
94 | showMaximized();
|
---|
95 | }
|
---|
96 |
|
---|
97 | QRect QIMainWindow::currentGeometry() const
|
---|
98 | {
|
---|
99 | return m_geometry;
|
---|
100 | }
|
---|
101 |
|
---|
102 | bool QIMainWindow::isCurrentlyMaximized() const
|
---|
103 | {
|
---|
104 | #ifdef VBOX_WS_MAC
|
---|
105 | return ::darwinIsWindowMaximized(this);
|
---|
106 | #else
|
---|
107 | return isMaximized();
|
---|
108 | #endif
|
---|
109 | }
|
---|