diff --git a/kpdf/kpdf_pagewidget.cc b/kpdf/kpdf_pagewidget.cc index a77623faf..251c448ad 100644 --- a/kpdf/kpdf_pagewidget.cc +++ b/kpdf/kpdf_pagewidget.cc @@ -181,6 +181,40 @@ namespace KPDF } e->accept(); } + + bool PageWidget::atTop() const + { + return verticalScrollBar()->value() == verticalScrollBar()->minValue(); + } + + bool PageWidget::atBottom() const + { + return verticalScrollBar()->value() == verticalScrollBar()->maxValue(); + } + + void PageWidget::wheelEvent( QWheelEvent *e ) + { + int delta = e->delta(); + e->accept(); + if ((e->state() & ShiftButton) == ShiftButton) { + if ( e->delta() > 0 ) + emit ZoomOut(); + else + emit ZoomIn(); + } + else if ( delta <= -120 && atBottom() ) + { + emit ReadDown(); + } + else if ( delta >= 120 && atTop()) + { + emit ReadUp(); + } + + else + QScrollView::wheelEvent( e ); + } + void PageWidget::updatePixmap() { if ( m_doc ) @@ -200,6 +234,50 @@ namespace KPDF viewport()->update(); } } + + bool PageWidget::readUp() + { + if( atTop() ) + return false; + else { + int newValue = QMAX( verticalScrollBar()->value() - height() + 50, + verticalScrollBar()->minValue() ); + + /* + int step = 10; + int value = verticalScrollBar()->value(); + while( value > newValue - step ) { + verticalScrollBar()->setValue( value ); + value -= step; + } + */ + + verticalScrollBar()->setValue( newValue ); + return true; + } + } + + bool PageWidget::readDown() + { + if( atBottom() ) + return false; + else { + int newValue = QMIN( verticalScrollBar()->value() + height() - 50, + verticalScrollBar()->maxValue() ); + + /* + int step = 10; + int value = verticalScrollBar()->value(); + while( value < newValue + step ) { + verticalScrollBar()->setValue( value ); + value += step; + } + */ + + verticalScrollBar()->setValue( newValue ); + return true; + } + } } // vim:ts=2:sw=2:tw=78:et diff --git a/kpdf/kpdf_pagewidget.h b/kpdf/kpdf_pagewidget.h index 40f8175b1..c262c16f2 100644 --- a/kpdf/kpdf_pagewidget.h +++ b/kpdf/kpdf_pagewidget.h @@ -31,6 +31,11 @@ namespace KPDF void setPage(int pagenum); int getPage() const { return m_currentPage; }; void enableScrollBars( bool b ); + /** + * Return true if the top resp. bottom of the page is visible. + */ + bool atTop() const; + bool atBottom() const; public slots: void nextPage(); void previousPage(); @@ -44,15 +49,20 @@ namespace KPDF void scrollLeft(); void scrollBottom(); void scrollTop(); + bool readUp(); + bool readDown(); signals: void linkClicked(LinkAction*); - + void ReadUp(); + void ReadDown(); + void ZoomOut(); + void ZoomIn(); protected: virtual void keyPressEvent( QKeyEvent* ); void contentsMousePressEvent(QMouseEvent*); void contentsMouseReleaseEvent(QMouseEvent*); void contentsMouseMoveEvent(QMouseEvent*); - + virtual void wheelEvent( QWheelEvent * ); virtual void drawContents ( QPainter *p, int, int, int, int ); private: diff --git a/kpdf/kpdf_part.cpp b/kpdf/kpdf_part.cpp index 3907b186d..106960ae3 100644 --- a/kpdf/kpdf_part.cpp +++ b/kpdf/kpdf_part.cpp @@ -105,6 +105,10 @@ Part::Part(QWidget *parentWidget, const char *widgetName, // set our XML-UI resource file setXMLFile("kpdf_part.rc"); + connect( m_outputDev, SIGNAL( ZoomIn() ), SLOT( slotZoomIn() )); + connect( m_outputDev, SIGNAL( ZoomOut() ), SLOT( slotZoomOut() )); + connect( m_outputDev, SIGNAL( ReadUp() ), SLOT( slotReadUp() )); + connect( m_outputDev, SIGNAL( ReadDown() ), SLOT( slotReadDown() )); readSettings(); } @@ -114,7 +118,28 @@ Part::~Part() writeSettings(); } +void Part::slotReadUp() +{ + if( !m_doc ) + return; + + if( !m_outputDev->readUp() ) { + slotPreviousPage(); + m_outputDev->scrollBottom(); + } +} +void Part::slotReadDown() +{ + if( !m_doc ) + return; + + if( !m_outputDev->readDown() ) { + //todo fix if we can "next page" as in kghostview + slotNextPage(); + m_outputDev->scrollTop(); + } +} void Part::writeSettings() { diff --git a/kpdf/kpdf_part.h b/kpdf/kpdf_part.h index e4335ce11..11e37eafc 100644 --- a/kpdf/kpdf_part.h +++ b/kpdf/kpdf_part.h @@ -98,6 +98,8 @@ namespace KPDF void showScrollBars( bool ); void showMarkList( bool ); + void slotReadUp(); + void slotReadDown(); private: PDFDoc* m_doc;