]> Shamusworld >> Repos - architektonas/blob - src/actions/actionprintpreview.cpp
Last checkin before major refactor...
[architektonas] / src / actions / actionprintpreview.cpp
1 // 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 "actionprintpreview.h"
16
17 #include "rs_dialogfactory.h"
18 #include "drawing.h"
19 #include "graphicview.h"
20
21 /**
22  * Constructor.
23  */
24 ActionPrintPreview::ActionPrintPreview(RS_EntityContainer & container, GraphicView & graphicView):
25         ActionInterface("Print Preview", container, graphicView)
26 {
27         showOptions();
28 }
29
30 ActionPrintPreview::~ActionPrintPreview()
31 {
32 }
33
34 /*virtual*/ RS2::ActionType ActionPrintPreview::rtti()
35 {
36         return RS2::ActionPrintPreview;
37 }
38
39 void ActionPrintPreview::init(int status)
40 {
41         ActionInterface::init(status);
42         showOptions();
43 }
44
45 void ActionPrintPreview::trigger()
46 {
47 }
48
49 void ActionPrintPreview::mouseMoveEvent(QMouseEvent * e)
50 {
51         switch (getStatus())
52         {
53         case Moving:
54                 v2 = graphicView->toGraph(e->x(), e->y());
55
56                 if (graphic)
57                 {
58                         Vector pinsbase = graphic->getPaperInsertionBase();
59                         double scale = graphic->getPaperScale();
60                         graphic->setPaperInsertionBase(pinsbase - v2 * scale + v1 * scale);
61                 }
62
63                 v1 = v2;
64                 graphicView->redraw();
65                 break;
66
67         default:
68                 break;
69         }
70 }
71
72 void ActionPrintPreview::mousePressEvent(QMouseEvent * e)
73 {
74         if (e->button() == Qt::LeftButton)
75         {
76                 switch (getStatus())
77                 {
78                 case Neutral:
79                         v1 = graphicView->toGraph(e->x(), e->y());
80                         setStatus(Moving);
81                         break;
82
83                 default:
84                         break;
85                 }
86         }
87 }
88
89 void ActionPrintPreview::mouseReleaseEvent(QMouseEvent * e)
90 {
91         switch (getStatus())
92         {
93         case Moving:
94                 setStatus(Neutral);
95                 break;
96
97         default:
98                 RS_DIALOGFACTORY->requestPreviousMenu();
99                 e->accept();
100                 break;
101         }
102 }
103
104 void ActionPrintPreview::coordinateEvent(Vector *)
105 {
106 }
107
108 void ActionPrintPreview::commandEvent(RS_CommandEvent *)
109 {
110 }
111
112 QStringList ActionPrintPreview::getAvailableCommands()
113 {
114         QStringList cmd;
115         return cmd;
116 }
117
118 void ActionPrintPreview::showOptions()
119 {
120         ActionInterface::showOptions();
121
122         RS_DIALOGFACTORY->requestOptions(this, true);
123 }
124
125 void ActionPrintPreview::hideOptions()
126 {
127         ActionInterface::hideOptions();
128
129         RS_DIALOGFACTORY->requestOptions(this, false);
130 }
131
132 void ActionPrintPreview::updateMouseButtonHints()
133 {
134 }
135
136 void ActionPrintPreview::updateMouseCursor()
137 {
138         graphicView->setMouseCursor(RS2::MovingHandCursor);
139 }
140
141 void ActionPrintPreview::updateToolBar()
142 {
143 }
144
145 void ActionPrintPreview::center()
146 {
147         if (graphic)
148         {
149                 graphic->centerToPage();
150                 graphicView->redraw();
151         }
152 }
153
154 void ActionPrintPreview::fit()
155 {
156         if (graphic)
157         {
158                 graphic->fitToPage();
159                 graphicView->redraw();
160         }
161 }
162
163 void ActionPrintPreview::setScale(double f)
164 {
165         if (graphic)
166         {
167                 graphic->setPaperScale(f);
168                 graphicView->redraw();
169         }
170 }
171
172 double ActionPrintPreview::getScale()
173 {
174         double ret = 1.0;
175
176         if (graphic)
177                 ret = graphic->getPaperScale();
178
179         return ret;
180 }
181
182 void ActionPrintPreview::setBlackWhite(bool bw)
183 {
184         if (bw)
185                 graphicView->setDrawingMode(RS2::ModeBW);
186         else
187                 graphicView->setDrawingMode(RS2::ModeFull);
188
189         graphicView->redraw();
190 }
191
192 RS2::Unit ActionPrintPreview::getUnit()
193 {
194         if (graphic)
195                 return graphic->getUnit();
196
197         return RS2::None;
198 }