summaryrefslogtreecommitdiffstats
path: root/ksysv/SpinBox.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit37333bf25ad9a4c538250f5af2f9f1d666362883 (patch)
treec45e8df5b9efbffe07eb3d9340df7811c7e16943 /ksysv/SpinBox.cpp
downloadtdeadmin-37333bf25ad9a4c538250f5af2f9f1d666362883.tar.gz
tdeadmin-37333bf25ad9a4c538250f5af2f9f1d666362883.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeadmin@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksysv/SpinBox.cpp')
-rw-r--r--ksysv/SpinBox.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/ksysv/SpinBox.cpp b/ksysv/SpinBox.cpp
new file mode 100644
index 0000000..63a217a
--- /dev/null
+++ b/ksysv/SpinBox.cpp
@@ -0,0 +1,87 @@
+// (c) 2000 Peter Putzer
+
+#include <qlineedit.h>
+
+#include <kdebug.h>
+
+#include "ksv_core.h"
+#include "SpinBox.h"
+
+KSVSpinBox::KSVSpinBox (QWidget* parent, const char* name)
+ : QSpinBox (0, 99, 1, parent, name),
+ KCompletionBase (),
+ mClearedSelection (false)
+{
+ KCompletion* comp = ksv::numberCompletion();
+ setCompletionObject (comp, true);
+
+ editor()->installEventFilter (this);
+
+ connect (editor(), SIGNAL (textChanged (const QString&)),
+ comp, SLOT (slotMakeCompletion (const QString&)));
+ connect (comp, SIGNAL (match (const QString&)),
+ this, SLOT (handleMatch (const QString&)));
+}
+
+KSVSpinBox::~KSVSpinBox ()
+{
+}
+
+QString KSVSpinBox::mapValueToText (int value)
+{
+ QString result;
+
+ if (value < 10)
+ result.sprintf("%.2i", value);
+ else
+ result.setNum (value);
+
+ return result;
+}
+
+void KSVSpinBox::setCompletedText (const QString& text)
+{
+ QLineEdit* e = editor ();
+ const int pos = e->cursorPosition();
+
+ e->setText (text);
+
+ e->setSelection (pos, text.length());
+ e->setCursorPosition (pos);
+}
+
+void KSVSpinBox::setCompletedItems (const QStringList& /*items*/)
+{
+ // dont know what is supposed to be in here but it has to be defined
+ // because else the lack of this damn thing is making it abstract
+}
+
+void KSVSpinBox::handleMatch (const QString& match)
+{
+ if (!match.isNull() && editor()->text().length() < 2 && !mClearedSelection)
+ setCompletedText (match);
+}
+
+bool KSVSpinBox::eventFilter (QObject* o, QEvent* e)
+{
+ Q_UNUSED(o);
+ if (e->type() == QEvent::KeyPress)
+ {
+ QKeyEvent* ke = static_cast<QKeyEvent*> (e);
+
+ switch (ke->key())
+ {
+ case Key_BackSpace:
+ case Key_Delete:
+ mClearedSelection = true;
+ break;
+
+ default:
+ mClearedSelection = false;
+ }
+ }
+
+ return false;
+}
+
+#include "SpinBox.moc"