summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooser.cpp
blob: aba02e4dd52cbf37a8d37ed504a7fba198433690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* $Id$ */
/** @file
 * VBox Qt GUI - UIChooser class implementation.
 */

/*
 * Copyright (C) 2012-2019 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

/* Qt includes: */
#include <QVBoxLayout>

/* GUI includes: */
#include "UIChooser.h"
#include "UIChooserModel.h"
#include "UIChooserView.h"
#include "UIVirtualBoxManagerWidget.h"
#include "UICommon.h"


UIChooser::UIChooser(UIVirtualBoxManagerWidget *pParent)
    : QWidget(pParent)
    , m_pManagerWidget(pParent)
    , m_pMainLayout(0)
    , m_pChooserModel(0)
    , m_pChooserView(0)
{
    /* Prepare: */
    prepare();
}

UIChooser::~UIChooser()
{
    /* Cleanup: */
    cleanup();
}

UIActionPool *UIChooser::actionPool() const
{
    return managerWidget()->actionPool();
}

UIVirtualMachineItem *UIChooser::currentItem() const
{
    return m_pChooserModel->firstSelectedMachineItem();
}

QList<UIVirtualMachineItem*> UIChooser::currentItems() const
{
    return m_pChooserModel->selectedMachineItems();
}

bool UIChooser::isGroupItemSelected() const
{
    return m_pChooserModel->isGroupItemSelected();
}

bool UIChooser::isGlobalItemSelected() const
{
    return m_pChooserModel->isGlobalItemSelected();
}

bool UIChooser::isMachineItemSelected() const
{
    return m_pChooserModel->isMachineItemSelected();
}

bool UIChooser::isSingleGroupSelected() const
{
    return m_pChooserModel->isSingleGroupSelected();
}

bool UIChooser::isAllItemsOfOneGroupSelected() const
{
    return m_pChooserModel->isAllItemsOfOneGroupSelected();
}

bool UIChooser::isGroupSavingInProgress() const
{
    return m_pChooserModel->isGroupSavingInProgress();
}

void UIChooser::sltHandleToolbarResize(const QSize &newSize)
{
    /* Pass height to a model: */
    model()->setGlobalItemHeightHint(newSize.height());
}

void UIChooser::sltToolMenuRequested(UIToolClass enmClass, const QPoint &position)
{
    /* Translate scene coordinates to global one: */
    emit sigToolMenuRequested(enmClass, mapToGlobal(view()->mapFromScene(position)));
}

void UIChooser::prepare()
{
    /* Prepare palette: */
    preparePalette();
    /* Prepare layout: */
    prepareLayout();
    /* Prepare model: */
    prepareModel();
    /* Prepare view: */
    prepareView();
    /* Prepare connections: */
    prepareConnections();

    /* Load settings: */
    loadSettings();
}

void UIChooser::preparePalette()
{
    /* Setup palette: */
    setAutoFillBackground(true);
    QPalette pal = palette();
    QColor bodyColor = pal.color(QPalette::Active, QPalette::Midlight).darker(110);
    pal.setColor(QPalette::Window, bodyColor);
    setPalette(pal);
}

void UIChooser::prepareLayout()
{
    /* Create main-layout: */
    m_pMainLayout = new QVBoxLayout(this);
    if (m_pMainLayout)
    {
        /* Configure main-layout: */
        m_pMainLayout->setContentsMargins(0, 0, 0, 0);
        m_pMainLayout->setSpacing(0);
    }
}

void UIChooser::prepareModel()
{
    /* Create chooser-model: */
    m_pChooserModel = new UIChooserModel(this);
}

void UIChooser::prepareView()
{
    /* Setup chooser-view: */
    m_pChooserView = new UIChooserView(this);
    if (m_pChooserView)
    {
        /* Configure chooser-view. */
        m_pChooserView->setScene(m_pChooserModel->scene());
        m_pChooserView->show();
        setFocusProxy(m_pChooserView);

        /* Add into layout: */
        m_pMainLayout->addWidget(m_pChooserView);
    }
}

void UIChooser::prepareConnections()
{
    /* Setup chooser-model connections: */
    connect(m_pChooserModel, &UIChooserModel::sigRootItemMinimumWidthHintChanged,
            m_pChooserView, &UIChooserView::sltMinimumWidthHintChanged);
    connect(m_pChooserModel, &UIChooserModel::sigToolMenuRequested,
            this, &UIChooser::sltToolMenuRequested);

    /* Setup chooser-view connections: */
    connect(m_pChooserView, &UIChooserView::sigResized,
            m_pChooserModel, &UIChooserModel::sltHandleViewResized);
}

void UIChooser::loadSettings()
{
    /* Init model: */
    m_pChooserModel->init();
}

void UIChooser::saveSettings()
{
    /* Deinit model: */
    m_pChooserModel->deinit();
}

void UIChooser::cleanup()
{
    /* Save settings: */
    saveSettings();
}