VirtualBox

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

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

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: UIAudioControllerEditor.cpp 80081 2019-07-31 16:19:53Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIAudioControllerEditor 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 "UIAudioControllerEditor.h"
27
28
29UIAudioControllerEditor::UIAudioControllerEditor(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 UIAudioControllerEditor::setValue(KAudioControllerType 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
48KAudioControllerType UIAudioControllerEditor::value() const
49{
50 return m_pCombo ? m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioControllerType>() : KAudioControllerType_AC97;
51}
52
53void UIAudioControllerEditor::retranslateUi()
54{
55 if (m_pLabel)
56 m_pLabel->setText(tr("Audio &Controller:"));
57 if (m_pCombo)
58 {
59 for (int i = 0; i < m_pCombo->count(); ++i)
60 {
61 const KAudioControllerType enmType = m_pCombo->itemData(i).value<KAudioControllerType>();
62 m_pCombo->setItemText(i, gpConverter->toString(enmType));
63 }
64 }
65}
66
67void UIAudioControllerEditor::sltHandleCurrentIndexChanged()
68{
69 if (m_pCombo)
70 emit sigValueChanged(m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioControllerType>());
71}
72
73void UIAudioControllerEditor::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, &UIAudioControllerEditor::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 UIAudioControllerEditor::populateCombo()
120{
121 /* Fill combo manually: */
122 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioControllerType_HDA));
123 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioControllerType_AC97));
124 m_pCombo->addItem(QString(), QVariant::fromValue(KAudioControllerType_SB16));
125}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use