1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26
27 #include "rs_actionzoompan.h"
28
29 #include <QAction>
30 #include <QMouseEvent>
31 #include "rs_graphicview.h"
32 #include "rs_dialogfactory.h"
33 #include "rs_graphicview.h"
34 #include "rs_commands.h"
35 #include "rs_commandevent.h"
36 #include "rs_debug.h"
37
RS_ActionZoomPan(RS_EntityContainer & container,RS_GraphicView & graphicView)38 RS_ActionZoomPan::RS_ActionZoomPan(RS_EntityContainer& container,
39 RS_GraphicView& graphicView)
40 :RS_ActionInterface("Zoom Panning", container, graphicView) {}
41
init(int status)42 void RS_ActionZoomPan::init(int status) {
43 RS_ActionInterface::init(status);
44 snapMode.clear();
45 snapMode.restriction = RS2::RestrictNothing;
46 //v1 = v2 = RS_Vector(false);
47 x1 = y1 = x2 = y2 = -1;
48 //graphicView->saveView();
49 setStatus(SetPanStart);
50 updateMouseButtonHints();
51 }
52
53
54
trigger()55 void RS_ActionZoomPan::trigger() {
56 /*if (v1.valid && v2.valid) {
57 graphicView->zoomPan(v2-v1);
58 v1 = v2;
59 }*/
60 if (getStatus()==SetPanning && (abs(x2-x1)>7 || abs(y2-y1)>7)) {
61 graphicView->zoomPan(x2-x1, y2-y1);
62 x1 = x2;
63 y1 = y2;
64 }
65 if(getStatus()==SetPanEnd)
66 {
67 finish(false);
68 graphicView->setPanning(false);
69 graphicView->redraw();
70 }
71 }
72
73
74
mouseMoveEvent(QMouseEvent * e)75 void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent* e) {
76 //v2 = snapPoint(e);
77 x2 = e->x();
78 y2 = e->y();
79 //if (getStatus()==1 && graphicView->toGuiDX((v2-v1).magnitude())>10) {
80 if (getStatus()==SetPanning ) {
81 if (abs(x2-x1)>7 || abs(y2-y1)>7) {
82 trigger();
83 }
84 }
85 }
86
87
mousePressEvent(QMouseEvent * e)88 void RS_ActionZoomPan::mousePressEvent(QMouseEvent* e) {
89 if (e->button()==Qt::MiddleButton ||
90 e->button()==Qt::LeftButton) {
91 //v1 = snapPoint(e);
92 x1 = e->x();
93 y1 = e->y();
94 setStatus(SetPanning);
95 graphicView->setPanning(true);
96 }
97 }
98
99
100
mouseReleaseEvent(QMouseEvent * e)101 void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent* e) {
102 switch (e->button()) {
103 case Qt::MiddleButton:
104 case Qt::RightButton:
105 setStatus(SetPanEnd);
106 break;
107 default:
108 setStatus(SetPanStart);
109 }
110 trigger();
111 //RS_DEBUG->print("RS_ActionZoomPan::mousePressEvent(): %f %f", v1.x, v1.y);
112 }
113
updateMouseButtonHints()114 void RS_ActionZoomPan::updateMouseButtonHints()
115 {
116 switch (getStatus()) {
117 case SetPanStart:
118 RS_DIALOGFACTORY->updateMouseWidget(tr("Click and drag to pan zoom"),
119 tr("Cancel"));
120 break;
121 case SetPanning:
122 RS_DIALOGFACTORY->updateMouseWidget(tr("Zoom panning"),
123 tr("Cancel"));
124 break;
125 default:
126 RS_DIALOGFACTORY->updateMouseWidget();
127 }
128 }
129
130
updateMouseCursor()131 void RS_ActionZoomPan::updateMouseCursor() {
132 switch (getStatus()){
133 case SetPanStart:
134 graphicView->setMouseCursor(RS2::OpenHandCursor);
135 break;
136 case SetPanning:
137 graphicView->setMouseCursor(RS2::ClosedHandCursor);
138 break;
139 default:
140 break;
141 }
142 }
143
144
145 // EOF
146