1 | /* $Id: UITools.cpp 74483 2018-09-26 16:27:10Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UITools class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2018 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 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # include <QVBoxLayout>
|
---|
24 |
|
---|
25 | /* GUI includes: */
|
---|
26 | # include "UITools.h"
|
---|
27 | # include "UIToolsModel.h"
|
---|
28 | # include "UIToolsView.h"
|
---|
29 | # include "UIVirtualBoxManagerWidget.h"
|
---|
30 | # include "VBoxGlobal.h"
|
---|
31 |
|
---|
32 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
33 |
|
---|
34 |
|
---|
35 | UITools::UITools(UIVirtualBoxManagerWidget *pParent)
|
---|
36 | : QWidget(pParent, Qt::Popup)
|
---|
37 | , m_pManagerWidget(pParent)
|
---|
38 | , m_pMainLayout(0)
|
---|
39 | , m_pToolsModel(0)
|
---|
40 | , m_pToolsView(0)
|
---|
41 | {
|
---|
42 | /* Prepare: */
|
---|
43 | prepare();
|
---|
44 | }
|
---|
45 |
|
---|
46 | UITools::~UITools()
|
---|
47 | {
|
---|
48 | /* Cleanup: */
|
---|
49 | cleanup();
|
---|
50 | }
|
---|
51 |
|
---|
52 | UIActionPool *UITools::actionPool() const
|
---|
53 | {
|
---|
54 | return managerWidget()->actionPool();
|
---|
55 | }
|
---|
56 |
|
---|
57 | void UITools::setToolsClass(UIToolsClass enmClass)
|
---|
58 | {
|
---|
59 | m_pToolsModel->setToolsClass(enmClass);
|
---|
60 | }
|
---|
61 |
|
---|
62 | UIToolsClass UITools::toolsClass() const
|
---|
63 | {
|
---|
64 | return m_pToolsModel->toolsClass();
|
---|
65 | }
|
---|
66 |
|
---|
67 | UIToolsType UITools::toolsType() const
|
---|
68 | {
|
---|
69 | return m_pToolsModel->toolsType();
|
---|
70 | }
|
---|
71 |
|
---|
72 | void UITools::setToolsEnabled(UIToolsClass enmClass, bool fEnabled)
|
---|
73 | {
|
---|
74 | m_pToolsModel->setToolsEnabled(enmClass, fEnabled);
|
---|
75 | }
|
---|
76 |
|
---|
77 | bool UITools::areToolsEnabled(UIToolsClass enmClass) const
|
---|
78 | {
|
---|
79 | return m_pToolsModel->areToolsEnabled(enmClass);
|
---|
80 | }
|
---|
81 |
|
---|
82 | UIToolsItem *UITools::currentItem() const
|
---|
83 | {
|
---|
84 | return m_pToolsModel->currentItem();
|
---|
85 | }
|
---|
86 |
|
---|
87 | void UITools::prepare()
|
---|
88 | {
|
---|
89 | /* Prepare palette: */
|
---|
90 | preparePalette();
|
---|
91 | /* Prepare layout: */
|
---|
92 | prepareLayout();
|
---|
93 | /* Prepare model: */
|
---|
94 | prepareModel();
|
---|
95 | /* Prepare view: */
|
---|
96 | prepareView();
|
---|
97 | /* Prepare connections: */
|
---|
98 | prepareConnections();
|
---|
99 |
|
---|
100 | /* Load settings: */
|
---|
101 | loadSettings();
|
---|
102 | }
|
---|
103 |
|
---|
104 | void UITools::preparePalette()
|
---|
105 | {
|
---|
106 | /* Setup palette: */
|
---|
107 | setAutoFillBackground(true);
|
---|
108 | QPalette pal = palette();
|
---|
109 | QColor bodyColor = pal.color(QPalette::Active, QPalette::Midlight).darker(110);
|
---|
110 | pal.setColor(QPalette::Window, bodyColor);
|
---|
111 | setPalette(pal);
|
---|
112 | }
|
---|
113 |
|
---|
114 | void UITools::prepareLayout()
|
---|
115 | {
|
---|
116 | /* Setup own layout rules: */
|
---|
117 | setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
|
---|
118 |
|
---|
119 | /* Create main-layout: */
|
---|
120 | m_pMainLayout = new QVBoxLayout(this);
|
---|
121 | if (m_pMainLayout)
|
---|
122 | {
|
---|
123 | /* Configure main-layout: */
|
---|
124 | m_pMainLayout->setContentsMargins(1, 1, 1, 1);
|
---|
125 | m_pMainLayout->setSpacing(0);
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | void UITools::prepareModel()
|
---|
130 | {
|
---|
131 | /* Create Tools-model: */
|
---|
132 | m_pToolsModel = new UIToolsModel(this);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void UITools::prepareView()
|
---|
136 | {
|
---|
137 | /* Setup Tools-view: */
|
---|
138 | m_pToolsView = new UIToolsView(this);
|
---|
139 | if (m_pToolsView)
|
---|
140 | {
|
---|
141 | /* Configure Tools-view. */
|
---|
142 | m_pToolsView->setScene(m_pToolsModel->scene());
|
---|
143 | m_pToolsView->show();
|
---|
144 | setFocusProxy(m_pToolsView);
|
---|
145 |
|
---|
146 | /* Add into layout: */
|
---|
147 | m_pMainLayout->addWidget(m_pToolsView);
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | void UITools::prepareConnections()
|
---|
152 | {
|
---|
153 | /* Setup Tools-model connections: */
|
---|
154 | connect(m_pToolsModel, &UIToolsModel::sigItemMinimumWidthHintChanged,
|
---|
155 | m_pToolsView, &UIToolsView::sltMinimumWidthHintChanged);
|
---|
156 | connect(m_pToolsModel, &UIToolsModel::sigItemMinimumHeightHintChanged,
|
---|
157 | m_pToolsView, &UIToolsView::sltMinimumHeightHintChanged);
|
---|
158 | connect(m_pToolsModel, &UIToolsModel::sigFocusChanged,
|
---|
159 | m_pToolsView, &UIToolsView::sltFocusChanged);
|
---|
160 |
|
---|
161 | /* Setup Tools-view connections: */
|
---|
162 | connect(m_pToolsView, &UIToolsView::sigResized,
|
---|
163 | m_pToolsModel, &UIToolsModel::sltHandleViewResized);
|
---|
164 | }
|
---|
165 |
|
---|
166 | void UITools::loadSettings()
|
---|
167 | {
|
---|
168 | /* Init model: */
|
---|
169 | m_pToolsModel->init();
|
---|
170 | }
|
---|
171 |
|
---|
172 | void UITools::saveSettings()
|
---|
173 | {
|
---|
174 | /* Deinit model: */
|
---|
175 | m_pToolsModel->deinit();
|
---|
176 | }
|
---|
177 |
|
---|
178 | void UITools::cleanup()
|
---|
179 | {
|
---|
180 | /* Save settings: */
|
---|
181 | saveSettings();
|
---|
182 | }
|
---|