lib

KoUnitWidgets.h
1/* This file is part of the KDE project
2 Copyright (C) 2002, Rob Buis(buis@kde.org)
3 Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __KOUNITWIDGETS_H__
22#define __KOUNITWIDGETS_H__
23
24#include <knuminput.h>
25#include <knumvalidator.h>
26#include <klineedit.h>
27#include <kcombobox.h>
28#include <KoUnit.h>
29#include <koffice_export.h>
30
31
32// ----------------------------------------------------------------
33// Support classes
34
35
37
38// ### TODO: put it out of the public header file (if possible)
44class KOFFICEUI_EXPORT KoUnitDoubleValidator : public KDoubleValidator
45{
46public:
47 KoUnitDoubleValidator( KoUnitDoubleBase *base, TQObject *parent, const char *name = 0 );
48
49 virtual TQValidator::State validate( TQString &, int & ) const;
50
51private:
52 KoUnitDoubleBase *m_base;
53};
54
55
60class KOFFICEUI_EXPORT KoUnitDoubleBase
61{
62public:
63 KoUnitDoubleBase( KoUnit::Unit unit, unsigned int precision ) : m_unit( unit ), m_precision( precision ) {}
64 virtual ~KoUnitDoubleBase() {}
65
66 virtual void changeValue( double ) = 0;
67 virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ) = 0;
68
69 void setValueInUnit( double value, KoUnit::Unit unit )
70 {
71 changeValue( KoUnit::ptToUnit( KoUnit::fromUserValue( value, unit ), m_unit ) );
72 }
73
74 void setPrecision( unsigned int precision ) { m_precision = precision; };
75
76protected:
77 friend class KoUnitDoubleValidator;
83 TQString getVisibleText( double value ) const;
90 double toDouble( const TQString& str, bool* ok ) const;
91
92protected:
93 KoUnitDoubleValidator *m_validator;
94 KoUnit::Unit m_unit;
95 unsigned int m_precision;
96};
97
98
99// ----------------------------------------------------------------
100// Widget classes
101
102
107class KOFFICEUI_EXPORT KoUnitDoubleSpinBox : public KDoubleSpinBox, public KoUnitDoubleBase
108{
109 TQ_OBJECT
110
111public:
112 KoUnitDoubleSpinBox( TQWidget *parent = 0L, const char *name = 0L );
113 // lower, upper, step and value are in pt
114 KoUnitDoubleSpinBox( TQWidget *parent, double lower, double upper, double step, double value = 0.0,
115 KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
116 // added so the class can be used in .ui files(by Tymoteusz Majewski, maju7@o2.pl)
117 virtual void changeValue( double );
118 virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
119
121 double value( void ) const;
122
124 void setMinValue(double min);
125
127 void setMaxValue(double max);
128
130 void setLineStep(double step);
131
133 void setLineStepPt(double step);
134
136 void setMinMaxStep( double min, double max, double step );
137
138signals:
140 void valueChangedPt( double );
141
142
143private:
144 double m_lowerInPoints;
145 double m_upperInPoints;
146 double m_stepInPoints;
147
148private slots:
149 // exists to do emits for valueChangedPt
150 void privateValueChanged();
151};
152
153
158class KOFFICEUI_EXPORT KoUnitDoubleLineEdit : public KLineEdit, public KoUnitDoubleBase
159{
160 TQ_OBJECT
161
162public:
163 KoUnitDoubleLineEdit( TQWidget *parent = 0L, const char *name = 0L );
164 KoUnitDoubleLineEdit( TQWidget *parent, double lower, double upper, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
165
166 virtual void changeValue( double );
167 virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
168
170 double value( void ) const;
171
172protected:
173 bool eventFilter( TQObject* obj, TQEvent* ev );
174
175private:
176 double m_value;
177 double m_lower;
178 double m_upper;
179 double m_lowerInPoints;
180 double m_upperInPoints;
181};
182
187class KOFFICEUI_EXPORT KoUnitDoubleComboBox : public KComboBox, public KoUnitDoubleBase
188{
189 TQ_OBJECT
190
191public:
192 KoUnitDoubleComboBox( TQWidget *parent = 0L, const char *name = 0L );
193 KoUnitDoubleComboBox( TQWidget *parent, double lower, double upper, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
194
195 virtual void changeValue( double );
196 void updateValue( double );
197 virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
198
200 double value( void ) const;
201 void insertItem( double, int index = -1 );
202
203protected:
204 bool eventFilter( TQObject* obj, TQEvent* ev );
205
206signals:
207 void valueChanged(double);
208
209private slots:
210 void slotActivated( int );
211
212protected:
213 double m_value;
214 double m_lower;
215 double m_upper;
218};
219
224class KOFFICEUI_EXPORT KoUnitDoubleSpinComboBox : public TQWidget
225{
226 TQ_OBJECT
227
228public:
229 KoUnitDoubleSpinComboBox( TQWidget *parent = 0L, const char *name = 0L );
230 KoUnitDoubleSpinComboBox( TQWidget *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 );
231
232 void insertItem( double, int index = -1 );
233 void updateValue( double );
235 double value( void ) const;
236
237signals:
238 void valueChanged(double);
239
240private slots:
241 void slotUpClicked();
242 void slotDownClicked();
243
244private:
245 KoUnitDoubleComboBox *m_combo;
246 double m_step;
247};
248
249#endif
250
KComboBox(TQWidget *parent=0, const char *name=0)
KDoubleSpinBox(TQWidget *parent=0, const char *name=0)
int precision() const
KDoubleValidator(TQObject *parent, const char *name=0)
virtual TQValidator::State validate(TQString &input, int &pos) const
KLineEdit(const TQString &string, TQWidget *parent, const char *name=0)
Base for the unit widgets.
TQString getVisibleText(double value) const
Transform the double in a nice text, using locale symbols.
double toDouble(const TQString &str, bool *ok) const
Transfrom a string into a double, while taking care of locale specific symbols.
Combo box for double precision numbers with unit display.
double m_upperInPoints
highest value in points
double m_lowerInPoints
lowest value in points
double value(void) const
double value(void) const
void valueChangedPt(double)
emitted like valueChanged in the parent, but this one emits the point value
void setMinValue(double min)
Set minimum value in points.
void setLineStep(double step)
Set step size in the current unit.
void setMaxValue(double max)
Set maximum value in points.
void setMinMaxStep(double min, double max, double step)
Set minimum, maximum value and the step size (all in points) (by Tymoteusz Majewski,...
double value(void) const
void setLineStepPt(double step)
Set step size in points.
double value(void) const
static double fromUserValue(double value, Unit unit)
This method is the one to use to read a value from a dialog.
Definition KoUnit.cpp:120
static double ptToUnit(const double ptValue, const Unit unit)
Convert the value ptValue to a given unit unit Unlike KoUnit::ptToUnit the return value remains unrou...
Definition KoUnit.cpp:91
Unit
Length units supported by KOffice.
Definition KoUnit.h:63