9#include "indielement.h"
11#include "indiproperty.h"
13#include "indidevice.h"
16#include "ksnotification.h"
20#include <KSqueezedTextLabel>
21#include <KLocalizedString>
25#include <QButtonGroup>
28#include <QDoubleSpinBox>
34extern const char *libindi_strings_context;
39INDI_E::INDI_E(
INDI_P *gProp, INDI::Property dProp) :
QWidget(gProp), guiProp(gProp), dataProp(dProp)
43 EHBox->setContentsMargins(0, 0, 0, 0);
46void INDI_E::buildSwitch(
QButtonGroup *groupB, ISwitch *sw)
49 label =
i18nc(libindi_strings_context, sw->label);
51 if (label ==
"(I18N_EMPTY_MESSAGE)")
57 label =
i18nc(libindi_strings_context, sw->name);
59 if (label ==
"(I18N_EMPTY_MESSAGE)")
62 if (groupB ==
nullptr)
65 switch (guiProp->getGUIType())
68 push_w =
new QPushButton(label,
this);
69 push_w->setStyleSheet(
":checked {background-color: darkGreen}");
70 push_w->setCheckable(
true);
75 guiProp->addWidget(push_w);
79 if (dataProp.getPermission() == IP_RO)
80 push_w->setEnabled(sw->s == ISS_ON);
85 check_w =
new QCheckBox(label,
this);
90 guiProp->addWidget(check_w);
94 if (dataProp.getPermission() == IP_RO)
95 check_w->setEnabled(sw->s == ISS_ON);
104void INDI_E::buildMenuItem(ISwitch *sw)
106 buildSwitch(
nullptr, sw);
109void INDI_E::buildText(IText *itp)
113 label =
i18nc(libindi_strings_context, itp->label);
115 if (label ==
"(I18N_EMPTY_MESSAGE)")
121 label =
i18nc(libindi_strings_context, itp->name);
123 if (label ==
"(I18N_EMPTY_MESSAGE)")
129 text =
i18nc(libindi_strings_context, tp->text);
131 switch (dataProp.getPermission())
148 guiProp->addLayout(EHBox);
151void INDI_E::setupElementLabel()
155 label_w =
new KSqueezedTextLabel(
this);
158 label_w->setMargin(2);
160 palette.setColor(label_w->backgroundRole(), QColor(224, 232, 238));
164 label_w->setWordWrap(
true);
166 label_w->setStyleSheet(
"border: 1px solid grey; border-radius: 2px");
168 if (label.length() > MAX_LABEL_LENGTH)
170 QFont tempFont(label_w->font());
171 tempFont.setPointSize(tempFont.pointSize() - MED_INDI_FONT);
172 label_w->setFont(tempFont);
175 label_w->setText(label);
177 EHBox->addWidget(label_w);
180void INDI_E::syncSwitch()
187 switch (guiProp->getGUIType())
192 push_w->setChecked(
true);
194 buttonFont = push_w->font();
196 push_w->setFont(buttonFont);
198 if (dataProp.getPermission() == IP_RO)
199 push_w->setEnabled(
true);
203 push_w->setChecked(
false);
205 buttonFont = push_w->font();
207 push_w->setFont(buttonFont);
209 if (dataProp.getPermission() == IP_RO)
210 push_w->setEnabled(
false);
217 check_w->setChecked(
true);
218 if (dataProp.getPermission() == IP_RO)
219 check_w->setEnabled(
true);
223 check_w->setChecked(
false);
224 if (dataProp.getPermission() == IP_RO)
225 check_w->setEnabled(
false);
234void INDI_E::syncText()
239 if (dataProp.getPermission() != IP_WO)
242 read_w->setText(
i18nc(libindi_strings_context, tp->text));
244 read_w->setText(tp->text);
249 write_w->setText(tp->text);
253void INDI_E::syncNumber()
255 char iNumber[MAXINDIFORMAT];
256 if (np ==
nullptr || read_w ==
nullptr)
259 numberFormat(iNumber, np->format, np->value);
263 read_w->setText(text);
267 if (np->min != spin_w->minimum())
269 if (np->max != spin_w->maximum())
274void INDI_E::updateTP()
279 IUSaveText(tp, write_w->text().toHtmlEscaped().toLatin1().constData());
282void INDI_E::updateNP()
287 if (write_w !=
nullptr)
289 if (write_w->text().isEmpty())
292 f_scansexa(write_w->text().replace(
',',
'.').toLatin1().constData(), &(np->value));
296 if (spin_w !=
nullptr)
297 np->value = spin_w->value();
300void INDI_E::setText(
const QString &newText)
305 switch (dataProp.getPermission())
308 read_w->setText(newText);
315 read_w->setText(newText);
316 write_w->setText(newText);
321void INDI_E::setValue(
double value)
323 if (spin_w ==
nullptr || np ==
nullptr)
326 if (value < np->min || value > np->max)
329 spin_w->setValue(value);
333void INDI_E::buildBLOB(IBLOB *ibp)
336 label =
i18nc(libindi_strings_context, ibp->label);
338 if (label ==
"(I18N_EMPTY_MESSAGE)")
344 label =
i18nc(libindi_strings_context, ibp->name);
346 if (label ==
"(I18N_EMPTY_MESSAGE)")
351 text =
i18n(
"INDI DATA STREAM");
353 switch (dataProp.getPermission())
371 guiProp->addLayout(EHBox);
374void INDI_E::buildNumber(INumber *inp)
377 char iNumber[MAXINDIFORMAT];
380 label =
i18nc(libindi_strings_context, inp->label);
382 if (label ==
"(I18N_EMPTY_MESSAGE)")
388 label =
i18nc(libindi_strings_context, inp->name);
390 if (label ==
"(I18N_EMPTY_MESSAGE)")
393 numberFormat(iNumber, np->format, np->value);
398 if (np->step != 0 && (np->max - np->min) / np->step <= 100)
401 switch (dataProp.getPermission())
410 guiProp->addLayout(EHBox);
415 guiProp->addLayout(EHBox);
424 guiProp->addLayout(EHBox);
430void INDI_E::buildLight(ILight *ilp)
433 label =
i18nc(libindi_strings_context, ilp->label);
435 if (label ==
"(I18N_EMPTY_MESSAGE)")
441 label =
i18nc(libindi_strings_context, ilp->name);
443 if (label ==
"(I18N_EMPTY_MESSAGE)")
446 led_w =
new KLed(
this);
447 led_w->setMaximumSize(16, 16);
448 led_w->setLook(KLed::Sunken);
452 EHBox->addWidget(led_w);
456 guiProp->addLayout(EHBox);
459void INDI_E::syncLight()
484void INDI_E::setupElementScale(
int length)
489 int steps =
static_cast<int>((np->max - np->min) / np->step);
490 spin_w =
new QDoubleSpinBox(
this);
491 spin_w->setRange(np->min, np->max);
492 spin_w->setSingleStep(np->step);
493 spin_w->setValue(np->value);
494 spin_w->setDecimals(3);
497 slider_w->setRange(0, steps);
498 slider_w->setPageStep(1);
499 slider_w->setValue(
static_cast<int>((np->value - np->min) / np->step));
501 connect(spin_w, SIGNAL(valueChanged(
double)),
this, SLOT(spinChanged(
double)));
502 connect(slider_w, SIGNAL(sliderMoved(
int)),
this, SLOT(sliderChanged(
int)));
509 spin_w->setMinimumWidth(
static_cast<int>(length * 0.45));
510 slider_w->setMinimumWidth(
static_cast<int>(length * 0.55));
512 EHBox->addWidget(slider_w);
513 EHBox->addWidget(spin_w);
516void INDI_E::spinChanged(
double value)
518 int slider_value =
static_cast<int>((value - np->min) / np->step);
519 slider_w->setValue(slider_value);
522void INDI_E::sliderChanged(
int value)
524 double spin_value = (value * np->step) + np->min;
525 spin_w->setValue(spin_value);
532 spin_w->setMinimum(np->min);
533 spin_w->setValue(np->value);
537 slider_w->setMaximum(
static_cast<int>((np->max - np->min) / np->step));
538 slider_w->setMinimum(0);
539 slider_w->setPageStep(1);
540 slider_w->setValue(
static_cast<int>((np->value - np->min) / np->step));
548 spin_w->setMaximum(np->max);
549 spin_w->setValue(np->value);
553 slider_w->setMaximum(
static_cast<int>((np->max - np->min) / np->step));
554 slider_w->setMinimum(0);
555 slider_w->setPageStep(1);
556 slider_w->setValue(
static_cast<int>((np->value - np->min) / np->step));
560void INDI_E::setupElementWrite(
int length)
562 write_w =
new QLineEdit(
this);
564 write_w->setMinimumWidth(length);
565 write_w->setMaximumWidth(length);
567 write_w->setText(text);
569 QObject::connect(write_w, SIGNAL(returnPressed()), guiProp, SLOT(sendText()));
570 EHBox->addWidget(write_w);
573void INDI_E::setupElementRead(
int length)
575 read_w =
new QLineEdit(
this);
576 read_w->setMinimumWidth(length);
578 read_w->setCursorPosition(0);
580 read_w->setReadOnly(
true);
581 read_w->setText(text);
583 EHBox->addWidget(read_w);
586void INDI_E::setupBrowseButton()
588 browse_w =
new QPushButton(
this);
594 EHBox->addWidget(browse_w);
598void INDI_E::browseBlob()
624 KSNotification::error(
i18n(
"Cannot open file %1 for reading", filename));
630 bp->blob =
static_cast<uint8_t *
>(realloc(bp->blob, bp->size));
631 if (bp->blob ==
nullptr)
633 KSNotification::error(
i18n(
"Not enough memory for file %1", filename));
646 return write_w->text();
654 return read_w->text();
INDI_P represents a single INDI property (Switch, Text, Number, Light, or BLOB).
static KStars * Instance()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
const char * constData() const const
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
void setFileName(const QString &name)
virtual qint64 size() const const override
virtual void close() override
QUrl getOpenFileUrl(QWidget *parent, const QString &caption, const QUrl &dir, const QString &filter, QString *selectedFilter, Options options, const QStringList &supportedSchemes)
void setBold(bool enable)
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
qreal devicePixelRatio() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
qsizetype size() const const
QByteArray toLatin1() const const
bool isEmpty() const const
bool isValid() const const
QString toLocalFile() const const