VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioControllerEditor.cpp@ 82968

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

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: UIAudioControllerEditor.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIAudioControllerEditor class implementation.
4 */
5
6/*
7 * Copyright (C) 2019-2020 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 <QGridLayout>
20#include <QHBoxLayout>
21#include <QLabel>
22
23/* GUI includes: */
24#include "QIComboBox.h"
25#include "UICommon.h"
26#include "UIConverter.h"
27#include "UIAudioControllerEditor.h"
28
29/* COM includes: */
30#include "CSystemProperties.h"
31
32
33UIAudioControllerEditor::UIAudioControllerEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */)
34 : QIWithRetranslateUI<QWidget>(pParent)
35 , m_fWithLabel(fWithLabel)
36 , m_enmValue(KAudioControllerType_Max)
37 , m_pLabel(0)
38 , m_pCombo(0)
39{
40 prepare();
41}
42
43void UIAudioControllerEditor::setValue(KAudioControllerType enmValue)
44{
45 if (m_pCombo)
46 {
47 /* Update cached value and
48 * combo if value has changed: */
49 if (m_enmValue != enmValue)
50 {
51 m_enmValue = enmValue;
52 populateCombo();
53 }
54
55 /* Look for proper index to choose: */
56 int iIndex = m_pCombo->findData(QVariant::fromValue(m_enmValue));
57 if (iIndex != -1)
58 m_pCombo->setCurrentIndex(iIndex);
59 }
60}
61
62KAudioControllerType UIAudioControllerEditor::value() const
63{
64 return m_pCombo ? m_pCombo->currentData().value<KAudioControllerType>() : m_enmValue;
65}
66
67void UIAudioControllerEditor::retranslateUi()
68{
69 if (m_pLabel)
70 m_pLabel->setText(tr("Audio &Controller:"));
71 if (m_pCombo)
72 {
73 for (int i = 0; i < m_pCombo->count(); ++i)
74 {
75 const KAudioControllerType enmType = m_pCombo->itemData(i).value<KAudioControllerType>();
76 m_pCombo->setItemText(i, gpConverter->toString(enmType));
77 }
78 }
79}
80
81void UIAudioControllerEditor::sltHandleCurrentIndexChanged()
82{
83 if (m_pCombo)
84 emit sigValueChanged(m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioControllerType>());
85}
86
87void UIAudioControllerEditor::prepare()
88{
89 /* Create main layout: */
90 QGridLayout *pMainLayout = new QGridLayout(this);
91 if (pMainLayout)
92 {
93 pMainLayout->setContentsMargins(0, 0, 0, 0);
94 int iRow = 0;
95
96 /* Create label: */
97 if (m_fWithLabel)
98 m_pLabel = new QLabel(this);
99 if (m_pLabel)
100 pMainLayout->addWidget(m_pLabel, 0, iRow++, 1, 1);
101
102 /* Create combo layout: */
103 QHBoxLayout *pComboLayout = new QHBoxLayout;
104 if (pComboLayout)
105 {
106 /* Create combo: */
107 m_pCombo = new QIComboBox(this);
108 if (m_pCombo)
109 {
110 setFocusProxy(m_pCombo->focusProxy());
111 /* This is necessary since contents is dynamical now: */
112 m_pCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
113 if (m_pLabel)
114 m_pLabel->setBuddy(m_pCombo->focusProxy());
115 connect(m_pCombo, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::currentIndexChanged),
116 this, &UIAudioControllerEditor::sltHandleCurrentIndexChanged);
117 pComboLayout->addWidget(m_pCombo);
118 }
119
120 /* Add stretch: */
121 pComboLayout->addStretch();
122
123 /* Add combo-layout into main-layout: */
124 pMainLayout->addLayout(pComboLayout, 0, iRow++, 1, 1);
125 }
126 }
127
128 /* Populate combo: */
129 populateCombo();
130
131 /* Apply language settings: */
132 retranslateUi();
133}
134
135void UIAudioControllerEditor::populateCombo()
136{
137 if (m_pCombo)
138 {
139 /* Clear combo first of all: */
140 m_pCombo->clear();
141
142 /* Load currently supported audio driver types: */
143 CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
144 m_supportedValues = comProperties.GetSupportedAudioControllerTypes();
145
146 /* Make sure requested value if sane is present as well: */
147 if ( m_enmValue != KAudioControllerType_Max
148 && !m_supportedValues.contains(m_enmValue))
149 m_supportedValues.prepend(m_enmValue);
150
151 /* Update combo with all the supported values: */
152 foreach (const KAudioControllerType &enmType, m_supportedValues)
153 m_pCombo->addItem(QString(), QVariant::fromValue(enmType));
154
155 /* Retranslate finally: */
156 retranslateUi();
157 }
158}
Note: See TracBrowser for help on using the repository browser.

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