1 | /* $Id: UITools.cpp 88805 2021-04-30 13:29:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UITools class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2021 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QVBoxLayout>
|
---|
20 |
|
---|
21 | /* GUI includes: */
|
---|
22 | #include "UICommon.h"
|
---|
23 | #include "UITools.h"
|
---|
24 | #include "UIToolsModel.h"
|
---|
25 | #include "UIToolsView.h"
|
---|
26 | #include "UIVirtualBoxManagerWidget.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | UITools::UITools(UIVirtualBoxManagerWidget *pParent /* = 0 */)
|
---|
30 | : QWidget(pParent, Qt::Popup)
|
---|
31 | , m_pManagerWidget(pParent)
|
---|
32 | , m_pMainLayout(0)
|
---|
33 | , m_pToolsModel(0)
|
---|
34 | , m_pToolsView(0)
|
---|
35 | {
|
---|
36 | prepare();
|
---|
37 | }
|
---|
38 |
|
---|
39 | UIActionPool *UITools::actionPool() const
|
---|
40 | {
|
---|
41 | return managerWidget()->actionPool();
|
---|
42 | }
|
---|
43 |
|
---|
44 | void UITools::setToolsClass(UIToolClass enmClass)
|
---|
45 | {
|
---|
46 | m_pToolsModel->setToolsClass(enmClass);
|
---|
47 | }
|
---|
48 |
|
---|
49 | UIToolClass UITools::toolsClass() const
|
---|
50 | {
|
---|
51 | return m_pToolsModel->toolsClass();
|
---|
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 | UIToolType UITools::lastSelectedToolGlobal() const
|
---|
65 | {
|
---|
66 | return m_pToolsModel->lastSelectedToolGlobal();
|
---|
67 | }
|
---|
68 |
|
---|
69 | UIToolType UITools::lastSelectedToolMachine() const
|
---|
70 | {
|
---|
71 | return m_pToolsModel->lastSelectedToolMachine();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void UITools::setToolClassEnabled(UIToolClass enmClass, bool fEnabled)
|
---|
75 | {
|
---|
76 | m_pToolsModel->setToolClassEnabled(enmClass, fEnabled);
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool UITools::toolClassEnabled(UIToolClass enmClass) const
|
---|
80 | {
|
---|
81 | return m_pToolsModel->toolClassEnabled(enmClass);
|
---|
82 | }
|
---|
83 |
|
---|
84 | void UITools::setRestrictedToolTypes(const QList<UIToolType> &types)
|
---|
85 | {
|
---|
86 | m_pToolsModel->setRestrictedToolTypes(types);
|
---|
87 | }
|
---|
88 |
|
---|
89 | QList<UIToolType> UITools::restrictedToolTypes() const
|
---|
90 | {
|
---|
91 | return m_pToolsModel->restrictedToolTypes();
|
---|
92 | }
|
---|
93 |
|
---|
94 | UIToolsItem *UITools::currentItem() const
|
---|
95 | {
|
---|
96 | return m_pToolsModel->currentItem();
|
---|
97 | }
|
---|
98 |
|
---|
99 | void UITools::prepare()
|
---|
100 | {
|
---|
101 | /* Prepare everything: */
|
---|
102 | prepareContents();
|
---|
103 | prepareConnections();
|
---|
104 |
|
---|
105 | /* Init model finally: */
|
---|
106 | initModel();
|
---|
107 | }
|
---|
108 |
|
---|
109 | void UITools::prepareContents()
|
---|
110 | {
|
---|
111 | /* Setup own layout rules: */
|
---|
112 | setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
|
---|
113 |
|
---|
114 | /* Prepare main-layout: */
|
---|
115 | m_pMainLayout = new QVBoxLayout(this);
|
---|
116 | if (m_pMainLayout)
|
---|
117 | {
|
---|
118 | m_pMainLayout->setContentsMargins(1, 1, 1, 1);
|
---|
119 | m_pMainLayout->setSpacing(0);
|
---|
120 |
|
---|
121 | /* Prepare model: */
|
---|
122 | prepareModel();
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | void UITools::prepareModel()
|
---|
127 | {
|
---|
128 | /* Prepare model: */
|
---|
129 | m_pToolsModel = new UIToolsModel(this);
|
---|
130 | if (m_pToolsModel)
|
---|
131 | prepareView();
|
---|
132 | }
|
---|
133 |
|
---|
134 | void UITools::prepareView()
|
---|
135 | {
|
---|
136 | AssertPtrReturnVoid(m_pToolsModel);
|
---|
137 | AssertPtrReturnVoid(m_pMainLayout);
|
---|
138 |
|
---|
139 | /* Prepare view: */
|
---|
140 | m_pToolsView = new UIToolsView(this);
|
---|
141 | if (m_pToolsView)
|
---|
142 | {
|
---|
143 | m_pToolsView->setScene(m_pToolsModel->scene());
|
---|
144 | m_pToolsView->show();
|
---|
145 | setFocusProxy(m_pToolsView);
|
---|
146 |
|
---|
147 | /* Add into layout: */
|
---|
148 | m_pMainLayout->addWidget(m_pToolsView);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | void UITools::prepareConnections()
|
---|
153 | {
|
---|
154 | /* Model connections: */
|
---|
155 | connect(m_pToolsModel, &UIToolsModel::sigItemMinimumWidthHintChanged,
|
---|
156 | m_pToolsView, &UIToolsView::sltMinimumWidthHintChanged);
|
---|
157 | connect(m_pToolsModel, &UIToolsModel::sigItemMinimumHeightHintChanged,
|
---|
158 | m_pToolsView, &UIToolsView::sltMinimumHeightHintChanged);
|
---|
159 | connect(m_pToolsModel, &UIToolsModel::sigFocusChanged,
|
---|
160 | m_pToolsView, &UIToolsView::sltFocusChanged);
|
---|
161 |
|
---|
162 | /* View connections: */
|
---|
163 | connect(m_pToolsView, &UIToolsView::sigResized,
|
---|
164 | m_pToolsModel, &UIToolsModel::sltHandleViewResized);
|
---|
165 | }
|
---|
166 |
|
---|
167 | void UITools::initModel()
|
---|
168 | {
|
---|
169 | m_pToolsModel->init();
|
---|
170 | }
|
---|