SVN_SILENT made messages (.desktop file)
[kdegraphics.git] / okular / ui / findbar.cpp
blob03f169c44c96edd1ff39c91e2826def1e381741f
1 /***************************************************************************
2 * Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
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 "findbar.h"
12 // qt/kde includes
13 #include <qlabel.h>
14 #include <qlayout.h>
15 #include <qmenu.h>
16 #include <qtoolbutton.h>
17 #include <kicon.h>
18 #include <klocale.h>
19 #include <kpushbutton.h>
21 // local includes
22 #include "searchlineedit.h"
23 #include "core/document.h"
25 FindBar::FindBar( Okular::Document * document, QWidget * parent )
26 : QWidget( parent )
28 QHBoxLayout * lay = new QHBoxLayout( this );
29 lay->setMargin( 2 );
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_search = new SearchLineWidget( this, document );
42 m_search->lineEdit()->setSearchCaseSensitivity( Qt::CaseInsensitive );
43 m_search->lineEdit()->setSearchMinimumLength( 0 );
44 m_search->lineEdit()->setSearchType( Okular::Document::NextMatch );
45 m_search->lineEdit()->setSearchId( PART_SEARCH_ID );
46 m_search->lineEdit()->setSearchColor( qRgb( 255, 255, 64 ) );
47 m_search->lineEdit()->setSearchMoveViewport( true );
48 m_search->lineEdit()->setToolTip( i18n( "Text to search for" ) );
49 label->setBuddy( m_search );
50 lay->addWidget( m_search );
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() ) );
77 hide();
80 FindBar::~FindBar()
84 QString FindBar::text() const
86 return m_search->lineEdit()->text();
89 Qt::CaseSensitivity FindBar::caseSensitivity() const
91 return m_caseSensitiveAct->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
94 void FindBar::focusAndSetCursor()
96 setFocus();
97 m_search->lineEdit()->selectAll();
98 m_search->lineEdit()->setFocus();
101 void FindBar::findNext()
103 m_search->lineEdit()->setSearchType( Okular::Document::NextMatch );
104 m_search->lineEdit()->findNext();
107 void FindBar::findPrev()
109 m_search->lineEdit()->setSearchType( Okular::Document::PreviousMatch );
110 m_search->lineEdit()->findPrev();
113 void FindBar::caseSensitivityChanged()
115 m_search->lineEdit()->setSearchCaseSensitivity( m_caseSensitiveAct->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive );
116 m_search->lineEdit()->restartSearch();
119 void FindBar::fromCurrentPageChanged()
121 m_search->lineEdit()->setSearchFromStart( !m_fromCurrentPageAct->isChecked() );
124 #include "findbar.moc"