VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityToolWidget.cpp

Last change on this file was 106061, checked in by vboxsync, 2 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/* $Id: UIVMActivityToolWidget.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVMActivityToolWidget class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QApplication>
30#include <QVBoxLayout>
31#include <QStyle>
32
33/* GUI includes: */
34#include "QIToolBar.h"
35#include "UIActionPoolManager.h"
36#include "UICommon.h"
37#include "UIVMActivityMonitor.h"
38#include "UIVMActivityToolWidget.h"
39#include "UIMessageCenter.h"
40#include "UIVirtualMachineItem.h"
41#include "UIVirtualMachineItemCloud.h"
42#include "UIVirtualMachineItemLocal.h"
43#include "UIVMActivityMonitorContainer.h"
44#ifdef VBOX_WS_MAC
45# include "UIWindowMenuManager.h"
46#endif /* VBOX_WS_MAC */
47
48/* COM includes: */
49#include "CMachine.h"
50
51UIVMActivityToolWidget::UIVMActivityToolWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool,
52 bool fShowToolbar /* = true */, QWidget *pParent /* = 0 */)
53 : QWidget(pParent)
54 , m_enmEmbedding(enmEmbedding)
55 , m_pActionPool(pActionPool)
56 , m_fShowToolbar(fShowToolbar)
57 , m_pToolBar(0)
58 , m_pMonitorContainer(0)
59{
60 uiCommon().setHelpKeyword(this, "vm-activity-session-information");
61 prepare();
62 prepareActions();
63 prepareToolBar();
64}
65
66
67QMenu *UIVMActivityToolWidget::menu() const
68{
69 return NULL;
70}
71
72bool UIVMActivityToolWidget::isCurrentTool() const
73{
74 return m_fIsCurrentTool;
75}
76
77void UIVMActivityToolWidget::setIsCurrentTool(bool fIsCurrentTool)
78{
79 m_fIsCurrentTool = fIsCurrentTool;
80}
81
82void UIVMActivityToolWidget::prepare()
83{
84 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
85 pMainLayout->setContentsMargins(0, 0, 0, 0);
86 m_pMonitorContainer = new UIVMActivityMonitorContainer(this, m_pActionPool, m_enmEmbedding);
87 pMainLayout->addWidget(m_pMonitorContainer);
88}
89
90void UIVMActivityToolWidget::setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
91{
92 setMachines(items);
93}
94
95void UIVMActivityToolWidget::setMachines(const QList<UIVirtualMachineItem*> &machines)
96{
97 QVector<QUuid> machineIds;
98 foreach (const UIVirtualMachineItem* pMachine, machines)
99 {
100 if (!pMachine)
101 continue;
102 machineIds << pMachine->id();
103 }
104 /* List of machines that are newly added to selected machine list: */
105 QList<UIVirtualMachineItem*> newSelections;
106 QVector<QUuid> unselectedMachines(m_machineIds);
107
108 foreach (UIVirtualMachineItem* pMachine, machines)
109 {
110 if (!pMachine)
111 continue;
112 QUuid id = pMachine->id();
113 unselectedMachines.removeAll(id);
114 if (!m_machineIds.contains(id))
115 newSelections << pMachine;
116 }
117 m_machineIds = machineIds;
118
119 m_pMonitorContainer->removeTabs(unselectedMachines);
120 addTabs(newSelections);
121}
122
123void UIVMActivityToolWidget::prepareActions()
124{
125 QAction *pToResourcesAction =
126 m_pActionPool->action(UIActionIndex_M_Activity_S_ToVMActivityOverview);
127 if (pToResourcesAction)
128 connect(pToResourcesAction, &QAction::triggered, this, &UIVMActivityToolWidget::sigSwitchToActivityOverviewPane);
129}
130
131void UIVMActivityToolWidget::prepareToolBar()
132{
133 /* Create toolbar: */
134 m_pToolBar = new QIToolBar(parentWidget());
135 AssertPtrReturnVoid(m_pToolBar);
136 {
137 /* Configure toolbar: */
138 const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize));
139 m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
140 m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
141
142#ifdef VBOX_WS_MAC
143 /* Check whether we are embedded into a stack: */
144 if (m_enmEmbedding == EmbedTo_Stack)
145 {
146 /* Add into layout: */
147 layout()->addWidget(m_pToolBar);
148 }
149#else
150 /* Add into layout: */
151 layout()->addWidget(m_pToolBar);
152#endif
153 }
154}
155
156void UIVMActivityToolWidget::addTabs(const QList<UIVirtualMachineItem*> &machines)
157{
158 AssertReturnVoid(m_pMonitorContainer);
159 foreach (UIVirtualMachineItem* pMachine, machines)
160 {
161 if (!pMachine)
162 continue;
163 if (pMachine->toLocal())
164 {
165 CMachine comMachine = pMachine->toLocal()->machine();
166 if (!comMachine.isOk())
167 continue;
168 m_pMonitorContainer->addLocalMachine(comMachine);
169 continue;
170 }
171 if (pMachine->toCloud())
172 {
173 CCloudMachine comMachine = pMachine->toCloud()->machine();
174 if (!comMachine.isOk())
175 continue;
176 m_pMonitorContainer->addCloudMachine(comMachine);
177 continue;
178 }
179 }
180}
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