summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmglobalsettingsedit.cpp
blob: 8a29773811bf94b86c8d0a5b3c6b3bcfc7a30fd0 (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
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2002 by Luis Carvalho
    email                : lpassos@mail.telepac.pt
**************************************************************************

**************************************************************************
*                                                                        *
*  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.                                   *
*                                                                        *
**************************************************************************/


#include "pmglobalsettingsedit.h"
#include "pmglobalsettings.h"
#include "pmlineedits.h"
#include "pmcoloredit.h"

#include <qlayout.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <klocale.h>
#include <kdialog.h>
#include <kmessagebox.h>

PMGlobalSettingsEdit::PMGlobalSettingsEdit( QWidget* parent, const char* name )
      : Base( parent, name )
{
   m_pDisplayedObject = 0;
}

void PMGlobalSettingsEdit::createTopWidgets( )
{
   QHBoxLayout* hl;
   QLabel* lbl;

   Base::createTopWidgets( );

   hl = new QHBoxLayout( topLayout( ) );
   lbl = new QLabel( i18n( "Adc bailout:" ), this );
   m_pAdcBailoutEdit = new PMFloatEdit( this );
   hl->addWidget( lbl );
   hl->addWidget( m_pAdcBailoutEdit );
   hl->addStretch( 1 );

   hl = new QHBoxLayout( topLayout( ) );
   lbl = new QLabel( i18n( "Ambient light:" ), this );
   m_pAmbientLightEdit = new PMColorEdit( false, this );
   topLayout( )->addWidget( lbl );
   topLayout( )->addWidget( m_pAmbientLightEdit );
   hl->addStretch( 1 );

   hl = new QHBoxLayout( topLayout( ) );
   lbl = new QLabel( i18n( "Assumed gamma:" ), this );
   m_pAssumedGammaEdit = new PMFloatEdit( this );
   hl->addWidget( lbl );
   hl->addWidget( m_pAssumedGammaEdit );
   hl->addStretch( 1 );

   m_pHfGray16Edit = new QCheckBox( i18n( "Hf gray 16" ), this );
   topLayout( )->addWidget( m_pHfGray16Edit );

   hl = new QHBoxLayout( topLayout( ) );
   lbl = new QLabel( i18n( "Iridiscence wave length:" ), this );
   m_pIridWaveLengthEdit = new PMColorEdit( false, this );
   topLayout( )->addWidget( lbl );
   topLayout( )->addWidget( m_pIridWaveLengthEdit );
   hl->addStretch( 1 );

   hl = new QHBoxLayout( topLayout( ) );
   QGridLayout* layout = new QGridLayout( hl, 4, 2 );
   lbl = new QLabel( i18n( "Maximum intersections:" ), this );
   m_pMaxIntersectionsEdit = new PMIntEdit( this );
   layout->addWidget( lbl, 0, 0 );
   layout->addWidget( m_pMaxIntersectionsEdit, 0, 1 );
   lbl = new QLabel( i18n( "Maximum trace level:" ), this );
   m_pMaxTraceLevelEdit = new PMIntEdit( this );
   layout->addWidget( lbl, 1, 0 );
   layout->addWidget( m_pMaxTraceLevelEdit, 1, 1 );
   lbl = new QLabel( i18n( "Number of waves:" ), this );
   m_pNumberWavesEdit = new PMIntEdit( this );
   layout->addWidget( lbl, 2, 0 );
   layout->addWidget( m_pNumberWavesEdit, 2, 1 );
   lbl = new QLabel( i18n( "Noise generator:" ), this );
   m_pNoiseGeneratorEdit = new QComboBox( false, this );
   m_pNoiseGeneratorEdit->insertItem( i18n( "Original" ) );
   m_pNoiseGeneratorEdit->insertItem( i18n( "Range Corrected" ) );
   m_pNoiseGeneratorEdit->insertItem( i18n( "Perlin" ) );
   layout->addWidget( lbl, 3, 0 );
   layout->addWidget( m_pNoiseGeneratorEdit, 3, 1 );
   hl->addStretch( 1 );

   m_pRadiosityEdit = new QCheckBox( i18n( "Radiosity (Povray 3.1)" ), this );
   topLayout( )->addWidget( m_pRadiosityEdit );

   m_pRadiosityWidget = new QWidget( this );
   hl = new QHBoxLayout( m_pRadiosityWidget, 0, KDialog::spacingHint( ) );
   layout = new QGridLayout( hl, 7, 2 );
   lbl = new QLabel( i18n( "Brightness:" ), m_pRadiosityWidget );
   m_pBrightnessEdit = new PMFloatEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 0, 0 );
   layout->addWidget( m_pBrightnessEdit, 0, 1 );
   lbl = new QLabel( i18n( "Count:" ), m_pRadiosityWidget );
   m_pCountEdit = new PMIntEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 1, 0 );
   layout->addWidget( m_pCountEdit, 1, 1 );
   lbl = new QLabel( i18n( "Maximum distance:" ), m_pRadiosityWidget );
   m_pDistanceMaximumEdit = new PMFloatEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 2, 0 );
   layout->addWidget( m_pDistanceMaximumEdit, 2, 1 );
   lbl = new QLabel( i18n( "Error boundary:" ), m_pRadiosityWidget );
   m_pErrorBoundEdit = new PMFloatEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 3, 0 );
   layout->addWidget( m_pErrorBoundEdit, 3, 1 );
   lbl = new QLabel( i18n( "Gray threshold:" ), m_pRadiosityWidget );
   m_pGrayThresholdEdit = new PMFloatEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 4, 0 );
   layout->addWidget( m_pGrayThresholdEdit, 4, 1 );
   lbl = new QLabel( i18n( "Low error factor:" ), m_pRadiosityWidget );
   m_pLowErrorFactorEdit = new PMFloatEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 5, 0 );
   layout->addWidget( m_pLowErrorFactorEdit, 5, 1 );
   lbl = new QLabel( i18n( "Minimum reuse:" ), m_pRadiosityWidget );
   m_pMinimumReuseEdit = new PMFloatEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 6, 0 );
   layout->addWidget( m_pMinimumReuseEdit, 6, 1 );
   lbl = new QLabel( i18n( "Nearest count:" ), m_pRadiosityWidget );
   m_pNearestCountEdit = new PMIntEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 7, 0 );
   layout->addWidget( m_pNearestCountEdit, 7, 1 );
   lbl = new QLabel( i18n( "Recursion limit:" ), m_pRadiosityWidget );
   m_pRecursionLimitEdit = new PMIntEdit( m_pRadiosityWidget );
   layout->addWidget( lbl, 8, 0 );
   layout->addWidget( m_pRecursionLimitEdit, 8, 1 );
   hl->addStretch( 1 );

   topLayout( )->addWidget( m_pRadiosityWidget );

   connect( m_pAdcBailoutEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pAmbientLightEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pAssumedGammaEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pHfGray16Edit, SIGNAL( clicked( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pIridWaveLengthEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pMaxIntersectionsEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pMaxTraceLevelEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pNumberWavesEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pNoiseGeneratorEdit, SIGNAL( activated( int ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pRadiosityEdit, SIGNAL( clicked( ) ), SLOT( slotRadiosityClicked( ) ) );
   connect( m_pBrightnessEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pCountEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pDistanceMaximumEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pErrorBoundEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pGrayThresholdEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pLowErrorFactorEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pMinimumReuseEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pNearestCountEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   connect( m_pRecursionLimitEdit, SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
}

void PMGlobalSettingsEdit::displayObject( PMObject* o )
{
   if( o->isA( "GlobalSettings" ) )
   {
      bool readOnly =  o->isReadOnly( );
      m_pDisplayedObject = ( PMGlobalSettings* ) o;

      m_pAdcBailoutEdit->setValue( m_pDisplayedObject->adcBailout( ) );
      m_pAdcBailoutEdit->setReadOnly( readOnly );
      m_pAmbientLightEdit->setColor( m_pDisplayedObject->ambientLight( ) );
      m_pAmbientLightEdit->setReadOnly( readOnly );
      m_pAssumedGammaEdit->setValue( m_pDisplayedObject->assumedGamma( ) );
      m_pAssumedGammaEdit->setReadOnly( readOnly );
      m_pHfGray16Edit->setChecked( m_pDisplayedObject->hfGray16( ) );
      m_pHfGray16Edit->setEnabled( !readOnly );
      m_pIridWaveLengthEdit->setColor( m_pDisplayedObject->iridWaveLength( ) );
      m_pIridWaveLengthEdit->setReadOnly( readOnly );
      m_pMaxIntersectionsEdit->setValue( m_pDisplayedObject->maxIntersections( ) );
      m_pMaxIntersectionsEdit->setReadOnly( readOnly );
      m_pMaxTraceLevelEdit->setValue( m_pDisplayedObject->maxTraceLevel( ) );
      m_pMaxTraceLevelEdit->setReadOnly( readOnly );
      m_pNumberWavesEdit->setValue( m_pDisplayedObject->numberWaves( ) );
      m_pNumberWavesEdit->setReadOnly( readOnly );
      m_pNoiseGeneratorEdit->setCurrentItem( m_pDisplayedObject->noiseGenerator( ) );
      m_pNoiseGeneratorEdit->setEnabled( !readOnly );
      m_pRadiosityEdit->setChecked( m_pDisplayedObject->isRadiosityEnabled( ) );
      m_pRadiosityEdit->setEnabled( !readOnly );
      m_pBrightnessEdit->setValue( m_pDisplayedObject->brightness( ) );
      m_pBrightnessEdit->setReadOnly( readOnly );
      m_pCountEdit->setValue( m_pDisplayedObject->count( ) );
      m_pCountEdit->setReadOnly( readOnly );
      m_pDistanceMaximumEdit->setValue( m_pDisplayedObject->distanceMaximum( ) );
      m_pDistanceMaximumEdit->setReadOnly( readOnly );
      m_pErrorBoundEdit->setValue( m_pDisplayedObject->errorBound( ) );
      m_pErrorBoundEdit->setReadOnly( readOnly );
      m_pGrayThresholdEdit->setValue( m_pDisplayedObject->grayThreshold( ) );
      m_pGrayThresholdEdit->setReadOnly( readOnly );
      m_pLowErrorFactorEdit->setValue( m_pDisplayedObject->lowErrorFactor( ) );
      m_pLowErrorFactorEdit->setReadOnly( readOnly );
      m_pMinimumReuseEdit->setValue( m_pDisplayedObject->minimumReuse( ) );
      m_pMinimumReuseEdit->setReadOnly( readOnly );
      m_pNearestCountEdit->setValue( m_pDisplayedObject->nearestCount( ) );
      m_pNearestCountEdit->setReadOnly( readOnly );
      m_pRecursionLimitEdit->setValue( m_pDisplayedObject->recursionLimit( ) );
      m_pRecursionLimitEdit->setReadOnly( readOnly );
      slotRadiosityClicked( );

      Base::displayObject( o );
   }
   else
      kdError( PMArea ) << "PMGlobalSettingsEdit: Can't display object\n";
}

void PMGlobalSettingsEdit::saveContents( )
{
   if( m_pDisplayedObject )
   {
      Base::saveContents( );
      m_pDisplayedObject->setAdcBailout( m_pAdcBailoutEdit->value( ) );
      m_pDisplayedObject->setAmbientLight( m_pAmbientLightEdit->color( ) );
      m_pDisplayedObject->setAssumedGamma( m_pAssumedGammaEdit->value( ) );
      m_pDisplayedObject->setHfGray16( m_pHfGray16Edit->isChecked( ) );
      m_pDisplayedObject->setIridWaveLength( m_pIridWaveLengthEdit->color( ) );
      m_pDisplayedObject->setMaxIntersections( m_pMaxIntersectionsEdit->value( ) );
      m_pDisplayedObject->setMaxTraceLevel( m_pMaxTraceLevelEdit->value( ) );
      m_pDisplayedObject->setNumberWaves( m_pNumberWavesEdit->value( ) );
      m_pDisplayedObject->setNoiseGenerator(
         ( PMGlobalSettings::PMNoiseType ) ( m_pNoiseGeneratorEdit->currentItem( ) ) );
      m_pDisplayedObject->enableRadiosity( m_pRadiosityEdit->isChecked( ) );
      m_pDisplayedObject->setBrightness( m_pBrightnessEdit->value( ) );
      m_pDisplayedObject->setCount( m_pCountEdit->value( ) );
      m_pDisplayedObject->setDistanceMaximum( m_pDistanceMaximumEdit->value( ) );
      m_pDisplayedObject->setErrorBound( m_pErrorBoundEdit->value( ) );
      m_pDisplayedObject->setGrayThreshold( m_pGrayThresholdEdit->value( ) );
      m_pDisplayedObject->setLowErrorFactor( m_pLowErrorFactorEdit->value( ) );
      m_pDisplayedObject->setMinimumReuse( m_pMinimumReuseEdit->value( ) );
      m_pDisplayedObject->setNearestCount( m_pNearestCountEdit->value( ) );
      m_pDisplayedObject->setRecursionLimit( m_pRecursionLimitEdit->value( ) );
   }
}

bool PMGlobalSettingsEdit::isDataValid( )
{
   if( !m_pAdcBailoutEdit->isDataValid( ) ) return false;
   if( !m_pAmbientLightEdit->isDataValid( ) ) return false;
   if( !m_pAssumedGammaEdit->isDataValid( ) ) return false;
   if( !m_pIridWaveLengthEdit->isDataValid( ) ) return false;
   if( !m_pMaxIntersectionsEdit->isDataValid( ) ) return false;
   if( !m_pMaxTraceLevelEdit->isDataValid( ) ) return false;
   if( !m_pNumberWavesEdit->isDataValid( ) ) return false;
   if( !m_pBrightnessEdit->isDataValid( ) ) return false;
   if( !m_pCountEdit->isDataValid( ) ) return false;
   if( !m_pDistanceMaximumEdit->isDataValid( ) ) return false;
   if( !m_pErrorBoundEdit->isDataValid( ) ) return false;
   if( !m_pGrayThresholdEdit->isDataValid( ) ) return false;
   if( !m_pLowErrorFactorEdit->isDataValid( ) ) return false;
   if( !m_pMinimumReuseEdit->isDataValid( ) ) return false;
   if( !m_pNearestCountEdit->isDataValid( ) ) return false;
   if( !m_pRecursionLimitEdit->isDataValid( ) ) return false;

   if( m_pMaxIntersectionsEdit->value( ) < 0 )
   {
      KMessageBox::error( this, i18n( "Maximum intersections must be a positive value." ),
                          i18n( "Error" ) );
      m_pMaxIntersectionsEdit->setFocus( );
      return false;
   }
   if( m_pMaxTraceLevelEdit->value( ) < 0 )
   {
      KMessageBox::error( this, i18n( "Maximum trace level must be a positive value." ),
                          i18n( "Error" ) );
      m_pMaxTraceLevelEdit->setFocus( );
      return false;
   }
   if( m_pNumberWavesEdit->value( ) < 0 )
   {
      KMessageBox::error( this, i18n( "Number of waves must be a positive value." ),
                          i18n( "Error" ) );
      m_pNumberWavesEdit->setFocus( );
      return false;
   }
   if( m_pNearestCountEdit->value( ) < 1 || m_pNearestCountEdit->value( ) > 10 )
   {
      KMessageBox::error( this, i18n( "Nearest count must be between 1 and 10." ),
                          i18n( "Error" ) );
      m_pNearestCountEdit->setFocus( );
      return false;
   }

   if( m_pRecursionLimitEdit->value( ) < 1 || m_pRecursionLimitEdit->value( ) > 2 )
   {
      KMessageBox::error( this, i18n( "Recursion limit must be 1 or 2." ),
                          i18n( "Error" ) );
      m_pRecursionLimitEdit->setFocus( );
      return false;
   }

   return Base::isDataValid( );
}

void PMGlobalSettingsEdit::slotRadiosityClicked( )
{
   if( m_pRadiosityEdit->isChecked( ) ) 
      m_pRadiosityWidget->show( );
   else 
      m_pRadiosityWidget->hide( );

   emit dataChanged( );
   emit sizeChanged( );
}

#include "pmglobalsettingsedit.moc"