Forward some events from QSearchField's internal lineEdit to QSearchField, so we can be aware of some events (like getting/losing focus).

Implemented for non-mac; something certainly still needs to be done for Mac
This commit is contained in:
Arnaud Bienner 2012-07-02 00:49:37 +02:00
parent 124d4e6a59
commit c57f58862f
4 changed files with 21 additions and 3 deletions

View File

@ -27,6 +27,7 @@ signals:
protected:
void resizeEvent(QResizeEvent*);
bool eventFilter(QObject*, QEvent*);
private:
friend class QSearchFieldPrivate;

View File

@ -22,6 +22,8 @@ THE SOFTWARE.
#include "qsearchfield.h"
#include <QApplication>
#include <QEvent>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QToolButton>
@ -79,6 +81,8 @@ QSearchField::QSearchField(QWidget *parent) : QWidget(parent)
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->addWidget(lineEdit);
lineEdit->installEventFilter(this);
}
void QSearchField::setText(const QString &text)
@ -150,3 +154,18 @@ void QSearchField::resizeEvent(QResizeEvent *resizeEvent)
const int y = (height() - pimpl->clearButton->height())/2;
pimpl->clearButton->move(x, y);
}
bool QSearchField::eventFilter(QObject *o, QEvent *e)
{
if (pimpl && pimpl->lineEdit && o == pimpl->lineEdit) {
// Forward some lineEdit events to QSearchField (only those we need for
// now, but some might be added later if needed)
switch (e->type()) {
case QEvent::FocusIn:
case QEvent::FocusOut:
QApplication::sendEvent(this, e);
break;
}
}
QWidget::eventFilter(o, e);
}

View File

@ -93,8 +93,6 @@ bool DidYouMean::eventFilter(QObject* object, QEvent* event) {
break;
// FIXME: FocusOut doesn't work with QSearchField, which is used as buddy
// in Spotify Service :(
case QEvent::FocusOut:
case QEvent::WindowDeactivate:
hide();

View File

@ -59,7 +59,7 @@ private:
QString did_you_mean_;
QString press_enter_;
// Size of the text to display, according to QFont above
// Size of the text to display, according to QFonts above.
// Stored here to avoid to recompute them each time
int did_you_mean_size_;
int press_enter_size_;