VirtualBox

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

Last change on this file since 107299 was 107299, checked in by vboxsync, 5 weeks ago

FE/Qt: bugref:10814: VBox Manager: Make sure Chooser and Tool panes have no dependency from VBox Manager widget as it should be possible to create them from other widgets.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: UITools.cpp 107299 2024-12-12 14:02:39Z 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, UIToolClass enmClass, UIActionPool *pActionPool)
41 : QWidget(pParent, Qt::Popup)
42 , m_enmClass(enmClass)
43 , m_pActionPool(pActionPool)
44 , m_pMainLayout(0)
45 , m_pToolsModel(0)
46 , m_pToolsView(0)
47{
48 prepare();
49}
50
51UIActionPool *UITools::actionPool() const
52{
53 return m_pActionPool;
54}
55
56void UITools::setToolsType(UIToolType enmType)
57{
58 m_pToolsModel->setToolsType(enmType);
59}
60
61UIToolType UITools::toolsType() const
62{
63 return m_pToolsModel->toolsType();
64}
65
66void UITools::setItemsEnabled(bool fEnabled)
67{
68 m_pToolsModel->setItemsEnabled(fEnabled);
69}
70
71bool UITools::isItemsEnabled() const
72{
73 return m_pToolsModel->isItemsEnabled();
74}
75
76void UITools::setRestrictedToolTypes(const QList<UIToolType> &types)
77{
78 m_pToolsModel->setRestrictedToolTypes(types);
79}
80
81QList<UIToolType> UITools::restrictedToolTypes() const
82{
83 return m_pToolsModel->restrictedToolTypes();
84}
85
86UIToolsItem *UITools::currentItem() const
87{
88 return m_pToolsModel->currentItem();
89}
90
91void UITools::prepare()
92{
93 /* Prepare everything: */
94 prepareContents();
95 prepareConnections();
96
97 /* Init model finally: */
98 initModel();
99}
100
101void UITools::prepareContents()
102{
103 /* Setup own layout rules: */
104 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
105
106 /* Prepare main-layout: */
107 m_pMainLayout = new QVBoxLayout(this);
108 if (m_pMainLayout)
109 {
110 m_pMainLayout->setContentsMargins(1, 1, 1, 1);
111 m_pMainLayout->setSpacing(0);
112
113 /* Prepare model: */
114 prepareModel();
115 }
116}
117
118void UITools::prepareModel()
119{
120 /* Prepare model: */
121 m_pToolsModel = new UIToolsModel(m_enmClass, this);
122 if (m_pToolsModel)
123 prepareView();
124}
125
126void UITools::prepareView()
127{
128 AssertPtrReturnVoid(m_pToolsModel);
129 AssertPtrReturnVoid(m_pMainLayout);
130
131 /* Prepare view: */
132 m_pToolsView = new UIToolsView(this);
133 if (m_pToolsView)
134 {
135 m_pToolsView->setScene(m_pToolsModel->scene());
136 m_pToolsView->show();
137 setFocusProxy(m_pToolsView);
138
139 /* Add into layout: */
140 m_pMainLayout->addWidget(m_pToolsView);
141 }
142}
143
144void UITools::prepareConnections()
145{
146 /* Model connections: */
147 connect(m_pToolsModel, &UIToolsModel::sigClose,
148 this, &UITools::close);
149 connect(m_pToolsModel, &UIToolsModel::sigSelectionChanged,
150 this, &UITools::sigSelectionChanged);
151 connect(m_pToolsModel, &UIToolsModel::sigExpandingStarted,
152 this, &UITools::sigExpandingStarted);
153 connect(m_pToolsModel, &UIToolsModel::sigExpandingFinished,
154 this, &UITools::sigExpandingFinished);
155 connect(m_pToolsModel, &UIToolsModel::sigItemMinimumWidthHintChanged,
156 m_pToolsView, &UIToolsView::sltMinimumWidthHintChanged);
157 connect(m_pToolsModel, &UIToolsModel::sigItemMinimumHeightHintChanged,
158 m_pToolsView, &UIToolsView::sltMinimumHeightHintChanged);
159 connect(m_pToolsModel, &UIToolsModel::sigFocusChanged,
160 m_pToolsView, &UIToolsView::sltFocusChanged);
161
162 /* View connections: */
163 connect(m_pToolsView, &UIToolsView::sigResized,
164 m_pToolsModel, &UIToolsModel::sltHandleViewResized);
165}
166
167void UITools::initModel()
168{
169 m_pToolsModel->init();
170}
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