1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00
OpenMW/components/contentselector/view/comboboxlineedit.cpp
graffy76 cfdc19c427 Renamed esxSelector to contentSelector
Fixed datafilespage model implementation in launcher
Filtered addons in table view by selected game file
2013-09-21 23:06:29 -05:00

36 lines
1.4 KiB
C++

#include <QToolButton>
#include <QStyle>
#include "comboboxlineedit.hpp"
ContentSelectorView::ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent)
: QLineEdit(parent)
{
mClearButton = new QToolButton(this);
QPixmap pixmap(":images/clear.png");
mClearButton->setIcon(QIcon(pixmap));
mClearButton->setIconSize(pixmap.size());
mClearButton->setCursor(Qt::ArrowCursor);
mClearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
mClearButton->hide();
connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateClearButton(const QString&)));
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
setObjectName(QString("ComboBoxLineEdit"));
setStyleSheet(QString("ComboBoxLineEdit { background-color: transparent; padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1));
}
void ContentSelectorView::ComboBoxLineEdit::resizeEvent(QResizeEvent *)
{
QSize sz = mClearButton->sizeHint();
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
mClearButton->move(rect().right() - frameWidth - sz.width(),
(rect().bottom() + 1 - sz.height())/2);
}
void ContentSelectorView::ComboBoxLineEdit::updateClearButton(const QString& text)
{
mClearButton->setVisible(!text.isEmpty());
}