[Okular-devel] [Bug 135521] Allow moving the view using the red square of the thumbnail view
Pino Toscano
toscano.pino at tiscali.it
Sun Jul 8 16:25:15 CEST 2007
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
http://bugs.kde.org/show_bug.cgi?id=135521
toscano.pino tiscali it changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
------- Additional Comments From toscano.pino tiscali it 2007-07-08 16:25 -------
SVN commit 685273 by pino:
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
M +9 -0 core/document.cpp
M +7 -0 core/document.h
M +4 -0 core/observer.cpp
M +5 -0 core/observer.h
M +8 -0 ui/pageview.cpp
M +1 -0 ui/pageview.h
M +114 -2 ui/thumbnaillist.cpp
M +5 -0 ui/thumbnaillist.h
--- trunk/KDE/kdegraphics/okular/core/document.cpp #685272:685273
@ -1654,6 +1654,15 @
}
}
+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
{
--- trunk/KDE/kdegraphics/okular/core/document.h #685272:685273
@ -318,6 +318,13 @
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.
*/
void requestPixmaps( const QLinkedList<PixmapRequest*> &requests );
--- trunk/KDE/kdegraphics/okular/core/observer.cpp #685272:685273
@ -40,6 +40,10 @
{
}
+void DocumentObserver::notifyZoom( int )
+{
+}
+
bool DocumentObserver::canUnloadPixmap( int ) const
{
return true;
--- trunk/KDE/kdegraphics/okular/core/observer.h #685272:685273
@ -107,6 +107,11 @
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.
*
--- trunk/KDE/kdegraphics/okular/ui/pageview.cpp #685272:685273
@ -813,6 +813,14 @
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 )
--- trunk/KDE/kdegraphics/okular/ui/pageview.h #685272:685273
@ -73,6 +73,7 @
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 );
--- trunk/KDE/kdegraphics/okular/ui/thumbnaillist.cpp #685272:685273
@ -53,7 +53,10 @
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 @
int m_pixmapWidth, m_pixmapHeight;
int m_labelHeight, m_labelNumber;
Okular::NormalizedRect m_visibleRect;
+ QPoint mouseGrabPos;
};
@ -302,6 +306,42 @
}
}
+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 @
{
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,12 +577,80 @
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 )
{
// don't handle the mouse click, forward it to the thumbnail list
--- trunk/KDE/kdegraphics/okular/ui/thumbnaillist.h #685272:685273
@ -15,6 +15,7 @
#include <kvbox.h>
#include <qtoolbar.h>
+#include "core/area.h"
#include "core/observer.h"
class QTimer;
@ -57,6 +58,10 @
// 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;
More information about the Okular-devel
mailing list