Browse Source

Follow project coding style. Issue #2192.

adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
ccec11e568
  1. 70
      src/gui/lineedit/src/lineedit.cpp
  2. 12
      src/gui/lineedit/src/lineedit.h

70
src/gui/lineedit/src/lineedit.cpp

@ -14,59 +14,59 @@
#include <QResizeEvent> #include <QResizeEvent>
LineEdit::LineEdit(QWidget *parent) LineEdit::LineEdit(QWidget *parent)
: QLineEdit(parent) : QLineEdit(parent)
{ {
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
QPixmap pixmap1(":/lineeditimages/search.png"); QPixmap pixmap1(":/lineeditimages/search.png");
searchButton = new QToolButton(this); searchButton = new QToolButton(this);
searchButton->setIcon(QIcon(pixmap1)); searchButton->setIcon(QIcon(pixmap1));
searchButton->setIconSize(pixmap1.size()); searchButton->setIconSize(pixmap1.size());
searchButton->setCursor(Qt::ArrowCursor); searchButton->setCursor(Qt::ArrowCursor);
searchButton->setStyleSheet("QToolButton { border: none; padding: 2px; }"); searchButton->setStyleSheet("QToolButton { border: none; padding: 2px; }");
int clearButtonSizeHintWidth = 0; int clearButtonSizeHintWidth = 0;
int clearButtonSizeHintHeight = 0; int clearButtonSizeHintHeight = 0;
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QPixmap pixmap2(":/lineeditimages/clear_left.png"); QPixmap pixmap2(":/lineeditimages/clear_left.png");
clearButton = new QToolButton(this); clearButton = new QToolButton(this);
clearButton->setIcon(QIcon(pixmap2)); clearButton->setIcon(QIcon(pixmap2));
clearButton->setIconSize(pixmap2.size()); clearButton->setIconSize(pixmap2.size());
clearButton->setCursor(Qt::ArrowCursor); clearButton->setCursor(Qt::ArrowCursor);
clearButton->setStyleSheet("QToolButton { border: none; padding: 2px; }"); clearButton->setStyleSheet("QToolButton { border: none; padding: 2px; }");
clearButton->setToolTip(tr("Clear the text")); clearButton->setToolTip(tr("Clear the text"));
clearButton->hide(); clearButton->hide();
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&))); connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(updateCloseButton(const QString &)));
clearButtonSizeHintWidth = clearButton->sizeHint().width(); clearButtonSizeHintWidth = clearButton->sizeHint().width();
clearButtonSizeHintHeight = clearButton->sizeHint().height(); clearButtonSizeHintHeight = clearButton->sizeHint().height();
setStyleSheet(QString("QLineEdit { padding-left: %1px; padding-right: %2px; }").arg(searchButton->sizeHint().width()).arg(clearButtonSizeHintWidth)); setStyleSheet(QString("QLineEdit { padding-left: %1px; padding-right: %2px; }").arg(searchButton->sizeHint().width()).arg(clearButtonSizeHintWidth));
#else #else
setClearButtonEnabled(true); setClearButtonEnabled(true);
setStyleSheet(QString("QLineEdit { padding-left: %1px; }").arg(searchButton->sizeHint().width())); // padding between text and widget borders setStyleSheet(QString("QLineEdit { padding-left: %1px; }").arg(searchButton->sizeHint().width())); // padding between text and widget borders
#endif #endif
QSize msz = sizeHint(); QSize msz = sizeHint();
setMinimumSize(qMax(msz.width(), searchButton->sizeHint().width() + clearButtonSizeHintWidth), setMinimumSize(qMax(msz.width(), searchButton->sizeHint().width() + clearButtonSizeHintWidth),
std::max({ msz.height(), searchButton->sizeHint().height(), clearButtonSizeHintHeight }) + frameWidth * 2); std::max({ msz.height(), searchButton->sizeHint().height(), clearButtonSizeHintHeight }) + frameWidth * 2);
} }
void LineEdit::resizeEvent(QResizeEvent *e) void LineEdit::resizeEvent(QResizeEvent *e)
{ {
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
QSize sz = searchButton->sizeHint(); QSize sz = searchButton->sizeHint();
searchButton->move(frameWidth, (e->size().height() - sz.height()) / 2); searchButton->move(frameWidth, (e->size().height() - sz.height()) / 2);
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QSize cz = clearButton->sizeHint(); QSize cz = clearButton->sizeHint();
clearButton->move((e->size().width() - frameWidth - cz.width()), (e->size().height() - sz.height()) / 2); clearButton->move((e->size().width() - frameWidth - cz.width()), (e->size().height() - sz.height()) / 2);
#endif #endif
} }
void LineEdit::updateCloseButton(const QString& text) void LineEdit::updateCloseButton(const QString &text)
{ {
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
clearButton->setVisible(!text.isEmpty()); clearButton->setVisible(!text.isEmpty());
#endif #endif
} }

12
src/gui/lineedit/src/lineedit.h

@ -16,21 +16,21 @@ class QToolButton;
class LineEdit : public QLineEdit class LineEdit : public QLineEdit
{ {
Q_OBJECT Q_OBJECT
public: public:
LineEdit(QWidget *parent); LineEdit(QWidget *parent);
protected: protected:
void resizeEvent(QResizeEvent *e); void resizeEvent(QResizeEvent *e);
private slots: private slots:
void updateCloseButton(const QString &text); void updateCloseButton(const QString &text);
private: private:
QToolButton *searchButton; QToolButton *searchButton;
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QToolButton *clearButton; QToolButton *clearButton;
#endif #endif
}; };

Loading…
Cancel
Save