2014-12-20 20:29:17 +03:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
|
|
|
|
**
|
|
|
|
** Use, modification and distribution is allowed without limitation,
|
|
|
|
** warranty, liability or support of any kind.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "lineedit.h"
|
2015-11-07 07:34:52 +03:00
|
|
|
#include <algorithm>
|
2014-12-20 20:29:17 +03:00
|
|
|
#include <QStyle>
|
2015-11-07 07:34:52 +03:00
|
|
|
#include <QToolButton>
|
|
|
|
#include <QResizeEvent>
|
2014-12-20 20:29:17 +03:00
|
|
|
|
|
|
|
LineEdit::LineEdit(QWidget *parent)
|
2015-11-07 11:24:16 +03:00
|
|
|
: QLineEdit(parent)
|
2014-12-20 20:29:17 +03:00
|
|
|
{
|
2015-11-07 11:24:16 +03:00
|
|
|
QPixmap pixmap1(":/lineeditimages/search.png");
|
|
|
|
searchButton = new QToolButton(this);
|
|
|
|
searchButton->setIcon(QIcon(pixmap1));
|
|
|
|
searchButton->setIconSize(pixmap1.size());
|
|
|
|
searchButton->setCursor(Qt::ArrowCursor);
|
|
|
|
searchButton->setStyleSheet("QToolButton { border: none; padding: 2px; }");
|
2016-04-18 13:34:14 +03:00
|
|
|
QSize searchButtonHint = searchButton->sizeHint();
|
2015-11-07 07:34:52 +03:00
|
|
|
|
2016-04-18 13:34:14 +03:00
|
|
|
QSize clearButtonHint(0, 0);
|
2015-11-07 11:24:16 +03:00
|
|
|
setClearButtonEnabled(true);
|
2016-04-18 13:34:14 +03:00
|
|
|
setStyleSheet(QString("QLineEdit { padding-left: %1px; }").arg(searchButtonHint.width())); // padding between text and widget borders
|
2015-11-07 07:34:52 +03:00
|
|
|
|
2016-04-18 13:34:14 +03:00
|
|
|
QSize widgetHint = sizeHint();
|
|
|
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
|
|
|
setMaximumHeight(std::max({ widgetHint.height(), searchButtonHint.height(), clearButtonHint.height() }) + frameWidth * 2);
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2014-12-20 20:29:17 +03:00
|
|
|
}
|
|
|
|
|
2015-11-07 07:34:52 +03:00
|
|
|
void LineEdit::resizeEvent(QResizeEvent *e)
|
2014-12-20 20:29:17 +03:00
|
|
|
{
|
2015-11-07 11:24:16 +03:00
|
|
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
2015-11-07 07:34:52 +03:00
|
|
|
|
2015-11-07 11:24:16 +03:00
|
|
|
QSize sz = searchButton->sizeHint();
|
|
|
|
searchButton->move(frameWidth, (e->size().height() - sz.height()) / 2);
|
2014-12-20 20:29:17 +03:00
|
|
|
}
|
|
|
|
|