1 | /* $Id: UIMachineLogicScale.cpp 52203 2014-07-25 23:46:23Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMachineLogicScale class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2013 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 Q_WS_MAC
|
---|
19 | /* Qt includes: */
|
---|
20 | # include <QTimer>
|
---|
21 | #endif /* !Q_WS_MAC */
|
---|
22 |
|
---|
23 | /* GUI includes: */
|
---|
24 | #include "VBoxGlobal.h"
|
---|
25 | #include "UIMessageCenter.h"
|
---|
26 | #include "UISession.h"
|
---|
27 | #include "UIActionPoolRuntime.h"
|
---|
28 | #include "UIMachineLogicScale.h"
|
---|
29 | #include "UIMachineWindow.h"
|
---|
30 | #include "UIShortcutPool.h"
|
---|
31 | #ifndef Q_WS_MAC
|
---|
32 | # include "QIMenu.h"
|
---|
33 | #else /* Q_WS_MAC */
|
---|
34 | # include "VBoxUtils.h"
|
---|
35 | #endif /* Q_WS_MAC */
|
---|
36 |
|
---|
37 | UIMachineLogicScale::UIMachineLogicScale(QObject *pParent, UISession *pSession)
|
---|
38 | : UIMachineLogic(pParent, pSession, UIVisualStateType_Scale)
|
---|
39 | #ifndef Q_WS_MAC
|
---|
40 | , m_pPopupMenu(0)
|
---|
41 | #endif /* !Q_WS_MAC */
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | bool UIMachineLogicScale::checkAvailability()
|
---|
46 | {
|
---|
47 | /* Show the info message. */
|
---|
48 | const UIShortcut &shortcut =
|
---|
49 | gShortcutPool->shortcut(actionPool()->shortcutsExtraDataID(),
|
---|
50 | actionPool()->action(UIActionIndexRT_M_View_T_Scale)->shortcutExtraDataID());
|
---|
51 | const QString strHotKey = QString("Host+%1").arg(shortcut.toString());
|
---|
52 | if (!msgCenter().confirmGoingScale(strHotKey))
|
---|
53 | return false;
|
---|
54 |
|
---|
55 | return true;
|
---|
56 | }
|
---|
57 |
|
---|
58 | #ifndef Q_WS_MAC
|
---|
59 | void UIMachineLogicScale::sltInvokePopupMenu()
|
---|
60 | {
|
---|
61 | /* Popup main-menu if present: */
|
---|
62 | if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
|
---|
63 | {
|
---|
64 | m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
|
---|
65 | QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
|
---|
66 | }
|
---|
67 | }
|
---|
68 | #endif /* !Q_WS_MAC */
|
---|
69 |
|
---|
70 | void UIMachineLogicScale::prepareActionGroups()
|
---|
71 | {
|
---|
72 | /* Call to base-class: */
|
---|
73 | UIMachineLogic::prepareActionGroups();
|
---|
74 |
|
---|
75 | /* Restrict 'Adjust Window', 'Guest Autoresize', 'Status Bar' and 'Resize' actions for 'View' menu: */
|
---|
76 | actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
|
---|
77 | (RuntimeMenuViewActionType)
|
---|
78 | (RuntimeMenuViewActionType_AdjustWindow |
|
---|
79 | RuntimeMenuViewActionType_GuestAutoresize |
|
---|
80 | RuntimeMenuViewActionType_StatusBar |
|
---|
81 | RuntimeMenuViewActionType_Resize));
|
---|
82 |
|
---|
83 | /* Take care of view-action toggle state: */
|
---|
84 | UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
|
---|
85 | if (!pActionScale->isChecked())
|
---|
86 | {
|
---|
87 | pActionScale->blockSignals(true);
|
---|
88 | pActionScale->setChecked(true);
|
---|
89 | pActionScale->blockSignals(false);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | void UIMachineLogicScale::prepareActionConnections()
|
---|
94 | {
|
---|
95 | /* Call to base-class: */
|
---|
96 | UIMachineLogic::prepareActionConnections();
|
---|
97 |
|
---|
98 | /* Prepare 'View' actions connections: */
|
---|
99 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), SIGNAL(triggered(bool)),
|
---|
100 | this, SLOT(sltChangeVisualStateToNormal()));
|
---|
101 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SIGNAL(triggered(bool)),
|
---|
102 | this, SLOT(sltChangeVisualStateToFullscreen()));
|
---|
103 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), SIGNAL(triggered(bool)),
|
---|
104 | this, SLOT(sltChangeVisualStateToSeamless()));
|
---|
105 | }
|
---|
106 |
|
---|
107 | void UIMachineLogicScale::prepareMachineWindows()
|
---|
108 | {
|
---|
109 | /* Do not create machine-window(s) if they created already: */
|
---|
110 | if (isMachineWindowsCreated())
|
---|
111 | return;
|
---|
112 |
|
---|
113 | #ifdef Q_WS_MAC // TODO: Is that really need here?
|
---|
114 | /* We have to make sure that we are getting the front most process.
|
---|
115 | * This is necessary for Qt versions > 4.3.3: */
|
---|
116 | ::darwinSetFrontMostProcess();
|
---|
117 | #endif /* Q_WS_MAC */
|
---|
118 |
|
---|
119 | /* Get monitors count: */
|
---|
120 | ulong uMonitorCount = session().GetMachine().GetMonitorCount();
|
---|
121 | /* Create machine window(s): */
|
---|
122 | for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
|
---|
123 | addMachineWindow(UIMachineWindow::create(this, uScreenId));
|
---|
124 | /* Order machine window(s): */
|
---|
125 | for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
|
---|
126 | machineWindows()[uScreenId - 1]->raise();
|
---|
127 |
|
---|
128 | /* Listen for frame-buffer resize: */
|
---|
129 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
130 | connect(pMachineWindow, SIGNAL(sigFrameBufferResize()),
|
---|
131 | this, SIGNAL(sigFrameBufferResize()));
|
---|
132 |
|
---|
133 | /* Mark machine-window(s) created: */
|
---|
134 | setMachineWindowsCreated(true);
|
---|
135 | }
|
---|
136 |
|
---|
137 | #ifndef Q_WS_MAC
|
---|
138 | void UIMachineLogicScale::prepareMenu()
|
---|
139 | {
|
---|
140 | /* Prepare popup-menu: */
|
---|
141 | m_pPopupMenu = new QIMenu;
|
---|
142 | AssertPtrReturnVoid(m_pPopupMenu);
|
---|
143 | {
|
---|
144 | /* Prepare popup-menu: */
|
---|
145 | foreach (QMenu *pMenu, actionPool()->menus())
|
---|
146 | m_pPopupMenu->addMenu(pMenu);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | #endif /* !Q_WS_MAC */
|
---|
150 |
|
---|
151 | #ifndef Q_WS_MAC
|
---|
152 | void UIMachineLogicScale::cleanupMenu()
|
---|
153 | {
|
---|
154 | /* Cleanup popup-menu: */
|
---|
155 | delete m_pPopupMenu;
|
---|
156 | m_pPopupMenu = 0;
|
---|
157 | }
|
---|
158 | #endif /* !Q_WS_MAC */
|
---|
159 |
|
---|
160 | void UIMachineLogicScale::cleanupMachineWindows()
|
---|
161 | {
|
---|
162 | /* Do not destroy machine-window(s) if they destroyed already: */
|
---|
163 | if (!isMachineWindowsCreated())
|
---|
164 | return;
|
---|
165 |
|
---|
166 | /* Mark machine-window(s) destroyed: */
|
---|
167 | setMachineWindowsCreated(false);
|
---|
168 |
|
---|
169 | /* Cleanup machine-window(s): */
|
---|
170 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
171 | UIMachineWindow::destroy(pMachineWindow);
|
---|
172 | }
|
---|
173 |
|
---|
174 | void UIMachineLogicScale::cleanupActionConnections()
|
---|
175 | {
|
---|
176 | /* "View" actions disconnections: */
|
---|
177 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), SIGNAL(triggered(bool)),
|
---|
178 | this, SLOT(sltChangeVisualStateToNormal()));
|
---|
179 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SIGNAL(triggered(bool)),
|
---|
180 | this, SLOT(sltChangeVisualStateToFullscreen()));
|
---|
181 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), SIGNAL(triggered(bool)),
|
---|
182 | this, SLOT(sltChangeVisualStateToSeamless()));
|
---|
183 |
|
---|
184 | /* Call to base-class: */
|
---|
185 | UIMachineLogic::cleanupActionConnections();
|
---|
186 |
|
---|
187 | }
|
---|
188 |
|
---|
189 | void UIMachineLogicScale::cleanupActionGroups()
|
---|
190 | {
|
---|
191 | /* Take care of view-action toggle state: */
|
---|
192 | UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
|
---|
193 | if (pActionScale->isChecked())
|
---|
194 | {
|
---|
195 | pActionScale->blockSignals(true);
|
---|
196 | pActionScale->setChecked(false);
|
---|
197 | pActionScale->blockSignals(false);
|
---|
198 | }
|
---|
199 |
|
---|
200 | /* Allow 'Adjust Window', 'Guest Autoresize', 'Status Bar' and 'Resize' actions for 'View' menu: */
|
---|
201 | actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
|
---|
202 | RuntimeMenuViewActionType_Invalid);
|
---|
203 |
|
---|
204 | /* Call to base-class: */
|
---|
205 | UIMachineLogic::cleanupActionGroups();
|
---|
206 | }
|
---|
207 |
|
---|