1 | /* $Id: UIMachineLogicScale.cpp 52478 2014-08-22 15:21:15Z 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 | (UIExtraDataMetaDefs::RuntimeMenuViewActionType)
|
---|
78 | (UIExtraDataMetaDefs::RuntimeMenuViewActionType_AdjustWindow |
|
---|
79 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_GuestAutoresize |
|
---|
80 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_MenuBar |
|
---|
81 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_StatusBar |
|
---|
82 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_Resize));
|
---|
83 |
|
---|
84 | /* Take care of view-action toggle state: */
|
---|
85 | UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
|
---|
86 | if (!pActionScale->isChecked())
|
---|
87 | {
|
---|
88 | pActionScale->blockSignals(true);
|
---|
89 | pActionScale->setChecked(true);
|
---|
90 | pActionScale->blockSignals(false);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | void UIMachineLogicScale::prepareActionConnections()
|
---|
95 | {
|
---|
96 | /* Call to base-class: */
|
---|
97 | UIMachineLogic::prepareActionConnections();
|
---|
98 |
|
---|
99 | /* Prepare 'View' actions connections: */
|
---|
100 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), SIGNAL(triggered(bool)),
|
---|
101 | this, SLOT(sltChangeVisualStateToNormal()));
|
---|
102 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SIGNAL(triggered(bool)),
|
---|
103 | this, SLOT(sltChangeVisualStateToFullscreen()));
|
---|
104 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), SIGNAL(triggered(bool)),
|
---|
105 | this, SLOT(sltChangeVisualStateToSeamless()));
|
---|
106 | }
|
---|
107 |
|
---|
108 | void UIMachineLogicScale::prepareMachineWindows()
|
---|
109 | {
|
---|
110 | /* Do not create machine-window(s) if they created already: */
|
---|
111 | if (isMachineWindowsCreated())
|
---|
112 | return;
|
---|
113 |
|
---|
114 | #ifdef Q_WS_MAC // TODO: Is that really need here?
|
---|
115 | /* We have to make sure that we are getting the front most process.
|
---|
116 | * This is necessary for Qt versions > 4.3.3: */
|
---|
117 | ::darwinSetFrontMostProcess();
|
---|
118 | #endif /* Q_WS_MAC */
|
---|
119 |
|
---|
120 | /* Get monitors count: */
|
---|
121 | ulong uMonitorCount = session().GetMachine().GetMonitorCount();
|
---|
122 | /* Create machine window(s): */
|
---|
123 | for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
|
---|
124 | addMachineWindow(UIMachineWindow::create(this, uScreenId));
|
---|
125 | /* Order machine window(s): */
|
---|
126 | for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
|
---|
127 | machineWindows()[uScreenId - 1]->raise();
|
---|
128 |
|
---|
129 | /* Listen for frame-buffer resize: */
|
---|
130 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
131 | connect(pMachineWindow, SIGNAL(sigFrameBufferResize()),
|
---|
132 | this, SIGNAL(sigFrameBufferResize()));
|
---|
133 | emit sigFrameBufferResize();
|
---|
134 |
|
---|
135 | /* Mark machine-window(s) created: */
|
---|
136 | setMachineWindowsCreated(true);
|
---|
137 | }
|
---|
138 |
|
---|
139 | #ifndef Q_WS_MAC
|
---|
140 | void UIMachineLogicScale::prepareMenu()
|
---|
141 | {
|
---|
142 | /* Prepare popup-menu: */
|
---|
143 | m_pPopupMenu = new QIMenu;
|
---|
144 | AssertPtrReturnVoid(m_pPopupMenu);
|
---|
145 | {
|
---|
146 | /* Prepare popup-menu: */
|
---|
147 | foreach (QMenu *pMenu, actionPool()->menus())
|
---|
148 | m_pPopupMenu->addMenu(pMenu);
|
---|
149 | }
|
---|
150 | }
|
---|
151 | #endif /* !Q_WS_MAC */
|
---|
152 |
|
---|
153 | #ifndef Q_WS_MAC
|
---|
154 | void UIMachineLogicScale::cleanupMenu()
|
---|
155 | {
|
---|
156 | /* Cleanup popup-menu: */
|
---|
157 | delete m_pPopupMenu;
|
---|
158 | m_pPopupMenu = 0;
|
---|
159 | }
|
---|
160 | #endif /* !Q_WS_MAC */
|
---|
161 |
|
---|
162 | void UIMachineLogicScale::cleanupMachineWindows()
|
---|
163 | {
|
---|
164 | /* Do not destroy machine-window(s) if they destroyed already: */
|
---|
165 | if (!isMachineWindowsCreated())
|
---|
166 | return;
|
---|
167 |
|
---|
168 | /* Mark machine-window(s) destroyed: */
|
---|
169 | setMachineWindowsCreated(false);
|
---|
170 |
|
---|
171 | /* Cleanup machine-window(s): */
|
---|
172 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
173 | UIMachineWindow::destroy(pMachineWindow);
|
---|
174 | }
|
---|
175 |
|
---|
176 | void UIMachineLogicScale::cleanupActionConnections()
|
---|
177 | {
|
---|
178 | /* "View" actions disconnections: */
|
---|
179 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), SIGNAL(triggered(bool)),
|
---|
180 | this, SLOT(sltChangeVisualStateToNormal()));
|
---|
181 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SIGNAL(triggered(bool)),
|
---|
182 | this, SLOT(sltChangeVisualStateToFullscreen()));
|
---|
183 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), SIGNAL(triggered(bool)),
|
---|
184 | this, SLOT(sltChangeVisualStateToSeamless()));
|
---|
185 |
|
---|
186 | /* Call to base-class: */
|
---|
187 | UIMachineLogic::cleanupActionConnections();
|
---|
188 |
|
---|
189 | }
|
---|
190 |
|
---|
191 | void UIMachineLogicScale::cleanupActionGroups()
|
---|
192 | {
|
---|
193 | /* Take care of view-action toggle state: */
|
---|
194 | UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
|
---|
195 | if (pActionScale->isChecked())
|
---|
196 | {
|
---|
197 | pActionScale->blockSignals(true);
|
---|
198 | pActionScale->setChecked(false);
|
---|
199 | pActionScale->blockSignals(false);
|
---|
200 | }
|
---|
201 |
|
---|
202 | /* Allow 'Adjust Window', 'Guest Autoresize', 'Status Bar' and 'Resize' actions for 'View' menu: */
|
---|
203 | actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
|
---|
204 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_Invalid);
|
---|
205 |
|
---|
206 | /* Call to base-class: */
|
---|
207 | UIMachineLogic::cleanupActionGroups();
|
---|
208 | }
|
---|
209 |
|
---|