]> Shamusworld >> Repos - architektonas/blob - src/base/rs_previewactioninterface.cpp
Scrubbed out all references to RS2::qtToRsButton(). Gone!
[architektonas] / src / base / rs_previewactioninterface.cpp
1 // rs_previewactioninterface.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/02/2010  Added this text. :-)
13 //
14
15 #include "rs_previewactioninterface.h"
16
17 #include "rs_debug.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
20
21 /**
22  * Constructor.
23  *
24  * Sets the entity container on which the action class inherited
25  * from this interface operates.
26  */
27 RS_PreviewActionInterface::RS_PreviewActionInterface(const char * name,
28         RS_EntityContainer & container, RS_GraphicView & graphicView):
29         RS_ActionInterface(name, container, graphicView)
30 {
31         RS_DEBUG->print("RS_PreviewActionInterface::RS_PreviewActionInterface: Setting up action with preview: \"%s\"", name);
32
33         // preview is linked to the container for getting access to
34         //   document settings / dictionary variables
35         preview = new RS_Preview(&container);
36         visible = false;
37
38         RS_DEBUG->print("RS_PreviewActionInterface::RS_PreviewActionInterface: Setting up action with preview: \"%s\": OK", name);
39 }
40
41 /** Destructor */
42 RS_PreviewActionInterface::~RS_PreviewActionInterface()
43 {
44         delete preview;
45 }
46
47 void RS_PreviewActionInterface::init(int status)
48 {
49         RS_ActionInterface::init(status);
50         //deletePreview();
51         clearPreview();
52 }
53
54 void RS_PreviewActionInterface::finish()
55 {
56         RS_ActionInterface::finish();
57         deletePreview();
58         clearPreview();
59 }
60
61 void RS_PreviewActionInterface::suspend()
62 {
63         RS_ActionInterface::suspend();
64         deletePreview();
65         //clearPreview();
66 }
67
68 void RS_PreviewActionInterface::resume()
69 {
70         RS_ActionInterface::resume();
71         drawPreview();
72 }
73
74 void RS_PreviewActionInterface::trigger()
75 {
76         RS_ActionInterface::trigger();
77         deletePreview();
78         clearPreview();
79 }
80
81 /**
82  * Clears the preview by removing all entities in it.
83  */
84 void RS_PreviewActionInterface::clearPreview()
85 {
86         preview->clear();
87 }
88
89 /**
90  * Draws the preview on the screen.
91  */
92 void RS_PreviewActionInterface::drawPreview()
93 {
94         if (!visible)
95                 xorPreview();
96 }
97
98 /**
99  * Deletes the preview from the screen.
100  */
101 void RS_PreviewActionInterface::deletePreview()
102 {
103         if (visible)
104                 xorPreview();
105 }
106
107 //#include "qg_graphicview.h"
108 /**
109  * Draws / deletes the current preview.
110  */
111 void RS_PreviewActionInterface::xorPreview()
112 {
113 #warning "!!! xorPreview() not working AT ALL !!!"
114 #if 0
115         if (!preview->isEmpty())
116         {
117                 RS_Painter * painter = graphicView->createDirectPainter();
118                 painter->setPreviewMode();
119                 painter->setOffset(offset);
120                 graphicView->drawEntity(preview, false);
121                 graphicView->destroyPainter();
122         }
123
124         visible = !visible;
125 #else
126         // OK, we need a new approach here--direct painting is NOT acceptable anymore!
127         // So, something like this:
128         /*
129         In graphicView->drawEntity(preview, false); we set the pointer to an entity
130         in the GV. We set a flag telling paintEvent that this is a preview, and then
131         call update() in the view. *That* should do it...
132         */
133 //This doesn't work, causes the thing to crash...
134 //Now it works, just need to upgrade the rendering paths so that they aren't all
135 //fucked up like QCad was...
136 #if 1
137         if (!preview->isEmpty())
138         {
139                 graphicView->SetPreviewMode();
140                 graphicView->SetPreviewEntity(preview);
141                 graphicView->SetPreviewOffset(offset);
142                 graphicView->redraw();
143         }
144
145         visible = !visible;
146 #endif
147 #endif
148 }