#include <QPainter>
#include <QEvent>
#include <QMouseEvent>
-#include "aniplayer.h"
+#include <QTime>
+#include <QFontMetrics>
+#include "aniplayer.h"
#include <QDebug>
SeekSlider::SeekSlider(QWidget *parent) : QWidget(parent)
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);
// unwatched part
p.fillRect(markerPos + markerWidth / 2, seekerTop + 1, seekerWidth - markerPos, seekerHeight - 1, unwatchedPartColor);
- int i = 0;
+ int i = 1;
for (QQueue<qint64>::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;
}
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);
}
}
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);
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));
+}