]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionprintpreview.cpp
c3f274c8546fdacc44f556d98fe66f82802e49b6
[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 "graphicview.h"
20
21 /**
22  * Constructor.
23  */
24 RS_ActionPrintPreview::RS_ActionPrintPreview(RS_EntityContainer & container, 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 (e->button() == Qt::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                 e->accept();
103                 break;
104         }
105 }
106
107 void RS_ActionPrintPreview::coordinateEvent(Vector *)
108 {
109 }
110
111 void RS_ActionPrintPreview::commandEvent(RS_CommandEvent *)
112 {
113 }
114
115 QStringList RS_ActionPrintPreview::getAvailableCommands()
116 {
117         QStringList cmd;
118         return cmd;
119 }
120
121 void RS_ActionPrintPreview::showOptions()
122 {
123         RS_ActionInterface::showOptions();
124
125         RS_DIALOGFACTORY->requestOptions(this, true);
126 }
127
128 void RS_ActionPrintPreview::hideOptions()
129 {
130         RS_ActionInterface::hideOptions();
131
132         RS_DIALOGFACTORY->requestOptions(this, false);
133 }
134
135 void RS_ActionPrintPreview::updateMouseButtonHints()
136 {
137 }
138
139 void RS_ActionPrintPreview::updateMouseCursor()
140 {
141         graphicView->setMouseCursor(RS2::MovingHandCursor);
142 }
143
144 void RS_ActionPrintPreview::updateToolBar()
145 {
146 }
147
148 void RS_ActionPrintPreview::center()
149 {
150         if (graphic != NULL)
151         {
152                 graphic->centerToPage();
153                 graphicView->redraw();
154         }
155 }
156
157 void RS_ActionPrintPreview::fit()
158 {
159         if (graphic != NULL)
160         {
161                 graphic->fitToPage();
162                 graphicView->redraw();
163         }
164 }
165
166 void RS_ActionPrintPreview::setScale(double f)
167 {
168         if (graphic != NULL)
169         {
170                 graphic->setPaperScale(f);
171                 graphicView->redraw();
172         }
173 }
174
175 double RS_ActionPrintPreview::getScale()
176 {
177         double ret = 1.0;
178
179         if (graphic != NULL)
180                 ret = graphic->getPaperScale();
181         return ret;
182 }
183
184 void RS_ActionPrintPreview::setBlackWhite(bool bw)
185 {
186         if (bw)
187                 graphicView->setDrawingMode(RS2::ModeBW);
188         else
189                 graphicView->setDrawingMode(RS2::ModeFull);
190         graphicView->redraw();
191 }
192
193 RS2::Unit RS_ActionPrintPreview::getUnit()
194 {
195         if (graphic != NULL)
196                 return graphic->getUnit();
197         else
198                 return RS2::None;
199 }
200
201 // EOF