summaryrefslogtreecommitdiffstats
path: root/src/gui/pieditor.cpp
blob: b7ca0e5dd30cc22b17e47cd4f15fc8b71b74d618 (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 <qlayout.h>

//BEGIN class PIEditor
PIEditor::PIEditor(QString id, Variant *data, QWidget *parent, const char *name)
 : QWidget(parent, name)
{
	m_id = id;
	m_data = data;
	connect(m_data,SIGNAL(valueChanged(QVariant, QVariant )),this,SLOT(valueChanged(QVariant)));
	setFocus();
	update();
	//show();
}

PIEditor::~PIEditor()
{
}

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


//BEGIN class PIBool
PIBool::PIBool(QString id, Variant *data, QWidget *parent, const char *name )
	: PIEditor( id, data, parent, name )
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->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, SIGNAL(activated(int )), this, SLOT(selectChanged(int )) );
}

PIBool::~PIBool()
{
}

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

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

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


//BEGIN class PIColor
PIColor::PIColor(QString id, Variant *data, QWidget *parent, const char *name )
	: PIEditor(id,data,parent, name)
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->setAutoAdd(true);
	
	m_combo = new ColorCombo( (ColorCombo::ColorScheme)m_data->colorScheme(), this );
	m_combo->setColor(m_data->value().toColor());
	
	connect(m_combo,SIGNAL(activated(const QColor&)),this,SLOT(colorChanged(const QColor&)));
// 	connect(m_combo,SIGNAL(highlighted(const QColor&)),this,SLOT(colorChanged(const QColor&)));
}

PIColor::~PIColor()
{
}

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

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

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


//BEGIN class PIDouble
PIDouble::PIDouble(QString id, Variant *data, QWidget *parent, const char *name )
	: PIEditor(id,data,parent, name)
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->setAutoAdd(true);
	
	spin = new DoubleSpinBox(m_data->minValue(),m_data->maxValue(),m_data->minAbsValue(),m_data->value().toDouble(),m_data->unit(),this);
	
	connect(spin,SIGNAL(valueChanged(double)),this,SLOT(spinValueChanged(double)));
}

PIDouble::~PIDouble()
{
}

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

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


//BEGIN class PIFileName
PIFilename::PIFilename(QString id, Variant *data, QWidget *parent, const char *name )
	: PIEditor(id,data,parent, name)
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->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,SIGNAL(urlSelected(const QString&)),this,SLOT(slotURLChanged(const QString&)));
	//connect(m_urlreq,SIGNAL(openFileDialog(KURLRequester*)),this,SLOT(slotOpenFileDialog(KURLRequester* )));
}

PIFilename::~PIFilename()
{
}

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

void PIFilename::valueChanged( QVariant /*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 QString &id, Variant *data, QWidget *parent, const char *name )
	: PIEditor( id, data, parent, name )
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->setAutoAdd(true);
	
	spin = new KIntSpinBox( (int)m_data->minValue(), (int)m_data->maxValue(), 1, m_data->value().toInt(), 10, this );
	
	connect( spin, SIGNAL(valueChanged(int)), this, SLOT(spinValueChanged(int)));
}

PIInt::~PIInt()
{
}

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

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


//BEGIN class PILineEdit
PILineEdit::PILineEdit(QString id, Variant *data, QWidget *parent, const char *name)
	: PIEditor( id, data, parent, name)
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->setAutoAdd(true);
	m_edit = new KLineEdit( m_data->value().toString() , this );
	connect(m_edit,SIGNAL(textChanged(const QString&)),this,SLOT(slotEditTextChanged()));
}


PILineEdit::~PILineEdit()
{
}

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

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


//BEGIN class PIStringCombo
PIStringCombo::PIStringCombo(QString id, Variant *data, QWidget *parent, const char *name)
	: PIEditor( id, data, parent, name)
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->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,SIGNAL(highlighted(const QString&)),this,SLOT(slotComboChanged()));
	connect(m_combo,SIGNAL(activated(const QString&)),this,SLOT(slotComboChanged()));
}


PIStringCombo::~PIStringCombo()
{
}

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

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

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




#include "pieditor.moc"