[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
src/klftools/klfunitinput.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfunitinput.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2011 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id$ */
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

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net