File indexing completed on 2024-04-14 14:10:54

0001 /*
0002     SPDX-FileCopyrightText: 2003 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006     2004-01-15  INDI element is the most basic unit of the INDI KStars client.
0007 */
0008 
0009 #pragma once
0010 
0011 #include "indicommon.h"
0012 
0013 #include <indiproperty.h>
0014 
0015 #include <QDialog>
0016 #include <QHBoxLayout>
0017 
0018 /* Forward declaration */
0019 class QLineEdit;
0020 class QDoubleSpinBox;
0021 class QPushButton;
0022 
0023 class QHBoxLayout;
0024 class QSpacerItem;
0025 class QCheckBox;
0026 class QButtonGroup;
0027 class QSlider;
0028 
0029 class KLed;
0030 class KSqueezedTextLabel;
0031 
0032 class INDI_P;
0033 
0034 /**
0035  * @class INDI_E
0036  * INDI_E represents an INDI GUI element (Number, Text, Switch, Light, or BLOB) within an INDI property.
0037  * It is the most basic GUI representation of property elements.
0038  *
0039  * @author Jasem Mutlaq
0040  */
0041 class INDI_E : public QWidget
0042 {
0043         Q_OBJECT
0044     public:
0045         INDI_E(INDI_P *gProp, INDI::Property dProp);
0046 
0047         const QString &getLabel()
0048         {
0049             return label;
0050         }
0051         const QString &getName()
0052         {
0053             return name;
0054         }
0055 
0056         QString getWriteField();
0057         QString getReadField();
0058 
0059         void buildSwitch(QButtonGroup *groupB, ISwitch *sw);
0060         void buildMenuItem(ISwitch *sw);
0061         void buildText(IText *itp);
0062         void buildNumber(INumber *inp);
0063         void buildLight(ILight *ilp);
0064         void buildBLOB(IBLOB *ibp);
0065 
0066         // Updates GUI from data in INDI properties
0067         void syncSwitch();
0068         void syncText();
0069         void syncNumber();
0070         void syncLight();
0071 
0072         // Save GUI data in INDI properties
0073         void updateTP();
0074         void updateNP();
0075 
0076         void setText(const QString &newText);
0077         void setValue(double value);
0078 
0079         void setMin();
0080         void setMax();
0081 
0082         void setupElementLabel();
0083         void setupElementRead(int length);
0084         void setupElementWrite(int length);
0085         void setupElementScale(int length);
0086         void setupBrowseButton();
0087 
0088         bool getBLOBDirty()
0089         {
0090             return blobDirty;
0091         }
0092         void setBLOBDirty(bool isDirty)
0093         {
0094             blobDirty = isDirty;
0095         }
0096 
0097     public slots:
0098         void spinChanged(double value);
0099         void sliderChanged(int value);
0100         void browseBlob();
0101 
0102     private:
0103         /// Name
0104         QString name;
0105         /// Label is the name by default, unless specified
0106         QString label;
0107         /// Parent GUI property
0108         INDI_P *guiProp { nullptr };
0109         /// Parent DATA property
0110         INDI::Property dataProp;
0111         /// Horizontal layout
0112         QHBoxLayout *EHBox { nullptr };
0113         /// Label widget
0114         KSqueezedTextLabel *label_w { nullptr };
0115         /// Read field widget
0116         QLineEdit *read_w { nullptr };
0117         /// Write field widget
0118         QLineEdit *write_w { nullptr };
0119         /// Light led widget
0120         KLed *led_w { nullptr };
0121         /// Spinbox widget
0122         QDoubleSpinBox *spin_w { nullptr };
0123         /// Slider widget
0124         QSlider *slider_w { nullptr };
0125         /// Push button widget
0126         QPushButton *push_w { nullptr };
0127         /// Browse button widget
0128         QPushButton *browse_w { nullptr };
0129         /// Check box widget
0130         QCheckBox *check_w { nullptr };
0131         /// Horizontal spacer widget
0132         QSpacerItem *hSpacer { nullptr };
0133 
0134         ISwitch *sp { nullptr };
0135         INumber *np { nullptr };
0136         IText *tp { nullptr };
0137         ILight *lp { nullptr };
0138         IBLOB *bp { nullptr };
0139 
0140         bool blobDirty { false };
0141         /// Current text
0142         QString text;
0143 };