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