[Okular-devel] playground/graphics/okular

Pino Toscano toscano.pino at tiscali.it
Sat Mar 17 23:58:48 CET 2007


SVN commit 643607 by pino:

Refactor the document search interfaces, as discussed on the mailing list.
Merge the search in normal mode and the type-ahead in a search bar that appears on the bottom of the page view. This should work nicely.
In presentation mode, add a small floating search toolbar that takes care of searching during the presentation mode, on document request. This is not working yet, but basically most of the work is done.

Please test and report any problems you find.

CCMAIL: okular-devel at kde.org


 M  +2 -0      CMakeLists.txt  
 M  +1 -0      core/document.h  
 M  +35 -21    part.cpp  
 M  +4 -0      part.h  
 A             ui/findbar.cpp   [License: GPL (v2+)]
 A             ui/findbar.h   [License: GPL (v2+)]
 M  +1 -121    ui/pageview.cpp  
 M  +0 -4      ui/pageview.h  
 A             ui/presentationsearchbar.cpp   [License: GPL (v2+)]
 A             ui/presentationsearchbar.h   [License: GPL (v2+)]
 M  +20 -1     ui/presentationwidget.cpp  
 M  +3 -0      ui/presentationwidget.h  


--- trunk/playground/graphics/okular/CMakeLists.txt #643606:643607
@@ -101,6 +101,7 @@
    ui/annotationtools.cpp
    ui/annotationwidgets.cpp
    ui/bookmarklist.cpp
+   ui/findbar.cpp
    ui/formwidgets.cpp
    ui/minibar.cpp
    ui/newstuff.cpp
@@ -110,6 +111,7 @@
    ui/pageviewannotator.cpp
    ui/pageview.cpp
    ui/pageviewutils.cpp
+   ui/presentationsearchbar.cpp
    ui/presentationwidget.cpp
    ui/propertiesdialog.cpp
    ui/searchlineedit.cpp
--- trunk/playground/graphics/okular/core/document.h #643606:643607
@@ -54,6 +54,7 @@
 #define PART_SEARCH_ID 1
 #define PAGEVIEW_SEARCH_ID 2
 #define SW_SEARCH_ID 3
+#define PRESENTATION_SEARCH_ID 4
 
 
 /**
--- trunk/playground/graphics/okular/part.cpp #643606:643607
@@ -36,9 +36,7 @@
 #include <kstandardaction.h>
 #include <kparts/genericfactory.h>
 #include <kfiledialog.h>
-#include <kfind.h>
 #include <kmessagebox.h>
-#include <kfinddialog.h>
 #include <knuminput.h>
 #include <kio/netaccess.h>
 #include <kmenu.h>
@@ -69,6 +67,7 @@
 #include "ui/presentationwidget.h"
 #include "ui/pagesizelabel.h"
 #include "ui/bookmarklist.h"
+#include "ui/findbar.h"
 #include "conf/preferencesdialog.h"
 #include "settings.h"
 #include "core/bookmarkmanager.h"
@@ -221,6 +220,8 @@
     connect( m_document, SIGNAL( warning( const QString&, int ) ), m_pageView, SLOT( warningMessage( const QString&, int ) ) );
     connect( m_document, SIGNAL( notice( const QString&, int ) ), m_pageView, SLOT( noticeMessage( const QString&, int ) ) );
     rightLayout->addWidget( m_pageView );
+    m_findBar = new FindBar( m_document, rightContainer );
+    rightLayout->addWidget( m_findBar );
     QWidget * bottomBar = new QWidget( rightContainer );
     QHBoxLayout * bottomBarLayout = new QHBoxLayout( bottomBar );
     m_pageSizeLabel = new PageSizeLabel( bottomBar, m_document );
@@ -309,8 +310,11 @@
     ac->addAction("edit_copy",m_copy);
 
     // Find and other actions
-    m_find = KStandardAction::find( this, SLOT( slotFind() ), ac );
+    m_find = KStandardAction::find( this, SLOT( slotShowFindBar() ), ac );
     ac->addAction("find", m_find);
+    QList<QKeySequence> s = m_find->shortcuts();
+    s.append( QKeySequence( Qt::Key_Slash ) );
+    m_find->setShortcuts( s );
     m_find->setEnabled( false );
 
     m_findNext = KStandardAction::findNext( this, SLOT( slotFindNext() ), ac);
@@ -396,6 +400,12 @@
     m_aboutBackend->setText(i18n("About backend..."));
     connect(m_aboutBackend, SIGNAL(triggered()), this, SLOT(slotAboutBackend()));
 
+    KAction *closeFindBar = new KAction( i18n( "Close &Find Bar" ), ac );
+    ac->addAction("close_find_bar", closeFindBar);
+    connect(closeFindBar, SIGNAL(triggered()), this, SLOT(slotHideFindBar()));
+    closeFindBar->setShortcut( QKeySequence( Qt::Key_Escape ) );
+    widget()->addAction(closeFindBar);
+
     // attach the actions of the children widgets too
     m_pageView->setupActions( ac );
     m_formsMessage->setActionButton( m_pageView->toggleFormsAction() );
@@ -928,6 +938,18 @@
 }
 
 
+void Part::slotShowFindBar()
+{
+    m_findBar->show();
+    m_findBar->focusAndSetCursor();
+}
+
+void Part::slotHideFindBar()
+{
+    m_findBar->hide();
+    m_pageView->setFocus();
+}
+
 //BEGIN go to page dialog
 class GotoPageDialog : public KDialog
 {
@@ -1055,29 +1077,21 @@
 
 void Part::slotFind()
 {
-    KFindDialog dlg( widget() );
-    dlg.setHasCursor( false );
-    if ( !m_searchHistory.empty() )
-        dlg.setFindHistory( m_searchHistory );
-    dlg.setSupportsBackwardsFind( false );
-    dlg.setSupportsWholeWordsFind( false );
-    dlg.setSupportsRegularExpressionFind( false );
-    if ( dlg.exec() == QDialog::Accepted )
-    {
-        m_searchHistory = dlg.findHistory();
-        m_searchStarted = true;
-        m_document->resetSearch( PART_SEARCH_ID );
-        m_document->searchText( PART_SEARCH_ID, dlg.pattern(), false,
-            dlg.options() & KFind::CaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive,
-            Okular::Document::NextMatch, true, qRgb( 255, 255, 64 ) );
-    }
+    // when in presentation mode, there's already a search bar, taking care of
+    // the 'find' requests
+    if ( (PresentationWidget*)m_presentationWidget != 0 )
+        return;
+
+    slotShowFindBar();
 }
 
 
 void Part::slotFindNext()
 {
-    if (!m_document->continueLastSearch())
-        slotFind();
+    if (m_findBar->isHidden())
+        slotShowFindBar();
+    else
+        m_findBar->findNext();
 }
 
 
--- trunk/playground/graphics/okular/part.h #643606:643607
@@ -41,6 +41,7 @@
 class KPrinter;
 class KTemporaryFile;
 
+class FindBar;
 class ThumbnailList;
 class ThumbnailController;
 class PageSizeLabel;
@@ -139,6 +140,8 @@
         void close();
         void cannotQuit();
         void splitterMoved( int pos, int index );
+        void slotShowFindBar();
+        void slotHideFindBar();
         void setMimeTypes(KIO::Job *job);
         void readMimeType(KIO::Job *job, const QString &mime);
         void saveSplitterSize();
@@ -171,6 +174,7 @@
         QWidget *m_leftPanel;
         QToolBox *m_toolBox;
         SearchWidget *m_searchWidget;
+        FindBar * m_findBar;
         PageViewTopMessage * m_topMessage;
         PageViewTopMessage * m_formsMessage;
         QPointer<ThumbnailList> m_thumbnailList;
--- trunk/playground/graphics/okular/ui/pageview.cpp #643606:643607
@@ -108,10 +108,6 @@
     QSet< int > pagesWithTextSelection;
     bool mouseOnRect;
 
-    // type ahead find
-    bool typeAheadActive;
-    QString typeAheadString;
-    QTimer * findTimeoutTimer;
     // viewport move
     bool viewportMoveActive;
     QTime viewportMoveTime;
@@ -269,8 +265,6 @@
     d->mouseSelecting = false;
     d->mouseTextSelecting = false;
     d->mouseOnRect = false;
-    d->typeAheadActive = false;
-    d->findTimeoutTimer = 0;
     d->viewportMoveActive = false;
     d->viewportMoveTimer = 0;
     d->scrollIncrement = 0;
@@ -1020,90 +1014,6 @@
     if ( ( d->mouseSelecting && e->key() != Qt::Key_Escape ) || d->mouseMidZooming )
         return;
 
-    // handle 'find as you type' (based on khtml/khtmlview.cpp)
-    if( d->typeAheadActive )
-    {
-        // backspace: remove a char and search or terminates search
-        if( e->key() == Qt::Key_Backspace )
-        {
-            if( d->typeAheadString.length() > 1 )
-            {
-                d->typeAheadString = d->typeAheadString.left( d->typeAheadString.length() - 1 );
-                bool found = d->document->searchText( PAGEVIEW_SEARCH_ID, d->typeAheadString,
-                                                      true, Qt::CaseInsensitive,
-                                                      Okular::Document::NextMatch, true, qRgb( 128, 255, 128 ), true );
-                KLocalizedString status = found ? ki18n("Text found: \"%1\".") : ki18n("Text not found: \"%1\".");
-                d->messageWindow->display( status.subs(d->typeAheadString.toLower()).toString(),
-                                           found ? PageViewMessage::Find : PageViewMessage::Warning, 4000 );
-                d->findTimeoutTimer->start( 3000 );
-            }
-            else
-            {
-                slotStopFindAhead();
-                d->document->resetSearch( PAGEVIEW_SEARCH_ID );
-            }
-        }
-        // go to next occurrency
-#ifdef __GNUC__
-#warning FIX the find next shortcut
-#endif
-        else if( e->key() == Qt::Key_F3 /*d->actionCollection->action( "find_next" )->shortcut().keyQt()*/ )
-        {
-            // part doesn't get this key event because of the keyboard grab
-            d->findTimeoutTimer->stop(); // restore normal operation during possible messagebox is displayed
-            // (1/4) it is needed to grab the keyboard becase people may have Space assigned
-            // to a accel and without grabbing the keyboard you can not vim-search for space
-            // because it activates the accel
-            releaseKeyboard();
-            if ( d->document->continueSearch( PAGEVIEW_SEARCH_ID ) )
-                d->messageWindow->display( i18n("Text found: \"%1\".", d->typeAheadString.toLower()),
-                                           PageViewMessage::Find, 3000 );
-            d->findTimeoutTimer->start( 3000 );
-            // (2/4) it is needed to grab the keyboard becase people may have Space assigned
-            // to a accel and without grabbing the keyboard you can not vim-search for space
-            // because it activates the accel
-            grabKeyboard();
-        }
-        // esc and return: end search
-        else if( e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return )
-        {
-            slotStopFindAhead();
-        }
-        // other key: add to text and search
-        else if( !e->text().isEmpty() )
-        {
-            d->typeAheadString += e->text();
-            doTypeAheadSearch();
-        }
-        return;
-    }
-    else if( e->key() == '/' && d->document->isOpened() && d->document->supportsSearching() )
-    {
-        // stop scrolling the page (if doing it)
-        if ( d->autoScrollTimer )
-        {
-            d->scrollIncrement = 0;
-            d->autoScrollTimer->stop();
-        }
-        // start type-adeas search
-        d->typeAheadString = QString();
-        d->messageWindow->display( i18n("Starting -- find text as you type"), PageViewMessage::Find, 3000 );
-        d->typeAheadActive = true;
-        if ( !d->findTimeoutTimer )
-        {
-            // create the timer on demand
-            d->findTimeoutTimer = new QTimer( this );
-            d->findTimeoutTimer->setSingleShot( true );
-            connect( d->findTimeoutTimer, SIGNAL( timeout() ), this, SLOT( slotStopFindAhead() ) );
-        }
-        d->findTimeoutTimer->start( 3000 );
-        // (3/4) it is needed to grab the keyboard becase people may have Space assigned
-        // to a accel and without grabbing the keyboard you can not vim-search for space
-        // because it activates the accel
-        grabKeyboard();
-        return;
-    }
-
     // if viewport is moving, disable keys handling
     if ( d->viewportMoveActive )
         return;
@@ -1197,15 +1107,7 @@
 
 void PageView::inputMethodEvent( QInputMethodEvent * e )
 {
-    if( d->typeAheadActive )
-    {
-        if( !e->commitString().isEmpty() )
-        {
-            d->typeAheadString += e->commitString();
-            doTypeAheadSearch();
-            e->accept();
-        }
-    }
+    Q_UNUSED(e)
 }
 
 void PageView::contentsMouseMoveEvent( QMouseEvent * e )
@@ -2411,17 +2313,6 @@
     }
 }
 
-void PageView::doTypeAheadSearch()
-{
-    bool found = d->document->searchText( PAGEVIEW_SEARCH_ID, d->typeAheadString,
-                                          false, Qt::CaseInsensitive,
-                                          Okular::Document::NextMatch, true, qRgb( 128, 255, 128 ), true );
-    KLocalizedString status = found ? ki18n("Text found: \"%1\".") : ki18n("Text not found: \"%1\".");
-    d->messageWindow->display( status.subs(d->typeAheadString.toLower()).toString(),
-                               found ? PageViewMessage::Find : PageViewMessage::Warning, 4000 );
-    d->findTimeoutTimer->start( 3000 );
-}
-
 //BEGIN private SLOTS
 void PageView::slotRelayoutPages()
 // called by: notifySetup, viewportResizeEvent, slotRenderMode, slotContinuousToggled, updateZoom
@@ -2887,17 +2778,6 @@
     selectionEndPoint( p );
 }
 
-void PageView::slotStopFindAhead()
-{
-    d->typeAheadActive = false;
-    d->typeAheadString = "";
-    d->messageWindow->display( i18n("Find stopped."), PageViewMessage::Find, 1000 );
-    // (4/4) it is needed to grab the keyboard becase people may have Space assigned
-    // to a accel and without grabbing the keyboard you can not vim-search for space
-    // because it activates the accel
-    releaseKeyboard();
-}
-
 void PageView::slotShowWelcome()
 {
     // show initial welcome text
--- trunk/playground/graphics/okular/ui/pageview.h #643606:643607
@@ -143,8 +143,6 @@
         void textSelectionClear();
         // updates cursor
         void updateCursor( const QPoint &p );
-        // does the type ahead search
-        void doTypeAheadSearch();
 
         int viewColumns() const;
         int viewRows() const;
@@ -167,8 +165,6 @@
         void slotAutoScoll();
         // activated by the dragScroll timer
         void slotDragScroll();
-        // type-ahead find timeout
-        void slotStopFindAhead();
         // show the welcome message
         void slotShowWelcome();
 
--- trunk/playground/graphics/okular/ui/presentationwidget.cpp #643606:643607
@@ -39,6 +39,7 @@
 #include "presentationwidget.h"
 #include "annotationtools.h"
 #include "pagepainter.h"
+#include "presentationsearchbar.h"
 #include "core/audioplayer.h"
 #include "core/document.h"
 #include "core/generator.h"
@@ -87,7 +88,7 @@
 PresentationWidget::PresentationWidget( QWidget * parent, Okular::Document * doc )
     : QDialog( parent, Qt::FramelessWindowHint ),
     m_pressedLink( 0 ), m_handCursor( false ), m_drawingEngine( 0 ), m_document( doc ),
-    m_frameIndex( -1 ), m_topBar( 0 ), m_pagesEdit( 0 )
+    m_frameIndex( -1 ), m_topBar( 0 ), m_pagesEdit( 0 ), m_searchBar( 0 )
 {
     setModal( true );
     setAttribute( Qt::WA_DeleteOnClose );
@@ -135,6 +136,12 @@
     // stop the audio playbacks
     Okular::AudioPlayer::instance()->stopPlaybacks();
 
+    // remove our highlights
+    if ( m_searchBar )
+    {
+        m_document->resetSearch( PRESENTATION_SEARCH_ID );
+    }
+
     // remove this widget from document observer
     m_document->removeObserver( this );
 
@@ -444,6 +451,8 @@
         p.setColor( QPalette::Active, QPalette::Background, Qt::darkGray );
         m_topBar->setPalette( p );
 
+        connect( m_document, SIGNAL( linkFind() ), this, SLOT( slotFind() ) );
+
         // register this observer in document. events will come immediately
         m_document->addObserver( this );
 
@@ -1069,7 +1078,17 @@
     m_currentPageDrawings.clear();
 }
 
+void PresentationWidget::slotFind()
+{
+    if ( !m_searchBar )
+    {
+        m_searchBar = new PresentationSearchBar( m_document, this, this );
+        m_searchBar->forceSnap();
+    }
+    m_searchBar->show();
+}
 
+
 const Okular::PageTransition PresentationWidget::defaultTransition() const
 {
     return defaultTransition( Okular::Settings::slidesTransition() );
--- trunk/playground/graphics/okular/ui/presentationwidget.h #643606:643607
@@ -23,6 +23,7 @@
 class KActionCollection;
 class AnnotatorEngine;
 class PresentationFrame;
+class PresentationSearchBar;
 
 namespace Okular {
 struct Annotation;
@@ -105,6 +106,7 @@
         QStringList m_metaStrings;
         QToolBar * m_topBar;
         QLineEdit *m_pagesEdit;
+        PresentationSearchBar *m_searchBar;
         KActionCollection * m_ac;
 
     private slots:
@@ -118,6 +120,7 @@
         void slotPageChanged();
         void togglePencilMode( bool );
         void clearDrawings();
+        void slotFind();
 };
 
 #endif


More information about the Okular-devel mailing list