]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Added miscellaneous features.
[architektonas] / src / drawingview.cpp
index 30b159172248d04c0e87e75d6396f1f629bca807..f50fca562d11ce438a51c61d70ef16e689ba92e1 100644 (file)
@@ -45,7 +45,7 @@
 DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        // The value in the settings file will override this.
        useAntialiasing(true), /*numSelected(0),*/ numHovered(0), shiftDown(false),
-       ctrlDown(false),
+       ctrlDown(false), altDown(false),
        gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE),
        scale(1.0), offsetX(-10), offsetY(-10), document(true),
        gridPixels(0), collided(false), hoveringIntersection(false),
@@ -747,6 +747,8 @@ void DrawingView::ToolHandler(int mode, Point p)
                RotateHandler(mode, p);
        else if (Global::tool == TTMirror)
                MirrorHandler(mode, p);
+       else if (Global::tool == TTDimension)
+               DimensionHandler(mode, p);
 }
 
 
@@ -885,6 +887,28 @@ void DrawingView::ToolDraw(Painter * painter)
                                informativeText += " (Copy)";
                }
        }
+       if (Global::tool == TTDimension)
+       {
+               if (Global::toolState == TSNone)
+               {
+                       painter->DrawHandle(toolPoint[0]);
+               }
+               else if ((Global::toolState == TSPoint2) && shiftDown)
+               {
+                       painter->DrawHandle(toolPoint[1]);
+               }
+               else
+               {
+                       painter->DrawLine(toolPoint[0], toolPoint[1]);
+                       painter->DrawHandle(toolPoint[1]);
+
+                       Vector v(toolPoint[0], toolPoint[1]);
+                       double absAngle = v.Angle() * RADIANS_TO_DEGREES;
+                       double absLength = v.Magnitude();
+                       QString text = tr("Length: %1 in.\n") + QChar(0x2221) + tr(": %2");
+                       informativeText = text.arg(absLength).arg(absAngle);
+               }
+       }
 }
 
 
@@ -921,7 +945,7 @@ void DrawingView::LineHandler(int mode, Point p)
                }
                else
                {
-                       Line * l = new Line(toolPoint[0], toolPoint[1]);
+                       Line * l = new Line(toolPoint[0], toolPoint[1], Global::penWidth, Global::penColor, Global::penStyle);
                        l->layer = Global::activeLayer;
                        document.objects.push_back(l);
                        toolPoint[0] = toolPoint[1];
@@ -964,7 +988,7 @@ void DrawingView::CircleHandler(int mode, Point p)
                else
                {
                        double length = Vector::Magnitude(toolPoint[0], toolPoint[1]);
-                       Circle * c = new Circle(toolPoint[0], length);
+                       Circle * c = new Circle(toolPoint[0], length, Global::penWidth, Global::penColor, Global::penStyle);
                        c->layer = Global::activeLayer;
                        document.objects.push_back(c);
                        toolPoint[0] = toolPoint[1];
@@ -1041,7 +1065,7 @@ void DrawingView::ArcHandler(int mode, Point p)
                        if (span < 0)
                                span += TAU;
 
-                       Arc * arc = new Arc(toolPoint[0], toolPoint[1].x, toolPoint[2].x, span);
+                       Arc * arc = new Arc(toolPoint[0], toolPoint[1].x, toolPoint[2].x, span, Global::penWidth, Global::penColor, Global::penStyle);
                        arc->layer = Global::activeLayer;
                        document.objects.push_back(arc);
                        Global::toolState = TSNone;
@@ -1257,6 +1281,48 @@ void DrawingView::MirrorHandler(int mode, Point p)
 }
 
 
+void DrawingView::DimensionHandler(int mode, Point p)
+{
+       switch (mode)
+       {
+       case ToolMouseDown:
+               if (Global::toolState == TSNone)
+                       toolPoint[0] = p;
+               else
+                       toolPoint[1] = p;
+
+               break;
+       case ToolMouseMove:
+               if (Global::toolState == TSNone)
+                       toolPoint[0] = p;
+               else
+                       toolPoint[1] = p;
+
+               break;
+       case ToolMouseUp:
+               if (Global::toolState == TSNone)
+               {
+                       Global::toolState = TSPoint2;
+                       // Prevent spurious line from drawing...
+                       toolPoint[1] = toolPoint[0];
+               }
+               else if ((Global::toolState == TSPoint2) && shiftDown)
+               {
+                       // Key override is telling us to make a new line, not continue the
+                       // previous one.
+                       toolPoint[0] = toolPoint[1];
+               }
+               else
+               {
+                       Dimension * d = new Dimension(toolPoint[0], toolPoint[1], DTLinear);
+                       d->layer = Global::activeLayer;
+                       document.objects.push_back(d);
+                       Global::toolState = TSNone;
+               }
+       }
+}
+
+
 void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -1339,9 +1405,10 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        // Only needs to be done here, as mouse down is always preceded by movement
        Global::snapPointIsValid = false;
        hoveringIntersection = false;
+       oldScrollPoint = Vector(event->x(), event->y());
 
        // Scrolling...
-       if (event->buttons() & Qt::MiddleButton)
+       if ((event->buttons() & Qt::MiddleButton) || scrollDrag)
        {
                point = Vector(event->x(), event->y());
                // Since we're using Qt coords for scrolling, we have to adjust them
@@ -1536,11 +1603,14 @@ void DrawingView::keyPressEvent(QKeyEvent * event)
 {
        bool oldShift = shiftDown;
        bool oldCtrl = ctrlDown;
+       bool oldAlt = altDown;
 
        if (event->key() == Qt::Key_Shift)
                shiftDown = true;
        else if (event->key() == Qt::Key_Control)
                ctrlDown = true;
+       else if (event->key() == Qt::Key_Alt)
+               altDown = true;
 
        if ((oldShift != shiftDown) || (oldCtrl != ctrlDown))
        {
@@ -1550,6 +1620,14 @@ void DrawingView::keyPressEvent(QKeyEvent * event)
                update();
        }
 
+       if (oldAlt != altDown)
+       {
+               scrollDrag = true;
+               setCursor(Qt::SizeAllCursor);
+//             oldPoint = Vector();
+               oldPoint = oldScrollPoint;
+       }
+
        if (select.size() > 0)
        {
                if (event->key() == Qt::Key_Up)
@@ -1580,11 +1658,14 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event)
 {
        bool oldShift = shiftDown;
        bool oldCtrl = ctrlDown;
+       bool oldAlt = altDown;
 
        if (event->key() == Qt::Key_Shift)
                shiftDown = false;
        else if (event->key() == Qt::Key_Control)
                ctrlDown = false;
+       else if (event->key() == Qt::Key_Alt)
+               altDown = false;
 
        if ((oldShift != shiftDown) || (oldCtrl != ctrlDown))
        {
@@ -1593,6 +1674,12 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event)
 
                update();
        }
+
+       if (oldAlt != altDown)
+       {
+               scrollDrag = false;
+               setCursor(Qt::ArrowCursor);
+       }
 }