1 /****************************************************************************
3 ** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
5 ** Use, modification and distribution is allowed without limitation,
6 ** warranty, liability or support of any kind.
8 ****************************************************************************/
14 #include <QGuiApplication>
15 #include <QResizeEvent>
17 #include <QToolButton>
19 #include "uithememanager.h"
21 LineEdit::LineEdit(QWidget
*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()
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
))
54 QLineEdit::keyPressEvent(event
);