Files
qad/qad/widgets/clineedit.h
2020-04-30 16:07:01 +03:00

66 lines
1.7 KiB
C++

/*
QAD - Qt ADvanced
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CLINEEDIT_H
#define CLINEEDIT_H
#include <QDebug>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPainter>
#include "qad_export.h"
class QAD_EXPORT CLineEdit: public QLineEdit
{
Q_OBJECT
Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
public:
explicit CLineEdit(QWidget * parent = 0);
~CLineEdit() {delete cw;}
const QString & defaultText() const {return dt;}
protected:
QWidget * cw;
QString dt;
QImage clear_im;
private:
bool eventFilter(QObject * o, QEvent * e);
void resizeEvent(QResizeEvent * );
void changeEvent(QEvent * e);
void cwPaintEvent();
private slots:
void clearMouseRelease(QMouseEvent * e) {if (cw->rect().contains(e->pos())) clearClick();}
void textChanged_(QString text) {cw->setVisible(text != dt);}
public slots:
void clearClick() {if (!isEnabled()) return; setText(dt); emit cleared(); emit textEdited(dt);}
void setDefaultText(const QString & t, bool set_text = false);
signals:
void cleared();
};
#endif // CLINEEDIT_H