Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 06326f73 authored by Jonathan Marten's avatar Jonathan Marten Committed by Albert Astals Cid

Allow the page number selector to be added to the toolbar

Ok, this is not really the review Jonathan did, i did rewrite the code partially because i did not really
want to have a new observer, but the code is heavily inspired in his patch.

Also the page number selector is not in the toolbar as the review had, it'd be silly to have it in both places
by default, so if you want to have it you have to go, edit the toolbar and add the "Page Number" action to it.

REVIEW: 103427
BUGS: 279128
FIXED-IN: 4.9.0
parent 76f96438
......@@ -410,14 +410,18 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
bottomBarLayout->setSpacing( 0 );
bottomBarLayout->addWidget( m_pageSizeLabel->antiWidget() );
bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
m_miniBar = new MiniBar( m_bottomBar, m_document );
MiniBarLogic * miniBarLogic = new MiniBarLogic( this, m_document );
m_miniBar = new MiniBar( m_bottomBar, miniBarLogic );
bottomBarLayout->addWidget( m_miniBar );
bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
bottomBarLayout->addWidget( m_pageSizeLabel );
rightLayout->addWidget( m_bottomBar );
m_pageNumberTool = new MiniBar( 0, miniBarLogic );
connect( m_findBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
connect( m_miniBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
connect( m_pageNumberTool, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
connect( m_reviewsWidget, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)),
m_pageView, SLOT(openAnnotationWindow(Okular::Annotation*,int)) );
......@@ -428,7 +432,7 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
m_document->addObserver( m_pageView );
m_document->registerView( m_pageView );
m_document->addObserver( m_toc );
m_document->addObserver( m_miniBar );
m_document->addObserver( miniBarLogic );
#ifdef OKULAR_ENABLE_MINIBAR
m_document->addObserver( m_progressWidget );
#endif
......@@ -514,6 +518,7 @@ void Part::setupViewerActions()
m_gotoPage->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_G) );
// dirty way to activate gotopage when pressing miniBar's button
connect( m_miniBar, SIGNAL(gotoPage()), m_gotoPage, SLOT(trigger()) );
connect( m_pageNumberTool, SIGNAL(gotoPage()), m_gotoPage, SLOT(trigger()) );
m_prevPage = KStandardAction::prior(this, SLOT(slotPreviousPage()), ac);
m_prevPage->setIconText( i18nc( "Previous page", "Previous" ) );
......@@ -522,6 +527,7 @@ void Part::setupViewerActions()
m_prevPage->setShortcut( 0 );
// dirty way to activate prev page when pressing miniBar's button
connect( m_miniBar, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
connect( m_pageNumberTool, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
#ifdef OKULAR_ENABLE_MINIBAR
connect( m_progressWidget, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
#endif
......@@ -533,6 +539,7 @@ void Part::setupViewerActions()
m_nextPage->setShortcut( 0 );
// dirty way to activate next page when pressing miniBar's button
connect( m_miniBar, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
connect( m_pageNumberTool, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
#ifdef OKULAR_ENABLE_MINIBAR
connect( m_progressWidget, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
#endif
......@@ -655,6 +662,10 @@ void Part::setupViewerActions()
ac->addAction("close_find_bar", m_closeFindBar);
connect(m_closeFindBar, SIGNAL(triggered()), this, SLOT(slotHideFindBar()));
widget()->addAction(m_closeFindBar);
KAction *pageno = new KAction( i18n( "Page Number" ), ac );
pageno->setDefaultWidget( m_pageNumberTool );
ac->addAction( "page_number", pageno );
}
void Part::setViewerShortcuts()
......@@ -775,6 +786,7 @@ Part::~Part()
delete m_pageView;
delete m_thumbnailList;
delete m_miniBar;
delete m_pageNumberTool;
delete m_bottomBar;
#ifdef OKULAR_ENABLE_MINIBAR
delete m_progressWidget;
......
......@@ -239,6 +239,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
QPointer<PageView> m_pageView;
QPointer<TOC> m_toc;
QPointer<MiniBar> m_miniBar;
QPointer<MiniBar> m_pageNumberTool;
QPointer<QWidget> m_bottomBar;
QPointer<PresentationWidget> m_presentationWidget;
QPointer<ProgressWidget> m_progressWidget;
......
......@@ -39,14 +39,126 @@ class HoverButton : public QToolButton
HoverButton( QWidget * parent );
};
MiniBarLogic::MiniBarLogic( QObject * parent, Okular::Document * document )
: QObject(parent)
, m_document( document )
, m_currentPage( -1 )
{
}
MiniBarLogic::~MiniBarLogic()
{
m_document->removeObserver( this );
}
void MiniBarLogic::addMiniBar( MiniBar * miniBar )
{
m_miniBars.insert( miniBar );
}
void MiniBarLogic::removeMiniBar( MiniBar * miniBar )
{
m_miniBars.remove( miniBar );
}
Okular::Document *MiniBarLogic::document() const
{
return m_document;
}
int MiniBarLogic::currentPage() const
{
return m_currentPage;
}
void MiniBarLogic::notifySetup( const QVector< Okular::Page * > & pageVector, int setupFlags )
{
// only process data when document changes
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
// if document is closed or has no pages, hide widget
const int pages = pageVector.count();
if ( pages < 1 )
{
m_currentPage = -1;
foreach ( MiniBar *miniBar, m_miniBars )
{
miniBar->setEnabled( false );
}
return;
}
bool labelsDiffer = false;
foreach(const Okular::Page * page, pageVector)
{
if (!page->label().isEmpty())
{
if (page->label().toInt() != (page->number() + 1))
{
labelsDiffer = true;
}
}
}
const QString pagesString = QString::number( pages );
foreach ( MiniBar *miniBar, m_miniBars )
{
// resize width of widgets
miniBar->resizeForPage( pages );
// update child widgets
miniBar->m_pageLabelEdit->setPageLabels( pageVector );
miniBar->m_pageNumberEdit->setPagesNumber( pages );
miniBar->m_pagesButton->setText( pagesString );
miniBar->m_prevButton->setEnabled( false );
miniBar->m_nextButton->setEnabled( false );
miniBar->m_pageLabelEdit->setVisible( labelsDiffer );
miniBar->m_pageNumberLabel->setVisible( labelsDiffer );
miniBar->m_pageNumberEdit->setVisible( !labelsDiffer );
miniBar->resize( miniBar->minimumSizeHint() );
miniBar->setEnabled( true );
}
}
void MiniBarLogic::notifyViewportChanged( bool /*smoothMove*/ )
{
// get current page number
const int page = m_document->viewport().pageNumber;
const int pages = m_document->pages();
// if the document is opened and page is changed
if ( page != m_currentPage && pages > 0 )
{
m_currentPage = page;
const QString pageNumber = QString::number( page + 1 );
const QString pageLabel = m_document->page(page)->label();
foreach ( MiniBar *miniBar, m_miniBars )
{
// update prev/next button state
miniBar->m_prevButton->setEnabled( page > 0 );
miniBar->m_nextButton->setEnabled( page < ( pages - 1 ) );
// update text on widgets
miniBar->m_pageNumberEdit->setText( pageNumber );
miniBar->m_pageNumberLabel->setText( pageNumber );
miniBar->m_pageLabelEdit->setText( pageLabel );
}
}
}
/** MiniBar **/
MiniBar::MiniBar( QWidget * parent, Okular::Document * document )
: QWidget( parent ), m_document( document ),
m_currentPage( -1 )
MiniBar::MiniBar( QWidget * parent, MiniBarLogic * miniBarLogic )
: QWidget( parent )
, m_miniBarLogic( miniBarLogic )
{
setObjectName( QLatin1String( "miniBar" ) );
m_miniBarLogic->addMiniBar( this );
QHBoxLayout * horLayout = new QHBoxLayout( this );
......@@ -106,7 +218,7 @@ MiniBar::MiniBar( QWidget * parent, Okular::Document * document )
MiniBar::~MiniBar()
{
m_document->removeObserver( this );
m_miniBarLogic->removeMiniBar( this );
}
bool MiniBar::eventFilter( QObject *target, QEvent *event )
......@@ -127,82 +239,16 @@ bool MiniBar::eventFilter( QObject *target, QEvent *event )
return false;
}
void MiniBar::notifySetup( const QVector< Okular::Page * > & pageVector, int setupFlags )
{
// only process data when document changes
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
// if document is closed or has no pages, hide widget
int pages = pageVector.count();
if ( pages < 1 )
{
m_currentPage = -1;
setEnabled( false );
return;
}
// resize width of widgets
resizeForPage( pages );
bool labelsDiffer = false;
foreach(const Okular::Page * page, pageVector)
{
if (!page->label().isEmpty())
{
if (page->label().toInt() != (page->number() + 1))
{
labelsDiffer = true;
}
}
}
// update child widgets
m_pageLabelEdit->setPageLabels( pageVector );
m_pageNumberEdit->setPagesNumber( pages );
m_pagesButton->setText( QString::number( pages ) );
m_prevButton->setEnabled( false );
m_nextButton->setEnabled( false );
m_pageLabelEdit->setVisible( labelsDiffer );
m_pageNumberLabel->setVisible( labelsDiffer );
m_pageNumberEdit->setVisible( !labelsDiffer );
resize( minimumSizeHint() );
setEnabled( true );
}
void MiniBar::notifyViewportChanged( bool /*smoothMove*/ )
{
// get current page number
int page = m_document->viewport().pageNumber;
int pages = m_document->pages();
// if the document is opened and page is changed
if ( page != m_currentPage && pages > 0 )
{
m_currentPage = page;
// update prev/next button state
m_prevButton->setEnabled( page > 0 );
m_nextButton->setEnabled( page < ( pages - 1 ) );
// update text on widgets
const QString pageNumber = QString::number( page + 1 );
m_pageNumberEdit->setText( pageNumber );
m_pageNumberLabel->setText( pageNumber );
m_pageLabelEdit->setText( m_document->page(page)->label() );
}
}
void MiniBar::slotChangePage()
{
// get text from the lineEdit
QString pageNumber = m_pageNumberEdit->text();
const QString pageNumber = m_pageNumberEdit->text();
// convert it to page number and go to that page
bool ok;
int number = pageNumber.toInt( &ok ) - 1;
if ( ok && number >= 0 && number < (int)m_document->pages() &&
number != m_currentPage )
if ( ok && number >= 0 && number < (int)m_miniBarLogic->document()->pages() &&
number != m_miniBarLogic->currentPage() )
{
slotChangePage( number );
}
......@@ -210,7 +256,7 @@ void MiniBar::slotChangePage()
void MiniBar::slotChangePage( int pageNumber )
{
m_document->setViewportPage( pageNumber );
m_miniBarLogic->document()->setViewportPage( pageNumber );
m_pageNumberEdit->clearFocus();
m_pageLabelEdit->clearFocus();
}
......
......@@ -11,6 +11,7 @@
#ifndef _OKULAR_MINIBAR_H_
#define _OKULAR_MINIBAR_H_
#include <qset.h>
#include <qwidget.h>
#include <klineedit.h>
#include "core/observer.h"
......@@ -72,19 +73,42 @@ class PageLabelEdit : public PagesEdit
};
/**
* @short A widget to display page number and change current page.
* @short The object that observes the document and feeds the minibars
*/
class MiniBar : public QWidget, public Okular::DocumentObserver
class MiniBarLogic : public QObject, public Okular::DocumentObserver
{
Q_OBJECT
public:
MiniBar( QWidget *parent, Okular::Document * document );
~MiniBar();
MiniBarLogic( QObject * parent, Okular::Document * m_document );
~MiniBarLogic();
void addMiniBar( MiniBar * miniBar );
void removeMiniBar( MiniBar * miniBar );
Okular::Document *document() const;
int currentPage() const;
// [INHERITED] from DocumentObserver
uint observerId() const { return MINIBAR_ID; }
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
private:
QSet<MiniBar *> m_miniBars;
Okular::Document * m_document;
int m_currentPage;
};
/**
* @short A widget to display page number and change current page.
*/
class MiniBar : public QWidget
{
Q_OBJECT
friend class MiniBarLogic;
public:
MiniBar( QWidget *parent, MiniBarLogic * miniBarLogic );
~MiniBar();
signals:
void gotoPage();
......@@ -102,14 +126,13 @@ class MiniBar : public QWidget, public Okular::DocumentObserver
void resizeForPage( int pages );
bool eventFilter( QObject *target, QEvent *event );
Okular::Document * m_document;
MiniBarLogic * m_miniBarLogic;
PageNumberEdit * m_pageNumberEdit;
PageLabelEdit * m_pageLabelEdit;
QLabel * m_pageNumberLabel;
HoverButton * m_prevButton;
HoverButton * m_pagesButton;
HoverButton * m_nextButton;
int m_currentPage;
};
/**
......
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