[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$ */
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
43class 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)
50public:
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
71public 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
91signals:
92 void unitChanged(const QString& unitName);
93 void unitChanged(double unitFactor);
94 void unitChanged(double unitFactor, const QString& suffix);
95
96protected:
97 virtual void changeEvent(QEvent *event);
98
99private:
100 QList<Unit> pUnits;
101
102 QString pDelayedUnitSet;
103
104private slots:
105 void internalCurrentIndexChanged(int index);
106};
107
109
110
149class 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)
155public:
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
165signals:
166 void valueInRefUnitChanged(double value);
167
168public 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
182private:
183 double pUnitFactor;
184 bool pShowUnitSuffix;
185
186private slots:
187 void internalValueChanged(double valueInExtUnits);
188};
189
190
191
192#endif
A combo box to select a unit for measures.
QStringList unitNames() const
void unitChanged(double unitFactor)
Unit currentUnit() const
QString currentUnitAbbrev() const
QString currentUnitName() const
QList< Unit > unitList() const
void unitChanged(double unitFactor, const QString &suffix)
double currentUnitFactor() const
void unitChanged(const QString &unitName)
A spin box that can display values in different units.
bool showUnitSuffix() const
void valueInRefUnitChanged(double value)
double valueInRefUnit() const
Base declarations for klatexformula and some utilities.
#define KLF_EXPORT
Definition klfdefs.h:41
Q_DECLARE_METATYPE(KLFUnitChooser::Unit)

Generated by doxygen 1.12.0