2012-05-20 14:14:15 -04: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"
|
|
|
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
#include <QtGui/QStyle>
|
|
|
|
|
|
|
|
#include "core/DataPath.h"
|
|
|
|
|
|
|
|
LineEdit::LineEdit(QWidget* parent)
|
|
|
|
: QLineEdit(parent)
|
|
|
|
{
|
2012-05-20 17:14:34 -04:00
|
|
|
m_clearButton = new QToolButton(this);
|
|
|
|
m_clearButton->setObjectName("clearButton");
|
2012-05-20 14:14:15 -04:00
|
|
|
QIcon icon = dataPath()->icon("action", "edit-clear-locationbar-rtl");
|
2012-05-20 17:14:34 -04:00
|
|
|
m_clearButton->setIcon(icon);
|
|
|
|
m_clearButton->setCursor(Qt::ArrowCursor);
|
|
|
|
m_clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
|
|
|
m_clearButton->hide();
|
|
|
|
connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear()));
|
2012-05-20 14:14:15 -04:00
|
|
|
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
|
|
|
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
|
|
|
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ")
|
2012-05-20 17:14:34 -04:00
|
|
|
.arg(m_clearButton->sizeHint().width() + frameWidth + 1));
|
2012-05-20 14:14:15 -04:00
|
|
|
QSize msz = minimumSizeHint();
|
2012-05-20 17:14:34 -04:00
|
|
|
setMinimumSize(qMax(msz.width(), m_clearButton->sizeHint().height() + frameWidth * 2 + 2),
|
|
|
|
qMax(msz.height(), m_clearButton->sizeHint().height() + frameWidth * 2 + 2));
|
2012-05-20 14:14:15 -04:00
|
|
|
}
|
|
|
|
|
2012-05-20 17:14:34 -04:00
|
|
|
void LineEdit::resizeEvent(QResizeEvent* event)
|
2012-05-20 14:14:15 -04:00
|
|
|
{
|
2012-05-20 17:14:34 -04:00
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
|
|
QSize sz = m_clearButton->sizeHint();
|
2012-05-20 14:14:15 -04:00
|
|
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
2012-05-20 17:14:34 -04:00
|
|
|
m_clearButton->move(rect().right() - frameWidth - sz.width(),
|
2012-05-20 14:14:15 -04:00
|
|
|
(rect().bottom() + 1 - sz.height())/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::updateCloseButton(const QString& text)
|
|
|
|
{
|
2012-05-20 17:14:34 -04:00
|
|
|
m_clearButton->setVisible(!text.isEmpty());
|
2012-05-20 14:14:15 -04:00
|
|
|
}
|