mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-29 18:13:55 -07:00
Add keyboard shortcuts for skipping forward/backward in replays (#5140)
* split skipToTime into own function * implement shortcut * fix shortcut warning bug * check boundary conditions in skipToTime * change default fast forward shortcut to . * implement big skip shortcuts * remove unnecessary arg in lambda * change default fast forward shortcut to Ctrl+F * rename constants * change default fast forward shortcut to Ctrl+P * use static const
This commit is contained in:
parent
c633a792f5
commit
c4c52bd8c0
6 changed files with 74 additions and 2 deletions
|
|
@ -67,6 +67,19 @@ void ReplayTimelineWidget::mousePressEvent(QMouseEvent *event)
|
||||||
#else
|
#else
|
||||||
int newTime = static_cast<int>((qint64)maxTime * (qint64)event->x() / width());
|
int newTime = static_cast<int>((qint64)maxTime * (qint64)event->x() / width());
|
||||||
#endif
|
#endif
|
||||||
|
skipToTime(newTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReplayTimelineWidget::skipToTime(int newTime)
|
||||||
|
{
|
||||||
|
// check boundary conditions
|
||||||
|
if (newTime < 0) {
|
||||||
|
newTime = 0;
|
||||||
|
}
|
||||||
|
if (newTime > maxTime) {
|
||||||
|
newTime = maxTime;
|
||||||
|
}
|
||||||
|
|
||||||
newTime -= newTime % 200; // Time should always be a multiple of 200
|
newTime -= newTime % 200; // Time should always be a multiple of 200
|
||||||
if (newTime < currentTime) {
|
if (newTime < currentTime) {
|
||||||
currentTime = 0;
|
currentTime = 0;
|
||||||
|
|
@ -119,3 +132,8 @@ void ReplayTimelineWidget::stopReplay()
|
||||||
{
|
{
|
||||||
replayTimer->stop();
|
replayTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReplayTimelineWidget::skipByAmount(int amount)
|
||||||
|
{
|
||||||
|
skipToTime(currentTime + amount);
|
||||||
|
}
|
||||||
|
|
@ -25,6 +25,8 @@ private:
|
||||||
qreal timeScaleFactor;
|
qreal timeScaleFactor;
|
||||||
int currentTime;
|
int currentTime;
|
||||||
int currentEvent;
|
int currentEvent;
|
||||||
|
|
||||||
|
void skipToTime(int newTime);
|
||||||
private slots:
|
private slots:
|
||||||
void replayTimerTimeout();
|
void replayTimerTimeout();
|
||||||
|
|
||||||
|
|
@ -41,6 +43,7 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void startReplay();
|
void startReplay();
|
||||||
void stopReplay();
|
void stopReplay();
|
||||||
|
void skipByAmount(int amount); // use a negative amount to skip backwards
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,18 @@ void TabGame::refreshShortcuts()
|
||||||
if (aFocusChat) {
|
if (aFocusChat) {
|
||||||
aFocusChat->setShortcuts(shortcuts.getShortcut("tab_game/aFocusChat"));
|
aFocusChat->setShortcuts(shortcuts.getShortcut("tab_game/aFocusChat"));
|
||||||
}
|
}
|
||||||
|
if (aReplaySkipForward) {
|
||||||
|
aReplaySkipForward->setShortcuts(shortcuts.getShortcut("Replays/aSkipForward"));
|
||||||
|
}
|
||||||
|
if (aReplaySkipBackward) {
|
||||||
|
aReplaySkipBackward->setShortcuts(shortcuts.getShortcut("Replays/aSkipBackward"));
|
||||||
|
}
|
||||||
|
if (aReplaySkipForwardBig) {
|
||||||
|
aReplaySkipForwardBig->setShortcuts(shortcuts.getShortcut("Replays/aSkipForwardBig"));
|
||||||
|
}
|
||||||
|
if (aReplaySkipBackwardBig) {
|
||||||
|
aReplaySkipBackwardBig->setShortcuts(shortcuts.getShortcut("Replays/aSkipBackwardBig"));
|
||||||
|
}
|
||||||
if (replayPlayButton) {
|
if (replayPlayButton) {
|
||||||
replayPlayButton->setShortcut(shortcuts.getSingleShortcut("Replays/playButton"));
|
replayPlayButton->setShortcut(shortcuts.getSingleShortcut("Replays/playButton"));
|
||||||
}
|
}
|
||||||
|
|
@ -1699,12 +1711,35 @@ void TabGame::createPlayAreaWidget(bool bReplay)
|
||||||
|
|
||||||
void TabGame::createReplayDock()
|
void TabGame::createReplayDock()
|
||||||
{
|
{
|
||||||
|
// timeline widget
|
||||||
timelineWidget = new ReplayTimelineWidget;
|
timelineWidget = new ReplayTimelineWidget;
|
||||||
timelineWidget->setTimeline(replayTimeline);
|
timelineWidget->setTimeline(replayTimeline);
|
||||||
connect(timelineWidget, SIGNAL(processNextEvent()), this, SLOT(replayNextEvent()));
|
connect(timelineWidget, SIGNAL(processNextEvent()), this, SLOT(replayNextEvent()));
|
||||||
connect(timelineWidget, SIGNAL(replayFinished()), this, SLOT(replayFinished()));
|
connect(timelineWidget, SIGNAL(replayFinished()), this, SLOT(replayFinished()));
|
||||||
connect(timelineWidget, &ReplayTimelineWidget::rewound, messageLog, &ChatView::clearChat);
|
connect(timelineWidget, &ReplayTimelineWidget::rewound, messageLog, &ChatView::clearChat);
|
||||||
|
|
||||||
|
// timeline skip shortcuts
|
||||||
|
aReplaySkipForward = new QAction(timelineWidget);
|
||||||
|
timelineWidget->addAction(aReplaySkipForward);
|
||||||
|
connect(aReplaySkipForward, &QAction::triggered, this,
|
||||||
|
[=]() { timelineWidget->skipByAmount(SMALL_SKIP_AMOUNT_MS); });
|
||||||
|
|
||||||
|
aReplaySkipBackward = new QAction(timelineWidget);
|
||||||
|
timelineWidget->addAction(aReplaySkipBackward);
|
||||||
|
connect(aReplaySkipBackward, &QAction::triggered, this,
|
||||||
|
[=]() { timelineWidget->skipByAmount(-SMALL_SKIP_AMOUNT_MS); });
|
||||||
|
|
||||||
|
aReplaySkipForwardBig = new QAction(timelineWidget);
|
||||||
|
timelineWidget->addAction(aReplaySkipForwardBig);
|
||||||
|
connect(aReplaySkipForwardBig, &QAction::triggered, this,
|
||||||
|
[=]() { timelineWidget->skipByAmount(BIG_SKIP_AMOUNT_MS); });
|
||||||
|
|
||||||
|
aReplaySkipBackwardBig = new QAction(timelineWidget);
|
||||||
|
timelineWidget->addAction(aReplaySkipBackwardBig);
|
||||||
|
connect(aReplaySkipBackwardBig, &QAction::triggered, this,
|
||||||
|
[=]() { timelineWidget->skipByAmount(-BIG_SKIP_AMOUNT_MS); });
|
||||||
|
|
||||||
|
// buttons
|
||||||
replayPlayButton = new QToolButton;
|
replayPlayButton = new QToolButton;
|
||||||
replayPlayButton->setIconSize(QSize(32, 32));
|
replayPlayButton->setIconSize(QSize(32, 32));
|
||||||
QIcon playButtonIcon = QIcon();
|
QIcon playButtonIcon = QIcon();
|
||||||
|
|
@ -1720,6 +1755,7 @@ void TabGame::createReplayDock()
|
||||||
replayFastForwardButton->setCheckable(true);
|
replayFastForwardButton->setCheckable(true);
|
||||||
connect(replayFastForwardButton, SIGNAL(toggled(bool)), this, SLOT(replayFastForwardButtonToggled(bool)));
|
connect(replayFastForwardButton, SIGNAL(toggled(bool)), this, SLOT(replayFastForwardButtonToggled(bool)));
|
||||||
|
|
||||||
|
// putting everything together
|
||||||
replayControlLayout = new QHBoxLayout;
|
replayControlLayout = new QHBoxLayout;
|
||||||
replayControlLayout->addWidget(timelineWidget, 10);
|
replayControlLayout->addWidget(timelineWidget, 10);
|
||||||
replayControlLayout->addWidget(replayPlayButton);
|
replayControlLayout->addWidget(replayPlayButton);
|
||||||
|
|
|
||||||
|
|
@ -142,11 +142,14 @@ private:
|
||||||
QStackedWidget *mainWidget;
|
QStackedWidget *mainWidget;
|
||||||
|
|
||||||
// Replay related members
|
// Replay related members
|
||||||
|
static const int SMALL_SKIP_AMOUNT_MS = 1000;
|
||||||
|
static const int BIG_SKIP_AMOUNT_MS = 10000;
|
||||||
GameReplay *replay;
|
GameReplay *replay;
|
||||||
int currentReplayStep;
|
int currentReplayStep;
|
||||||
QList<int> replayTimeline;
|
QList<int> replayTimeline;
|
||||||
ReplayTimelineWidget *timelineWidget;
|
ReplayTimelineWidget *timelineWidget;
|
||||||
QToolButton *replayPlayButton, *replayFastForwardButton;
|
QToolButton *replayPlayButton, *replayFastForwardButton;
|
||||||
|
QAction *aReplaySkipForward, *aReplaySkipBackward, *aReplaySkipForwardBig, *aReplaySkipBackwardBig;
|
||||||
|
|
||||||
CardFrame *cardInfo;
|
CardFrame *cardInfo;
|
||||||
PlayerListWidget *playerListWidget;
|
PlayerListWidget *playerListWidget;
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ void ShortcutsSettings::clearAllShortcuts()
|
||||||
bool ShortcutsSettings::isKeyAllowed(const QString &name, const QString &Sequences) const
|
bool ShortcutsSettings::isKeyAllowed(const QString &name, const QString &Sequences) const
|
||||||
{
|
{
|
||||||
// if the shortcut is not to be used in deck-editor then it doesn't matter
|
// if the shortcut is not to be used in deck-editor then it doesn't matter
|
||||||
if (name.startsWith("Player")) {
|
if (name.startsWith("Player") || name.startsWith("Replays")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
QString checkSequence = Sequences.split(sep).last();
|
QString checkSequence = Sequences.split(sep).last();
|
||||||
|
|
|
||||||
|
|
@ -590,11 +590,23 @@ private:
|
||||||
{"DlgLoadDeckFromClipboard/refreshButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Refresh"),
|
{"DlgLoadDeckFromClipboard/refreshButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Refresh"),
|
||||||
parseSequenceString("F5"),
|
parseSequenceString("F5"),
|
||||||
ShortcutGroup::Load_deck)},
|
ShortcutGroup::Load_deck)},
|
||||||
|
{"Replays/aSkipForward", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Skip Forward"),
|
||||||
|
parseSequenceString("Right"),
|
||||||
|
ShortcutGroup::Replays)},
|
||||||
|
{"Replays/aSkipBackward", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Skip Backward"),
|
||||||
|
parseSequenceString("Left"),
|
||||||
|
ShortcutGroup::Replays)},
|
||||||
|
{"Replays/aSkipForwardBig", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Skip Forward by a lot"),
|
||||||
|
parseSequenceString("Ctrl+Right"),
|
||||||
|
ShortcutGroup::Replays)},
|
||||||
|
{"Replays/aSkipBackwardBig", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Skip Backward by a lot"),
|
||||||
|
parseSequenceString("Ctrl+Left"),
|
||||||
|
ShortcutGroup::Replays)},
|
||||||
{"Replays/playButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Play/Pause"),
|
{"Replays/playButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Play/Pause"),
|
||||||
parseSequenceString("Space"),
|
parseSequenceString("Space"),
|
||||||
ShortcutGroup::Replays)},
|
ShortcutGroup::Replays)},
|
||||||
{"Replays/fastForwardButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Toggle Fast Forward"),
|
{"Replays/fastForwardButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Toggle Fast Forward"),
|
||||||
parseSequenceString("Ctrl+Right"),
|
parseSequenceString("Ctrl+P"),
|
||||||
ShortcutGroup::Replays)}};
|
ShortcutGroup::Replays)}};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue