23#include "volumeslider.h"
24#include "volumeslider_p.h"
25#include "audiooutput.h"
26#include "phonondefs_p.h"
27#include "phononnamespace_p.h"
30#ifndef QT_NO_PHONON_VOLUMESLIDER
36 k_ptr(new VolumeSliderPrivate(this))
42#ifndef QT_NO_WHATSTHIS
43 setWhatsThis(
tr(
"Use this slider to adjust the volume. The leftmost position is 0%, the rightmost is %1%").arg(100));
46 connect(&d->slider, SIGNAL(valueChanged(
int)), SLOT(_k_sliderChanged(
int)));
47 connect(&d->slider, SIGNAL(sliderPressed()),
this, SLOT(_k_sliderPressed()));
48 connect(&d->slider, SIGNAL(sliderReleased()),
this, SLOT(_k_sliderReleased()));
49 connect(&d->slider, SIGNAL(scrollStart()),
this, SLOT(_k_sliderPressed()));
50 connect(&d->slider, SIGNAL(scrollEnd()),
this, SLOT(_k_sliderReleased()));
51 connect(&d->muteButton, SIGNAL(clicked()), SLOT(_k_buttonClicked()));
58 k_ptr(new VolumeSliderPrivate(this))
64#ifndef QT_NO_WHATSTHIS
65 setWhatsThis(
tr(
"Use this slider to adjust the volume. The leftmost position is 0%, the rightmost is %1%").arg(100));
68 connect(&d->slider, SIGNAL(valueChanged(
int)), SLOT(_k_sliderChanged(
int)));
69 connect(&d->slider, SIGNAL(sliderPressed()),
this, SLOT(_k_sliderPressed()));
70 connect(&d->slider, SIGNAL(sliderReleased()),
this, SLOT(_k_sliderReleased()));
71 connect(&d->slider, SIGNAL(scrollStart()),
this, SLOT(_k_sliderPressed()));
72 connect(&d->slider, SIGNAL(scrollEnd()),
this, SLOT(_k_sliderReleased()));
73 connect(&d->muteButton, SIGNAL(clicked()), SLOT(_k_buttonClicked()));
77 d->slider.setValue(qRound(100 * output->
volume()));
78 d->slider.setEnabled(
true);
79 d->muteButton.setEnabled(
true);
80 connect(output, SIGNAL(volumeChanged(qreal)), SLOT(_k_volumeChanged(qreal)));
81 connect(output, SIGNAL(mutedChanged(
bool)), SLOT(_k_mutedChanged(
bool)));
87VolumeSlider::~VolumeSlider()
92bool VolumeSlider::isMuteVisible()
const
94 return !k_ptr->muteButton.isHidden();
97void VolumeSlider::setMuteVisible(
bool visible)
99 k_ptr->muteButton.setVisible(
visible);
104 return k_ptr->muteButton.iconSize();
107void VolumeSlider::setIconSize(
const QSize &iconSize)
109 pDebug() << Q_FUNC_INFO <<
iconSize;
110 k_ptr->muteButton.setIconSize(
iconSize);
115 return k_ptr->slider.maximum() * 0.01;
118void VolumeSlider::setMaximumVolume(qreal volume)
120 int max =
static_cast<int>(
volume * 100);
121 k_ptr->slider.setMaximum(max);
122#ifndef QT_NO_WHATSTHIS
123 setWhatsThis(
tr(
"Use this slider to adjust the volume. The leftmost position is 0%, the rightmost is %1%")
130 return k_ptr->slider.orientation();
137 d->layout.setAlignment(&d->muteButton, align);
138 d->layout.setAlignment(&d->slider, align);
140 d->slider.setOrientation(o);
143AudioOutput *VolumeSlider::audioOutput()
const
153 disconnect(d->output,
nullptr,
this,
nullptr);
157 d->slider.setValue(qRound(100 * output->
volume()));
158 d->slider.setEnabled(
true);
159 d->muteButton.setEnabled(
true);
161 d->_k_volumeChanged(output->
volume());
162 d->_k_mutedChanged(output->isMuted());
164 connect(output, SIGNAL(volumeChanged(qreal)), SLOT(_k_volumeChanged(qreal)));
165 connect(output, SIGNAL(mutedChanged(
bool)), SLOT(_k_mutedChanged(
bool)));
167 d->slider.setValue(100);
168 d->slider.setEnabled(
false);
169 d->muteButton.setEnabled(
false);
173void VolumeSliderPrivate::_k_buttonClicked()
176 output->setMuted(!output->isMuted());
178 slider.setEnabled(
false);
179 muteButton.setEnabled(
false);
183void VolumeSliderPrivate::_k_sliderPressed()
185 sliderPressed =
true;
188void VolumeSliderPrivate::_k_sliderReleased()
190 sliderPressed =
false;
192 _k_volumeChanged(output->
volume());
196void VolumeSliderPrivate::_k_mutedChanged(
bool muted)
205 muteButton.setIcon(mutedIcon);
210 muteButton.setIcon(volumeIcon);
214void VolumeSliderPrivate::_k_sliderChanged(
int value)
222 if (!output->isMuted()) {
227 qreal newvolume = (
static_cast<qreal
>(value)) * 0.01;
228 if (!ignoreVolumeChangeObserve && output->
volume() != newvolume) {
229 ignoreVolumeChangeAction =
true;
230 output->setVolume(newvolume);
233 slider.setEnabled(
false);
234 muteButton.setEnabled(
false);
237 ignoreVolumeChangeObserve =
false;
240void VolumeSliderPrivate::_k_volumeChanged(qreal value)
246 int newslidervalue = qRound(100 * value);
247 if (!ignoreVolumeChangeAction && slider.value() != newslidervalue) {
248 ignoreVolumeChangeObserve =
true;
249 slider.setValue(newslidervalue);
252 ignoreVolumeChangeAction =
false;
255bool VolumeSlider::hasTracking()
const
257 return k_ptr->slider.hasTracking();
260void VolumeSlider::setTracking(
bool tracking)
262 k_ptr->slider.setTracking(
tracking);
267 return k_ptr->slider.pageStep();
270void VolumeSlider::setPageStep(
int milliseconds)
272 k_ptr->slider.setPageStep(milliseconds);
277 return k_ptr->slider.singleStep();
280void VolumeSlider::setSingleStep(
int milliseconds)
282 k_ptr->slider.setSingleStep(milliseconds);
289#include "moc_volumeslider.cpp"
Class for audio output to the soundcard.
qreal volume
This is the current loudness of the output (it is using Stevens' law to calculate the change in volta...
Widget providing a slider to control the volume of an AudioOutput.
bool tracking
This property holds whether slider tracking is enabled.
void setAudioOutput(Phonon::AudioOutput *)
Sets the audio output object to be controlled by this slider.
Qt::Orientation orientation
This property holds the orientation of the slider.
qreal maximumVolume
This property holds the maximum volume that can be set with this slider.
int pageStep
This property holds the page step.
QSize iconSize
the icon size used for the mute button/icon.
int singleStep
This property holds the single step.
VolumeSlider(QWidget *parent=nullptr)
Constructs a new volume slider with a parent.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QString tr(const char *sourceText, const char *disambiguation, int n)