Click replay timeline to seek. (#3570)

* Click replay timeline to seek.

* Fix seek for long games

* Erase log when rewinding

* zach cleanup

Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com>
This commit is contained in:
Rob Blanckaert 2019-02-08 17:32:56 -08:00 committed by Zach H
parent b065ada633
commit 612edae5f6
3 changed files with 29 additions and 12 deletions

View file

@ -22,12 +22,12 @@ void ReplayTimelineWidget::setTimeline(const QList<int> &_replayTimeline)
histogram.clear();
int binEndTime = binLength - 1;
int binValue = 0;
for (int i = 0; i < replayTimeline.size(); ++i) {
if (replayTimeline[i] > binEndTime) {
for (int i : replayTimeline) {
if (i > binEndTime) {
histogram.append(binValue);
if (binValue > maxBinValue)
maxBinValue = binValue;
while (replayTimeline[i] > binEndTime + binLength) {
while (i > binEndTime + binLength) {
histogram.append(0);
binEndTime += binLength;
}
@ -59,17 +59,30 @@ void ReplayTimelineWidget::paintEvent(QPaintEvent * /* event */)
const QColor barColor = QColor::fromHsv(120, 255, 255, 100);
quint64 w = (quint64)(width() - 1) * (quint64)currentTime / maxTime;
painter.fillRect(0, 0, w, height() - 1, barColor);
painter.fillRect(0, 0, static_cast<int>(w), height() - 1, barColor);
}
void ReplayTimelineWidget::mousePressEvent(QMouseEvent *event)
{
int newTime = static_cast<int>((long)maxTime * (long)event->x() / width());
if (newTime < currentTime) {
currentTime = 0;
currentEvent = 0;
emit rewound();
}
currentTime = newTime - 200; // 200 is added back in replayTimerTimeout
replayTimerTimeout();
update();
}
QSize ReplayTimelineWidget::sizeHint() const
{
return QSize(-1, 50);
return {-1, 50};
}
QSize ReplayTimelineWidget::minimumSizeHint() const
{
return QSize(400, 50);
return {400, 50};
}
void ReplayTimelineWidget::replayTimerTimeout()
@ -91,12 +104,12 @@ void ReplayTimelineWidget::replayTimerTimeout()
void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor)
{
timeScaleFactor = _timeScaleFactor;
replayTimer->setInterval(200 / timeScaleFactor);
replayTimer->setInterval(static_cast<int>(200 / timeScaleFactor));
}
void ReplayTimelineWidget::startReplay()
{
replayTimer->start(200 / timeScaleFactor);
replayTimer->start(static_cast<int>(200 / timeScaleFactor));
}
void ReplayTimelineWidget::stopReplay()

View file

@ -2,6 +2,7 @@
#define REPLAY_TIMELINE_WIDGET
#include <QList>
#include <QMouseEvent>
#include <QWidget>
class QPaintEvent;
@ -13,6 +14,7 @@ class ReplayTimelineWidget : public QWidget
signals:
void processNextEvent();
void replayFinished();
void rewound();
private:
QTimer *replayTimer;
@ -27,10 +29,10 @@ private slots:
void replayTimerTimeout();
public:
ReplayTimelineWidget(QWidget *parent = 0);
explicit ReplayTimelineWidget(QWidget *parent = nullptr);
void setTimeline(const QList<int> &_replayTimeline);
QSize sizeHint() const;
QSize minimumSizeHint() const;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
void setTimeScaleFactor(qreal _timeScaleFactor);
int getCurrentEvent() const
{
@ -41,7 +43,8 @@ public slots:
void stopReplay();
protected:
void paintEvent(QPaintEvent *event);
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
};
#endif

View file

@ -1604,6 +1604,7 @@ void TabGame::createReplayDock()
timelineWidget->setTimeline(replayTimeline);
connect(timelineWidget, SIGNAL(processNextEvent()), this, SLOT(replayNextEvent()));
connect(timelineWidget, SIGNAL(replayFinished()), this, SLOT(replayFinished()));
connect(timelineWidget, &ReplayTimelineWidget::rewound, messageLog, &ChatView::clearChat);
replayStartButton = new QToolButton;
replayStartButton->setIconSize(QSize(32, 32));