Commit 6f6664c2 authored by Enrico Ros's avatar Enrico Ros

ThumbnailList: show graphical 'clip' on thumbnails.

PageView: avoid update() on bookmark change (since rendering is bookmark
 independant).

svn path=/trunk/kdegraphics/kpdf/; revision=383987
parent c4c09c7c
......@@ -16,6 +16,7 @@ In progress 3.4 features (deadline is 2k5-Feb-2):
More items (first items will enter 'In progress list' first):
-> go to next/previous bookmark actions (showing in thumbnailslist rmb popup too)
-> viewport restoring: sometimes it seems to restore the viewport a bit under where it was
-> viewport restoring: save the page width setting between runs (save/restore zoom factor)
-> presentation: provide a pageX/totalPages indicator in addition to the circle one
-> add scrollbar marks for bookmarks (like kate)
-> google search in the page
......
......@@ -331,11 +331,11 @@ void PageView::notifyViewportChanged()
updateCursor( viewportToContents( mapFromGlobal( QCursor::pos() ) ) );
}
void PageView::notifyPageChanged( int pageNumber, int /*changedFlags*/ )
void PageView::notifyPageChanged( int pageNumber, int changedFlags )
{
// only handle pixmap changed notifies (the only defined for now)
//if ( !(changedFlags & DocumentObserver::Pixmap) )
// return;
// only handle pixmap / highlight changes notifies
if ( changedFlags & DocumentObserver::Bookmark )
return;
// iterate over visible items: if page(pageNumber) is one of them, repaint it
QValueList< PageViewItem * >::iterator iIt = d->visibleItems.begin(), iEnd = d->visibleItems.end();
......
......@@ -14,6 +14,7 @@
#include <kurl.h>
#include <kurldrag.h>
#include <kaction.h>
#include <kiconloader.h>
#include <kactioncollection.h>
// local includes
......@@ -47,7 +48,8 @@ class ThumbnailWidget : public QWidget
void paintEvent(QPaintEvent *);
private:
ThumbnailList * m_tl; // only for accessing 'forwardRightClick( .. )'
// used to access 'forwardRightClick( .. )' and 'getBookmarkOverlay()'
ThumbnailList * m_tl;
const KPDFPage * m_page;
bool m_selected;
int m_pixmapWidth, m_pixmapHeight;
......@@ -59,7 +61,7 @@ class ThumbnailWidget : public QWidget
ThumbnailList::ThumbnailList( QWidget *parent, KPDFDocument *document )
: QScrollView( parent, "KPDF::Thumbnails", WNoAutoErase | WStaticContents ),
m_document( document ), m_selected( 0 ), m_delayTimer( 0 )
m_document( document ), m_selected( 0 ), m_delayTimer( 0 ), m_bookmarkOverlay( 0 )
{
// set scrollbars
setHScrollBarMode( QScrollView::AlwaysOff );
......@@ -82,6 +84,10 @@ ThumbnailList::ThumbnailList( QWidget *parent, KPDFDocument *document )
connect( this, SIGNAL(contentsMoving(int, int)), this, SLOT(slotRequestVisiblePixmaps(int, int)) );
}
ThumbnailList::~ThumbnailList()
{
delete m_bookmarkOverlay;
}
//BEGIN DocumentObserver inherited methods
void ThumbnailList::notifySetup( const QValueVector< KPDFPage * > & pages, bool /*documentChanged*/ )
......@@ -226,6 +232,11 @@ void ThumbnailList::forwardRightClick( const KPDFPage * p, const QPoint & t )
emit rightClick( p, t );
}
const QPixmap * ThumbnailList::getBookmarkOverlay() const
{
return m_bookmarkOverlay;
}
void ThumbnailList::slotFilterBookmarks( bool filterOn )
{
// save state
......@@ -300,6 +311,7 @@ void ThumbnailList::viewportResizeEvent( QResizeEvent * e )
{
if ( m_thumbnails.count() < 1 || width() < 1 )
return;
// if width changed resize all the Thumbnails, reposition them to the
// right place and recalculate the contents area
if ( e->size().width() != e->oldSize().width() )
......@@ -328,6 +340,14 @@ void ThumbnailList::viewportResizeEvent( QResizeEvent * e )
}
else if ( e->size().height() <= e->oldSize().height() )
return;
// invalidate the bookmark overlay
if ( m_bookmarkOverlay )
{
delete m_bookmarkOverlay;
m_bookmarkOverlay = 0;
}
// update Thumbnails since width has changed or height has increased
delayedRequestVisiblePixmaps( 500 );
}
......@@ -348,12 +368,12 @@ void ThumbnailList::dropEvent( QDropEvent * ev )
//BEGIN internal SLOTS
void ThumbnailList::slotRequestVisiblePixmaps( int /*newContentsX*/, int newContentsY )
{
// if an update is already scheduled or the widget is hidden, don't proceed
if ( (m_delayTimer && m_delayTimer->isActive()) || !isShown() )
return;
// if an update is already scheduled or the widget is hidden, don't proceed
if ( (m_delayTimer && m_delayTimer->isActive()) || !isShown() )
return;
int vHeight = visibleHeight(),
vOffset = newContentsY == -1 ? contentsY() : newContentsY;
int vHeight = visibleHeight(),
vOffset = newContentsY == -1 ? contentsY() : newContentsY;
// scroll from the top to the last visible thumbnail
m_visibleThumbnails.clear();
......@@ -382,6 +402,20 @@ void ThumbnailList::slotRequestVisiblePixmaps( int /*newContentsX*/, int newCont
if ( !requestedPixmaps.isEmpty() )
m_document->requestPixmaps( requestedPixmaps );
}
void ThumbnailList::slotDelayTimeout()
{
// resize the bookmark overlay
delete m_bookmarkOverlay;
int expectedWidth = contentsWidth() / 4;
if ( expectedWidth > 10 )
m_bookmarkOverlay = new QPixmap( DesktopIcon( "attach", expectedWidth ) );
else
m_bookmarkOverlay = 0;
// request pixmaps
slotRequestVisiblePixmaps();
}
//END internal SLOTS
void ThumbnailList::delayedRequestVisiblePixmaps( int delayMs )
......@@ -389,7 +423,7 @@ void ThumbnailList::delayedRequestVisiblePixmaps( int delayMs )
if ( !m_delayTimer )
{
m_delayTimer = new QTimer( this );
connect( m_delayTimer, SIGNAL( timeout() ), this, SLOT( slotRequestVisiblePixmaps() ) );
connect( m_delayTimer, SIGNAL( timeout() ), this, SLOT( slotDelayTimeout() ) );
}
m_delayTimer->start( delayMs, true );
}
......@@ -398,7 +432,7 @@ void ThumbnailList::delayedRequestVisiblePixmaps( int delayMs )
/** ThumbnailWidget implementation **/
ThumbnailWidget::ThumbnailWidget( QWidget * parent, const KPDFPage * kp, ThumbnailList * tl )
: QWidget( parent, 0, WNoAutoErase ), m_tl( tl ), m_page( kp ),
: QWidget( parent, 0, WNoAutoErase ), m_tl( tl ), m_page( kp ),
m_selected( false ), m_pixmapWidth( 10 ), m_pixmapHeight( 10 )
{
m_labelNumber = m_page->number() + 1;
......@@ -475,6 +509,17 @@ void ThumbnailWidget::paintEvent( QPaintEvent * e )
PagePainter::paintPageOnPainter( m_page, THUMBNAILS_ID, flags, &p,
clipRect, m_pixmapWidth, m_pixmapHeight );
}
// draw the bookmark overlay on the top-right corner
const QPixmap * bookmarkPixmap = m_tl->getBookmarkOverlay();
if ( isBookmarked && bookmarkPixmap )
{
int pixW = bookmarkPixmap->width(),
pixH = bookmarkPixmap->height();
clipRect = clipRect.intersect( QRect( m_pixmapWidth - pixW, 0, pixW, pixH ) );
if ( clipRect.isValid() )
p.drawPixmap( m_pixmapWidth - pixW, -pixH/8, *bookmarkPixmap );
}
}
}
......
......@@ -32,6 +32,7 @@ class ThumbnailList : public QScrollView, public DocumentObserver
Q_OBJECT
public:
ThumbnailList(QWidget *parent, KPDFDocument *document);
~ThumbnailList();
// inherited: return thumbnails observer id
uint observerId() const { return THUMBNAILS_ID; }
......@@ -51,6 +52,8 @@ Q_OBJECT
// called by ThumbnailWidgets to send (forward) rightClick signals
void forwardRightClick( const KPDFPage *, const QPoint & );
// called by ThumbnailWidgets to get the overlay bookmark pixmap
const QPixmap * getBookmarkOverlay() const;
public slots:
// these are connected to ThumbnailController buttons
......@@ -79,6 +82,7 @@ Q_OBJECT
KPDFDocument *m_document;
ThumbnailWidget *m_selected;
QTimer *m_delayTimer;
QPixmap *m_bookmarkOverlay;
QValueVector<ThumbnailWidget *> m_thumbnails;
QValueList<ThumbnailWidget *> m_visibleThumbnails;
int m_vectorIndex;
......@@ -86,6 +90,8 @@ Q_OBJECT
private slots:
// make requests for generating pixmaps for visible thumbnails
void slotRequestVisiblePixmaps( int newContentsX = -1, int newContentsY = -1 );
// delay timeout: resize overlays and requests pixmaps
void slotDelayTimeout();
};
/**
......
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