diff --git a/dust3d.pro b/dust3d.pro index ba3598e4..d8baaa02 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -323,9 +323,6 @@ HEADERS += src/tabwidget.h SOURCES += src/flowlayout.cpp HEADERS += src/flowlayout.h -SOURCES += src/shortcuts.cpp -HEADERS += src/shortcuts.h - SOURCES += src/trianglesourcenoderesolve.cpp HEADERS += src/trianglesourcenoderesolve.h diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index c4af7f8c..12e2e777 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -41,7 +41,6 @@ #include "imageforever.h" #include "spinnableawesomebutton.h" #include "fbxfile.h" -#include "shortcuts.h" #include "floatnumberwidget.h" #include "scriptwidget.h" #include "variablesxml.h" @@ -1142,8 +1141,7 @@ DocumentWindow::DocumentWindow() connect(m_document, &Document::skeletonChanged, this, &DocumentWindow::generateSilhouetteImage); connect(m_shapeGraphicsWidget, &SkeletonGraphicsWidget::loadedTurnaroundImageChanged, this, &DocumentWindow::generateSilhouetteImage); - initShortCuts(this, m_shapeGraphicsWidget); - //initShortCuts(this, m_boneGraphicsWidget); + initializeShortcuts(); connect(this, &DocumentWindow::initialized, m_document, &Document::uiReady); connect(this, &DocumentWindow::initialized, this, &DocumentWindow::autoRecover); @@ -2459,7 +2457,72 @@ void DocumentWindow::silhouetteImageReady() generateSilhouetteImage(); } +QShortcut *DocumentWindow::createShortcut(QKeySequence key) +{ + auto shortcutIt = m_shortcutMap.find(key); + if (shortcutIt != m_shortcutMap.end()) + return shortcutIt->second; + QShortcut *shortcut = new QShortcut(this); + shortcut->setKey(key); + m_shortcutMap.insert({key, shortcut}); + return shortcut; +} + +#define defineShortcut(keyVal, widget, funcName) \ + QObject::connect(createShortcut(keyVal), &QShortcut::activated, widget, funcName) + +void DocumentWindow::initializeToolShortcuts(SkeletonGraphicsWidget *graphicsWidget) +{ + defineShortcut(Qt::Key_A, graphicsWidget, &SkeletonGraphicsWidget::shortcutAddMode); + defineShortcut(Qt::CTRL + Qt::Key_A, graphicsWidget, &SkeletonGraphicsWidget::shortcutSelectAll); + defineShortcut(Qt::CTRL + Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutUndo); + defineShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutRedo); + defineShortcut(Qt::CTRL + Qt::Key_Y, graphicsWidget, &SkeletonGraphicsWidget::shortcutRedo); + defineShortcut(Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutZlock); + defineShortcut(Qt::Key_Y, graphicsWidget, &SkeletonGraphicsWidget::shortcutYlock); + defineShortcut(Qt::Key_X, graphicsWidget, &SkeletonGraphicsWidget::shortcutXlock); + defineShortcut(Qt::Key_S, graphicsWidget, &SkeletonGraphicsWidget::shortcutSelectMode); + defineShortcut(Qt::Key_D, graphicsWidget, &SkeletonGraphicsWidget::shortcutPaintMode); + defineShortcut(Qt::Key_R, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleRotation); + defineShortcut(Qt::Key_O, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleFlatShading); + defineShortcut(Qt::Key_W, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleWireframe); + defineShortcut(Qt::Key_Escape, graphicsWidget, &SkeletonGraphicsWidget::shortcutEscape); +} + +void DocumentWindow::initializeCanvasShortcuts(SkeletonGraphicsWidget *graphicsWidget) +{ + defineShortcut(Qt::Key_Delete, graphicsWidget, &SkeletonGraphicsWidget::shortcutDelete); + defineShortcut(Qt::Key_Backspace, graphicsWidget, &SkeletonGraphicsWidget::shortcutDelete); + defineShortcut(Qt::CTRL + Qt::Key_X, graphicsWidget, &SkeletonGraphicsWidget::shortcutCut); + defineShortcut(Qt::CTRL + Qt::Key_C, graphicsWidget, &SkeletonGraphicsWidget::shortcutCopy); + defineShortcut(Qt::CTRL + Qt::Key_V, graphicsWidget, &SkeletonGraphicsWidget::shortcutPaste); + defineShortcut(Qt::ALT + Qt::Key_Minus, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomRenderedModelByMinus10); + defineShortcut(Qt::Key_Minus, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomSelectedByMinus1); + defineShortcut(Qt::ALT + Qt::Key_Equal, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomRenderedModelBy10); + defineShortcut(Qt::Key_Equal, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomSelectedBy1); + defineShortcut(Qt::Key_Comma, graphicsWidget, &SkeletonGraphicsWidget::shortcutRotateSelectedByMinus1); + defineShortcut(Qt::Key_Period, graphicsWidget, &SkeletonGraphicsWidget::shortcutRotateSelectedBy1); + defineShortcut(Qt::Key_Left, graphicsWidget, &SkeletonGraphicsWidget::shortcutMoveSelectedToLeft); + defineShortcut(Qt::Key_Right, graphicsWidget, &SkeletonGraphicsWidget::shortcutMoveSelectedToRight); + defineShortcut(Qt::Key_Up, graphicsWidget, &SkeletonGraphicsWidget::shortcutMoveSelectedToUp); + defineShortcut(Qt::Key_Down, graphicsWidget, &SkeletonGraphicsWidget::shortcutMoveSelectedToDown); + defineShortcut(Qt::Key_BracketLeft, graphicsWidget, &SkeletonGraphicsWidget::shortcutScaleSelectedByMinus1); + defineShortcut(Qt::Key_BracketRight, graphicsWidget, &SkeletonGraphicsWidget::shortcutScaleSelectedBy1); + defineShortcut(Qt::Key_E, graphicsWidget, &SkeletonGraphicsWidget::shortcutSwitchProfileOnSelected); + defineShortcut(Qt::Key_H, graphicsWidget, &SkeletonGraphicsWidget::shortcutShowOrHideSelectedPart); + defineShortcut(Qt::Key_J, graphicsWidget, &SkeletonGraphicsWidget::shortcutEnableOrDisableSelectedPart); + defineShortcut(Qt::Key_L, graphicsWidget, &SkeletonGraphicsWidget::shortcutLockOrUnlockSelectedPart); + defineShortcut(Qt::Key_F, graphicsWidget, &SkeletonGraphicsWidget::shortcutCheckPartComponent); +} + void DocumentWindow::initializeShortcuts() { + initializeToolShortcuts(m_shapeGraphicsWidget); + initializeCanvasShortcuts(m_shapeGraphicsWidget); + initializeCanvasShortcuts(m_boneGraphicsWidget); + defineShortcut(Qt::Key_M, m_shapeGraphicsWidget, &SkeletonGraphicsWidget::shortcutXmirrorOnOrOffSelectedPart); + defineShortcut(Qt::Key_B, m_shapeGraphicsWidget, &SkeletonGraphicsWidget::shortcutSubdivedOrNotSelectedPart); + defineShortcut(Qt::Key_U, m_shapeGraphicsWidget, &SkeletonGraphicsWidget::shortcutRoundEndOrNotSelectedPart); + defineShortcut(Qt::Key_C, m_shapeGraphicsWidget, &SkeletonGraphicsWidget::shortcutChamferedOrNotSelectedPart); } \ No newline at end of file diff --git a/src/documentwindow.h b/src/documentwindow.h index d53577ca..d85f4f3b 100644 --- a/src/documentwindow.h +++ b/src/documentwindow.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "modelwidget.h" #include "rigwidget.h" #include "bonemark.h" @@ -124,6 +125,9 @@ private: void updateTitle(); void createPartSnapshotForFillMesh(const QUuid &fillMeshFileId, Snapshot *snapshot); void initializeShortcuts(); + void initializeToolShortcuts(SkeletonGraphicsWidget *graphicsWidget); + void initializeCanvasShortcuts(SkeletonGraphicsWidget *graphicsWidget); + QShortcut *createShortcut(QKeySequence key); private: Document *m_document = nullptr; BoneDocument *m_boneDocument = nullptr; @@ -218,6 +222,8 @@ private: GraphicsViewEditTarget m_graphicsViewEditTarget = GraphicsViewEditTarget::Shape; bool m_isSilhouetteImageObsolete = false; SilhouetteImageGenerator *m_silhouetteImageGenerator = nullptr; + + std::map m_shortcutMap; public: static int m_autoRecovered; }; diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp deleted file mode 100644 index 679d9e27..00000000 --- a/src/shortcuts.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include -#include "shortcuts.h" - -static std::map g_shortcutMap; - -#define defineKey(keyVal, funcName) do { \ - auto key = new QShortcut(widget); \ - key->setKey(keyVal); \ - QObject::connect(key, &QShortcut::activated, \ - graphicsWidget, funcName); \ -} while (false) - -void initShortCuts(QWidget *widget, SkeletonGraphicsWidget *graphicsWidget) -{ - defineKey(Qt::Key_Escape, &SkeletonGraphicsWidget::shortcutEscape); - defineKey(Qt::Key_Delete, &SkeletonGraphicsWidget::shortcutDelete); - defineKey(Qt::Key_Backspace, &SkeletonGraphicsWidget::shortcutDelete); - defineKey(Qt::Key_A, &SkeletonGraphicsWidget::shortcutAddMode); - //defineKey(Qt::Key_G, &SkeletonGraphicsWidget::shortcutMarkMode); - defineKey(Qt::CTRL + Qt::Key_A, &SkeletonGraphicsWidget::shortcutSelectAll); - 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::Key_S, &SkeletonGraphicsWidget::shortcutSelectMode); - defineKey(Qt::Key_D, &SkeletonGraphicsWidget::shortcutPaintMode); - 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::shortcutToggleWireframe); - defineKey(Qt::Key_F, &SkeletonGraphicsWidget::shortcutCheckPartComponent); - defineKey(Qt::Key_C, &SkeletonGraphicsWidget::shortcutChamferedOrNotSelectedPart); - defineKey(Qt::Key_O, &SkeletonGraphicsWidget::shortcutToggleFlatShading); - defineKey(Qt::Key_R, &SkeletonGraphicsWidget::shortcutToggleRotation); -} diff --git a/src/shortcuts.h b/src/shortcuts.h deleted file mode 100644 index 426ae9c5..00000000 --- a/src/shortcuts.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef DUST3D_SHORTCUTS_H -#define DUST3D_SHORTCUTS_H -#include -#include "skeletongraphicswidget.h" - -void initShortCuts(QWidget *widget, SkeletonGraphicsWidget *graphicsWidget); - -#endif