From 9b433379eec833ae6dc7858c5dd4f8f679ef290f Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 17 Aug 2011 02:20:41 +0200 Subject: [PATCH] * Fixed TWK-212: Sliders should jump to the position they are clicked on. --- src/audiocontrols.cpp | 23 ------------ src/audiocontrols.h | 5 --- src/audiocontrols.ui | 9 +++-- src/libtomahawk/CMakeLists.txt | 2 ++ src/libtomahawk/widgets/SeekSlider.cpp | 50 ++++++++++++++++++++++++++ src/libtomahawk/widgets/SeekSlider.h | 41 +++++++++++++++++++++ 6 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 src/libtomahawk/widgets/SeekSlider.cpp create mode 100644 src/libtomahawk/widgets/SeekSlider.h diff --git a/src/audiocontrols.cpp b/src/audiocontrols.cpp index f371fca04..ee806f19c 100644 --- a/src/audiocontrols.cpp +++ b/src/audiocontrols.cpp @@ -132,16 +132,6 @@ AudioControls::AudioControls( QWidget* parent ) "background-repeat: no-repeat;" "}" ); -/* m_playAction = new QAction( this ); - m_pauseAction = new QAction( this ); - m_prevAction = new QAction( this ); - m_nextAction = new QAction( this ); - - connect( m_playAction, SIGNAL( triggered() ), (QObject*)APP->audioEngine(), SLOT( play() ) ); - connect( m_pauseAction, SIGNAL( triggered() ), (QObject*)APP->audioEngine(), SLOT( pause() ) ); - connect( m_prevAction, SIGNAL( triggered() ), (QObject*)APP->audioEngine(), SLOT( previous() ) ); - connect( m_nextAction, SIGNAL( triggered() ), (QObject*)APP->audioEngine(), SLOT( next() ) ); */ - connect( ui->seekSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( seek( int ) ) ); connect( ui->volumeSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( setVolume( int ) ) ); connect( ui->prevButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( previous() ) ); @@ -180,7 +170,6 @@ AudioControls::AudioControls( QWidget* parent ) connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); - ui->buttonAreaLayout->setSpacing( 0 ); ui->stackedLayout->setSpacing( 0 ); ui->stackedLayout->setContentsMargins( 0, 0, 0, 0 ); @@ -306,9 +295,6 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result ) ui->seekSlider->setValue( 0 ); ui->seekSlider->setVisible( true ); -/* m_playAction->setEnabled( false ); - m_pauseAction->setEnabled( true ); */ - ui->stackedLayout->setCurrentWidget( ui->pauseButton ); ui->loveButton->setEnabled( true ); @@ -344,18 +330,12 @@ AudioControls::socialActionsLoaded() void AudioControls::onPlaybackPaused() { -/* m_pauseAction->setEnabled( false ); - m_playAction->setEnabled( true ); */ - ui->stackedLayout->setCurrentWidget( ui->playPauseButton ); } void AudioControls::onPlaybackResumed() { -/* m_playAction->setEnabled( false ); - m_pauseAction->setEnabled( true ); */ - ui->stackedLayout->setCurrentWidget( ui->pauseButton ); ui->loveButton->setVisible( true ); } @@ -377,9 +357,6 @@ AudioControls::onPlaybackStopped() ui->stackedLayout->setCurrentWidget( ui->playPauseButton ); ui->loveButton->setEnabled( false ); ui->loveButton->setVisible( false ); - -/* m_pauseAction->setEnabled( false ); - m_playAction->setEnabled( true ); */ } diff --git a/src/audiocontrols.h b/src/audiocontrols.h index 5e738e50b..c4e8cfe27 100644 --- a/src/audiocontrols.h +++ b/src/audiocontrols.h @@ -82,11 +82,6 @@ private slots: private: Ui::AudioControls *ui; - QAction* m_playAction; - QAction* m_pauseAction; - QAction* m_prevAction; - QAction* m_nextAction; - QPixmap m_defaultCover; Tomahawk::result_ptr m_currentTrack; diff --git a/src/audiocontrols.ui b/src/audiocontrols.ui index a73e384b8..8b4ea01ca 100644 --- a/src/audiocontrols.ui +++ b/src/audiocontrols.ui @@ -337,7 +337,7 @@ - + 0 @@ -489,7 +489,7 @@ - + 0 @@ -529,6 +529,11 @@ + + SeekSlider + QSlider +
widgets/SeekSlider.h
+
ImageButton QPushButton diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 7eaad04e8..c2c9c74f5 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -177,6 +177,7 @@ set( libSources widgets/newplaylistwidget.cpp widgets/searchwidget.cpp + widgets/SeekSlider.cpp widgets/playlisttypeselectordlg.cpp widgets/welcomewidget.cpp widgets/welcomeplaylistmodel.cpp @@ -356,6 +357,7 @@ set( libHeaders widgets/newplaylistwidget.h widgets/searchwidget.h + widgets/SeekSlider.h widgets/playlisttypeselectordlg.h widgets/welcomewidget.h widgets/welcomeplaylistmodel.h diff --git a/src/libtomahawk/widgets/SeekSlider.cpp b/src/libtomahawk/widgets/SeekSlider.cpp new file mode 100644 index 000000000..4b31f1ea9 --- /dev/null +++ b/src/libtomahawk/widgets/SeekSlider.cpp @@ -0,0 +1,50 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "SeekSlider.h" + +#include +#include + +#include "utils/logger.h" + + +SeekSlider::SeekSlider( QWidget* parent ) + : QSlider( parent ) + , m_parent( parent ) +{ + setMouseTracking( true ); +} + + +SeekSlider::~SeekSlider() +{ +} + + +void +SeekSlider::mousePressEvent( QMouseEvent* event ) +{ + if ( event->button() == Qt::LeftButton ) + { + QMouseEvent eventSwap( QEvent::MouseButtonRelease, event->pos(), event->globalPos(), Qt::MidButton, Qt::MidButton, event->modifiers() ); + QSlider::mousePressEvent( &eventSwap ); + } + else + QSlider::mousePressEvent( event ); +} diff --git a/src/libtomahawk/widgets/SeekSlider.h b/src/libtomahawk/widgets/SeekSlider.h new file mode 100644 index 000000000..6b6a41acb --- /dev/null +++ b/src/libtomahawk/widgets/SeekSlider.h @@ -0,0 +1,41 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef SEEKSLIDER_H +#define SEEKSLIDER_H + +#include + +#include "dllmacro.h" + +class DLLEXPORT SeekSlider : public QSlider +{ +Q_OBJECT + +public: + SeekSlider( QWidget* parent = 0 ); + ~SeekSlider(); + +protected: + void mousePressEvent( QMouseEvent* event ); + +private: + QWidget* m_parent; +}; + +#endif // SEEKSLIDER_H