summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmpreviewsettings.cpp
blob: 54afb0dd4bbdf6face2029915799a1c8e4b8a4cf (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
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2003 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.                                   *
*                                                                        *
**************************************************************************/

#include "pmpreviewsettings.h"

#include "pmlineedits.h"
#include "pmdialogeditbase.h"
#include "pmdefaults.h"

#include <tqlayout.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <kcolorbutton.h>
#include <klocale.h>
#include <kmessagebox.h>

PMPreviewSettings::PMPreviewSettings( TQWidget* tqparent, const char* name )
      : PMSettingsDialogPage( tqparent, name )
{
   TQHBoxLayout* htqlayout;
   TQVBoxLayout* vtqlayout;
   TQVBoxLayout* gvl;
   TQGridLayout* grid;
   TQGroupBox* gb;

   vtqlayout = new TQVBoxLayout( this, 0, KDialog::spacingHint( ) );
   
   htqlayout = new TQHBoxLayout( vtqlayout );
   grid = new TQGridLayout( htqlayout, 2, 2 );
   grid->addWidget( new TQLabel( i18n( "Size:" ), this ), 0, 0 );
   m_pPreviewSize = new PMIntEdit( this );
   m_pPreviewSize->setValidation( true, 10, true, 400 );
   grid->addWidget( m_pPreviewSize, 0, 1 );

   grid->addWidget( new TQLabel( i18n( "Gamma:" ), this ), 1, 0 );
   m_pPreviewGamma = new PMFloatEdit( this );
   grid->addWidget( m_pPreviewGamma, 1, 1 );
   htqlayout->addStretch( 1 );

   gb = new TQGroupBox( i18n( "Rendered Objects" ), this );
   vtqlayout->addWidget( gb );
   gvl = new TQVBoxLayout( gb, KDialog::marginHint( ), KDialog::spacingHint( ) );
   gvl->addSpacing( 10 );
   m_pPreviewSphere = new TQCheckBox( i18n( "Sphere" ), gb );
   gvl->addWidget( m_pPreviewSphere );
   m_pPreviewCylinder = new TQCheckBox( i18n( "Cylinder" ), gb );
   gvl->addWidget( m_pPreviewCylinder );
   m_pPreviewBox = new TQCheckBox( i18n( "Box" ), gb );
   gvl->addWidget( m_pPreviewBox );

   gb = new TQGroupBox( i18n( "Wall" ), this );
   vtqlayout->addWidget( gb );
   gvl = new TQVBoxLayout( gb, KDialog::marginHint( ), KDialog::spacingHint( ) );
   gvl->addSpacing( 10 );
   m_pPreviewWall = new TQCheckBox( i18n( "Enable wall" ), gb );
   gvl->addWidget( m_pPreviewWall );
   htqlayout = new TQHBoxLayout( gvl );
   htqlayout->addWidget( new TQLabel( i18n( "Color 1:" ), gb ) );
   m_pWallColor1 = new KColorButton( gb );
   htqlayout->addWidget( m_pWallColor1 );
   htqlayout->addWidget( new TQLabel( i18n( "Color 2:" ), gb ) );
   m_pWallColor2 = new KColorButton( gb );
   htqlayout->addWidget( m_pWallColor2 );
   htqlayout->addStretch( 1 );

   gb = new TQGroupBox( i18n( "Floor" ), this );
   vtqlayout->addWidget( gb );
   gvl = new TQVBoxLayout( gb, KDialog::marginHint( ), KDialog::spacingHint( ) );
   gvl->addSpacing( 10 );
   m_pPreviewFloor = new TQCheckBox( i18n( "Enable floor" ), gb );
   gvl->addWidget( m_pPreviewFloor );
   htqlayout = new TQHBoxLayout( gvl );
   htqlayout->addWidget( new TQLabel( i18n( "Color 1:" ), gb ) );
   m_pFloorColor1 = new KColorButton( gb );
   htqlayout->addWidget( m_pFloorColor1 );
   htqlayout->addWidget( new TQLabel( i18n( "Color 2:" ), gb ) );
   m_pFloorColor2 = new KColorButton( gb );
   htqlayout->addWidget( m_pFloorColor2 );
   htqlayout->addStretch( 1 );

   gb = new TQGroupBox( i18n( "Antialiasing" ), this );
   vtqlayout->addWidget( gb );
   gvl = new TQVBoxLayout( gb, KDialog::marginHint( ), KDialog::spacingHint( ) );
   gvl->addSpacing( 10 );
   m_pPreviewAA = new TQCheckBox( i18n( "Enable antialiasing" ), gb );
   gvl->addWidget( m_pPreviewAA );
   htqlayout = new TQHBoxLayout( gvl );
   htqlayout->addWidget( new TQLabel( i18n( "Depth:" ), gb ) );
   m_pPreviewAALevel = new PMIntEdit( gb );
   m_pPreviewAALevel->setValidation( true, 1, true, 9 );
   htqlayout->addWidget( m_pPreviewAALevel );
   htqlayout->addWidget( new TQLabel( i18n( "Threshold:" ), gb ) );
   m_pPreviewAAThreshold = new PMFloatEdit( gb );
   htqlayout->addWidget( m_pPreviewAAThreshold );
   htqlayout->addStretch( 1 );
   
   vtqlayout->addStretch( 1 );
}

void PMPreviewSettings::displaySettings( )
{
   m_pPreviewSize->setValue( PMDialogEditBase::previewSize( ) );
   m_pPreviewGamma->setValue( PMDialogEditBase::previewGamma( ) );
   m_pPreviewSphere->setChecked( PMDialogEditBase::previewShowSphere( ) );
   m_pPreviewCylinder->setChecked( PMDialogEditBase::previewShowCylinder( ) );
   m_pPreviewBox->setChecked( PMDialogEditBase::previewShowBox( ) );
   m_pPreviewAA->setChecked( PMDialogEditBase::isPreviewAAEnabled( ) );
   m_pPreviewAALevel->setValue( PMDialogEditBase::previewAADepth( ) );
   m_pPreviewAAThreshold->setValue( PMDialogEditBase::previewAAThreshold( ) );
   m_pPreviewWall->setChecked( PMDialogEditBase::previewShowWall( ) );
   m_pPreviewFloor->setChecked( PMDialogEditBase::previewShowFloor( ) );
   m_pFloorColor1->setColor( PMDialogEditBase::previewFloorColor1( ) );
   m_pFloorColor2->setColor( PMDialogEditBase::previewFloorColor2( ) );
   m_pWallColor1->setColor( PMDialogEditBase::previewWallColor1( ) );
   m_pWallColor2->setColor( PMDialogEditBase::previewWallColor2( ) );
}

void PMPreviewSettings::displayDefaults( )
{
   m_pPreviewSize->setValue( c_defaultTPSize );
   m_pPreviewGamma->setValue( c_defaultTPGamma );
   m_pPreviewSphere->setChecked( c_defaultTPShowSphere );
   m_pPreviewCylinder->setChecked( c_defaultTPShowCylinder );
   m_pPreviewBox->setChecked( c_defaultTPShowBox );
   m_pPreviewAA->setChecked( c_defaultTPAA );
   m_pPreviewAALevel->setValue( c_defaultTPAADepth );
   m_pPreviewAAThreshold->setValue( c_defaultTPAAThreshold );
   m_pPreviewWall->setChecked( c_defaultTPShowWall );
   m_pPreviewFloor->setChecked( c_defaultTPShowFloor );
   m_pFloorColor1->setColor( c_defaultTPFloorColor1 );
   m_pFloorColor2->setColor( c_defaultTPFloorColor2 );
   m_pWallColor1->setColor( c_defaultTPWallColor1 );
   m_pWallColor2->setColor( c_defaultTPWallColor2 );
}

bool PMPreviewSettings::validateData( )
{
   if( !m_pPreviewSize->isDataValid( ) )
   {
      emit showMe( );
      m_pPreviewSize->setFocus( );
      return false;
   }
   if( !m_pPreviewGamma->isDataValid( ) )
   {
      emit showMe( );
      m_pPreviewGamma->setFocus( );
      return false;
   }
   if( !m_pPreviewAALevel->isDataValid( ) )
   {
      emit showMe( );
      m_pPreviewAALevel->setFocus( );
      return false;
   }
   if( !m_pPreviewAAThreshold->isDataValid( ) )
   {
      emit showMe( );
      m_pPreviewAAThreshold->setFocus( );
      return false;
   }
   if( !( m_pPreviewSphere->isChecked( ) || m_pPreviewCylinder->isChecked( )
          || m_pPreviewBox->isChecked( ) ) )
   {
      emit showMe( );
      KMessageBox::error( this, i18n( "At least one object has to be selected." ),
                          i18n( "Error" ) );
  
      return false;
   }
   return true;
}

void PMPreviewSettings::applySettings( )
{
   PMDialogEditBase::setPreviewSize( m_pPreviewSize->value( ) );
   PMDialogEditBase::setPreviewGamma( m_pPreviewGamma->value( ) );
   PMDialogEditBase::previewShowSphere( m_pPreviewSphere->isChecked( ) );
   PMDialogEditBase::previewShowCylinder( m_pPreviewCylinder->isChecked( ) );
   PMDialogEditBase::previewShowBox( m_pPreviewBox->isChecked( ) );
   PMDialogEditBase::setPreviewAAEnabled( m_pPreviewAA->isChecked( ) );
   PMDialogEditBase::setPreviewAADepth( m_pPreviewAALevel->value( ) );
   PMDialogEditBase::setPreviewAAThreshold( m_pPreviewAAThreshold->value( ) );
   PMDialogEditBase::previewShowFloor( m_pPreviewFloor->isChecked( ) );
   PMDialogEditBase::previewShowWall( m_pPreviewWall->isChecked( ) );
   PMDialogEditBase::setPreviewWallColor1( m_pWallColor1->color( ) );
   PMDialogEditBase::setPreviewWallColor2( m_pWallColor2->color( ) );
   PMDialogEditBase::setPreviewFloorColor1( m_pFloorColor1->color( ) );
   PMDialogEditBase::setPreviewFloorColor2( m_pFloorColor2->color( ) );
}

#include "pmpreviewsettings.moc"