refactoring qad widgets part 1
c++ cast, nullptr, forward declaration, agregate ui, connect to member functions, order and clear includes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "clineedit.h"
|
||||
#include "qad_types.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
|
||||
@@ -9,7 +11,7 @@ CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
|
||||
cw->setToolTip(tr("Clear"));
|
||||
cw->hide();
|
||||
cw->installEventFilter(this);
|
||||
connect(this, SIGNAL(textChanged(QString)), this, SLOT(textChanged_(QString)));
|
||||
connect(this, &QLineEdit::textChanged, this, &CLineEdit::textChangedSlot);
|
||||
int is = fontHeight(this);
|
||||
QMargins m = textMargins();
|
||||
m.setRight(m.right() + (is * 1.2));
|
||||
@@ -17,10 +19,15 @@ CLineEdit::CLineEdit(QWidget * parent): QLineEdit(parent) {
|
||||
}
|
||||
|
||||
|
||||
CLineEdit::~CLineEdit() {
|
||||
delete cw;
|
||||
}
|
||||
|
||||
|
||||
bool CLineEdit::eventFilter(QObject * o, QEvent * e) {
|
||||
switch (e->type()) {
|
||||
case QEvent::MouseButtonRelease:
|
||||
clearMouseRelease((QMouseEvent * )e);
|
||||
clearMouseRelease(static_cast<QMouseEvent *>(e));
|
||||
break;
|
||||
case QEvent::Paint:
|
||||
cwPaintEvent();
|
||||
@@ -62,5 +69,17 @@ void CLineEdit::setDefaultText(const QString & t, bool set_text) {
|
||||
cw->hide();
|
||||
return;
|
||||
}
|
||||
textChanged_(text());
|
||||
textChangedSlot(text());
|
||||
}
|
||||
|
||||
|
||||
void CLineEdit::clearMouseRelease(QMouseEvent *e) {
|
||||
if (cw->rect().contains(e->pos())) {
|
||||
clearClick();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CLineEdit::textChangedSlot(QString text) {
|
||||
cw->setVisible(text != dt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user