From eb0a56909e331352caf4838277ff93c6496fe034 Mon Sep 17 00:00:00 2001 From: jabarrera Date: Feb 01 2017 03:56:14 +0000 Subject: Set auto markers (#982) close #572 --- diff --git a/toonz/sources/toonz/xshrowviewer.cpp b/toonz/sources/toonz/xshrowviewer.cpp index 3e89693..820bec5 100644 --- a/toonz/sources/toonz/xshrowviewer.cpp +++ b/toonz/sources/toonz/xshrowviewer.cpp @@ -688,6 +688,11 @@ void RowArea::contextMenuEvent(QContextMenuEvent *event) { connect(setStartMarker, SIGNAL(triggered()), SLOT(onSetStartMarker())); QAction *setStopMarker = menu->addAction(tr("Set Stop Marker")); connect(setStopMarker, SIGNAL(triggered()), SLOT(onSetStopMarker())); + + QAction *setAutoMarkers = menu->addAction(tr("Set Auto Markers")); + connect(setAutoMarkers, SIGNAL(triggered()), SLOT(onSetAutoMarkers())); + setAutoMarkers->setEnabled(canSetAutoMarkers()); + QAction *removeMarkers = menu->addAction(tr("Remove Markers")); connect(removeMarkers, SIGNAL(triggered()), SLOT(onRemoveMarkers())); @@ -719,6 +724,32 @@ void RowArea::contextMenuEvent(QContextMenuEvent *event) { } //----------------------------------------------------------------------------- +// Checks if there is a cell non empty at current row and column to enable the +// auto markers item-menu. +bool RowArea::canSetAutoMarkers() { + TXshCell cell = + m_viewer->getXsheet()->getCell(m_row, m_viewer->getCurrentColumn()); + 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) { int currentFrame = TApp::instance()->getCurrentFrame()->getFrame(); @@ -796,6 +827,20 @@ void RowArea::onPreviewThis() { 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() { diff --git a/toonz/sources/toonz/xshrowviewer.h b/toonz/sources/toonz/xshrowviewer.h index a486a22..53e1bdf 100644 --- a/toonz/sources/toonz/xshrowviewer.h +++ b/toonz/sources/toonz/xshrowviewer.h @@ -30,6 +30,8 @@ class RowArea final : public QWidget { Mos } m_showOnionToSet; // TODO:�����͂����Fos,Mos�ǂ�����n�C���C�g���Ă���̂����肳����I�I�I�I + enum Direction { up = 0, down }; + // Play ranges int m_r0; int m_r1; @@ -51,6 +53,12 @@ class RowArea final : public QWidget { DragTool *getDragTool() const; void setDragTool(DragTool *dragTool); + // 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 RowArea(XsheetViewer *parent, Qt::WindowFlags flags = 0); @@ -77,6 +85,9 @@ protected slots: 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(); };