2004-09-16 21:27:34 +00:00
|
|
|
/***************************************************************************
|
2006-03-24 19:35:20 +00:00
|
|
|
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
|
2004-09-16 21:27:34 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "searchwidget.h"
|
|
|
|
|
2004-09-16 21:27:34 +00:00
|
|
|
// qt/kde includes
|
2007-08-24 14:04:48 +00:00
|
|
|
#include <qlayout.h>
|
2006-03-24 19:35:20 +00:00
|
|
|
#include <qmenu.h>
|
|
|
|
#include <qaction.h>
|
2006-04-03 20:48:26 +00:00
|
|
|
#include <qsizepolicy.h>
|
2006-05-17 15:50:18 +00:00
|
|
|
#include <qtoolbutton.h>
|
2006-03-31 23:29:45 +00:00
|
|
|
#include <kicon.h>
|
2004-09-16 21:27:34 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
|
|
|
|
// local includes
|
2007-03-17 16:58:01 +00:00
|
|
|
#include "searchlineedit.h"
|
2004-09-16 21:27:34 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
SearchWidget::SearchWidget( QWidget * parent, Okular::Document * document )
|
2007-08-24 14:04:48 +00:00
|
|
|
: QWidget( parent )
|
2004-09-16 21:27:34 +00:00
|
|
|
{
|
2006-03-31 23:08:20 +00:00
|
|
|
setObjectName( "iSearchBar" );
|
2007-08-24 14:04:48 +00:00
|
|
|
|
2006-04-03 20:48:26 +00:00
|
|
|
QSizePolicy sp = sizePolicy();
|
|
|
|
sp.setVerticalPolicy( QSizePolicy::Minimum );
|
|
|
|
setSizePolicy( sp );
|
2004-09-16 21:27:34 +00:00
|
|
|
|
2007-08-24 14:04:48 +00:00
|
|
|
QHBoxLayout * mainlay = new QHBoxLayout( this );
|
|
|
|
mainlay->setMargin( 0 );
|
|
|
|
mainlay->setSpacing( 3 );
|
|
|
|
|
2006-03-31 23:08:20 +00:00
|
|
|
// 2. text line
|
2007-03-17 16:58:01 +00:00
|
|
|
m_lineEdit = new SearchLineEdit( this, document );
|
2006-10-08 21:37:28 +00:00
|
|
|
m_lineEdit->setClearButtonShown( true );
|
2006-03-24 19:35:20 +00:00
|
|
|
m_lineEdit->setToolTip(i18n( "Enter at least 3 letters to filter pages" ));
|
2007-03-17 16:58:01 +00:00
|
|
|
m_lineEdit->setSearchCaseSensitivity( Qt::CaseInsensitive );
|
|
|
|
m_lineEdit->setSearchMinimumLength( 3 );
|
|
|
|
m_lineEdit->setSearchType( Okular::Document::GoogleAll );
|
|
|
|
m_lineEdit->setSearchId( SW_SEARCH_ID );
|
|
|
|
m_lineEdit->setSearchColor( qRgb( 0, 183, 255 ) );
|
2007-08-24 14:04:48 +00:00
|
|
|
mainlay->addWidget( m_lineEdit );
|
2004-12-13 18:21:37 +00:00
|
|
|
|
2005-02-20 16:04:40 +00:00
|
|
|
// 3.1. create the popup menu for changing filtering features
|
2006-03-24 19:35:20 +00:00
|
|
|
m_menu = new QMenu( this );
|
|
|
|
m_caseSensitiveAction = m_menu->addAction( i18n("Case Sensitive") );
|
2006-03-30 15:27:27 +00:00
|
|
|
m_menu->addSeparator();
|
2006-03-24 19:35:20 +00:00
|
|
|
m_matchPhraseAction = m_menu->addAction( i18n("Match Phrase") );
|
|
|
|
m_marchAllWordsAction = m_menu->addAction( i18n("Match All Words") );
|
|
|
|
m_marchAnyWordsAction = m_menu->addAction( i18n("Match Any Word") );
|
|
|
|
|
|
|
|
m_caseSensitiveAction->setCheckable( true );
|
2006-03-31 23:08:20 +00:00
|
|
|
QActionGroup *actgrp = new QActionGroup( this );
|
2006-03-24 19:35:20 +00:00
|
|
|
m_matchPhraseAction->setCheckable( true );
|
2006-03-31 23:08:20 +00:00
|
|
|
m_matchPhraseAction->setActionGroup( actgrp );
|
2006-03-24 19:35:20 +00:00
|
|
|
m_marchAllWordsAction->setCheckable( true );
|
2006-03-31 23:08:20 +00:00
|
|
|
m_marchAllWordsAction->setActionGroup( actgrp );
|
2006-03-24 19:35:20 +00:00
|
|
|
m_marchAnyWordsAction->setCheckable( true );
|
2006-03-31 23:08:20 +00:00
|
|
|
m_marchAnyWordsAction->setActionGroup( actgrp );
|
2006-03-24 19:35:20 +00:00
|
|
|
|
|
|
|
m_marchAllWordsAction->setChecked( true );
|
|
|
|
connect( m_menu, SIGNAL( triggered(QAction *) ), SLOT( slotMenuChaged(QAction*) ) );
|
2004-11-26 11:34:16 +00:00
|
|
|
|
2005-02-20 16:04:40 +00:00
|
|
|
// 3.2. create the toolbar button that spawns the popup menu
|
2006-05-17 15:50:18 +00:00
|
|
|
QToolButton *optionsMenuAction = new QToolButton( this );
|
2007-08-24 14:04:48 +00:00
|
|
|
mainlay->addWidget( optionsMenuAction );
|
|
|
|
optionsMenuAction->setAutoRaise( true );
|
2007-10-02 16:23:28 +00:00
|
|
|
optionsMenuAction->setIcon( KIcon( "graphics-viewer-document" ) );
|
2006-05-17 15:50:18 +00:00
|
|
|
optionsMenuAction->setToolTip( i18n( "Filter Options" ) );
|
|
|
|
optionsMenuAction->setPopupMode( QToolButton::InstantPopup );
|
2006-03-31 23:08:20 +00:00
|
|
|
optionsMenuAction->setMenu( m_menu );
|
2004-09-16 21:27:34 +00:00
|
|
|
}
|
|
|
|
|
2005-02-03 17:09:33 +00:00
|
|
|
void SearchWidget::clearText()
|
|
|
|
{
|
2006-03-24 19:35:20 +00:00
|
|
|
m_lineEdit->clear();
|
2005-02-03 17:09:33 +00:00
|
|
|
}
|
|
|
|
|
2006-03-24 19:35:20 +00:00
|
|
|
void SearchWidget::slotMenuChaged( QAction * act )
|
2005-02-20 16:04:40 +00:00
|
|
|
{
|
|
|
|
// update internal variables and checked state
|
2006-03-24 19:35:20 +00:00
|
|
|
if ( act == m_caseSensitiveAction )
|
2005-02-20 16:04:40 +00:00
|
|
|
{
|
2007-03-17 16:58:01 +00:00
|
|
|
m_lineEdit->setSearchCaseSensitivity( m_caseSensitiveAction->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive );
|
2006-03-24 19:35:20 +00:00
|
|
|
}
|
|
|
|
else if ( act == m_matchPhraseAction )
|
|
|
|
{
|
2007-03-17 16:58:01 +00:00
|
|
|
m_lineEdit->setSearchType( Okular::Document::AllDocument );
|
2006-03-24 19:35:20 +00:00
|
|
|
}
|
|
|
|
else if ( act == m_marchAllWordsAction )
|
|
|
|
{
|
2007-03-17 16:58:01 +00:00
|
|
|
m_lineEdit->setSearchType( Okular::Document::GoogleAll );
|
2005-02-20 16:04:40 +00:00
|
|
|
}
|
2006-03-24 19:35:20 +00:00
|
|
|
else if ( act == m_marchAnyWordsAction )
|
2005-02-20 16:04:40 +00:00
|
|
|
{
|
2007-03-17 16:58:01 +00:00
|
|
|
m_lineEdit->setSearchType( Okular::Document::GoogleAny );
|
2005-02-20 16:04:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
// update search
|
2007-03-17 16:58:01 +00:00
|
|
|
m_lineEdit->restartSearch();
|
2004-09-16 21:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "searchwidget.moc"
|