VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UITools.cpp@ 74483

Last change on this file since 74483 was 74483, checked in by vboxsync, 6 years ago

FE/Qt: VirtualBox Manager: Chooser and Tools panes: Handle tools button click for machine/global items; rework Tools pane to be popup widget.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
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
35UITools::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
46UITools::~UITools()
47{
48 /* Cleanup: */
49 cleanup();
50}
51
52UIActionPool *UITools::actionPool() const
53{
54 return managerWidget()->actionPool();
55}
56
57void UITools::setToolsClass(UIToolsClass enmClass)
58{
59 m_pToolsModel->setToolsClass(enmClass);
60}
61
62UIToolsClass UITools::toolsClass() const
63{
64 return m_pToolsModel->toolsClass();
65}
66
67UIToolsType UITools::toolsType() const
68{
69 return m_pToolsModel->toolsType();
70}
71
72void UITools::setToolsEnabled(UIToolsClass enmClass, bool fEnabled)
73{
74 m_pToolsModel->setToolsEnabled(enmClass, fEnabled);
75}
76
77bool UITools::areToolsEnabled(UIToolsClass enmClass) const
78{
79 return m_pToolsModel->areToolsEnabled(enmClass);
80}
81
82UIToolsItem *UITools::currentItem() const
83{
84 return m_pToolsModel->currentItem();
85}
86
87void 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
104void 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
114void 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
129void UITools::prepareModel()
130{
131 /* Create Tools-model: */
132 m_pToolsModel = new UIToolsModel(this);
133}
134
135void 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
151void 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
166void UITools::loadSettings()
167{
168 /* Init model: */
169 m_pToolsModel->init();
170}
171
172void UITools::saveSettings()
173{
174 /* Deinit model: */
175 m_pToolsModel->deinit();
176}
177
178void UITools::cleanup()
179{
180 /* Save settings: */
181 saveSettings();
182}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette