From ee20aff397a799c252f3161a9057506be34dd92f Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 24 Oct 2018 21:44:21 +0800 Subject: [PATCH] Improve shortcuts Shortcuts implementation now use QShortcut instead of using the raw key event. Besides, hold spacebar to temporarily enter drag mode also implemented in this commit, this is very useful in zoom mode. --- dust3d.pro | 3 + src/shortcuts.cpp | 49 ++++ src/shortcuts.h | 8 + src/skeletondocumentwindow.cpp | 3 + src/skeletongraphicswidget.cpp | 515 +++++++++++++++++++-------------- src/skeletongraphicswidget.h | 49 +++- 6 files changed, 402 insertions(+), 225 deletions(-) create mode 100644 src/shortcuts.cpp create mode 100644 src/shortcuts.h diff --git a/dust3d.pro b/dust3d.pro index d627f18b..70c28268 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -266,6 +266,9 @@ HEADERS += src/tabwidget.h SOURCES += src/flowlayout.cpp HEADERS += src/flowlayout.h +SOURCES += src/shortcuts.cpp +HEADERS += src/shortcuts.h + SOURCES += src/main.cpp HEADERS += src/version.h diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp new file mode 100644 index 00000000..08407a2c --- /dev/null +++ b/src/shortcuts.cpp @@ -0,0 +1,49 @@ +#include +#include +#include "shortcuts.h" + +#define defineKey(keyVal, funcName) do { \ + auto key = new QShortcut(mainWindow); \ + key->setKey(keyVal); \ + QObject::connect(key, &QShortcut::activated, \ + graphicsWidget, funcName); \ +} while (false) + +void initShortCuts(QMainWindow *mainWindow, SkeletonGraphicsWidget *graphicsWidget) +{ + defineKey(Qt::Key_Delete, &SkeletonGraphicsWidget::shortcutDelete); + defineKey(Qt::Key_Backspace, &SkeletonGraphicsWidget::shortcutDelete); + defineKey(Qt::Key_A, &SkeletonGraphicsWidget::shortcutAddMode); + defineKey(Qt::CTRL + Qt::Key_Z, &SkeletonGraphicsWidget::shortcutUndo); + defineKey(Qt::CTRL + Qt::SHIFT + Qt::Key_Z, &SkeletonGraphicsWidget::shortcutRedo); + defineKey(Qt::CTRL + Qt::Key_Y, &SkeletonGraphicsWidget::shortcutRedo); + defineKey(Qt::Key_Z, &SkeletonGraphicsWidget::shortcutZlock); + defineKey(Qt::Key_Y, &SkeletonGraphicsWidget::shortcutYlock); + defineKey(Qt::CTRL + Qt::Key_X, &SkeletonGraphicsWidget::shortcutCut); + defineKey(Qt::Key_X, &SkeletonGraphicsWidget::shortcutXlock); + defineKey(Qt::CTRL + Qt::Key_C, &SkeletonGraphicsWidget::shortcutCopy); + defineKey(Qt::CTRL + Qt::Key_V, &SkeletonGraphicsWidget::shortcutPaste); + defineKey(Qt::CTRL + Qt::Key_S, &SkeletonGraphicsWidget::shortcutSave); + defineKey(Qt::Key_S, &SkeletonGraphicsWidget::shortcutSelectMode); + defineKey(Qt::Key_D, &SkeletonGraphicsWidget::shortcutDragMode); + defineKey(Qt::ALT + Qt::Key_Minus, &SkeletonGraphicsWidget::shortcutZoomRenderedModelByMinus10); + defineKey(Qt::Key_Minus, &SkeletonGraphicsWidget::shortcutZoomSelectedByMinus1); + defineKey(Qt::ALT + Qt::Key_Equal, &SkeletonGraphicsWidget::shortcutZoomRenderedModelBy10); + defineKey(Qt::Key_Equal, &SkeletonGraphicsWidget::shortcutZoomSelectedBy1); + defineKey(Qt::Key_Comma, &SkeletonGraphicsWidget::shortcutRotateSelectedByMinus1); + defineKey(Qt::Key_Period, &SkeletonGraphicsWidget::shortcutRotateSelectedBy1); + defineKey(Qt::Key_Left, &SkeletonGraphicsWidget::shortcutMoveSelectedToLeft); + defineKey(Qt::Key_Right, &SkeletonGraphicsWidget::shortcutMoveSelectedToRight); + defineKey(Qt::Key_Up, &SkeletonGraphicsWidget::shortcutMoveSelectedToUp); + defineKey(Qt::Key_Down, &SkeletonGraphicsWidget::shortcutMoveSelectedToDown); + defineKey(Qt::Key_BracketLeft, &SkeletonGraphicsWidget::shortcutScaleSelectedByMinus1); + defineKey(Qt::Key_BracketRight, &SkeletonGraphicsWidget::shortcutScaleSelectedBy1); + defineKey(Qt::Key_E, &SkeletonGraphicsWidget::shortcutSwitchProfileOnSelected); + defineKey(Qt::Key_H, &SkeletonGraphicsWidget::shortcutShowOrHideSelectedPart); + defineKey(Qt::Key_J, &SkeletonGraphicsWidget::shortcutEnableOrDisableSelectedPart); + defineKey(Qt::Key_L, &SkeletonGraphicsWidget::shortcutLockOrUnlockSelectedPart); + defineKey(Qt::Key_M, &SkeletonGraphicsWidget::shortcutXmirrorOnOrOffSelectedPart); + defineKey(Qt::Key_B, &SkeletonGraphicsWidget::shortcutSubdivedOrNotSelectedPart); + defineKey(Qt::Key_U, &SkeletonGraphicsWidget::shortcutRoundEndOrNotSelectedPart); + defineKey(Qt::Key_W, &SkeletonGraphicsWidget::shortcutWrapOrNotSelectedPart); +} diff --git a/src/shortcuts.h b/src/shortcuts.h new file mode 100644 index 00000000..1bc3eefb --- /dev/null +++ b/src/shortcuts.h @@ -0,0 +1,8 @@ +#ifndef SHORTCUTS_H +#define SHORTCUTS_H +#include +#include "skeletongraphicswidget.h" + +void initShortCuts(QMainWindow *mainWindow, SkeletonGraphicsWidget *graphicsWidget); + +#endif diff --git a/src/skeletondocumentwindow.cpp b/src/skeletondocumentwindow.cpp index 079a2823..599fdeed 100644 --- a/src/skeletondocumentwindow.cpp +++ b/src/skeletondocumentwindow.cpp @@ -35,6 +35,7 @@ #include "imageforever.h" #include "spinnableawesomebutton.h" #include "fbxfile.h" +#include "shortcuts.h" int SkeletonDocumentWindow::m_modelRenderWidgetInitialX = 16; int SkeletonDocumentWindow::m_modelRenderWidgetInitialY = 16; @@ -887,6 +888,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : Q_UNUSED(materialId); m_document->generateMaterialPreviews(); }); + + initShortCuts(this, m_graphicsWidget); connect(this, &SkeletonDocumentWindow::initialized, m_document, &SkeletonDocument::uiReady); diff --git a/src/skeletongraphicswidget.cpp b/src/skeletongraphicswidget.cpp index 158d4133..83901139 100644 --- a/src/skeletongraphicswidget.cpp +++ b/src/skeletongraphicswidget.cpp @@ -43,7 +43,9 @@ SkeletonGraphicsWidget::SkeletonGraphicsWidget(const SkeletonDocument *document) m_ikMover(nullptr), m_deferredRemoveTimer(nullptr), m_eventForwardingToModelWidget(false), - m_modelWidget(nullptr) + m_modelWidget(nullptr), + m_inTempDragMode(false), + m_modeBeforeEnterTempDragMode(SkeletonDocumentEditMode::Select) { setRenderHint(QPainter::Antialiasing, false); setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern)); @@ -627,6 +629,13 @@ void SkeletonGraphicsWidget::keyPressEvent(QKeyEvent *event) QGraphicsView::keyPressEvent(event); } +void SkeletonGraphicsWidget::keyReleaseEvent(QKeyEvent *event) +{ + if (keyRelease(event)) + return; + QGraphicsView::keyReleaseEvent(event); +} + bool SkeletonGraphicsWidget::mouseMove(QMouseEvent *event) { if (m_dragStarted) { @@ -1374,229 +1383,297 @@ void SkeletonGraphicsWidget::deleteSelected() } } +void SkeletonGraphicsWidget::shortcutDelete() +{ + bool processed = false; + if (!m_rangeSelectionSet.empty()) { + deleteSelected(); + processed = true; + } + if (processed) { + emit groupOperationAdded(); + return; + } +} + +void SkeletonGraphicsWidget::shortcutAddMode() +{ + if (SkeletonDocumentEditMode::Add == m_document->editMode) { + emit setEditMode(SkeletonDocumentEditMode::Select); + } else { + emit setEditMode(SkeletonDocumentEditMode::Add); + } +} + +void SkeletonGraphicsWidget::shortcutUndo() +{ + emit undo(); +} + +void SkeletonGraphicsWidget::shortcutRedo() +{ + emit redo(); +} + +void SkeletonGraphicsWidget::shortcutXlock() +{ + emit setXlockState(!m_document->xlocked); +} + +void SkeletonGraphicsWidget::shortcutYlock() +{ + emit setYlockState(!m_document->ylocked); +} + +void SkeletonGraphicsWidget::shortcutZlock() +{ + emit setZlockState(!m_document->zlocked); +} + +void SkeletonGraphicsWidget::shortcutCut() +{ + cut(); +} + +void SkeletonGraphicsWidget::shortcutCopy() +{ + copy(); +} + +void SkeletonGraphicsWidget::shortcutPaste() +{ + emit paste(); +} + +void SkeletonGraphicsWidget::shortcutSave() +{ + emit save(); +} + +void SkeletonGraphicsWidget::shortcutSelectMode() +{ + emit setEditMode(SkeletonDocumentEditMode::Select); +} + +void SkeletonGraphicsWidget::shortcutDragMode() +{ + emit setEditMode(SkeletonDocumentEditMode::Drag); +} + +void SkeletonGraphicsWidget::shortcutZoomRenderedModelByMinus10() +{ + emit zoomRenderedModelBy(-10); +} + +void SkeletonGraphicsWidget::shortcutZoomSelectedByMinus1() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { + zoomSelected(-1); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutZoomRenderedModelBy10() +{ + emit zoomRenderedModelBy(10); +} + +void SkeletonGraphicsWidget::shortcutZoomSelectedBy1() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { + zoomSelected(1); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutRotateSelectedByMinus1() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { + rotateSelected(-1); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutRotateSelectedBy1() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { + rotateSelected(1); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutMoveSelectedToLeft() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode) { + if (m_checkedOriginItem) { + moveCheckedOrigin(-1, 0); + emit groupOperationAdded(); + } else if (hasSelection()) { + moveSelected(-1, 0); + emit groupOperationAdded(); + } + } +} + +void SkeletonGraphicsWidget::shortcutMoveSelectedToRight() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode) { + if (m_checkedOriginItem) { + moveCheckedOrigin(1, 0); + emit groupOperationAdded(); + } else if (hasSelection()) { + moveSelected(1, 0); + emit groupOperationAdded(); + } + } +} + +void SkeletonGraphicsWidget::shortcutMoveSelectedToUp() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode) { + if (m_checkedOriginItem) { + moveCheckedOrigin(0, -1); + emit groupOperationAdded(); + } else if (hasSelection()) { + moveSelected(0, -1); + emit groupOperationAdded(); + } + } +} + +void SkeletonGraphicsWidget::shortcutMoveSelectedToDown() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode) { + if (m_checkedOriginItem) { + moveCheckedOrigin(0, 1); + emit groupOperationAdded(); + } else if (hasSelection()) { + moveSelected(0, 1); + emit groupOperationAdded(); + } + } +} + +void SkeletonGraphicsWidget::shortcutScaleSelectedByMinus1() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { + scaleSelected(-1); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutScaleSelectedBy1() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { + scaleSelected(1); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutSwitchProfileOnSelected() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { + switchProfileOnRangeSelection(); + } +} + +void SkeletonGraphicsWidget::shortcutShowOrHideSelectedPart() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { + const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); + bool partVisible = part && part->visible; + emit setPartVisibleState(m_lastCheckedPart, !partVisible); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutEnableOrDisableSelectedPart() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { + const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); + bool partDisabled = part && part->disabled; + emit setPartDisableState(m_lastCheckedPart, !partDisabled); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutLockOrUnlockSelectedPart() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { + const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); + bool partLocked = part && part->locked; + emit setPartLockState(m_lastCheckedPart, !partLocked); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutXmirrorOnOrOffSelectedPart() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { + const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); + bool partXmirrored = part && part->xMirrored; + emit setPartXmirrorState(m_lastCheckedPart, !partXmirrored); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutSubdivedOrNotSelectedPart() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { + const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); + bool partSubdived = part && part->subdived; + emit setPartSubdivState(m_lastCheckedPart, !partSubdived); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutRoundEndOrNotSelectedPart() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { + const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); + bool partRounded = part && part->rounded; + emit setPartRoundState(m_lastCheckedPart, !partRounded); + emit groupOperationAdded(); + } +} + +void SkeletonGraphicsWidget::shortcutWrapOrNotSelectedPart() +{ + if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { + const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); + bool partWrapped = part && part->wrapped; + emit setPartWrapState(m_lastCheckedPart, !partWrapped); + emit groupOperationAdded(); + } +} + bool SkeletonGraphicsWidget::keyPress(QKeyEvent *event) { - if (event->key() == Qt::Key_Delete || event->key() ==Qt::Key_Backspace) { - bool processed = false; - if (!m_rangeSelectionSet.empty()) { - deleteSelected(); - processed = true; - } - if (processed) { - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_A) { - if (SkeletonDocumentEditMode::Add == m_document->editMode) { - emit setEditMode(SkeletonDocumentEditMode::Select); - } else { - emit setEditMode(SkeletonDocumentEditMode::Add); - } - return true; - } else if (event->key() == Qt::Key_Z) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { - emit redo(); - return true; - } else { - emit undo(); - return true; - } - } else { - emit setZlockState(!m_document->zlocked); - return true; - } - } else if (event->key() == Qt::Key_Y) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) { - if (!QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { - emit redo(); - return true; - } - } else { - emit setYlockState(!m_document->ylocked); - return true; - } - } else if (event->key() == Qt::Key_X) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) { - cut(); - return true; - } else { - emit setXlockState(!m_document->xlocked); - return true; - } - } else if (event->key() == Qt::Key_C) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) { - copy(); - return true; - } - } else if (event->key() == Qt::Key_V) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) { - emit paste(); - return true; - } - } else if (event->key() == Qt::Key_S) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier)) { - emit save(); - return true; - } else { - emit setEditMode(SkeletonDocumentEditMode::Select); - return true; - } - } else if (event->key() == Qt::Key_D) { - emit setEditMode(SkeletonDocumentEditMode::Drag); - return true; - } else if (event->key() == Qt::Key_Minus) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::AltModifier)) { - emit zoomRenderedModelBy(-10); - return true; - } else if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { - zoomSelected(-1); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_Equal) { - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::AltModifier)) { - emit zoomRenderedModelBy(10); - return true; - } else if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { - zoomSelected(1); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_Comma) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { - rotateSelected(-1); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_Period) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { - rotateSelected(1); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_Left) { - if (SkeletonDocumentEditMode::Select == m_document->editMode) { - if (m_checkedOriginItem) { - moveCheckedOrigin(-1, 0); - emit groupOperationAdded(); - return true; - } else if (hasSelection()) { - moveSelected(-1, 0); - emit groupOperationAdded(); - return true; - } - } - } else if (event->key() == Qt::Key_Right) { - if (SkeletonDocumentEditMode::Select == m_document->editMode) { - if (m_checkedOriginItem) { - moveCheckedOrigin(1, 0); - emit groupOperationAdded(); - return true; - } else if (hasSelection()) { - moveSelected(1, 0); - emit groupOperationAdded(); - return true; - } - } - } else if (event->key() == Qt::Key_Up) { - if (SkeletonDocumentEditMode::Select == m_document->editMode) { - if (m_checkedOriginItem) { - moveCheckedOrigin(0, -1); - emit groupOperationAdded(); - return true; - } else if (hasSelection()) { - moveSelected(0, -1); - emit groupOperationAdded(); - return true; - } - } - } else if (event->key() == Qt::Key_Down) { - if (SkeletonDocumentEditMode::Select == m_document->editMode) { - if (m_checkedOriginItem) { - moveCheckedOrigin(0, 1); - emit groupOperationAdded(); - return true; - } else if (hasSelection()) { - moveSelected(0, 1); - emit groupOperationAdded(); - return true; - } - } - } else if (event->key() == Qt::Key_BracketLeft) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { - scaleSelected(-1); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_BracketRight) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { - scaleSelected(1); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_E) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && hasSelection()) { - switchProfileOnRangeSelection(); - return true; - } - } else if (event->key() == Qt::Key_H) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { - const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); - bool partVisible = part && part->visible; - emit setPartVisibleState(m_lastCheckedPart, !partVisible); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_J) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { - const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); - bool partDisabled = part && part->disabled; - emit setPartDisableState(m_lastCheckedPart, !partDisabled); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_L) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { - const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); - bool partLocked = part && part->locked; - emit setPartLockState(m_lastCheckedPart, !partLocked); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_M) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { - const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); - bool partXmirrored = part && part->xMirrored; - emit setPartXmirrorState(m_lastCheckedPart, !partXmirrored); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_B) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { - const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); - bool partSubdived = part && part->subdived; - emit setPartSubdivState(m_lastCheckedPart, !partSubdived); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_U) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { - const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); - bool partRounded = part && part->rounded; - emit setPartRoundState(m_lastCheckedPart, !partRounded); - emit groupOperationAdded(); - return true; - } - } else if (event->key() == Qt::Key_W) { - if (SkeletonDocumentEditMode::Select == m_document->editMode && !m_lastCheckedPart.isNull()) { - const SkeletonPart *part = m_document->findPart(m_lastCheckedPart); - bool partWrapped = part && part->wrapped; - emit setPartWrapState(m_lastCheckedPart, !partWrapped); - emit groupOperationAdded(); + if (event->key() == Qt::Key_Space) { + if (SkeletonDocumentEditMode::ZoomIn == m_document->editMode || + SkeletonDocumentEditMode::ZoomOut == m_document->editMode || + SkeletonDocumentEditMode::Select == m_document->editMode || + SkeletonDocumentEditMode::Add == m_document->editMode) { + m_inTempDragMode = true; + m_modeBeforeEnterTempDragMode = m_document->editMode; + emit setEditMode(SkeletonDocumentEditMode::Drag); return true; } } + + return false; +} + +bool SkeletonGraphicsWidget::keyRelease(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Space) { + if (m_inTempDragMode) { + m_inTempDragMode = false; + emit setEditMode(m_modeBeforeEnterTempDragMode); + return true; + } + } + return false; } diff --git a/src/skeletongraphicswidget.h b/src/skeletongraphicswidget.h index da8f4ecc..9ac2f396 100644 --- a/src/skeletongraphicswidget.h +++ b/src/skeletongraphicswidget.h @@ -389,6 +389,7 @@ public: bool mousePress(QMouseEvent *event); bool mouseDoubleClick(QMouseEvent *event); bool keyPress(QKeyEvent *event); + bool keyRelease(QKeyEvent *event); bool checkSkeletonItem(QGraphicsItem *item, bool checked); QUuid querySkeletonItemPartId(QGraphicsItem *item); static SkeletonProfile readSkeletonItemProfile(QGraphicsItem *item); @@ -403,12 +404,13 @@ public: bool hasTwoDisconnectedNodesSelection(); void setModelWidget(ModelWidget *modelWidget); protected: - void mouseMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event); - void keyPressEvent(QKeyEvent *event); + void mouseMoveEvent(QMouseEvent *event) override; + void wheelEvent(QWheelEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseDoubleClickEvent(QMouseEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void keyReleaseEvent(QKeyEvent *event) override; public slots: void nodeAdded(QUuid nodeId); void edgeAdded(QUuid edgeId); @@ -462,6 +464,39 @@ public slots: void setSelectedNodesBoneMark(SkeletonBoneMark boneMark); void timeToRemoveDeferredNodesAndEdges(); void switchSelectedXZ(); + void shortcutDelete(); + void shortcutAddMode(); + void shortcutUndo(); + void shortcutRedo(); + void shortcutXlock(); + void shortcutYlock(); + void shortcutZlock(); + void shortcutCut(); + void shortcutCopy(); + void shortcutPaste(); + void shortcutSave(); + void shortcutSelectMode(); + void shortcutDragMode(); + void shortcutZoomRenderedModelByMinus10(); + void shortcutZoomSelectedByMinus1(); + void shortcutZoomRenderedModelBy10(); + void shortcutZoomSelectedBy1(); + void shortcutRotateSelectedByMinus1(); + void shortcutRotateSelectedBy1(); + void shortcutMoveSelectedToLeft(); + void shortcutMoveSelectedToRight(); + void shortcutMoveSelectedToUp(); + void shortcutMoveSelectedToDown(); + void shortcutScaleSelectedByMinus1(); + void shortcutScaleSelectedBy1(); + void shortcutSwitchProfileOnSelected(); + void shortcutShowOrHideSelectedPart(); + void shortcutEnableOrDisableSelectedPart(); + void shortcutLockOrUnlockSelectedPart(); + void shortcutXmirrorOnOrOffSelectedPart(); + void shortcutSubdivedOrNotSelectedPart(); + void shortcutRoundEndOrNotSelectedPart(); + void shortcutWrapOrNotSelectedPart(); private slots: void turnaroundImageReady(); private: @@ -515,6 +550,8 @@ private: //need initalize QTimer *m_deferredRemoveTimer; bool m_eventForwardingToModelWidget; ModelWidget *m_modelWidget; + bool m_inTempDragMode; + SkeletonDocumentEditMode m_modeBeforeEnterTempDragMode; private: QVector3D m_ikMoveTarget; QUuid m_ikMoveEndEffectorId;