PageRenderTime 183ms CodeModel.GetById 81ms app.highlight 9ms RepoModel.GetById 91ms app.codeStats 0ms

/src/libtomahawk/widgets/SeekSlider.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 129 lines | 84 code | 21 blank | 24 comment | 8 complexity | 312e0a3b963ba427092d3bb94f2a5195 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2016, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *   Copyright 2013,      Teo Mrnjavac <teo@kde.org>
  6 *
  7 *   Tomahawk is free software: you can redistribute it and/or modify
  8 *   it under the terms of the GNU General Public License as published by
  9 *   the Free Software Foundation, either version 3 of the License, or
 10 *   (at your option) any later version.
 11 *
 12 *   Tomahawk is distributed in the hope that it will be useful,
 13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *   GNU General Public License for more details.
 16 *
 17 *   You should have received a copy of the GNU General Public License
 18 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21#include "SeekSlider.h"
 22
 23#include <QtGui/QMouseEvent>
 24#include <QtCore/QTimeLine>
 25
 26#include "utils/TomahawkUtils.h"
 27#include "utils/TomahawkStyle.h"
 28#include "utils/Logger.h"
 29
 30
 31SeekSlider::SeekSlider( QWidget* parent )
 32    : QSlider( parent )
 33    , TomahawkUtils::DpiScaler( this )
 34    , m_timeLine( 0 )
 35    , m_acceptWheelEvents( true )
 36    , m_isScrubbing( false )
 37{
 38    setStyleSheet( QString(
 39                   "QSlider::groove:horizontal {"
 40                   "margin-top: %1px; margin-bottom: %1px; border: %2px solid rgba(200, 200, 200, 0); background: rgba(200, 200, 200, 40);"
 41//                   "border-image: url(" RESPATH "images/seek-slider-bkg.png) %2 %2 %2 %2 stretch stretch;"
 42                   "}"
 43
 44                   "QSlider::sub-page:horizontal {"
 45                   "margin-top: %1px; margin-bottom: %1px; border: %2px solid rgba(0, 0, 0, 0); background: %3;"
 46//                   "border-image: url(" RESPATH "images/seek-slider-level.png) %2 %2 %2 %2 stretch stretch;"
 47                   "}" )
 48                   .arg( scaledX( 7 ) /*margin*/ )
 49                   .arg( 0 /*border*/ )
 50                   .arg( /*color*/ TomahawkStyle::SEEKSLIDER_FOREGROUND.name() ) +
 51                   QString(
 52                   "QSlider::handle:horizontal {"
 53                   "margin-bottom: -%1px; margin-top: -%1px;"
 54                   "margin-left: -%2px; margin-right: -%2px;"
 55                   "height: %3px; width: %4px;"
 56//                   "background-image: url(" RESPATH "images/seek-and-volume-knob-rest.png);"
 57                   "background-repeat: no-repeat;"
 58                   "}" )
 59                   .arg( /*margin top&bottom*/ 0 )
 60                   .arg( /*margin left&right*/ 0 )
 61                   .arg( /*height*/ 0 )
 62                   .arg( /*width*/ 0 ) );
 63}
 64
 65
 66SeekSlider::~SeekSlider()
 67{
 68}
 69
 70
 71void
 72SeekSlider::mousePressEvent( QMouseEvent* event )
 73{
 74    if ( event->button() == Qt::LeftButton )
 75    {
 76        m_isScrubbing = true;
 77
 78        QMouseEvent eventSwap( QEvent::MouseButtonRelease, event->pos(), event->globalPos(), Qt::MidButton, Qt::MidButton, event->modifiers() );
 79        QSlider::mousePressEvent( &eventSwap );
 80    }
 81    else
 82        QSlider::mousePressEvent( event );
 83}
 84
 85
 86void
 87SeekSlider::setValue( int value )
 88{
 89//    int newVal = qBound( minimum(), value, maximum() );
 90
 91    if ( !m_timeLine || sender() != m_timeLine )
 92    {
 93        QSlider::setValue( value );
 94        return;
 95    }
 96
 97    blockSignals( true );
 98    QSlider::setValue( value );
 99    blockSignals( false );
100}
101
102
103void
104SeekSlider::wheelEvent( QWheelEvent* event )
105{
106    if ( m_acceptWheelEvents )
107    {
108        QAbstractSlider::wheelEvent( event );
109        return;
110    }
111    event->ignore();
112}
113
114
115void
116SeekSlider::mouseMoveEvent( QMouseEvent* event )
117{
118    if ( !m_isScrubbing )
119        return;
120
121    // disable further scrubbing when we're past the slider's right margin
122    if ( event->pos().x() > width() )
123    {
124        m_isScrubbing = false;
125        return;
126    }
127
128    QSlider::mouseMoveEvent( event );
129}