VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp@ 52130

Last change on this file since 52130 was 52130, checked in by vboxsync, 10 years ago

FE/Qt: 7462: Runtime UI: Menu-bar, menu cleanup/rework (part 03).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: UIMachineLogicScale.cpp 52130 2014-07-22 15:52:00Z 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#ifndef Q_WS_MAC
31# include "QIMenu.h"
32#else /* Q_WS_MAC */
33# include "VBoxUtils.h"
34#endif /* Q_WS_MAC */
35
36UIMachineLogicScale::UIMachineLogicScale(QObject *pParent, UISession *pSession)
37 : UIMachineLogic(pParent, pSession, UIVisualStateType_Scale)
38#ifndef Q_WS_MAC
39 , m_pPopupMenu(0)
40#endif /* !Q_WS_MAC */
41{
42}
43
44bool UIMachineLogicScale::checkAvailability()
45{
46 /* Take the toggle hot key from the menu item.
47 * Since VBoxGlobal::extractKeyFromActionText gets exactly
48 * the linked key without the 'Host+' part we are adding it here. */
49 QString strHotKey = QString("Host+%1")
50 .arg(VBoxGlobal::extractKeyFromActionText(gActionPool->action(UIActionIndexRuntime_Toggle_Scale)->text()));
51 Assert(!strHotKey.isEmpty());
52
53 /* Show the info message. */
54 if (!msgCenter().confirmGoingScale(strHotKey))
55 return false;
56
57 return true;
58}
59
60#ifndef Q_WS_MAC
61void UIMachineLogicScale::sltInvokePopupMenu()
62{
63 /* Popup main-menu if present: */
64 if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
65 {
66 m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
67 QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
68 }
69}
70#endif /* !Q_WS_MAC */
71
72void UIMachineLogicScale::prepareActionGroups()
73{
74 /* Call to base-class: */
75 UIMachineLogic::prepareActionGroups();
76
77 /* Take care of view-action toggle state: */
78 UIAction *pActionScale = gActionPool->action(UIActionIndexRuntime_Toggle_Scale);
79 if (!pActionScale->isChecked())
80 {
81 pActionScale->blockSignals(true);
82 pActionScale->setChecked(true);
83 pActionScale->blockSignals(false);
84 pActionScale->update();
85 }
86}
87
88void UIMachineLogicScale::prepareActionConnections()
89{
90 /* Call to base-class: */
91 UIMachineLogic::prepareActionConnections();
92
93 /* "View" actions connections: */
94 connect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
95 this, SLOT(sltChangeVisualStateToNormal()));
96 connect(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SIGNAL(triggered(bool)),
97 this, SLOT(sltChangeVisualStateToFullscreen()));
98 connect(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SIGNAL(triggered(bool)),
99 this, SLOT(sltChangeVisualStateToSeamless()));
100}
101
102void UIMachineLogicScale::prepareMachineWindows()
103{
104 /* Do not create machine-window(s) if they created already: */
105 if (isMachineWindowsCreated())
106 return;
107
108#ifdef Q_WS_MAC // TODO: Is that really need here?
109 /* We have to make sure that we are getting the front most process.
110 * This is necessary for Qt versions > 4.3.3: */
111 ::darwinSetFrontMostProcess();
112#endif /* Q_WS_MAC */
113
114 /* Get monitors count: */
115 ulong uMonitorCount = session().GetMachine().GetMonitorCount();
116 /* Create machine window(s): */
117 for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
118 addMachineWindow(UIMachineWindow::create(this, uScreenId));
119 /* Order machine window(s): */
120 for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
121 machineWindows()[uScreenId - 1]->raise();
122
123 /* Mark machine-window(s) created: */
124 setMachineWindowsCreated(true);
125}
126
127#ifndef Q_WS_MAC
128void UIMachineLogicScale::prepareMenu()
129{
130 /* Call to base-class: */
131 UIMachineLogic::prepareMenu();
132
133 /* Prepare popup-menu: */
134 m_pPopupMenu = new QIMenu;
135 AssertPtrReturnVoid(m_pPopupMenu);
136 {
137 /* Prepare popup-menu: */
138 foreach (QMenu *pMenu, menus())
139 m_pPopupMenu->addMenu(pMenu);
140 }
141}
142#endif /* !Q_WS_MAC */
143
144#ifndef Q_WS_MAC
145void UIMachineLogicScale::cleanupMenu()
146{
147 /* Cleanup popup-menu: */
148 delete m_pPopupMenu;
149 m_pPopupMenu = 0;
150
151 /* Call to base-class: */
152 UIMachineLogic::cleanupMenu();
153}
154#endif /* !Q_WS_MAC */
155
156void UIMachineLogicScale::cleanupMachineWindows()
157{
158 /* Do not destroy machine-window(s) if they destroyed already: */
159 if (!isMachineWindowsCreated())
160 return;
161
162 /* Mark machine-window(s) destroyed: */
163 setMachineWindowsCreated(false);
164
165 /* Cleanup machine-window(s): */
166 foreach (UIMachineWindow *pMachineWindow, machineWindows())
167 UIMachineWindow::destroy(pMachineWindow);
168}
169
170void UIMachineLogicScale::cleanupActionConnections()
171{
172 /* "View" actions disconnections: */
173 disconnect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
174 this, SLOT(sltChangeVisualStateToNormal()));
175 disconnect(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SIGNAL(triggered(bool)),
176 this, SLOT(sltChangeVisualStateToFullscreen()));
177 disconnect(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SIGNAL(triggered(bool)),
178 this, SLOT(sltChangeVisualStateToSeamless()));
179
180 /* Call to base-class: */
181 UIMachineLogic::cleanupActionConnections();
182
183}
184
185void UIMachineLogicScale::cleanupActionGroups()
186{
187 /* Take care of view-action toggle state: */
188 UIAction *pActionScale = gActionPool->action(UIActionIndexRuntime_Toggle_Scale);
189 if (pActionScale->isChecked())
190 {
191 pActionScale->blockSignals(true);
192 pActionScale->setChecked(false);
193 pActionScale->blockSignals(false);
194 pActionScale->update();
195 }
196
197 /* Call to base-class: */
198 UIMachineLogic::cleanupActionGroups();
199}
200
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette