1 | /* $Id: UIGuestOSTypeSelectionButton.cpp 73119 2018-07-13 12:44:55Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIGuestOSTypeSelectionButton class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-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 <QMenu>
|
---|
24 | # include <QSignalMapper>
|
---|
25 | # include <QStyle>
|
---|
26 |
|
---|
27 | /* GUI includes */
|
---|
28 | # include "VBoxGlobal.h"
|
---|
29 | # include "UIGuestOSTypeSelectionButton.h"
|
---|
30 |
|
---|
31 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
32 |
|
---|
33 |
|
---|
34 | UIGuestOSTypeSelectionButton::UIGuestOSTypeSelectionButton(QWidget *pParent)
|
---|
35 | : QIWithRetranslateUI<QPushButton>(pParent)
|
---|
36 | {
|
---|
37 | /* Determine icon metric: */
|
---|
38 | const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
---|
39 | setIconSize(QSize(iIconMetric, iIconMetric));
|
---|
40 |
|
---|
41 | /* We have to make sure that the button has strong focus, otherwise
|
---|
42 | * the editing is ended when the menu is shown: */
|
---|
43 | setFocusPolicy(Qt::StrongFocus);
|
---|
44 |
|
---|
45 | /* Create a signal mapper so that we not have to react to
|
---|
46 | * every single menu activation ourself: */
|
---|
47 | m_pSignalMapper = new QSignalMapper(this);
|
---|
48 | if (m_pSignalMapper)
|
---|
49 | connect(m_pSignalMapper, static_cast<void(QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
|
---|
50 | this, &UIGuestOSTypeSelectionButton::setOSTypeId);
|
---|
51 |
|
---|
52 | /* Create main menu: */
|
---|
53 | m_pMainMenu = new QMenu(pParent);
|
---|
54 | if (m_pMainMenu)
|
---|
55 | setMenu(m_pMainMenu);
|
---|
56 |
|
---|
57 | /* Apply language settings: */
|
---|
58 | retranslateUi();
|
---|
59 | }
|
---|
60 |
|
---|
61 | bool UIGuestOSTypeSelectionButton::isMenuShown() const
|
---|
62 | {
|
---|
63 | return m_pMainMenu->isVisible();
|
---|
64 | }
|
---|
65 |
|
---|
66 | void UIGuestOSTypeSelectionButton::setOSTypeId(const QString &strOSTypeId)
|
---|
67 | {
|
---|
68 | m_strOSTypeId = strOSTypeId;
|
---|
69 | CGuestOSType enmType = vboxGlobal().vmGuestOSType(strOSTypeId);
|
---|
70 |
|
---|
71 | #ifndef VBOX_WS_MAC
|
---|
72 | /* Looks ugly on the Mac: */
|
---|
73 | setIcon(vboxGlobal().vmGuestOSTypePixmapDefault(enmType.GetId()));
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | setText(enmType.GetDescription());
|
---|
77 | }
|
---|
78 |
|
---|
79 | void UIGuestOSTypeSelectionButton::retranslateUi()
|
---|
80 | {
|
---|
81 | populateMenu();
|
---|
82 | }
|
---|
83 |
|
---|
84 | void UIGuestOSTypeSelectionButton::populateMenu()
|
---|
85 | {
|
---|
86 | /* Clea initially: */
|
---|
87 | m_pMainMenu->clear();
|
---|
88 |
|
---|
89 | /* Create a list of all possible OS types: */
|
---|
90 | foreach(const QString &strFamilyId, vboxGlobal().vmGuestOSFamilyIDs())
|
---|
91 | {
|
---|
92 | QMenu *pSubMenu = m_pMainMenu->addMenu(vboxGlobal().vmGuestOSFamilyDescription(strFamilyId));
|
---|
93 | foreach (const CGuestOSType &comType, vboxGlobal().vmGuestOSTypeList(strFamilyId))
|
---|
94 | {
|
---|
95 | QAction *pAction = pSubMenu->addAction(vboxGlobal().vmGuestOSTypePixmapDefault(comType.GetId()),
|
---|
96 | comType.GetDescription());
|
---|
97 | connect(pAction, &QAction::triggered,
|
---|
98 | m_pSignalMapper, static_cast<void(QSignalMapper::*)(void)>(&QSignalMapper::map));
|
---|
99 | m_pSignalMapper->setMapping(pAction, comType.GetId());
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|