VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIGuestOSTypeSelectionButton.cpp@ 100347

Last change on this file since 100347 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: UIGuestOSTypeSelectionButton.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIGuestOSTypeSelectionButton class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes */
29#include <QMenu>
30#include <QSignalMapper>
31#include <QStyle>
32
33/* GUI includes */
34#include "UICommon.h"
35#include "UIGuestOSTypeSelectionButton.h"
36#include "UIIconPool.h"
37
38
39UIGuestOSTypeSelectionButton::UIGuestOSTypeSelectionButton(QWidget *pParent)
40 : QIWithRetranslateUI<QPushButton>(pParent)
41{
42 /* Determine icon metric: */
43 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
44 setIconSize(QSize(iIconMetric, iIconMetric));
45
46 /* We have to make sure that the button has strong focus, otherwise
47 * the editing is ended when the menu is shown: */
48 setFocusPolicy(Qt::StrongFocus);
49
50 /* Create a signal mapper so that we not have to react to
51 * every single menu activation ourself: */
52 m_pSignalMapper = new QSignalMapper(this);
53 if (m_pSignalMapper)
54#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
55 connect(m_pSignalMapper, static_cast<void(QSignalMapper::*)(const QString &)>(&QSignalMapper::mappedString),
56 this, &UIGuestOSTypeSelectionButton::setOSTypeId);
57#else
58 connect(m_pSignalMapper, static_cast<void(QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
59 this, &UIGuestOSTypeSelectionButton::setOSTypeId);
60#endif
61
62 /* Create main menu: */
63 m_pMainMenu = new QMenu(pParent);
64 if (m_pMainMenu)
65 setMenu(m_pMainMenu);
66
67 /* Apply language settings: */
68 retranslateUi();
69}
70
71bool UIGuestOSTypeSelectionButton::isMenuShown() const
72{
73 return m_pMainMenu->isVisible();
74}
75
76void UIGuestOSTypeSelectionButton::setOSTypeId(const QString &strOSTypeId)
77{
78 m_strOSTypeId = strOSTypeId;
79 CGuestOSType enmType = uiCommon().vmGuestOSType(strOSTypeId);
80
81#ifndef VBOX_WS_MAC
82 /* Looks ugly on the Mac: */
83 setIcon(generalIconPool().guestOSTypePixmapDefault(enmType.GetId()));
84#endif
85
86 setText(enmType.GetDescription());
87}
88
89void UIGuestOSTypeSelectionButton::retranslateUi()
90{
91 populateMenu();
92}
93
94void UIGuestOSTypeSelectionButton::populateMenu()
95{
96 /* Clea initially: */
97 m_pMainMenu->clear();
98
99 /* Create a list of all possible OS types: */
100 foreach(const QString &strFamilyId, uiCommon().vmGuestOSFamilyIDs())
101 {
102 QMenu *pSubMenu = m_pMainMenu->addMenu(uiCommon().vmGuestOSFamilyDescription(strFamilyId));
103 foreach (const CGuestOSType &comType, uiCommon().vmGuestOSTypeList(strFamilyId))
104 {
105 QAction *pAction = pSubMenu->addAction(generalIconPool().guestOSTypePixmapDefault(comType.GetId()),
106 comType.GetDescription());
107 connect(pAction, &QAction::triggered,
108 m_pSignalMapper, static_cast<void(QSignalMapper::*)(void)>(&QSignalMapper::map));
109 m_pSignalMapper->setMapping(pAction, comType.GetId());
110 }
111 }
112}
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