Child: [790848] (diff)

Download this file

volumewidget.cpp    105 lines (92 with data), 2.9 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
/* 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(int volume, bool ismute, QWidget *parent)
: VolumeWidgetIF(parent), m_mute(ismute)
{
setupUi(this);
volumeSlider->setMinimum(0);
volumeSlider->setMaximum(100);
connect(volumeSlider, SIGNAL(valueChanged(int)),
this, SLOT(onVolumeSliderChanged(int)));
connect(btn_mute, SIGNAL(clicked()),
this, SLOT(onButtonClicked()));
setUi(volume);
setMuteUi(m_mute);
}
void VolumeWidget::onVolumeSliderChanged(int value)
{
setupButton(value);
emit volumeChanged(value);
}
void VolumeWidget::onButtonClicked()
{
setMuteUi(!m_mute);
emit muteChanged(m_mute);
}
void VolumeWidget::set(int value)
{
setupButton(value);
volumeSlider->setValueNoSigs(value);
emit volumeChanged(value);
}
void VolumeWidget::step(int steps)
{
int current = 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);
}
volumeSlider->setValueNoSigs(value);
}
void VolumeWidget::setMuteUi(bool ismute)
{
m_mute = ismute;
qDebug() << "VolumeWidget::setMuteUi(" << m_mute << ")";
volumeSlider->setDisabled(m_mute);
if (m_mute) {
btn_mute->setIcon(QIcon(Helper::getIconPath() + "vol_mute.png"));
} else {
setupButton(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;
btn_mute->setIcon(QIcon(butFilename));
}