Fri, 04 Jul 2014 22:40:35 +0300
- more work on edit modes
--- a/src/editmodes/abstracteditmode.cc Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/abstracteditmode.cc Fri Jul 04 22:40:35 2014 +0300 @@ -62,8 +62,11 @@ m_drawedVerts << pos; } -virtual void AbstractDrawMode::mouseReleased (MouseEventData const& data) +bool AbstractDrawMode::mouseReleased (MouseEventData const& data) { + if (Super::mouseReleased (data)) + return true; + if (data.releasedButtons & Qt::MidButton) { // Find the closest vertex to our cursor
--- a/src/editmodes/abstracteditmode.h Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/abstracteditmode.h Fri Jul 04 22:40:35 2014 +0300 @@ -33,8 +33,8 @@ virtual void render (QPainter& painter) const {}; GLRenderer* renderer() const; virtual EditModeType type() const = 0; - virtual void mousePressed (MouseEventData const& data) {} - virtual void mouseReleased (MouseEventData const& data) {} + virtual bool mousePressed (MouseEventData const& data) { return false; } + virtual bool mouseReleased (MouseEventData const& data) { return false; } static AbstractEditMode* createByType (GLRenderer* renderer, EditModeType type); }; @@ -47,6 +47,8 @@ QList<Vertex> m_drawedVerts; Vertex m_rectverts[4]; + DEFINE_CLASS (AbstractDrawMode, AbstractEditMode) + public: AbstractDrawMode (GLRenderer* renderer); @@ -55,7 +57,7 @@ return false; } - virtual void mouseReleased (MouseEventData const& data) override; + bool mouseReleased (const AbstractEditMode::MouseEventData& data) override; void addDrawnVertex (const Vertex& pos); virtual bool preAddVertex (Vertex const&) @@ -69,6 +71,8 @@ // class AbstractSelectMode : public AbstractEditMode { + DEFINE_CLASS (AbstractSelectMode, AbstractEditMode) + public: AbstractSelectMode (GLRenderer* renderer);
--- a/src/editmodes/circlemode.cc Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/circlemode.cc Fri Jul 04 22:40:35 2014 +0300 @@ -43,6 +43,8 @@ void CircleMode::render (QPainter& painter) const { + QFontMetrics const metrics (QFont()); + // If we have not specified the center point of the circle yet, preview it on the screen. if (m_drawedVerts.isEmpty()) { @@ -121,7 +123,7 @@ // Draw the current radius in the middle of the circle. QPoint origin = renderer()->coordconv3_2 (m_drawedVerts[0]); QString label = QString::number (dist0); - painter.setPen (textpen); + painter.setPen (renderer()->getTextPen()); painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label); if (m_drawedVerts.size() >= 2) @@ -130,4 +132,18 @@ origin.y() + metrics.height(), QString::number (dist1)); } } -} \ No newline at end of file +} + +bool CircleMode::mouseReleased (MouseEventData const& data) +{ + if (Super::mouseReleased (data)) + return true; + + if (m_drawedVerts.size() < 3) + { + addDrawnVertex (m_position3D); + return; + } + + Super::mouseReleased (data); +}
--- a/src/editmodes/circlemode.h Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/circlemode.h Fri Jul 04 22:40:35 2014 +0300 @@ -10,6 +10,7 @@ virtual void render (QPainter& painter) const override; virtual EditModeType type() const override; - double getCircleDrawDist (int pos) const; - Matrix getCircleDrawMatrix (double scale); + double getCircleDrawDist (int pos) const; + Matrix getCircleDrawMatrix (double scale); + bool mouseReleased (const AbstractEditMode::MouseEventData& data) override; };
--- a/src/editmodes/drawmode.cc Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/drawmode.cc Fri Jul 04 22:40:35 2014 +0300 @@ -121,14 +121,17 @@ return false; } -void DrawMode::mouseReleased (MouseEventData const& data) +bool DrawMode::mouseReleased (MouseEventData const& data) { + if (Super::mouseReleased (data)) + return true; + if (_rectdraw) { if (m_drawedVerts.size() == 2) { endDraw (true); - return; + return true; } } else @@ -148,4 +151,5 @@ } addDrawnVertex (renderer()->position3D()); + return true; }
--- a/src/editmodes/drawmode.h Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/drawmode.h Fri Jul 04 22:40:35 2014 +0300 @@ -11,5 +11,5 @@ virtual void render (QPainter& painter) const override; virtual EditModeType type() const override; virtual bool preAddVertex (Vertex const& pos) override; - virtual void mouseReleased (MouseEventData const& data) override; + virtual bool mouseReleased (MouseEventData const& data) override; };
--- a/src/editmodes/magicwandmode.cc Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/magicwandmode.cc Fri Jul 04 22:40:35 2014 +0300 @@ -197,8 +197,11 @@ g_win->buildObjList(); } -void MagicWandMode::mouseReleased (MouseEventData const& data) +bool MagicWandMode::mouseReleased (MouseEventData const& data) { + if (Super::mouseReleased (data)) + return true; + MagicType wandtype = MagicWandMode::Set; if (data.keymods & Qt::ShiftModifier) @@ -207,4 +210,5 @@ wandtype = MagicWandMode::Subtractive; doMagic (renderer()->pickOneObject (data.ev->x(), data.ev->y()), wandtype); + return true; }
--- a/src/editmodes/magicwandmode.h Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/magicwandmode.h Fri Jul 04 22:40:35 2014 +0300 @@ -42,7 +42,7 @@ MagicWandMode (GLRenderer* renderer); void doMagic (LDObjectPtr obj, MagicType type); virtual EditModeType type() const override; - virtual void mouseReleased (MouseEventData const& data) override; + virtual bool mouseReleased (MouseEventData const& data) override; private: void fillBoundaries (LDObjectPtr obj, QVector<BoundaryType>& boundaries, QVector<LDObjectPtr>& candidates);
--- a/src/editmodes/selectmode.cc Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/selectmode.cc Fri Jul 04 22:40:35 2014 +0300 @@ -10,8 +10,11 @@ return EditModeType::Select; } -void SelectMode::mouseReleased (MouseEventData const& data) +bool SelectMode::mouseReleased (MouseEventData const& data) { + if (Super::mouseReleased (data)) + return true; + if (not data.mouseMoved) _rangepick = false; @@ -20,10 +23,15 @@ if (not data.mouseMoved || _rangepick) renderer()->pick (data.ev->x(), data.ev->y()); + + _rangepick = false; } -void SelectMode::mousePressed (MouseEventData const& data) +bool SelectMode::mousePressed (MouseEventData const& data) { + if (Super::mousePressed (data)) + return true; + if (data.ev->modifiers() & Qt::ControlModifier) { _rangepick = true; @@ -31,5 +39,8 @@ _rangeStart.setY (data.ev->y()); _addpick = (data.keymods & Qt::AltModifier); data.ev->accept(); + return true; } + + return false; } \ No newline at end of file
--- a/src/editmodes/selectmode.h Fri Jul 04 22:19:01 2014 +0300 +++ b/src/editmodes/selectmode.h Fri Jul 04 22:40:35 2014 +0300 @@ -11,6 +11,6 @@ public: SelectMode (GLRenderer* renderer); - virtual void mouseReleased (MouseEventData const& data) override; + virtual bool mouseReleased (MouseEventData const& data) override; virtual EditModeType type() const override; }; \ No newline at end of file
--- a/src/glRenderer.cc Fri Jul 04 22:19:01 2014 +0300 +++ b/src/glRenderer.cc Fri Jul 04 22:40:35 2014 +0300 @@ -774,31 +774,10 @@ data.mouseMoved = m_totalmove >= 10; data.keymods = m_keymods; data.releasedButtons = releasedbuttons; - m_editmode->mouseReleased (data); + + if (m_editmode->mouseReleased (data)) + goto end; } - - switch (editMode()) - { - case EDrawMode: - { - - break; - } - - case ECircleMode: - { - if (m_drawedVerts.size() == 3) - { - endDraw (true); - return; - } - - addDrawnVertex (m_position3D); - break; - } - } - - m_rangepick = false; } if (wasMid && editMode() != ESelectMode && m_drawedVerts.size() < 4 && m_totalmove < 10)