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@kde.org svn path=/trunk/playground/graphics/okular/; revision=643607remotes/origin/KDE/4.0
parent
af1fd0c1f3
commit
f55c401b20
12 changed files with 385 additions and 147 deletions
@ -0,0 +1,94 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> * |
||||
* * |
||||
* 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. * |
||||
***************************************************************************/ |
||||
|
||||
// qt/kde includes
|
||||
#include <qlayout.h> |
||||
#include <qmenu.h> |
||||
#include <qtoolbutton.h> |
||||
#include <kicon.h> |
||||
#include <klocale.h> |
||||
#include <kpushbutton.h> |
||||
|
||||
// local includes
|
||||
#include "findbar.h" |
||||
#include "searchlineedit.h" |
||||
#include "core/document.h" |
||||
|
||||
FindBar::FindBar( Okular::Document * document, QWidget * parent ) |
||||
: QWidget( parent ) |
||||
{ |
||||
QHBoxLayout * lay = new QHBoxLayout( this ); |
||||
lay->setMargin( 2 ); |
||||
|
||||
QToolButton * closeBtn = new QToolButton( this ); |
||||
closeBtn->setIcon( KIcon( "fileclose" ) ); |
||||
closeBtn->setIconSize( QSize( 24, 24 ) ); |
||||
closeBtn->setToolTip( i18n( "Close" ) ); |
||||
closeBtn->setAutoRaise( true ); |
||||
lay->addWidget( closeBtn ); |
||||
|
||||
m_text = new SearchLineEdit( this, document ); |
||||
m_text->setSearchCaseSensitivity( Qt::CaseInsensitive ); |
||||
m_text->setSearchMinimumLength( 0 ); |
||||
m_text->setSearchType( Okular::Document::NextMatch ); |
||||
m_text->setSearchId( PART_SEARCH_ID ); |
||||
m_text->setSearchColor( qRgb( 255, 255, 64 ) ); |
||||
m_text->setSearchMoveViewport( true ); |
||||
lay->addWidget( m_text ); |
||||
|
||||
KPushButton * findNextBtn = new KPushButton( KIcon( "find-next" ), i18n( "Find Next" ), this ); |
||||
lay->addWidget( findNextBtn ); |
||||
|
||||
QPushButton * optionsBtn = new QPushButton( this ); |
||||
optionsBtn->setText( i18n( "Options" ) ); |
||||
QMenu * optionsMenu = new QMenu(); |
||||
m_caseSensitiveAct = optionsMenu->addAction( i18n( "Case sensitive" ) ); |
||||
m_caseSensitiveAct->setCheckable( true ); |
||||
optionsBtn->setMenu( optionsMenu ); |
||||
lay->addWidget( optionsBtn ); |
||||
|
||||
connect( closeBtn, SIGNAL( clicked() ), this, SLOT( close() ) ); |
||||
connect( findNextBtn, SIGNAL( clicked() ), this, SLOT( findNext() ) ); |
||||
connect( m_caseSensitiveAct, SIGNAL( toggled( bool ) ), this, SLOT( caseSensitivityChanged() ) ); |
||||
|
||||
hide(); |
||||
} |
||||
|
||||
FindBar::~FindBar() |
||||
{ |
||||
} |
||||
|
||||
QString FindBar::text() const |
||||
{ |
||||
return m_text->text(); |
||||
} |
||||
|
||||
Qt::CaseSensitivity FindBar::caseSensitivity() const |
||||
{ |
||||
return m_caseSensitiveAct->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; |
||||
} |
||||
|
||||
void FindBar::focusAndSetCursor() |
||||
{ |
||||
setFocus(); |
||||
m_text->setFocus(); |
||||
} |
||||
|
||||
void FindBar::findNext() |
||||
{ |
||||
m_text->findNext(); |
||||
} |
||||
|
||||
void FindBar::caseSensitivityChanged() |
||||
{ |
||||
m_text->setSearchCaseSensitivity( m_caseSensitiveAct->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive ); |
||||
m_text->restartSearch(); |
||||
} |
||||
|
||||
#include "findbar.moc" |
||||
@ -0,0 +1,48 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> * |
||||
* * |
||||
* 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. * |
||||
***************************************************************************/ |
||||
|
||||
#ifndef _FINDBAR_H_ |
||||
#define _FINDBAR_H_ |
||||
|
||||
#include <qwidget.h> |
||||
|
||||
class QAction; |
||||
class SearchLineEdit; |
||||
|
||||
namespace Okular { |
||||
class Document; |
||||
} |
||||
|
||||
class FindBar |
||||
: public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
FindBar( Okular::Document * document, QWidget * parent = 0 ); |
||||
virtual ~FindBar(); |
||||
|
||||
QString text() const; |
||||
Qt::CaseSensitivity caseSensitivity() const; |
||||
|
||||
void focusAndSetCursor(); |
||||
|
||||
public slots: |
||||
void findNext(); |
||||
|
||||
private slots: |
||||
void caseSensitivityChanged(); |
||||
|
||||
private: |
||||
SearchLineEdit * m_text; |
||||
QAction * m_caseSensitiveAct; |
||||
}; |
||||
|
||||
|
||||
#endif |
||||
@ -0,0 +1,132 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> * |
||||
* * |
||||
* 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 <qevent.h> |
||||
#include <qlayout.h> |
||||
#include <qstyle.h> |
||||
#include <qstyleoption.h> |
||||
#include <qstylepainter.h> |
||||
#include <qtoolbutton.h> |
||||
|
||||
#include <kicon.h> |
||||
#include <klocale.h> |
||||
|
||||
#include "presentationsearchbar.h" |
||||
#include "searchlineedit.h" |
||||
|
||||
#define SNAP_DELTA 15 |
||||
|
||||
class HandleDrag |
||||
: public QWidget |
||||
{ |
||||
public: |
||||
HandleDrag( QWidget *parent = 0 ) |
||||
: QWidget( parent ) |
||||
{ |
||||
setCursor( Qt::SizeAllCursor ); |
||||
setFixedWidth( style()->pixelMetric( QStyle::PM_ToolBarHandleExtent ) ); |
||||
installEventFilter( parent ); |
||||
} |
||||
|
||||
void paintEvent( QPaintEvent * ) |
||||
{ |
||||
QStyleOption opt; |
||||
opt.initFrom( this ); |
||||
opt.state |= QStyle::State_Horizontal; |
||||
QStylePainter p( this ); |
||||
p.drawPrimitive( QStyle::PE_IndicatorToolBarHandle, opt ); |
||||
} |
||||
}; |
||||
|
||||
|
||||
PresentationSearchBar::PresentationSearchBar( Okular::Document *document, QWidget *anchor, QWidget *parent ) |
||||
: QWidget( parent ), m_anchor( anchor ), m_snapped( true ) |
||||
{ |
||||
setAutoFillBackground( true ); |
||||
|
||||
QHBoxLayout * lay = new QHBoxLayout( this ); |
||||
lay->setMargin( 0 ); |
||||
|
||||
m_handle = new HandleDrag( this ); |
||||
lay->addWidget( m_handle ); |
||||
|
||||
QToolButton * closeBtn = new QToolButton( this ); |
||||
closeBtn->setIcon( KIcon( "fileclose" ) ); |
||||
closeBtn->setIconSize( QSize( 24, 24 ) ); |
||||
closeBtn->setToolTip( i18n( "Close" ) ); |
||||
closeBtn->setAutoRaise( true ); |
||||
lay->addWidget( closeBtn ); |
||||
|
||||
m_search = new SearchLineEdit( this, document ); |
||||
m_search->setClearButtonShown( true ); |
||||
m_search->setSearchCaseSensitivity( Qt::CaseInsensitive ); |
||||
m_search->setSearchMinimumLength( 0 ); |
||||
m_search->setSearchType( Okular::Document::NextMatch ); |
||||
m_search->setSearchId( PRESENTATION_SEARCH_ID ); |
||||
m_search->setSearchColor( qRgb( 255, 255, 64 ) ); |
||||
m_search->setSearchMoveViewport( true ); |
||||
lay->addWidget( m_search ); |
||||
|
||||
m_anchor->installEventFilter( this ); |
||||
|
||||
connect( closeBtn, SIGNAL( clicked() ), this, SLOT( close() ) ); |
||||
|
||||
// force the initial snap
|
||||
forceSnap(); |
||||
} |
||||
|
||||
PresentationSearchBar::~PresentationSearchBar() |
||||
{ |
||||
} |
||||
|
||||
void PresentationSearchBar::forceSnap() |
||||
{ |
||||
m_point = QPoint( m_anchor->width() / 2, m_anchor->height() ); |
||||
m_snapped = true; |
||||
move( m_point.x() - width() / 2, m_point.y() - height() ); |
||||
} |
||||
|
||||
bool PresentationSearchBar::eventFilter( QObject *obj, QEvent *e ) |
||||
{ |
||||
if ( obj == m_handle && |
||||
( e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::MouseMove ) ) |
||||
{ |
||||
QMouseEvent *me = (QMouseEvent*)e; |
||||
if ( e->type() == QEvent::MouseButtonPress ) |
||||
{ |
||||
m_drag = m_handle->mapTo( this, me->pos() ); |
||||
} |
||||
else if ( e->type() == QEvent::MouseButtonRelease ) |
||||
{ |
||||
m_drag = QPoint(); |
||||
} |
||||
else if ( e->type() == QEvent::MouseMove ) |
||||
{ |
||||
QPoint snapdelta( width() / 2, height() ); |
||||
QPoint delta = m_handle->mapTo( this, me->pos() ) - m_drag; |
||||
QPoint newpostemp = pos() + delta; |
||||
QPoint tmp = newpostemp + snapdelta - m_point; |
||||
QPoint newpos = abs( tmp.x() ) < SNAP_DELTA && abs( tmp.y() ) < SNAP_DELTA ? m_point - snapdelta : newpostemp; |
||||
m_snapped = newpos == ( m_point - snapdelta ); |
||||
move( newpos ); |
||||
} |
||||
return true; |
||||
} |
||||
if ( obj == m_anchor && e->type() == QEvent::Resize ) |
||||
{ |
||||
m_point = QPoint( m_anchor->width() / 2, m_anchor->height() ); |
||||
|
||||
if ( m_snapped ) |
||||
move( m_point.x() - width() / 2, m_point.y() - height() ); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
#include "presentationsearchbar.moc" |
||||
@ -0,0 +1,45 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> * |
||||
* * |
||||
* 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. * |
||||
***************************************************************************/ |
||||
|
||||
#ifndef _OKULAR_PRESENTATIONSEARCHBAR_H_ |
||||
#define _OKULAR_PRESENTATIONSEARCHBAR_H_ |
||||
|
||||
#include <qwidget.h> |
||||
|
||||
class SearchLineEdit; |
||||
|
||||
namespace Okular { |
||||
class Document; |
||||
} |
||||
|
||||
class PresentationSearchBar |
||||
: public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
PresentationSearchBar( Okular::Document *document, QWidget *anchor, QWidget *parent = 0 ); |
||||
virtual ~PresentationSearchBar(); |
||||
|
||||
void forceSnap(); |
||||
|
||||
protected: |
||||
bool eventFilter( QObject *, QEvent * ); |
||||
|
||||
private: |
||||
QWidget *m_handle; |
||||
QWidget *m_anchor; |
||||
QPoint m_point; |
||||
bool m_snapped; |
||||
QPoint m_drag; |
||||
|
||||
SearchLineEdit *m_search; |
||||
}; |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue