]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionzoompan.cpp
Initial import
[architektonas] / src / actions / rs_actionzoompan.cpp
1 /****************************************************************************
2 ** $Id: rs_actionzoompan.cpp 1134 2004-07-13 23:26:13Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionzoompan.h"
28 #include "rs_snapper.h"
29 #include "rs_point.h"
30 //Added by qt3to4:
31 //#include <QPixmap>
32
33 RS_ActionZoomPan::RS_ActionZoomPan(RS_EntityContainer& container,
34         RS_GraphicView& graphicView):
35         RS_ActionInterface("Zoom Pan", container, graphicView)
36 {
37 }
38
39 QAction * RS_ActionZoomPan::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
40 {
41         QAction * action = new QAction(QIcon(":/res/zoompan.png"), tr("&Pan Zoom"), 0);
42 //      QAction* action = new QAction(tr("Pan Zoom"), QPixmap::fromMimeSource("zoompan.png"),
43 //                                                                      tr("&Pan Zoom"), QKeySequence(), NULL);
44         action->setStatusTip(tr("Realtime Panning"));
45         return action;
46 }
47
48 void RS_ActionZoomPan::init(int status)
49 {
50     RS_ActionInterface::init(status);
51     snapMode = RS2::SnapFree;
52     snapRes = RS2::RestrictNothing;
53     //v1 = v2 = Vector(false);
54     x1 = y1 = x2 = y2 = -1;
55     //graphicView->saveView();
56 }
57
58
59
60 void RS_ActionZoomPan::trigger() {
61     /*if (v1.valid && v2.valid) {
62         graphicView->zoomPan(v2-v1);
63         v1 = v2;
64 }*/
65     if (x1>=0) {
66         graphicView->zoomPan(x2-x1, y2-y1);
67         x1 = x2;
68         y1 = y2;
69     }
70 }
71
72
73
74 void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent* e) {
75     //v2 = snapPoint(e);
76     x2 = e->x();
77     y2 = e->y();
78     //if (getStatus()==1 && graphicView->toGuiDX((v2-v1).magnitude())>10) {
79     if (getStatus()==1 && (abs(x2-x1)>7 || abs(y2-y1)>7)) {
80         trigger();
81     }
82 }
83
84
85
86 void RS_ActionZoomPan::mousePressEvent(QMouseEvent* e) {
87     if (RS2::qtToRsButtonState(e->button())==RS2::MidButton ||
88             RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
89         //v1 = snapPoint(e);
90         x1 = e->x();
91         y1 = e->y();
92         setStatus(1);
93     }
94 }
95
96
97
98 void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent* e) {
99     if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
100         init(getStatus()-1);
101     } else if (RS2::qtToRsButtonState(e->button())==RS2::MidButton) {
102         init(-1);
103     } else {
104         setStatus(0);
105     }
106
107     //RS_DEBUG->print("RS_ActionZoomPan::mousePressEvent(): %f %f", v1.x, v1.y);
108 }
109
110
111
112 void RS_ActionZoomPan::updateMouseCursor() {
113 #ifndef __APPLE__
114     graphicView->setMouseCursor(RS2::SizeAllCursor);
115 #endif
116 }
117
118
119 // EOF