Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

#assistants: handle common delete shortcuts

Ivan Mahonin4dfb4a1dfcdc
diff --git a/toonz/sources/tnztools/editassistantstool.cpp b/toonz/sources/tnztools/editassistantstool.cpp
index 7a3ba76b1..763a64c11 100644
--- a/toonz/sources/tnztools/editassistantstool.cpp
+++ b/toonz/sources/tnztools/editassistantstool.cpp
@@ -17,6 +17,8 @@
#include <tproperty.h>
#include <tmetaimage.h>
+#include <toonzqt/selection.h>
+#include <toonzqt/selectioncommandids.h>
#include <toonzqt/tselectionhandle.h>
// For Qt translation support
@@ -112,6 +114,24 @@ public:
class EditAssistantsTool final : public TTool {
Q_DECLARE_TR_FUNCTIONS(EditAssistantsTool)
+public:
+ class Selection final : public TSelection {
+ private:
+ EditAssistantsTool &tool;
+ public:
+ explicit Selection(EditAssistantsTool &tool):
+ tool(tool) { }
+ void deleteSelection()
+ { tool.removeSelected(); }
+
+ void enableCommands() override
+ { if (!isEmpty()) enableCommand(this, MI_Clear, &Selection::deleteSelection); }
+ bool isEmpty() const override
+ { return !tool.isSelected(); }
+ void selectNone() override
+ { tool.deselect(); }
+ };
+
protected:
enum Mode {
ModeImage,
@@ -147,6 +167,8 @@ protected:
TMetaObjectP m_writeObject;
TAssistant *m_writeAssistant;
+ Selection *selection;
+
public:
EditAssistantsTool():
TTool("T_EditAssistants"),
@@ -163,13 +185,16 @@ public:
m_writeImage(),
m_writeAssistant()
{
+ selection = new Selection(*this);
bind(MetaImage | EmptyTarget);
m_toolProperties.bind(m_assistantType);
updateTranslation();
}
- ~EditAssistantsTool()
- { close(); }
+ ~EditAssistantsTool() {
+ close();
+ delete selection;
+ }
ToolType getToolType() const override
{ return TTool::LevelWriteTool; }
@@ -238,7 +263,10 @@ public:
}
return true;
}
-
+
+ TSelection* getSelection() override
+ { return isSelected() ? selection : 0; }
+
protected:
void close() {
m_readAssistant = 0;
@@ -261,7 +289,7 @@ protected:
|| (mode >= ModeAssistant && m_currentAssistantIndex < 0)
|| (mode >= ModePoint && !m_currentPointName) ) return false;
- m_readImage = dynamic_cast<TMetaImage*>(getImage(true));
+ m_readImage = dynamic_cast<TMetaImage*>(getImage(false));
if (m_readImage) {
m_reader = new TMetaImage::Reader(*m_readImage);
if (mode == ModeImage) return true;
@@ -430,16 +458,48 @@ protected:
if (success) {
notifyImageChanged();
getApplication()->getCurrentTool()->notifyToolChanged();
+ TTool::getApplication()->getCurrentSelection()->setSelection( getSelection() );
getViewer()->GLInvalidateAll();
}
return success;
}
-
+
public:
+ void deselect()
+ { resetCurrentPoint(); }
+
+ bool isSelected()
+ { return read(ModeAssistant); }
+
+ bool removeSelected() {
+ apply();
+ bool success = false;
+ if (Closer closer = write(ModeAssistant, true)) {
+ (*m_writer)->erase((*m_writer)->begin() + m_currentAssistantIndex);
+ TUndoManager::manager()->add(new EditAssistantsUndo(
+ getApplication()->getCurrentLevel()->getLevel()->getSimpleLevel(),
+ getCurrentFid(),
+ false, // frameCreated
+ false, // levelCreated
+ false, // objectCreated
+ true, // objectRemoved
+ m_currentAssistantIndex, m_writeObject, m_writeObject->data()));
+ success = true;
+ }
+
+ if (success) notifyImageChanged();
+
+ resetCurrentPoint();
+ getApplication()->getCurrentTool()->notifyToolChanged();
+ TTool::getApplication()->getCurrentSelection()->setSelection( getSelection() );
+ getViewer()->GLInvalidateAll();
+ return success;
+ }
+
bool preLeftButtonDown() override {
if (m_assistantType.getIndex() != 0) touchImage();
- TTool::getApplication()->getCurrentSelection()->setSelection(0);
+ TTool::getApplication()->getCurrentSelection()->setSelection( getSelection() );
return true;
}
@@ -456,6 +516,7 @@ public:
assistant->setDefaults();
assistant->move(position);
assistant->selectAll();
+ m_currentImage.set(m_writeImage);
m_dragAllPoints = true;
m_currentAssistantCreated = true;
m_currentAssistantChanged = true;
@@ -498,11 +559,9 @@ public:
}
void leftButtonUp(const TPointD &position, const TMouseEvent&) override {
- if (m_currentAssistantCreated) {
- if (Closer closer = write(ModeAssistant, true)) {
- m_writeAssistant->getBasePoint();
+ if (m_dragAllPoints) {
+ if (Closer closer = write(ModeAssistant, true))
m_writeAssistant->move( position + m_currentPointOffset );
- }
} else {
if (Closer closer = write(ModePoint, true))
m_writeAssistant->movePoint(
@@ -513,45 +572,13 @@ public:
apply();
m_assistantType.setIndex(0);
getApplication()->getCurrentTool()->notifyToolChanged();
- emit getApplication()->getCurrentTool()->toolChanged();
+ TTool::getApplication()->getCurrentSelection()->setSelection( getSelection() );
m_currentPosition = position;
getViewer()->GLInvalidateAll();
m_dragAllPoints = false;
m_dragging = false;
}
- bool keyDown(QKeyEvent *keyEvent) override {
- if (keyEvent->key() == Qt::Key_Backspace) {
- if (!m_dragging) {
- apply();
- bool success = false;
- if (Closer closer = write(ModeAssistant, true)) {
- (*m_writer)->erase((*m_writer)->begin() + m_currentAssistantIndex);
- TUndoManager::manager()->add(new EditAssistantsUndo(
- getApplication()->getCurrentLevel()->getLevel()->getSimpleLevel(),
- getCurrentFid(),
- false, // frameCreated
- false, // levelCreated
- false, // objectCreated
- true, // objectRemoved
- m_currentAssistantIndex,
- m_writeObject,
- m_writeObject->data() ));
- success = true;
- }
-
- if (success)
- notifyImageChanged();
-
- resetCurrentPoint();
- getApplication()->getCurrentTool()->notifyToolChanged();
- getViewer()->GLInvalidateAll();
- }
- return true;
- }
- return false;
- }
-
void draw() override {
m_currentGuidelines.clear();