QElectroTech
0.70
sources
qfilenameedit.cpp
Go to the documentation of this file.
1
/*
2
Copyright 2006-2019 The QElectroTech Team
3
This file is part of QElectroTech.
4
5
QElectroTech is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 2 of the License, or
8
(at your option) any later version.
9
10
QElectroTech is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
#include "
qfilenameedit.h
"
19
#include "
qetregexpvalidator.h
"
20
#include <QKeyEvent>
21
#include <QRegExp>
22
#include <QToolTip>
23
28
QFileNameEdit::QFileNameEdit
(QWidget *parent) : QLineEdit(parent) {
29
init
();
30
}
31
37
QFileNameEdit::QFileNameEdit
(
const
QString &contents, QWidget *parent) : QLineEdit(parent) {
38
init
();
39
if
(!contents.isEmpty() &&
regexp_
.exactMatch(contents)) {
40
setText(contents);
41
}
42
}
43
47
QFileNameEdit::~QFileNameEdit
() {
48
}
49
53
bool
QFileNameEdit::isEmpty
() {
54
return
(text().
isEmpty
());
55
}
56
60
bool
QFileNameEdit::isValid
() {
61
return
(
regexp_
.exactMatch(text()));
62
}
63
67
void
QFileNameEdit::init
() {
68
regexp_
= QRegExp(
"^[0-9a-z_\\-\\.]+$"
, Qt::CaseSensitive);
69
validator_
=
new
QETRegExpValidator
(
regexp_
,
this
);
70
setValidator(
validator_
);
71
tooltip_text_
= QString(
72
tr
(
73
"Les caractères autorisés sont : \n"
74
" - les chiffres [0-9]\n"
75
" - les minuscules [a-z]\n"
76
" - le tiret [-], l'underscore [_] et le point [.]\n"
,
77
"tooltip content when editing a filename"
78
)
79
);
80
connect(
validator_
, SIGNAL(
validationFailed
()),
this
, SLOT(
validationFailed
()));
81
}
82
86
void
QFileNameEdit::displayToolTip
() {
87
QToolTip::showText(
88
mapToGlobal(QPoint(x() + width(), 0)),
89
tooltip_text_
,
90
this
,
91
QRect()
92
);
93
}
94
98
void
QFileNameEdit::validationFailed
() {
99
displayToolTip
();
100
}
QFileNameEdit::validator_
QETRegExpValidator * validator_
Definition:
qfilenameedit.h:58
QETRegExpValidator
Definition:
qetregexpvalidator.h:25
QFileNameEdit::isEmpty
bool isEmpty()
Definition:
qfilenameedit.cpp:53
QFileNameEdit::validationFailed
void validationFailed()
Definition:
qfilenameedit.cpp:98
QFileNameEdit::init
void init()
Definition:
qfilenameedit.cpp:67
QET::Icons::tr
QIcon tr
Definition:
qeticons.cpp:204
qetregexpvalidator.h
QFileNameEdit::QFileNameEdit
QFileNameEdit(QWidget *=nullptr)
Definition:
qfilenameedit.cpp:28
QFileNameEdit::~QFileNameEdit
~QFileNameEdit() override
Definition:
qfilenameedit.cpp:47
qfilenameedit.h
QFileNameEdit::regexp_
QRegExp regexp_
Definition:
qfilenameedit.h:57
QFileNameEdit::tooltip_text_
QString tooltip_text_
Definition:
qfilenameedit.h:59
QFileNameEdit::displayToolTip
void displayToolTip()
Definition:
qfilenameedit.cpp:86
QFileNameEdit::isValid
bool isValid()
Definition:
qfilenameedit.cpp:60
Generated by
1.8.15