mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-08-24 11:30:23 +02:00
Split logic and interface for HMD and desktop devices. Added CheckBox control based on QQC2
This commit is contained in:
parent
d0e7584f0f
commit
560696e41c
7 changed files with 436 additions and 114 deletions
111
interface/resources/qml/controls-uit/CheckBox2.qml
Normal file
111
interface/resources/qml/controls-uit/CheckBox2.qml
Normal file
|
@ -0,0 +1,111 @@
|
|||
//
|
||||
// CheckBox2.qml
|
||||
//
|
||||
// Created by Vlad Stelmahovsky on 10 Aug 2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
import "../styles-uit"
|
||||
import "../controls-uit" as HiFiControls
|
||||
|
||||
CheckBox {
|
||||
id: checkBox
|
||||
|
||||
HifiConstants { id: hifi; }
|
||||
|
||||
property int colorScheme: hifi.colorSchemes.light
|
||||
property string color: hifi.colors.lightGrayText
|
||||
readonly property bool isLightColorScheme: colorScheme === hifi.colorSchemes.light
|
||||
property bool isRedCheck: false
|
||||
property int boxSize: 14
|
||||
property int boxRadius: 3
|
||||
property bool wrap: true;
|
||||
readonly property int checkSize: Math.max(boxSize - 8, 10)
|
||||
readonly property int checkRadius: 2
|
||||
focusPolicy: Qt.ClickFocus
|
||||
|
||||
indicator: Rectangle {
|
||||
id: box
|
||||
width: boxSize
|
||||
height: boxSize
|
||||
radius: boxRadius
|
||||
x: checkBox.leftPadding
|
||||
y: parent.height / 2 - height / 2
|
||||
border.width: 1
|
||||
border.color: pressed || hovered
|
||||
? hifi.colors.checkboxCheckedBorder
|
||||
: (checkBox.isLightColorScheme ? hifi.colors.checkboxLightFinish : hifi.colors.checkboxDarkFinish)
|
||||
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0.2
|
||||
color: pressed || hovered
|
||||
? (checkBox.isLightColorScheme ? hifi.colors.checkboxChecked : hifi.colors.checkboxLightStart)
|
||||
: (checkBox.isLightColorScheme ? hifi.colors.checkboxLightStart : hifi.colors.checkboxDarkStart)
|
||||
}
|
||||
GradientStop {
|
||||
position: 1.0
|
||||
color: pressed || hovered
|
||||
? (checkBox.isLightColorScheme ? hifi.colors.checkboxChecked : hifi.colors.checkboxLightFinish)
|
||||
: (checkBox.isLightColorScheme ? hifi.colors.checkboxLightFinish : hifi.colors.checkboxDarkFinish)
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
visible: pressed || hovered
|
||||
anchors.centerIn: parent
|
||||
id: innerBox
|
||||
width: checkSize - 4
|
||||
height: width
|
||||
radius: checkRadius
|
||||
color: hifi.colors.checkboxCheckedBorder
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: check
|
||||
width: checkSize
|
||||
height: checkSize
|
||||
radius: checkRadius
|
||||
anchors.centerIn: parent
|
||||
color: isRedCheck ? hifi.colors.checkboxCheckedRed : hifi.colors.checkboxChecked
|
||||
border.width: 2
|
||||
border.color: isRedCheck? hifi.colors.checkboxCheckedBorderRed : hifi.colors.checkboxCheckedBorder
|
||||
visible: checked && !pressed || !checked && pressed
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: disabledOverlay
|
||||
visible: !enabled
|
||||
width: boxSize
|
||||
height: boxSize
|
||||
radius: boxRadius
|
||||
border.width: 1
|
||||
border.color: hifi.colors.baseGrayHighlight
|
||||
color: hifi.colors.baseGrayHighlight
|
||||
opacity: 0.5
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
id: root
|
||||
FontLoader { id: ralewaySemiBold; source: pathToFonts + "fonts/Raleway-SemiBold.ttf"; }
|
||||
font.pixelSize: hifi.fontSizes.inputLabel
|
||||
font.family: ralewaySemiBold.name
|
||||
text: checkBox.text
|
||||
color: checkBox.color
|
||||
x: 2
|
||||
wrapMode: checkBox.wrap ? Text.Wrap : Text.NoWrap
|
||||
elide: checkBox.wrap ? Text.ElideNone : Text.ElideRight
|
||||
enabled: checkBox.enabled
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
leftPadding: checkBox.indicator.width + checkBox.spacing
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
//
|
||||
|
||||
import QtQuick 2.5
|
||||
import QtQuick.Controls 1.4
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Layouts 1.3
|
||||
|
||||
import "../../styles-uit"
|
||||
|
@ -36,13 +36,27 @@ Rectangle {
|
|||
return (root.parent !== null) && root.parent.objectName == "loader";
|
||||
}
|
||||
|
||||
property bool isVR: Audio.context === "VR"
|
||||
//placeholder for control sizes and paddings
|
||||
//recalculates dynamically in case of UI size is changed
|
||||
QtObject {
|
||||
id: margins
|
||||
property real paddings: parent.width / 20.25
|
||||
|
||||
property real sizeCheckBox: parent.width / 13.5
|
||||
property real sizeText: parent.width / 2.5
|
||||
property real sizeLevel: parent.width / 5.8
|
||||
property real sizeDesktop: parent.width / 5.8
|
||||
property real sizeVR: parent.width / 13.5
|
||||
}
|
||||
|
||||
Column {
|
||||
y: 16; // padding does not work
|
||||
spacing: 16;
|
||||
width: parent.width;
|
||||
|
||||
RalewayRegular {
|
||||
x: 16; // padding does not work
|
||||
x: margins.paddings; // padding does not work
|
||||
size: 16;
|
||||
color: "white";
|
||||
text: root.title;
|
||||
|
@ -53,8 +67,9 @@ Rectangle {
|
|||
Separator { visible: root.showTitle() }
|
||||
|
||||
ColumnLayout {
|
||||
x: 16; // padding does not work
|
||||
x: margins.paddings; // padding does not work
|
||||
spacing: 16;
|
||||
width: parent.width;
|
||||
|
||||
// mute is in its own row
|
||||
RowLayout {
|
||||
|
@ -93,52 +108,106 @@ Rectangle {
|
|||
Separator {}
|
||||
|
||||
RowLayout {
|
||||
x: margins.paddings;
|
||||
width: parent.width - margins.paddings*2
|
||||
height: 28
|
||||
spacing: 0
|
||||
HiFiGlyphs {
|
||||
Layout.minimumWidth: margins.sizeCheckBox
|
||||
Layout.maximumWidth: margins.sizeCheckBox
|
||||
text: hifi.glyphs.mic;
|
||||
color: hifi.colors.primaryHighlight;
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 28;
|
||||
size: 36;
|
||||
}
|
||||
RalewayRegular {
|
||||
Layout.minimumWidth: margins.sizeText + margins.sizeLevel
|
||||
Layout.maximumWidth: margins.sizeText + margins.sizeLevel
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 16;
|
||||
color: hifi.colors.lightGrayText;
|
||||
text: qsTr("CHOOSE INPUT DEVICE");
|
||||
}
|
||||
|
||||
RalewayRegular {
|
||||
Layout.minimumWidth: margins.sizeDesktop
|
||||
Layout.maximumWidth: margins.sizeDesktop
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 16;
|
||||
color: hifi.colors.lightGrayText;
|
||||
text: qsTr("DESKTOP");
|
||||
}
|
||||
|
||||
RalewayRegular {
|
||||
Layout.minimumWidth: margins.sizeVR
|
||||
Layout.maximumWidth: margins.sizeVR
|
||||
Layout.alignment: Qt.AlignRight
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 16;
|
||||
color: hifi.colors.lightGrayText;
|
||||
text: qsTr("VR");
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
anchors { left: parent.left; right: parent.right; leftMargin: 70 }
|
||||
id: inputView
|
||||
width: parent.width - margins.paddings*2
|
||||
x: margins.paddings
|
||||
height: 125;
|
||||
spacing: 0;
|
||||
snapMode: ListView.SnapToItem;
|
||||
clip: true;
|
||||
model: Audio.devices.input;
|
||||
delegate: Item {
|
||||
width: parent.width;
|
||||
delegate: RowLayout {
|
||||
width: inputView.width;
|
||||
height: 36;
|
||||
|
||||
spacing: 0
|
||||
|
||||
RalewaySemiBold {
|
||||
Layout.minimumWidth: margins.sizeCheckBox + margins.sizeText
|
||||
Layout.maximumWidth: margins.sizeCheckBox + margins.sizeText
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
clip: true
|
||||
size: 16;
|
||||
color: "white";
|
||||
text: devicename;
|
||||
}
|
||||
|
||||
//placeholder for invisible level
|
||||
Item {
|
||||
Layout.minimumWidth: margins.sizeLevel
|
||||
Layout.maximumWidth: margins.sizeLevel
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
height: 8;
|
||||
InputLevel {
|
||||
visible: (isVR && selectedHMD) || (!isVR && selectedDesktop);
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
AudioControls.CheckBox {
|
||||
id: checkbox
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
text: display;
|
||||
wrap: false;
|
||||
checked: selected;
|
||||
enabled: false;
|
||||
Layout.minimumWidth: margins.sizeDesktop
|
||||
Layout.maximumWidth: margins.sizeDesktop
|
||||
leftPadding: margins.sizeDesktop - implicitWidth/2
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
checked: selectedDesktop;
|
||||
onClicked: {
|
||||
if (checked) {
|
||||
Audio.setInputDevice(info, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: checkbox
|
||||
onClicked: Audio.setInputDevice(info);
|
||||
}
|
||||
|
||||
InputLevel {
|
||||
id: level;
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 30
|
||||
visible: selected;
|
||||
AudioControls.CheckBox {
|
||||
Layout.minimumWidth: margins.sizeVR
|
||||
Layout.maximumWidth: margins.sizeVR
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
leftPadding: margins.sizeVR - implicitWidth/2
|
||||
checked: selectedHMD;
|
||||
onClicked: {
|
||||
if (checked) {
|
||||
Audio.setInputDevice(info, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,51 +215,104 @@ Rectangle {
|
|||
Separator {}
|
||||
|
||||
RowLayout {
|
||||
Column {
|
||||
RowLayout {
|
||||
HiFiGlyphs {
|
||||
text: hifi.glyphs.unmuted;
|
||||
color: hifi.colors.primaryHighlight;
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 36;
|
||||
}
|
||||
RalewayRegular {
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 16;
|
||||
color: hifi.colors.lightGrayText;
|
||||
text: qsTr("CHOOSE OUTPUT DEVICE");
|
||||
}
|
||||
}
|
||||
x: margins.paddings;
|
||||
width: parent.width - margins.paddings*2
|
||||
height: 28
|
||||
spacing: 0
|
||||
HiFiGlyphs {
|
||||
Layout.minimumWidth: margins.sizeCheckBox
|
||||
Layout.maximumWidth: margins.sizeCheckBox
|
||||
text: hifi.glyphs.unmuted;
|
||||
color: hifi.colors.primaryHighlight;
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 28;
|
||||
}
|
||||
RalewayRegular {
|
||||
Layout.minimumWidth: margins.sizeText + margins.sizeLevel
|
||||
Layout.maximumWidth: margins.sizeText + margins.sizeLevel
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 16;
|
||||
color: hifi.colors.lightGrayText;
|
||||
text: qsTr("CHOOSE OUTPUT DEVICE");
|
||||
}
|
||||
|
||||
PlaySampleSound { anchors { left: parent.left; leftMargin: 60 }}
|
||||
RalewayRegular {
|
||||
Layout.minimumWidth: margins.sizeDesktop
|
||||
Layout.maximumWidth: margins.sizeDesktop
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 16;
|
||||
color: hifi.colors.lightGrayText;
|
||||
text: qsTr("DESKTOP");
|
||||
}
|
||||
|
||||
RalewayRegular {
|
||||
Layout.minimumWidth: margins.sizeVR
|
||||
Layout.maximumWidth: margins.sizeVR
|
||||
Layout.alignment: Qt.AlignRight
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
size: 16;
|
||||
color: hifi.colors.lightGrayText;
|
||||
text: qsTr("VR");
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
anchors { left: parent.left; right: parent.right; leftMargin: 70 }
|
||||
height: Math.min(250, contentHeight);
|
||||
id: outputView
|
||||
width: parent.width - margins.paddings*2
|
||||
x: margins.paddings
|
||||
height: Math.min(220, contentHeight);
|
||||
spacing: 0;
|
||||
snapMode: ListView.SnapToItem;
|
||||
clip: true;
|
||||
model: Audio.devices.output;
|
||||
delegate: Item {
|
||||
width: parent.width;
|
||||
delegate: RowLayout {
|
||||
width: inputView.width;
|
||||
height: 36;
|
||||
spacing: 0
|
||||
|
||||
AudioControls.CheckBox {
|
||||
id: checkbox
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
text: display;
|
||||
checked: selected;
|
||||
enabled: false;
|
||||
RalewaySemiBold {
|
||||
Layout.minimumWidth: margins.sizeCheckBox + margins.sizeText
|
||||
Layout.maximumWidth: margins.sizeCheckBox + margins.sizeText
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
clip: true
|
||||
size: 16;
|
||||
color: "white";
|
||||
text: devicename;
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: checkbox
|
||||
onClicked: Audio.setOutputDevice(info);
|
||||
//placeholder for invisible level
|
||||
Item {
|
||||
Layout.minimumWidth: margins.sizeLevel
|
||||
Layout.maximumWidth: margins.sizeLevel
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
height: 8;
|
||||
}
|
||||
AudioControls.CheckBox {
|
||||
Layout.minimumWidth: margins.sizeDesktop
|
||||
Layout.maximumWidth: margins.sizeDesktop
|
||||
leftPadding: margins.sizeDesktop - implicitWidth/2
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
checked: selectedDesktop;
|
||||
onClicked: {
|
||||
if (checked) {
|
||||
Audio.setOutputDevice(info, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
AudioControls.CheckBox {
|
||||
Layout.minimumWidth: margins.sizeVR
|
||||
Layout.maximumWidth: margins.sizeVR
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
leftPadding: margins.sizeVR - implicitWidth/2
|
||||
checked: selectedHMD;
|
||||
onClicked: {
|
||||
if (checked) {
|
||||
Audio.setOutputDevice(info, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PlaySampleSound { anchors { left: parent.left; leftMargin: margins.paddings }}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
import QtQuick 2.5
|
||||
import QtQuick 2.7
|
||||
|
||||
import "../../controls-uit" as HifiControls
|
||||
|
||||
HifiControls.CheckBox {
|
||||
HifiControls.CheckBox2 {
|
||||
color: "white"
|
||||
}
|
||||
|
|
|
@ -135,10 +135,10 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) {
|
|||
DependencyManager::get<AudioClient>()->setReverbOptions(options);
|
||||
}
|
||||
|
||||
void Audio::setInputDevice(const QAudioDeviceInfo& device) {
|
||||
_devices.chooseInputDevice(device);
|
||||
void Audio::setInputDevice(const QAudioDeviceInfo& device, bool isHMD) {
|
||||
_devices.chooseInputDevice(device, isHMD);
|
||||
}
|
||||
|
||||
void Audio::setOutputDevice(const QAudioDeviceInfo& device) {
|
||||
_devices.chooseOutputDevice(device);
|
||||
void Audio::setOutputDevice(const QAudioDeviceInfo& device, bool isHMD) {
|
||||
_devices.chooseOutputDevice(device, isHMD);
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@ public:
|
|||
void showMicMeter(bool show);
|
||||
void setInputVolume(float volume);
|
||||
|
||||
Q_INVOKABLE void setInputDevice(const QAudioDeviceInfo& device);
|
||||
Q_INVOKABLE void setOutputDevice(const QAudioDeviceInfo& device);
|
||||
Q_INVOKABLE void setInputDevice(const QAudioDeviceInfo& device, bool isHMD);
|
||||
Q_INVOKABLE void setOutputDevice(const QAudioDeviceInfo& device, bool isHMD);
|
||||
Q_INVOKABLE void setReverb(bool enable);
|
||||
Q_INVOKABLE void setReverbOptions(const AudioEffectOptions* options);
|
||||
|
||||
|
|
|
@ -53,22 +53,28 @@ static QString getTargetDevice(bool hmd, QAudio::Mode mode) {
|
|||
}
|
||||
|
||||
QHash<int, QByteArray> AudioDeviceList::_roles {
|
||||
{ Qt::DisplayRole, "display" },
|
||||
{ Qt::CheckStateRole, "selected" },
|
||||
{ Qt::UserRole, "info" }
|
||||
{ AudioDeviceList::DeviceNameRole, "devicename" },
|
||||
{ AudioDeviceList::SelectedDesktopRole, "selectedDesktop" },
|
||||
{ AudioDeviceList::SelectedHMDRole, "selectedHMD" },
|
||||
{ AudioDeviceList::DeviceInfoRole, "info" }
|
||||
};
|
||||
|
||||
Qt::ItemFlags AudioDeviceList::_flags { Qt::ItemIsSelectable | Qt::ItemIsEnabled };
|
||||
|
||||
AudioDeviceList::AudioDeviceList(QAudio::Mode mode) : _mode(mode) {}
|
||||
|
||||
QVariant AudioDeviceList::data(const QModelIndex& index, int role) const {
|
||||
if (!index.isValid() || index.row() >= _devices.size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (role == DeviceNameRole) {
|
||||
return _devices.at(index.row()).display;
|
||||
} else if (role == Qt::CheckStateRole) {
|
||||
return _devices.at(index.row()).selected;
|
||||
} else if (role == Qt::UserRole) {
|
||||
} else if (role == SelectedDesktopRole) {
|
||||
return _devices.at(index.row()).selectedDesktop;
|
||||
} else if (role == SelectedHMDRole) {
|
||||
return _devices.at(index.row()).selectedHMD;
|
||||
} else if (role == DeviceInfoRole) {
|
||||
return QVariant::fromValue<QAudioDeviceInfo>(_devices.at(index.row()).info);
|
||||
} else {
|
||||
return QVariant();
|
||||
|
@ -109,36 +115,47 @@ void AudioDeviceList::resetDevice(bool contextIsHMD) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void AudioDeviceList::onDeviceChanged(const QAudioDeviceInfo& device) {
|
||||
auto oldDevice = _selectedDevice;
|
||||
_selectedDevice = device;
|
||||
void AudioDeviceList::onDeviceChanged(const QAudioDeviceInfo& device, bool isHMD) {
|
||||
auto oldDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice;
|
||||
QAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice;
|
||||
selectedDevice = device;
|
||||
|
||||
for (auto i = 0; i < _devices.size(); ++i) {
|
||||
AudioDevice& device = _devices[i];
|
||||
if (device.selected && device.info != _selectedDevice) {
|
||||
device.selected = false;
|
||||
} else if (device.info == _selectedDevice) {
|
||||
device.selected = true;
|
||||
bool &isSelected = isHMD ? device.selectedHMD : device.selectedDesktop;
|
||||
if (isSelected && device.info != selectedDevice) {
|
||||
isSelected = false;
|
||||
} else if (device.info == selectedDevice) {
|
||||
isSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
emit deviceChanged(_selectedDevice);
|
||||
emit deviceChanged(selectedDevice);
|
||||
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, 0));
|
||||
}
|
||||
|
||||
void AudioDeviceList::onDevicesChanged(const QList<QAudioDeviceInfo>& devices) {
|
||||
void AudioDeviceList::onDevicesChanged(const QList<QAudioDeviceInfo>& devices, bool isHMD) {
|
||||
QAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice;
|
||||
|
||||
const QString& savedDeviceName = isHMD ? _hmdSavedDeviceName : _desktopSavedDeviceName;
|
||||
beginResetModel();
|
||||
|
||||
_devices.clear();
|
||||
|
||||
foreach(const QAudioDeviceInfo& deviceInfo, devices) {
|
||||
AudioDevice device;
|
||||
bool &isSelected = isHMD ? device.selectedHMD : device.selectedDesktop;
|
||||
device.info = deviceInfo;
|
||||
device.display = device.info.deviceName()
|
||||
.replace("High Definition", "HD")
|
||||
.remove("Device")
|
||||
.replace(" )", ")");
|
||||
device.selected = (device.info == _selectedDevice);
|
||||
if (!selectedDevice.isNull()) {
|
||||
isSelected = (device.info == selectedDevice);
|
||||
} else {
|
||||
//no selected device for context. fallback to saved
|
||||
isSelected = (device.info.deviceName() == savedDeviceName);
|
||||
}
|
||||
_devices.push_back(device);
|
||||
}
|
||||
|
||||
|
@ -151,11 +168,18 @@ AudioDevices::AudioDevices(bool& contextIsHMD) : _contextIsHMD(contextIsHMD) {
|
|||
connect(client.data(), &AudioClient::deviceChanged, this, &AudioDevices::onDeviceChanged, Qt::QueuedConnection);
|
||||
connect(client.data(), &AudioClient::devicesChanged, this, &AudioDevices::onDevicesChanged, Qt::QueuedConnection);
|
||||
|
||||
_inputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioInput), contextIsHMD);
|
||||
_outputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioOutput), contextIsHMD);
|
||||
|
||||
// connections are made after client is initialized, so we must also fetch the devices
|
||||
_inputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioInput));
|
||||
_outputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioOutput));
|
||||
_inputs.onDevicesChanged(client->getAudioDevices(QAudio::AudioInput));
|
||||
_outputs.onDevicesChanged(client->getAudioDevices(QAudio::AudioOutput));
|
||||
const QList<QAudioDeviceInfo>& devicesInput = client->getAudioDevices(QAudio::AudioInput);
|
||||
const QList<QAudioDeviceInfo>& devicesOutput = client->getAudioDevices(QAudio::AudioOutput);
|
||||
//setup HMD devices
|
||||
_inputs.onDevicesChanged(devicesInput, true);
|
||||
_outputs.onDevicesChanged(devicesOutput, true);
|
||||
//setup Desktop devices
|
||||
_inputs.onDevicesChanged(devicesInput, false);
|
||||
_outputs.onDevicesChanged(devicesOutput, false);
|
||||
}
|
||||
|
||||
void AudioDevices::onContextChanged(const QString& context) {
|
||||
|
@ -163,10 +187,11 @@ void AudioDevices::onContextChanged(const QString& context) {
|
|||
_outputs.resetDevice(_contextIsHMD);
|
||||
}
|
||||
|
||||
void AudioDevices::onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& device, const QAudioDeviceInfo& previousDevice) {
|
||||
void AudioDevices::onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& device,
|
||||
const QAudioDeviceInfo& previousDevice, bool isHMD) {
|
||||
QString deviceName = device.isNull() ? QString() : device.deviceName();
|
||||
|
||||
auto& setting = getSetting(_contextIsHMD, mode);
|
||||
auto& setting = getSetting(isHMD, mode);
|
||||
|
||||
// check for a previous device
|
||||
auto wasDefault = setting.get().isNull();
|
||||
|
@ -202,42 +227,94 @@ void AudioDevices::onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& d
|
|||
void AudioDevices::onDeviceChanged(QAudio::Mode mode, const QAudioDeviceInfo& device) {
|
||||
if (mode == QAudio::AudioInput) {
|
||||
if (_requestedInputDevice == device) {
|
||||
onDeviceSelected(QAudio::AudioInput, device, _inputs._selectedDevice);
|
||||
onDeviceSelected(QAudio::AudioInput, device,
|
||||
_contextIsHMD ? _inputs._selectedHMDDevice : _inputs._selectedDesktopDevice,
|
||||
_contextIsHMD);
|
||||
_requestedInputDevice = QAudioDeviceInfo();
|
||||
}
|
||||
_inputs.onDeviceChanged(device);
|
||||
_inputs.onDeviceChanged(device, _contextIsHMD);
|
||||
} else { // if (mode == QAudio::AudioOutput)
|
||||
if (_requestedOutputDevice == device) {
|
||||
onDeviceSelected(QAudio::AudioOutput, device, _outputs._selectedDevice);
|
||||
onDeviceSelected(QAudio::AudioOutput, device,
|
||||
_contextIsHMD ? _outputs._selectedHMDDevice : _outputs._selectedDesktopDevice,
|
||||
_contextIsHMD);
|
||||
_requestedOutputDevice = QAudioDeviceInfo();
|
||||
}
|
||||
_outputs.onDeviceChanged(device);
|
||||
_outputs.onDeviceChanged(device, _contextIsHMD);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDevices::onDevicesChanged(QAudio::Mode mode, const QList<QAudioDeviceInfo>& devices) {
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [&] {
|
||||
//readout settings
|
||||
auto client = DependencyManager::get<AudioClient>();
|
||||
|
||||
_inputs._hmdSavedDeviceName = getTargetDevice(true, QAudio::AudioInput);
|
||||
_inputs._desktopSavedDeviceName = getTargetDevice(false, QAudio::AudioInput);
|
||||
|
||||
//fallback to default device
|
||||
if (_inputs._desktopSavedDeviceName.isEmpty()) {
|
||||
_inputs._desktopSavedDeviceName = client->getActiveAudioDevice(QAudio::AudioInput).deviceName();
|
||||
}
|
||||
//fallback to desktop device
|
||||
if (_inputs._hmdSavedDeviceName.isEmpty()) {
|
||||
_inputs._hmdSavedDeviceName = _inputs._desktopSavedDeviceName;
|
||||
}
|
||||
|
||||
_outputs._hmdSavedDeviceName = getTargetDevice(true, QAudio::AudioOutput);
|
||||
_outputs._desktopSavedDeviceName = getTargetDevice(false, QAudio::AudioOutput);
|
||||
|
||||
if (_outputs._desktopSavedDeviceName.isEmpty()) {
|
||||
_outputs._desktopSavedDeviceName = client->getActiveAudioDevice(QAudio::AudioOutput).deviceName();
|
||||
}
|
||||
if (_outputs._hmdSavedDeviceName.isEmpty()) {
|
||||
_outputs._hmdSavedDeviceName = _outputs._desktopSavedDeviceName;
|
||||
}
|
||||
onContextChanged(QString());
|
||||
});
|
||||
|
||||
//set devices for both contexts
|
||||
if (mode == QAudio::AudioInput) {
|
||||
_inputs.onDevicesChanged(devices);
|
||||
_inputs.onDevicesChanged(devices, _contextIsHMD);
|
||||
_inputs.onDevicesChanged(devices, !_contextIsHMD);
|
||||
} else { // if (mode == QAudio::AudioOutput)
|
||||
_outputs.onDevicesChanged(devices);
|
||||
_outputs.onDevicesChanged(devices, _contextIsHMD);
|
||||
_outputs.onDevicesChanged(devices, !_contextIsHMD);
|
||||
}
|
||||
std::call_once(once, [&] { onContextChanged(QString()); });
|
||||
}
|
||||
|
||||
|
||||
void AudioDevices::chooseInputDevice(const QAudioDeviceInfo& device) {
|
||||
auto client = DependencyManager::get<AudioClient>();
|
||||
_requestedInputDevice = device;
|
||||
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
||||
Q_ARG(QAudio::Mode, QAudio::AudioInput),
|
||||
Q_ARG(const QAudioDeviceInfo&, device));
|
||||
void AudioDevices::chooseInputDevice(const QAudioDeviceInfo& device, bool isHMD) {
|
||||
//check if current context equals device to change
|
||||
if (_contextIsHMD == isHMD) {
|
||||
auto client = DependencyManager::get<AudioClient>();
|
||||
_requestedInputDevice = device;
|
||||
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
||||
Q_ARG(QAudio::Mode, QAudio::AudioInput),
|
||||
Q_ARG(const QAudioDeviceInfo&, device));
|
||||
} else {
|
||||
//context is different. just save device in settings
|
||||
onDeviceSelected(QAudio::AudioInput, device,
|
||||
isHMD ? _inputs._selectedHMDDevice : _inputs._selectedDesktopDevice,
|
||||
isHMD);
|
||||
_inputs.onDeviceChanged(device, isHMD);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDevices::chooseOutputDevice(const QAudioDeviceInfo& device) {
|
||||
auto client = DependencyManager::get<AudioClient>();
|
||||
_requestedOutputDevice = device;
|
||||
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
||||
Q_ARG(QAudio::Mode, QAudio::AudioOutput),
|
||||
Q_ARG(const QAudioDeviceInfo&, device));
|
||||
void AudioDevices::chooseOutputDevice(const QAudioDeviceInfo& device, bool isHMD) {
|
||||
//check if current context equals device to change
|
||||
if (_contextIsHMD == isHMD) {
|
||||
auto client = DependencyManager::get<AudioClient>();
|
||||
_requestedOutputDevice = device;
|
||||
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
||||
Q_ARG(QAudio::Mode, QAudio::AudioOutput),
|
||||
Q_ARG(const QAudioDeviceInfo&, device));
|
||||
} else {
|
||||
//context is different. just save device in settings
|
||||
onDeviceSelected(QAudio::AudioOutput, device,
|
||||
isHMD ? _outputs._selectedHMDDevice : _outputs._selectedDesktopDevice,
|
||||
isHMD);
|
||||
_outputs.onDeviceChanged(device, isHMD);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,14 +22,22 @@ class AudioDevice {
|
|||
public:
|
||||
QAudioDeviceInfo info;
|
||||
QString display;
|
||||
bool selected { false };
|
||||
bool selectedDesktop { false };
|
||||
bool selectedHMD { false };
|
||||
};
|
||||
|
||||
class AudioDeviceList : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
||||
enum AudioDeviceRoles {
|
||||
DeviceNameRole = Qt::UserRole + 1,
|
||||
SelectedDesktopRole,
|
||||
SelectedHMDRole,
|
||||
DeviceInfoRole
|
||||
};
|
||||
|
||||
public:
|
||||
AudioDeviceList(QAudio::Mode mode) : _mode(mode) {}
|
||||
AudioDeviceList(QAudio::Mode mode);
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override { Q_UNUSED(parent); return _devices.size(); }
|
||||
QHash<int, QByteArray> roleNames() const override { return _roles; }
|
||||
|
@ -45,8 +53,8 @@ signals:
|
|||
void deviceChanged(const QAudioDeviceInfo& device);
|
||||
|
||||
private slots:
|
||||
void onDeviceChanged(const QAudioDeviceInfo& device);
|
||||
void onDevicesChanged(const QList<QAudioDeviceInfo>& devices);
|
||||
void onDeviceChanged(const QAudioDeviceInfo& device, bool isHMD);
|
||||
void onDevicesChanged(const QList<QAudioDeviceInfo>& devices, bool isHMD);
|
||||
|
||||
private:
|
||||
friend class AudioDevices;
|
||||
|
@ -54,8 +62,11 @@ private:
|
|||
static QHash<int, QByteArray> _roles;
|
||||
static Qt::ItemFlags _flags;
|
||||
const QAudio::Mode _mode;
|
||||
QAudioDeviceInfo _selectedDevice;
|
||||
QAudioDeviceInfo _selectedDesktopDevice;
|
||||
QAudioDeviceInfo _selectedHMDDevice;
|
||||
QList<AudioDevice> _devices;
|
||||
QString _hmdSavedDeviceName;
|
||||
QString _desktopSavedDeviceName;
|
||||
};
|
||||
|
||||
class Audio;
|
||||
|
@ -67,15 +78,16 @@ class AudioDevices : public QObject {
|
|||
|
||||
public:
|
||||
AudioDevices(bool& contextIsHMD);
|
||||
void chooseInputDevice(const QAudioDeviceInfo& device);
|
||||
void chooseOutputDevice(const QAudioDeviceInfo& device);
|
||||
void chooseInputDevice(const QAudioDeviceInfo& device, bool isHMD);
|
||||
void chooseOutputDevice(const QAudioDeviceInfo& device, bool isHMD);
|
||||
|
||||
signals:
|
||||
void nop();
|
||||
|
||||
private slots:
|
||||
void onContextChanged(const QString& context);
|
||||
void onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& device, const QAudioDeviceInfo& previousDevice);
|
||||
void onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& device,
|
||||
const QAudioDeviceInfo& previousDevice, bool isHMD);
|
||||
void onDeviceChanged(QAudio::Mode mode, const QAudioDeviceInfo& device);
|
||||
void onDevicesChanged(QAudio::Mode mode, const QList<QAudioDeviceInfo>& devices);
|
||||
|
||||
|
|
Loading…
Reference in a new issue