Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef KLFUNITINPUT_H
00025 #define KLFUNITINPUT_H
00026
00027 #include <QWidget>
00028 #include <QString>
00029 #include <QComboBox>
00030 #include <QDoubleSpinBox>
00031
00032 #include <klfdefs.h>
00033
00043 class KLF_EXPORT KLFUnitChooser : public QComboBox
00044 {
00045 Q_OBJECT
00046
00047 Q_PROPERTY(QString currentUnit READ currentUnitName WRITE setCurrentUnit USER true)
00048 Q_PROPERTY(double currentUnitFactor READ currentUnitFactor)
00049 Q_PROPERTY(QString klfUnits READ unitStringDescription WRITE setUnits)
00050 public:
00051 KLFUnitChooser(QWidget *parent = NULL);
00052 virtual ~KLFUnitChooser();
00053
00054 struct Unit {
00055 QString name;
00056 QString abbrev;
00057 double factor;
00058 };
00059
00060 inline Unit currentUnit() const { return itemData(currentIndex()).value<Unit>(); }
00061 inline QString currentUnitName() const { return currentUnit().name; }
00062 inline QString currentUnitAbbrev() const { return currentUnit().abbrev; }
00063 inline double currentUnitFactor() const { return currentUnit().factor; }
00064
00065 inline QStringList unitNames() const
00066 { QStringList l; foreach (Unit unit, pUnits) { l << unit.name; } return l; }
00067 inline QList<Unit> unitList() const { return pUnits; }
00068
00069 QString unitStringDescription() const;
00070
00071 public slots:
00083 void setUnits(const QString& unitstrlist);
00085 void setUnits(const QList<Unit>& unitlist);
00086
00087 void setCurrentUnit(const QString& unitName);
00088 void setCurrentUnitAbbrev(const QString& unitAbbrev);
00089 void setCurrentUnitIndex(int k);
00090
00091 signals:
00092 void unitChanged(const QString& unitName);
00093 void unitChanged(double unitFactor);
00094 void unitChanged(double unitFactor, const QString& suffix);
00095
00096 protected:
00097 virtual void changeEvent(QEvent *event);
00098
00099 private:
00100 QList<Unit> pUnits;
00101
00102 QString pDelayedUnitSet;
00103
00104 private slots:
00105 void internalCurrentIndexChanged(int index);
00106 };
00107
00108 Q_DECLARE_METATYPE(KLFUnitChooser::Unit) ;
00109
00110
00149 class KLF_EXPORT KLFUnitSpinBox : public QDoubleSpinBox
00150 {
00151 Q_OBJECT
00152 Q_PROPERTY(double valurInRefUnit READ valueInRefUnit WRITE setValueInRefUnit USER true)
00153 Q_PROPERTY(double unitFactor READ unitFactor WRITE setUnit)
00154 Q_PROPERTY(bool showUnitSuffix READ showUnitSuffix WRITE setShowUnitSuffix)
00155 public:
00156 KLFUnitSpinBox(QWidget *parent = NULL);
00157 virtual ~KLFUnitSpinBox();
00158
00159 inline double unitFactor() const { return pUnitFactor; }
00160
00161 inline bool showUnitSuffix() const { return pShowUnitSuffix; }
00162
00163 inline double valueInRefUnit() const { return QDoubleSpinBox::value() * unitFactor(); }
00164
00165 signals:
00166 void valueInRefUnitChanged(double value);
00167
00168 public slots:
00169 void setUnit(double unitfactor);
00170
00174 void setUnitWithSuffix(double unitfactor, const QString& suffix);
00175
00178 void setShowUnitSuffix(bool show);
00179
00180 void setValueInRefUnit(double value);
00181
00182 private:
00183 double pUnitFactor;
00184 bool pShowUnitSuffix;
00185
00186 private slots:
00187 void internalValueChanged(double valueInExtUnits);
00188 };
00189
00190
00191
00192 #endif