1
/* This file is part of the KDE project
2
Copyright (C) 2002, Rob Buis(buis@kde.org)
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
20
#ifndef __KOUNITWIDGETS_H__
21
#define __KOUNITWIDGETS_H__
23
#include <knuminput.h>
24
#include <knumvalidator.h>
25
#include <klineedit.h>
26
#include <kcombobox.h>
29
class KoUnitDoubleBase;
31
class KoUnitDoubleValidator : public KDoubleValidator
34
KoUnitDoubleValidator( KoUnitDoubleBase *base, QObject *parent, const char *name = 0 );
36
virtual QValidator::State validate( QString &, int & ) const;
39
KoUnitDoubleBase *m_base;
42
class KoUnitDoubleBase
45
KoUnitDoubleBase( KoUnit::Unit unit, unsigned int precision ) : m_unit( unit ), m_precision( precision ) {}
46
virtual ~KoUnitDoubleBase() {}
48
virtual void changeValue( double ) = 0;
49
virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ) = 0;
51
void setValueInUnit( double value, KoUnit::Unit unit )
53
changeValue( KoUnit::ptToUnit( KoUnit::ptFromUnit( value, unit ), m_unit ) );
56
void setPrecision( unsigned int precision ) { m_precision = precision; };
59
friend class KoUnitDoubleValidator;
60
KoUnitDoubleValidator *m_validator;
62
unsigned int m_precision;
65
class KoUnitDoubleSpinBox : public KDoubleSpinBox, public KoUnitDoubleBase
68
KoUnitDoubleSpinBox( QWidget *parent, double lower, double upper, double step, double value = 0.0,
69
KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
71
virtual void changeValue( double );
72
virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
75
class KoUnitDoubleLineEdit : public KLineEdit, public KoUnitDoubleBase
78
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 );
80
virtual void changeValue( double );
81
virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
83
double value() const { return m_value; }
86
bool eventFilter( QObject* obj, QEvent* ev );
94
class KoUnitDoubleComboBox : public KComboBox, public KoUnitDoubleBase
98
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 );
100
virtual void changeValue( double );
101
void updateValue( double );
102
virtual void setUnit( KoUnit::Unit = KoUnit::U_PT );
104
double value() const { return m_value; }
105
void insertItem( double, int index = -1 );
108
bool eventFilter( QObject* obj, QEvent* ev );
111
void valueChanged(double);
114
void slotActivated( int );
122
class KoUnitDoubleSpinComboBox : public QWidget
126
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 );
128
void insertItem( double, int index = -1 );
129
void updateValue( double );
130
double value() const;
133
void valueChanged(double);
136
void slotUpClicked();
137
void slotDownClicked();
140
KoUnitDoubleComboBox *m_combo;