]> Shamusworld >> Repos - architektonas/blob - src/base/rs_previewactioninterface.cpp
Refactoring: Moved RS_GraphicView to GraphicView.
[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
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 /**
108  * Draws / deletes the current preview.
109  */
110 void RS_PreviewActionInterface::xorPreview()
111 {
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 1
136         if (!preview->isEmpty())
137         {
138                 graphicView->SetPreviewMode();
139                 graphicView->SetPreviewEntity(preview);
140                 graphicView->SetPreviewOffset(offset);
141                 graphicView->redraw();
142         }
143
144         visible = !visible;
145 #endif
146 #endif
147 }