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 #include <koffice_export.h>
00030 
00031 
00032 // ----------------------------------------------------------------
00033 //                          Support classes
00034 
00035 
00036 class KoUnitDoubleBase;
00037 
00038 // ### TODO: put it out of the public header file (if possible)
00044 class KOFFICEUI_EXPORT KoUnitDoubleValidator : public KDoubleValidator
00045 {
00046 public:
00047     KoUnitDoubleValidator( KoUnitDoubleBase *base, QObject *parent, const char *name = 0 );
00048 
00049     virtual QValidator::State validate( QString &, int & ) const;
00050 
00051 private:
00052     KoUnitDoubleBase *m_base;
00053 };
00054 
00055 
00060 class KOFFICEUI_EXPORT KoUnitDoubleBase
00061 {
00062 public:
00063     KoUnitDoubleBase( KoUnit::Unit unit, unsigned int precision ) : m_unit( unit ), m_precision( precision ) {}
00064     virtual ~KoUnitDoubleBase() {}
00065 
00066     virtual void changeValue( double ) = 0;
00067     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ) = 0;
00068 
00069     void setValueInUnit( double value, KoUnit::Unit unit )
00070     {
00071         changeValue( KoUnit::ptToUnit( KoUnit::fromUserValue( value, unit ), m_unit ) );
00072     }
00073 
00074     void setPrecision( unsigned int precision ) { m_precision = precision; };
00075 
00076 protected:
00077     friend class KoUnitDoubleValidator;
00083     QString getVisibleText( double value ) const;
00090     double toDouble( const QString& str, bool* ok ) const;
00091 
00092 protected:
00093     KoUnitDoubleValidator *m_validator;
00094     KoUnit::Unit m_unit;
00095     unsigned int m_precision;
00096 };
00097 
00102 class KOFFICEUI_EXPORT KoUnitDoubleSpinBox : public KDoubleSpinBox, public KoUnitDoubleBase
00103 {
00104 public:
00105     // lower, upper, step and value are in pt
00106     KoUnitDoubleSpinBox( QWidget *parent, double lower, double upper, double step, double value = 0.0,
00107                          KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
00108 
00109     virtual void changeValue( double );
00110     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00111 
00113     double value( void ) const;
00114 
00116     void setMinValue(double min);
00117 
00119     void setMaxValue(double max);
00120 
00122     void setLineStep(double step);
00123 
00124 private:
00125     double m_lowerInPoints; 
00126     double m_upperInPoints; 
00127     double m_stepInPoints;  
00128 };
00129 
00130 
00135 class KOFFICEUI_EXPORT KoUnitDoubleLineEdit : public KLineEdit, public KoUnitDoubleBase
00136 {
00137 public:
00138     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 );
00139 
00140     virtual void changeValue( double );
00141     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00142 
00144     double value( void ) const;
00145 
00146 protected:
00147     bool eventFilter( QObject* obj, QEvent* ev );
00148 
00149 private:
00150     double m_value;
00151     double m_lower;
00152     double m_upper;
00153     double m_lowerInPoints; 
00154     double m_upperInPoints; 
00155 };
00156 
00161 class KOFFICEUI_EXPORT KoUnitDoubleComboBox : public KComboBox, public KoUnitDoubleBase
00162 {
00163     Q_OBJECT
00164 public:
00165     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 );
00166 
00167     virtual void changeValue( double );
00168     void updateValue( double );
00169     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00170 
00172     double value( void ) const;
00173     void insertItem( double, int index = -1 );
00174 
00175 protected:
00176     bool eventFilter( QObject* obj, QEvent* ev );
00177 
00178 signals:
00179     void valueChanged(double);
00180 
00181 private slots:
00182     void slotActivated( int );
00183 
00184 protected:
00185     double m_value;
00186     double m_lower;
00187     double m_upper;
00188     double m_lowerInPoints; 
00189     double m_upperInPoints; 
00190 };
00191 
00196 class KOFFICEUI_EXPORT KoUnitDoubleSpinComboBox : public QWidget
00197 {
00198     Q_OBJECT
00199 public:
00200     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 );
00201 
00202     void insertItem( double, int index = -1 );
00203     void updateValue( double );
00205     double value( void ) const;
00206 
00207 signals:
00208     void valueChanged(double);
00209 
00210 private slots:
00211     void slotUpClicked();
00212     void slotDownClicked();
00213 
00214 private:
00215     KoUnitDoubleComboBox *m_combo;
00216     double m_step;
00217 };
00218 
00219 #endif
00220 
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:13 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003