[vlc-commits] Qt: TimeToolTip: Show Chapters too
Francois Cartegnie
git at videolan.org
Tue Jul 19 20:56:25 CEST 2011
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jul 19 19:54:11 2011 +0200| [7b3e31f94abd5b71f26ec096b78520e57cd887f4] | committer: Francois Cartegnie
Qt: TimeToolTip: Show Chapters too
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7b3e31f94abd5b71f26ec096b78520e57cd887f4
---
modules/gui/qt4/util/input_slider.cpp | 16 +++++++++++++++-
modules/gui/qt4/util/timetooltip.cpp | 30 ++++++++++++++++++++++++------
modules/gui/qt4/util/timetooltip.hpp | 6 +++++-
3 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp
index b99fdbe..1c54a15 100644
--- a/modules/gui/qt4/util/input_slider.cpp
+++ b/modules/gui/qt4/util/input_slider.cpp
@@ -221,12 +221,26 @@ void SeekSlider::mouseMoveEvent( QMouseEvent *event )
{
int posX = qMax( rect().left(), qMin( rect().right(), event->x() ) );
+ QString chapterLabel;
QPoint p( event->globalX() - ( event->x() - posX ) - ( mTimeTooltip->width() / 2 ),
QWidget::mapToGlobal( pos() ).y() - ( mTimeTooltip->height() + 2 ) );
+ if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
+ {
+ QList<SeekPoint> points = chapters->getPoints();
+ int i_selected = -1;
+ for( int i = 0 ; i < points.count() ; i++ )
+ {
+ int x = points.at(i).time / 1000000.0 / inputLength * size().width();
+ if ( event->x() >= x )
+ i_selected = i;
+ }
+ if ( i_selected >= 0 )
+ chapterLabel = points.at( i_selected ).name;
+ }
secstotimestr( psz_length, ( posX * inputLength ) / size().width() );
- mTimeTooltip->setTime( psz_length );
+ mTimeTooltip->setText( psz_length, chapterLabel );
mTimeTooltip->move( p );
}
event->accept();
diff --git a/modules/gui/qt4/util/timetooltip.cpp b/modules/gui/qt4/util/timetooltip.cpp
index a515fcd..c6086e8 100644
--- a/modules/gui/qt4/util/timetooltip.cpp
+++ b/modules/gui/qt4/util/timetooltip.cpp
@@ -40,11 +40,24 @@ TimeTooltip::TimeTooltip( QWidget *parent ) :
// Inherit from the system default font size -5
mFont = QFont( "Verdana", qMax( qApp->font().pointSize() - 5, 7 ) );
+ mPreviousMetricsWidth = 0;
+ // Set default text
+ setText( "00:00:00", "" );
+}
+
+void TimeTooltip::buildPath()
+{
QFontMetrics metrics( mFont );
// Get the bounding box required to print the text and add some padding
- QRect textbox = metrics.boundingRect( "00:00:00" ).adjusted( -2, -2, 2, 2 );
+ QRect textbox = metrics.boundingRect( mDisplayedText ).adjusted( -2, -2, 2, 2 );
+
+ if ( mPreviousMetricsWidth == textbox.width() )
+ return; //same width == same path
+ else
+ mPreviousMetricsWidth = textbox.width();
+
mBox = QRect( 0, 0, textbox.width(), textbox.height() );
// Resize the widget to fit our needs
@@ -54,6 +67,7 @@ TimeTooltip::TimeTooltip( QWidget *parent ) :
// we only have to generate the text at runtime.
// Draw the text box
+ mPainterPath = QPainterPath();
mPainterPath.addRect( mBox );
// Draw the tip
@@ -79,14 +93,18 @@ TimeTooltip::TimeTooltip( QWidget *parent ) :
painter.end();
setMask( mMask );
-
- // Set default text
- setTime("00:00");
}
-void TimeTooltip::setTime( const QString& time )
+void TimeTooltip::setText( const QString& time, const QString& text )
{
+ mDisplayedText = time;
+ if ( !mText.isEmpty() ) mDisplayedText.append( " - " + text );
+
+ if ( time.length() != mTime.length() || mText != text )
+ buildPath();
+
mTime = time;
+ mText = text;
update();
}
@@ -101,7 +119,7 @@ void TimeTooltip::paintEvent( QPaintEvent * )
p.setFont( mFont );
p.setPen( QPen( qApp->palette().text(), 1 ) );
- p.drawText( mBox, Qt::AlignCenter, mTime );
+ p.drawText( mBox, Qt::AlignCenter, mDisplayedText );
}
#undef TIP_HEIGHT
diff --git a/modules/gui/qt4/util/timetooltip.hpp b/modules/gui/qt4/util/timetooltip.hpp
index f218d38..6e74f64 100644
--- a/modules/gui/qt4/util/timetooltip.hpp
+++ b/modules/gui/qt4/util/timetooltip.hpp
@@ -36,17 +36,21 @@ class TimeTooltip : public QWidget
Q_OBJECT
public:
explicit TimeTooltip( QWidget *parent = 0 );
- void setTime( const QString& time );
+ void setText( const QString& time, const QString& text );
protected:
virtual void paintEvent( QPaintEvent * );
private:
+ void buildPath();
QString mTime;
+ QString mText;
+ QString mDisplayedText;
QFont mFont;
QRect mBox;
QPainterPath mPainterPath;
QBitmap mMask;
+ int mPreviousMetricsWidth;
};
#endif // TIMETOOLTIP_H
More information about the vlc-commits
mailing list