]> Shamusworld >> Repos - architektonas/blob - src/base/rs_previewactioninterface.cpp
Last checkin before major refactor...
[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 "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, 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 document
34         // 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         clearPreview();
51 }
52
53 void RS_PreviewActionInterface::finish()
54 {
55         RS_ActionInterface::finish();
56         deletePreview();
57         clearPreview();
58 }
59
60 void RS_PreviewActionInterface::suspend()
61 {
62         RS_ActionInterface::suspend();
63         deletePreview();
64 }
65
66 void RS_PreviewActionInterface::resume()
67 {
68         RS_ActionInterface::resume();
69         drawPreview();
70 }
71
72 void RS_PreviewActionInterface::trigger()
73 {
74         RS_ActionInterface::trigger();
75         deletePreview();
76         clearPreview();
77 }
78
79 /**
80  * Clears the preview by removing all entities in it.
81  */
82 void RS_PreviewActionInterface::clearPreview()
83 {
84         preview->clear();
85 }
86
87 /**
88  * Draws the preview on the screen.
89  */
90 void RS_PreviewActionInterface::drawPreview()
91 {
92         if (!visible)
93                 xorPreview();
94 }
95
96 /**
97  * Deletes the preview from the screen.
98  */
99 void RS_PreviewActionInterface::deletePreview()
100 {
101         if (visible)
102                 xorPreview();
103 }
104
105 /**
106  * Draws / deletes the current preview.
107  */
108 void RS_PreviewActionInterface::xorPreview()
109 {
110 #warning "!!! RS_PreviewActionInterface::xorPreview() is DEPRECATED !!!"
111 //not true anymore..
112 //#warning "!!! xorPreview() not working AT ALL !!!"
113 #if 0
114         if (!preview->isEmpty())
115         {
116                 RS_Painter * painter = graphicView->createDirectPainter();
117                 painter->setPreviewMode();
118                 painter->setOffset(offset);
119                 graphicView->drawEntity(preview, false);
120                 graphicView->destroyPainter();
121         }
122
123         visible = !visible;
124 #else
125         // OK, we need a new approach here--direct painting is NOT acceptable anymore!
126         // So, something like this:
127         /*
128         In graphicView->drawEntity(preview, false); we set the pointer to an entity
129         in the GV. We set a flag telling paintEvent that this is a preview, and then
130         call update() in the view. *That* should do it...
131         */
132 //This doesn't work, causes the thing to crash...
133 //Now it works, just need to upgrade the rendering paths so that they aren't all
134 //fucked up like QCad was...
135         if (!preview->isEmpty())
136         {
137                 graphicView->SetPreviewMode();
138                 graphicView->SetPreviewEntity(preview);
139                 graphicView->SetPreviewOffset(offset);
140                 graphicView->redraw();
141         }
142
143         visible = !visible;
144 #endif
145 }