Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
55 lines
1.8 KiB
10 years ago
|
/****************************************************************************
|
||
|
**
|
||
|
** 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"
|
||
7 years ago
|
|
||
9 years ago
|
#include <algorithm>
|
||
7 years ago
|
|
||
6 years ago
|
#include <QGuiApplication>
|
||
7 years ago
|
#include <QResizeEvent>
|
||
10 years ago
|
#include <QStyle>
|
||
9 years ago
|
#include <QToolButton>
|
||
7 years ago
|
|
||
|
#include "guiiconprovider.h"
|
||
10 years ago
|
|
||
|
LineEdit::LineEdit(QWidget *parent)
|
||
9 years ago
|
: QLineEdit(parent)
|
||
10 years ago
|
{
|
||
7 years ago
|
m_searchButton = new QToolButton(this);
|
||
|
m_searchButton->setIcon(GuiIconProvider::instance()->getIcon("edit-find"));
|
||
|
m_searchButton->setCursor(Qt::ArrowCursor);
|
||
7 years ago
|
m_searchButton->setStyleSheet("QToolButton {border: none; padding: 2px;}");
|
||
7 years ago
|
|
||
7 years ago
|
// padding between text and widget borders
|
||
|
setStyleSheet(QString("QLineEdit {padding-left: %1px;}").arg(m_searchButton->sizeHint().width()));
|
||
7 years ago
|
|
||
9 years ago
|
setClearButtonEnabled(true);
|
||
9 years ago
|
|
||
7 years ago
|
const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||
|
setMaximumHeight(std::max(sizeHint().height(), m_searchButton->sizeHint().height()) + frameWidth * 2);
|
||
9 years ago
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
void LineEdit::resizeEvent(QResizeEvent *e)
|
||
10 years ago
|
{
|
||
7 years ago
|
const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||
6 years ago
|
const int xPos = QGuiApplication::isLeftToRight()
|
||
|
? frameWidth
|
||
|
: (e->size().width() - m_searchButton->sizeHint().width() - frameWidth);
|
||
|
m_searchButton->move(xPos, (e->size().height() - m_searchButton->sizeHint().height()) / 2);
|
||
10 years ago
|
}
|
||
7 years ago
|
|
||
|
void LineEdit::keyPressEvent(QKeyEvent *event)
|
||
|
{
|
||
|
if ((event->modifiers() == Qt::NoModifier) && (event->key() == Qt::Key_Escape)) {
|
||
|
clear();
|
||
|
}
|
||
|
QLineEdit::keyPressEvent(event);
|
||
|
}
|