1 | /* $Id: UIMachineLogicScale.cpp 30848 2010-07-14 17:06:55Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMachineLogicScale class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Local includes */
|
---|
21 | #include "COMDefs.h"
|
---|
22 | #include "VBoxGlobal.h"
|
---|
23 | #include "VBoxProblemReporter.h"
|
---|
24 |
|
---|
25 | #include "UISession.h"
|
---|
26 | #include "UIActionsPool.h"
|
---|
27 | #include "UIMachineLogicScale.h"
|
---|
28 | #include "UIMachineWindow.h"
|
---|
29 | #include "UIDownloaderAdditions.h"
|
---|
30 |
|
---|
31 | #ifdef Q_WS_MAC
|
---|
32 | #include "VBoxUtils.h"
|
---|
33 | #endif /* Q_WS_MAC */
|
---|
34 |
|
---|
35 | UIMachineLogicScale::UIMachineLogicScale(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
|
---|
36 | : UIMachineLogic(pParent, pSession, pActionsPool, UIVisualStateType_Scale)
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | UIMachineLogicScale::~UIMachineLogicScale()
|
---|
41 | {
|
---|
42 | #ifdef Q_WS_MAC
|
---|
43 | /* Cleanup the dock stuff before the machine window(s): */
|
---|
44 | cleanupDock();
|
---|
45 | #endif /* Q_WS_MAC */
|
---|
46 |
|
---|
47 | /* Cleanup machine window(s): */
|
---|
48 | cleanupMachineWindow();
|
---|
49 |
|
---|
50 | /* Cleanup handlers: */
|
---|
51 | cleanupHandlers();
|
---|
52 | }
|
---|
53 |
|
---|
54 | void UIMachineLogicScale::initialize()
|
---|
55 | {
|
---|
56 | /* Prepare required features: */
|
---|
57 | prepareRequiredFeatures();
|
---|
58 |
|
---|
59 | /* Prepare session connections: */
|
---|
60 | prepareSessionConnections();
|
---|
61 |
|
---|
62 | /* Prepare action groups:
|
---|
63 | * Note: This has to be done before prepareActionConnections
|
---|
64 | * cause here actions/menus are recreated. */
|
---|
65 | prepareActionGroups();
|
---|
66 |
|
---|
67 | /* Prepare action connections: */
|
---|
68 | prepareActionConnections();
|
---|
69 |
|
---|
70 | /* Prepare handlers: */
|
---|
71 | prepareHandlers();
|
---|
72 |
|
---|
73 | /* Prepare scale machine window: */
|
---|
74 | prepareMachineWindows();
|
---|
75 |
|
---|
76 | /* If there is an Additions download running, update the parent window
|
---|
77 | * information. */
|
---|
78 | if (UIDownloaderAdditions *pDl = UIDownloaderAdditions::current())
|
---|
79 | pDl->setParentWidget(mainMachineWindow()->machineWindow());
|
---|
80 |
|
---|
81 | #ifdef Q_WS_MAC
|
---|
82 | /* Prepare dock: */
|
---|
83 | prepareDock();
|
---|
84 | #endif /* Q_WS_MAC */
|
---|
85 |
|
---|
86 | /* Power up machine: */
|
---|
87 | uisession()->powerUp();
|
---|
88 |
|
---|
89 | /* Initialization: */
|
---|
90 | sltMachineStateChanged();
|
---|
91 | sltAdditionsStateChanged();
|
---|
92 | sltMouseCapabilityChanged();
|
---|
93 |
|
---|
94 | /* Retranslate logic part: */
|
---|
95 | retranslateUi();
|
---|
96 | }
|
---|
97 |
|
---|
98 | void UIMachineLogicScale::prepareActionGroups()
|
---|
99 | {
|
---|
100 | /* Base class action groups: */
|
---|
101 | UIMachineLogic::prepareActionGroups();
|
---|
102 |
|
---|
103 | /* Guest auto-resize isn't allowed in scale-mode: */
|
---|
104 | actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setVisible(false);
|
---|
105 |
|
---|
106 | /* Adjust-window isn't allowed in scale-mode: */
|
---|
107 | actionsPool()->action(UIActionIndex_Simple_AdjustWindow)->setVisible(false);
|
---|
108 | }
|
---|
109 |
|
---|
110 | void UIMachineLogicScale::prepareMachineWindows()
|
---|
111 | {
|
---|
112 | /* Do not create window(s) if they created already: */
|
---|
113 | if (isMachineWindowsCreated())
|
---|
114 | return;
|
---|
115 |
|
---|
116 | #ifdef Q_WS_MAC // TODO: Is that really need here?
|
---|
117 | /* We have to make sure that we are getting the front most process.
|
---|
118 | * This is necessary for Qt versions > 4.3.3: */
|
---|
119 | ::darwinSetFrontMostProcess();
|
---|
120 | #endif /* Q_WS_MAC */
|
---|
121 |
|
---|
122 | /* Get monitors count: */
|
---|
123 | ulong uMonitorCount = session().GetMachine().GetMonitorCount();
|
---|
124 | /* Create machine window(s): */
|
---|
125 | for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
|
---|
126 | addMachineWindow(UIMachineWindow::create(this, visualStateType(), uScreenId));
|
---|
127 | /* Order machine window(s): */
|
---|
128 | for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
|
---|
129 | machineWindows()[uScreenId - 1]->machineWindow()->raise();
|
---|
130 |
|
---|
131 | /* Remember what machine window(s) created: */
|
---|
132 | setMachineWindowsCreated(true);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void UIMachineLogicScale::cleanupMachineWindow()
|
---|
136 | {
|
---|
137 | /* Do not cleanup machine window(s) if not present: */
|
---|
138 | if (!isMachineWindowsCreated())
|
---|
139 | return;
|
---|
140 |
|
---|
141 | /* Cleanup machine window(s): */
|
---|
142 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
143 | UIMachineWindow::destroy(pMachineWindow);
|
---|
144 | }
|
---|
145 |
|
---|
146 | void UIMachineLogicScale::cleanupActionGroups()
|
---|
147 | {
|
---|
148 | /* Reenable guest-autoresize action: */
|
---|
149 | actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setVisible(true);
|
---|
150 |
|
---|
151 | /* Reenable adjust-window action: */
|
---|
152 | actionsPool()->action(UIActionIndex_Simple_AdjustWindow)->setVisible(true);
|
---|
153 | }
|
---|
154 |
|
---|