Commit 00edf6b1 authored by Matthias Kretz's avatar Matthias Kretz

- Simplify SliderAction (and usage of it) a lot by using Phonon::SeekSlider and

  Phonon::VolumeSlider which also fixes seeking
- make PlayerManager::mute() use the mute property of AudioOutput

svn path=/trunk/KDE/kdemultimedia/juk/; revision=633015
parent 54a94dec
......@@ -96,7 +96,8 @@ kde4_add_executable(juk ${juk_SRCS})
# Add gstreamer here too...
target_link_libraries(juk m ${KDE4_KIO_LIBS} ${KDE4_KHTML_LIBS} ${TAGLIB_LIBRARIES} phononcore)
target_link_libraries(juk m ${KDE4_KIO_LIBS} ${KDE4_KHTML_LIBS} ${TAGLIB_LIBRARIES}
${KDE4_PHONONUI_LIBS})
if(TUNEPIMP_FOUND)
target_link_libraries(juk ${TUNEPIMP_LIBRARIES})
endif(TUNEPIMP_FOUND)
......
......@@ -361,10 +361,11 @@ void JuK::readConfig()
KConfigGroup playerConfig(KGlobal::config(), "Player");
if(m_sliderAction->volumeSlider()) {
int maxVolume = m_sliderAction->volumeSlider()->maximum();
int volume = playerConfig.readEntry("Volume", maxVolume);
m_sliderAction->volumeSlider()->setVolume(volume);
if(m_player)
{
const int maxVolume = 100;
const int volume = playerConfig.readEntry("Volume", maxVolume);
m_player->setVolume(volume * 0.01);
}
// Default to no random play
......@@ -402,9 +403,9 @@ void JuK::saveConfig()
KConfigGroup playerConfig(KGlobal::config(), "Player");
if (m_sliderAction->volumeSlider())
if (m_player)
{
playerConfig.writeEntry("Volume", m_sliderAction->volumeSlider()->volume());
playerConfig.writeEntry("Volume", static_cast<int>(100.0 * m_player->volume()));
}
playerConfig.writeEntry("RandomPlay", m_randomPlayAction->isChecked());
......
......@@ -117,7 +117,7 @@ bool PlayerManager::paused() const
float PlayerManager::volume() const
{
if(!m_output)
return 0;
return 1.0;
return m_output->volume();
}
......@@ -152,6 +152,7 @@ int PlayerManager::currentTime() const
return m_media->currentTime() / 1000;
}
/*
int PlayerManager::position() const
{
if(!m_media)
......@@ -162,6 +163,7 @@ int PlayerManager::position() const
return static_cast<int>(static_cast<float>(curr * SliderAction::maxPosition) / m_media->totalTime() + 0.5f);
return -1;
}
*/
QStringList PlayerManager::trackProperties()
{
......@@ -232,8 +234,6 @@ void PlayerManager::play(const FileHandle &file)
if(paused())
m_media->play();
else if(playing()) {
if(m_sliderAction->trackPositionSlider())
m_sliderAction->trackPositionSlider()->setValue(0);
m_media->seek(0);
}
else {
......@@ -268,9 +268,6 @@ void PlayerManager::play(const FileHandle &file)
action("forwardAlbum")->setEnabled(true);
action("back")->setEnabled(true);
if(m_sliderAction->trackPositionSlider())
m_sliderAction->trackPositionSlider()->setEnabled(true);
emit signalPlay();
}
......@@ -316,11 +313,6 @@ void PlayerManager::stop()
action("forward")->setEnabled(false);
action("forwardAlbum")->setEnabled(false);
if(m_sliderAction->trackPositionSlider()) {
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setEnabled(false);
}
m_media->stop();
m_playlistInterface->stop();
......@@ -344,6 +336,7 @@ void PlayerManager::seek(int seekTime)
m_media->seek(seekTime);
}
/*
void PlayerManager::seekPosition(int position)
{
if(!m_media)
......@@ -354,19 +347,21 @@ void PlayerManager::seekPosition(int position)
slotUpdateTime(position);
m_media->seek(static_cast<qint64>(static_cast<float>(m_media->totalTime() * position) / SliderAction::maxPosition + 0.5f));
if(m_sliderAction->trackPositionSlider())
m_sliderAction->trackPositionSlider()->setValue(position);
}
*/
void PlayerManager::seekForward()
{
seekPosition(qMin(SliderAction::maxPosition, position() + 10));
const qint64 total = m_media->totalTime();
const qint64 newtime = m_media->currentTime() + total / 100;
m_media->seek(qMin(total, newtime));
}
void PlayerManager::seekBack()
{
seekPosition(qMax(SliderAction::minPosition, position() - 10));
const qint64 total = m_media->totalTime();
const qint64 newtime = m_media->currentTime() - total / 100;
m_media->seek(qMax(qint64(0), newtime));
}
void PlayerManager::playPause()
......@@ -398,35 +393,28 @@ void PlayerManager::back()
void PlayerManager::volumeUp()
{
if(!m_media || !m_sliderAction || !m_sliderAction->volumeSlider())
if(!m_output)
return;
int volume = m_sliderAction->volumeSlider()->volume() +
m_sliderAction->volumeSlider()->maximum() / 25; // 4% up
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setVolume(volume);
float volume = m_output->volume() + 0.04; // 4% up
m_output->setVolume(volume);
}
void PlayerManager::volumeDown()
{
if(!m_media || !m_sliderAction || !m_sliderAction->volumeSlider())
if(!m_output)
return;
int volume = m_sliderAction->volumeSlider()->value() -
m_sliderAction->volumeSlider()->maximum() / 25; // 4% down
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setVolume(volume);
float volume = m_output->volume() - 0.04; // 4% up
m_output->setVolume(volume);
}
void PlayerManager::mute()
{
if(!m_media || !m_sliderAction || !m_sliderAction->volumeSlider())
if(!m_output)
return;
slotSetVolume(m_muted ? m_sliderAction->volumeSlider()->value() : 0);
m_muted = !m_muted;
m_output->setMuted(!m_output->isMuted());
}
////////////////////////////////////////////////////////////////////////////////
......@@ -476,56 +464,14 @@ void PlayerManager::slotTick(qint64 msec)
m_noSeek = true;
if(!m_sliderAction->dragging()) {
if(m_sliderAction->trackPositionSlider()) {
int position = static_cast<int>(static_cast<float>(msec * SliderAction::maxPosition) / m_media->totalTime() + 0.5f);
m_sliderAction->trackPositionSlider()->setValue(position);
}
if(m_statusLabel) {
m_statusLabel->setItemCurrentTime(msec / 1000);
}
}
// This call is done because when the user adds the slider to the toolbar
// while playback is occurring the volume slider generally defaults to 0,
// and doesn't get updated to the correct volume. It might be better to
// have the SliderAction class fill in the correct volume, but I'm trying
// to avoid having it depend on PlayerManager since it may not be
// constructed in time during startup. -mpyne
if(!m_sliderAction->volumeDragging() && m_sliderAction->volumeSlider())
{
int maxV = m_sliderAction->volumeSlider()->maximum();
float v = sqrt(sqrt(volume())); // Cancel out exponential scaling
m_sliderAction->volumeSlider()->blockSignals(true);
m_sliderAction->volumeSlider()->setVolume((int)((v) * maxV));
m_sliderAction->volumeSlider()->blockSignals(false);
if(m_statusLabel) {
m_statusLabel->setItemCurrentTime(msec / 1000);
}
m_noSeek = false;
}
void PlayerManager::slotSetVolume(int volume)
{
float scaledVolume;
if(m_sliderAction->volumeSlider())
scaledVolume = float(volume) / m_sliderAction->volumeSlider()->maximum();
else {
scaledVolume = float(volume) / 100.0; // Hopefully this is accurate
scaledVolume = qMin(1.0f, scaledVolume);
}
// Perform exponential scaling to counteract the fact that humans perceive
// volume changes logarithmically.
scaledVolume *= scaledVolume;
scaledVolume *= scaledVolume;
m_output->setVolume(scaledVolume); // scaledVolume ^ 4
}
/*
void PlayerManager::slotUpdateTime(int position)
{
if(!m_statusLabel)
......@@ -537,6 +483,7 @@ void PlayerManager::slotUpdateTime(int position)
m_statusLabel->setItemCurrentTime(seekTime);
}
*/
////////////////////////////////////////////////////////////////////////////////
// private members
......@@ -589,24 +536,21 @@ void PlayerManager::setup()
m_sliderAction = action<SliderAction>("trackPositionAction");
/*
connect(m_sliderAction, SIGNAL(signalPositionChanged(int)),
this, SLOT(seekPosition(int)));
connect(m_sliderAction->trackPositionSlider(), SIGNAL(valueChanged(int)),
this, SLOT(slotUpdateTime(int)));
connect(m_sliderAction, SIGNAL(signalVolumeChanged(int)),
this, SLOT(slotSetVolume(int)));
float volume;
*/
if(m_sliderAction->volumeSlider()) {
volume =
float(m_sliderAction->volumeSlider()->volume()) /
float(m_sliderAction->volumeSlider()->maximum());
if(m_sliderAction->trackPositionSlider())
{
m_sliderAction->trackPositionSlider()->setMediaProducer(m_media);
}
if(m_sliderAction->volumeSlider())
{
m_sliderAction->volumeSlider()->setAudioOutput(m_output);
}
else
volume = 1.0f; // Assume user wants full volume
m_output->setVolume(volume);
connect(m_media, SIGNAL(length(qint64)), SLOT(slotLength(qint64)));
connect(m_media, SIGNAL(tick(qint64)), SLOT(slotTick(qint64)));
......
......@@ -56,7 +56,7 @@ public:
int status() const;
int totalTime() const;
int currentTime() const;
int position() const;
//int position() const;
QStringList trackProperties();
QString trackProperty(const QString &property) const;
......@@ -81,7 +81,7 @@ public slots:
void stop();
void setVolume(float volume = 1.0);
void seek(int seekTime);
void seekPosition(int position);
//void seekPosition(int position);
void seekForward();
void seekBack();
void playPause();
......@@ -106,8 +106,7 @@ private slots:
void slotFinished();
void slotLength(qint64);
void slotTick(qint64);
void slotUpdateTime(int position);
void slotSetVolume(int volume);
//void slotUpdateTime(int position);
private:
FileHandle m_file;
......
......@@ -43,6 +43,7 @@
* to the left mouse button.
*/
#if 0
class TrackPositionSlider : public QSlider
{
public:
......@@ -65,25 +66,16 @@ protected:
}
}
};
#endif
////////////////////////////////////////////////////////////////////////////////
// VolumeSlider implementation
////////////////////////////////////////////////////////////////////////////////
VolumeSlider::VolumeSlider(Qt::Orientation o, QWidget *parent) :
QSlider(o, parent)
{
connect(this, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));
}
void VolumeSlider::wheelEvent(QWheelEvent *e)
Phonon::VolumeSlider(parent)
{
if(orientation() == Qt::Horizontal) {
QWheelEvent transposed(e->pos(), -(e->delta()), e->buttons(), e->modifiers(), e->orientation());
QSlider::wheelEvent(&transposed);
}
else
QSlider::wheelEvent(e);
setOrientation(o);
}
void VolumeSlider::focusInEvent(QFocusEvent *)
......@@ -91,57 +83,17 @@ void VolumeSlider::focusInEvent(QFocusEvent *)
clearFocus();
}
int VolumeSlider::volume() const
{
if(orientation() == Qt::Horizontal)
return value();
else
return maximum() - value();
}
void VolumeSlider::setVolume(int value)
{
if(orientation() == Qt::Horizontal)
setValue(value);
else
setValue(maximum() - value);
}
void VolumeSlider::setOrientation(Qt::Orientation o)
{
if(o == orientation())
return;
blockSignals(true);
setValue(maximum() - value());
blockSignals(false);
QSlider::setOrientation(o);
}
void VolumeSlider::slotValueChanged(int value)
{
if(orientation() == Qt::Horizontal)
emit signalVolumeChanged(value);
else
emit signalVolumeChanged(maximum() - value);
}
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
const int SliderAction::minPosition = 0;
const int SliderAction::maxPosition = 1000;
SliderAction::SliderAction(const QString &text, QObject* parent)
: KAction(text, parent),
m_toolBar(0),
m_widget(0),
m_layout(0),
m_trackPositionSlider(0),
m_volumeSlider(0),
m_dragging(false),
m_volumeDragging(false)
m_volumeSlider(0)
{
}
......@@ -162,7 +114,7 @@ int SliderAction::plug(QWidget *parent, int index)
// the check for null makes sure that there is only one toolbar that this is
// "plugged" in to
if(parent->inherits("KToolBar") && !m_toolBar) {
if(!m_toolBar && qobject_cast<KToolBar *>(parent)) {
m_toolBar = static_cast<KToolBar *>(parent);
// m_toolBar->insertWidget(id, m_widget->width(), m_widget, index);
......@@ -173,6 +125,13 @@ int SliderAction::plug(QWidget *parent, int index)
this, SLOT(slotUpdateOrientation()));
connect(m_toolBar, SIGNAL(placeChanged(Q3DockWindow::Place)),
this, SLOT(slotUpdateOrientation()));
if(m_volumeSlider)
{
connect(m_toolBar, SIGNAL(iconSizeChanged(QSize)), m_volumeSlider,
SLOT(setIconSize(QSize)));
connect(m_toolBar, SIGNAL(iconSizeChanged(QSize)), m_trackPositionSlider,
SLOT(setIconSize(QSize)));
}
slotUpdateOrientation();
return (associatedWidgets().count() - 1);
......@@ -216,37 +175,21 @@ QWidget *SliderAction::createToolBarWidget( QToolBar * parent )
m_layout->addItem(new QSpacerItem(20, 1));
QLabel *trackPositionLabel = new QLabel(base);
trackPositionLabel->setObjectName("kde toolbar widget");
trackPositionLabel->setPixmap(SmallIcon("player_time"));
trackPositionLabel->setToolTip( i18n("Track position"));
m_layout->addWidget(trackPositionLabel);
m_trackPositionSlider = new TrackPositionSlider(base);
m_trackPositionSlider = new Phonon::SeekSlider(base);
m_trackPositionSlider->setObjectName("trackPositionSlider");
m_trackPositionSlider->setOrientation(orientation);
m_trackPositionSlider->setMaximum(maxPosition);
m_trackPositionSlider->setToolTip( i18n("Track position"));
//m_trackPositionSlider->setToolTip( i18n("Track position"));
m_layout->addWidget(m_trackPositionSlider);
connect(m_trackPositionSlider, SIGNAL(sliderPressed()), this, SLOT(slotSliderPressed()));
connect(m_trackPositionSlider, SIGNAL(sliderReleased()), this, SLOT(slotSliderReleased()));
connect(parent, SIGNAL(iconSizeChanged(QSize)), m_trackPositionSlider,
SLOT(setIconSize(QSize)));
m_layout->addItem(new QSpacerItem(10, 1));
QLabel *volumeLabel = new QLabel(base);
volumeLabel->setObjectName("kde toolbar widget");
volumeLabel->setPixmap(SmallIcon("player_volume"));
volumeLabel->setToolTip( i18n("Volume"));
m_layout->addWidget(volumeLabel);
m_volumeSlider = new VolumeSlider(orientation, base);
m_volumeSlider->setObjectName("volumeSlider");
m_volumeSlider->setMaximum(100);
m_volumeSlider->setToolTip( i18n("Volume"));
m_layout->addWidget(m_volumeSlider);
connect(m_volumeSlider, SIGNAL(signalVolumeChanged(int)), SIGNAL(signalVolumeChanged(int)));
connect(m_volumeSlider, SIGNAL(sliderPressed()), this, SLOT(slotVolumeSliderPressed()));
connect(m_volumeSlider, SIGNAL(sliderReleased()), this, SLOT(slotVolumeSliderReleased()));
connect(parent, SIGNAL(iconSizeChanged(QSize)), m_volumeSlider,
SLOT(setIconSize(QSize)));
m_volumeSlider->setObjectName("kde toolbar widget");
m_trackPositionSlider->setObjectName("kde toolbar widget");
......@@ -315,36 +258,20 @@ QWidget *SliderAction::createWidget(QWidget *parent) // virtual -- used by base
m_layout->addItem(new QSpacerItem(20, 1));
QLabel *trackPositionLabel = new QLabel(base);
trackPositionLabel->setObjectName("kde toolbar widget");
trackPositionLabel->setPixmap(SmallIcon("player_time"));
trackPositionLabel->setToolTip( i18n("Track position"));
m_layout->addWidget(trackPositionLabel);
m_trackPositionSlider = new TrackPositionSlider(base);
m_trackPositionSlider = new Phonon::SeekSlider(base);
m_trackPositionSlider->setObjectName("trackPositionSlider");
m_trackPositionSlider->setMaximum(maxPosition);
m_trackPositionSlider->setToolTip( i18n("Track position"));
//m_trackPositionSlider->setToolTip( i18n("Track position"));
m_layout->addWidget(m_trackPositionSlider);
connect(m_trackPositionSlider, SIGNAL(sliderPressed()), this, SLOT(slotSliderPressed()));
connect(m_trackPositionSlider, SIGNAL(sliderReleased()), this, SLOT(slotSliderReleased()));
connect(parent, SIGNAL(iconSizeChanged(QSize)), m_trackPositionSlider,
SLOT(setIconSize(QSize)));
m_layout->addItem(new QSpacerItem(10, 1));
QLabel *volumeLabel = new QLabel(base);
volumeLabel->setObjectName("kde toolbar widget");
volumeLabel->setPixmap(SmallIcon("player_volume"));
volumeLabel->setToolTip( i18n("Volume"));
m_layout->addWidget(volumeLabel);
m_volumeSlider = new VolumeSlider(orientation, base);
m_volumeSlider->setObjectName("volumeSlider");
m_volumeSlider->setMaximum(100);
m_volumeSlider->setToolTip( i18n("Volume"));
m_layout->addWidget(m_volumeSlider);
connect(m_volumeSlider, SIGNAL(signalVolumeChanged(int)), SIGNAL(signalVolumeChanged(int)));
connect(m_volumeSlider, SIGNAL(sliderPressed()), this, SLOT(slotVolumeSliderPressed()));
connect(m_volumeSlider, SIGNAL(sliderReleased()), this, SLOT(slotVolumeSliderReleased()));
connect(parent, SIGNAL(iconSizeChanged(QSize)), m_volumeSlider,
SLOT(setIconSize(QSize)));
m_volumeSlider->setObjectName("kde toolbar widget");
m_trackPositionSlider->setObjectName("kde toolbar widget");
......@@ -392,28 +319,6 @@ void SliderAction::slotUpdateSize()
}
}
void SliderAction::slotSliderPressed()
{
m_dragging = true;
}
void SliderAction::slotSliderReleased()
{
m_dragging = false;
emit signalPositionChanged(m_trackPositionSlider->value());
}
void SliderAction::slotVolumeSliderPressed()
{
m_volumeDragging = true;
}
void SliderAction::slotVolumeSliderReleased()
{
m_volumeDragging = false;
emit signalVolumeChanged(m_volumeSlider->value());
}
void SliderAction::slotToolbarDestroyed()
{
#if 0 // what's going on here?
......
......@@ -17,37 +17,26 @@
#define SLIDERACTION_H
#include <kaction.h>
#include <qslider.h>
//Added by qt3to4:
#include <QWheelEvent>
#include <QFocusEvent>
#include <QBoxLayout>
#include <ktoolbar.h>
#include <phonon/ui/volumeslider.h>
#include <phonon/ui/seekslider.h>
class KActionCollection;
class QBoxLayout;
class Q3DockWindow;
class VolumeSlider : public QSlider
class VolumeSlider : public Phonon::VolumeSlider
{
Q_OBJECT
public:
VolumeSlider(Qt::Orientation o, QWidget *parent);
int volume() const;
void setVolume(int value);
void setOrientation(Qt::Orientation o);
signals:
void signalVolumeChanged(int value);
protected:
virtual void wheelEvent(QWheelEvent *e);
virtual void focusInEvent(QFocusEvent *);
private slots:
void slotValueChanged(int value);
};
class SliderAction : public KAction
......@@ -59,45 +48,29 @@ public:
virtual ~SliderAction();
VolumeSlider *volumeSlider() const { return m_volumeSlider; }
QSlider *trackPositionSlider() const { return m_trackPositionSlider; }
bool dragging() const { return m_dragging; }
bool volumeDragging() const { return m_volumeDragging; }
Phonon::SeekSlider *trackPositionSlider() const { return m_trackPositionSlider; }
virtual int plug(QWidget *parent, int index = -1);
virtual void unplug(QWidget *widget);
static const int minPosition;
static const int maxPosition;
virtual QWidget* createToolBarWidget(QToolBar* parent);
public slots:
void slotUpdateOrientation();
signals:
void signalPositionChanged(int position);
void signalVolumeChanged(int volume);
private:
QWidget *createWidget(QWidget *parent);
private slots:
void slotUpdateSize();
void slotVolumeSliderPressed();
void slotVolumeSliderReleased();
void slotSliderPressed();
void slotSliderReleased();
void slotToolbarDestroyed();
private:
KToolBar *m_toolBar;
QWidget *m_widget;
QBoxLayout *m_layout;
QSlider *m_trackPositionSlider;
Phonon::SeekSlider *m_trackPositionSlider;
VolumeSlider *m_volumeSlider;
bool m_dragging;
bool m_volumeDragging;
static const int volumeMax = 50;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment