forked from foldynl/QLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditLine.cpp
110 lines (89 loc) · 2.67 KB
/
EditLine.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <QFocusEvent>
#include <QCompleter>
#include <QSerialPortInfo>
#include "EditLine.h"
NewContactEditLine::NewContactEditLine(QWidget *parent) :
QLineEdit(parent),
spaceForbiddenFlag(false)
{
}
void NewContactEditLine::focusInEvent(QFocusEvent *event)
{
QLineEdit::focusInEvent(event);
Qt::FocusReason reason = event->reason();
if ( reason != Qt::ActiveWindowFocusReason &&
reason != Qt::PopupFocusReason )
{
end(false);
emit focusIn();
}
//Deselect text when focus
if ( hasSelectedText() && reason != Qt::PopupFocusReason )
{
deselect();
}
}
void NewContactEditLine::focusOutEvent(QFocusEvent *event)
{
QLineEdit::focusOutEvent(event);
Qt::FocusReason reason = event->reason();
if ( reason != Qt::ActiveWindowFocusReason &&
reason != Qt::PopupFocusReason )
{
home(false);
emit focusOut();
}
}
void NewContactEditLine::keyPressEvent(QKeyEvent *event)
{
if ( spaceForbiddenFlag && event->key() == Qt::Key_Space )
focusNextChild();
else
QLineEdit::keyPressEvent(event);
}
void NewContactEditLine::setText(const QString &text)
{
QLineEdit::setText(text);
home(false);
}
void NewContactEditLine::spaceForbidden(bool inSpaceForbidden)
{
spaceForbiddenFlag = inSpaceForbidden;
}
NewContactRSTEditLine::NewContactRSTEditLine(QWidget *parent) :
NewContactEditLine(parent),
focusInSelectionBackwardOffset(1)
{
}
void NewContactRSTEditLine::setSelectionBackwardOffset(int offset)
{
focusInSelectionBackwardOffset = offset;
}
void NewContactRSTEditLine::focusInEvent(QFocusEvent *event)
{
NewContactEditLine::focusInEvent(event);
if ( event->reason() != Qt::PopupFocusReason && !text().isEmpty() && text().length() >= focusInSelectionBackwardOffset )
setSelection(text().length() - focusInSelectionBackwardOffset, 1);
}
SerialPortEditLine::SerialPortEditLine(QWidget *parent) :
QLineEdit(parent)
{
#if defined(Q_OS_WIN)
// setInputMask("COM000"); // temporarily removed - it does not work in a user-friendly
// because when you click, the cursor can reach the end
// and in that case the mask does not work correctly.
QStringList portNames;
const QList<QSerialPortInfo> &ports = QSerialPortInfo::availablePorts();
for ( const QSerialPortInfo &port : ports )
portNames << port.portName();
setCompleter(new QCompleter(portNames));
#endif
}
void SerialPortEditLine::focusInEvent(QFocusEvent *event)
{
QLineEdit::focusInEvent(event);
#if defined(Q_OS_WIN)
completer()->setCompletionPrefix("COM");
completer()->complete();
#endif
}