Commit 0a20efd1 authored by Michael Pyne's avatar Michael Pyne

My New's Year's gift to people: Fix bug 95447 (Juk crashes without "track...

My New's Year's gift to people:  Fix bug 95447 (Juk crashes without "track position" in the toolbar) in HEAD.

In addition I think I finally fixed the bug where re-arranging the track position entry in the toolbar would cause INSANE amounts of vertical space to be used.

Minor code formatting changes were also done, such as converting slideraction.cpp to be all one style of spacing.

I think this can be backported, I'll try to do so tonight.

CCBUG:95447

svn path=/trunk/kdemultimedia/juk/; revision=374583
parent d5fca087
......@@ -239,7 +239,8 @@ void PlayerManager::play(const FileHandle &file)
if(player()->paused())
player()->play();
else if(player()->playing()) {
m_sliderAction->trackPositionSlider()->setValue(0);
if(m_sliderAction->trackPositionSlider())
m_sliderAction->trackPositionSlider()->setValue(0);
player()->seekPosition(0);
}
else {
......@@ -267,7 +268,8 @@ void PlayerManager::play(const FileHandle &file)
action("forward")->setEnabled(true);
action("back")->setEnabled(true);
m_sliderAction->trackPositionSlider()->setEnabled(true);
if(m_sliderAction->trackPositionSlider())
m_sliderAction->trackPositionSlider()->setEnabled(true);
m_timer->start(m_pollInterval);
......@@ -318,8 +320,10 @@ void PlayerManager::stop()
action("back")->setEnabled(false);
action("forward")->setEnabled(false);
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setEnabled(false);
if(m_sliderAction->trackPositionSlider()) {
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setEnabled(false);
}
player()->stop();
m_playlistInterface->stop();
......@@ -355,19 +359,19 @@ void PlayerManager::seekPosition(int position)
slotUpdateTime(position);
player()->seekPosition(position);
m_sliderAction->trackPositionSlider()->setValue(position);
if(m_sliderAction->trackPositionSlider())
m_sliderAction->trackPositionSlider()->setValue(position);
}
void PlayerManager::seekForward()
{
int position = m_sliderAction->trackPositionSlider()->value();
seekPosition(kMin(m_sliderAction->trackPositionSlider()->maxValue(), position + 10));
seekPosition(kMin(SliderAction::maxPosition, position() + 10));
}
void PlayerManager::seekBack()
{
int position = m_sliderAction->trackPositionSlider()->value();
seekPosition(kMax(m_sliderAction->trackPositionSlider()->minValue(), position - 10));
seekPosition(kMax(SliderAction::minPosition, position() - 10));
}
void PlayerManager::playPause()
......@@ -399,7 +403,7 @@ void PlayerManager::back()
void PlayerManager::volumeUp()
{
if(!player() || !m_sliderAction)
if(!player() || !m_sliderAction || !m_sliderAction->volumeSlider())
return;
int volume = m_sliderAction->volumeSlider()->volume() +
......@@ -411,7 +415,7 @@ void PlayerManager::volumeUp()
void PlayerManager::volumeDown()
{
if(!player() || !m_sliderAction)
if(!player() || !m_sliderAction || !m_sliderAction->volumeSlider())
return;
int volume = m_sliderAction->volumeSlider()->value() -
......@@ -423,7 +427,7 @@ void PlayerManager::volumeDown()
void PlayerManager::mute()
{
if(!player() || !m_sliderAction)
if(!player() || !m_sliderAction || !m_sliderAction->volumeSlider())
return;
slotSetVolume(m_muted ? m_sliderAction->volumeSlider()->value() : 0);
......@@ -452,7 +456,8 @@ void PlayerManager::slotPollPlay()
stop();
}
else if(!m_sliderAction->dragging()) {
m_sliderAction->trackPositionSlider()->setValue(player()->position());
if(m_sliderAction->trackPositionSlider())
m_sliderAction->trackPositionSlider()->setValue(player()->position());
if(m_statusLabel) {
m_statusLabel->setItemTotalTime(player()->totalTime());
......@@ -460,6 +465,16 @@ void PlayerManager::slotPollPlay()
}
}
// This call is done because when the user adds the slider to the toolbar
// while playback is occuring 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())
m_sliderAction->volumeSlider()->setVolume((int) (m_sliderAction->volumeSlider()->maxValue() * volume()));
// Ok, this is weird stuff, but it works pretty well. Ordinarily we don't
// need to check up on our playing time very often, but in the span of the
// last interval, we want to check a lot -- to figure out that we've hit the
......@@ -485,7 +500,10 @@ void PlayerManager::slotSetOutput(int system)
void PlayerManager::slotSetVolume(int volume)
{
setVolume(float(volume) / float(m_sliderAction->volumeSlider()->maxValue()));
if(m_sliderAction->volumeSlider())
setVolume(float(volume) / float(m_sliderAction->volumeSlider()->maxValue()));
else
setVolume(float(volume) / 100.0);
}
void PlayerManager::slotUpdateTime(int position)
......@@ -493,7 +511,7 @@ void PlayerManager::slotUpdateTime(int position)
if(!m_statusLabel)
return;
float positionFraction = float(position) / m_sliderAction->trackPositionSlider()->maxValue();
float positionFraction = float(position) / SliderAction::maxPosition;
float totalTime = float(player()->totalTime());
int seekTime = int(positionFraction * totalTime + 0.5); // "+0.5" for rounding
......@@ -541,7 +559,7 @@ void PlayerManager::setup()
this, SLOT(seekPosition(int)));
connect(m_sliderAction->trackPositionSlider(), SIGNAL(valueChanged(int)),
this, SLOT(slotUpdateTime(int)));
connect(m_sliderAction->volumeSlider(), SIGNAL(signalVolumeChanged(int)),
connect(m_sliderAction, SIGNAL(signalVolumeChanged(int)),
this, SLOT(slotSetVolume(int)));
// Call this method manually to avoid warnings.
......@@ -556,9 +574,15 @@ void PlayerManager::setup()
else
m_player = createPlayer();
float volume =
float(m_sliderAction->volumeSlider()->volume()) /
float(m_sliderAction->volumeSlider()->maxValue());
float volume;
if(m_sliderAction->volumeSlider()) {
volume =
float(m_sliderAction->volumeSlider()->volume()) /
float(m_sliderAction->volumeSlider()->maxValue());
}
else
volume = 1; // Assume user wants full volume
m_player->setVolume(volume);
......@@ -567,3 +591,5 @@ void PlayerManager::setup()
}
#include "playermanager.moc"
// vim: set et ts=4 sw=4:
......@@ -123,13 +123,17 @@ void VolumeSlider::slotValueChanged(int value)
// public members
////////////////////////////////////////////////////////////////////////////////
const int SliderAction::minPosition = 0;
const int SliderAction::maxPosition = 1000;
SliderAction::SliderAction(const QString &text, QObject *parent, const char *name)
: KAction(text, 0, parent, name),
m_toolBar(0),
m_layout(0),
m_trackPositionSlider(0),
m_volumeSlider(0),
m_dragging(false)
m_dragging(false),
m_volumeDragging(false)
{
}
......@@ -144,28 +148,31 @@ int SliderAction::plug(QWidget *parent, int index)
QWidget *w = createWidget(parent);
if(!w)
return -1;
return -1;
// the check for null makes sure that there is only one toolbar that this is
// "plugged" in to
if(parent->inherits("KToolBar") && !m_toolBar) {
m_toolBar = static_cast<KToolBar *>(parent);
m_toolBar = static_cast<KToolBar *>(parent);
int id = KAction::getToolButtonID();
int id = KAction::getToolButtonID();
m_toolBar->insertWidget(id, w->width(), w, index);
m_toolBar->insertWidget(id, w->width(), w, index);
addContainer(m_toolBar, id);
addContainer(m_toolBar, id);
connect(m_toolBar, SIGNAL(destroyed()), this, SLOT(slotDestroyed()));
connect(m_toolBar, SIGNAL(orientationChanged(Orientation)),
this, SLOT(slotUpdateOrientation()));
connect(m_toolBar, SIGNAL(placeChanged(QDockWindow::Place)),
this, SLOT(slotUpdateOrientation()));
connect(m_toolBar, SIGNAL(destroyed()), this, SLOT(slotToolbarDestroyed()));
connect(m_toolBar, SIGNAL(orientationChanged(Orientation)),
this, SLOT(slotUpdateOrientation()));
connect(m_toolBar, SIGNAL(placeChanged(QDockWindow::Place)),
this, SLOT(slotUpdateOrientation()));
return (containerCount() - 1);
slotUpdateOrientation();
return (containerCount() - 1);
}
else
slotUpdateOrientation();
return -1;
}
......@@ -194,15 +201,18 @@ void SliderAction::slotUpdateOrientation()
{
// if the toolbar is not null and either the dockWindow not defined or is the toolbar
if(!m_toolBar)
return;
if(m_toolBar->barPos() == KToolBar::Right || m_toolBar->barPos() == KToolBar::Left) {
m_trackPositionSlider->setOrientation(Vertical);
m_volumeSlider->setOrientation(Vertical);
m_layout->setDirection(QBoxLayout::TopToBottom);
m_trackPositionSlider->setOrientation(Vertical);
m_volumeSlider->setOrientation(Vertical);
m_layout->setDirection(QBoxLayout::TopToBottom);
}
else {
m_trackPositionSlider->setOrientation(Horizontal);
m_volumeSlider->setOrientation(Horizontal);
m_layout->setDirection(QBoxLayout::LeftToRight);
m_trackPositionSlider->setOrientation(Horizontal);
m_volumeSlider->setOrientation(Horizontal);
m_layout->setDirection(QBoxLayout::LeftToRight);
}
slotUpdateSize();
}
......@@ -241,11 +251,11 @@ QWidget *SliderAction::createWidget(QWidget *parent) // virtual -- used by base
m_layout->addWidget(trackPositionLabel);
m_trackPositionSlider = new TrackPositionSlider(base, "trackPositionSlider");
m_trackPositionSlider->setMaxValue(1000);
m_trackPositionSlider->setMaxValue(maxPosition);
QToolTip::add(m_trackPositionSlider, 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(m_trackPositionSlider, SIGNAL(sliderPressed()), this, SLOT(slotSliderPressed()));
connect(m_trackPositionSlider, SIGNAL(sliderReleased()), this, SLOT(slotSliderReleased()));
m_layout->addItem(new QSpacerItem(10, 1));
......@@ -259,6 +269,9 @@ QWidget *SliderAction::createWidget(QWidget *parent) // virtual -- used by base
m_volumeSlider->setMaxValue(100);
QToolTip::add(m_volumeSlider, 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()));
m_volumeSlider->setName("kde toolbar widget");
m_trackPositionSlider->setName("kde toolbar widget");
......@@ -283,6 +296,9 @@ void SliderAction::slotUpdateSize()
static const int offset = 3;
static const int absoluteMax = 10000;
if(!m_toolBar)
return;
if(m_toolBar->barPos() == KToolBar::Right || m_toolBar->barPos() == KToolBar::Left) {
m_volumeSlider->setMaximumWidth(m_toolBar->iconSize() - offset);
m_volumeSlider->setMaximumHeight(volumeMax);
......@@ -310,4 +326,32 @@ void SliderAction::slotSliderReleased()
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()
{
int index = findContainer(m_toolBar);
if(index != -1)
removeContainer(index);
m_toolBar = 0;
// This is probably a leak, but this code path hardly ever occurs, and it's
// too hard to debug correctly.
m_trackPositionSlider = 0;
m_volumeSlider = 0;
}
#include "slideraction.moc"
// vim: set et sw=4 ts=4:
......@@ -57,23 +57,31 @@ public:
QSlider *trackPositionSlider() const { return m_trackPositionSlider; }
bool dragging() const { return m_dragging; }
bool volumeDragging() const { return m_volumeDragging; }
virtual int plug(QWidget *parent, int index = -1);
virtual void unplug(QWidget *widget);
static const int minPosition;
static const int maxPosition;
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;
......@@ -81,6 +89,7 @@ private:
QSlider *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