File: searchwidget.cpp

package info (click to toggle)
okular 4%3A4.14.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,584 kB
  • ctags: 7,898
  • sloc: cpp: 73,406; ansic: 3,964; xml: 57; sh: 42; makefile: 7
file content (109 lines) | stat: -rw-r--r-- 3,979 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/***************************************************************************
 *   Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>                  *
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

#include "searchwidget.h"

// qt/kde includes
#include <qlayout.h>
#include <qmenu.h>
#include <qaction.h>
#include <qsizepolicy.h>
#include <qtoolbutton.h>
#include <kicon.h>
#include <klocale.h>

// local includes
#include "searchlineedit.h"

SearchWidget::SearchWidget( QWidget * parent, Okular::Document * document )
    : QWidget( parent )
{
    setObjectName( QLatin1String( "iSearchBar" ) );

    QSizePolicy sp = sizePolicy();
    sp.setVerticalPolicy( QSizePolicy::Minimum );
    setSizePolicy( sp );

    QHBoxLayout * mainlay = new QHBoxLayout( this );
    mainlay->setMargin( 0 );
    mainlay->setSpacing( 3 );

    // 2. text line
    m_lineEdit = new SearchLineEdit( this, document );
    m_lineEdit->setClearButtonShown( true );
    m_lineEdit->setToolTip(i18n( "Enter at least 3 letters to filter pages" ));
    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 ) );
    mainlay->addWidget( m_lineEdit );

    // 3.1. create the popup menu for changing filtering features
    m_menu = new QMenu( this );
    m_caseSensitiveAction = m_menu->addAction( i18n("Case Sensitive") );
    m_menu->addSeparator();
    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 );
    QActionGroup *actgrp = new QActionGroup( this );
    m_matchPhraseAction->setCheckable( true );
    m_matchPhraseAction->setActionGroup( actgrp );
    m_marchAllWordsAction->setCheckable( true );
    m_marchAllWordsAction->setActionGroup( actgrp );
    m_marchAnyWordsAction->setCheckable( true );
    m_marchAnyWordsAction->setActionGroup( actgrp );

    m_marchAllWordsAction->setChecked( true );
    connect( m_menu, SIGNAL(triggered(QAction*)), SLOT(slotMenuChaged(QAction*)) );

    // 3.2. create the toolbar button that spawns the popup menu
    QToolButton *optionsMenuAction =  new QToolButton( this );
    mainlay->addWidget( optionsMenuAction );
    optionsMenuAction->setAutoRaise( true );
    optionsMenuAction->setIcon( KIcon( "view-filter" ) );
    optionsMenuAction->setToolTip( i18n( "Filter Options" ) );
    optionsMenuAction->setPopupMode( QToolButton::InstantPopup );
    optionsMenuAction->setMenu( m_menu );
}

void SearchWidget::clearText()
{
    m_lineEdit->clear();
}

void SearchWidget::slotMenuChaged( QAction * act )
{
    // update internal variables and checked state
    if ( act == m_caseSensitiveAction )
    {
        m_lineEdit->setSearchCaseSensitivity( m_caseSensitiveAction->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive );
    }
    else if ( act == m_matchPhraseAction )
    {
        m_lineEdit->setSearchType( Okular::Document::AllDocument );
    }
    else if ( act == m_marchAllWordsAction )
    {
        m_lineEdit->setSearchType( Okular::Document::GoogleAll );
    }
    else if ( act == m_marchAnyWordsAction )
    {
        m_lineEdit->setSearchType( Okular::Document::GoogleAny );
    }
    else
        return;

    // update search
    m_lineEdit->restartSearch();
}

#include "searchwidget.moc"