Make setting markers easier (#324)

* Make setting markers easier

* More tweaks
This commit is contained in:
Jeremy Bullock 2020-11-04 14:25:00 -07:00 committed by GitHub
parent a599d98bca
commit dfed2a033d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 158 additions and 118 deletions

View file

@ -2058,6 +2058,12 @@ void MainWindow::defineActions() {
tr("Remove Multiple Keys"), "");
menuAct->setIcon(createQIcon("remove_multiple_keys"));
menuAct = createMenuXsheetAction(MI_SetStartMarker, tr("Set Start Marker"), "");
menuAct = createMenuXsheetAction(MI_SetStopMarker, tr("Set Stop Marker"), "");
menuAct = createMenuXsheetAction(MI_ClearMarkers, tr("Remove Markers"), "");
menuAct = createMenuXsheetAction(MI_SetAutoMarkers, tr("Set Auto Markers"), "");
menuAct = createMenuXsheetAction(MI_PreviewThis, tr("Set Markers to Current Frame"), "");
menuAct = createMenuLevelAction(MI_NewNoteLevel, tr("New Note Level"), "");
menuAct->setIcon(createQIcon("new_note_level"));

View file

@ -138,6 +138,12 @@
#define MI_InsertFx "MI_InsertFx"
#define MI_NewOutputFx "MI_NewOutputFx"
#define MI_SetStartMarker "MI_SetStartMarker"
#define MI_SetStopMarker "MI_SetStopMarker"
#define MI_ClearMarkers "MI_ClearMarkers"
#define MI_SetAutoMarkers "MI_SetAutoMarkers"
#define MI_PreviewThis "MI_PreviewThis"
#define MI_PasteNew "MI_PasteNew"
#define MI_Autorenumber "MI_Autorenumber"
#define MI_CreateBlankDrawing "MI_CreateBlankDrawing"

View file

@ -49,7 +49,8 @@
#include "toonzqt/menubarcommand.h"
#include "toonzqt/stageobjectsdata.h"
#include "historytypes.h"
#include "xsheetdragtool.h"
#include "xsheetviewer.h"
// Tnz6 includes
#include "cellselection.h"
#include "columnselection.h"
@ -2142,3 +2143,129 @@ public:
}
} ToggleXsheetCameraColumnCommand;
//============================================================
class SetStartMarker final : public MenuItemHandler {
public:
SetStartMarker()
: MenuItemHandler(MI_SetStartMarker) {}
void execute() override {
int frame = TApp::instance()->getCurrentFrame()->getFrame();
assert(frame >= 0);
int r0, r1, step;
XsheetGUI::getPlayRange(r0, r1, step);
if (r0 > r1) {
r0 = 0;
r1 = TApp::instance()->getCurrentScene()->getScene()->getFrameCount() - 1;
if (r1 < 1) r1 = 1;
}
r0 = frame;
if (r1 < r0) r1 = r0;
XsheetGUI::setPlayRange(r0, r1, step);
TApp::instance()->getCurrentXsheetViewer()->update();
}
} SetStartMarker;
//============================================================
class SetStopMarker final : public MenuItemHandler {
public:
SetStopMarker()
: MenuItemHandler(MI_SetStopMarker) {}
void execute() override {
int frame = TApp::instance()->getCurrentFrame()->getFrame();
assert(frame >= 0);
int r0, r1, step;
XsheetGUI::getPlayRange(r0, r1, step);
if (r0 > r1) {
r0 = 0;
r1 = TApp::instance()->getCurrentScene()->getScene()->getFrameCount() - 1;
if (r1 < 1) r1 = 1;
}
r1 = frame;
if (r1 < r0) r0 = r1;
r1 -= (step == 0) ? (r1 - r0) : (r1 - r0) % step;
XsheetGUI::setPlayRange(r0, r1, step);
TApp::instance()->getCurrentXsheetViewer()->update();
}
} SetStopMarker;
//============================================================
class ClearMarkers final : public MenuItemHandler {
public:
ClearMarkers()
: MenuItemHandler(MI_ClearMarkers) {}
void execute() override {
int step, r0, r1;
XsheetGUI::getPlayRange(r0, r1, step);
XsheetGUI::setPlayRange(0, -1, step);
TApp::instance()->getCurrentXsheetViewer()->update();
}
} ClearMarkers;
//============================================================
class SetAutoMarkers final : public MenuItemHandler {
public:
SetAutoMarkers()
: MenuItemHandler(MI_SetAutoMarkers) {}
enum Direction { up = 0, down };
int getNonEmptyCell(int row, int column, Direction direction) {
int currentPos = row;
bool exit = false;
while (!exit) {
TXshCell cell = TApp::instance()->getCurrentXsheetViewer()->getXsheet()->getCell(currentPos, column);
if (cell.isEmpty()) {
(direction == up) ? currentPos++ : currentPos--;
exit = true;
}
else
(direction == up) ? currentPos-- : currentPos++;
}
return currentPos;
}
void execute() override {
int col = TApp::instance()->getCurrentColumn()->getColumnIndex();
int row = TApp::instance()->getCurrentFrame()->getFrame();
TXshCell cell =
TApp::instance()->getCurrentXsheetViewer()->getXsheet()->getCell(row, col);
if (cell.isEmpty()) return;
int step, r0, r1;
int top = getNonEmptyCell(row, col, Direction::up);
int bottom = getNonEmptyCell(row, col, Direction::down);
XsheetGUI::getPlayRange(r0, r1, step);
XsheetGUI::setPlayRange(top, bottom, step);
TApp::instance()->getCurrentXsheetViewer()->update();
}
} SetAutoMarkers;
//============================================================
class PreviewThis final : public MenuItemHandler {
public:
PreviewThis()
: MenuItemHandler(MI_PreviewThis) {}
void execute() override {
int row = TApp::instance()->getCurrentFrame()->getFrame();
assert(row >= 0);
int r0, r1, step;
XsheetGUI::getPlayRange(r0, r1, step);
XsheetGUI::setPlayRange(row, row, step);
TApp::instance()->getCurrentXsheetViewer()->update();
}
} PreviewThis;

View file

@ -1201,9 +1201,16 @@ void RowArea::mouseReleaseEvent(QMouseEvent *event) {
TPoint pos(event->pos().x(), event->pos().y());
int row = m_viewer->xyToPosition(pos).frame();
if (m_playRangeActiveInMousePress && row == m_mousePressRow &&
(13 <= pos.x && pos.x <= 26 && (row == m_r0 || row == m_r1)))
onRemoveMarkers();
if ((event->modifiers() & Qt::AltModifier) && (event->modifiers() & Qt::ControlModifier)) {
CommandManager::instance()->execute(MI_ClearMarkers);
}
else if (m_mousePressRow == -1 && (event->modifiers() & Qt::ControlModifier)) {
CommandManager::instance()->execute(MI_SetStartMarker);
}
else if (m_mousePressRow == -1 && (event->modifiers() & Qt::AltModifier)) {
CommandManager::instance()->execute(MI_SetStopMarker);
}
}
//-----------------------------------------------------------------------------
@ -1213,21 +1220,18 @@ void RowArea::contextMenuEvent(QContextMenuEvent *event) {
TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
QMenu *menu = new QMenu(this);
QAction *setStartMarker = menu->addAction(tr("Set Start Marker"));
connect(setStartMarker, SIGNAL(triggered()), SLOT(onSetStartMarker()));
QAction *setStopMarker = menu->addAction(tr("Set Stop Marker"));
connect(setStopMarker, SIGNAL(triggered()), SLOT(onSetStopMarker()));
menu->addAction(CommandManager::instance()->getAction(MI_SetStartMarker));
menu->addAction(CommandManager::instance()->getAction(MI_SetStopMarker));
QAction *setAutoMarkers = menu->addAction(tr("Set Auto Markers"));
connect(setAutoMarkers, SIGNAL(triggered()), SLOT(onSetAutoMarkers()));
QAction* setAutoMarkers = CommandManager::instance()->getAction(MI_SetAutoMarkers);
menu->addAction(setAutoMarkers);
setAutoMarkers->setEnabled(canSetAutoMarkers());
QAction *removeMarkers = menu->addAction(tr("Remove Markers"));
connect(removeMarkers, SIGNAL(triggered()), SLOT(onRemoveMarkers()));
menu->addAction(CommandManager::instance()->getAction(MI_ClearMarkers));
// set both the from and to markers at the specified row
QAction *previewThis = menu->addAction(tr("Preview This"));
connect(previewThis, SIGNAL(triggered()), SLOT(onPreviewThis()));
menu->addAction(CommandManager::instance()->getAction(MI_PreviewThis));
menu->addSeparator();
@ -1267,23 +1271,6 @@ bool RowArea::canSetAutoMarkers() {
return cell.isEmpty() ? false : true;
}
//-----------------------------------------------------------------------------
int RowArea::getNonEmptyCell(int row, int column, Direction direction) {
int currentPos = row;
bool exit = false;
while (!exit) {
TXshCell cell = m_viewer->getXsheet()->getCell(currentPos, column);
if (cell.isEmpty()) {
(direction == up) ? currentPos++ : currentPos--;
exit = true;
} else
(direction == up) ? currentPos-- : currentPos++;
}
return currentPos;
}
//-----------------------------------------------------------------------------
void RowArea::mouseDoubleClickEvent(QMouseEvent *event) {
@ -1327,74 +1314,4 @@ bool RowArea::event(QEvent *event) {
//-----------------------------------------------------------------------------
void RowArea::setMarker(int index) {
assert(m_row >= 0);
// I use only the step value..
int unused0, unused1, step;
getPlayRange(unused0, unused1, step);
if (m_r0 > m_r1) {
m_r0 = 0;
m_r1 = TApp::instance()->getCurrentScene()->getScene()->getFrameCount() - 1;
if (m_r1 < 1) m_r1 = 1;
}
if (index == 0) {
m_r0 = m_row;
if (m_r1 < m_r0) m_r1 = m_r0;
} else if (index == 1) {
m_r1 = m_row;
if (m_r1 < m_r0) m_r0 = m_r1;
m_r1 -= (step == 0) ? (m_r1 - m_r0) : (m_r1 - m_r0) % step;
}
setPlayRange(m_r0, m_r1, step);
}
//-----------------------------------------------------------------------------
void RowArea::onSetStartMarker() {
setMarker(0);
update();
}
//-----------------------------------------------------------------------------
void RowArea::onSetStopMarker() {
setMarker(1);
update();
}
//-----------------------------------------------------------------------------
// set both the from and to markers at the specified row
void RowArea::onPreviewThis() {
assert(m_row >= 0);
int r0, r1, step;
getPlayRange(r0, r1, step);
setPlayRange(m_row, m_row, step);
update();
}
// Set the playing markers to the continuous block of the cell pointed by
// current row and column
void RowArea::onSetAutoMarkers() {
int currentColumn = m_viewer->getCurrentColumn();
int top = getNonEmptyCell(m_row, currentColumn, Direction::up);
int bottom = getNonEmptyCell(m_row, currentColumn, Direction::down);
int r0, r1, step;
getPlayRange(r0, r1, step);
setPlayRange(top, bottom, step);
update();
}
//-----------------------------------------------------------------------------
void RowArea::onRemoveMarkers() {
int step;
XsheetGUI::getPlayRange(m_r0, m_r1, step);
XsheetGUI::setPlayRange(0, -1, step);
update();
}
//-----------------------------------------------------------------------------
} // namespace XsheetGUI

View file

@ -61,9 +61,6 @@ class RowArea final : public QWidget {
// Return when the item-menu setAutoMarkers can be enabled.
bool canSetAutoMarkers();
// Return the number of the last non-empty cell finded. You can set the
// direction of the search.
int getNonEmptyCell(int row, int column, Direction);
public:
#if QT_VERSION >= 0x050500
@ -83,19 +80,6 @@ protected:
void mouseDoubleClickEvent(QMouseEvent *event) override;
bool event(QEvent *event) override;
void setMarker(int index);
protected slots:
void onSetStartMarker();
void onSetStopMarker();
void onRemoveMarkers();
// Set start and end marker automatically respect the current row and column.
void onSetAutoMarkers();
// set both the from and to markers at the specified row
void onPreviewThis();
};
} // namespace XsheetGUI;