Skip to content

Commit

Permalink
Update commandpalette.cpp
Browse files Browse the repository at this point in the history
Skip next/prev frames using -/+ INT (s/m)

Ref: #214
  • Loading branch information
rodlie committed Jul 28, 2024
1 parent 63bcd57 commit 772075c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ui/dialogs/commandpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ void CommandPalette::parseCmd(const QString &input)
const bool goToFrame = (validFrameCmd.match(input).hasMatch() && input != ":");
qDebug() << "go to frame?" << goToFrame;

static QRegularExpression validFrameSkipNextCmd("^\\+[0-9]*[sm]?$");
const bool skipToNextFrame = (validFrameSkipNextCmd.match(input).hasMatch() && input != "+");
qDebug() << "skip to next frame?" << skipToNextFrame;

static QRegularExpression validFrameSkipPrevCmd("^\\-[0-9]*[sm]?$");
const bool skipToPrevFrame = (validFrameSkipPrevCmd.match(input).hasMatch() && input != "-");
qDebug() << "skip to prev frame?" << skipToPrevFrame;

static QRegularExpression validRotateCmd("^rotate[:][-]?[0-9,.]*$");
const bool doRotate = (validRotateCmd.match(input).hasMatch() && input != "rotate:");
qDebug() << "do rotate?" << doRotate;
Expand All @@ -223,20 +231,22 @@ void CommandPalette::parseCmd(const QString &input)
const bool doFrameOut = (validFrameOutCmd.match(input).hasMatch() && input != "out:");
qDebug() << "do frame out?" << doFrameOut;

if (goToFrame) {
if (goToFrame || skipToNextFrame || skipToPrevFrame) {
QString frame = input.simplified();
const bool hasSec = frame.endsWith("s");
const bool hasMin = frame.endsWith("m");
if (hasSec && hasMin) { return; }
if (!isIntOrDouble(frame.replace(":", "")
if (!isIntOrDouble(frame.replace(goToFrame ? ":" : (skipToNextFrame ? "+" : "-"), "")
.replace("m", "")
.replace("s", ""))) { return; }
int value = frame.toInt();
const auto scene = *mDocument.fActiveScene;
if (!scene) { return; }
if (hasSec) { value *= scene->getFps(); }
else if (hasMin) { value = (value * 60) * scene->getFps(); }
qDebug() << "go to frame" << value;

if (!goToFrame) { value = skipToNextFrame ? scene->getCurrentFrame() + value : scene->getCurrentFrame() - value; }
qDebug() << "go to or skip to frame" << value;
scene->anim_setAbsFrame(value);
mDocument.actionFinished();
appendHistory(input);
Expand Down Expand Up @@ -395,7 +405,7 @@ bool CommandPalette::eventFilter(QObject *obj, QEvent *e)
getHistory(keyEvent->modifiers() & Qt::ShiftModifier);
return true;
} else if (keyEvent->key() == Qt::Key_Down) {
mSuggestions->setFocus();
if (mSuggestions->isVisible()) { mSuggestions->setFocus(); }
return true;
}
}
Expand Down

0 comments on commit 772075c

Please sign in to comment.