Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ListenerLocalVolumeDialog.cpp « mumble « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 50ee97c2415beec10f02a6742e0f98c7b5b5dce3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "ListenerLocalVolumeDialog.h"
#include "Channel.h"
#include "ChannelListener.h"
#include "ClientUser.h"

#include <QtWidgets/QPushButton>

#include <cmath>

ListenerLocalVolumeDialog::ListenerLocalVolumeDialog(ClientUser *user, Channel *channel, QWidget *parent)
	: QDialog(parent), m_user(user), m_channel(channel) {
	setupUi(this);

	m_initialAdjustemt = ChannelListener::getListenerLocalVolumeAdjustment(m_channel);

	// Decibel formula: +6db = *2
	// Calculate the db-shift from the set volume-faactor
	float fdbShift = log2f(m_initialAdjustemt) * 6;
	qsUserLocalVolume->setValue(static_cast< int >(roundf(fdbShift)));

	setWindowTitle(tr("Adjusting local volume for listening to %1").arg(channel->qsName));
}

void ListenerLocalVolumeDialog::on_qsUserLocalVolume_valueChanged(int value) {
	qsbUserLocalVolume->setValue(value);
}

void ListenerLocalVolumeDialog::on_qsbUserLocalVolume_valueChanged(int value) {
	qsUserLocalVolume->setValue(value);

	// Decibel formula: +6db = *2
	// Calculate the volume-factor for the set db-shift
	ChannelListener::setListenerLocalVolumeAdjustment(m_channel,
													  static_cast< float >(pow(2.0, qsUserLocalVolume->value() / 6.0)));
}

void ListenerLocalVolumeDialog::on_qbbUserLocalVolume_clicked(QAbstractButton *button) {
	if (button == qbbUserLocalVolume->button(QDialogButtonBox::Reset)) {
		qsUserLocalVolume->setValue(0);
	}
	if (button == qbbUserLocalVolume->button(QDialogButtonBox::Ok)) {
		ListenerLocalVolumeDialog::accept();
	}
	if (button == qbbUserLocalVolume->button(QDialogButtonBox::Cancel)) {
		ListenerLocalVolumeDialog::close();
	}
}

void ListenerLocalVolumeDialog::reject() {
	// Restore to what has been set before the dialog
	ChannelListener::setListenerLocalVolumeAdjustment(m_channel, m_initialAdjustemt);

	QDialog::reject();
}