summaryrefslogtreecommitdiffstats
path: root/src/gui/pieditor.cpp
blob: 7ca2663f6a52a824cc43c138b21561b67d6fdd3c (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
/***************************************************************************
 *   Copyright (C) 2003-2004 by David Saxton                               *
 *   david@bluehaze.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 "colorcombo.h"
#include "doublespinbox.h"
#include "pieditor.h"
#include "variant.h"

#include <kcombobox.h>
#include <klineedit.h>
#include <klocale.h>
#include <knuminput.h>
#include <kurlrequester.h>
#include <tqlayout.h>

//BEGIN class PIEditor
PIEditor::PIEditor(TQString id, Variant *data, TQWidget *tqparent, const char *name)
 : TQWidget(tqparent, name)
{
	m_id = id;
	m_data = data;
	connect(m_data,TQT_SIGNAL(valueChanged(TQVariant, TQVariant )),this,TQT_SLOT(valueChanged(TQVariant)));
	setFocus();
	update();
	//show();
}

PIEditor::~PIEditor()
{
}

void PIEditor::valueChanged( TQVariant /*variant*/ )
{
}
//END class PIEditor


//BEGIN class PIBool
PIBool::PIBool(TQString id, Variant *data, TQWidget *tqparent, const char *name )
	: PIEditor( id, data, tqparent, name )
{
	TQHBoxLayout *tqlayout = new TQHBoxLayout(this);
	tqlayout->setAutoAdd(true);
	
	m_comboBox = new KComboBox(this);
	m_comboBox->insertItem( i18n("True"), 0 );
	m_comboBox->insertItem( i18n("False"), 1 );
	m_comboBox->setCurrentItem( m_data->value().toBool() ? 0 : 1 );
	
	connect( m_comboBox, TQT_SIGNAL(activated(int )), this, TQT_SLOT(selectChanged(int )) );
}

PIBool::~PIBool()
{
}

void PIBool::popup()
{
	m_comboBox->popup();
}

void PIBool::selectChanged( int index )
{
	emit editorDataChanged( m_id, TQVariant( index == 0 ) );
}

void PIBool::valueChanged( TQVariant /*variant*/ )
{
	m_comboBox->setCurrentItem( m_data->value().toBool() ? 0 : 1 );
}
//END class PIBool


//BEGIN class PIColor
PIColor::PIColor(TQString id, Variant *data, TQWidget *tqparent, const char *name )
	: PIEditor(id,data,tqparent, name)
{
	TQHBoxLayout *tqlayout = new TQHBoxLayout(this);
	tqlayout->setAutoAdd(true);
	
	m_combo = new ColorCombo( (ColorCombo::ColorScheme)m_data->colorScheme(), this );
	m_combo->setColor(m_data->value().toColor());
	
	connect(m_combo,TQT_SIGNAL(activated(const TQColor&)),this,TQT_SLOT(colorChanged(const TQColor&)));
// 	connect(m_combo,TQT_SIGNAL(highlighted(const TQColor&)),this,TQT_SLOT(colorChanged(const TQColor&)));
}

PIColor::~PIColor()
{
}

void PIColor::popup()
{
	m_combo->popup();
}

void PIColor::colorChanged(const TQColor &col)
{
	emit editorDataChanged(m_id,TQVariant(col));
}

void PIColor::valueChanged( TQVariant /*variant*/ )
{
	m_combo->setColor(m_data->value().toColor());
}
//END class PIColor


//BEGIN class PIDouble
PIDouble::PIDouble(TQString id, Variant *data, TQWidget *tqparent, const char *name )
	: PIEditor(id,data,tqparent, name)
{
	TQHBoxLayout *tqlayout = new TQHBoxLayout(this);
	tqlayout->setAutoAdd(true);
	
	spin = new DoubleSpinBox(m_data->minValue(),m_data->maxValue(),m_data->minAbsValue(),m_data->value().toDouble(),m_data->unit(),this);
	
	connect(spin,TQT_SIGNAL(valueChanged(double)),this,TQT_SLOT(spinValueChanged(double)));
}

PIDouble::~PIDouble()
{
}

void PIDouble::spinValueChanged(double value)
{
	emit editorDataChanged(m_id,TQVariant(value));
}

void PIDouble::valueChanged( TQVariant /*variant*/ )
{
	spin->setValue(m_data->value().toDouble());
}
//END class PIDouble


//BEGIN class PIFileName
PIFilename::PIFilename(TQString id, Variant *data, TQWidget *tqparent, const char *name )
	: PIEditor(id,data,tqparent, name)
{
	TQHBoxLayout *tqlayout = new TQHBoxLayout(this);
	tqlayout->setAutoAdd(true);
	
	m_combo = 0L;
	if( m_data->allowed().count() == 0 )
	{
		m_combo = new KComboBox(this);
		m_combo->insertStringList( m_data->allowed() );
		m_urlreq = new KURLRequester(m_combo, this);
	}
	else m_urlreq = new KURLRequester(this);
	
	m_urlreq->setURL( m_data->value().toString() );
	m_urlreq->setFilter( m_data->filter() );
	
	connect(m_urlreq,TQT_SIGNAL(urlSelected(const TQString&)),this,TQT_SLOT(slotURLChanged(const TQString&)));
	//connect(m_urlreq,TQT_SIGNAL(openFileDialog(KURLRequester*)),this,TQT_SLOT(slotOpenFileDialog(KURLRequester* )));
}

PIFilename::~PIFilename()
{
}

void PIFilename::slotURLChanged(const TQString &url)
{
	emit editorDataChanged(m_id,TQVariant(url));
}

void PIFilename::valueChanged( TQVariant /*variant*/ )
{
	if(m_combo) m_combo->setCurrentItem( m_data->value().toString() );
	m_urlreq->setURL( m_data->value().toString() );
}

/* //FIXME Reintroduce this code if deciding not to go with dropping cod files
   onto the PIC componenent ?? */
//
// void PIFilename::slotOpenFileDialog(KURLRequester *kurlreq)
// {
// 	// If no file has been selected so far then it seems
// 	// to make most sense to open the dialog at the directory
// 	// of the current project if open.
// 	if(kurlreq->url() == m_data->defaultValue().toString() && !ProjectManager::self()->directory().isEmpty() ) kurlreq->setURL(ProjectManager::self()->directory());
// }
//END class PIFileName


//BEGIN class PIInt
PIInt::PIInt( const TQString &id, Variant *data, TQWidget *tqparent, const char *name )
	: PIEditor( id, data, tqparent, name )
{
	TQHBoxLayout *tqlayout = new TQHBoxLayout(this);
	tqlayout->setAutoAdd(true);
	
	spin = new KIntSpinBox( (int)m_data->minValue(), (int)m_data->maxValue(), 1, m_data->value().toInt(), 10, this );
	
	connect( spin, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(spinValueChanged(int)));
}

PIInt::~PIInt()
{
}

void PIInt::spinValueChanged( int value )
{
	emit editorDataChanged( m_id, TQVariant(value) );
}

void PIInt::valueChanged( TQVariant /*variant*/ )
{
	spin->setValue( m_data->value().toInt() );
}
//END class PIInt


//BEGIN class PILineEdit
PILineEdit::PILineEdit(TQString id, Variant *data, TQWidget *tqparent, const char *name)
	: PIEditor( id, data, tqparent, name)
{
	TQHBoxLayout *tqlayout = new TQHBoxLayout(this);
	tqlayout->setAutoAdd(true);
	m_edit = new KLineEdit( m_data->value().toString() , this );
	connect(m_edit,TQT_SIGNAL(textChanged(const TQString&)),this,TQT_SLOT(slotEditTextChanged()));
}


PILineEdit::~PILineEdit()
{
}

void PILineEdit::slotEditTextChanged()
{
	emit editorDataChanged(m_id,TQVariant(m_edit->text()));
}

void PILineEdit::valueChanged( TQVariant /*variant*/ )
{
	m_edit->setText(m_data->value().toString());
}
//END class PILineEdit


//BEGIN class PIStringCombo
PIStringCombo::PIStringCombo(TQString id, Variant *data, TQWidget *tqparent, const char *name)
	: PIEditor( id, data, tqparent, name)
{
	TQHBoxLayout *tqlayout = new TQHBoxLayout(this);
	tqlayout->setAutoAdd(true);
	
	m_combo = new KComboBox( this );
	m_combo->insertStringList(m_data->allowed());
	m_combo->setCurrentItem(m_data->value().toString());
	const Variant::Type::Value type = m_data->type();
	m_combo->setEditable( type == Variant::Type::Combo ||
			type == Variant::Type::FileName || 
			type == Variant::Type::VarName );
	
	connect(m_combo,TQT_SIGNAL(highlighted(const TQString&)),this,TQT_SLOT(slotComboChanged()));
	connect(m_combo,TQT_SIGNAL(activated(const TQString&)),this,TQT_SLOT(slotComboChanged()));
}


PIStringCombo::~PIStringCombo()
{
}

void PIStringCombo::popup()
{
	m_combo->popup();
}

void PIStringCombo::slotComboChanged()
{
	emit editorDataChanged(m_id,TQVariant(m_combo->currentText()));
}

void PIStringCombo::valueChanged( TQVariant /*variant*/ )
{
	m_combo->setCurrentItem(m_data->value().toString());
}
//END class PIStringCombo




#include "pieditor.moc"