1 /***************************************************************************
2 * Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
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 ***************************************************************************/
16 #include <qtoolbutton.h>
19 #include <kpushbutton.h>
22 #include "searchlineedit.h"
23 #include "core/document.h"
25 FindBar::FindBar( Okular::Document
* document
, QWidget
* parent
)
28 QHBoxLayout
* lay
= new QHBoxLayout( this );
31 QToolButton
* closeBtn
= new QToolButton( this );
32 closeBtn
->setIcon( KIcon( "dialog-close" ) );
33 closeBtn
->setIconSize( QSize( 24, 24 ) );
34 closeBtn
->setToolTip( i18n( "Close" ) );
35 closeBtn
->setAutoRaise( true );
36 lay
->addWidget( closeBtn
);
38 QLabel
* label
= new QLabel( i18nc( "Find text", "F&ind:" ), this );
39 lay
->addWidget( label
);
41 m_text
= new SearchLineEdit( this, document
);
42 m_text
->setSearchCaseSensitivity( Qt::CaseInsensitive
);
43 m_text
->setSearchMinimumLength( 0 );
44 m_text
->setSearchType( Okular::Document::NextMatch
);
45 m_text
->setSearchId( PART_SEARCH_ID
);
46 m_text
->setSearchColor( qRgb( 255, 255, 64 ) );
47 m_text
->setSearchMoveViewport( true );
48 m_text
->setToolTip( i18n( "Text to search for" ) );
49 label
->setBuddy( m_text
);
50 lay
->addWidget( m_text
);
52 QPushButton
* findNextBtn
= new QPushButton( KIcon( "go-down-search" ), i18nc( "Find and go to the next search match", "Next" ), this );
53 findNextBtn
->setToolTip( i18n( "Jump to next match" ) );
54 lay
->addWidget( findNextBtn
);
56 QPushButton
* findPrevBtn
= new QPushButton( KIcon( "go-up-search" ), i18nc( "Find and go to the previous search match", "Previous" ), this );
57 findPrevBtn
->setToolTip( i18n( "Jump to previous match" ) );
58 lay
->addWidget( findPrevBtn
);
60 QPushButton
* optionsBtn
= new QPushButton( this );
61 optionsBtn
->setText( i18n( "Options" ) );
62 optionsBtn
->setToolTip( i18n( "Modify search behavior" ) );
63 QMenu
* optionsMenu
= new QMenu( optionsBtn
);
64 m_caseSensitiveAct
= optionsMenu
->addAction( i18n( "Case sensitive" ) );
65 m_caseSensitiveAct
->setCheckable( true );
66 m_fromCurrentPageAct
= optionsMenu
->addAction( i18n( "From current page" ) );
67 m_fromCurrentPageAct
->setCheckable( true );
68 optionsBtn
->setMenu( optionsMenu
);
69 lay
->addWidget( optionsBtn
);
71 connect( closeBtn
, SIGNAL( clicked() ), this, SLOT( close() ) );
72 connect( findNextBtn
, SIGNAL( clicked() ), this, SLOT( findNext() ) );
73 connect( findPrevBtn
, SIGNAL( clicked() ), this, SLOT( findPrev() ) );
74 connect( m_caseSensitiveAct
, SIGNAL( toggled( bool ) ), this, SLOT( caseSensitivityChanged() ) );
75 connect( m_fromCurrentPageAct
, SIGNAL( toggled( bool ) ), this, SLOT( fromCurrentPageChanged() ) );
84 QString
FindBar::text() const
86 return m_text
->text();
89 Qt::CaseSensitivity
FindBar::caseSensitivity() const
91 return m_caseSensitiveAct
->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive
;
94 void FindBar::focusAndSetCursor()
100 void FindBar::findNext()
102 m_text
->setSearchType( Okular::Document::NextMatch
);
106 void FindBar::findPrev()
108 m_text
->setSearchType( Okular::Document::PreviousMatch
);
112 void FindBar::caseSensitivityChanged()
114 m_text
->setSearchCaseSensitivity( m_caseSensitiveAct
->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive
);
115 m_text
->restartSearch();
118 void FindBar::fromCurrentPageChanged()
120 m_text
->setSearchFromStart( !m_fromCurrentPageAct
->isChecked() );
123 #include "findbar.moc"