Parent: [ea731d] (diff)

Child: [729750] (diff)

Download this file

volumewidget.cpp    121 lines (105 with data), 3.2 kB

  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
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* Copyright (C) 2015 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "volumewidget.h"
#include "HelperStructs/Helper.h"
#include <QDebug>
VolumeWidget::VolumeWidget(QWidget *parent, bool horiz)
: VolumeWidgetIF(parent), ui(new Ui::VolumeWidget)
{
ui->setupUi(this, horiz);
init();
}
void VolumeWidget::init()
{
ui->volumeSlider->setMinimum(0);
ui->volumeSlider->setMaximum(100);
connect(ui->volumeSlider, SIGNAL(valueChanged(int)),
this, SLOT(onVolumeSliderChanged(int)));
connect(ui->btn_mute, SIGNAL(clicked()),
this, SLOT(onMuteClicked()));
setUi(20);
setMuteUi(m_mute = false);
}
void VolumeWidget::onVolumeSliderChanged(int value)
{
setupButton(value);
emit volumeChanged(value);
}
void VolumeWidget::toggleMute()
{
onMuteClicked();
}
void VolumeWidget::onMuteClicked()
{
setMuteUi(!m_mute);
emit muteChanged(m_mute);
}
void VolumeWidget::set(int value)
{
setupButton(value);
ui->volumeSlider->setValueNoSigs(value);
emit volumeChanged(value);
}
void VolumeWidget::step(int steps)
{
int current = ui->volumeSlider->value();
current += steps;
if (current < 0)
current = 0;
if (current > 100)
current = 100;
set(current);
}
void VolumeWidget::setUi(int value)
{
if (!m_mute) {
setupButton(value);
ui->volumeSlider->setValueNoSigs(value);
}
}
void VolumeWidget::setMuteUi(bool ismute)
{
m_mute = ismute;
//qDebug() << "VolumeWidget::setMuteUi(" << m_mute << ")";
ui->volumeSlider->setDisabled(m_mute);
if (m_mute) {
ui->btn_mute->setIcon(QIcon(Helper::getIconPath() + "vol_mute.png"));
} else {
setupButton(ui->volumeSlider->value());
}
}
void VolumeWidget::setSkinName(const QString& s)
{
m_skinSuffix = s.isEmpty() ? "" : "_" + s;
setupButton(ui->volumeSlider->value());
}
void VolumeWidget::setupButton(int value)
{
//qDebug() << "VolumeWidget::setupButton(" << value << ")";
QString butFilename = Helper::getIconPath() + "vol_";
if (value <= 1) {
butFilename += QString("mute") + m_skinSuffix + ".png";
} else if (value < 40) {
butFilename += QString("1") + m_skinSuffix + ".png";
} else if (value < 80) {
butFilename += QString("2") + m_skinSuffix + ".png";
} else {
butFilename += QString("3") + m_skinSuffix + ".png";
}
//qDebug() << "VolumeWidget::setupButton: fn: " << butFilename;
ui->btn_mute->setIcon(QIcon(butFilename));
}