Commit 0ff129b6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

WheelMouse works as in kghostview

svn path=/trunk/kdegraphics/kpdf/; revision=251103
parent 5e89aedf
......@@ -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
......@@ -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:
......
......@@ -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()
{
......
......@@ -98,6 +98,8 @@ namespace KPDF
void showScrollBars( bool );
void showMarkList( bool );
void slotReadUp();
void slotReadDown();
private:
PDFDoc* m_doc;
......
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