VirtualBox

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

Last change on this file since 82781 was 79365, checked in by vboxsync, 5 years ago

Renaming VBoxGlobal to UICommon for bugref:9049 as planned.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use