-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilenamelineedit.cpp
50 lines (42 loc) · 1.06 KB
/
filenamelineedit.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
#include "filenamelineedit.h"
#include <QKeyEvent>
FileNameLineEdit::FileNameLineEdit(QWidget *parent)
: QLineEdit(parent)
{
this->InitLineEdit();
}
FileNameLineEdit::~FileNameLineEdit()
{
}
void FileNameLineEdit::InitLineEdit()
{
this->setReadOnly(true);
this->setMaxLength(256);
}
void FileNameLineEdit::focusOutEvent(QFocusEvent* event)
{
if (!this->isReadOnly())
{
this->setReadOnly(true);
m_strNewName = QLineEdit::text().trimmed();
emit SignalNameChanged(m_strNewName,m_strOldName);
}
QLineEdit::focusOutEvent(event);
}
void FileNameLineEdit::mouseDoubleClickEvent(QMouseEvent* event)
{
this->setReadOnly(false);
this->setFocus();
m_strOldName = QLineEdit::text().trimmed();
QLineEdit::mouseDoubleClickEvent(event);
}
void FileNameLineEdit::keyPressEvent(QKeyEvent* event)
{
int nKey = event->key();
bool blEndEdit = nKey == Qt::Key_Return || nKey == Qt::Key_Enter || nKey == Qt::Key_Escape || nKey == Qt::Key_Tab;
if (blEndEdit)
{
this->clearFocus();
}
QLineEdit::keyPressEvent(event);
}