From 92fbe4d34b747f62a6acdf575e6668e08ddae024 Mon Sep 17 00:00:00 2001 From: dmeltzer Date: Mon, 16 Apr 2007 21:49:54 +0000 Subject: [PATCH] Bookmarks now show a popup with their location in hours/minutes/seconds (the popup looks ugly.) CLicking on a bookmark also seeks to the location of the bookmark. git-svn-id: svn+ssh://ianmonroe@svn.kde.org/home/kde/trunk/extragear/multimedia/amarok@654780 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/progressslider.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- src/progressslider.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/progressslider.cpp b/src/progressslider.cpp index 766db459b..c31d801af 100644 --- a/src/progressslider.cpp +++ b/src/progressslider.cpp @@ -17,6 +17,9 @@ #include "progressslider.h" #include "timeLabel.h" +#include +#include + #include #include #include @@ -25,9 +28,11 @@ // Class ProgressSlider ProgressSlider *ProgressSlider::s_instance = 0; ProgressSlider::ProgressSlider( QWidget *parent ) : - Amarok::PrettySlider( Qt::Horizontal, Amarok::PrettySlider::Normal, parent, 100000 ) + Amarok::PrettySlider( Qt::Horizontal, Amarok::PrettySlider::Normal, parent ) { + oldpoint = QPoint(0, 0); s_instance = this; + setMouseTracking( true ); } // Add A bookmark to the slider at given second @@ -52,14 +57,47 @@ void ProgressSlider::paintEvent( QPaintEvent *e ) foreach( uint it, m_bookmarks ) { const int pos = int( double( width() ) / maximum() * ( it * 1000 ) ); - QPolygon pa( 3 ); + Polygon pa( 3, it ); pa.setPoint( 0, pos - 5, 1 ); pa.setPoint( 1, pos + 5, 1 ); pa.setPoint( 2, pos, 9 ); p.setBrush( Qt::red ); + m_polygons << pa; p.drawConvexPolygon( pa ); } } +void ProgressSlider::mouseMoveEvent( QMouseEvent *e ) +{ + + foreach( Polygon p, m_polygons ) + { + //only create a popup if the mouse enters a bookmark, not if it moves inside of one. + if( p.contains( e->pos(), Qt::OddEvenFill ) && !p.contains( oldpoint, Qt::OddEvenFill ) ) + { + m_popup = new KPassivePopup( parentWidget() ); + KHBox *khb = new KHBox( m_popup ); + new QLabel( p.time(), khb ); + m_popup->setView( khb ); + m_popup->setAutoDelete( false ); + m_popup->show( mapToGlobal( e->pos() ) ); + oldpoint = e->pos(); + } + //If the mouse moves outside of the bookmark, hide the popup + else if ( p.contains( oldpoint, Qt::OddEvenFill) && !p.contains( e->pos(), Qt::OddEvenFill ) ) + { + if( m_popup->isVisible() ) + m_popup->hide(); + } + } + oldpoint = e->pos(); +} +void ProgressSlider::mousePressEvent( QMouseEvent *e ) +{ + EngineController *ec = EngineController::instance(); + foreach( Polygon p, m_polygons ) + if( p.contains( e->pos(), Qt::OddEvenFill ) ) + ec->seek( p.seconds() * 1000 ); +} // END Class ProgressSlider //Class ProgressWidget diff --git a/src/progressslider.h b/src/progressslider.h index 778cb14ab..897324193 100644 --- a/src/progressslider.h +++ b/src/progressslider.h @@ -17,12 +17,52 @@ #include "engineobserver.h" #include "sliderwidget.h" +#include + #include -#include +#include #include +#include class QLabel; -class QPolygon; + +class Polygon : public QPolygon +{ + public: + Polygon( int size, int seconds ) : QPolygon( size ), + m_seconds( seconds) + {} + QString time() { return prettyTime( m_seconds ); } + inline int seconds() { return m_seconds; } + void setTime( int seconds ) { m_seconds = seconds; } + + private: + QString prettyTime( int seconds ) + { + int hours = 0; + int minutes = 0; + while( seconds >= 3600 ) + { + hours++; + seconds -= 3600; + } + while( seconds >= 60 ) + { + minutes++; + seconds -= 60; + } + QString sHours, sMinutes, sSeconds; + sHours = sMinutes = sSeconds = QString(); + if( hours > 0 ) + sHours = QString("%1 Hours").arg( hours ); + if( minutes > 0) + sMinutes = QString("%1 Minutes").arg( minutes ); + if( seconds > 0 ) + sSeconds = QString("%1 Seconds").arg( seconds ); + return QString( "%1\n%2\n%3" ).arg( sHours, sMinutes, sSeconds ); + } + int m_seconds; +}; class ProgressSlider : public Amarok::PrettySlider { @@ -38,9 +78,14 @@ class ProgressSlider : public Amarok::PrettySlider protected: virtual void paintEvent( QPaintEvent *e ); + virtual void mouseMoveEvent( QMouseEvent *e ); + virtual void mousePressEvent( QMouseEvent *e ); private: QList m_bookmarks; + QList m_polygons; + QPoint oldpoint; + KPassivePopup *m_popup; }; class ProgressWidget : public QWidget, public EngineObserver -- 2.11.4.GIT