-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiisLineEdit.cpp
executable file
·108 lines (85 loc) · 2.62 KB
/
iisLineEdit.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
/*
* iisLineEdit.cpp
*
* Created on: 29.07.2008
*/
#include "iisLineEdit.h"
int iisLineEdit::MinHeight = 0;
int iisLineEdit::MaxHeight = 0;
iisLineEdit::iisLineEdit(QWidget *parent) : QWidget(parent)
{
QHBoxLayout *hbl = new QHBoxLayout();
hbl->setMargin(0);
hbl->setSpacing(0);
setLayout(hbl);
myLineEdit = new QLineEdit(this);
myLineEdit->installEventFilter(this);
if (MinHeight)
myLineEdit->setMinimumHeight(MinHeight);
if (MaxHeight)
myLineEdit->setMaximumHeight(MaxHeight);
myButton = new QToolButton(this);
myButton->setFocusPolicy(Qt::NoFocus);
hbl->addWidget(myLineEdit);
hbl->addWidget(myButton);
connect(myButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
connect(myLineEdit, SIGNAL(textEdited(const QString &)), this, SLOT(handleTextEdited(const QString &)));
}
iisLineEdit::~iisLineEdit()
{
// TODO Auto-generated destructor stub
}
bool iisLineEdit::eventFilter(QObject *obj, QEvent *event)
{
if (obj == myLineEdit) {
switch (event->type()) {
case QEvent::FocusOut:
emit lostFocus(this);
break;
case QEvent::FocusIn:
emit gotFocus(this);
break;
case QEvent::Resize: {
int w = ((QResizeEvent*)event)->size().height();
myButton->setFixedSize(w,w);
return true;
}
default:;
}
}
return QObject::eventFilter(obj, event);
}
void iisLineEdit::setPickTitle(const QString &title)
{
myTitlePicker = title;
}
////////////////////////////////////////////////////////////////////////////////
QIcon iisLineEditDir::IconPickDir;
iisLineEditDir::iisLineEditDir(QWidget *parent) : iisLineEdit(parent)
{
myButton->setIcon(IconPickDir);
}
void iisLineEditDir::buttonClicked()
{
QString dir = QFileDialog::getExistingDirectory(this,
myTitlePicker, myLineEdit->text());
if (!dir.isEmpty()) {
myLineEdit->setText(dir);
emit buttonClickedOk(this);
}
}
////////////////////////////////////////////////////////////////////////////////
QIcon iisLineEditFile::IconPickFile;
iisLineEditFile::iisLineEditFile(QWidget *parent) : iisLineEdit(parent)
{
myButton->setIcon(IconPickFile);
}
void iisLineEditFile::buttonClicked()
{
QString file = QFileDialog::getOpenFileName(this,
myTitlePicker, myLineEdit->text());
if (!file.isEmpty()) {
myLineEdit->setText(file);
emit buttonClickedOk(this);
}
}