Sync translations from Transifex and run lupdate
[qBittorrent.git] / src / gui / lineedit.cpp
blobf1cbb9f9c99d04b6224d6dbc723668815a3e059a
1 /****************************************************************************
2 **
3 ** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
4 **
5 ** Use, modification and distribution is allowed without limitation,
6 ** warranty, liability or support of any kind.
7 **
8 ****************************************************************************/
10 #include "lineedit.h"
12 #include <algorithm>
14 #include <QGuiApplication>
15 #include <QResizeEvent>
16 #include <QStyle>
17 #include <QToolButton>
19 #include "uithememanager.h"
21 LineEdit::LineEdit(QWidget *parent)
22 : QLineEdit(parent)
24 m_searchButton = new QToolButton(this);
25 m_searchButton->setIcon(UIThemeManager::instance()->getIcon("edit-find"));
26 m_searchButton->setCursor(Qt::ArrowCursor);
27 m_searchButton->setStyleSheet("QToolButton {border: none; padding: 2px;}");
29 // padding between text and widget borders
30 setStyleSheet(QString::fromLatin1("QLineEdit {padding-left: %1px;}").arg(m_searchButton->sizeHint().width()));
32 setClearButtonEnabled(true);
34 const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
35 setMaximumHeight(std::max(sizeHint().height(), m_searchButton->sizeHint().height()) + frameWidth * 2);
36 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
39 void LineEdit::resizeEvent(QResizeEvent *e)
41 const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
42 const int xPos = QGuiApplication::isLeftToRight()
43 ? frameWidth
44 : (e->size().width() - m_searchButton->sizeHint().width() - frameWidth);
45 m_searchButton->move(xPos, (e->size().height() - m_searchButton->sizeHint().height()) / 2);
48 void LineEdit::keyPressEvent(QKeyEvent *event)
50 if ((event->modifiers() == Qt::NoModifier) && (event->key() == Qt::Key_Escape))
52 clear();
54 QLineEdit::keyPressEvent(event);