00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00034
00035
00036 class KoUnitDoubleBase;
00037
00038
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
00098
00099
00100
00101
00102
00107 class KOFFICEUI_EXPORT KoUnitDoubleSpinBox : public KDoubleSpinBox, public KoUnitDoubleBase
00108 {
00109 Q_OBJECT
00110 public:
00111 KoUnitDoubleSpinBox( QWidget *parent = 0L, const char *name = 0L );
00112
00113 KoUnitDoubleSpinBox( QWidget *parent, double lower, double upper, double step, double value = 0.0,
00114 KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
00115
00116 virtual void changeValue( double );
00117 virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00118
00120 double value( void ) const;
00121
00123 void setMinValue(double min);
00124
00126 void setMaxValue(double max);
00127
00129 void setLineStep(double step);
00130
00132 void setLineStepPt(double step);
00133
00135 void setMinMaxStep( double min, double max, double step );
00136
00137 signals:
00139 void valueChangedPt( double );
00140
00141
00142 private:
00143 double m_lowerInPoints;
00144 double m_upperInPoints;
00145 double m_stepInPoints;
00146
00147 private slots:
00148
00149 void privateValueChanged();
00150 };
00151
00152
00157 class KOFFICEUI_EXPORT KoUnitDoubleLineEdit : public KLineEdit, public KoUnitDoubleBase
00158 {
00159 Q_OBJECT
00160 public:
00161 KoUnitDoubleLineEdit( QWidget *parent = 0L, const char *name = 0L );
00162 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 );
00163
00164 virtual void changeValue( double );
00165 virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00166
00168 double value( void ) const;
00169
00170 protected:
00171 bool eventFilter( QObject* obj, QEvent* ev );
00172
00173 private:
00174 double m_value;
00175 double m_lower;
00176 double m_upper;
00177 double m_lowerInPoints;
00178 double m_upperInPoints;
00179 };
00180
00185 class KOFFICEUI_EXPORT KoUnitDoubleComboBox : public KComboBox, public KoUnitDoubleBase
00186 {
00187 Q_OBJECT
00188 public:
00189 KoUnitDoubleComboBox( QWidget *parent = 0L, const char *name = 0L );
00190 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 );
00191
00192 virtual void changeValue( double );
00193 void updateValue( double );
00194 virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
00195
00197 double value( void ) const;
00198 void insertItem( double, int index = -1 );
00199
00200 protected:
00201 bool eventFilter( QObject* obj, QEvent* ev );
00202
00203 signals:
00204 void valueChanged(double);
00205
00206 private slots:
00207 void slotActivated( int );
00208
00209 protected:
00210 double m_value;
00211 double m_lower;
00212 double m_upper;
00213 double m_lowerInPoints;
00214 double m_upperInPoints;
00215 };
00216
00221 class KOFFICEUI_EXPORT KoUnitDoubleSpinComboBox : public QWidget
00222 {
00223 Q_OBJECT
00224 public:
00225 KoUnitDoubleSpinComboBox( QWidget *parent = 0L, const char *name = 0L );
00226 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 );
00227
00228 void insertItem( double, int index = -1 );
00229 void updateValue( double );
00231 double value( void ) const;
00232
00233 signals:
00234 void valueChanged(double);
00235
00236 private slots:
00237 void slotUpClicked();
00238 void slotDownClicked();
00239
00240 private:
00241 KoUnitDoubleComboBox *m_combo;
00242 double m_step;
00243 };
00244
00245 #endif
00246