From 72a8faafdb6179e1353f7160ea0eb7dd5436719b Mon Sep 17 00:00:00 2001 From: APTX Date: Thu, 27 Aug 2009 00:16:01 +0200 Subject: [PATCH] - Display the seek time with the marker shadow on the seek slider. --- src/seekslider.cpp | 42 ++++++++++++++++++++++++++++++++++++------ src/seekslider.h | 3 +++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/seekslider.cpp b/src/seekslider.cpp index 5c8770a..0692e90 100644 --- a/src/seekslider.cpp +++ b/src/seekslider.cpp @@ -3,8 +3,10 @@ #include #include #include -#include "aniplayer.h" +#include +#include +#include "aniplayer.h" #include SeekSlider::SeekSlider(QWidget *parent) : QWidget(parent) @@ -106,12 +108,15 @@ void SeekSlider::paintEvent(QPaintEvent *event) seekerWidth = width() - 1; const int markerWidth = 2; - const int markerPos = seekerLeft + 1 + markerWidth / 2 + qRound(double(m_value) / double(m_length) * double(seekerWidth - markerWidth / 2 - 1)); + const int markerPos = time2pos(m_value); const QColor markerColor(255, 0, 0); const QColor markerShadowColor(255, 0, 0, 100); const QColor previousMarkerColor(255, 255, 255); const QColor watchedPartColor(0, 0, 255, 150); const QColor unwatchedPartColor(0, 255, 0, 100); + const QColor toolTipBackgroundColor(0, 0, 0, 150); + const QColor toolTipForegroundColor(255, 255, 255); + // border p.drawRect(seekerLeft, seekerTop, seekerWidth, seekerHeight); @@ -121,12 +126,12 @@ void SeekSlider::paintEvent(QPaintEvent *event) // unwatched part p.fillRect(markerPos + markerWidth / 2, seekerTop + 1, seekerWidth - markerPos, seekerHeight - 1, unwatchedPartColor); - int i = 0; + int i = 1; for (QQueue::const_iterator it = previuousPos.constBegin(); it != previuousPos.constEnd(); ++it) { int markerPos = seekerLeft + 1 + markerWidth / 2 + qRound(double(*it) / double(m_length) * double(seekerWidth - markerWidth / 2 - 1)); QColor c = previousMarkerColor; - c.setAlpha(255 / previuousPos.count() * (i + 1)); + c.setAlpha(255 / previuousPos.count() * i); p.fillRect(markerPos - markerWidth / 2, seekerTop + 1, markerWidth, seekerHeight - 1, c); ++i; } @@ -135,10 +140,23 @@ void SeekSlider::paintEvent(QPaintEvent *event) p.fillRect(markerPos - markerWidth / 2, seekerTop + 1, markerWidth, seekerHeight - 1, markerColor); // marker shadow (where the marker would move when mouse is clicked) - if (drawMarkerShadow) + if (drawMarkerShadow && isEnabled()) { markerShadowPos = qBound(seekerLeft + 1 + markerWidth / 2, markerShadowPos, seekerLeft + seekerWidth - markerWidth / 2); p.fillRect(markerShadowPos - markerWidth / 2, seekerTop + 1, markerWidth, seekerHeight - 1, markerShadowColor); + + QString time = QTime().addMSecs(pos2time(markerShadowPos)).toString("hh:mm:ss"); + QRect r = p.fontMetrics().boundingRect(time); + + int xdelta = markerShadowPos + markerWidth / 2 + 1; + if (xdelta + r.width() < width()) + r.translate(xdelta, r.height()); + else + r.translate(markerShadowPos - (markerWidth / 2 + 1) - r.width(), r.height()); + + p.fillRect(r, toolTipBackgroundColor); + p.setPen(QPen(toolTipForegroundColor)); + p.drawText(r, time); } } @@ -280,7 +298,7 @@ void SeekSlider::setLength(qint64 length) void SeekSlider::seek(int x) { int newMarkerPos = qBound(seekerLeft + 1, x, seekerLeft + seekerWidth); - qint64 newSeekPos = double(newMarkerPos) / double(seekerLeft + seekerWidth) * double(m_length); + qint64 newSeekPos = pos2time(newMarkerPos); while (!previuousPos.isEmpty() && previuousPos.count() + 1 > maxPreviousPos) previuousPos.dequeue(); previuousPos.enqueue(m_value); @@ -290,3 +308,15 @@ void SeekSlider::seek(int x) ticking = false; seek(newSeekPos); } + +qint64 SeekSlider::pos2time(int pos) const +{ + const int halfMarkerWidth = markerWidth / 2; + return qint64(double(pos - (seekerLeft + 1 + halfMarkerWidth)) / double(seekerWidth - halfMarkerWidth - 1) * double(m_length)); +} + +int SeekSlider::time2pos(qint64 msec) const +{ + const int halfMarkerWidth = markerWidth / 2; + return seekerLeft + 1 + halfMarkerWidth + qRound(double(msec) / double(m_length) * double(seekerWidth - halfMarkerWidth - 1)); +} diff --git a/src/seekslider.h b/src/seekslider.h index 45e7f4c..b28943c 100644 --- a/src/seekslider.h +++ b/src/seekslider.h @@ -79,6 +79,9 @@ private: void seek(int x); + qint64 pos2time(int pos) const; + int time2pos(qint64 msec) const; + QPointer m_media; bool ticking; bool markerShadowEnabled; -- 2.52.0