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