Commit add680a2 authored by Scott Wheeler's avatar Scott Wheeler

Hmm, why did I think this was going to be a one-liner? :-)

Switch the min and max ends of the volume slider when it's in vertical mode.
Also did some cleanups in the (very old) CustomAction class -- which can
really probably just be merged into the SliderAction class, but I'm too lazy
for that just now...

CCMAIL:77099-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=299398
parent 7d44551c
......@@ -24,9 +24,10 @@
////////////////////////////////////////////////////////////////////////////////
CustomAction::CustomAction(const QString &text, QObject *parent, const char *name)
: KAction(text, 0, parent, name)
: KAction(text, 0, parent, name),
m_toolBar(0)
{
toolbar=NULL;
}
CustomAction::~CustomAction()
......@@ -36,52 +37,44 @@ CustomAction::~CustomAction()
int CustomAction::plug(QWidget *parent, int index)
{
customWidget = createWidget(parent);
QWidget *w = createWidget(parent);
if(customWidget) {
// the check for null makes sure that there is only one toolbar that this is
// "plugged" in to
if (parent->inherits("KToolBar") && !toolbar) {
toolbar = static_cast<KToolBar *>(parent);
int id = KAction::getToolButtonID();
if(!w)
return -1;
toolbar->insertWidget(id, customWidget->width(), customWidget, index);
// the check for null makes sure that there is only one toolbar that this is
// "plugged" in to
addContainer(toolbar, id);
connect(toolbar, SIGNAL(destroyed()), this, SLOT(slotDestroyed()));
if(parent->inherits("KToolBar") && !m_toolBar) {
m_toolBar = static_cast<KToolBar *>(parent);
int id = KAction::getToolButtonID();
return (containerCount() - 1);
}
m_toolBar->insertWidget(id, w->width(), w, index);
return -1;
}
else {
return -1;
addContainer(m_toolBar, id);
connect(m_toolBar, SIGNAL(destroyed()), this, SLOT(slotDestroyed()));
return (containerCount() - 1);
}
return -1;
}
void CustomAction::unplug(QWidget *parent)
{
if (parent->inherits("KToolBar")) {
toolbar = static_cast<KToolBar *>(parent);
m_toolBar = static_cast<KToolBar *>(parent);
int index = findContainer(toolbar);
int index = findContainer(m_toolBar);
if (index != -1) {
toolbar->removeItem(itemId(index));
m_toolBar->removeItem(itemId(index));
removeContainer(index);
toolbar = 0;
m_toolBar = 0;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
KToolBar *CustomAction::getToolBar()
{
return toolbar;
}
#include "customaction.moc"
......@@ -36,10 +36,9 @@ public:
virtual void unplug(QWidget *widget);
protected:
KToolBar *getToolBar();
KToolBar *toolBar() const { return m_toolBar; }
QWidget *customWidget;
KToolBar *toolbar;
KToolBar *m_toolBar;
signals:
void pluggedIn(QWidget *parent);
......
......@@ -66,6 +66,8 @@ JuK::JuK(QWidget *parent, const char *name) :
SplashScreen::finishedLoading();
QTimer::singleShot(0, CollectionList::instance(), SLOT(slotCheckCache()));
m_sliderAction->slotUpdateOrientation();
}
JuK::~JuK()
......@@ -314,9 +316,6 @@ void JuK::setupActions()
"trackPositionAction");
createGUI();
// set the slider to the proper orientation and make it stay that way
m_sliderAction->slotUpdateOrientation();
}
void JuK::setupSplitterConnections()
......@@ -421,7 +420,7 @@ void JuK::readConfig()
if(m_sliderAction->volumeSlider()) {
int maxVolume = m_sliderAction->volumeSlider()->maxValue();
int volume = config->readNumEntry("Volume", maxVolume);
m_sliderAction->volumeSlider()->setValue(volume);
m_sliderAction->volumeSlider()->setVolume(volume);
}
bool randomPlay = config->readBoolEntry("RandomPlay", false);
m_randomPlayAction->setChecked(randomPlay);
......@@ -471,7 +470,7 @@ void JuK::saveConfig()
KConfig *config = KGlobal::config();
{ // player settings
KConfigGroupSaver saver(config, "Player");
config->writeEntry("Volume", m_sliderAction->volumeSlider()->value());
config->writeEntry("Volume", m_sliderAction->volumeSlider()->volume());
config->writeEntry("RandomPlay", m_randomPlayAction->isChecked());
KToggleAction *a = ActionCollection::action<KToggleAction>("loopPlaylist");
......
......@@ -268,11 +268,11 @@ void PlayerManager::volumeUp()
if(!player() || !m_sliderAction)
return;
int volume = m_sliderAction->volumeSlider()->value() +
int volume = m_sliderAction->volumeSlider()->volume() +
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% up
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setValue(volume);
m_sliderAction->volumeSlider()->setVolume(volume);
}
void PlayerManager::volumeDown()
......@@ -284,7 +284,7 @@ void PlayerManager::volumeDown()
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% down
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setValue(volume);
m_sliderAction->volumeSlider()->setVolume(volume);
}
void PlayerManager::mute()
......@@ -405,7 +405,7 @@ void PlayerManager::setup()
this, SLOT(seekPosition(int)));
connect(m_sliderAction->trackPositionSlider(), SIGNAL(valueChanged(int)),
this, SLOT(slotUpdateTime(int)));
connect(m_sliderAction->volumeSlider(), SIGNAL(valueChanged(int)),
connect(m_sliderAction->volumeSlider(), SIGNAL(signalVolumeChanged(int)),
this, SLOT(slotSetVolume(int)));
KAction *outputAction = action("outputSelect");
......@@ -419,7 +419,7 @@ void PlayerManager::setup()
m_player = Player::createPlayer();
float volume =
float(m_sliderAction->volumeSlider()->value()) /
float(m_sliderAction->volumeSlider()->volume()) /
float(m_sliderAction->volumeSlider()->maxValue());
m_player->setVolume(volume);
......
......@@ -23,7 +23,7 @@
#include <qtooltip.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qslider.h>
#include <qtimer.h>
#include "slideraction.h"
......@@ -44,7 +44,8 @@ public:
TrackPositionSlider(QWidget *parent, const char *name) : QSlider(parent, name) {}
protected:
virtual void mousePressEvent(QMouseEvent *e) {
virtual void mousePressEvent(QMouseEvent *e)
{
if(e->button() == LeftButton) {
QMouseEvent reverse(QEvent::MouseButtonPress, e->pos(), MidButton, e->state());
QSlider::mousePressEvent(&reverse);
......@@ -58,18 +59,65 @@ protected:
virtual void focusInEvent(QFocusEvent *) { clearFocus(); }
};
class VolumeSlider : public QSlider
////////////////////////////////////////////////////////////////////////////////
// VolumeSlider implementation
////////////////////////////////////////////////////////////////////////////////
VolumeSlider::VolumeSlider(Orientation o, QWidget *parent, const char *name) :
QSlider(o, parent, name)
{
public:
VolumeSlider(QWidget *parent, const char *name) : QSlider(parent, name) {}
connect(this, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));
}
protected:
virtual void wheelEvent(QWheelEvent *e) {
void VolumeSlider::wheelEvent(QWheelEvent *e)
{
if(orientation() == Horizontal) {
QWheelEvent transposed(e->pos(), -(e->delta()), e->state(), e->orientation());
QSlider::wheelEvent(&transposed);
}
virtual void focusInEvent(QFocusEvent *) { clearFocus(); }
};
else
QSlider::wheelEvent(e);
}
void VolumeSlider::focusInEvent(QFocusEvent *)
{
clearFocus();
}
int VolumeSlider::volume() const
{
if(orientation() == Horizontal)
return value();
else
return maxValue() - value();
}
void VolumeSlider::setVolume(int value)
{
if(orientation() == Horizontal)
setValue(value);
else
setValue(maxValue() - value);
}
void VolumeSlider::setOrientation(Orientation o)
{
if(o == orientation())
return;
blockSignals(true);
setValue(maxValue() - value());
blockSignals(false);
QSlider::setOrientation(o);
}
void VolumeSlider::slotValueChanged(int value)
{
if(orientation() == Horizontal)
emit signalVolumeChanged(value);
else
emit signalVolumeChanged(maxValue() - value);
}
////////////////////////////////////////////////////////////////////////////////
// public members
......@@ -94,15 +142,15 @@ SliderAction::~SliderAction()
void SliderAction::slotUpdateOrientation(QDockWindow *dockWindow)
{
// if the toolbar is not null and either the dockWindow not defined or is the toolbar
if(customWidget && toolbar && (!dockWindow || dockWindow == dynamic_cast<QDockWindow *>(toolbar))) {
if(toolbar->barPos() == KToolBar::Right || toolbar->barPos() == KToolBar::Left) {
m_trackPositionSlider->setOrientation(Qt::Vertical);
m_volumeSlider->setOrientation(Qt::Vertical);
if((!dockWindow || dockWindow == dynamic_cast<QDockWindow *>(toolBar()))) {
if(toolBar()->barPos() == KToolBar::Right || toolBar()->barPos() == KToolBar::Left) {
m_trackPositionSlider->setOrientation(Vertical);
m_volumeSlider->setOrientation(Vertical);
m_layout->setDirection(QBoxLayout::TopToBottom);
}
else {
m_trackPositionSlider->setOrientation(Qt::Horizontal);
m_volumeSlider->setOrientation(Qt::Horizontal);
m_trackPositionSlider->setOrientation(Horizontal);
m_volumeSlider->setOrientation(Horizontal);
m_layout->setDirection(QBoxLayout::LeftToRight);
}
}
......@@ -120,9 +168,17 @@ QWidget *SliderAction::createWidget(QWidget *parent) // virtual -- used by base
base->setBackgroundMode(parent->backgroundMode());
base->setName("kde toolbar widget");
QToolBar *toolbar = dynamic_cast<QToolBar *>(parent);
if(toolbar)
toolbar->setStretchableWidget(base);
KToolBar *toolBar = dynamic_cast<KToolBar *>(parent);
if(toolBar)
toolBar->setStretchableWidget(base);
Orientation orientation;
if(toolBar && toolBar->barPos() == KToolBar::Right || toolBar->barPos() == KToolBar::Left)
orientation = Vertical;
else
orientation = Horizontal;
m_layout = new QBoxLayout(base, QBoxLayout::TopToBottom, 5, 5);
......@@ -149,7 +205,7 @@ QWidget *SliderAction::createWidget(QWidget *parent) // virtual -- used by base
QToolTip::add(volumeLabel, i18n("Volume"));
m_layout->addWidget(volumeLabel);
m_volumeSlider = new VolumeSlider(base, "volumeSlider");
m_volumeSlider = new VolumeSlider(orientation, base, "volumeSlider");
m_volumeSlider->setMaxValue(100);
QToolTip::add(m_volumeSlider, i18n("Volume"));
m_layout->addWidget(m_volumeSlider);
......@@ -161,6 +217,7 @@ QWidget *SliderAction::createWidget(QWidget *parent) // virtual -- used by base
m_layout->setStretchFactor(m_volumeSlider, 1);
connect(parent, SIGNAL(modechange()), this, SLOT(slotUpdateSize()));
return base;
}
else
......@@ -176,21 +233,19 @@ void SliderAction::slotUpdateSize()
static const int offset = 3;
static const int absoluteMax = 10000;
if(customWidget && toolbar) {
if(toolbar->barPos() == KToolBar::Right || toolbar->barPos() == KToolBar::Left) {
m_volumeSlider->setMaximumWidth(toolbar->iconSize() - offset);
m_volumeSlider->setMaximumHeight(volumeMax);
if(toolBar()->barPos() == KToolBar::Right || toolBar()->barPos() == KToolBar::Left) {
m_volumeSlider->setMaximumWidth(toolBar()->iconSize() - offset);
m_volumeSlider->setMaximumHeight(volumeMax);
m_trackPositionSlider->setMaximumWidth(toolbar->iconSize() - offset);
m_trackPositionSlider->setMaximumHeight(absoluteMax);
}
else {
m_volumeSlider->setMaximumHeight(toolbar->iconSize() - offset);
m_volumeSlider->setMaximumWidth(volumeMax);
m_trackPositionSlider->setMaximumWidth(toolBar()->iconSize() - offset);
m_trackPositionSlider->setMaximumHeight(absoluteMax);
}
else {
m_volumeSlider->setMaximumHeight(toolBar()->iconSize() - offset);
m_volumeSlider->setMaximumWidth(volumeMax);
m_trackPositionSlider->setMaximumHeight(toolbar->iconSize() - offset);
m_trackPositionSlider->setMaximumWidth(absoluteMax);
}
m_trackPositionSlider->setMaximumHeight(toolBar()->iconSize() - offset);
m_trackPositionSlider->setMaximumWidth(absoluteMax);
}
}
......
......@@ -18,12 +18,37 @@
#ifndef SLIDERACTION_H
#define SLIDERACTION_H
#include <qslider.h>
#include "customaction.h"
class QSlider;
class QBoxLayout;
class QDockWindow;
class VolumeSlider : public QSlider
{
Q_OBJECT
public:
VolumeSlider(Orientation o, QWidget *parent, const char *name);
int volume() const;
void setVolume(int value);
void setOrientation(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 CustomAction
{
Q_OBJECT
......@@ -32,7 +57,7 @@ public:
SliderAction(const QString &text, QObject *parent, const char *name);
virtual ~SliderAction();
QSlider *volumeSlider() const { return m_volumeSlider; }
VolumeSlider *volumeSlider() const { return m_volumeSlider; }
QSlider *trackPositionSlider() const { return m_trackPositionSlider; }
bool dragging() const { return m_dragging; }
......@@ -54,7 +79,7 @@ private slots:
private:
QBoxLayout *m_layout;
QSlider *m_trackPositionSlider;
QSlider *m_volumeSlider;
VolumeSlider *m_volumeSlider;
bool m_dragging;
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