1 | /* $Id: UIMachineLogicScale.cpp 49596 2013-11-21 10:11:36Z 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 | /* GUI includes: */
|
---|
19 | #include "VBoxGlobal.h"
|
---|
20 | #include "UIMessageCenter.h"
|
---|
21 | #include "UISession.h"
|
---|
22 | #include "UIActionPoolRuntime.h"
|
---|
23 | #include "UIMachineLogicScale.h"
|
---|
24 | #include "UIMachineWindow.h"
|
---|
25 | #ifdef Q_WS_MAC
|
---|
26 | #include "VBoxUtils.h"
|
---|
27 | #endif /* Q_WS_MAC */
|
---|
28 |
|
---|
29 | UIMachineLogicScale::UIMachineLogicScale(QObject *pParent, UISession *pSession)
|
---|
30 | : UIMachineLogic(pParent, pSession, UIVisualStateType_Scale)
|
---|
31 | {
|
---|
32 | }
|
---|
33 |
|
---|
34 | bool UIMachineLogicScale::checkAvailability()
|
---|
35 | {
|
---|
36 | /* Take the toggle hot key from the menu item.
|
---|
37 | * Since VBoxGlobal::extractKeyFromActionText gets exactly
|
---|
38 | * the linked key without the 'Host+' part we are adding it here. */
|
---|
39 | QString strHotKey = QString("Host+%1")
|
---|
40 | .arg(VBoxGlobal::extractKeyFromActionText(gActionPool->action(UIActionIndexRuntime_Toggle_Scale)->text()));
|
---|
41 | Assert(!strHotKey.isEmpty());
|
---|
42 |
|
---|
43 | /* Show the info message. */
|
---|
44 | if (!msgCenter().confirmGoingScale(strHotKey))
|
---|
45 | return false;
|
---|
46 |
|
---|
47 | return true;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void UIMachineLogicScale::prepareActionGroups()
|
---|
51 | {
|
---|
52 | /* Call to base-class: */
|
---|
53 | UIMachineLogic::prepareActionGroups();
|
---|
54 |
|
---|
55 | /* Guest auto-resize isn't allowed in scale-mode: */
|
---|
56 | gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->setVisible(false);
|
---|
57 | /* Adjust-window isn't allowed in scale-mode: */
|
---|
58 | gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow)->setVisible(false);
|
---|
59 |
|
---|
60 | /* Take care of view-action toggle state: */
|
---|
61 | UIAction *pActionScale = gActionPool->action(UIActionIndexRuntime_Toggle_Scale);
|
---|
62 | if (!pActionScale->isChecked())
|
---|
63 | {
|
---|
64 | pActionScale->blockSignals(true);
|
---|
65 | pActionScale->setChecked(true);
|
---|
66 | pActionScale->blockSignals(false);
|
---|
67 | pActionScale->update();
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | void UIMachineLogicScale::prepareActionConnections()
|
---|
72 | {
|
---|
73 | /* Call to base-class: */
|
---|
74 | UIMachineLogic::prepareActionConnections();
|
---|
75 |
|
---|
76 | /* "View" actions connections: */
|
---|
77 | connect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
|
---|
78 | uisession(), SLOT(sltChangeVisualStateToNormal()));
|
---|
79 | connect(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SIGNAL(triggered(bool)),
|
---|
80 | uisession(), SLOT(sltChangeVisualStateToFullscreen()));
|
---|
81 | connect(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SIGNAL(triggered(bool)),
|
---|
82 | uisession(), SLOT(sltChangeVisualStateToSeamless()));
|
---|
83 | }
|
---|
84 |
|
---|
85 | void UIMachineLogicScale::prepareMachineWindows()
|
---|
86 | {
|
---|
87 | /* Do not create machine-window(s) if they created already: */
|
---|
88 | if (isMachineWindowsCreated())
|
---|
89 | return;
|
---|
90 |
|
---|
91 | #ifdef Q_WS_MAC // TODO: Is that really need here?
|
---|
92 | /* We have to make sure that we are getting the front most process.
|
---|
93 | * This is necessary for Qt versions > 4.3.3: */
|
---|
94 | ::darwinSetFrontMostProcess();
|
---|
95 | #endif /* Q_WS_MAC */
|
---|
96 |
|
---|
97 | /* Get monitors count: */
|
---|
98 | ulong uMonitorCount = session().GetMachine().GetMonitorCount();
|
---|
99 | /* Create machine window(s): */
|
---|
100 | for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
|
---|
101 | addMachineWindow(UIMachineWindow::create(this, uScreenId));
|
---|
102 | /* Order machine window(s): */
|
---|
103 | for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
|
---|
104 | machineWindows()[uScreenId - 1]->raise();
|
---|
105 |
|
---|
106 | /* Mark machine-window(s) created: */
|
---|
107 | setMachineWindowsCreated(true);
|
---|
108 | }
|
---|
109 |
|
---|
110 | void UIMachineLogicScale::cleanupMachineWindows()
|
---|
111 | {
|
---|
112 | /* Do not destroy machine-window(s) if they destroyed already: */
|
---|
113 | if (!isMachineWindowsCreated())
|
---|
114 | return;
|
---|
115 |
|
---|
116 | /* Mark machine-window(s) destroyed: */
|
---|
117 | setMachineWindowsCreated(false);
|
---|
118 |
|
---|
119 | /* Cleanup machine-window(s): */
|
---|
120 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
121 | UIMachineWindow::destroy(pMachineWindow);
|
---|
122 | }
|
---|
123 |
|
---|
124 | void UIMachineLogicScale::cleanupActionConnections()
|
---|
125 | {
|
---|
126 | /* "View" actions disconnections: */
|
---|
127 | disconnect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
|
---|
128 | uisession(), SLOT(sltChangeVisualStateToNormal()));
|
---|
129 | disconnect(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SIGNAL(triggered(bool)),
|
---|
130 | uisession(), SLOT(sltChangeVisualStateToFullscreen()));
|
---|
131 | disconnect(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SIGNAL(triggered(bool)),
|
---|
132 | uisession(), SLOT(sltChangeVisualStateToSeamless()));
|
---|
133 |
|
---|
134 | /* Call to base-class: */
|
---|
135 | UIMachineLogic::cleanupActionConnections();
|
---|
136 |
|
---|
137 | }
|
---|
138 |
|
---|
139 | void UIMachineLogicScale::cleanupActionGroups()
|
---|
140 | {
|
---|
141 | /* Take care of view-action toggle state: */
|
---|
142 | UIAction *pActionScale = gActionPool->action(UIActionIndexRuntime_Toggle_Scale);
|
---|
143 | if (pActionScale->isChecked())
|
---|
144 | {
|
---|
145 | pActionScale->blockSignals(true);
|
---|
146 | pActionScale->setChecked(false);
|
---|
147 | pActionScale->blockSignals(false);
|
---|
148 | pActionScale->update();
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* Reenable guest-autoresize action: */
|
---|
152 | gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->setVisible(true);
|
---|
153 | /* Reenable adjust-window action: */
|
---|
154 | gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow)->setVisible(true);
|
---|
155 |
|
---|
156 | /* Call to base-class: */
|
---|
157 | UIMachineLogic::cleanupActionGroups();
|
---|
158 | }
|
---|
159 |
|
---|