/*
* searchwidget.cc
*
* Copyright (c) 2002, 2003 Frerich Raabe <raabe@kde.org>
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the
* accompanying file 'COPYING'.
*/
#include "searchwidget.h"
#include <qgroupbox.h>
#include <qlayout.h>
#include <qtoolbutton.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <klocale.h>
using namespace Barry;
SearchWidget::SearchWidget( QWidget *parent ): QWidget( parent, "searchwidget" )
{
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
QGroupBox *frame = new QGroupBox( 1, Vertical, this );
frame->setTitle( i18n( "Search" ) );
layout->addWidget( frame );
m_editField = new KLineEdit( frame, "editField" );
connect( m_editField, SIGNAL( textChanged( const QString & ) ),
this, SLOT( contentsChanged( const QString & ) ) );
connect( m_editField, SIGNAL( returnPressed( const QString & ) ),
this, SLOT( gotSearchTerm( const QString & ) ) );
QPixmap helpPixmap = SmallIcon( QString::fromLatin1( "help" ) );
m_toolButton = new QToolButton( frame, "toolButton" );
connect( m_toolButton, SIGNAL( pressed() ),
this, SLOT( buttonPressed() ) );
m_toolButton->setIconSet( QIconSet( helpPixmap ) );
m_toolButton->setEnabled( false );
}
void SearchWidget::addEntry( const QString &entry )
{
m_editField->completionObject()->addItem( entry );
}
void SearchWidget::contentsChanged( const QString &contents )
{
m_toolButton->setEnabled( !contents.isEmpty() );
}
void SearchWidget::gotSearchTerm( const QString &term )
{
emit searchTerm( term );
m_editField->clear();
}
void SearchWidget::buttonPressed()
{
gotSearchTerm( m_editField->text() );
}
#include "searchwidget.moc"
// vim:ts=4:sw=4:noet:list
syntax highlighted by Code2HTML, v. 0.9.1