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