2 Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
4 This application is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 2004-01-15 INDI element is the most basic unit of the INDI KStars client.
12 #include "indielement.h"
13 #include "indiproperty.h"
14 #include "indigroup.h"
15 #include "indidevice.h"
17 #include "indi/indicom.h"
19 #include <qcheckbox.h>
28 #include <kfiledialog.h>
30 #include <ksqueezedtextlabel.h>
31 #include <klineedit.h>
32 #include <kpushbutton.h>
35 #include <kcombobox.h>
36 #include <knuminput.h>
37 #include <kdialogbase.h>
39 /* search element for attribute.
40 * return XMLAtt if find, else NULL with helpful info in errmsg.
42 XMLAtt
* findAtt (XMLEle
*ep
, const char *name
, char errmsg
[])
44 XMLAtt
*ap
= findXMLAtt (ep
, name
);
48 snprintf (errmsg
, ERRMSG_SIZE
, "INDI: <%.64s> missing attribute '%.64s'", tagXMLEle(ep
),name
);
52 /* search element for given child. pp is just to build a better errmsg.
53 * return XMLEle if find, else NULL with helpful info in errmsg.
55 XMLEle
* findEle (XMLEle
*ep
, INDI_P
*pp
, const char *child
, char errmsg
[])
57 XMLEle
*cp
= findXMLEle (ep
, child
);
61 snprintf (errmsg
, ERRMSG_SIZE
, "INDI: <%.64s %.64s %.64s> missing child '%.64s'", tagXMLEle(ep
),
62 pp
->pg
->dp
->name
.ascii(), pp
->name
.ascii(), child
);
66 /*******************************************************************
68 *******************************************************************/
69 INDI_E::INDI_E(INDI_P
*parentProperty
, QString inName
, QString inLabel
)
76 EHBox
= new QHBoxLayout(0, 0, KDialog::spacingHint());
105 void INDI_E::setupElementLabel()
107 label_w
= new KSqueezedTextLabel(pp
->pg
->propertyContainer
);
108 label_w
->setMinimumWidth(ELEMENT_LABEL_WIDTH
);
109 label_w
->setMaximumWidth(ELEMENT_LABEL_WIDTH
);
110 label_w
->setFrameShape( KSqueezedTextLabel::Box
);
111 label_w
->setPaletteBackgroundColor( QColor( 224, 232, 238 ) );
112 label_w
->setTextFormat( QLabel::RichText
);
113 label_w
->setAlignment( int( QLabel::WordBreak
| QLabel::AlignCenter
) );
114 label_w
->setText(label
);
116 EHBox
->addWidget(label_w
);
119 int INDI_E::buildTextGUI(QString initText
)
129 setupElementRead(ELEMENT_READ_WIDTH
);
130 setupElementWrite(ELEMENT_WRITE_WIDTH
);
135 setupElementRead(ELEMENT_FULL_WIDTH
);
139 setupElementWrite(ELEMENT_FULL_WIDTH
);
143 pp
->PVBox
->addLayout(EHBox
);
148 int INDI_E::buildBLOBGUI()
153 text
= "INDI DATA STREAM";
158 setupElementRead(ELEMENT_READ_WIDTH
);
159 setupElementWrite(ELEMENT_WRITE_WIDTH
);
165 setupElementRead(ELEMENT_FULL_WIDTH
);
169 setupElementWrite(ELEMENT_FULL_WIDTH
);
174 pp
->PVBox
->addLayout(EHBox
);
179 int INDI_E::buildNumberGUI (double initValue
)
183 updateValue(initValue
);
186 if (step
!= 0 && (max
- min
)/step
<= MAXSCSTEPS
)
192 setupElementRead(ELEMENT_READ_WIDTH
);
194 setupElementScale(ELEMENT_WRITE_WIDTH
);
196 setupElementWrite(ELEMENT_WRITE_WIDTH
);
198 pp
->PVBox
->addLayout(EHBox
);
202 setupElementRead(ELEMENT_READ_WIDTH
);
203 pp
->PVBox
->addLayout(EHBox
);
208 setupElementScale(ELEMENT_FULL_WIDTH
);
210 setupElementWrite(ELEMENT_FULL_WIDTH
);
212 pp
->PVBox
->addLayout(EHBox
);
221 int INDI_E::buildLightGUI()
224 led_w
= new KLed (pp
->pg
->propertyContainer
);
225 led_w
->setMaximumSize(16,16);
226 led_w
->setLook( KLed::Sunken
);
229 EHBox
->addWidget(led_w
);
233 pp
->PVBox
->addLayout(EHBox
);
238 void INDI_E::drawLt()
240 /* set state light */
244 led_w
->setColor(Qt::gray
);
248 led_w
->setColor(Qt::green
);
252 led_w
->setColor(Qt::yellow
);
256 led_w
->setColor(Qt::red
);
266 void INDI_E::updateValue(double newValue
)
272 numberFormat(iNumber
, format
.ascii(), value
);
277 void INDI_E::setupElementScale(int length
)
280 int steps
= (int) ((max
- min
) / step
);
281 spin_w
= new KDoubleSpinBox(min
, max
, step
, value
, 2, pp
->pg
->propertyContainer
);
282 slider_w
= new QSlider(0, steps
, 1, (int) ((value
- min
) / step
), Qt::Horizontal
, pp
->pg
->propertyContainer
);
284 connect(spin_w
, SIGNAL(valueChanged(double)), this, SLOT(spinChanged(double )));
285 connect(slider_w
, SIGNAL(sliderMoved(int)), this, SLOT(sliderChanged(int )));
287 //kdDebug() << "For element " << label << " we have step of " << step << endl;
289 if (length
== ELEMENT_FULL_WIDTH
)
290 spin_w
->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType
)7, (QSizePolicy::SizeType
)0, 0, 0, spin_w
->sizePolicy().hasHeightForWidth() ) );
292 spin_w
->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType
)0, (QSizePolicy::SizeType
)0, 0, 0, spin_w
->sizePolicy().hasHeightForWidth() ) );
294 spin_w
->setMinimumWidth( (int) (length
* 0.45) );
295 slider_w
->setMinimumWidth( (int) (length
* 0.55) );
297 EHBox
->addWidget(slider_w
);
298 EHBox
->addWidget(spin_w
);
301 void INDI_E::spinChanged(double value
)
303 int slider_value
= (int) ((value
- min
) / step
);
304 slider_w
->setValue(slider_value
);
307 void INDI_E::sliderChanged(int value
)
310 double spin_value
= (value
* step
) + min
;
311 spin_w
->setValue(spin_value
);
315 void INDI_E::setMin (double inMin
)
320 spin_w
->setMinValue(min
);
321 spin_w
->setValue(value
);
325 slider_w
->setMaxValue((int) ((max
- min
) / step
));
326 slider_w
->setMinValue(0);
327 slider_w
->setPageStep(1);
328 slider_w
->setValue( (int) ((value
- min
) / step
));
333 void INDI_E::setMax (double inMax
)
338 spin_w
->setMaxValue(max
);
339 spin_w
->setValue(value
);
343 slider_w
->setMaxValue((int) ((max
- min
) / step
));
344 slider_w
->setMinValue(0);
345 slider_w
->setPageStep(1);
346 slider_w
->setValue( (int) ((value
- min
) / step
));
351 void INDI_E::setupElementWrite(int length
)
353 write_w
= new KLineEdit( pp
->pg
->propertyContainer
);
354 write_w
->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType
)0, (QSizePolicy::SizeType
)0, 0, 0, write_w
->sizePolicy().hasHeightForWidth() ));
355 write_w
->setMinimumWidth( length
);
356 write_w
->setMaximumWidth( length
);
358 QObject::connect(write_w
, SIGNAL(returnPressed()), pp
, SLOT(newText()));
359 EHBox
->addWidget(write_w
);
363 void INDI_E::setupElementRead(int length
)
366 read_w
= new KLineEdit( pp
->pg
->propertyContainer
);
367 read_w
->setMinimumWidth( length
);
368 read_w
->setFocusPolicy( KLineEdit::NoFocus
);
369 read_w
->setFrameShape( KLineEdit::GroupBoxPanel
);
370 read_w
->setFrameShadow( KLineEdit::Plain
);
371 read_w
->setCursorPosition( 0 );
372 read_w
->setAlignment( int( KLineEdit::AlignHCenter
) );
373 read_w
->setReadOnly( TRUE
);
374 read_w
->setText(text
);
376 EHBox
->addWidget(read_w
);
380 void INDI_E::setupBrowseButton()
382 browse_w
= new KPushButton("...", pp
->pg
->propertyContainer
);
383 browse_w
->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType
)5, (QSizePolicy::SizeType
)0, 0, 0, browse_w
->sizePolicy().hasHeightForWidth() ) );
384 browse_w
->setMinimumWidth( MIN_SET_WIDTH
);
385 browse_w
->setMaximumWidth( MAX_SET_WIDTH
);
387 EHBox
->addWidget(browse_w
);
388 QObject::connect(browse_w
, SIGNAL(clicked()), this, SLOT(browseBlob()));
392 void INDI_E::initNumberValues(double newMin
, double newMax
, double newStep
, char * newFormat
)
400 void INDI_E::browseBlob()
405 currentURL
= KFileDialog::getOpenURL( QDir::homeDirPath(), "*");
407 // if user presses cancel
408 if (currentURL
.isEmpty())
411 if ( currentURL
.isValid() )
412 write_w
->setText(currentURL
.path());
417 #include "indielement.moc"