5
5
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
6
6
//=========================================================
14
#include <QMouseEvent>
16
#include <QPaintEvent>
18
#include <QResizeEvent>
21
#include <QTimerEvent>
8
25
#include "sigedit.h"
10
#include <qrangecontrol.h>
11
#include <qapplication.h>
13
#include <qapplication.h>
14
#include <qvaluelist.h>
22
28
extern int mtcType;
68
74
//---------------------------------------------------------
70
class SigEditor : public QWidget
76
class SigEditor : public QLineEdit
76
QValueList<NumberSection> sections;
82
QList<NumberSection> sections;
79
85
int section(const QPoint&);
84
90
void resizeEvent(QResizeEvent*);
85
91
void paintEvent(QPaintEvent*);
86
92
void mousePressEvent(QMouseEvent *e);
93
void keyPressEvent(QKeyEvent * event );
87
94
void applyFocusSelection() {}
99
106
void appendSection(const NumberSection& sec);
100
107
void clearSections();
101
108
void setSectionSelection(int sec, int selstart, int selend);
102
bool eventFilter(QObject *o, QEvent *e);
105
111
//---------------------------------------------------------
111
117
if (pm->isNull())
114
int fw = frm ? style().pixelMetric(QStyle::PM_DefaultFrameWidth) : 0;
120
int fw = frm ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth) : 0;
118
124
int h = height();
119
for (unsigned int i = 0; i < sections.count(); ++i) {
125
for (int i = 0; i < sections.count(); ++i) {
120
126
QString s = cw->sectionFormattedText(i);
121
QRect bb = p.boundingRect(x, y, w, h, AlignVCenter|AlignLeft, s);
127
QRect bb = p.boundingRect(x, y, w, h, Qt::AlignVCenter|Qt::AlignLeft, s);
122
128
int nx = bb.x() + bb.width();
123
129
if (pt.x() >= x && pt.x() < nx)
126
132
if (i < sections.count()-1) {
128
p.drawText(x, y, w, h, AlignVCenter|AlignLeft, s, -1, &bb);
134
p.drawText(x, y, w, h, Qt::AlignVCenter|Qt::AlignLeft, s, -1, &bb);
129
135
x = bb.x() + bb.width();
163
170
void SigEditor::init()
165
setBackgroundMode(PaletteBase);
172
setBackgroundMode(Qt::PaletteBase);
166
173
setFocusSection(-1);
167
174
setKeyCompression(true);
168
installEventFilter(this);
169
setFocusPolicy(WheelFocus);
175
setFocusPolicy(Qt::WheelFocus);
172
178
//---------------------------------------------------------
178
184
if (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut) {
179
185
repaint( rect(), false);
181
else if (e->type() == QEvent::AccelOverride) {
187
else if (e->type() == QEvent::ShortcutOverride) {
182
188
QKeyEvent* ke = (QKeyEvent*) e;
183
189
switch (ke->key()) {
191
case Qt::Key_Backspace:
195
return QWidget::event(e);
201
return QLineEdit::event(e);
198
204
void SigEditor::resizeEvent(QResizeEvent *e)
200
206
pm->resize(e->size());
201
QWidget::resizeEvent(e);
207
QLineEdit::resizeEvent(e);
204
210
//---------------------------------------------------------
215
221
p.setPen(colorGroup().text());
216
222
QBrush bg = cg.brush(QColorGroup::Base);
218
int fw = frm ? style().pixelMetric(QStyle::PM_DefaultFrameWidth) : 0;
224
int fw = frm ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth) : 0;
222
228
int h = height();
223
229
p.fillRect(0, 0, w, h, bg);
225
for (unsigned int i = 0; i < sections.count(); ++i) {
231
for (int i = 0; i < sections.count(); ++i) {
227
233
QString s = cw->sectionFormattedText(i);
229
235
if (hasFocus() && (int(i) == focusSec)) {
230
236
QBrush bg = cg.brush(QColorGroup::Highlight);
231
QRect r = p.boundingRect(x, y, w, h, AlignVCenter|AlignLeft, s, -1);
237
QRect r = p.boundingRect(x, y, w, h, Qt::AlignVCenter|Qt::AlignLeft, s, -1);
232
238
p.setPen(colorGroup().highlightedText());
233
239
p.fillRect(r, bg);
236
242
p.setPen(colorGroup().text());
237
p.drawText(x, y, w, h, AlignVCenter|AlignLeft, s, -1, &bb);
243
p.drawText(x, y, w, h, Qt::AlignVCenter|Qt::AlignLeft, s, -1, &bb);
238
244
x = bb.x() + bb.width();
239
245
if (i < sections.count()-1) {
241
p.drawText(x, y, w, h, AlignVCenter|AlignLeft, s, -1, &bb);
247
p.drawText(x, y, w, h, Qt::AlignVCenter|Qt::AlignLeft, s, -1, &bb);
242
248
x = bb.x() + bb.width();
263
269
//---------------------------------------------------------
265
271
//---------------------------------------------------------
267
bool SigEditor::eventFilter(QObject *o, QEvent *e)
273
void SigEditor::keyPressEvent(QKeyEvent * e )
271
if (e->type() != QEvent::KeyPress )
274
QKeyEvent *ke = (QKeyEvent*)e;
277
277
if (unsigned(focusSec) <= sections.count()) {
278
278
if (cw->setFocusSection(focusSec+1))
279
279
repaint(rect(), false);
283
282
if (focusSec > 0 ) {
284
283
if (cw->setFocusSection(focusSec-1))
285
284
repaint(rect(), false);
290
case Qt::Key_Backspace:
296
292
cw->removeLastNumber(focusSec);
300
295
cw->enterPressed();
303
QString txt = ke->text();
297
QString txt = e->text();
304
298
if (!txt.isEmpty() && txt[0] == '/') {
305
299
// do the same thing as KEY_RIGHT when the user presses the separator key
306
300
if (focusSec < (signed)(sections.count())) {
307
301
if (cw->setFocusSection(focusSec+1))
308
302
repaint(rect(), false);
312
305
int num = txt[0].digitValue();
314
//printf("SigEditor::eventFilter num:%d\n", num);
307
//printf("SigEditor::keyPressEvent num:%d\n", num);
317
310
cw->addNumber(focusSec, num);
324
315
void SigEditor::appendSection(const NumberSection& sec)
380
372
void SigEdit::init()
382
374
ed = new SigEditor(this, "pos editor");
383
controls = new QSpinWidget(this, "pos edit controls");
384
controls->setEditWidget(ed);
375
controls = new SpinBox(this);
376
controls->setEditor(ed);
385
377
setFocusProxy(ed);
386
378
connect(controls, SIGNAL(stepUpPressed()), SLOT(stepUp()));
387
379
connect(controls, SIGNAL(stepDownPressed()), SLOT(stepDown()));
422
414
void SigEdit::setValue(const QString& s)
425
sscanf(s.latin1(), "%d/%d", &z, &n);
417
sscanf(s.toLatin1(), "%d/%d", &z, &n);
633
625
QString txt = sectionText(secNo);
635
//printf("SigEdit::addNumber secNo:%d num:%d voff:%d txt:%s\n", secNo, num, voff, txt.latin1());
627
//printf("SigEdit::addNumber secNo:%d num:%d voff:%d txt:%s\n", secNo, num, voff, txt.toLatin1());
637
if (txt.length() == sec[secNo].len) {
629
if ((unsigned) txt.length() == sec[secNo].len) {
638
630
//printf("SigEdit::addNumber txt.length() == sec[secNo].len (%d)\n", sec[secNo].len);
640
632
if (!outOfRange(secNo, num - voff)) {
651
643
int temp = txt.toInt() - voff;
652
644
if (outOfRange(secNo, temp))
654
//printf("SigEdit::addNumber not accepted secNo:%d txt:%s temp:%d\n", secNo, txt.latin1(), temp);
646
//printf("SigEdit::addNumber not accepted secNo:%d txt:%s temp:%d\n", secNo, txt.toLatin1(), temp);
656
648
txt = sectionText(secNo);
702
694
QSize SigEdit::sizeHint() const
704
696
QFontMetrics fm(font());
705
int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
697
int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this); // ddskrjo
706
698
int h = fm.height() + fw * 2;
707
int w = 2 + controls->upRect().width() + fw * 4;
700
int w = 2 + controls->arrowWidth() + fw * 4;
708
701
w += fm.width('9') * 5 + fm.width('/');
709
702
return QSize(w, h).expandedTo(QApplication::globalStrut());
733
726
case 128: upEnabled = false; break;
736
controls->setUpEnabled(isEnabled() && upEnabled);
737
controls->setDownEnabled(isEnabled() && downEnabled);
729
controls->setStepEnabled(isEnabled() & upEnabled, isEnabled() & downEnabled);
740
732
//---------------------------------------------------------