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