Add document node picking edit mode

master
Jeremy HU 2022-11-16 20:25:31 +11:00
parent 0f77ed243d
commit d736d86969
4 changed files with 11 additions and 54 deletions

View File

@ -31,10 +31,7 @@ public:
enum class EditMode { enum class EditMode {
Add = 0, Add = 0,
Select, Select,
Paint, Pick
Drag,
ZoomIn,
ZoomOut
}; };
enum class SnapshotFor { enum class SnapshotFor {

View File

@ -1300,7 +1300,6 @@ void DocumentWindow::initializeToolShortcuts(SkeletonGraphicsWidget* graphicsWid
defineShortcut(Qt::Key_Y, graphicsWidget, &SkeletonGraphicsWidget::shortcutYlock); defineShortcut(Qt::Key_Y, graphicsWidget, &SkeletonGraphicsWidget::shortcutYlock);
defineShortcut(Qt::Key_X, graphicsWidget, &SkeletonGraphicsWidget::shortcutXlock); defineShortcut(Qt::Key_X, graphicsWidget, &SkeletonGraphicsWidget::shortcutXlock);
defineShortcut(Qt::Key_S, graphicsWidget, &SkeletonGraphicsWidget::shortcutSelectMode); defineShortcut(Qt::Key_S, graphicsWidget, &SkeletonGraphicsWidget::shortcutSelectMode);
defineShortcut(Qt::Key_D, graphicsWidget, &SkeletonGraphicsWidget::shortcutPaintMode);
defineShortcut(Qt::Key_R, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleRotation); defineShortcut(Qt::Key_R, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleRotation);
defineShortcut(Qt::Key_O, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleFlatShading); defineShortcut(Qt::Key_O, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleFlatShading);
defineShortcut(Qt::Key_W, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleWireframe); defineShortcut(Qt::Key_W, graphicsWidget, &SkeletonGraphicsWidget::shortcutToggleWireframe);

View File

@ -105,7 +105,7 @@ void SkeletonGraphicsWidget::shortcutEscape()
if (!isVisible()) if (!isVisible())
return; return;
if (Document::EditMode::Add == m_document->editMode || Document::EditMode::Paint == m_document->editMode) { if (Document::EditMode::Select != m_document->editMode) {
emit setEditMode(Document::EditMode::Select); emit setEditMode(Document::EditMode::Select);
return; return;
} }
@ -700,6 +700,14 @@ void SkeletonGraphicsWidget::updateCursor()
} }
// Set cursor here if needed // Set cursor here if needed
switch (m_document->editMode) {
case Document::EditMode::Pick:
setCursor(Qt::CrossCursor);
break;
default:
unsetCursor();
break;
}
emit cursorChanged(); emit cursorChanged();
} }
@ -1384,29 +1392,7 @@ QPointF SkeletonGraphicsWidget::mouseEventScenePos(QMouseEvent* event)
bool SkeletonGraphicsWidget::mousePress(QMouseEvent* event) bool SkeletonGraphicsWidget::mousePress(QMouseEvent* event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
if (Document::EditMode::ZoomIn == m_document->editMode) { if (Document::EditMode::Add == m_document->editMode) {
ViewportAnchor lastAnchor = transformationAnchor();
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
scale(1.25, 1.25);
setTransformationAnchor(lastAnchor);
return true;
} else if (Document::EditMode::ZoomOut == m_document->editMode) {
ViewportAnchor lastAnchor = transformationAnchor();
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
scale(0.8, 0.8);
setTransformationAnchor(lastAnchor);
//if ((!verticalScrollBar() || !verticalScrollBar()->isVisible()) &&
// (!horizontalScrollBar() || !horizontalScrollBar()->isVisible())) {
// setTransform(QTransform());
//}
return true;
} else if (Document::EditMode::Drag == m_document->editMode) {
if (!m_dragStarted) {
m_lastGlobalPos = event->globalPos();
m_dragStarted = true;
updateCursor();
}
} else if (Document::EditMode::Add == m_document->editMode) {
if (m_cursorNodeItem->isVisible()) { if (m_cursorNodeItem->isVisible()) {
if (m_addFromNodeItem) { if (m_addFromNodeItem) {
if (m_hoveredNodeItem && m_addFromNodeItem && m_hoveredNodeItem != m_addFromNodeItem && m_hoveredNodeItem->profile() == m_addFromNodeItem->profile() && !m_document->findEdgeByNodes(m_addFromNodeItem->id(), m_hoveredNodeItem->id()) && m_document->isNodeEditable(m_hoveredNodeItem->id())) { if (m_hoveredNodeItem && m_addFromNodeItem && m_hoveredNodeItem != m_addFromNodeItem && m_hoveredNodeItem->profile() == m_addFromNodeItem->profile() && !m_document->findEdgeByNodes(m_addFromNodeItem->id(), m_hoveredNodeItem->id()) && m_document->isNodeEditable(m_hoveredNodeItem->id())) {
@ -1748,11 +1734,6 @@ void SkeletonGraphicsWidget::shortcutSelectMode()
emit setEditMode(Document::EditMode::Select); emit setEditMode(Document::EditMode::Select);
} }
void SkeletonGraphicsWidget::shortcutPaintMode()
{
emit setEditMode(Document::EditMode::Paint);
}
void SkeletonGraphicsWidget::shortcutZoomRenderedModelByMinus10() void SkeletonGraphicsWidget::shortcutZoomRenderedModelByMinus10()
{ {
if (!isVisible()) if (!isVisible())
@ -2022,28 +2003,11 @@ void SkeletonGraphicsWidget::shortcutRoundEndOrNotSelectedPart()
bool SkeletonGraphicsWidget::keyPress(QKeyEvent* event) bool SkeletonGraphicsWidget::keyPress(QKeyEvent* event)
{ {
if (event->key() == Qt::Key_Space) {
if (Document::EditMode::ZoomIn == m_document->editMode || Document::EditMode::ZoomOut == m_document->editMode || Document::EditMode::Select == m_document->editMode || Document::EditMode::Add == m_document->editMode) {
m_inTempDragMode = true;
m_modeBeforeEnterTempDragMode = m_document->editMode;
emit setEditMode(Document::EditMode::Drag);
return true;
}
}
return false; return false;
} }
bool SkeletonGraphicsWidget::keyRelease(QKeyEvent* event) 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; return false;
} }

View File

@ -185,7 +185,6 @@ public slots:
void shortcutCopy(); void shortcutCopy();
void shortcutPaste(); void shortcutPaste();
void shortcutSelectMode(); void shortcutSelectMode();
void shortcutPaintMode();
void shortcutZoomRenderedModelByMinus10(); void shortcutZoomRenderedModelByMinus10();
void shortcutZoomSelectedByMinus1(); void shortcutZoomSelectedByMinus1();
void shortcutZoomRenderedModelBy10(); void shortcutZoomRenderedModelBy10();
@ -270,8 +269,6 @@ private:
QTimer* m_deferredRemoveTimer = nullptr; QTimer* m_deferredRemoveTimer = nullptr;
bool m_eventForwardingToModelWidget = false; bool m_eventForwardingToModelWidget = false;
ModelWidget* m_modelWidget = nullptr; ModelWidget* m_modelWidget = nullptr;
bool m_inTempDragMode = false;
Document::EditMode m_modeBeforeEnterTempDragMode = Document::EditMode::Select;
float m_turnaroundOpacity = 0.25f; float m_turnaroundOpacity = 0.25f;
bool m_rotated = false; bool m_rotated = false;
QImage* m_backgroundImage = nullptr; QImage* m_backgroundImage = nullptr;