]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionprintpreview.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionprintpreview.cpp
1 // rs_actionprintpreview.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/04/2010  Added this text. :-)
13 //
14
15 #include "rs_actionprintpreview.h"
16
17 #include "rs_dialogfactory.h"
18 #include "drawing.h"
19 #include "rs_graphicview.h"
20
21 /**
22  * Constructor.
23  */
24 RS_ActionPrintPreview::RS_ActionPrintPreview(RS_EntityContainer & container, RS_GraphicView & graphicView):
25         RS_ActionInterface("Print Preview",
26                 container, graphicView)
27 {
28         showOptions();
29 }
30
31 RS_ActionPrintPreview::~RS_ActionPrintPreview()
32 {
33 }
34
35 /*virtual*/ RS2::ActionType RS_ActionPrintPreview::rtti()
36 {
37         return RS2::ActionPrintPreview;
38 }
39
40 void RS_ActionPrintPreview::init(int status)
41 {
42         RS_ActionInterface::init(status);
43         showOptions();
44 }
45
46 void RS_ActionPrintPreview::trigger()
47 {
48 }
49
50 void RS_ActionPrintPreview::mouseMoveEvent(QMouseEvent * e)
51 {
52         switch (getStatus())
53         {
54         case Moving:
55                 v2 = graphicView->toGraph(e->x(), e->y());
56
57                 if (graphic != NULL)
58                 {
59                         Vector pinsbase = graphic->getPaperInsertionBase();
60
61                         double scale = graphic->getPaperScale();
62
63                         graphic->setPaperInsertionBase(pinsbase - v2 * scale + v1 * scale);
64                 }
65                 v1 = v2;
66                 graphicView->redraw();
67                 break;
68
69         default:
70                 break;
71         }
72 }
73
74 void RS_ActionPrintPreview::mousePressEvent(QMouseEvent * e)
75 {
76         if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
77         {
78                 switch (getStatus())
79                 {
80                 case Neutral:
81                         v1 = graphicView->toGraph(e->x(), e->y());
82                         setStatus(Moving);
83                         break;
84
85                 default:
86                         break;
87                 }
88         }
89 }
90
91 void RS_ActionPrintPreview::mouseReleaseEvent(QMouseEvent * e)
92 {
93         switch (getStatus())
94         {
95         case Moving:
96                 setStatus(Neutral);
97                 break;
98
99         default:
100                 //deleteSnapper();
101                 RS_DIALOGFACTORY->requestPreviousMenu();
102 #if QT_VERSION >= 0x030000
103                 e->accept();
104 #endif
105                 break;
106         }
107 }
108
109 void RS_ActionPrintPreview::coordinateEvent(Vector *)
110 {
111 }
112
113 void RS_ActionPrintPreview::commandEvent(RS_CommandEvent *)
114 {
115 }
116
117 QStringList RS_ActionPrintPreview::getAvailableCommands()
118 {
119         QStringList cmd;
120         return cmd;
121 }
122
123 void RS_ActionPrintPreview::showOptions()
124 {
125         RS_ActionInterface::showOptions();
126
127         RS_DIALOGFACTORY->requestOptions(this, true);
128 }
129
130 void RS_ActionPrintPreview::hideOptions()
131 {
132         RS_ActionInterface::hideOptions();
133
134         RS_DIALOGFACTORY->requestOptions(this, false);
135 }
136
137 void RS_ActionPrintPreview::updateMouseButtonHints()
138 {
139 }
140
141 void RS_ActionPrintPreview::updateMouseCursor()
142 {
143         graphicView->setMouseCursor(RS2::MovingHandCursor);
144 }
145
146 void RS_ActionPrintPreview::updateToolBar()
147 {
148 }
149
150 void RS_ActionPrintPreview::center()
151 {
152         if (graphic != NULL)
153         {
154                 graphic->centerToPage();
155                 graphicView->redraw();
156         }
157 }
158
159 void RS_ActionPrintPreview::fit()
160 {
161         if (graphic != NULL)
162         {
163                 graphic->fitToPage();
164                 graphicView->redraw();
165         }
166 }
167
168 void RS_ActionPrintPreview::setScale(double f)
169 {
170         if (graphic != NULL)
171         {
172                 graphic->setPaperScale(f);
173                 graphicView->redraw();
174         }
175 }
176
177 double RS_ActionPrintPreview::getScale()
178 {
179         double ret = 1.0;
180
181         if (graphic != NULL)
182                 ret = graphic->getPaperScale();
183         return ret;
184 }
185
186 void RS_ActionPrintPreview::setBlackWhite(bool bw)
187 {
188         if (bw)
189                 graphicView->setDrawingMode(RS2::ModeBW);
190         else
191                 graphicView->setDrawingMode(RS2::ModeFull);
192         graphicView->redraw();
193 }
194
195 RS2::Unit RS_ActionPrintPreview::getUnit()
196 {
197         if (graphic != NULL)
198                 return graphic->getUnit();
199         else
200                 return RS2::None;
201 }
202
203 // EOF