VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UITools.cpp@ 108211

Last change on this file since 108211 was 108211, checked in by vboxsync, 3 months ago

FE/Qt: bugref:10814: VBox Manager / Tools pane: Pass popup flag deeper into the model.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: UITools.cpp 108211 2025-02-13 17:02:55Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UITools class implementation.
4 */
5
6/*
7 * Copyright (C) 2012-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 <QVBoxLayout>
30
31/* GUI includes: */
32#include "UITools.h"
33#include "UIToolsModel.h"
34#include "UIToolsView.h"
35
36/* Other VBox includes: */
37#include "iprt/assert.h"
38
39
40UITools::UITools(QWidget *pParent,
41 UIToolClass enmClass,
42 UIActionPool *pActionPool,
43 Qt::WindowFlags theFlags /* = Qt::Popup */)
44 : QWidget(pParent, theFlags)
45 , m_enmClass(enmClass)
46 , m_pActionPool(pActionPool)
47 , m_fPopup(theFlags == Qt::Popup)
48 , m_pMainLayout(0)
49 , m_pToolsModel(0)
50 , m_pToolsView(0)
51{
52 prepare();
53}
54
55UITools::~UITools()
56{
57 cleanup();
58}
59
60void UITools::setToolsType(UIToolType enmType)
61{
62 m_pToolsModel->setToolsType(enmType);
63}
64
65UIToolType UITools::toolsType() const
66{
67 return m_pToolsModel->toolsType();
68}
69
70void UITools::setItemsEnabled(bool fEnabled)
71{
72 m_pToolsModel->setItemsEnabled(fEnabled);
73}
74
75bool UITools::isItemsEnabled() const
76{
77 return m_pToolsModel->isItemsEnabled();
78}
79
80void UITools::setRestrictedToolTypes(const QList<UIToolType> &types)
81{
82 m_pToolsModel->setRestrictedToolTypes(types);
83}
84
85QList<UIToolType> UITools::restrictedToolTypes() const
86{
87 return m_pToolsModel->restrictedToolTypes();
88}
89
90void UITools::prepare()
91{
92 /* Prepare everything: */
93 prepareContents();
94 prepareConnections();
95
96 /* Init model finally: */
97 initModel();
98}
99
100void UITools::prepareContents()
101{
102 /* Setup own layout rules: */
103 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
104
105 /* Prepare main-layout: */
106 m_pMainLayout = new QVBoxLayout(this);
107 if (m_pMainLayout)
108 {
109 m_pMainLayout->setContentsMargins(1, 1, 1, 1);
110 m_pMainLayout->setSpacing(0);
111
112 /* Prepare model: */
113 prepareModel();
114 }
115}
116
117void UITools::prepareModel()
118{
119 /* Prepare model: */
120 m_pToolsModel = new UIToolsModel(m_enmClass, this, isPopup());
121 if (m_pToolsModel)
122 prepareView();
123}
124
125void UITools::prepareView()
126{
127 AssertPtrReturnVoid(m_pToolsModel);
128 AssertPtrReturnVoid(m_pMainLayout);
129
130 /* Prepare view: */
131 m_pToolsView = new UIToolsView(this, m_pToolsModel, isPopup());
132 if (m_pToolsView)
133 {
134 m_pToolsView->setScene(m_pToolsModel->scene());
135 m_pToolsView->show();
136 setFocusProxy(m_pToolsView);
137
138 /* Add into layout: */
139 m_pMainLayout->addWidget(m_pToolsView);
140 }
141}
142
143void UITools::prepareConnections()
144{
145 /* Model connections: */
146 connect(m_pToolsModel, &UIToolsModel::sigClose,
147 this, &UITools::close);
148 connect(m_pToolsModel, &UIToolsModel::sigSelectionChanged,
149 this, &UITools::sigSelectionChanged);
150}
151
152void UITools::initModel()
153{
154 m_pToolsModel->init();
155}
156
157void UITools::cleanupConnections()
158{
159 /* Model connections: */
160 disconnect(m_pToolsModel, &UIToolsModel::sigClose,
161 this, &UITools::close);
162 disconnect(m_pToolsModel, &UIToolsModel::sigSelectionChanged,
163 this, &UITools::sigSelectionChanged);
164}
165
166void UITools::cleanupView()
167{
168 delete m_pToolsView;
169 m_pToolsView = 0;
170}
171
172void UITools::cleanupModel()
173{
174 delete m_pToolsModel;
175 m_pToolsModel = 0;
176}
177
178void UITools::cleanup()
179{
180 /* Cleanup everything: */
181 cleanupConnections();
182 cleanupView();
183 cleanupModel();
184}
Note: See TracBrowser for help on using the repository browser.

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