Commit 7b3e31f9 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: TimeToolTip: Show Chapters too

parent e9a99cda
......@@ -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();
......
......@@ -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
......@@ -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
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