diff options
Diffstat (limited to 'src')
5 files changed, 247 insertions, 57 deletions
diff --git a/src/VBox/Frontends/VirtualBox/Makefile.kmk b/src/VBox/Frontends/VirtualBox/Makefile.kmk index f8862e899bd..90ffaff8f2a 100644 --- a/src/VBox/Frontends/VirtualBox/Makefile.kmk +++ b/src/VBox/Frontends/VirtualBox/Makefile.kmk @@ -887,6 +887,7 @@ UICommon_QT_MOCHDRS = \ src/settings/machine/UIMachineSettingsUSB.h \ src/settings/machine/UIMachineSettingsUSBFilterDetails.h \ src/widgets/UIAddDiskEncryptionPasswordDialog.h \ + src/widgets/UIAudioHostDriverEditor.h \ src/widgets/UIBaseMemoryEditor.h \ src/widgets/UIBaseMemorySlider.h \ src/widgets/UIBootOrderEditor.h \ @@ -1381,6 +1382,7 @@ UICommon_SOURCES = \ src/settings/machine/UIMachineSettingsUSB.cpp \ src/settings/machine/UIMachineSettingsUSBFilterDetails.cpp \ src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \ + src/widgets/UIAudioHostDriverEditor.cpp \ src/widgets/UIBaseMemoryEditor.cpp \ src/widgets/UIBaseMemorySlider.cpp \ src/widgets/UIBootOrderEditor.cpp \ diff --git a/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp b/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp index 9db30223889..d927f5ba939 100644 --- a/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp +++ b/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp @@ -121,7 +121,7 @@ void UIMachineSettingsAudio::getFromCache() /* Load old audio data from the cache: */ m_pCheckBoxAudio->setChecked(oldAudioData.m_fAudioEnabled); - m_pComboAudioDriver->setCurrentIndex(m_pComboAudioDriver->findData((int)oldAudioData.m_audioDriverType)); + m_pAudioHostDriverEditor->setValue(oldAudioData.m_audioDriverType); m_pComboAudioController->setCurrentIndex(m_pComboAudioController->findData((int)oldAudioData.m_audioControllerType)); m_pCheckBoxAudioOutput->setChecked(oldAudioData.m_fAudioOutputEnabled); m_pCheckBoxAudioInput->setChecked(oldAudioData.m_fAudioInputEnabled); @@ -137,7 +137,7 @@ void UIMachineSettingsAudio::putToCache() /* Gather new audio data: */ newAudioData.m_fAudioEnabled = m_pCheckBoxAudio->isChecked(); - newAudioData.m_audioDriverType = static_cast<KAudioDriverType>(m_pComboAudioDriver->itemData(m_pComboAudioDriver->currentIndex()).toInt()); + newAudioData.m_audioDriverType = m_pAudioHostDriverEditor->value(); newAudioData.m_audioControllerType = static_cast<KAudioControllerType>(m_pComboAudioController->itemData(m_pComboAudioController->currentIndex()).toInt()); newAudioData.m_fAudioOutputEnabled = m_pCheckBoxAudioOutput->isChecked(); newAudioData.m_fAudioInputEnabled = m_pCheckBoxAudioInput->isChecked(); @@ -163,32 +163,9 @@ void UIMachineSettingsAudio::retranslateUi() /* Translate generated strings: */ Ui::UIMachineSettingsAudio::retranslateUi(this); - /* Translate audio-driver combo. - * Make sure this order corresponds the same in prepare(): */ - int iIndex = -1; - m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_Null)); -#ifdef Q_OS_WIN - m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_DirectSound)); -# ifdef VBOX_WITH_WINMM - m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_WinMM)); -# endif -#endif -#ifdef VBOX_WITH_AUDIO_OSS - m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_OSS)); -#endif -#ifdef VBOX_WITH_AUDIO_ALSA - m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_ALSA)); -#endif -#ifdef VBOX_WITH_AUDIO_PULSE - m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_Pulse)); -#endif -#ifdef Q_OS_MACX - m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_CoreAudio)); -#endif - /* Translate audio-controller combo. * Make sure this order corresponds the same in prepare(): */ - iIndex = -1; + int iIndex = -1; m_pComboAudioController->setItemText(++iIndex, gpConverter->toString(KAudioControllerType_HDA)); m_pComboAudioController->setItemText(++iIndex, gpConverter->toString(KAudioControllerType_AC97)); m_pComboAudioController->setItemText(++iIndex, gpConverter->toString(KAudioControllerType_SB16)); @@ -198,8 +175,8 @@ void UIMachineSettingsAudio::polishPage() { /* Polish audio page availability: */ m_pCheckBoxAudio->setEnabled(isMachineOffline()); - m_pLabelAudioDriver->setEnabled(isMachineOffline()); - m_pComboAudioDriver->setEnabled(isMachineOffline()); + m_pAudioHostDriverLabel->setEnabled(isMachineOffline()); + m_pAudioHostDriverEditor->setEnabled(isMachineOffline()); m_pLabelAudioController->setEnabled(isMachineOffline()); m_pComboAudioController->setEnabled(isMachineOffline()); m_pLabelAudioExtended->setEnabled(isMachineInValidMode()); @@ -219,31 +196,12 @@ void UIMachineSettingsAudio::prepare() /* Layout created in the .ui file. */ { - /* Audio-driver combo-box created in the .ui file. */ - AssertPtrReturnVoid(m_pComboAudioDriver); + /* Audio host-driver label & editor created in the .ui file. */ + AssertPtrReturnVoid(m_pAudioHostDriverLabel); + AssertPtrReturnVoid(m_pAudioHostDriverEditor); { - /* Configure combo-box. - * Make sure this order corresponds the same in retranslateUi(): */ - int iIndex = -1; - m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_Null); -#ifdef Q_OS_WIN - m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_DirectSound); -# ifdef VBOX_WITH_WINMM - m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_WinMM); -# endif -#endif -#ifdef VBOX_WITH_AUDIO_OSS - m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_OSS); -#endif -#ifdef VBOX_WITH_AUDIO_ALSA - m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_ALSA); -#endif -#ifdef VBOX_WITH_AUDIO_PULSE - m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_Pulse); -#endif -#ifdef Q_OS_MACX - m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_CoreAudio); -#endif + /* Configure label & editor: */ + m_pAudioHostDriverLabel->setBuddy(m_pAudioHostDriverEditor->focusProxy()); } /* Audio-controller combo-box created in the .ui file. */ diff --git a/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.ui b/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.ui index fd4ee3b036d..95c9e46ca6b 100644 --- a/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.ui +++ b/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.ui @@ -51,20 +51,17 @@ <number>0</number> </property> <item row="0" column="0"> - <widget class="QLabel" name="m_pLabelAudioDriver"> + <widget class="QLabel" name="m_pAudioHostDriverLabel"> <property name="text"> <string>Host Audio &Driver:</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> - <property name="buddy"> - <cstring>m_pComboAudioDriver</cstring> - </property> </widget> </item> <item row="0" column="1"> - <widget class="QComboBox" name="m_pComboAudioDriver"> + <widget class="UIAudioHostDriverEditor" name="m_pAudioHostDriverEditor"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>1</horstretch> @@ -166,6 +163,13 @@ </layout> </widget> <resources/> + <customwidgets> + <customwidget> + <class>UIAudioHostDriverEditor</class> + <extends>QWidget</extends> + <header>UIAudioHostDriverEditor.h</header> + </customwidget> + </customwidgets> <connections> <connection> <sender>m_pCheckBoxAudio</sender> diff --git a/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioHostDriverEditor.cpp b/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioHostDriverEditor.cpp new file mode 100644 index 00000000000..f9d6f5ecdc3 --- /dev/null +++ b/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioHostDriverEditor.cpp @@ -0,0 +1,141 @@ +/* $Id$ */ +/** @file + * VBox Qt GUI - UIAudioHostDriverEditor class implementation. + */ + +/* + * Copyright (C) 2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +/* Qt includes: */ +#include <QGridLayout> +#include <QHBoxLayout> +#include <QLabel> + +/* GUI includes: */ +#include "QIComboBox.h" +#include "UIConverter.h" +#include "UIAudioHostDriverEditor.h" + + +UIAudioHostDriverEditor::UIAudioHostDriverEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */) + : QIWithRetranslateUI<QWidget>(pParent) + , m_fWithLabel(fWithLabel) + , m_pLabel(0) + , m_pCombo(0) +{ + prepare(); +} + +void UIAudioHostDriverEditor::setValue(KAudioDriverType enmValue) +{ + if (m_pCombo) + { + int iIndex = m_pCombo->findData(QVariant::fromValue(enmValue)); + if (iIndex != -1) + m_pCombo->setCurrentIndex(iIndex); + } +} + +KAudioDriverType UIAudioHostDriverEditor::value() const +{ + return m_pCombo ? m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioDriverType>() : KAudioDriverType_Null; +} + +void UIAudioHostDriverEditor::retranslateUi() +{ + if (m_pLabel) + m_pLabel->setText(tr("Host Audio &Driver:")); + if (m_pCombo) + { + for (int i = 0; i < m_pCombo->count(); ++i) + { + const KAudioDriverType enmType = m_pCombo->itemData(i).value<KAudioDriverType>(); + m_pCombo->setItemText(i, gpConverter->toString(enmType)); + } + } +} + +void UIAudioHostDriverEditor::sltHandleCurrentIndexChanged() +{ + if (m_pCombo) + emit sigValueChanged(m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioDriverType>()); +} + +void UIAudioHostDriverEditor::prepare() +{ + /* Create main layout: */ + QGridLayout *pMainLayout = new QGridLayout(this); + if (pMainLayout) + { + pMainLayout->setContentsMargins(0, 0, 0, 0); + int iRow = 0; + + /* Create label: */ + if (m_fWithLabel) + m_pLabel = new QLabel(this); + if (m_pLabel) + pMainLayout->addWidget(m_pLabel, 0, iRow++, 1, 1); + + /* Create combo layout: */ + QHBoxLayout *pComboLayout = new QHBoxLayout; + if (pComboLayout) + { + /* Create combo: */ + m_pCombo = new QIComboBox(this); + if (m_pCombo) + { + setFocusProxy(m_pCombo->focusProxy()); + if (m_pLabel) + m_pLabel->setBuddy(m_pCombo->focusProxy()); + connect(m_pCombo, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::currentIndexChanged), + this, &UIAudioHostDriverEditor::sltHandleCurrentIndexChanged); + pComboLayout->addWidget(m_pCombo); + } + + /* Add stretch: */ + pComboLayout->addStretch(); + + /* Add combo-layout into main-layout: */ + pMainLayout->addLayout(pComboLayout, 0, iRow++, 1, 1); + } + } + + /* Populate combo: */ + populateCombo(); + + /* Apply language settings: */ + retranslateUi(); +} + +void UIAudioHostDriverEditor::populateCombo() +{ + /* Fill combo manually: */ + m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_Null)); +#ifdef Q_OS_WIN + m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_DirectSound)); +# ifdef VBOX_WITH_WINMM + m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_WinMM)); +# endif +#endif +#ifdef VBOX_WITH_AUDIO_OSS + m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_OSS)); +#endif +#ifdef VBOX_WITH_AUDIO_ALSA + m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_ALSA)); +#endif +#ifdef VBOX_WITH_AUDIO_PULSE + m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_Pulse)); +#endif +#ifdef Q_OS_MACX + m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_CoreAudio)); +#endif +} diff --git a/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioHostDriverEditor.h b/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioHostDriverEditor.h new file mode 100644 index 00000000000..2379f240425 --- /dev/null +++ b/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioHostDriverEditor.h @@ -0,0 +1,85 @@ +/* $Id$ */ +/** @file + * VBox Qt GUI - UIAudioHostDriverEditor class declaration. + */ + +/* + * Copyright (C) 2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef FEQT_INCLUDED_SRC_widgets_UIAudioHostDriverEditor_h +#define FEQT_INCLUDED_SRC_widgets_UIAudioHostDriverEditor_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +/* Qt includes: */ +#include <QWidget> + +/* GUI includes: */ +#include "QIWithRetranslateUI.h" +#include "UILibraryDefs.h" + +/* COM includes: */ +#include "COMEnums.h" + +/* Forward declarations: */ +class QLabel; +class QIComboBox; + +/** QWidget subclass used as a audio host driver editor. */ +class SHARED_LIBRARY_STUFF UIAudioHostDriverEditor : public QIWithRetranslateUI<QWidget> +{ + Q_OBJECT; + +signals: + + /** Notifies listeners about @a enmValue change. */ + void sigValueChanged(KAudioDriverType enmValue); + +public: + + /** Constructs audio host driver editor passing @a pParent to the base-class. + * @param fWithLabel Brings whether we should add label ourselves. */ + UIAudioHostDriverEditor(QWidget *pParent = 0, bool fWithLabel = false); + + /** Defines editor @a enmValue. */ + void setValue(KAudioDriverType enmValue); + /** Returns editor value. */ + KAudioDriverType value() const; + +protected: + + /** Handles translation event. */ + virtual void retranslateUi() /* override */; + +private slots: + + /** Handles current index change. */ + void sltHandleCurrentIndexChanged(); + +private: + + /** Prepares all. */ + void prepare(); + /** Populates combo. */ + void populateCombo(); + + /** Holds whether descriptive label should be created. */ + bool m_fWithLabel; + + /** Holds the label instance. */ + QLabel *m_pLabel; + /** Holds the combo instance. */ + QIComboBox *m_pCombo; +}; + +#endif /* !FEQT_INCLUDED_SRC_widgets_UIAudioHostDriverEditor_h */ |