compile
[kdegraphics.git] / okular / ui / searchwidget.cpp
blobe0f2aba5bbfedf8b88e0fde4f443178027c8f6ec
1 /***************************************************************************
2 * Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
3 * *
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. *
8 ***************************************************************************/
10 #include "searchwidget.h"
12 // qt/kde includes
13 #include <qlayout.h>
14 #include <qmenu.h>
15 #include <qaction.h>
16 #include <qsizepolicy.h>
17 #include <qtoolbutton.h>
18 #include <kicon.h>
19 #include <klocale.h>
21 // local includes
22 #include "searchlineedit.h"
24 SearchWidget::SearchWidget( QWidget * parent, Okular::Document * document )
25 : QWidget( parent )
27 setObjectName( "iSearchBar" );
29 QSizePolicy sp = sizePolicy();
30 sp.setVerticalPolicy( QSizePolicy::Minimum );
31 setSizePolicy( sp );
33 QHBoxLayout * mainlay = new QHBoxLayout( this );
34 mainlay->setMargin( 0 );
35 mainlay->setSpacing( 3 );
37 // 2. text line
38 m_lineEdit = new SearchLineEdit( this, document );
39 m_lineEdit->setClearButtonShown( true );
40 m_lineEdit->setToolTip(i18n( "Enter at least 3 letters to filter pages" ));
41 m_lineEdit->setSearchCaseSensitivity( Qt::CaseInsensitive );
42 m_lineEdit->setSearchMinimumLength( 3 );
43 m_lineEdit->setSearchType( Okular::Document::GoogleAll );
44 m_lineEdit->setSearchId( SW_SEARCH_ID );
45 m_lineEdit->setSearchColor( qRgb( 0, 183, 255 ) );
46 mainlay->addWidget( m_lineEdit );
48 // 3.1. create the popup menu for changing filtering features
49 m_menu = new QMenu( this );
50 m_caseSensitiveAction = m_menu->addAction( i18n("Case Sensitive") );
51 m_menu->addSeparator();
52 m_matchPhraseAction = m_menu->addAction( i18n("Match Phrase") );
53 m_marchAllWordsAction = m_menu->addAction( i18n("Match All Words") );
54 m_marchAnyWordsAction = m_menu->addAction( i18n("Match Any Word") );
56 m_caseSensitiveAction->setCheckable( true );
57 QActionGroup *actgrp = new QActionGroup( this );
58 m_matchPhraseAction->setCheckable( true );
59 m_matchPhraseAction->setActionGroup( actgrp );
60 m_marchAllWordsAction->setCheckable( true );
61 m_marchAllWordsAction->setActionGroup( actgrp );
62 m_marchAnyWordsAction->setCheckable( true );
63 m_marchAnyWordsAction->setActionGroup( actgrp );
65 m_marchAllWordsAction->setChecked( true );
66 connect( m_menu, SIGNAL( triggered(QAction *) ), SLOT( slotMenuChaged(QAction*) ) );
68 // 3.2. create the toolbar button that spawns the popup menu
69 QToolButton *optionsMenuAction = new QToolButton( this );
70 mainlay->addWidget( optionsMenuAction );
71 optionsMenuAction->setAutoRaise( true );
72 optionsMenuAction->setIcon( KIcon( "view-filter" ) );
73 optionsMenuAction->setToolTip( i18n( "Filter Options" ) );
74 optionsMenuAction->setPopupMode( QToolButton::InstantPopup );
75 optionsMenuAction->setMenu( m_menu );
78 void SearchWidget::clearText()
80 m_lineEdit->clear();
83 void SearchWidget::slotMenuChaged( QAction * act )
85 // update internal variables and checked state
86 if ( act == m_caseSensitiveAction )
88 m_lineEdit->setSearchCaseSensitivity( m_caseSensitiveAction->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive );
90 else if ( act == m_matchPhraseAction )
92 m_lineEdit->setSearchType( Okular::Document::AllDocument );
94 else if ( act == m_marchAllWordsAction )
96 m_lineEdit->setSearchType( Okular::Document::GoogleAll );
98 else if ( act == m_marchAnyWordsAction )
100 m_lineEdit->setSearchType( Okular::Document::GoogleAny );
102 else
103 return;
105 // update search
106 m_lineEdit->restartSearch();
109 #include "searchwidget.moc"