F:/KPlato/koffice/libs/kofficeui/KoUnitWidgets.h

Aller à la documentation de ce fichier.
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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, 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 //Added by qt3to4:
00031 #include <QEvent>
00032 
00033 
00034 // ----------------------------------------------------------------
00035 //                          Support classes
00036 
00037 
00038 class KoUnitDoubleBase;
00039 
00040 // ### TODO: put it out of the public header file (if possible)
00046 class KOFFICEUI_EXPORT KoUnitDoubleValidator : public KDoubleValidator
00047 {
00048 public:
00049     KoUnitDoubleValidator( KoUnitDoubleBase *base, QObject *parent, const char *name = 0 );
00050 
00051     virtual QValidator::State validate( QString &, int & ) const;
00052 
00053 private:
00054     KoUnitDoubleBase *m_base;
00055 };
00056 
00057 
00062 class KOFFICEUI_EXPORT KoUnitDoubleBase
00063 {
00064 public:
00065     KoUnitDoubleBase( KoUnit::Unit unit, unsigned int precision ) : m_unit( unit ), m_precision( precision ) {}
00066     virtual ~KoUnitDoubleBase() {}
00067 
00068     virtual void changeValue( double ) = 0;
00069     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ) = 0;
00070 
00071     void setValueInUnit( double value, KoUnit::Unit unit )
00072     {
00073         changeValue( KoUnit::ptToUnit( KoUnit::fromUserValue( value, unit ), m_unit ) );
00074     }
00075 
00076     void setPrecision( unsigned int precision ) { m_precision = precision; };
00077 
00078 protected:
00079     friend class KoUnitDoubleValidator;
00085     QString getVisibleText( double value ) const;
00092     double toDouble( const QString& str, bool* ok ) const;
00093 
00094 protected:
00095     KoUnitDoubleValidator *m_validator;
00096     KoUnit::Unit m_unit;
00097     unsigned int m_precision;
00098 };
00099 
00100 
00101 // ----------------------------------------------------------------
00102 //                          Widget classes
00103 
00104 
00118 class KOFFICEUI_EXPORT KoUnitDoubleSpinBox : public KDoubleSpinBox, public KoUnitDoubleBase
00119 {
00120     Q_OBJECT
00121 public:
00130     KoUnitDoubleSpinBox( QWidget *parent = 0L, const char *name = 0L );
00144     KoUnitDoubleSpinBox( QWidget *parent, double lower, double upper, double step, double value = 0.0,
00145                          KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
00151     virtual void changeValue( double newValue );
00155     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00156 
00158     double value( void ) const;
00159 
00161     void setMinimum(double min);
00162 
00164     void setMaximum(double max);
00165 
00167     void setLineStep(double step);
00168 
00170     void setLineStepPt(double step);
00171 
00173     void setMinMaxStep( double min, double max, double step );
00174 
00175 signals:
00177     void valueChangedPt( double );
00178 
00179 private:
00180     double m_lowerInPoints; 
00181     double m_upperInPoints; 
00182     double m_stepInPoints;  
00183 
00184 private slots:
00185     // exists to do emits for valueChangedPt
00186     void privateValueChanged();
00187 };
00188 
00189 
00194 class KOFFICEUI_EXPORT KoUnitDoubleLineEdit : public KLineEdit, public KoUnitDoubleBase
00195 {
00196     Q_OBJECT
00197 public:
00198     KoUnitDoubleLineEdit( QWidget *parent = 0L, const char *name = 0L );
00199     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 );
00200 
00201     virtual void changeValue( double );
00202     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00203 
00205     double value( void ) const;
00206 
00207 protected:
00208     bool eventFilter( QObject* obj, QEvent* ev );
00209 
00210 private:
00211     double m_value;
00212     double m_lower;
00213     double m_upper;
00214     double m_lowerInPoints; 
00215     double m_upperInPoints; 
00216 };
00217 
00222 class KOFFICEUI_EXPORT KoUnitDoubleComboBox : public KComboBox, public KoUnitDoubleBase
00223 {
00224     Q_OBJECT
00225 public:
00226     KoUnitDoubleComboBox( QWidget *parent = 0L, const char *name = 0L );
00227     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 );
00228 
00229     virtual void changeValue( double );
00230     void updateValue( double );
00231     virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00232 
00234     double value( void ) const;
00235     void insertItem( double, int index = -1 );
00236 
00237 protected:
00238     bool eventFilter( QObject* obj, QEvent* ev );
00239 
00240 signals:
00241     void valueChanged(double);
00242 
00243 private slots:
00244     void slotActivated( int );
00245 
00246 protected:
00247     double m_value;
00248     double m_lower;
00249     double m_upper;
00250     double m_lowerInPoints; 
00251     double m_upperInPoints; 
00252 };
00253 
00258 class KOFFICEUI_EXPORT KoUnitDoubleSpinComboBox : public QWidget
00259 {
00260     Q_OBJECT
00261 public:
00262     KoUnitDoubleSpinComboBox( QWidget *parent = 0L, const char *name = 0L );
00263     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 );
00264 
00265     void insertItem( double, int index = -1 );
00266     void updateValue( double );
00268     double value( void ) const;
00269 
00270 signals:
00271     void valueChanged(double);
00272 
00273 private slots:
00274     void slotUpClicked();
00275     void slotDownClicked();
00276 
00277 private:
00278     KoUnitDoubleComboBox *m_combo;
00279     double m_step;
00280 };
00281 
00282 #endif
00283 

Généré le Wed Nov 22 23:41:05 2006 pour KPlato par  doxygen 1.5.1-p1