Commit b2ed18c6 authored by Enrico Ros's avatar Enrico Ros

Added google-like searches on thumbnailslist (in fact the controller is the

  SearchWidget). Splitted SearchType::GoogleLike in GoogleAll and GoogleAny
  to mark pages if all words are present or at least one is present resp.
--TODOs;

svn path=/branches/kpdf_annotations/kdegraphics/kpdf/; revision=391354
parent f5ed9252
......@@ -13,7 +13,6 @@ In progress:
-> se: check tools not working after a certain time (pretty nice bug :-)
More items (first items will enter 'In progress list' first):
-> search: google search in the page
-> pageview: add scrollbar marks for bookmarks (like kate)
-> bookmarks: fastmarks (new bookmark concept with tab-like signs, shortcuts, etc)
-> bookmarks: go to next/previous actions (showing in thumbnailslist rmb popup too)
......@@ -75,6 +74,7 @@ More items (first items will enter 'In progress list' first):
-> cleanup code and update README.png
Done (newest features come first):
-> ADD: google-like search on thumbnails
-> ADD: use kde wallet for storing passwords of protected files
-> The branch 'kpdf_annotations' was created at this point. [2005-Feb-12]
-> FIX: trigger redraw on 'filter text' on current page (need new highligh engine first)
......
/***************************************************************************
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
* Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> *
* Copyright (C) 2004-2005 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -622,7 +622,7 @@ bool KPDFDocument::searchText( int searchID, const QString & text, bool fromStar
// 1. ALLDOC - proces all document marking pages
if ( type == AllDoc )
{
// search and highlight text on all pages
// search and highlight 'text' (as a solid phrase) on all pages
QValueVector< KPDFPage * >::iterator it = pages_vector.begin(), end = pages_vector.end();
for ( ; it != end; ++it )
{
......@@ -665,9 +665,8 @@ bool KPDFDocument::searchText( int searchID, const QString & text, bool fromStar
// reset cursor to previous shape
QApplication::restoreOverrideCursor();
// send page lists if found anything new
//if ( foundAMatch ) ?maybe?
foreachObserver( notifySetup( pages_vector, false ) );
// send page lists to update observers (since some filter on bookmarks)
foreachObserver( notifySetup( pages_vector, false ) );
}
// 2. NEXTMATCH - find next matching item (or start from top)
else if ( type == NextMatch )
......@@ -749,9 +748,77 @@ bool KPDFDocument::searchText( int searchID, const QString & text, bool fromStar
else if ( type == PrevMatch )
{
}
// 4. GOOGLELIKE //TODO
else if ( type == GoogleLike )
// 4. GOOGLE* - process all document marking pages
else if ( type == GoogleAll || type == GoogleAny )
{
// search and highlight every word in 'text' on all pages
bool matchAll = type == GoogleAll;
QStringList words = QStringList::split( " ", text );
int wordsCount = words.count(),
hueStep = (wordsCount > 1) ? (60 / (wordsCount - 1)) : 60,
baseHue, baseSat, baseVal;
color.getHsv( &baseHue, &baseSat, &baseVal );
QValueVector< KPDFPage * >::iterator it = pages_vector.begin(), end = pages_vector.end();
for ( ; it != end; ++it )
{
// get page (from the first to the last)
KPDFPage * page = *it;
int pageNumber = page->number();
// request search page if needed
if ( !page->hasSearchPage() )
requestTextPage( pageNumber );
// loop on a page adding highlights for all found items
bool allMatched = wordsCount > 0,
anyMatched = false;
for ( int w = 0; w < wordsCount; w++ )
{
QString word = words[ w ];
int newHue = baseHue - w * hueStep;
if ( newHue < 0 )
newHue += 360;
QColor wordColor = QColor( newHue, baseSat, baseVal, QColor::Hsv );
NormalizedRect * lastMatch = 0;
// add all highlights for current word
bool wordMatched = false;
while ( 1 )
{
if ( lastMatch )
lastMatch = page->findText( word, caseSensitive, lastMatch );
else
lastMatch = page->findText( word, caseSensitive );
if ( !lastMatch )
break;
// add highligh rect to the page
page->setHighlight( searchID, lastMatch, wordColor );
wordMatched = true;
}
allMatched = allMatched && wordMatched;
anyMatched = anyMatched || wordMatched;
}
// if not all words are present in page, remove partial highlights
if ( !allMatched && matchAll )
page->deleteHighlights( searchID );
// if page contains all words, udpate internals and queue page for notify
if ( (allMatched && matchAll) || (anyMatched && !matchAll) )
{
foundAMatch = true;
s->highlightedPages.append( pageNumber );
if ( !pagesToNotify.contains( pageNumber ) )
pagesToNotify.append( pageNumber );
}
}
// reset cursor to previous shape
QApplication::restoreOverrideCursor();
// send page lists to update observers (since some filter on bookmarks)
foreachObserver( notifySetup( pages_vector, false ) );
}
// notify observers about highlights changes
......
/***************************************************************************
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
* Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> *
* Copyright (C) 2004-2005 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -83,7 +83,7 @@ class KPDFDocument : public QObject
void requestTextPage( uint page );
void addPageAnnotation( int page, Annotation * annotation );
enum SearchType { NextMatch, PrevMatch, AllDoc, GoogleLike };
enum SearchType { NextMatch, PrevMatch, AllDoc, GoogleAll, GoogleAny };
bool searchText( int searchID, const QString & text, bool fromStart, bool caseSensitive,
SearchType type, bool moveViewport, const QColor & color, bool noDialogs = false );
bool continueSearch( int searchID );
......
/***************************************************************************
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
* Copyright (C) 2004-2005 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 *
......@@ -24,14 +24,13 @@
#include "core/document.h"
#include "conf/settings.h"
// uncomment following to enable the case switching button
//#define SW_ENABLE_CASE_BUTTON
#define CLEAR_ID 1
#define LEDIT_ID 2
#define FIND_ID 3
SearchWidget::SearchWidget( QWidget * parent, KPDFDocument * document )
: KToolBar( parent, "iSearchBar" ), m_document( document ), m_caseSensitive( false )
: KToolBar( parent, "iSearchBar" ), m_document( document ),
m_searchType( 0 ), m_caseSensitive( false )
{
// change toolbar appearance
setMargin( 3 );
......@@ -44,31 +43,31 @@ SearchWidget::SearchWidget( QWidget * parent, KPDFDocument * document )
connect( m_inputDelayTimer, SIGNAL( timeout() ),
this, SLOT( startSearch() ) );
// line edit
// 1. text line
insertLined( QString::null, LEDIT_ID, SIGNAL( textChanged(const QString &) ),
this, SLOT( slotTextChanged(const QString &) ), true,
i18n( "Enter at least 3 letters to filter pages" ), 0/*size*/, 1 );
// clear button (uses a lineEdit slot, so it must be created after)
// 2. clear button (uses a lineEdit slot, so it must be created after)
insertButton( QApplication::reverseLayout() ? "clear_left" : "locationbar_erase",
CLEAR_ID, SIGNAL( clicked() ),
getLined( LEDIT_ID ), SLOT( clear() ), true,
i18n( "Clear filter" ), 0/*index*/ );
#ifdef SW_ENABLE_CASE_BUTTON
// create popup menu for change case button
m_caseMenu = new KPopupMenu( this );
m_caseMenu->insertItem( i18n("Case Insensitive"), 1 );
m_caseMenu->insertItem( i18n("Case Sensitive"), 2 );
m_caseMenu->setItemChecked( 1, true );
connect( m_caseMenu, SIGNAL( activated(int) ), SLOT( slotCaseChanged(int) ) );
// 3.1. create the popup menu for changing filtering features
m_menu = new KPopupMenu( this );
m_menu->insertItem( i18n("Case Sensitive"), 1 );
m_menu->insertSeparator( 2 );
m_menu->insertItem( i18n("Match Phrase"), 3 );
m_menu->insertItem( i18n("Match All Words"), 4 );
m_menu->insertItem( i18n("Match Any Word"), 5 );
m_menu->setItemChecked( 3, true );
connect( m_menu, SIGNAL( activated(int) ), SLOT( slotMenuChaged(int) ) );
// create the change case button
insertButton( "find", FIND_ID, m_caseMenu, true,
i18n( "Change Case" ), 2/*index*/ );
#endif
// 3.2. create the toolbar button that spawns the popup menu
insertButton( "kpdf", FIND_ID, m_menu, true, i18n( "Filter Options" ), 2/*index*/ );
// setStretchableWidget( lineEditWidget );
// always maximize the text line
setItemAutoSized( LEDIT_ID );
}
......@@ -88,13 +87,40 @@ void SearchWidget::slotTextChanged( const QString & text )
m_inputDelayTimer->start(333, true);
}
void SearchWidget::slotMenuChaged( int index )
{
// update internal variables and checked state
if ( index == 1 )
{
m_caseSensitive = !m_caseSensitive;
m_menu->setItemChecked( 1, m_caseSensitive );
}
else if ( index >= 3 && index <= 5 )
{
m_searchType = index - 3;
for ( int i = 0; i < 3; i++ )
m_menu->setItemChecked( i + 3, m_searchType == i );
}
else
return;
// update search
slotTextChanged( getLined( LEDIT_ID )->text() );
}
void SearchWidget::startSearch()
{
// search text if have more than 3 chars or else clear search
QString text = getLined( LEDIT_ID )->text();
bool ok = true;
if ( text.length() >= 3 )
ok = m_document->searchText( SW_SEARCH_ID, text, true, m_caseSensitive, KPDFDocument::AllDoc, false, qRgb( 0, 183, 255 ) );
{
KPDFDocument::SearchType type = !m_searchType ? KPDFDocument::AllDoc :
( (m_searchType > 1) ? KPDFDocument::GoogleAny :
KPDFDocument::GoogleAll );
ok = m_document->searchText( SW_SEARCH_ID, text, true, m_caseSensitive,
type, false, qRgb( 0, 183, 255 ) );
}
else
m_document->resetSearch( SW_SEARCH_ID );
// if not found, use warning colors
......@@ -106,16 +132,4 @@ void SearchWidget::startSearch()
}
}
void SearchWidget::slotCaseChanged( int index )
{
bool newState = (index == 2);
if ( newState != m_caseSensitive )
{
m_caseSensitive = newState;
m_caseMenu->setItemChecked( 1, !m_caseSensitive );
m_caseMenu->setItemChecked( 2, m_caseSensitive );
slotTextChanged( getLined( LEDIT_ID )->text() );
}
}
#include "searchwidget.moc"
/***************************************************************************
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
* Copyright (C) 2004-2005 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 *
......@@ -36,13 +36,14 @@ class SearchWidget : public KToolBar
private:
KPDFDocument * m_document;
KPopupMenu * m_caseMenu;
KPopupMenu * m_menu;
QTimer * m_inputDelayTimer;
int m_searchType;
bool m_caseSensitive;
private slots:
void slotTextChanged( const QString & text );
void slotCaseChanged( int index );
void slotMenuChaged( int index );
void startSearch();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment