[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfunitinput.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfunitinput.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klfunitinput.h 604 2011-02-27 23:34:37Z phfaist $ */
23 
24 #ifndef KLFUNITINPUT_H
25 #define KLFUNITINPUT_H
26 
27 #include <QWidget>
28 #include <QString>
29 #include <QComboBox>
30 #include <QDoubleSpinBox>
31 
32 #include <klfdefs.h>
33 
43 class KLF_EXPORT KLFUnitChooser : public QComboBox
44 {
45  Q_OBJECT
46 
47  Q_PROPERTY(QString currentUnit READ currentUnitName WRITE setCurrentUnit USER true)
48  Q_PROPERTY(double currentUnitFactor READ currentUnitFactor)
49  Q_PROPERTY(QString klfUnits READ unitStringDescription WRITE setUnits)
50 public:
51  KLFUnitChooser(QWidget *parent = NULL);
52  virtual ~KLFUnitChooser();
53 
54  struct Unit {
57  double factor;
58  };
59 
60  inline Unit currentUnit() const { return itemData(currentIndex()).value<Unit>(); }
61  inline QString currentUnitName() const { return currentUnit().name; }
62  inline QString currentUnitAbbrev() const { return currentUnit().abbrev; }
63  inline double currentUnitFactor() const { return currentUnit().factor; }
64 
65  inline QStringList unitNames() const
66  { QStringList l; foreach (Unit unit, pUnits) { l << unit.name; } return l; }
67  inline QList<Unit> unitList() const { return pUnits; }
68 
69  QString unitStringDescription() const;
70 
71 public slots:
83  void setUnits(const QString& unitstrlist);
85  void setUnits(const QList<Unit>& unitlist);
86 
87  void setCurrentUnit(const QString& unitName);
88  void setCurrentUnitAbbrev(const QString& unitAbbrev);
89  void setCurrentUnitIndex(int k);
90 
91 signals:
92  void unitChanged(const QString& unitName);
93  void unitChanged(double unitFactor);
94  void unitChanged(double unitFactor, const QString& suffix);
95 
96 protected:
97  virtual void changeEvent(QEvent *event);
98 
99 private:
100  QList<Unit> pUnits;
101 
102  QString pDelayedUnitSet;
103 
104 private slots:
105  void internalCurrentIndexChanged(int index);
106 };
107 
109 
110 
149 class KLF_EXPORT KLFUnitSpinBox : public QDoubleSpinBox
150 {
151  Q_OBJECT
152  Q_PROPERTY(double valurInRefUnit READ valueInRefUnit WRITE setValueInRefUnit USER true)
153  Q_PROPERTY(double unitFactor READ unitFactor WRITE setUnit)
154  Q_PROPERTY(bool showUnitSuffix READ showUnitSuffix WRITE setShowUnitSuffix)
155 public:
156  KLFUnitSpinBox(QWidget *parent = NULL);
157  virtual ~KLFUnitSpinBox();
158 
159  inline double unitFactor() const { return pUnitFactor; }
160 
161  inline bool showUnitSuffix() const { return pShowUnitSuffix; }
162 
163  inline double valueInRefUnit() const { return QDoubleSpinBox::value() * unitFactor(); }
164 
165 signals:
166  void valueInRefUnitChanged(double value);
167 
168 public slots:
169  void setUnit(double unitfactor);
170 
174  void setUnitWithSuffix(double unitfactor, const QString& suffix);
175 
178  void setShowUnitSuffix(bool show);
179 
180  void setValueInRefUnit(double value);
181 
182 private:
183  double pUnitFactor;
184  bool pShowUnitSuffix;
185 
186 private slots:
187  void internalValueChanged(double valueInExtUnits);
188 };
189 
190 
191 
192 #endif
QString currentUnitName() const
Definition: klfunitinput.h:61
Base declarations for klatexformula and some utilities.
Q_DECLARE_METATYPE(KLFUnitChooser::Unit)
bool showUnitSuffix() const
Definition: klfunitinput.h:161
A combo box to select a unit for measures.
Definition: klfunitinput.h:43
double valueInRefUnit() const
Definition: klfunitinput.h:163
double currentUnitFactor() const
Definition: klfunitinput.h:63
#define KLF_EXPORT
Definition: klfdefs.h:41
QStringList unitNames() const
Definition: klfunitinput.h:65
Unit currentUnit() const
Definition: klfunitinput.h:60
QList< Unit > unitList() const
Definition: klfunitinput.h:67
A spin box that can display values in different units.
Definition: klfunitinput.h:149
QString currentUnitAbbrev() const
Definition: klfunitinput.h:62

Generated by doxygen 1.8.13