]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actiondrawimage.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actiondrawimage.cpp
index 65ae1c9dd00f8df63ccec215765f9e6c6bba5172..d68e5b517fd86cd4a4566048f8ab97b2d676c057 100644 (file)
@@ -1,40 +1,28 @@
-/****************************************************************************
-** $Id: rs_actiondrawimage.cpp 1134 2004-07-13 23:26:13Z andrew $
-**
-** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
-**
-** This file is part of the qcadlib Library project.
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** Licensees holding valid qcadlib Professional Edition licenses may use
-** this file in accordance with the qcadlib Commercial License
-** Agreement provided with the Software.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** See http://www.ribbonsoft.com for further details.
-**
-** Contact info@ribbonsoft.com if any conditions of this licensing are
-** not clear to you.
-**
-**********************************************************************/
+// rs_actiondrawimage.cpp
+//
+// Part of the Architektonas Project
+// Originally part of QCad Community Edition by Andrew Mustun
+// Extensively rewritten and refactored by James L. Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -----------------------------------------------------------
+// JLH  05/22/2010  Added this text. :-)
+//
 
 #include "rs_actiondrawimage.h"
 
 #include "rs_creation.h"
-#include "commands.h"
-#include "rs_modification.h"
+#include "rs_dialogfactory.h"
+#include "rs_graphicview.h"
+#include "rs_preview.h"
 
 /**
  * Constructor.
  */
-RS_ActionDrawImage::RS_ActionDrawImage(RS_EntityContainer & container,
-       RS_GraphicView & graphicView):
+RS_ActionDrawImage::RS_ActionDrawImage(RS_EntityContainer & container, RS_GraphicView & graphicView):
        RS_PreviewActionInterface("Image", container, graphicView)
 {
 }
@@ -43,13 +31,9 @@ RS_ActionDrawImage::~RS_ActionDrawImage()
 {
 }
 
-QAction * RS_ActionDrawImage::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
+/*virtual*/ RS2::ActionType RS_ActionDrawImage::rtti()
 {
-       QAction * action = new QAction(tr("&Image"), 0);
-//     QAction* action = new QAction(tr("Image"), tr("&Image"),
-//                                                     QKeySequence(), NULL);
-       action->setStatusTip(tr("Insert Image (Bitmap)"));
-       return action;
+       return RS2::ActionDrawImage;
 }
 
 void RS_ActionDrawImage::init(int status)
@@ -79,12 +63,12 @@ void RS_ActionDrawImage::init(int status)
 void RS_ActionDrawImage::reset()
 {
        data = RS_ImageData(0,
-               Vector(0.0,0.0),
-               Vector(1.0,0.0),
-               Vector(0.0,1.0),
-               Vector(1.0,1.0),
-               "",
-               50, 50, 0);
+                       Vector(0.0, 0.0),
+                       Vector(1.0, 0.0),
+                       Vector(0.0, 1.0),
+                       Vector(1.0, 1.0),
+                       "",
+                       50, 50, 0);
 }
 
 void RS_ActionDrawImage::trigger()
@@ -120,15 +104,15 @@ void RS_ActionDrawImage::mouseMoveEvent(QMouseEvent * e)
                line = new RS_Line(preview, RS_LineData(Vector(0, 0), Vector(img.width(), 0)));
                preview->addEntity(line);
                line = new RS_Line(preview,
-                       RS_LineData(Vector(img.width(), 0), Vector(img.width(), img.height())));
+                               RS_LineData(Vector(img.width(), 0), Vector(img.width(), img.height())));
                preview->addEntity(line);
                line = new RS_Line(preview,
-                       RS_LineData(Vector(img.width(), img.height()), Vector(0, img.height())));
+                               RS_LineData(Vector(img.width(), img.height()), Vector(0, img.height())));
                preview->addEntity(line);
                line = new RS_Line(preview, RS_LineData(Vector(0, img.height()), Vector(0, 0)));
                preview->addEntity(line);
-               preview->scale(Vector(0,0), Vector(data.uVector.magnitude(), data.uVector.magnitude()));
-               preview->rotate(Vector(0,0), data.uVector.angle());
+               preview->scale(Vector(0, 0), Vector(data.uVector.magnitude(), data.uVector.magnitude()));
+               preview->rotate(Vector(0, 0), data.uVector.angle());
                preview->move(data.insertionPoint);
 
                drawPreview();
@@ -141,12 +125,14 @@ void RS_ActionDrawImage::mouseMoveEvent(QMouseEvent * e)
 
 void RS_ActionDrawImage::mouseReleaseEvent(QMouseEvent * e)
 {
-       if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+//     if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+       if (e->button() == Qt::LeftButton)
        {
-               RS_CoordinateEvent ce(snapPoint(e));
+               Vector ce(snapPoint(e));
                coordinateEvent(&ce);
        }
-       else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
+//     else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
+       else if (e->button() == Qt::RightButton)
        {
                deleteSnapper();
                //init(getStatus()-1);
@@ -154,12 +140,12 @@ void RS_ActionDrawImage::mouseReleaseEvent(QMouseEvent * e)
        }
 }
 
-void RS_ActionDrawImage::coordinateEvent(RS_CoordinateEvent * e)
+void RS_ActionDrawImage::coordinateEvent(Vector * e)
 {
        if (e == NULL)
                return;
 
-       data.insertionPoint = e->getCoordinate();
+       data.insertionPoint = *e;
        trigger();
 }
 
@@ -177,6 +163,7 @@ void RS_ActionDrawImage::commandEvent(RS_CommandEvent * e)
        switch (getStatus())
        {
        case SetTargetPoint:
+
                if (checkCommand("angle", c))
                {
                        deleteSnapper();
@@ -197,31 +184,31 @@ void RS_ActionDrawImage::commandEvent(RS_CommandEvent * e)
 
        case SetAngle:
        {
-                       bool ok;
-                       double a = RS_Math::eval(c, &ok);
-                       if (ok==true) {
-                               setAngle(RS_Math::deg2rad(a));
-                       } else {
-                               RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-                       }
-                       RS_DIALOGFACTORY->requestOptions(this, true, true);
-                       setStatus(lastStatus);
+               bool ok;
+               double a = RS_Math::eval(c, &ok);
+
+               if (ok == true)
+                       setAngle(RS_Math::deg2rad(a));
+               else
+                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+               RS_DIALOGFACTORY->requestOptions(this, true, true);
+               setStatus(lastStatus);
        }
-               break;
+       break;
 
        case SetFactor:
        {
-                       bool ok;
-                       double f = RS_Math::eval(c, &ok);
-                       if (ok==true) {
-                               setFactor(f);
-                       } else {
-                               RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-                       }
-                       RS_DIALOGFACTORY->requestOptions(this, true, true);
-                       setStatus(lastStatus);
+               bool ok;
+               double f = RS_Math::eval(c, &ok);
+
+               if (ok == true)
+                       setFactor(f);
+               else
+                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+               RS_DIALOGFACTORY->requestOptions(this, true, true);
+               setStatus(lastStatus);
        }
-               break;
+       break;
 
        default:
                break;
@@ -238,6 +225,7 @@ QStringList RS_ActionDrawImage::getAvailableCommands()
                cmd += command("angle");
                cmd += command("factor");
                break;
+
        default:
                break;
        }
@@ -266,12 +254,15 @@ void RS_ActionDrawImage::updateMouseButtonHints()
        case SetTargetPoint:
                RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
                break;
+
        case SetAngle:
                RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
                break;
+
        case SetFactor:
                RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
                break;
+
        default:
                RS_DIALOGFACTORY->updateMouseWidget("", "");
                break;
@@ -285,9 +276,33 @@ void RS_ActionDrawImage::updateMouseCursor()
 
 void RS_ActionDrawImage::updateToolBar()
 {
-       if (!isFinished()) {
+       if (!isFinished())
                RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
-       } else {
+       else
                RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
-       }
 }
+
+double RS_ActionDrawImage::getAngle()
+{
+       return data.uVector.angle();
+}
+
+void RS_ActionDrawImage::setAngle(double a)
+{
+       double l = data.uVector.magnitude();
+       data.uVector.setPolar(l, a);
+       data.vVector.setPolar(l, a + M_PI / 2);
+}
+
+double RS_ActionDrawImage::getFactor()
+{
+       return data.uVector.magnitude();
+}
+
+void RS_ActionDrawImage::setFactor(double f)
+{
+       double a = data.uVector.angle();
+       data.uVector.setPolar(f, a);
+       data.vVector.setPolar(f, a + M_PI / 2);
+}
+