summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/knuminput.h
Side-by-side diff
Diffstat (limited to 'microkde/kdeui/knuminput.h') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/knuminput.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/microkde/kdeui/knuminput.h b/microkde/kdeui/knuminput.h
index 123fefa..9f9e200 100644
--- a/microkde/kdeui/knuminput.h
+++ b/microkde/kdeui/knuminput.h
@@ -1,148 +1,153 @@
/*
* knuminput.h
*
* Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca>
* Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org>
* Copyright (c) 2002 Marc Mutz <mutz@kde.org>
*
* Requires the Qt widget libraries, available at no cost at
* http://www.troll.no/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef K_NUMINPUT_H
#define K_NUMINPUT_H
#include <qwidget.h>
#include <qspinbox.h>
+#include <QLineEdit>
+//Added by qt3to4:
+#include <QResizeEvent>
+#include <QLabel>
+#include <QEvent>
class QLabel;
class QSlider;
class QLineEdit;
class QLayout;
class QValidator;
class KIntSpinBox;
/* ------------------------------------------------------------------------ */
/**
* You need to inherit from this class if you want to implement K*NumInput
* for a different variable type
*
*/
class KNumInput : public QWidget
{
Q_OBJECT
Q_PROPERTY( QString label READ label WRITE setLabel )
public:
/**
* Default constructor
*
*/
KNumInput(QWidget* parent=0, const char* name=0);
/**
* @param below A pointer to another KNumInput.
*
*/
KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0);
~KNumInput();
/**
* Sets the text and alignment of the main description label.
*
* @param label The text of the label.
* Use QString::null to remove an existing one.
*
* @param a one of @p AlignLeft, @p AlignHCenter, YAlignRight and
* @p AlignTop, @p AlignVCenter, @p AlignBottom.
* default is @p AlignLeft | @p AlignTop.
*
* The vertical alignment flags have special meaning with this
* widget:
*
* @li @p AlignTop The label is placed above the edit/slider
* @li @p AlignVCenter The label is placed left beside the edit
* @li @p AlignBottom The label is placed below the edit/slider
*
*/
- virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
+ virtual void setLabel(const QString & label, int a = Qt::AlignLeft | Qt::AlignTop);
/**
* @return the text of the label.
*/
QString label() const;
/**
* @return if the num input has a slider.
* @since 3.1
*/
bool showSlider() const { return m_slider; }
/**
* Sets the spacing of tickmarks for the slider.
*
* @param minor Minor tickmark separation.
* @param major Major tickmark separation.
*/
void setSteps(int minor, int major);
/**
* Specifies that this widget may stretch horizontally, but is
* fixed vertically (like @ref QSpinBox itself).
*/
QSizePolicy sizePolicy() const;
/**
* Returns a size which fits the contents of the control.
*
* @return the preferred size necessary to show the control
*/
virtual QSize sizeHint() const;
protected:
/**
* Call this function whenever you change something in the geometry
* of your KNumInput child.
*
*/
void layout(bool deep);
/**
* You need to overwrite this method and implement your layout
* calculations there.
*
* See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation
* for details.
*
*/
virtual void doLayout() = 0;
KNumInput* m_prev, *m_next;
int m_colw1, m_colw2;
QLabel* m_label;
QSlider* m_slider;
QSize m_sizeSlider, m_sizeLabel;
int m_alignment;
private:
void init();
protected:
@@ -241,129 +246,129 @@ public:
int value() const;
/**
* @return the curent value in units of the @ref referencePoint.
* @since 3.1
*/
double relativeValue() const;
/**
* @return the current reference point
* @since 3.1
*/
int referencePoint() const;
/**
* @return the suffix displayed behind the value.
* @see #setSuffix()
*/
QString suffix() const;
/**
* @return the prefix displayed in front of the value.
* @see #setPrefix()
*/
QString prefix() const;
/**
* @return the string displayed for a special value.
* @see #setSpecialValueText()
*/
QString specialValueText() const;
/**
* @param min minimum value
* @param max maximum value
* @param step step size for the QSlider
*/
void setRange(int min, int max, int step=1, bool slider=true);
/**
* Sets the minimum value.
*/
void setMinValue(int min);
/**
* @return the minimum value.
*/
int minValue() const;
/**
* Sets the maximum value.
*/
void setMaxValue(int max);
/**
* @return the maximum value.
*/
int maxValue() const;
/**
* Sets the special value text. If set, the SpinBox will display
* this text instead of the numeric value whenever the current
* value is equal to minVal(). Typically this is used for indicating
* that the choice has a special (default) meaning.
*/
void setSpecialValueText(const QString& text);
/**
* @reimplemented
*/
- virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
+ virtual void setLabel(const QString & label, int a = Qt::AlignLeft | Qt::AlignTop);
/**
* This method returns the minimum size necessary to display the
* control. The minimum size is enough to show all the labels
* in the current font (font change may invalidate the return value).
*
* @return the minimum size necessary to show the control
*/
virtual QSize minimumSizeHint() const;
public slots:
/**
* Sets the value of the control.
*/
void setValue(int);
/**
* Sets the value in units of the @ref referencePoint
* @since 3.1
*/
void setRelativeValue(double);
/**
* Sets the reference point for @ref relativeValue.
* @since 3.1
*/
void setReferencePoint(int);
/**
* Sets the suffix to @p suffix.
* Use QString::null to disable this feature.
* Formatting has to be provided (e.g. a space separator between the
* prepended @p value and the suffix's text has to be provided
* as the first character in the suffix).
*
* @see QSpinBox::setSuffix(), #setPrefix()
*/
void setSuffix(const QString &suffix);
/**
* Sets the prefix to @p prefix.
* Use QString::null to disable this feature.
* Formatting has to be provided (see above).
*
* @see QSpinBox::setPrefix(), #setSuffix()
*/
void setPrefix(const QString &prefix);
/**
* sets focus to the edit widget and marks all text in if mark == true
*
*/
void setEditFocus( bool mark = true );
signals:
/**
* Emitted every time the value changes (by calling @ref setValue() or
* by user interaction).
*/
void valueChanged(int);
/**
* Emitted whenever @ref #valueChanged is. Contains the change
* relative to the @ref referencePoint.
@@ -527,129 +532,129 @@ public:
/**
* @return the precision.
* @see #setPrecision()
*/
int precision() const;
/**
* @return the string displayed for a special value.
* @see #setSpecialValueText()
*/
QString specialValueText() const { return m_specialvalue; }
/**
* @param min minimum value
* @param max maximum value
* @param step step size for the QSlider
*/
void setRange(double min, double max, double step=1, bool slider=true);
/**
* Sets the minimum value.
*/
void setMinValue(double min);
/**
* @return the minimum value.
*/
double minValue() const;
/**
* Sets the maximum value.
*/
void setMaxValue(double max);
/**
* @return the maximum value.
*/
double maxValue() const;
/**
* Specifies the number of digits to use.
*/
void setPrecision(int precision);
/**
* @return the reference point for @ref #relativeValue calculation
* @since 3.1
*/
double referencePoint() const;
/**
* @return the current value in units of @ref #referencePoint.
* @since 3.1
*/
double relativeValue() const;
/**
* Sets the special value text. If set, the spin box will display
* this text instead of the numeric value whenever the current
* value is equal to @ref #minVal(). Typically this is used for indicating
* that the choice has a special (default) meaning.
*/
void setSpecialValueText(const QString& text);
/**
* @reimplemented
*/
- virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
+ virtual void setLabel(const QString & label, int a = Qt::AlignLeft | Qt::AlignTop);
/**
* @reimplemented
*/
virtual QSize minimumSizeHint() const;
/**
* @reimplemented
*/
virtual bool eventFilter(QObject*, QEvent*);
public slots:
/**
* Sets the value of the control.
*/
void setValue(double);
/**
* Sets the value in units of @ref #referencePoint.
* @since 3.1
*/
void setRelativeValue(double);
/**
* Sets the reference Point to @p ref. It @p ref == 0, emitting of
* @ref #relativeValueChanged is blocked and @ref #relativeValue
* just returns 0.
* @since 3.1
*/
void setReferencePoint(double ref);
/**
* Sets the suffix to be displayed to @p suffix. Use QString::null to disable
* this feature. Note that the suffix is attached to the value without any
* spacing. So if you prefer to display a space separator, set suffix
* to something like " cm".
* @see #setSuffix()
*/
void setSuffix(const QString &suffix);
/**
* Sets the prefix to be displayed to @p prefix. Use QString::null to disable
* this feature. Note that the prefix is attached to the value without any
* spacing.
* @see #setPrefix()
*/
void setPrefix(const QString &prefix);
signals:
/**
* Emitted every time the value changes (by calling @ref setValue() or
* by user interaction).
*/
void valueChanged(double);
/**
* This is an overloaded member function, provided for
* convenience. It essentially behaves like the above function.
*
* Contains the value in units of @ref #referencePoint.
* @since 3.1
*/
void relativeValueChanged(double);
private slots:
void sliderMoved(int);
void slotEmitRelativeValueChanged(double);
@@ -697,128 +702,132 @@ private:
/* ------------------------------------------------------------------------ */
/**
* A @ref QSpinBox with support for arbitrary base numbers
* (e.g. hexadecimal).
*
* The class provides an easy interface to use other
* numeric systems than the decimal.
*
* @short A @ref QSpinBox with support for arbitrary base numbers.
*/
class KIntSpinBox : public QSpinBox
{
Q_OBJECT
Q_PROPERTY( int base READ base WRITE setBase )
public:
/**
* Constructor.
*
* Constructs a widget with an integer inputline with a little scrollbar
* and a slider, with minimal value 0, maximal value 99, step 1, base 10
* and initial value 0.
*/
KIntSpinBox( QWidget *parent=0, const char *name=0);
/**
* Constructor.
*
* Constructs a widget with an integer inputline with a little scrollbar
* and a slider.
*
* @param lower The lowest valid value.
* @param upper The greatest valid value.
* @param step The step size of the scrollbar.
* @param value The actual value.
* @param base The base of the used number system.
* @param parent The parent of the widget.
* @param name The Name of the widget.
*/
KIntSpinBox(int lower, int upper, int step, int value, int base = 10,
QWidget* parent = 0, const char* name = 0);
/**
* Destructor.
*/
virtual ~KIntSpinBox();
/**
* Sets the base in which the numbers in the spin box are represented.
*/
void setBase(int base);
/**
* @return the base in which numbers in the spin box are represented.
*/
int base() const;
/**
* sets focus and optionally marks all text
*
*/
void setEditFocus(bool mark);
+ void setValidator(const QValidator *v) {
+ lineEdit()->setValidator(v);
+ }
+
protected:
/**
* Overloaded the method in QSpinBox
* to make use of the base given in the constructor.
*/
virtual QString mapValueToText(int);
/**
* Overloaded the method in QSpinBox
* to make use of the base given in the constructor.
*/
virtual int mapTextToValue(bool*);
private:
int val_base;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KIntSpinBoxPrivate;
KIntSpinBoxPrivate *d;
};
/* --------------------------------------------------------------------------- */
/**
This class provides a spin box for fractional numbers.
@sect Parameters
There are a number of interdependent parameters whose relation to
each other you need to understand in order to make successful use
of the spin box.
@li precision: The number of decimals after the decimal point.
@li maxValue/minValue: upper and lower bound of the valid range
@li lineStep: the size of the step that is taken when the user hits
the up or down buttons
Since we work with fixed-point numbers internally, the maximum
precision is a function of the valid range and vice versa. More
precisely, the following relations hold:
<pre>
max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision
maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) )
</pre>
Since the value, bounds and step are rounded to the current
precision, you may experience that the order of setting above
parameters matters. E.g. the following are @em not equivalent (try
it!):
<pre>
// sets precision,
// then min/max value (rounded to precison and clipped to obtainable range if needed)
// then value and lineStep
KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this );
// sets minValue to 0; maxValue to 10.00(!); value to 4.32(!) and only then
// increases the precision - too late, since e.g. value has already been rounded...
KDpubleSpinBox * spin = new KDoubleSpinBox( this );
spin->setMinValue( 0 );
spin->setMaxValue( 9.999 );