VirtualBox

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

Last change on this file since 102811 was 102811, checked in by vboxsync, 14 months ago

FE/Qt: A bit of cleanup for UITools; Rework the way model asks parent to close.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: UITools.cpp 102811 2024-01-10 11:08:41Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UITools class implementation.
4 */
5
6/*
7 * Copyright (C) 2012-2023 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 "UICommon.h"
33#include "UITools.h"
34#include "UIToolsModel.h"
35#include "UIToolsView.h"
36#include "UIVirtualBoxManagerWidget.h"
37
38
39UITools::UITools(UIToolClass enmClass, UIVirtualBoxManagerWidget *pParent /* = 0 */)
40 : QWidget(pParent, Qt::Popup)
41 , m_enmClass(enmClass)
42 , m_pManagerWidget(pParent)
43 , m_pMainLayout(0)
44 , m_pToolsModel(0)
45 , m_pToolsView(0)
46{
47 prepare();
48}
49
50UIActionPool *UITools::actionPool() const
51{
52 return managerWidget()->actionPool();
53}
54
55void UITools::setToolsType(UIToolType enmType)
56{
57 m_pToolsModel->setToolsType(enmType);
58}
59
60UIToolType UITools::toolsType() const
61{
62 return m_pToolsModel->toolsType();
63}
64
65void UITools::setItemsEnabled(bool fEnabled)
66{
67 m_pToolsModel->setItemsEnabled(fEnabled);
68}
69
70bool UITools::isItemsEnabled() const
71{
72 return m_pToolsModel->isItemsEnabled();
73}
74
75void UITools::setRestrictedToolTypes(const QList<UIToolType> &types)
76{
77 m_pToolsModel->setRestrictedToolTypes(types);
78}
79
80QList<UIToolType> UITools::restrictedToolTypes() const
81{
82 return m_pToolsModel->restrictedToolTypes();
83}
84
85UIToolsItem *UITools::currentItem() const
86{
87 return m_pToolsModel->currentItem();
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);
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);
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::sigItemMinimumWidthHintChanged,
149 m_pToolsView, &UIToolsView::sltMinimumWidthHintChanged);
150 connect(m_pToolsModel, &UIToolsModel::sigItemMinimumHeightHintChanged,
151 m_pToolsView, &UIToolsView::sltMinimumHeightHintChanged);
152 connect(m_pToolsModel, &UIToolsModel::sigFocusChanged,
153 m_pToolsView, &UIToolsView::sltFocusChanged);
154
155 /* View connections: */
156 connect(m_pToolsView, &UIToolsView::sigResized,
157 m_pToolsModel, &UIToolsModel::sltHandleViewResized);
158}
159
160void UITools::initModel()
161{
162 m_pToolsModel->init();
163}
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