mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 08:56:43 +00:00 
			
		
		
		
	Conflicts: apps/launcher/CMakeLists.txt apps/launcher/datafilespage.cpp apps/launcher/datafilespage.hpp apps/launcher/graphicspage.cpp components/fileorderlist/utils/filedialog.cpp components/fileorderlist/utils/filedialog.hpp
		
			
				
	
	
		
			38 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <QToolButton>
 | 
						|
#include <QStyle>
 | 
						|
 | 
						|
#include "lineedit.hpp"
 | 
						|
 | 
						|
LineEdit::LineEdit(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("LineEdit"));
 | 
						|
    setStyleSheet(QString("LineEdit { padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1));
 | 
						|
    QSize msz = minimumSizeHint();
 | 
						|
    setMinimumSize(qMax(msz.width(), mClearButton->sizeHint().height() + frameWidth * 2 + 2),
 | 
						|
                   qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2));
 | 
						|
}
 | 
						|
 | 
						|
void LineEdit::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 LineEdit::updateClearButton(const QString& text)
 | 
						|
{
 | 
						|
    mClearButton->setVisible(!text.isEmpty());
 | 
						|
}
 |