1
/***************************************************************************
2
* Copyright (C) 2006 by Pino Toscano, toscano.pino@tiscali.it *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18
***************************************************************************/
20
#include "searchwidget.h"
25
#include <QHBoxLayout>
28
#include "kalziumdataobject.h"
31
SearchWidget::SearchWidget( QWidget *parent )
32
: QWidget( parent ), m_timer( 0 )
34
QHBoxLayout *mainlay = new QHBoxLayout( this );
35
mainlay->setMargin( 2 );
36
mainlay->setSpacing( 5 );
38
mainlay->addWidget( new QLabel( i18n( "Search:" ), this ) );
40
m_searchLine = new KLineEdit( this );
41
m_searchLine->setClearButtonShown(true);
42
m_searchLine->setTrapReturnKey(true);
43
connect( m_searchLine, SIGNAL( textChanged( const QString& ) ),
44
this, SLOT( searchTextChanged( const QString& ) ) );
45
connect( m_searchLine, SIGNAL( returnPressed() ),
46
this, SLOT( slotReturnPressed() ) );
47
mainlay->addWidget( m_searchLine );
50
SearchWidget::~SearchWidget()
56
void SearchWidget::giveFocus()
58
m_searchLine->setFocus( Qt::MouseFocusReason );
59
m_searchLine->setCursorPosition( m_searchLine->text().length() );
62
void SearchWidget::searchTextChanged( const QString& )
70
m_timer = new QTimer( this );
71
m_timer->setSingleShot( true );
72
connect( m_timer, SIGNAL( timeout() ), this, SLOT( doSearch() ) );
74
// 1/3 of second should be ok
75
m_timer->start( 333 );
78
void SearchWidget::slotReturnPressed()
87
void SearchWidget::doSearch()
89
Search *s = KalziumDataObject::instance()->search();
92
QString txt = m_searchLine->text();
93
if ( txt.length() > 0 )
94
s->doSearch( txt, Search::SearchAll );
99
#include "searchwidget.moc"