Allow the user to change the visible part(s) of the document by dragging the visible areas in the thumbnails, and to change the zoom of the document by Ctrl+wheel on them.

Patch by Diego R. Brogna, thanks a lot!

BUG: 135521

svn path=/trunk/KDE/kdegraphics/okular/; revision=685273
This commit is contained in:
Pino Toscano 2007-07-08 14:25:08 +00:00
parent 75251b74d5
commit 8a31e6f3f0
8 changed files with 153 additions and 2 deletions

View file

@ -1654,6 +1654,15 @@ void Document::setViewport( const DocumentViewport & viewport, int excludeId, bo
}
}
void Document::setZoom(int factor, int excludeId)
{
// notify change to all other (different from id) observers
QMap< int, DocumentObserver * >::const_iterator it = d->m_observers.begin(), end = d->m_observers.end();
for ( ; it != end ; ++ it )
if ( it.key() != excludeId )
(*it)->notifyZoom( factor );
}
void Document::setPrevViewport()
// restore viewport from the history
{

View file

@ -317,6 +317,13 @@ class OKULAR_EXPORT Document : public QObject
*/
void setNextDocumentViewport( const DocumentViewport &viewport );
/**
* Sets the zoom for the current document.
*
* @param excludeId The observer ids which shouldn't be effected by this change.
*/
void setZoom( int factor, int excludeId = -1 );
/**
* Sends @p requests for pixmap generation.
*/

View file

@ -40,6 +40,10 @@ void DocumentObserver::notifyVisibleRectsChanged()
{
}
void DocumentObserver::notifyZoom( int )
{
}
bool DocumentObserver::canUnloadPixmap( int ) const
{
return true;

View file

@ -106,6 +106,11 @@ class OKULAR_EXPORT DocumentObserver
*/
virtual void notifyVisibleRectsChanged();
/**
* This method is called whenever the zoom of the document has been changed.
*/
virtual void notifyZoom( int factor );
/**
* Returns whether the observer agrees that all pixmaps for the given
* @p page can be unloaded to improve memory usage.

View file

@ -813,6 +813,14 @@ void PageView::notifyContentsCleared( int changedFlags )
QMetaObject::invokeMethod(this, "slotRequestVisiblePixmaps", Qt::QueuedConnection);
}
void PageView::notifyZoom( int factor )
{
if ( factor > 0 )
updateZoom( ZoomIn );
else
updateZoom( ZoomOut );
}
bool PageView::canUnloadPixmap( int pageNumber ) const
{
if ( Okular::Settings::memoryLevel() != Okular::Settings::EnumMemoryLevel::Aggressive )

View file

@ -73,6 +73,7 @@ Q_OBJECT
void notifyViewportChanged( bool smoothMove );
void notifyPageChanged( int pageNumber, int changedFlags );
void notifyContentsCleared( int changedFlags );
void notifyZoom(int factor);
bool canUnloadPixmap( int pageNum ) const;
QList< Okular::RegularAreaRect * > textSelections( const QPoint& start, const QPoint& end, int& firstpage );

View file

@ -53,7 +53,10 @@ class ThumbnailWidget : public QWidget
QSize sizeHint() const;
protected:
void mousePressEvent( QMouseEvent * e );
void mouseReleaseEvent( QMouseEvent * e );
void mouseMoveEvent( QMouseEvent * e );
void wheelEvent( QWheelEvent * e );
void contextMenuEvent( QContextMenuEvent * e );
void paintEvent(QPaintEvent *);
@ -69,6 +72,7 @@ class ThumbnailWidget : public QWidget
int m_pixmapWidth, m_pixmapHeight;
int m_labelHeight, m_labelNumber;
Okular::NormalizedRect m_visibleRect;
QPoint mouseGrabPos;
};
@ -302,6 +306,42 @@ void ThumbnailList::forwardClick( const Okular::Page * p, const QPoint & t, Qt::
}
}
void ThumbnailList::forwardTrack( const Okular::Page * p, const QPoint &d, const QPoint &s )
{
Okular::DocumentViewport vp=m_document->viewport();
QVector< Okular::VisiblePageRect * > vVpr = m_document->visiblePageRects();
QVector< Okular::VisiblePageRect * >::const_iterator vIt = vVpr.begin();
QVector< Okular::VisiblePageRect * >::const_iterator vEnd = vVpr.end();
for ( ; vIt != vEnd; ++vIt )
{
Okular::VisiblePageRect *vpr = ( *vIt );
if( vpr->pageNumber == p->number() )
{
double w = vpr->rect.right - vpr->rect.left,
h = vpr->rect.bottom - vpr->rect.top,
deltaX = d.x()*w/s.x(),
deltaY = d.y()*h/s.y();
vp.rePos.normalizedX -= deltaX;
vp.rePos.normalizedY -= deltaY;
if( !vp.rePos.enabled )
{
vp.rePos.enabled = true;
vp.rePos.normalizedY += h/2;
}
m_document->setViewport( vp );
}
}
}
void ThumbnailList::forwardZoom( const Okular::Page *, int i )
{
m_document->setZoom( i );
}
const QPixmap * ThumbnailList::getBookmarkOverlay() const
{
return m_bookmarkOverlay;
@ -500,6 +540,10 @@ ThumbnailWidget::ThumbnailWidget( QWidget * parent, const Okular::Document * doc
{
m_labelNumber = m_page->number() + 1;
m_labelHeight = QFontMetrics( font() ).height();
setMouseTracking(true);
mouseGrabPos.setX(0);
mouseGrabPos.setY(0);
}
void ThumbnailWidget::resizeFitWidth( int width )
@ -533,10 +577,78 @@ QSize ThumbnailWidget::sizeHint() const
return QSize( width(), heightHint() );
}
void ThumbnailWidget::mousePressEvent( QMouseEvent * e )
{
QRect r = m_visibleRect.geometry( m_pixmapWidth, m_pixmapHeight );
if ( r.contains( e->pos() ) )
{
mouseGrabPos = e->pos();
}
else
{
mouseGrabPos.setX( 0 );
mouseGrabPos.setY( 0 );
}
}
void ThumbnailWidget::mouseReleaseEvent( QMouseEvent * e )
{
// don't handle the mouse click, forward it to the thumbnail list
m_tl->forwardClick( m_page, e->globalPos(), e->button() );
QRect r = m_visibleRect.geometry( m_pixmapWidth, m_pixmapHeight );
if ( r.contains( e->pos() ) )
{
setCursor( Qt::OpenHandCursor );
}
else
{
setCursor( Qt::ArrowCursor );
if ( mouseGrabPos.isNull() )
{
// don't handle the mouse click, forward it to the thumbnail list
m_tl->forwardClick( m_page, e->globalPos(), e->button() );
}
}
mouseGrabPos.setX( 0 );
mouseGrabPos.setY( 0 );
}
void ThumbnailWidget::mouseMoveEvent( QMouseEvent * e )
{
QRect r = m_visibleRect.geometry( m_pixmapWidth, m_pixmapHeight );
if ( r.contains( e->pos()-QPoint( m_margin / 2, m_margin / 2 ) ) )
{
if (!mouseGrabPos.isNull())
{
setCursor( Qt::ClosedHandCursor );
QPoint mousePos = e->pos();
QPoint delta = mouseGrabPos - mousePos;
// don't handle the mouse move, forward it to the thumbnail list
m_tl->forwardTrack( m_page, delta, QPoint( r.width(), r.height() ) );
mouseGrabPos = e->pos();
}
else
{
setCursor( Qt::OpenHandCursor );
}
}
else
{
setCursor( Qt::ArrowCursor );
}
}
void ThumbnailWidget::wheelEvent( QWheelEvent * e )
{
QRect r = m_visibleRect.geometry( m_pixmapWidth, m_pixmapHeight );
if ( r.contains( e->pos() - QPoint( m_margin / 2, m_margin / 2 ) ) && e->orientation() == Qt::Vertical && e->modifiers() == Qt::ControlModifier )
{
m_tl->forwardZoom( m_page, e->delta() );
}
else
{
e->ignore();
}
}
void ThumbnailWidget::contextMenuEvent( QContextMenuEvent * e )

View file

@ -15,6 +15,7 @@
#include <kvbox.h>
#include <qtoolbar.h>
#include "core/area.h"
#include "core/observer.h"
class QTimer;
@ -57,6 +58,10 @@ Q_OBJECT
// called by ThumbnailWidgets to send (forward) the mouse click signals
void forwardClick( const Okular::Page *, const QPoint &, Qt::MouseButton );
// called by ThumbnailWidgets to send (forward) the mouse move signals
void forwardTrack( const Okular::Page *, const QPoint &, const QPoint & );
// called by ThumbnailWidgets to send (forward) the mouse zoom signals
void forwardZoom( const Okular::Page *, int );
// called by ThumbnailWidgets to get the overlay bookmark pixmap
const QPixmap * getBookmarkOverlay() const;