Commit 35b789f6 authored by Michael Pyne's avatar Michael Pyne

Add the ability to go to the search results from the search line by hitting the

Down Arrow.  I hope that QListView in Qt 4 isn't as lame as it's been in Qt 3.

svn path=/trunk/KDE/kdemultimedia/juk/; revision=414810
parent 9776da39
......@@ -17,6 +17,7 @@
#include <kdebug.h>
#include <qlayout.h>
#include <qevent.h>
#include "playlistsplitter.h"
#include "searchwidget.h"
......@@ -68,6 +69,39 @@ void PlaylistSplitter::setFocus()
m_searchWidget->setFocus();
}
void PlaylistSplitter::slotFocusCurrentPlaylist()
{
kdDebug() << k_funcinfo << endl;
Playlist *playlist = m_playlistBox->visiblePlaylist();
if(playlist) {
playlist->setFocus();
playlist->KListView::selectAll(false);
// Select top item.
PlaylistItem *item = playlist->visibleItems().first();
playlist->markItemSelected(item, true);
playlist->setCurrentItem(item);
// STUPID FREAKING EVIL HACK because QListView hates me and you.
// Apparently all of the selecting items and setting current items
// that we just did works, but doesn't update the GUI (even after
// calling repaint). So let's simulate some user interaction.
QKeyEvent downP(QEvent::KeyPress, Qt::Key_Down, 32, 0);
QKeyEvent downR(QEvent::KeyRelease, Qt::Key_Down, 32, 0);
QKeyEvent upP (QEvent::KeyPress, Qt::Key_Up, 32, 0);
QKeyEvent upR (QEvent::KeyRelease, Qt::Key_Up, 32, 0);
KApplication::sendEvent(playlist, &downP);
KApplication::sendEvent(playlist, &downR);
KApplication::sendEvent(playlist, &upP);
KApplication::sendEvent(playlist, &upR);
kapp->processEvents();
}
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......@@ -125,6 +159,8 @@ void PlaylistSplitter::setupLayout()
m_searchWidget = new SearchWidget(top, "searchWidget");
connect(m_searchWidget, SIGNAL(signalQueryChanged()),
this, SLOT(slotShowSearchResults()));
connect(m_searchWidget, SIGNAL(signalDownPressed()),
this, SLOT(slotFocusCurrentPlaylist()));
connect(m_searchWidget, SIGNAL(signalAdvancedSearchClicked()),
m_playlistBox->object(), SLOT(slotCreateSearchPlaylist()));
connect(m_searchWidget, SIGNAL(signalShown(bool)),
......
......@@ -50,6 +50,7 @@ public:
public slots:
virtual void setFocus();
virtual void slotFocusCurrentPlaylist();
private:
......
......@@ -53,6 +53,7 @@ SearchLine::SearchLine(QWidget *parent, bool simple, const char *name) :
}
m_lineEdit = new KLineEdit(this, "searchLineEdit");
m_lineEdit->installEventFilter(this);
connect(m_lineEdit, SIGNAL(textChanged(const QString &)),
this, SIGNAL(signalQueryChanged()));
connect(m_lineEdit, SIGNAL(returnPressed()),
......@@ -133,6 +134,18 @@ void SearchLine::setFocus()
m_lineEdit->setFocus();
}
bool SearchLine::eventFilter(QObject *watched, QEvent *e)
{
if(watched != m_lineEdit || e->type() != QEvent::KeyPress)
return QHBox::eventFilter(watched, e);
QKeyEvent *key = static_cast<QKeyEvent *>(e);
if(key->key() == Qt::Key_Down)
emit signalDownPressed();
return QHBox::eventFilter(watched, e);
}
void SearchLine::slotActivate()
{
action("stop")->activate();
......@@ -258,6 +271,7 @@ void SearchWidget::setupLayout()
m_searchLine = new SearchLine(this, true, "kde toolbar widget");
connect(m_searchLine, SIGNAL(signalQueryChanged()), this, SIGNAL(signalQueryChanged()));
connect(m_searchLine, SIGNAL(signalDownPressed()), this, SIGNAL(signalDownPressed()));
connect(clearSearchButton, SIGNAL(pressed()), m_searchLine, SLOT(clear()));
setStretchableWidget(m_searchLine);
......
......@@ -51,8 +51,12 @@ public slots:
void clear();
virtual void setFocus();
protected:
virtual bool eventFilter(QObject *watched, QEvent *e);
signals:
void signalQueryChanged();
void signalDownPressed();
private slots:
void slotActivate();
......@@ -93,6 +97,8 @@ signals:
void signalShown(bool shown);
void signalDownPressed();
private:
void updateColumns();
void setupLayout();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment