Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KDoubleNumInput (./kdelibs/kdeui/knuminput.h:302)
class KDoubleNumInput : public KNumInput
{
Q_OBJECT
public:
/**
* Constructor
*
* @param value initial value for the control
* @param parent parent QWidget
* @param name internal name for this widget
*/
KDoubleNumInput(double value, QWidget *parent=0, const char *name=0);
/**
* destructor
*/
virtual ~KDoubleNumInput();
/**
* Constructor
*
* put it below other KNumInput
*
* @param below
* @param value initial value for the control
* @param parent parent QWidget
* @param name internal name for this widget
**/
KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0);
/**
* 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;
/**
* @return the current value
*/
double value() const;
/**
* @param lower lower bound on range
* @param upper upper bound on range
* @param step step size for the QSlider
*/
void setRange(double lower, double upper, double step=1, bool slider=true);
/**
* the Format string that should be used to display the double value.
*
* @param format uses the same format as QString::sprintf().
*/
void setFormat(const char* format);
/**
* 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 for internal reasons.
*
*/
virtual void setLabel(QString label, int a = AlignLeft | AlignTop);
public slots:
/**
* Sets the value of the control.
*/
void setValue(double);
/**
* sets the Suffix
* @param suffix the suffix that should be used. QString::null to disable
*/
void setSuffix(QString suffix);
/**
* sets the Prefix
* @param prefix the prefix that should be used. QString::null to disable
*/
void setPrefix(QString prefix);
signals:
void valueChanged(double);
protected slots:
void sliderMoved(int);
protected:
void init(double value);
virtual void doLayout();
virtual bool eventFilter(QObject*, QEvent*);
void resizeEvent ( QResizeEvent * );
void resetEditBox();
KDoubleLine* edit;
bool m_range;
double m_value, m_lower, m_upper, m_step;
QString m_units, m_specialvalue, m_prefix, m_suffix;
char *m_format;
int m_sliderstep;
QSize m_sizeEdit;
friend class KDoubleLine;
class KDoubleNumInputPrivate;
KDoubleNumInputPrivate *d;
};
/* ------------------------------------------------------------------------ */
/**
* An integer inputline with scrollbar and slider.
*
* The class provides an easy interface to use other
* numeric systems then the decimal.
*
* @short An integer inputline with scrollbar and slider.
*/
kdelibs'KDoubleNumInput::KDoubleNumInput() (./kdelibs/kdeui/knuminput.cpp:536)
KDoubleNumInput::KDoubleNumInput(double value, QWidget *parent, const char *name)
: KNumInput(parent, name)
{
init(value);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::KDoubleNumInput() (./kdelibs/kdeui/knuminput.cpp:545)
KDoubleNumInput::KDoubleNumInput(KNumInput* below, double value, QWidget* parent,
const char* name)
: KNumInput(below, parent, name)
{
init(value);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::~KDoubleNumInput() (./kdelibs/kdeui/knuminput.cpp:555)
KDoubleNumInput::~KDoubleNumInput()
{
delete m_format;
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::init() (./kdelibs/kdeui/knuminput.cpp:563)
void KDoubleNumInput::init(double value)
{
m_value = value;
m_format = qstrdup("%.2f");
edit = new KDoubleLine(this, "KDoubleNumInput::QLineEdit");
edit->setAlignment(AlignRight);
edit->setValidator(new KFloatValidator(this, "KDoubleNumInput::KFloatValidator"));
edit->installEventFilter( this );
//setFocusProxy(edit);
m_suffix = m_prefix = "";
layout(true);
resetEditBox();
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::sliderMoved() (./kdelibs/kdeui/knuminput.cpp:583)
void KDoubleNumInput::sliderMoved(int val)
{
m_value = m_lower + (m_upper - m_lower)*(val/double(m_sliderstep));
resetEditBox();
emit valueChanged(m_value);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::minimumSizeHint() (./kdelibs/kdeui/knuminput.cpp:594)
QSize KDoubleNumInput::minimumSizeHint() const
{
constPolish();
int w = 0;
int h = 0;
// if in extra row, then count it here
if(m_label && (m_alignment & (AlignBottom|AlignTop)))
h += 4 + m_sizeLabel.height();
else
// no extra frame space
h += m_sizeLabel.height();
h += 2 + QMAX(m_sizeEdit.height(), m_sizeSlider.height());
w += m_slider ? m_slider->sizeHint().width() + 8 : 0;
w += m_colw1 + m_colw2;
if(m_alignment & (AlignTop|AlignBottom))
w = QMAX(w, m_sizeLabel.width() + 4);
return QSize(w, h);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::resizeEvent() (./kdelibs/kdeui/knuminput.cpp:622)
void KDoubleNumInput::resizeEvent(QResizeEvent* e)
{
int w = m_colw1;
int h = 0;
if(m_label && (m_alignment & AlignTop)) {
m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height());
h += m_sizeLabel.height() + 4;
}
if(m_label && (m_alignment & AlignVCenter))
m_label->setGeometry(0, 0, w, m_sizeEdit.height());
edit->setGeometry(w, h, m_slider ? m_colw2 : e->size().width() - w, m_sizeEdit.height());
w += m_colw2 + 8;
if(m_slider)
m_slider->setGeometry(w, h, e->size().width() - w, m_sizeEdit.height());
h += m_sizeEdit.height() + 2;
if(m_label && (m_alignment & AlignBottom))
m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height());
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::doLayout() (./kdelibs/kdeui/knuminput.cpp:650)
void KDoubleNumInput::doLayout()
{
// edit sizeHint
edit->constPolish();
QFontMetrics fm( edit->font() );
QString s;
int h = fm.height();
s.sprintf(m_format, m_value);
int w = fm.width(m_prefix) + fm.width(s) + fm.width(m_suffix);
w = QMAX(w, fm.width(m_specialvalue));
if(m_range) {
s.sprintf(m_format, m_lower);
w = QMAX(w, fm.width(s));
s.sprintf(m_format, m_upper);
w = QMAX(w, fm.width(s));
// something inbetween
s.sprintf(m_format, m_lower + m_step);
w = QMAX(w, fm.width(s));
}
if ( edit->frame() ) {
h += 8;
if ( edit->style() == WindowsStyle && h < 26 )
h = 22;
m_sizeEdit.setWidth(w + 8);
m_sizeEdit.setHeight(h);
} else {
m_sizeEdit.setWidth(w + 4);
m_sizeEdit.setHeight(h + 4);
}
m_colw2 = m_sizeEdit.width();
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::setValue() (./kdelibs/kdeui/knuminput.cpp:687)
void KDoubleNumInput::setValue(double val)
{
m_value = val;
if(m_value < m_lower) m_value = m_lower;
if(m_upper < m_value) m_value = m_upper;
if(m_slider) {
int slvalue = int(((m_value - m_lower)/(m_upper - m_lower))*m_sliderstep);
m_slider->setValue(slvalue);
}
resetEditBox();
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::setRange() (./kdelibs/kdeui/knuminput.cpp:705)
void KDoubleNumInput::setRange(double lower, double upper, double step, bool slider)
{
m_lower = lower;
m_upper = upper;
m_step = step;
m_range = (m_lower < m_upper);
// bounds checking the values
if(m_value < m_lower) m_value = m_lower;
if(m_upper < m_lower) m_upper = m_value;
if(m_upper < m_value) m_value = m_upper;
// make m_value a multiple of step
m_value = floor(m_value / m_step) * m_step;
if(slider) {
m_sliderstep = int(floor(QMIN((m_upper - m_lower)/m_step, double(INT_MAX-5e7))));
int slvalue = int(((m_value - m_lower)/(m_upper - m_lower))*m_sliderstep);
m_slider = new QSlider(0, m_sliderstep, 1, slvalue,
QSlider::Horizontal, this);
m_slider->setTickmarks(QSlider::Below);
m_slider->setTickInterval(m_slider->maxValue() / 10);
connect(m_slider, SIGNAL(valueChanged(int)), SLOT(sliderMoved(int)));
}
else {
delete m_slider;
m_slider = 0;
}
resetEditBox();
layout(true);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::value() (./kdelibs/kdeui/knuminput.cpp:741)
double KDoubleNumInput::value() const
{
return m_value;
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::setSuffix() (./kdelibs/kdeui/knuminput.cpp:748)
void KDoubleNumInput::setSuffix(QString suffix)
{
m_suffix = suffix;
resetEditBox();
layout(true);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::setPrefix() (./kdelibs/kdeui/knuminput.cpp:758)
void KDoubleNumInput::setPrefix(QString prefix)
{
m_prefix = prefix;
resetEditBox();
layout(true);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::setFormat() (./kdelibs/kdeui/knuminput.cpp:768)
void KDoubleNumInput::setFormat(const char* fmt)
{
m_format = qstrdup(fmt);
resetEditBox();
layout(true);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::resetEditBox() (./kdelibs/kdeui/knuminput.cpp:778)
void KDoubleNumInput::resetEditBox()
{
if(!m_specialvalue.isEmpty() && (fabs(m_value - m_lower) < 1e-10))
edit->setText(m_specialvalue);
else {
QString s;
s.sprintf(m_format, m_value);
edit->setText(m_prefix + s + m_suffix);
}
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::setSpecialValueText() (./kdelibs/kdeui/knuminput.cpp:792)
void KDoubleNumInput::setSpecialValueText(const QString& text)
{
m_specialvalue = text;
resetEditBox();
layout(true);
};
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::setLabel() (./kdelibs/kdeui/knuminput.cpp:803)
void KDoubleNumInput::setLabel(QString label, int a)
{
KNumInput::setLabel(label, a);
if(m_label)
m_label->setBuddy(edit);
}
// -----------------------------------------------------------------------------
kdelibs'KDoubleNumInput::eventFilter() (./kdelibs/kdeui/knuminput.cpp:814)
bool KDoubleNumInput::eventFilter( QObject* obj, QEvent* ev )
{
if ( obj != edit )
return false;
bool revalue = false;
double old_value = m_value;
if (ev->type() == QEvent::FocusOut || ev->type() == QEvent::Leave) {
edit->interpretText();
revalue = false;
} else if ( ev->type() == QEvent::KeyPress ) {
QKeyEvent* k = (QKeyEvent*)ev;
if ( k->key() == Key_Up || k->text() == "+" ) {
if(m_range)
m_value += m_step;
revalue = true;
} else if ( k->key() == Key_Down || k->text() == "-" ) {
if(m_range)
m_value -= m_step;
revalue = true;
} else if ( k->key() == Key_Return ) {
edit->interpretText();
revalue = false;
}
}
if(m_value != old_value) {
setValue(m_value);
emit valueChanged(m_value);
}
return revalue;
}
// -----------------------------------------------------------------------------