VirtualBox

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

Last change on this file since 107945 was 107945, checked in by vboxsync, 4 weeks ago

FE/Qt: bugref:10814: VBox Manager / Tools pane: A bit of cleanup here and there.

  • 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 107945 2025-01-27 16:06:13Z 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
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::sltClose()
91{
92 /* Close the widget in popup mode only: */
93 if (isPopup())
94 close();
95}
96
97void UITools::prepare()
98{
99 /* Prepare everything: */
100 prepareContents();
101 prepareConnections();
102
103 /* Init model finally: */
104 initModel();
105}
106
107void UITools::prepareContents()
108{
109 /* Setup own layout rules: */
110 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
111
112 /* Prepare main-layout: */
113 m_pMainLayout = new QVBoxLayout(this);
114 if (m_pMainLayout)
115 {
116 m_pMainLayout->setContentsMargins(1, 1, 1, 1);
117 m_pMainLayout->setSpacing(0);
118
119 /* Prepare model: */
120 prepareModel();
121 }
122}
123
124void UITools::prepareModel()
125{
126 /* Prepare model: */
127 m_pToolsModel = new UIToolsModel(m_enmClass, this);
128 if (m_pToolsModel)
129 prepareView();
130}
131
132void UITools::prepareView()
133{
134 AssertPtrReturnVoid(m_pToolsModel);
135 AssertPtrReturnVoid(m_pMainLayout);
136
137 /* Prepare view: */
138 m_pToolsView = new UIToolsView(this);
139 if (m_pToolsView)
140 {
141 m_pToolsView->setScene(m_pToolsModel->scene());
142 m_pToolsView->show();
143 setFocusProxy(m_pToolsView);
144
145 /* Add into layout: */
146 m_pMainLayout->addWidget(m_pToolsView);
147 }
148}
149
150void UITools::prepareConnections()
151{
152 /* Model connections: */
153 connect(m_pToolsModel, &UIToolsModel::sigClose,
154 this, &UITools::sltClose);
155 connect(m_pToolsModel, &UIToolsModel::sigSelectionChanged,
156 this, &UITools::sigSelectionChanged);
157 connect(m_pToolsModel, &UIToolsModel::sigItemMinimumWidthHintChanged,
158 m_pToolsView, &UIToolsView::sltMinimumWidthHintChanged);
159 connect(m_pToolsModel, &UIToolsModel::sigItemMinimumHeightHintChanged,
160 m_pToolsView, &UIToolsView::sltMinimumHeightHintChanged);
161 connect(m_pToolsModel, &UIToolsModel::sigFocusChanged,
162 m_pToolsView, &UIToolsView::sltFocusChanged);
163
164 /* View connections: */
165 connect(m_pToolsView, &UIToolsView::sigResized,
166 m_pToolsModel, &UIToolsModel::sltHandleViewResized);
167}
168
169void UITools::initModel()
170{
171 m_pToolsModel->init();
172}
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