summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_int_spinbox.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chalk/ui/kis_int_spinbox.cc')
-rw-r--r--chalk/ui/kis_int_spinbox.cc198
1 files changed, 198 insertions, 0 deletions
diff --git a/chalk/ui/kis_int_spinbox.cc b/chalk/ui/kis_int_spinbox.cc
new file mode 100644
index 00000000..8dc0e68d
--- /dev/null
+++ b/chalk/ui/kis_int_spinbox.cc
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
+ * Copyright (c) 2006 Casper Boemann <cbr@boemann.dk>
+ *
+ * Requires the TQt 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#include <assert.h>
+#include <math.h>
+#include <algorithm>
+
+#include <tqtimer.h>
+#include <tqapplication.h>
+#include <tqsize.h>
+#include <tqslider.h>
+#include <tqstyle.h>
+#include <tqlabel.h>
+#include <tqpopupmenu.h>
+#include <tqlineedit.h>
+#include <tqlayout.h>
+#include <tqvalidator.h>
+
+#include <knuminput.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <karrowbutton.h>
+
+#include "kdialog.h"
+#include "knumvalidator.h"
+#include "kis_int_spinbox.h"
+
+class KisIntSpinbox::KisIntSpinboxPrivate {
+public:
+
+ KIntSpinBox * m_numinput;
+ KisPopupSlider *m_slider;
+ KArrowButton *m_arrow;
+ int m_prevValue;
+ TQValidator *m_validator;
+ TQTimer m_timer;
+};
+
+
+KisIntSpinbox::KisIntSpinbox(TQWidget *tqparent, const char *name)
+ : TQWidget(tqparent, name)
+{
+ init(0);
+}
+
+KisIntSpinbox::KisIntSpinbox(const TQString & /*label*/, int val, TQWidget *tqparent, const char *name)
+ : TQWidget(tqparent, name)
+{
+ init(val);
+}
+
+void KisIntSpinbox::init(int val)
+{
+ d = new KisIntSpinboxPrivate( );
+ TQBoxLayout * l = new TQHBoxLayout( this );
+
+ l->insertStretch(0, 1);
+ d->m_numinput = new KIntSpinBox(0, 100, 1, val, 10, this, "KisIntSpinbox::KIntSpinBox");
+
+ d->m_numinput->tqsetSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Fixed);
+ d->m_numinput->setSuffix("%");
+ l->addWidget( d->m_numinput );
+
+ d->m_slider = new KisPopupSlider(0, 100, 10, val, Qt::Horizontal, this);
+ d->m_slider->setFrameStyle(TQFrame::Panel|TQFrame::Raised);
+
+ d->m_arrow = new KArrowButton(this, Qt::DownArrow);
+ d->m_arrow->setPopup(d->m_slider);
+ d->m_arrow->setMaximumHeight( fontMetrics().height() + 4);
+ d->m_arrow->setEnabled(true); // Why is the arrow still gray?
+
+ l->addWidget( d->m_arrow );
+
+ d->m_prevValue = val;
+ setValue(val);
+ setFocusProxy(d->m_numinput);
+ tqlayout();
+
+ connect(d->m_numinput, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(spinboxValueChanged(int)));
+ connect(d->m_slider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(sliderValueChanged(int)));
+ connect(d->m_slider, TQT_SIGNAL(aboutToShow()), TQT_SLOT(slotAboutToShow()));
+ connect(d->m_slider, TQT_SIGNAL(aboutToHide()), TQT_SLOT(slotAboutToHide()));
+
+ connect(&(d->m_timer), TQT_SIGNAL(timeout()), this, TQT_SLOT(slotTimeout()));
+}
+
+void KisIntSpinbox::spinboxValueChanged(int val)
+{
+ setValue(val);
+ d->m_timer.start(300, true);
+
+}
+
+void KisIntSpinbox::sliderValueChanged(int val)
+{
+ setValue(val);
+ emit valueChanged(val);
+ emit valueChanged(val, true);
+}
+
+void KisIntSpinbox::setRange(int lower, int upper, int /*step*/)
+{
+ upper = kMax(upper, lower);
+ lower = kMin(upper, lower);
+ d->m_slider->setRange(lower, upper);
+
+ tqlayout();
+}
+
+void KisIntSpinbox::setMinValue(int min)
+{
+ setRange(min, maxValue(), d->m_slider->lineStep());
+}
+
+int KisIntSpinbox::minValue() const
+{
+ return d->m_slider->minValue();
+}
+
+void KisIntSpinbox::setMaxValue(int max)
+{
+ setRange(minValue(), max, d->m_slider->lineStep());
+}
+
+int KisIntSpinbox::maxValue() const
+{
+ return d->m_slider->maxValue();
+}
+
+KisIntSpinbox::~KisIntSpinbox()
+{
+ delete d;
+}
+
+void KisIntSpinbox::setValue(int val)
+{
+ d->m_slider->blockSignals(true);
+ d->m_slider->setValue(val);
+ d->m_slider->blockSignals(false);
+
+ d->m_numinput->blockSignals(true);
+ d->m_numinput->setValue(val);
+ d->m_numinput->blockSignals(false);
+}
+
+int KisIntSpinbox::value() const
+{
+ return d->m_numinput->value(); // From the numinput: that one isn't in steps of ten
+}
+
+void KisIntSpinbox::setLabel(const TQString & /*label*/)
+{
+}
+
+void KisIntSpinbox::slotAboutToShow()
+{
+ d->m_prevValue = value();
+}
+
+void KisIntSpinbox::slotAboutToHide()
+{
+ if( d->m_prevValue != value() )
+ {
+ emit finishedChanging( d->m_prevValue, value() );
+ d->m_prevValue = value();
+ }
+}
+
+void KisIntSpinbox::slotTimeout()
+{
+ emit valueChanged(value());
+ emit valueChanged(value(), true);
+}
+#include "kis_int_spinbox.moc"