QElectroTech  0.70
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 
48 }
49 
54  return(text().isEmpty());
55 }
56 
61  return(regexp_.exactMatch(text()));
62 }
63 
68  regexp_ = QRegExp("^[0-9a-z_\\-\\.]+$", Qt::CaseSensitive);
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 
87  QToolTip::showText(
88  mapToGlobal(QPoint(x() + width(), 0)),
90  this,
91  QRect()
92  );
93 }
94 
100 }
QETRegExpValidator * validator_
Definition: qfilenameedit.h:58
void validationFailed()
QIcon tr
Definition: qeticons.cpp:204
QFileNameEdit(QWidget *=nullptr)
~QFileNameEdit() override
QRegExp regexp_
Definition: qfilenameedit.h:57
QString tooltip_text_
Definition: qfilenameedit.h:59
void displayToolTip()