From 5d1bede9e50c13d72f548f23d3b5e8da60b79119 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Thu, 14 Feb 2013 11:20:47 +0100 Subject: [PATCH] Forgot to add two files --- apps/launcher/utils/comboboxlineedit.cpp | 35 ++++++++++++++++++++++++ apps/launcher/utils/comboboxlineedit.hpp | 35 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 apps/launcher/utils/comboboxlineedit.cpp create mode 100644 apps/launcher/utils/comboboxlineedit.hpp diff --git a/apps/launcher/utils/comboboxlineedit.cpp b/apps/launcher/utils/comboboxlineedit.cpp new file mode 100644 index 0000000000..4d62e1399a --- /dev/null +++ b/apps/launcher/utils/comboboxlineedit.cpp @@ -0,0 +1,35 @@ +#include +#include + +#include "comboboxlineedit.hpp" + +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 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 ComboBoxLineEdit::updateClearButton(const QString& text) +{ + mClearButton->setVisible(!text.isEmpty()); +} diff --git a/apps/launcher/utils/comboboxlineedit.hpp b/apps/launcher/utils/comboboxlineedit.hpp new file mode 100644 index 0000000000..ba10731ae3 --- /dev/null +++ b/apps/launcher/utils/comboboxlineedit.hpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (c) 2007 Trolltech ASA +** +** Use, modification and distribution is allowed without limitation, +** warranty, liability or support of any kind. +** +****************************************************************************/ + +#ifndef LINEEDIT_H +#define LINEEDIT_H + +#include + +class QToolButton; + +class ComboBoxLineEdit : public QLineEdit +{ + Q_OBJECT + +public: + ComboBoxLineEdit(QWidget *parent = 0); + +protected: + void resizeEvent(QResizeEvent *); + +private slots: + void updateClearButton(const QString &text); + +private: + QToolButton *mClearButton; +}; + +#endif // LIENEDIT_H +