X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actioninfodist.cpp;h=a63ea037d9f3d2da821e360f11a3097755ae5445;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=a3c2e8f8518148fa6e0556f41a3313b6c0eee76a;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actioninfodist.cpp b/src/actions/rs_actioninfodist.cpp index a3c2e8f..a63ea03 100644 --- a/src/actions/rs_actioninfodist.cpp +++ b/src/actions/rs_actioninfodist.cpp @@ -1,190 +1,177 @@ -/**************************************************************************** -** $Id: rs_actioninfodist.cpp 1161 2004-12-09 23:10:09Z 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_actioninfodist.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 +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 06/04/2010 Added this text. :-) +// #include "rs_actioninfodist.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionInfoDist::RS_ActionInfoDist(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Info Dist", - container, graphicView) {} - - -QAction* RS_ActionInfoDist::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionInfoDist::RS_ActionInfoDist(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Info Dist", + container, graphicView) { - QAction * action = new QAction(tr("&Distance Point to Point"), 0); -// QAction* action = new QAction(tr("Distance Point to Point"), -// tr("&Distance Point to Point"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Measures the distance between two points")); - return action; } - -void RS_ActionInfoDist::init(int status) { - RS_ActionInterface::init(status); - +RS_ActionInfoDist::~RS_ActionInfoDist() +{ } - - -void RS_ActionInfoDist::trigger() { - - RS_DEBUG->print("RS_ActionInfoDist::trigger()"); - - if (point1.valid && point2.valid) { - double dist = point1.distanceTo(point2); - QString str; - str.sprintf("%.6f", dist); - RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); - } +void RS_ActionInfoDist::init(int status) +{ + RS_ActionInterface::init(status); } +void RS_ActionInfoDist::trigger() +{ + RS_DEBUG->print("RS_ActionInfoDist::trigger()"); + + if (point1.valid && point2.valid) + { + double dist = point1.distanceTo(point2); + QString str; + str.sprintf("%.6f", dist); + RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); + } +} +void RS_ActionInfoDist::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent begin"); -void RS_ActionInfoDist::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent begin"); + if (getStatus() == SetPoint1 + || getStatus() == SetPoint2) + { + Vector mouse = snapPoint(e); - if (getStatus()==SetPoint1 || - getStatus()==SetPoint2) { + switch (getStatus()) + { + case SetPoint1: + break; - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetPoint1: - break; + case SetPoint2: - case SetPoint2: - if (point1.valid) { - point2 = mouse; + if (point1.valid) + { + point2 = mouse; - deletePreview(); - clearPreview(); + deletePreview(); + clearPreview(); - preview->addEntity(new RS_Line(preview, - RS_LineData(point1, - point2))); + preview->addEntity(new RS_Line(preview, + RS_LineData(point1, + point2))); - drawPreview(); - } - break; + drawPreview(); + } + break; - default: - break; - } - } + default: + break; + } + } - RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent end"); } - - -void RS_ActionInfoDist::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionInfoDist::mouseReleaseEvent(QMouseEvent * e) +{ + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionInfoDist::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetPoint1: - point1 = mouse; - graphicView->moveRelativeZero(point1); - setStatus(SetPoint2); - break; - - case SetPoint2: - if (point1.valid) { - point2 = mouse; - deletePreview(); - clearPreview(); - graphicView->moveRelativeZero(point2); - trigger(); - setStatus(SetPoint1); - } - break; - - default: - break; - } +void RS_ActionInfoDist::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetPoint1: + point1 = mouse; + graphicView->moveRelativeZero(point1); + setStatus(SetPoint2); + break; + + case SetPoint2: + + if (point1.valid) + { + point2 = mouse; + deletePreview(); + clearPreview(); + graphicView->moveRelativeZero(point2); + trigger(); + setStatus(SetPoint1); + } + break; + + default: + break; + } } - -void RS_ActionInfoDist::updateMouseButtonHints() { - switch (getStatus()) { - case SetPoint1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first point of distance"), - tr("Cancel")); - break; - case SetPoint2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify second point of distance"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionInfoDist::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetPoint1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify first point of distance"), + tr("Cancel")); + break; + + case SetPoint2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify second point of distance"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionInfoDist::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionInfoDist::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionInfoDist::updateToolBar() { - switch (getStatus()) { - case SetPoint1: - case SetPoint2: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); - break; - } +void RS_ActionInfoDist::updateToolBar() +{ + switch (getStatus()) + { + case SetPoint1: + case SetPoint2: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); + break; + } } - // EOF