1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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"
|