lib Library API Documentation

koUnitWidgets.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, Rob Buis(buis@kde.org)
00003    Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef __KOUNITWIDGETS_H__
00022 #define __KOUNITWIDGETS_H__
00023 
00024 #include <knuminput.h>
00025 #include <knumvalidator.h>
00026 #include <klineedit.h>
00027 #include <kcombobox.h>
00028 #include <koUnit.h>
00029 
00030 class KoUnitDoubleBase;
00031 
00032 class KoUnitDoubleValidator : public KDoubleValidator
00033 {
00034 public:
00035     KoUnitDoubleValidator( KoUnitDoubleBase *base, QObject *parent, const char *name = 0 );
00036 
00037     virtual QValidator::State validate( QString &, int & ) const;
00038 
00039 private:
00040     KoUnitDoubleBase    *m_base;
00041 };
00042 
00043 class KoUnitDoubleBase
00044 {
00045 public:
00046     KoUnitDoubleBase( KoUnit::Unit unit, unsigned int precision ) : m_unit( unit ), m_precision( precision ) {}
00047     virtual ~KoUnitDoubleBase() {}
00048 
00049     virtual void changeValue( double ) = 0;
00050     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ) = 0;
00051 
00052     void setValueInUnit( double value, KoUnit::Unit unit )
00053     {
00054         changeValue( KoUnit::ptToUnit( KoUnit::ptFromUnit( value, unit ), m_unit ) );
00055     }
00056 
00057     void setPrecision( unsigned int precision ) { m_precision = precision; };
00058 
00059 protected:
00060     friend class KoUnitDoubleValidator;
00061         
00067         QString getVisibleText( double value ) const;
00074         static double toDouble( const QString& str, bool* ok );
00075 
00076         KoUnitDoubleValidator   *m_validator;
00077     KoUnit::Unit            m_unit;
00078     unsigned int            m_precision;
00079 };
00080 
00081 class KoUnitDoubleSpinBox : public KDoubleSpinBox, public KoUnitDoubleBase
00082 {
00083 public:
00084     KoUnitDoubleSpinBox( QWidget *parent, double lower, double upper, double step, double value = 0.0,
00085                     KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
00086 
00087     virtual void changeValue( double );
00088     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00089 };
00090 
00091 class KoUnitDoubleLineEdit : public KLineEdit, public KoUnitDoubleBase
00092 {
00093 public:
00094     KoUnitDoubleLineEdit( QWidget *parent, double lower, double upper, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
00095 
00096     virtual void changeValue( double );
00097     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00098 
00099     double value() const { return m_value; }
00100 
00101 protected:
00102      bool eventFilter( QObject* obj, QEvent* ev );
00103 
00104 private:
00105     double m_value;
00106     double m_lower;
00107     double m_upper;
00108 };
00109 
00110 class KoUnitDoubleComboBox : public KComboBox, public KoUnitDoubleBase
00111 {
00112 Q_OBJECT
00113 public:
00114     KoUnitDoubleComboBox( QWidget *parent, double lower, double upper, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
00115 
00116     virtual void changeValue( double );
00117     void updateValue( double );
00118     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00119 
00120     double value() const { return m_value; }
00121     void insertItem( double, int index = -1 );
00122 
00123 protected:
00124      bool eventFilter( QObject* obj, QEvent* ev );
00125 
00126 signals:
00127      void valueChanged(double);
00128 
00129 private slots:
00130     void slotActivated( int );
00131 
00132 protected:
00133     double m_value;
00134     double m_lower;
00135     double m_upper;
00136 };
00137 
00138 class KoUnitDoubleSpinComboBox : public QWidget
00139 {
00140 Q_OBJECT
00141 public:
00142     KoUnitDoubleSpinComboBox( QWidget *parent, double lower, double upper, double step, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
00143 
00144     void insertItem( double, int index = -1 );
00145     void updateValue( double );
00146     double value() const;
00147 
00148 signals:
00149      void valueChanged(double);
00150 
00151 private slots:
00152     void slotUpClicked();
00153     void slotDownClicked();
00154 
00155 private:
00156     KoUnitDoubleComboBox *m_combo;
00157     double m_step;
00158 };
00159 
00160 #endif
00161 
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 11 11:47:45 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003