summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmdialogeditbase.h
blob: 33dbf3077951576fc3dcad4e88b0736e66faa924 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2001 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/


#ifndef PMDIALOGEDITBASE_H
#define PMDIALOGEDITBASE_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tqwidget.h>
#include <tqstring.h>

#include "pmobject.h"

class TQBoxLayout;
class TQCheckBox;
class TQLayout;
class TQPushButton;
class TQVBox;
class TDEConfig;
class PMPart;
class PMPovrayRenderWidget;
class PMPovrayOutputWidget;

/**
 * Base class for all widgets for editing object attributes.
 *
 * Ensures a consistent layout for all widgets. Widgets should not
 * created within the constructor, but with the functions @ref createTopWidgets
 * and @ref createBottomWidgets.
 * 
 * Each subclass uses the functionality of the base class. For example all
 * widgets for solid objects have the same base class that shows attributes
 * of solid objects. Subclasses like the widget for the box object add their
 * object specific controls.
 */
class PMDialogEditBase : public TQWidget
{
   TQ_OBJECT
  
public:
   /**
    * Creates a new PMDialogEditBase widget objectType is
    * @ref PMObject->description( ).
    *
    * No widgets are created within the constructor! You have to call
    * @ref createWidgets after creating a new edit widget.
    */
   PMDialogEditBase( TQWidget* parent, const char* name = 0 );
   /**
    * Destructor
    */
   virtual ~PMDialogEditBase( );

   /**
    * Creates child widgets.
    *
    * This function is necessary because virtual functions do not work
    * properly inside the constructor.
    *
    * Calls @ref createTopWidgets and @ref createBottomWidgets
    */
   void createWidgets( );

   /**
    * Displays the object o.
    * Always call displayObject( ) of the base class after displaying the
    * objects data
    */
   virtual void displayObject( PMObject* o );
   
   /**
    * returns a pointer to the displayed object
    */
   PMObject* displayedObject( ) const { return m_pDisplayedObject; }
   
   /**
    * Function that is called, when the "Apply" button is pressed.
    *
    * Returns true if successful
    */
   bool saveData( );
   
   /**
    * Called, when the contents have to be checked.
    *
    * Display an error message and return false, if the data is invalid.
    * Otherwise return isDataValid( ) of the base class.
    */
   virtual bool isDataValid( ) { return true; }
   
   /**
    * Returns the help topic
    */
   const TQString& helpTopic( ) { return m_helpTopic; }

   /**
    * Discards changes and redisplays the object
    */
   void redisplay( );
   
   /**
    * Called when the control point selection has changed
    */
   virtual void updateControlPointSelection( ) { };

   /**
    * Sets the check box to state s
    */
   static void setCheckBox( TQCheckBox* box, PMThreeState s );
   /**
    * Gets the state of the checkbox
    */
   static PMThreeState checkBoxState( TQCheckBox* box );

   /**
    * Sets the part
    */
   void setPart( PMPart* p ) { m_pPart = p; }
   /**
    * Returns the part
    */
   PMPart* part( ) const { return m_pPart; }

   /**
    * Returns the size of the texture preview widget
    */
   static int previewSize( ) { return s_previewSize; }
   /**
    * Sets the texture preview size
    */
   static void setPreviewSize( int size );
   /**
    * Returns true if a sphere should be renderend
    */
   static bool previewShowSphere( ) { return s_showSphere; }
   /**
    * Enable/disable the sphere in the texture preview widget
    */
   static void previewShowSphere( bool show ) { s_showSphere = show; }
   /**
    * Returns true if a cylinder should be renderend
    */
   static bool previewShowCylinder( ) { return s_showCylinder; }
   /**
    * Enable/disable the cylinder in the texture preview widget
    */
   static void previewShowCylinder( bool show ) { s_showCylinder = show; }
   /**
    * Returns true if a box should be renderend
    */
   static bool previewShowBox( ) { return s_showBox; }
   /**
    * Enable/disable the box in the texture preview widget
    */
   static void previewShowBox( bool show ) { s_showBox = show; }

   /**
    * Returns true if AA is enabled
    */
   static bool isPreviewAAEnabled( ) { return s_previewAA; }
   /**
    * Enables/disables AA
    */
   static void setPreviewAAEnabled( bool enable ) { s_previewAA = enable; }
   /**
    * Returns the AA depth
    */
   static int previewAADepth( ) { return s_previewAADepth; }
   /**
    * Sets the AA depth
    */
   static void setPreviewAADepth( int d );
   /**
    * Returns the AA threshold
    */
   static double previewAAThreshold( ) { return s_previewAAThreshold; }
   /**
    * Sets the AA threshold
    */
   static void setPreviewAAThreshold( double t ) { s_previewAAThreshold = t; }
   
   /**
    * Returns true if the floor should be rendered
    */
   static bool previewShowFloor( ) { return s_showFloor; }
   /**
    * Enables/disables the floor
    */
   static void previewShowFloor( bool show ) { s_showFloor = show; }
   /**
    * Returns true if the wall should be rendered
    */
   static bool previewShowWall( ) { return s_showWall; }
   /**
    * Enables/disables the wall
    */
   static void previewShowWall( bool show ) { s_showWall = show; }
   /**
    * Returns the first wall color
    */
   static TQColor previewWallColor1( ) { return s_wallColor1; }
   /**
    * Sets the first wall color
    */
   static void setPreviewWallColor1( const TQColor& c ) { s_wallColor1 = c; }
   /**
    * Returns the second wall color
    */
   static TQColor previewWallColor2( ) { return s_wallColor2; }
   /**
    * Sets the second wall color
    */
   static void setPreviewWallColor2( const TQColor& c ) { s_wallColor2 = c; }
   /**
    * Returns the first floor color
    */
   static TQColor previewFloorColor1( ) { return s_floorColor1; }
   /**
    * Sets the first floor color
    */
   static void setPreviewFloorColor1( const TQColor& c ) { s_floorColor1 = c; }
   /**
    * Returns the second floor color
    */
   static TQColor previewFloorColor2( ) { return s_floorColor2; }
   /**
    * Sets the second floor color
    */
   static void setPreviewFloorColor2( const TQColor& c ) { s_floorColor2 = c; }
   /**
    * Returns the local flag for texture preview
    */
   static bool previewLocal( ) { return s_previewLocal; }
   /**
    * Sets the local flag
    */
   static void setPreviewLocal( bool l ) { s_previewLocal = l; }
   /**
    * Returns the gamma value for the texture preview
    */
   static double previewGamma( ) { return s_previewGamma; }
   /**
    * Sets the gamma value for the texture preview
    */
   static void setPreviewGamma( double g ) { s_previewGamma = g; }

   static void saveConfig( TDEConfig* cfg );
   static void restoreConfig( TDEConfig* cfg );
protected:
   /**
    * Sets the help topic
    * @param anchor Defined anchor in your docbook sources
    */
   void setHelp( const TQString& anchor );

   /**
    * Create widgets here, that should be placed on top of the widgets
    * of the sub class.
    *
    * First call the function of the base class, then create and append
    * the widgets to the top layout.
    */
   virtual void createTopWidgets( ) { };

   /**
    * Create widgets here, that should be placed under the widgets
    * of the sub class.
    *
    * First create and append the widgets to the top layout, then
    * call the function of the base class
    */
   virtual void createBottomWidgets( );
   
   /**
    * Save here the class specific data and call saveContents( )
    * of the base class
    */
   virtual void saveContents( );

   /**
    * Returns a pointer to the top layout
    */
   TQBoxLayout* topLayout( ) const { return m_pTopLayout; }

protected slots:
   void slotTexturePreview( );
   void slotPreviewLocal( bool on );
   void slotPreviewFinished( int exitStatus );
   void slotPovrayOutput( );
   
signals:
   /**
    * Emit this, if data has changed
    */
   void dataChanged( );
   /**
    * Emit this, if the size of the widget has changed
    */
   void sizeChanged( );
   /**
    * Emit this, if the control point selection has changed
    */
   void controlPointSelectionChanged( );
   /**
    * Emit this signal, before the displayed object or texture is rendered
    */
   void aboutToRender( );
private:
   void findTextures( PMObject*& global, PMObject*& local ) const;
   
   PMObject* m_pDisplayedObject;
   TQBoxLayout* m_pTopLayout;
   TQString m_helpTopic;
   PMPart* m_pPart;
   TQWidget* m_pTexturePreviewWidget;
   PMPovrayRenderWidget* m_pRenderWidget;
   PMPovrayOutputWidget* m_pOutputWidget;
   TQVBox* m_pRenderFrame;
   TQCheckBox* m_pPreviewLocalBox;
   TQPushButton* m_pPreviewButton;
   TQPushButton* m_pOutputButton;

   static int s_previewSize;
   static bool s_showSphere;
   static bool s_showCylinder;
   static bool s_showBox;
   static bool s_previewAA;
   static int s_previewAADepth;
   static double s_previewAAThreshold;
   static bool s_showFloor;
   static bool s_showWall;
   static TQColor s_wallColor1, s_wallColor2;
   static TQColor s_floorColor1, s_floorColor2;
   static bool s_previewLocal;
   static double s_previewGamma;
};


#endif