]> Shamusworld >> Repos - architektonas/blob - src/actions/actionprintpreview.cpp
Bugfixes related to removing Snapper class.
[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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/04/2010  Added this text. :-)
15 //
16
17 #include "actionprintpreview.h"
18
19 #include "dialogfactory.h"
20 #include "drawing.h"
21 #include "graphicview.h"
22
23 /**
24  * Constructor.
25  */
26 ActionPrintPreview::ActionPrintPreview(EntityContainer & container, GraphicView & graphicView):
27         ActionInterface("Print Preview", container, graphicView)
28 {
29         showOptions();
30 }
31
32 ActionPrintPreview::~ActionPrintPreview()
33 {
34 }
35
36 /*virtual*/ RS2::ActionType ActionPrintPreview::rtti()
37 {
38         return RS2::ActionPrintPreview;
39 }
40
41 void ActionPrintPreview::init(int status)
42 {
43         ActionInterface::init(status);
44         showOptions();
45 }
46
47 void ActionPrintPreview::trigger()
48 {
49 }
50
51 void ActionPrintPreview::mouseMoveEvent(QMouseEvent * e)
52 {
53         switch (getStatus())
54         {
55         case Moving:
56                 v2 = graphicView->toGraph(e->x(), e->y());
57
58                 if (graphic)
59                 {
60                         Vector pinsbase = graphic->getPaperInsertionBase();
61                         double scale = graphic->getPaperScale();
62                         graphic->setPaperInsertionBase(pinsbase - v2 * scale + v1 * scale);
63                 }
64
65                 v1 = v2;
66                 graphicView->redraw();
67                 break;
68
69         default:
70                 break;
71         }
72 }
73
74 void 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 ActionPrintPreview::mouseReleaseEvent(QMouseEvent * e)
92 {
93         switch (getStatus())
94         {
95         case Moving:
96                 setStatus(Neutral);
97                 break;
98
99         default:
100                 DIALOGFACTORY->requestPreviousMenu();
101                 e->accept();
102                 break;
103         }
104 }
105
106 void ActionPrintPreview::coordinateEvent(Vector *)
107 {
108 }
109
110 void ActionPrintPreview::commandEvent(CommandEvent *)
111 {
112 }
113
114 QStringList ActionPrintPreview::getAvailableCommands()
115 {
116         QStringList cmd;
117         return cmd;
118 }
119
120 void ActionPrintPreview::showOptions()
121 {
122         ActionInterface::showOptions();
123
124         DIALOGFACTORY->requestOptions(this, true);
125 }
126
127 void ActionPrintPreview::hideOptions()
128 {
129         ActionInterface::hideOptions();
130
131         DIALOGFACTORY->requestOptions(this, false);
132 }
133
134 void ActionPrintPreview::updateMouseButtonHints()
135 {
136 }
137
138 void ActionPrintPreview::updateMouseCursor()
139 {
140         graphicView->setMouseCursor(RS2::MovingHandCursor);
141 }
142
143 void ActionPrintPreview::updateToolBar()
144 {
145 }
146
147 void ActionPrintPreview::center()
148 {
149         if (graphic)
150         {
151                 graphic->centerToPage();
152                 graphicView->redraw();
153         }
154 }
155
156 void ActionPrintPreview::fit()
157 {
158         if (graphic)
159         {
160                 graphic->fitToPage();
161                 graphicView->redraw();
162         }
163 }
164
165 void ActionPrintPreview::setScale(double f)
166 {
167         if (graphic)
168         {
169                 graphic->setPaperScale(f);
170                 graphicView->redraw();
171         }
172 }
173
174 double ActionPrintPreview::getScale()
175 {
176         double ret = 1.0;
177
178         if (graphic)
179                 ret = graphic->getPaperScale();
180
181         return ret;
182 }
183
184 void ActionPrintPreview::setBlackWhite(bool bw)
185 {
186         if (bw)
187                 graphicView->setDrawingMode(RS2::ModeBW);
188         else
189                 graphicView->setDrawingMode(RS2::ModeFull);
190
191         graphicView->redraw();
192 }
193
194 RS2::Unit ActionPrintPreview::getUnit()
195 {
196         if (graphic)
197                 return graphic->getUnit();
198
199         return RS2::None;
200 }