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