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
|
/*
**************************************************************************
description
--------------------
copyright : (C) 2002 by Andreas Zehender
email : [email protected]
**************************************************************************
**************************************************************************
* *
* 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 "pmheightfieldedit.h"
#include "pmheightfield.h"
#include "pmlineedits.h"
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqslider.h>
#include <klocale.h>
#include <kiconloader.h>
#include <tdefiledialog.h>
PMHeightFieldEdit::PMHeightFieldEdit( TQWidget* parent, const char* name )
: Base( parent, name )
{
m_pDisplayedObject = 0;
}
void PMHeightFieldEdit::createTopWidgets( )
{
Base::createTopWidgets( );
TQHBoxLayout* hl = new TQHBoxLayout( topLayout( ) );
hl->addWidget( new TQLabel( i18n( "Type:" ), this ) );
m_pHeightFieldType = new TQComboBox( false, this );
hl->addWidget( m_pHeightFieldType );
hl->addStretch( 0 );
m_pHeightFieldType->insertItem( "gif" );
m_pHeightFieldType->insertItem( "tga" );
m_pHeightFieldType->insertItem( "pot" );
m_pHeightFieldType->insertItem( "png" );
m_pHeightFieldType->insertItem( "pgm" );
m_pHeightFieldType->insertItem( "ppm" );
m_pHeightFieldType->insertItem( "sys" );
hl = new TQHBoxLayout( topLayout( ) );
hl->addWidget( new TQLabel( i18n( "File name:" ), this ) );
m_pFileName = new TQLineEdit( this );
hl->addWidget( m_pFileName );
m_pChooseFileName = new TQPushButton( this );
m_pChooseFileName->setPixmap( SmallIcon( "fileopen" ) );
hl->addWidget( m_pChooseFileName );
hl = new TQHBoxLayout( topLayout( ) );
hl->addWidget( new TQLabel( i18n( "Water level:" ), this ) );
m_pWaterLevel = new PMFloatEdit( this );
m_pWaterLevel->setValidation( true, 0.0, true, 1.0 );
hl->addWidget( m_pWaterLevel );
hl->addStretch( 1 );
m_pHierarchy = new TQCheckBox( i18n( "Hierarchy" ), this );
topLayout( )->addWidget( m_pHierarchy );
m_pSmooth = new TQCheckBox( i18n( "Smooth" ), this );
topLayout( )->addWidget( m_pSmooth );
connect( m_pHeightFieldType, TQT_SIGNAL( activated( int ) ),
TQT_SLOT( slotTypeChanged( int ) ) );
connect( m_pFileName, TQT_SIGNAL( textChanged( const TQString& ) ),
TQT_SLOT( slotFileNameChanged( const TQString& ) ) );
connect( m_pChooseFileName, TQT_SIGNAL( clicked( ) ),
TQT_SLOT( slotFileNameClicked( ) ) );
connect( m_pWaterLevel, TQT_SIGNAL( dataChanged( ) ), TQT_SIGNAL( dataChanged( ) ) );
connect( m_pHierarchy, TQT_SIGNAL( clicked( ) ), TQT_SIGNAL( dataChanged( ) ) );
connect( m_pSmooth, TQT_SIGNAL( clicked( ) ), TQT_SIGNAL( dataChanged( ) ) );
}
void PMHeightFieldEdit::displayObject( PMObject* o )
{
if( o->isA( "HeightField" ) )
{
bool readOnly = o->isReadOnly( );
m_pDisplayedObject = ( PMHeightField* ) o;
switch( m_pDisplayedObject->heightFieldType( ) )
{
case PMHeightField::HFgif:
m_pHeightFieldType->setCurrentItem( 0 );
break;
case PMHeightField::HFtga:
m_pHeightFieldType->setCurrentItem( 1 );
break;
case PMHeightField::HFpot:
m_pHeightFieldType->setCurrentItem( 2 );
break;
case PMHeightField::HFpng:
m_pHeightFieldType->setCurrentItem( 3 );
break;
case PMHeightField::HFpgm:
m_pHeightFieldType->setCurrentItem( 4 );
break;
case PMHeightField::HFppm:
m_pHeightFieldType->setCurrentItem( 5 );
break;
case PMHeightField::HFsys:
m_pHeightFieldType->setCurrentItem( 6 );
break;
}
m_pFileName->setText( m_pDisplayedObject->fileName( ) );
m_pWaterLevel->setValue( m_pDisplayedObject->waterLevel( ) );
m_pHierarchy->setChecked( m_pDisplayedObject->hierarchy( ) );
m_pSmooth->setChecked( m_pDisplayedObject->smooth( ) );
m_pHeightFieldType->setEnabled( !readOnly );
m_pFileName->setReadOnly( readOnly );
m_pChooseFileName->setEnabled( !readOnly );
m_pHierarchy->setEnabled( !readOnly );
m_pSmooth->setEnabled( !readOnly );
Base::displayObject( o );
}
else
kdError( PMArea ) << "PMHeightFieldEdit: Can't display object\n";
}
void PMHeightFieldEdit::saveContents( )
{
if( m_pDisplayedObject )
{
Base::saveContents( );
switch( m_pHeightFieldType->currentItem( ) )
{
case 0:
m_pDisplayedObject->setHeightFieldType( PMHeightField::HFgif );
break;
case 1:
m_pDisplayedObject->setHeightFieldType( PMHeightField::HFtga );
break;
case 2:
m_pDisplayedObject->setHeightFieldType( PMHeightField::HFpot );
break;
case 3:
m_pDisplayedObject->setHeightFieldType( PMHeightField::HFpng );
break;
case 4:
m_pDisplayedObject->setHeightFieldType( PMHeightField::HFpgm );
break;
case 5:
m_pDisplayedObject->setHeightFieldType( PMHeightField::HFppm );
break;
case 6:
m_pDisplayedObject->setHeightFieldType( PMHeightField::HFsys );
break;
}
m_pDisplayedObject->setFileName( m_pFileName->text( ) );
m_pDisplayedObject->setWaterLevel( m_pWaterLevel->value( ) );
m_pDisplayedObject->setHierarchy( m_pHierarchy->isChecked( ) );
m_pDisplayedObject->setSmooth( m_pSmooth->isChecked( ) );
}
}
bool PMHeightFieldEdit::isDataValid( )
{
if( m_pWaterLevel->isDataValid( ) )
return Base::isDataValid( );
return false;
}
void PMHeightFieldEdit::slotTypeChanged( int )
{
emit dataChanged( );
}
void PMHeightFieldEdit::slotFileNameChanged( const TQString& )
{
emit dataChanged( );
}
void PMHeightFieldEdit::slotFileNameClicked( )
{
TQString str = KFileDialog::getOpenFileName( TQString(), TQString() );
if( !str.isEmpty() )
{
m_pFileName->setText( str );
emit dataChanged( );
}
}
#include "pmheightfieldedit.moc"
|