From 1b73d45a893b45b46ba4d8ceec9380ef54f7c4c0 Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Tue, 14 Oct 2014 01:48:00 -0400 Subject: [PATCH] New feature: menu option toggle sticky vertices --- MainWindow.cpp | 15 +++++++++++++++ MainWindow.h | 1 + MapperGLCanvas.cpp | 11 +++++++++-- MapperGLCanvas.h | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 8ae59ec..2ebf162 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -1143,6 +1143,19 @@ void MainWindow::createActions() connect(displayCanvasControls, SIGNAL(toggled(bool)), sourceCanvas, SLOT(enableDisplayControls(bool))); connect(displayCanvasControls, SIGNAL(toggled(bool)), destinationCanvas, SLOT(enableDisplayControls(bool))); connect(displayCanvasControls, SIGNAL(toggled(bool)), outputWindow->getCanvas(), SLOT(enableDisplayControls(bool))); + + // Toggle sticky vertices + stickyVertices = new QAction(tr("&Sticky vertices"), this); + // stickyVertices->setShortcut(tr("Ctrl+E")); + stickyVertices->setIcon(QIcon(":/control-points")); + stickyVertices->setStatusTip(tr("Enable sticky vertices")); + stickyVertices->setIconVisibleInMenu(false); + stickyVertices->setCheckable(true); + stickyVertices->setChecked(true); + // Manage sticky vertices + connect(stickyVertices, SIGNAL(toggled(bool)), sourceCanvas, SLOT(enableStickyVertices(bool))); + connect(stickyVertices, SIGNAL(toggled(bool)), destinationCanvas, SLOT(enableStickyVertices(bool))); + connect(stickyVertices, SIGNAL(toggled(bool)), outputWindow->getCanvas(), SLOT(enableStickyVertices(bool))); } void MainWindow::createMenus() @@ -1181,6 +1194,7 @@ void MainWindow::createMenus() viewMenu->addAction(displayOutputWindow); viewMenu->addAction(outputWindowFullScreen); viewMenu->addAction(displayCanvasControls); + viewMenu->addAction(stickyVertices); // Run. runMenu = menuBar->addMenu(tr("&Run")); @@ -1242,6 +1256,7 @@ void MainWindow::createToolBars() mainToolBar->addAction(displayOutputWindow); mainToolBar->addAction(outputWindowFullScreen); mainToolBar->addAction(displayCanvasControls); + mainToolBar->addAction(stickyVertices); runToolBar = addToolBar(tr("&Run")); runToolBar->setIconSize(QSize(MM::TOP_TOOLBAR_ICON_SIZE, MM::TOP_TOOLBAR_ICON_SIZE)); diff --git a/MainWindow.h b/MainWindow.h index 49f5376..5c0e3e8 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -249,6 +249,7 @@ private: QAction *displayOutputWindow; QAction *outputWindowFullScreen; QAction *displayCanvasControls; + QAction *stickyVertices; // Widgets and layout. diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index bdf1ad5..536f653 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -29,7 +29,8 @@ MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QG _activeVertex(NO_VERTEX), _shapeGrabbed(false), // comment out? _shapeFirstGrab(false), // comment out? - _displayControls(true) + _displayControls(true), + _stickyVertices(true) { } @@ -156,7 +157,8 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) p.setY(event->y()); // Stick to vertices. - glueVertex(shape, &p); + if (stickyVertices()) + glueVertex(shape, &p); shape->setVertex(_activeVertex, p); update(); @@ -254,6 +256,11 @@ void MapperGLCanvas::enableDisplayControls(bool display) updateCanvas(); } +void MapperGLCanvas::enableStickyVertices(bool value) +{ + _stickyVertices = value; +} + /* Stick vertex p of Shape orig to another Shape's vertex, if the 2 vertices are * close enough. The distance per coordinate is currently set in dist_stick * variable. Perhaps the sticky-sensitivity should be configurable through GUI */ diff --git a/MapperGLCanvas.h b/MapperGLCanvas.h index ddd3538..1e86b72 100644 --- a/MapperGLCanvas.h +++ b/MapperGLCanvas.h @@ -52,6 +52,7 @@ public: MainWindow* getMainWindow() const { return _mainWindow; } bool displayControls() const { return _displayControls; } + bool stickyVertices() const { return _stickyVertices; } protected: void initializeGL(); @@ -76,6 +77,7 @@ private: bool _shapeGrabbed; bool _shapeFirstGrab; bool _displayControls; + bool _stickyVertices; signals: void shapeChanged(Shape*); @@ -84,6 +86,7 @@ signals: public slots: void updateCanvas(); void enableDisplayControls(bool display); + void enableStickyVertices(bool display); void deselectAll(); public: