1 /* Copyright (C) 2003-2006 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #include "SearchBar.h"
19 #include <klineedit.h>
20 #include <kmainwindow.h>
26 #include <qapplication.h>
27 #include <kactioncollection.h>
29 MainWindow::SearchBar::SearchBar( KMainWindow
* parent
)
32 QLabel
* label
= new QLabel( i18n("Search:") + QString::fromLatin1(" ") );
35 _edit
= new KLineEdit( this );
36 _edit
->setClearButtonShown(true);
37 label
->setBuddy( _edit
);
40 connect( _edit
, SIGNAL( textChanged( const QString
& ) ), this, SIGNAL( textChanged( const QString
& ) ) );
41 connect( _edit
, SIGNAL( returnPressed() ), this, SIGNAL( returnPressed() ) );
43 _edit
->installEventFilter( this );
46 bool MainWindow::SearchBar::eventFilter( QObject
* , QEvent
* e
)
48 if ( e
->type() == QEvent::KeyPress
) {
49 QKeyEvent
* ke
= static_cast<QKeyEvent
*>( e
);
50 if ( ke
->key() == Qt::Key_Up
||
51 ke
->key() == Qt::Key_Down
||
52 ke
->key() == Qt::Key_Left
||
53 ke
->key() == Qt::Key_Right
||
54 ke
->key() == Qt::Key_PageDown
||
55 ke
->key() == Qt::Key_PageUp
||
56 ke
->key() == Qt::Key_Home
||
57 ke
->key() == Qt::Key_End
) {
58 emit
keyPressed( ke
);
61 else if ( ke
->key() == Qt::Key_Enter
|| ke
->key() == Qt::Key_Return
) {
62 // If I don't interpret return and enter here, but simply rely
63 // on QLineEdit itself to emit the signal, then it will
64 // propagate to the main window, and from there be delivered to
65 // the central widget.
69 else if ( ke
->key() == Qt::Key_Escape
)
75 void MainWindow::SearchBar::reset()
81 * This was originally just a call to setEnabled() on the SearchBar itself,
82 * but due to a bug in either KDE or Qt, this resulted in the bar never
83 * being enabled again after a disable.
85 void MainWindow::SearchBar::setLineEditEnabled(bool b
)
91 #include "SearchBar.moc"