VirtualBox

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

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

FE/Qt: bugref:7720: VM settings / Audio page: Replace heavily distributed across audio page widgets related to host driver editing functionality with single UIAudioHostDriverEditor.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: UIAudioHostDriverEditor.cpp 80079 2019-07-31 15:57:55Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIAudioHostDriverEditor class implementation.
4 */
5
6/*
7 * Copyright (C) 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 <QGridLayout>
20#include <QHBoxLayout>
21#include <QLabel>
22
23/* GUI includes: */
24#include "QIComboBox.h"
25#include "UIConverter.h"
26#include "UIAudioHostDriverEditor.h"
27
28
29UIAudioHostDriverEditor::UIAudioHostDriverEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */)
30 : QIWithRetranslateUI<QWidget>(pParent)
31 , m_fWithLabel(fWithLabel)
32 , m_pLabel(0)
33 , m_pCombo(0)
34{
35 prepare();
36}
37
38void UIAudioHostDriverEditor::setValue(KAudioDriverType enmValue)
39{
40 if (m_pCombo)
41 {
42 int iIndex = m_pCombo->findData(QVariant::fromValue(enmValue));
43 if (iIndex != -1)
44 m_pCombo->setCurrentIndex(iIndex);
45 }
46}
47
48KAudioDriverType UIAudioHostDriverEditor::value() const
49{
50 return m_pCombo ? m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioDriverType>() : KAudioDriverType_Null;
51}
52
53void UIAudioHostDriverEditor::retranslateUi()
54{
55 if (m_pLabel)
56 m_pLabel->setText(tr("Host Audio &Driver:"));
57 if (m_pCombo)
58 {
59 for (int i = 0; i < m_pCombo->count(); ++i)
60 {
61 const KAudioDriverType enmType = m_pCombo->itemData(i).value<KAudioDriverType>();
62 m_pCombo->setItemText(i, gpConverter->toString(enmType));
63 }
64 }
65}
66
67void UIAudioHostDriverEditor::sltHandleCurrentIndexChanged()
68{
69 if (m_pCombo)
70 emit sigValueChanged(m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioDriverType>());
71}
72
73void UIAudioHostDriverEditor::prepare()
74{
75 /* Create main layout: */
76 QGridLayout *pMainLayout = new QGridLayout(this);
77 if (pMainLayout)
78 {
79 pMainLayout->setContentsMargins(0, 0, 0, 0);
80 int iRow = 0;
81
82 /* Create label: */
83 if (m_fWithLabel)
84 m_pLabel = new QLabel(this);
85 if (m_pLabel)
86 pMainLayout->addWidget(m_pLabel, 0, iRow++, 1, 1);
87
88 /* Create combo layout: */
89 QHBoxLayout *pComboLayout = new QHBoxLayout;
90 if (pComboLayout)
91 {
92 /* Create combo: */
93 m_pCombo = new QIComboBox(this);
94 if (m_pCombo)
95 {
96 setFocusProxy(m_pCombo->focusProxy());
97 if (m_pLabel)
98 m_pLabel->setBuddy(m_pCombo->focusProxy());
99 connect(m_pCombo, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::currentIndexChanged),
100 this, &UIAudioHostDriverEditor::sltHandleCurrentIndexChanged);
101 pComboLayout->addWidget(m_pCombo);
102 }
103
104 /* Add stretch: */
105 pComboLayout->addStretch();
106
107 /* Add combo-layout into main-layout: */
108 pMainLayout->addLayout(pComboLayout, 0, iRow++, 1, 1);
109 }
110 }
111
112 /* Populate combo: */
113 populateCombo();
114
115 /* Apply language settings: */
116 retranslateUi();
117}
118
119void UIAudioHostDriverEditor::populateCombo()
120{
121 /* Fill combo manually: */
122 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_Null));
123#ifdef Q_OS_WIN
124 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_DirectSound));
125# ifdef VBOX_WITH_WINMM
126 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_WinMM));
127# endif
128#endif
129#ifdef VBOX_WITH_AUDIO_OSS
130 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_OSS));
131#endif
132#ifdef VBOX_WITH_AUDIO_ALSA
133 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_ALSA));
134#endif
135#ifdef VBOX_WITH_AUDIO_PULSE
136 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_Pulse));
137#endif
138#ifdef Q_OS_MACX
139 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_CoreAudio));
140#endif
141}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use