Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[e8cdcd]: plugins / gui-standard-display / radioview_volume.cpp Maximize Restore History

Download this file

radioview_volume.cpp    149 lines (114 with data), 4.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***************************************************************************
radioview_volume.cpp - description
-------------------
begin : Don Jun 19 2003
copyright : (C) 2003 by Martin Witte
email : emw-kradio@nocabal.de
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <math.h>
#include <QtGui/QSlider>
#include <QtGui/QLayout>
#include <QtGui/QToolTip>
// #include <QtGui/QAccel>
#include <klocale.h>
#include "radioview_volume.h"
#include "pluginbase.h"
#define SLIDER_MINVAL 0
#define SLIDER_MAXVAL 32768
#define SLIDER_RANGE (SLIDER_MAXVAL - SLIDER_MINVAL)
RadioViewVolume::RadioViewVolume(QWidget *parent, const QString &name)
: RadioViewElement (parent, name, clsRadioSound),
m_slider(NULL),
m_handlingSlot(false),
m_volUpAction(parent),
m_volDownAction(parent)
{
float v = 0;
SoundStreamID ssid = queryCurrentSoundStreamSinkID();
sendLogDebug (QString ("RadioViewVolume: ssid=%1").arg(ssid.getID()));
queryPlaybackVolume(ssid, v);
m_slider = new QSlider(Qt::Vertical, this);
m_slider->setMinimum(SLIDER_MINVAL);
m_slider->setMaximum(SLIDER_MAXVAL);
m_slider->setPageStep(SLIDER_RANGE/10);
m_slider->setValue(getSlider4Volume(v));
QObject::connect(m_slider, SIGNAL(valueChanged(int)),
this, SLOT(slotVolumeChanged(int)));
QHBoxLayout *l = new QHBoxLayout(this);
l->setSpacing(0);
l->addWidget(m_slider);
// Tooltips
m_slider->setToolTip(i18n("Change volume"));
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
}
RadioViewVolume::~RadioViewVolume()
{
}
float RadioViewVolume::getUsability (Interface */*i*/) const
{
return 0.5; // there could be more features like mute control, capture settings, ...
}
bool RadioViewVolume::connectI (Interface *i)
{
bool a = IRadioDeviceClient::connectI(i);
bool b = ISoundStreamClient::connectI(i);
return a || b;
}
bool RadioViewVolume::disconnectI(Interface *i)
{
bool a = IRadioDeviceClient::disconnectI(i);
bool b = ISoundStreamClient::disconnectI(i);
return a || b;
}
void RadioViewVolume::noticeConnectedI (ISoundStreamServer *s, bool pointer_valid)
{
ISoundStreamClient::noticeConnectedI(s, pointer_valid);
if (s && pointer_valid) {
s->register4_notifyPlaybackVolumeChanged(this);
}
}
// ISoundStreamClient
bool RadioViewVolume::noticePlaybackVolumeChanged(SoundStreamID id, float v)
{
if (queryCurrentSoundStreamSinkID() != id)
return false;
m_slider->setValue(getSlider4Volume(v));
return true;
}
void RadioViewVolume::slotVolumeChanged(int val)
{
if (m_handlingSlot) return;
m_handlingSlot = true;
SoundStreamID ssid = queryCurrentSoundStreamSinkID();
sendPlaybackVolume(ssid, getVolume4Slider(val));
m_handlingSlot = false;
}
int RadioViewVolume::getSlider4Volume(float volume)
{
if (volume >= 1) volume = 1;
if (volume < 0) volume = 0;
return SLIDER_MINVAL + (int)rint(SLIDER_RANGE * volume);
}
float RadioViewVolume::getVolume4Slider(int sl)
{
if (sl > SLIDER_MAXVAL) sl = SLIDER_MAXVAL;
if (sl < SLIDER_MINVAL) sl = SLIDER_MINVAL;
return (float)(sl - SLIDER_MINVAL) / (float)SLIDER_RANGE;
}
void RadioViewVolume::slotStepUp()
{
m_slider->triggerAction(QAbstractSlider::SliderSingleStepAdd);
}
void RadioViewVolume::slotStepDown()
{
m_slider->triggerAction(QAbstractSlider::SliderSingleStepSub);
}
#include "radioview_volume.moc"