Don't show the global search popup immediately when clicking in the search field, making it possible to double click the search box to select all text.

This commit is contained in:
David Sansome 2011-10-15 20:48:48 +01:00
parent 4a25ddee00
commit ce501d982a
4 changed files with 29 additions and 16 deletions

View File

@ -21,14 +21,16 @@
#include "sha2.h"
#include <QCoreApplication>
#include <QApplication>
#include <QDateTime>
#include <QDesktopServices>
#include <QDir>
#include <QIODevice>
#include <QMouseEvent>
#include <QStringList>
#include <QTemporaryFile>
#include <QUrl>
#include <QWidget>
#include <QtDebug>
#include <QtGlobal>
@ -348,6 +350,18 @@ QString PrettySize(const QSize& size) {
QString::number(size.height());
}
void ForwardMouseEvent(const QMouseEvent* e, QWidget* target) {
QMouseEvent c(e->type(), target->mapFromGlobal(e->globalPos()),
e->globalPos(), e->button(), e->buttons(), e->modifiers());
target->setAttribute(Qt::WA_UnderMouse, true);
QApplication::sendEvent(target, &c);
}
bool IsMouseEventInWidget(const QMouseEvent* e, const QWidget* widget) {
return widget->rect().contains(widget->mapFromGlobal(e->globalPos()));
}
} // namespace Utilities

View File

@ -27,6 +27,7 @@
#include <boost/scoped_array.hpp>
class QIODevice;
class QMouseEvent;
namespace Utilities {
QString PrettyTime(int seconds);
@ -60,6 +61,14 @@ namespace Utilities {
QByteArray Sha256(const QByteArray& data);
// Forwards a mouse event to a different widget, remapping the event's widget
// coordinates relative to those of the target widget.
void ForwardMouseEvent(const QMouseEvent* e, QWidget* target);
// Checks if the mouse event was inside the widget's rectangle.
bool IsMouseEventInWidget(const QMouseEvent* e, const QWidget* widget);
enum ConfigPath {
Path_Root,
Path_AlbumCovers,

View File

@ -19,6 +19,7 @@
#include "tooltipactionwidget.h"
#include "tooltipresultwidget.h"
#include "core/logging.h"
#include "core/utilities.h"
#include <QAction>
#include <QApplication>
@ -154,17 +155,11 @@ bool GlobalSearchTooltip::event(QEvent* e) {
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
if (!underMouse()) {
QMouseEvent* me = static_cast<QMouseEvent*>(e);
QMouseEvent c(me->type(), event_target_->mapFromGlobal(me->globalPos()),
me->globalPos(), me->button(),
me->buttons(), me->modifiers());
const QMouseEvent* me = static_cast<QMouseEvent*>(e);
QWidget* child = event_target_->childAt(
event_target_->mapFromGlobal(me->globalPos()));
QWidget* child = event_target_->childAt(c.pos());
if (child)
child->setAttribute(Qt::WA_UnderMouse, true);
QApplication::sendEvent(child ? child : event_target_, &c);
Utilities::ForwardMouseEvent(me, child ? child : event_target_);
return true;
}
break;

View File

@ -354,11 +354,6 @@ bool GlobalSearchWidget::EventFilterSearchWidget(QObject* o, QEvent* e) {
break;
}
case QEvent::MouseButtonPress:
if (!ui_->search->text().isEmpty())
RepositionPopup();
break;
default:
break;
}