Commit f27f44fd authored by Pino Toscano's avatar Pino Toscano

Detach the progress widget from the minibar, and move the minibar as a small...

Detach the progress widget from the minibar, and move the minibar as a small toolbar on the bottom of the page view.
Implements KPDF wish #102788.

svn path=/trunk/playground/graphics/okular/; revision=595764
parent 0635edb9
......@@ -24,9 +24,10 @@ namespace Okular {
#define TOC_ID 5
#define MINIBAR_ID 6
#define REVIEWS_ID 7
#define PROGRESSWIDGET_ID 8
// the biggest ide, useful for ignoring wrong id request
#define MAX_OBSERVER_ID 8
#define MAX_OBSERVER_ID 9
/** PRIORITIES for requests. Globally defined here. **/
#define PAGEVIEW_PRIO 1
#define PAGEVIEW_PRELOAD_PRIO 3
......
......@@ -166,17 +166,22 @@ Part::Part(QWidget *parentWidget,
QVBoxLayout * miniBarLayout = new QVBoxLayout( miniBarContainer );
miniBarLayout->setMargin( 0 );
// widgets: [../[spacer/..]] | []
QWidget * miniSpacer = new QWidget( miniBarContainer );
miniSpacer->setFixedHeight( 6 );
miniBarLayout->addWidget( miniSpacer );
miniBarLayout->addItem( new QSpacerItem( 6, 6, QSizePolicy::Fixed, QSizePolicy::Fixed ) );
// widgets: [../[../MiniBar]] | []
m_miniBar = new MiniBar( miniBarContainer, m_document );
miniBarLayout->addWidget( m_miniBar );
QFrame * bevelContainer = new QFrame( miniBarContainer );
bevelContainer->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
QVBoxLayout * bevelContainerLayout = new QVBoxLayout( bevelContainer );
bevelContainerLayout->setMargin( 4 );
m_progressWidget = new ProgressWidget( bevelContainer, m_document );
bevelContainerLayout->addWidget( m_progressWidget );
miniBarLayout->addWidget( bevelContainer );
miniBarLayout->addItem( new QSpacerItem( 6, 6, QSizePolicy::Fixed, QSizePolicy::Fixed ) );
// widgets: [] | [right 'pageView']
QWidget * rightContainer = new QWidget( m_splitter );
QVBoxLayout * rightLayout = new QVBoxLayout( rightContainer );
rightLayout->setMargin( 0 );
rightLayout->setSpacing( 0 );
// KToolBar * rtb = new KToolBar( rightContainer, "mainToolBarSS" );
// rightLayout->addWidget( rtb );
m_topMessage = new PageViewTopMessage( rightContainer );
......@@ -190,6 +195,15 @@ Part::Part(QWidget *parentWidget,
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 );
QWidget * bottomBar = new QWidget( rightContainer );
QHBoxLayout * bottomBarLayout = new QHBoxLayout( bottomBar );
bottomBarLayout->setMargin( 0 );
bottomBarLayout->setSpacing( 0 );
bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
m_miniBar = new MiniBar( bottomBar, m_document );
bottomBarLayout->addWidget( m_miniBar );
bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
rightLayout->addWidget( bottomBar );
// add document observers
m_document->addObserver( this );
......@@ -197,6 +211,7 @@ Part::Part(QWidget *parentWidget,
m_document->addObserver( m_pageView );
m_document->addObserver( m_toc );
m_document->addObserver( m_miniBar );
m_document->addObserver( m_progressWidget );
m_document->addObserver( reviewsWidget );
// ACTIONS
......@@ -213,12 +228,14 @@ Part::Part(QWidget *parentWidget,
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_progressWidget, SIGNAL( prevPage() ), m_prevPage, SLOT( trigger() ) );
m_nextPage = KStdAction::next(this, SLOT(slotNextPage()), ac, "next_page" );
m_nextPage->setWhatsThis( i18n( "Moves to the next page of the document" ) );
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_progressWidget, SIGNAL( nextPage() ), m_nextPage, SLOT( trigger() ) );
m_firstPage = KStdAction::firstPage( this, SLOT( slotGotoFirst() ), ac, "first_page" );
m_firstPage->setWhatsThis( i18n( "Moves to the first page of the document" ) );
......@@ -345,6 +362,7 @@ Part::~Part()
delete m_pageView;
delete m_thumbnailList;
delete m_miniBar;
delete m_progressWidget;
delete m_document;
}
......
......@@ -45,6 +45,7 @@ class ThumbnailController;
class PageView;
class PageViewTopMessage;
class PresentationWidget;
class ProgressWidget;
class SearchWidget;
class TOC;
class MiniBar;
......@@ -163,6 +164,7 @@ private:
QPointer<TOC> m_toc;
QPointer<MiniBar> m_miniBar;
QPointer<PresentationWidget> m_presentationWidget;
QPointer<ProgressWidget> m_progressWidget;
// document watcher (and reloader) variables
KDirWatch *m_watcher;
......
......@@ -27,24 +27,6 @@
#include "core/document.h"
#include "minibar.h"
// [private widget] show progress
class ProgressWidget : public QWidget
{
public:
ProgressWidget( MiniBar * parent );
void setProgress( float percentage );
protected:
void mouseMoveEvent( QMouseEvent * e );
void mousePressEvent( QMouseEvent * e );
void wheelEvent( QWheelEvent * e );
void paintEvent( QPaintEvent * e );
private:
MiniBar * m_miniBar;
float m_progressPercentage;
};
// [private widget] lineEdit for entering/validating page numbers
class PagesEdit : public QLineEdit
{
......@@ -88,53 +70,51 @@ MiniBar::MiniBar( QWidget * parent, Okular::Document * document )
setObjectName( "miniBar" );
// left spacer
QHBoxLayout * horLayout = new QHBoxLayout( this );
horLayout->setMargin( 2 );
QSpacerItem * spacerL = new QSpacerItem( 20, 10, QSizePolicy::Expanding );
horLayout->addItem( spacerL );
// central 2r by 5c grid layout that contains all components
QGridLayout * gridLayout = new QGridLayout();
gridLayout->setMargin( 2 );
gridLayout->setSpacing( 1 );
// top spacer 6x6 px
// QSpacerItem * spacerTop = new QSpacerItem( 6, 6, QSizePolicy::Fixed, QSizePolicy::Fixed );
// gridLayout->addMultiCell( spacerTop, 0, 0, 0, 4 );
// center progress widget
m_progressWidget = new ProgressWidget( this );
gridLayout->addWidget( m_progressWidget, 0, 0, 1, 5 );
horLayout->setMargin( 0 );
horLayout->setSpacing( 0 );
// bottom: left prev_page button
m_prevButton = new HoverButton( this );
m_prevButton->setIcon( KIcon( layoutDirection() == Qt::RightToLeft ? "1rightarrow" : "1leftarrow" ) );
gridLayout->addWidget( m_prevButton, 1, 0 );
horLayout->addWidget( m_prevButton );
// bottom: left lineEdit (current page box)
m_pagesEdit = new PagesEdit( this );
gridLayout->addWidget( m_pagesEdit, 1, 1 );
horLayout->addWidget( m_pagesEdit );
// bottom: central '/' label
gridLayout->addWidget( new QLabel( "/", this ), 1, 2 );
horLayout->addWidget( new QLabel( "/", this ) );
// bottom: right button
m_pagesButton = new HoverButton( this );
gridLayout->addWidget( m_pagesButton, 1, 3 );
horLayout->addWidget( m_pagesButton );
// bottom: right next_page button
m_nextButton = new HoverButton( this );
m_nextButton->setIcon( KIcon( layoutDirection() == Qt::RightToLeft ? "1leftarrow" : "1rightarrow" ) );
gridLayout->addWidget( m_nextButton, 1, 4 );
horLayout->addLayout( gridLayout );
// right spacer
QSpacerItem * spacerR = new QSpacerItem( 20, 10, QSizePolicy::Expanding );
horLayout->addItem( spacerR );
horLayout->addWidget( m_nextButton );
// customize own look
setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
QSizePolicy sp = sizePolicy();
sp.setHorizontalPolicy( QSizePolicy::Fixed );
sp.setVerticalPolicy( QSizePolicy::Fixed );
setSizePolicy( sp );
// resize height of widgets
int fixedHeight = fontMetrics().height();
m_pagesEdit->setFixedHeight( fixedHeight );
m_pagesButton->setFixedHeight( fixedHeight );
m_prevButton->setFixedHeight( fixedHeight );
m_nextButton->setFixedHeight( fixedHeight );
// connect signals from child widgets to internal handlers / signals bouncers
connect( m_pagesEdit, SIGNAL( returnPressed() ), this, SLOT( slotChangePage() ) );
connect( m_pagesButton, SIGNAL( clicked() ), this, SIGNAL( gotoPage() ) );
connect( m_prevButton, SIGNAL( clicked() ), this, SIGNAL( prevPage() ) );
connect( m_nextButton, SIGNAL( clicked() ), this, SIGNAL( nextPage() ) );
// widget starts hidden (will be shown after opening a document)
parent->hide();
resize( minimumSizeHint() );
// widget starts disabled (will be enabled after opening a document)
setEnabled( false );
}
MiniBar::~MiniBar()
......@@ -153,7 +133,7 @@ void MiniBar::notifySetup( const QVector< Okular::Page * > & pageVector, bool ch
if ( pages < 1 )
{
m_currentPage = -1;
parentWidget()->hide();
setEnabled( false );
return;
}
......@@ -164,21 +144,15 @@ void MiniBar::notifySetup( const QVector< Okular::Page * > & pageVector, bool ch
m_pagesButton->setMinimumWidth( numberWidth );
m_pagesButton->setMaximumWidth( 2 * numberWidth );
// resize height of widgets
int fixedHeight = fontMetrics().height() + 4;
if ( fixedHeight < 20 )
fixedHeight = 20;
m_pagesEdit->setFixedHeight( fixedHeight );
m_pagesButton->setFixedHeight( fixedHeight );
m_prevButton->setFixedHeight( fixedHeight );
m_nextButton->setFixedHeight( fixedHeight );
// update child widgets
m_pagesEdit->setPagesNumber( pages );
m_pagesButton->setText( QString::number( pages ) );
m_prevButton->setEnabled( false );
m_nextButton->setEnabled( false );
parentWidget()->show();
resize( minimumSizeHint() );
setEnabled( true );
}
void MiniBar::notifyViewportChanged( bool /*smoothMove*/ )
......@@ -190,10 +164,7 @@ void MiniBar::notifyViewportChanged( bool /*smoothMove*/ )
// if the document is opened and page is changed
if ( page != m_currentPage && pages > 0 )
{
// update percentage
m_currentPage = page;
float percentage = pages < 2 ? 1.0 : (float)page / (float)(pages - 1);
m_progressWidget->setProgress( percentage );
// update prev/next button state
m_prevButton->setEnabled( page > 0 );
m_nextButton->setEnabled( page < ( pages - 1 ) );
......@@ -202,29 +173,6 @@ void MiniBar::notifyViewportChanged( bool /*smoothMove*/ )
}
}
void MiniBar::resizeEvent( QResizeEvent * e )
{
// auto-hide 'prev' and 'next' buttons if not enough space
const QSize & myHint = minimumSizeHint();
bool shown = m_prevButton->isVisible() && m_nextButton->isVisible();
if ( shown && e->size().width() < myHint.width() )
{
m_prevButton->hide();
m_nextButton->hide();
updateGeometry();
}
else if ( !shown )
{
int histeresis = m_prevButton->sizeHint().width() * 2 + 2;
if ( e->size().width() > (myHint.width() + histeresis) )
{
m_prevButton->show();
m_nextButton->show();
updateGeometry();
}
}
}
void MiniBar::slotChangePage()
{
// get text from the lineEdit
......@@ -241,15 +189,6 @@ void MiniBar::slotChangePage()
}
}
void MiniBar::slotGotoNormalizedPage( float index )
{
// figure out page number and go to that page
int number = (int)( index * (float)m_document->pages() );
if ( number >= 0 && number < (int)m_document->pages() &&
number != m_currentPage )
m_document->setViewportPage( number );
}
void MiniBar::slotEmitNextPage()
{
// emit signal
......@@ -266,9 +205,9 @@ void MiniBar::slotEmitPrevPage()
/** ProgressWidget **/
ProgressWidget::ProgressWidget( MiniBar * parent )
: QWidget( parent ),
m_miniBar( parent ), m_progressPercentage( -1 )
ProgressWidget::ProgressWidget( QWidget * parent, Okular::Document * document )
: QWidget( parent ), m_document( document ),
m_currentPage( -1 ), m_progressPercentage( -1 )
{
setObjectName( "progress" );
setAttribute( Qt::WA_OpaquePaintEvent, true );
......@@ -276,30 +215,60 @@ ProgressWidget::ProgressWidget( MiniBar * parent )
setMouseTracking( true );
}
ProgressWidget::~ProgressWidget()
{
m_document->removeObserver( this );
}
void ProgressWidget::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 )
{
// update percentage
m_currentPage = page;
float percentage = pages < 2 ? 1.0 : (float)page / (float)(pages - 1);
setProgress( percentage );
}
}
void ProgressWidget::setProgress( float percentage )
{
m_progressPercentage = percentage;
update();
}
void ProgressWidget::slotGotoNormalizedPage( float index )
{
// figure out page number and go to that page
int number = (int)( index * (float)m_document->pages() );
if ( number >= 0 && number < (int)m_document->pages() &&
number != m_currentPage )
m_document->setViewportPage( number );
}
void ProgressWidget::mouseMoveEvent( QMouseEvent * e )
{
if ( ( QApplication::mouseButtons() & Qt::LeftButton ) && width() > 0 )
m_miniBar->slotGotoNormalizedPage( (float)( QApplication::isRightToLeft() ? width() - e->x() : e->x() ) / (float)width() );
slotGotoNormalizedPage( (float)( QApplication::isRightToLeft() ? width() - e->x() : e->x() ) / (float)width() );
}
void ProgressWidget::mousePressEvent( QMouseEvent * e )
{
if ( e->button() == Qt::LeftButton && width() > 0 )
m_miniBar->slotGotoNormalizedPage( (float)( QApplication::isRightToLeft() ? width() - e->x() : e->x() ) / (float)width() );
slotGotoNormalizedPage( (float)( QApplication::isRightToLeft() ? width() - e->x() : e->x() ) / (float)width() );
}
void ProgressWidget::wheelEvent( QWheelEvent * e )
{
if ( e->delta() > 0 )
m_miniBar->slotEmitNextPage();
emit nextPage();
else
m_miniBar->slotEmitPrevPage();
emit prevPage();
}
void ProgressWidget::paintEvent( QPaintEvent * e )
......
......@@ -20,7 +20,6 @@ class Document;
class PagesEdit;
class HoverButton;
class ProgressWidget;
/**
* @short A widget to display page number and change current page.
......@@ -44,21 +43,50 @@ class MiniBar : public QFrame, public Okular::DocumentObserver
public slots:
void slotChangePage();
void slotGotoNormalizedPage( float normIndex );
void slotEmitNextPage();
void slotEmitPrevPage();
protected:
void resizeEvent( QResizeEvent * );
private:
Okular::Document * m_document;
PagesEdit * m_pagesEdit;
HoverButton * m_prevButton;
HoverButton * m_pagesButton;
HoverButton * m_nextButton;
ProgressWidget * m_progressWidget;
int m_currentPage;
};
/**
* @short A small progress bar.
*/
class ProgressWidget : public QWidget, public Okular::DocumentObserver
{
Q_OBJECT
public:
ProgressWidget( QWidget * parent, Okular::Document * document );
~ProgressWidget();
// [INHERITED] from DocumentObserver
uint observerId() const { return PROGRESSWIDGET_ID; }
void notifyViewportChanged( bool smoothMove );
void slotGotoNormalizedPage( float index );
signals:
void prevPage();
void nextPage();
protected:
void setProgress( float percentage );
void mouseMoveEvent( QMouseEvent * e );
void mousePressEvent( QMouseEvent * e );
void wheelEvent( QWheelEvent * e );
void paintEvent( QPaintEvent * e );
private:
Okular::Document * m_document;
int m_currentPage;
float m_progressPercentage;
};
#endif
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