summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtClosableLineEdit.cpp')
-rw-r--r--Swift/QtUI/QtClosableLineEdit.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/Swift/QtUI/QtClosableLineEdit.cpp b/Swift/QtUI/QtClosableLineEdit.cpp
index 414463a..033db78 100644
--- a/Swift/QtUI/QtClosableLineEdit.cpp
+++ b/Swift/QtUI/QtClosableLineEdit.cpp
@@ -27,40 +27,40 @@ namespace Swift {
const int QtClosableLineEdit::clearButtonPadding = 2;
QtClosableLineEdit::QtClosableLineEdit(QWidget *parent) : QLineEdit(parent) {
- clearButton = new QToolButton(this);
- clearButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
- clearButton->setIconSize(QSize(16,16));
- clearButton->setCursor(Qt::ArrowCursor);
- clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
- clearButton->hide();
- connect(clearButton, SIGNAL(clicked()), this, SLOT(handleCloseButtonClicked()));
- connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
- int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
- QSize minimumSize = minimumSizeHint();
- setMinimumSize(qMax(minimumSize.width(), clearButton->sizeHint().width() + frameWidth * 2 + clearButtonPadding),
- qMax(minimumSize.height(), clearButton->sizeHint().height() + frameWidth * 2 + clearButtonPadding));
+ clearButton = new QToolButton(this);
+ clearButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
+ clearButton->setIconSize(QSize(16,16));
+ clearButton->setCursor(Qt::ArrowCursor);
+ clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
+ clearButton->hide();
+ connect(clearButton, SIGNAL(clicked()), this, SLOT(handleCloseButtonClicked()));
+ connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
+ QSize minimumSize = minimumSizeHint();
+ setMinimumSize(qMax(minimumSize.width(), clearButton->sizeHint().width() + frameWidth * 2 + clearButtonPadding),
+ qMax(minimumSize.height(), clearButton->sizeHint().height() + frameWidth * 2 + clearButtonPadding));
}
void QtClosableLineEdit::resizeEvent(QResizeEvent *) {
- QSize size = clearButton->sizeHint();
- int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- int verticalAdjustment = 1;
+ QSize size = clearButton->sizeHint();
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ int verticalAdjustment = 1;
#if defined(Q_OS_WIN32)
- // This vertical adjustment is required on Windows so the close button is vertically centered in the line edit.
- verticalAdjustment += 2;
-#endif
- clearButton->move(rect().right() - frameWidth - size.width(), (rect().bottom() + verticalAdjustment - size.height())/2);
+ // This vertical adjustment is required on Windows so the close button is vertically centered in the line edit.
+ verticalAdjustment += 2;
+#endif
+ clearButton->move(rect().right() - frameWidth - size.width(), (rect().bottom() + verticalAdjustment - size.height())/2);
}
void QtClosableLineEdit::updateCloseButton(const QString& text) {
- clearButton->setVisible(!text.isEmpty());
+ clearButton->setVisible(!text.isEmpty());
}
void QtClosableLineEdit::handleCloseButtonClicked() {
- clear();
- QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier));
- QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Escape, Qt::NoModifier));
+ clear();
+ QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier));
+ QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Escape, Qt::NoModifier));
}
}