Commit cd81b54d authored by Pino Toscano's avatar Pino Toscano

Show the current viewport in the thumbnail view, with a read contour.

svn path=/trunk/playground/graphics/okular/; revision=554363
parent a3dc3b26
......@@ -8,6 +8,8 @@ Legend:
In progress [working on]:
-> toc: higlight the row of the current page (BR127358)
(check if there's a better way to do the highlighting - in case just edit TOCItem::setSelected())
-> thumbnailslist: show Viewport in(blended/contour)
(actually it's only a red contour)
-> annotations: renderers in PagePainter (for the 6 annots)
-> annotations: handlers in PageView for WindowAnnots and others..
-> annotations: creators in PageViewAnnotator (40% done)
......@@ -44,7 +46,6 @@ More items (first items will enter 'In progress list' first):
-> core: add a way to handle "named xpdf links" in KPDFLink instead of resolving all
dests when displaying a page (speedups a lot generation of page with many links)
-> toolbar: move the toolbar to the top of pageview (left panel is really at the left of the toolbar)
-> thumbnailslist: show Viewport in(blended/contour)
-> thumbnailslist: refactor to do internal rendering as pageview does (way faster
than using QScrollView + inserted Widgets and saves 8% on document loading)
-> thumbnailslist: clinking on higlighted rect should bring the viewport to that search result (BR98334)
......
......@@ -35,6 +35,9 @@ NormalizedRect::NormalizedRect( const QRect & r, double xScale, double yScale )
: left( (double)r.left() / xScale ), top( (double)r.top() / yScale ),
right( (double)r.right() / xScale ), bottom( (double)r.bottom() / yScale ) {}
NormalizedRect::NormalizedRect( const NormalizedRect & rect )
: left( rect.left ), top( rect.top ), right( rect.right ), bottom( rect.bottom ) {}
bool NormalizedRect::isNull() const
{
return left == 0 && top== 0 && right == 0 && bottom == 0;
......@@ -75,6 +78,16 @@ NormalizedRect& NormalizedRect::operator|= (const NormalizedRect & r)
{
return ((*this) = (*this) | r );
}
NormalizedRect & NormalizedRect::operator=( const NormalizedRect & r )
{
left = r.left;
right = r.right;
top = r.top;
bottom = r.bottom;
return *this;
}
/*
kdbgstream& operator << (kdbgstream& str , const NormalizedRect &r)
{
......
......@@ -42,6 +42,7 @@ class OKULAR_EXPORT NormalizedRect
NormalizedRect();
NormalizedRect( double l, double t, double r, double b );
NormalizedRect( const QRect &r, double xScale, double yScale );
NormalizedRect( const NormalizedRect & rect );
bool isNull() const;
bool contains( double x, double y ) const;
bool intersects( const NormalizedRect & normRect ) const;
......@@ -50,6 +51,7 @@ class OKULAR_EXPORT NormalizedRect
QRect geometry( int xScale, int yScale ) const;
NormalizedRect operator| (const NormalizedRect & r) const;
NormalizedRect& operator|= (const NormalizedRect & r);
NormalizedRect& operator=( const NormalizedRect & r );
};
// kdbgstream& operator << (kdbgstream &, const NormalizedRect &);
......
......@@ -395,6 +395,11 @@ void KPDFDocument::notifyObservers (NotifyRequest * request)
case DocumentObserver::Contents:
foreachObserver( notifyContentsCleared( request->flags ) );
break;
case DocumentObserver::VisibleAreas:
qDeleteAll(page_rects);
page_rects = request->rects;
foreachObserver( notifyVisibleRectsChanged() );
break;
}
}
......@@ -503,6 +508,25 @@ const DocumentViewport & KPDFDocument::viewport() const
return (*d->viewportIterator);
}
const QVector< VisiblePageRect * > & KPDFDocument::visiblePageRects() const
{
return page_rects;
}
void KPDFDocument::setVisiblePageRects( const QVector< VisiblePageRect * > & visiblePageRects, int excludeId )
{
QVector< VisiblePageRect * >::iterator vIt = page_rects.begin();
QVector< VisiblePageRect * >::iterator vEnd = page_rects.end();
for ( ; vIt != vEnd; ++vIt )
delete *vIt;
page_rects = visiblePageRects;
// notify change to all other (different from id) observers
QMap< int, DocumentObserver * >::iterator it = d->observers.begin(), end = d->observers.end();
for ( ; it != end ; ++ it )
if ( it.key() != excludeId )
(*it)->notifyVisibleRectsChanged();
}
uint KPDFDocument::currentPage() const
{
return (*d->viewportIterator).pageNumber;
......
......@@ -21,6 +21,8 @@
#include <qhash.h>
#include <kmimetype.h>
#include "area.h"
class KPDFPage;
class KPDFLink;
class DocumentObserver;
......@@ -37,6 +39,7 @@ class KUrl;
class KActionCollection;
class QToolBox;
class NotifyRequest;
class VisiblePageRect;
/** IDs for seaches. Globally defined here. **/
#define PART_SEARCH_ID 1
......@@ -91,6 +94,8 @@ class OKULAR_EXPORT KPDFDocument : public QObject
const QList<EmbeddedFile*> *embeddedFiles() const;
const KPDFPage * page( int page ) const;
const DocumentViewport & viewport() const;
const QVector< VisiblePageRect * > & visiblePageRects() const;
void setVisiblePageRects( const QVector< VisiblePageRect * > & visiblePageRects, int excludeId = -1 );
uint currentPage() const;
uint pages() const;
KUrl currentDocument() const;
......@@ -163,6 +168,7 @@ class OKULAR_EXPORT KPDFDocument : public QObject
Generator * generator;
bool m_usingCachedGenerator;
QVector< KPDFPage * > pages_vector;
QVector< VisiblePageRect * > page_rects;
class KPDFDocumentPrivate * d;
private slots:
......@@ -290,4 +296,17 @@ class OKULAR_EXPORT EmbeddedFile
};
/**
* @short An area of a specified page
*/
class VisiblePageRect
{
public:
VisiblePageRect( int _pageNumber = -1, const NormalizedRect & r = NormalizedRect() )
: pageNumber( _pageNumber ), rect( r ) {};
int pageNumber;
NormalizedRect rect;
};
#endif
......@@ -33,6 +33,7 @@
#define PRESENTATION_PRIO 0
class KPDFPage;
class VisiblePageRect;
/**
* @short Base class for objects being notified when something changes.
......@@ -50,11 +51,12 @@ class DocumentObserver
// commands from the Document to all observers
enum ChangedFlags { Pixmap = 1, Bookmark = 2, Highlights = 4, Annotations = 8 };
enum NotifyType { Setup = 1, Viewport = 2, Page = 4, Contents = 8 };
enum NotifyType { Setup = 1, Viewport = 2, Page = 4, Contents = 8, VisibleAreas = 16 };
virtual void notifySetup( const QVector< KPDFPage * > & /*pages*/, bool /*documentChanged*/ ) {};
virtual void notifyViewportChanged( bool /*smoothMove*/ ) {};
virtual void notifyPageChanged( int /*pageNumber*/, int /*changedFlags*/ ) {};
virtual void notifyContentsCleared( int /*changedFlags*/ ) {};
virtual void notifyVisibleRectsChanged() {};
// queries to observers
virtual bool canUnloadPixmap( int /*pageNum*/ ) { return true; }
......@@ -66,6 +68,7 @@ struct NotifyRequest
bool toggle;
int page;
int flags;
QVector<VisiblePageRect*> rects;
NotifyRequest (DocumentObserver::NotifyType t, bool to=false)
: type(t), toggle(to), page(-1), flags(0) { ; };
NotifyRequest (DocumentObserver::NotifyType t, int p, int f)
......
......@@ -2235,6 +2235,7 @@ void PageView::slotRequestVisiblePixmaps( int newLeft, int newTop )
// iterate over all items
d->visibleItems.clear();
QLinkedList< PixmapRequest * > requestedPixmaps;
QVector< VisiblePageRect * > visibleRects;
QVector< PageViewItem * >::iterator iIt = d->items.begin(), iEnd = d->items.end();
for ( ; iIt != iEnd; ++iIt )
{
......@@ -2244,11 +2245,14 @@ void PageView::slotRequestVisiblePixmaps( int newLeft, int newTop )
kWarning() << "viewportRect is " << viewportRect << ", page item is " << i->geometry() << " intersect : " << viewportRect.intersects( i->geometry() ) << endl;
#endif
// if the item doesn't intersect the viewport, skip it
if ( !viewportRect.intersects( i->geometry() ) )
QRect intersectionRect = viewportRect.intersect( i->geometry() );
if ( intersectionRect.isEmpty() )
continue;
// add the item to the 'visible list'
d->visibleItems.push_back( i );
VisiblePageRect * vItem = new VisiblePageRect( i->pageNumber(), NormalizedRect( intersectionRect.translated( -i->geometry().topLeft() ), i->geometry().width(), i->geometry().height() ) );
visibleRects.push_back( vItem );
#ifdef PAGEVIEW_DEBUG
kWarning() << "checking for pixmap for page " << i->pageNumber() << " = " << i->page()->hasPixmap( PAGEVIEW_ID, i->width(), i->height() ) << "\n";
#endif
......@@ -2328,6 +2332,7 @@ void PageView::slotRequestVisiblePixmaps( int newLeft, int newTop )
// set the viewport to other observers
d->document->setViewport( newViewport , PAGEVIEW_ID);
}
d->document->setVisiblePageRects( visibleRects, PAGEVIEW_ID );
}
void PageView::slotMoveViewport()
......
......@@ -26,6 +26,7 @@
// local includes
#include "thumbnaillist.h"
#include "pagepainter.h"
#include "core/area.h"
#include "core/document.h"
#include "core/generator.h"
#include "core/page.h"
......@@ -41,6 +42,8 @@ class ThumbnailWidget : public QWidget
void resizeFitWidth( int width );
// set thumbnail's selected state
void setSelected( bool selected );
// set the visible rect of the current page
void setVisibleRect( const NormalizedRect & rect );
// query methods
int heightHint() const { return m_pixmapHeight + m_labelHeight + m_margin; }
......@@ -65,6 +68,7 @@ class ThumbnailWidget : public QWidget
bool m_selected;
int m_pixmapWidth, m_pixmapHeight;
int m_labelHeight, m_labelNumber;
NormalizedRect m_visibleRect;
};
......@@ -236,6 +240,31 @@ void ThumbnailList::notifyContentsCleared( int changedFlags )
slotRequestVisiblePixmaps();
}
void ThumbnailList::notifyVisibleRectsChanged()
{
bool found = false;
const QVector<VisiblePageRect *> & visibleRects = m_document->visiblePageRects();
QVector<ThumbnailWidget *>::iterator tIt = m_thumbnails.begin(), tEnd = m_thumbnails.end();
QVector<VisiblePageRect *>::const_iterator vEnd = visibleRects.end();
for ( ; tIt != tEnd; ++tIt )
{
found = false;
QVector<VisiblePageRect *>::const_iterator vIt = visibleRects.begin();
for ( ; ( vIt != vEnd ) && !found; ++vIt )
{
if ( (*tIt)->pageNumber() == (*vIt)->pageNumber )
{
(*tIt)->setVisibleRect( (*vIt)->rect );
found = true;
}
}
if ( ! found )
{
(*tIt)->setVisibleRect( NormalizedRect() );
}
}
}
bool ThumbnailList::canUnloadPixmap( int pageNumber )
{
// if the thubnail 'pageNumber' is one of the visible ones, forbid unloading
......@@ -493,6 +522,12 @@ void ThumbnailWidget::setSelected( bool selected )
}
}
void ThumbnailWidget::setVisibleRect( const NormalizedRect & rect )
{
m_visibleRect = rect;
update();
}
QSize ThumbnailWidget::sizeHint() const
{
return QSize( width(), heightHint() );
......@@ -560,6 +595,13 @@ void ThumbnailWidget::paintEvent( QPaintEvent * e )
m_pixmapWidth, m_pixmapHeight, clipRect );
}
if ( !m_visibleRect.isNull() )
{
p.setPen( QPen( QBrush( Qt::red ), 2 ) );
p.setBrush( Qt::NoBrush );
p.drawRect( m_visibleRect.geometry( m_pixmapWidth, m_pixmapHeight ) );
}
// draw the bookmark overlay on the top-right corner
const QPixmap * bookmarkPixmap = m_tl->getBookmarkOverlay();
if ( isBookmarked && bookmarkPixmap )
......
......@@ -46,6 +46,8 @@ Q_OBJECT
void notifyPageChanged( int pageNumber, int changedFlags );
// inherited: request all visible pixmap (due to a global shange or so..)
void notifyContentsCleared( int changedFlags );
// inherited: the visible areas of the page have changed
void notifyVisibleRectsChanged();
// inherited: tell if pixmap is hidden and can be unloaded
bool canUnloadPixmap( int pageNumber );
......
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