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"
26 #include <QToolButton>
31 #include "kalziumdataobject.h"
34 SearchWidget::SearchWidget( QWidget
*parent
)
35 : QWidget( parent
), m_timer( 0 )
37 QHBoxLayout
*mainlay
= new QHBoxLayout( this );
38 mainlay
->setMargin( 2 );
39 mainlay
->setSpacing( 5 );
41 mainlay
->addWidget( new QLabel( i18n( "Search:" ), this ) );
43 m_searchLine
= new KLineEdit( this );
44 m_searchLine
->setClearButtonShown(true);
45 m_searchLine
->setTrapReturnKey(true);
46 connect( m_searchLine
, SIGNAL( textChanged( const QString
& ) ),
47 this, SLOT( searchTextChanged( const QString
& ) ) );
48 connect( m_searchLine
, SIGNAL( returnPressed() ),
49 this, SLOT( slotReturnPressed() ) );
50 mainlay
->addWidget( m_searchLine
);
53 SearchWidget::~SearchWidget()
57 void SearchWidget::giveFocus()
59 m_searchLine
->setFocus( Qt::MouseFocusReason
);
60 m_searchLine
->setCursorPosition( m_searchLine
->text().length() );
63 void SearchWidget::appendSearchText( const QString
& text
)
65 m_searchLine
->setText( m_searchLine
->text() + text
);
68 void SearchWidget::searchTextChanged( const QString
& )
76 m_timer
= new QTimer( this );
77 m_timer
->setSingleShot( true );
78 connect( m_timer
, SIGNAL( timeout() ), this, SLOT( doSearch() ) );
80 // 1/3 of second should be ok
81 m_timer
->start( 333 );
84 void SearchWidget::slotReturnPressed()
93 void SearchWidget::doSearch()
95 Search
*s
= KalziumDataObject::instance()->search();
98 QString txt
= m_searchLine
->text();
99 if ( txt
.length() > 0 )
100 s
->doSearch( txt
, Search::SearchAll
);
105 #include "searchwidget.moc"