Commit 7befe4e9 authored by Enrico Ros's avatar Enrico Ros

Fix switching Paper color on the fly. Fix clearing viewport when can't open

a document. Fix countour drawing on links and images. Synced TODO.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=362414
parent 79412e73
...@@ -7,8 +7,7 @@ Legend: ...@@ -7,8 +7,7 @@ Legend:
(*) - Some parts of this item are already done (*) - Some parts of this item are already done
In progress on the branch (first item comes first): In progress on the branch (first item comes first):
-> ADD: click over image allows "save image" [60% done] -> ADD: viewport changes the right way when clicking links (also suggested by Mikolaj Machowski) [40% done]
-> ADD: viewport changes the right way when clicking links [40% done]
Things to do in order to merge in HEAD (first item has highest priority): Things to do in order to merge in HEAD (first item has highest priority):
-> memory manager with different profiles (mem/cpu tradeoff: {memory saving, normal, memory aggressive}) -> memory manager with different profiles (mem/cpu tradeoff: {memory saving, normal, memory aggressive})
...@@ -17,13 +16,14 @@ Things to do in order to merge in HEAD (first item has highest priority): ...@@ -17,13 +16,14 @@ Things to do in order to merge in HEAD (first item has highest priority):
-> usability: layout 2PPV [1 2,3 4,5 6] -> [1,2 3,4 5]. add option for 'ebook' style alignemnt. (by Mikolaj) -> usability: layout 2PPV [1 2,3 4,5 6] -> [1,2 3,4 5]. add option for 'ebook' style alignemnt. (by Mikolaj)
-> usability: clear search must restore the full thumbs list (by Mikolaj) -> usability: clear search must restore the full thumbs list (by Mikolaj)
-> usability: trigger redraw on 'filter text' on current page (by Mikolaj) -> usability: trigger redraw on 'filter text' on current page (by Mikolaj)
-> fix viewport change on link (also suggested by Mikolaj Machowski)
-> new icons (contest at kde-look has ended and we know the winner. good choice :-) -> new icons (contest at kde-look has ended and we know the winner. good choice :-)
-> take care of naming on merge, too differences (remove some kpdf_* prefixes -> take care of naming on merge, too differences (remove some kpdf_* prefixes
and rename internals toodocument->kpdfdocument) and rename internals toodocument->kpdfdocument)
More items (first items will enter 'In progress list' first): More items (first items will enter 'In progress list' first):
*THIS ITEMS ARE CURRENTLY FROZEN SINCE "HEAD-MERGE" LIST IS CLEARED* *THIS ITEMS ARE CURRENTLY FROZEN SINCE "HEAD-MERGE" LIST IS CLEARED*
-> find: scroll page if the the searched string is not visible [after 'viewport changes']
-> ADD: click over image allows "save image" [60% done]
-> screen editing (annotations): framework (BR67300,BR62793) -> screen editing (annotations): framework (BR67300,BR62793)
-> screen editing (annotations): tools (BR67300) -> screen editing (annotations): tools (BR67300)
-> display current page / total pages (with analog indicator too (progressbar/indicator/...)) -> display current page / total pages (with analog indicator too (progressbar/indicator/...))
...@@ -34,9 +34,9 @@ More items (first items will enter 'In progress list' first): ...@@ -34,9 +34,9 @@ More items (first items will enter 'In progress list' first):
-> implement history (mainly for actionNamed) -> implement history (mainly for actionNamed)
-> history as a toolbox child (collecting DOs's setPage calls) -> history as a toolbox child (collecting DOs's setPage calls)
-> zoom: fit text (with configurable margin) -> zoom: fit text (with configurable margin)
-> find: scroll page if the the searched string is not visible
-> open gzipped (.pdf.gz?) files -> open gzipped (.pdf.gz?) files
-> autodetect "/dev/speech" and provide {document/page/selection} -> reading -> kttsd output with menu entries. speech{document/page/selection}. (see kdenonbeta/kttsd)
-> kttsd alternative (1): autodetect "/dev/speech" (speechd/festival) and provide reading
-> automatic online dictionaries / translators (BR80338) -> automatic online dictionaries / translators (BR80338)
-> add OCR for building TextPages out of pure graphical (aka scanned) pages -> add OCR for building TextPages out of pure graphical (aka scanned) pages
-> merge head copyright headers (by albert) -> merge head copyright headers (by albert)
...@@ -46,7 +46,7 @@ More items (first items will enter 'In progress list' first): ...@@ -46,7 +46,7 @@ More items (first items will enter 'In progress list' first):
Done (newest feature comes firts): Done (newest feature comes firts):
-> ADD: reading aids (inverted display, recolor, black/white, draw link border, draw image border) -> ADD: reading aids (inverted display, recolor, black/white, draw link border, draw image border)
-> FIX: zoom preserved when switching modes and flickerless -> FIX: zoom preserved when switching modes and flickerless drawing
-> ADD: Printing as PS instead of as image (Albert) -> ADD: Printing as PS instead of as image (Albert)
-> ADD: Remember page on session logout and put the document in it on session restore (Albert) -> ADD: Remember page on session logout and put the document in it on session restore (Albert)
-> ADD: gfx capturing tool -> ADD: gfx capturing tool
......
...@@ -220,6 +220,9 @@ void KPDFDocument::reparseConfig() ...@@ -220,6 +220,9 @@ void KPDFDocument::reparseConfig()
// load paper color from Settings or use the white default color // load paper color from Settings or use the white default color
QColor color = ( (Settings::renderMode() == Settings::EnumRenderMode::Paper ) && QColor color = ( (Settings::renderMode() == Settings::EnumRenderMode::Paper ) &&
Settings::changeColors() ) ? Settings::paperColor() : Qt::white; Settings::changeColors() ) ? Settings::paperColor() : Qt::white;
// if paper color changed we have to rebuild every visible pixmap in addition to
// the outputDevice. it's the 'heaviest' case, other effect are just recoloring
// over the page rendered on 'standard' white background.
if ( color != d->paperColor || !d->kpdfOutputDev ) if ( color != d->paperColor || !d->kpdfOutputDev )
{ {
d->paperColor = color; d->paperColor = color;
...@@ -232,8 +235,11 @@ void KPDFDocument::reparseConfig() ...@@ -232,8 +235,11 @@ void KPDFDocument::reparseConfig()
if ( d->pdfdoc ) if ( d->pdfdoc )
d->kpdfOutputDev->startDoc( d->pdfdoc->getXRef() ); d->kpdfOutputDev->startDoc( d->pdfdoc->getXRef() );
d->docLock.unlock(); d->docLock.unlock();
// invalidate pixmaps // invalidate pixmaps and send reload signals to observers
//FIXME missing QValueVector<KPDFPage*>::iterator it = d->pages.begin(), end = d->pages.end();
for ( ; it != end; ++it )
(*it)->deletePixmapsAndLinks();
foreachObserver( notifyPixmapsCleared() );
} }
} }
......
...@@ -33,6 +33,7 @@ class KPDFDocumentObserver ...@@ -33,6 +33,7 @@ class KPDFDocumentObserver
// monitor changes in pixmaps (generation thread complete) // monitor changes in pixmaps (generation thread complete)
virtual void notifyPixmapChanged( int /*pageNumber*/ ) {}; virtual void notifyPixmapChanged( int /*pageNumber*/ ) {};
virtual void notifyPixmapsCleared() {};
// commands from the Document to all observers // commands from the Document to all observers
virtual void pageSetup( const QValueVector<KPDFPage*> & /*pages*/, bool /*documentChanged*/ ) {}; virtual void pageSetup( const QValueVector<KPDFPage*> & /*pages*/, bool /*documentChanged*/ ) {};
......
...@@ -234,9 +234,15 @@ bool Part::openFile() ...@@ -234,9 +234,15 @@ bool Part::openFile()
bool Part::openURL(const KURL &url) bool Part::openURL(const KURL &url)
{ {
bool b = KParts::ReadOnlyPart::openURL(url); bool b = KParts::ReadOnlyPart::openURL(url);
if (!b) KMessageBox::error(widget(), i18n("Could not open %1").arg(url.prettyURL())); // if can't open document, update windows so they display blank contents
return b; if ( !b )
{
m_pageView->updateContents();
m_thumbnailList->updateContents();
KMessageBox::error( widget(), i18n("Could not open %1").arg(url.prettyURL()) );
}
return b;
} }
bool Part::closeURL() bool Part::closeURL()
......
...@@ -41,15 +41,7 @@ KPDFPage::KPDFPage( uint page, float w, float h, int r ) ...@@ -41,15 +41,7 @@ KPDFPage::KPDFPage( uint page, float w, float h, int r )
KPDFPage::~KPDFPage() KPDFPage::~KPDFPage()
{ {
QMap<int,QPixmap *>::iterator it = m_pixmaps.begin(), end = m_pixmaps.end(); deletePixmapsAndLinks();
for ( ; it != end; ++it )
delete *it;
QValueList< KPDFLink * >::iterator lIt = m_links.begin(), lEnd = m_links.end();
for ( ; lIt != lEnd; ++lIt )
delete *lIt;
QValueList< KPDFActiveRect * >::iterator rIt = m_rects.begin(), rEnd = m_rects.end();
for ( ; rIt != rEnd; ++rIt )
delete *rIt;
delete m_text; delete m_text;
} }
...@@ -126,7 +118,6 @@ bool KPDFPage::hasText( const QString & text, bool strictCase, bool fromTop ) ...@@ -126,7 +118,6 @@ bool KPDFPage::hasText( const QString & text, bool strictCase, bool fromTop )
return found; return found;
} }
void KPDFPage::setPixmap( int id, QPixmap * pixmap ) void KPDFPage::setPixmap( int id, QPixmap * pixmap )
{ {
if ( m_pixmaps.contains( id ) ) if ( m_pixmaps.contains( id ) )
...@@ -156,6 +147,25 @@ void KPDFPage::setActiveRects( const QValueList<KPDFActiveRect *> rects ) ...@@ -156,6 +147,25 @@ void KPDFPage::setActiveRects( const QValueList<KPDFActiveRect *> rects )
m_rects = rects; m_rects = rects;
} }
void KPDFPage::deletePixmapsAndLinks()
{
// delete all stored pixmaps
QMap<int,QPixmap *>::iterator it = m_pixmaps.begin(), end = m_pixmaps.end();
for ( ; it != end; ++it )
delete *it;
m_pixmaps.clear();
// delete Links
QValueList< KPDFLink * >::iterator lIt = m_links.begin(), lEnd = m_links.end();
for ( ; lIt != lEnd; ++lIt )
delete *lIt;
m_links.clear();
// delete ActiveRects
QValueList< KPDFActiveRect * >::iterator rIt = m_rects.begin(), rEnd = m_rects.end();
for ( ; rIt != rEnd; ++rIt )
delete *rIt;
m_rects.clear();
}
void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags, void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags,
QPainter * destPainter, const QRect & limits, int width, int height ) QPainter * destPainter, const QRect & limits, int width, int height )
...@@ -270,12 +280,15 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags, ...@@ -270,12 +280,15 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags,
{ {
QColor normalColor = QApplication::palette().active().highlight(); QColor normalColor = QApplication::palette().active().highlight();
QColor lightColor = normalColor.light( 140 ); QColor lightColor = normalColor.light( 140 );
// enlarging limits for intersection is like growing the 'linkGeometry' below
QRect limitsEnlarged = limits;
limitsEnlarged.addCoords( -2, -2, 2, 2 );
// draw links that are inside the 'limits' paint region as opaque rects // draw links that are inside the 'limits' paint region as opaque rects
QValueList< KPDFLink * >::const_iterator lIt = page->m_links.begin(), lEnd = page->m_links.end(); QValueList< KPDFLink * >::const_iterator lIt = page->m_links.begin(), lEnd = page->m_links.end();
for ( ; lIt != lEnd; ++lIt ) for ( ; lIt != lEnd; ++lIt )
{ {
QRect linkGeometry = (*lIt)->geometry(); QRect linkGeometry = (*lIt)->geometry();
if ( linkGeometry.intersects( limits ) ) if ( linkGeometry.intersects( limitsEnlarged ) )
{ {
// expand rect and draw inner border // expand rect and draw inner border
linkGeometry.addCoords( -1,-1,1,1 ); linkGeometry.addCoords( -1,-1,1,1 );
...@@ -294,12 +307,15 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags, ...@@ -294,12 +307,15 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags,
{ {
QColor normalColor = QApplication::palette().active().highlight(); QColor normalColor = QApplication::palette().active().highlight();
QColor lightColor = normalColor.light( 140 ); QColor lightColor = normalColor.light( 140 );
// enlarging limits for intersection is like growing the 'linkGeometry' below
QRect limitsEnlarged = limits;
limitsEnlarged.addCoords( -2, -2, 2, 2 );
// draw links that are inside the 'limits' paint region as opaque rects // draw links that are inside the 'limits' paint region as opaque rects
QValueList< KPDFActiveRect * >::const_iterator rIt = page->m_rects.begin(), rEnd = page->m_rects.end(); QValueList< KPDFActiveRect * >::const_iterator rIt = page->m_rects.begin(), rEnd = page->m_rects.end();
for ( ; rIt != rEnd; ++rIt ) for ( ; rIt != rEnd; ++rIt )
{ {
QRect rectGeometry = (*rIt)->geometry(); QRect rectGeometry = (*rIt)->geometry();
if ( rectGeometry.intersects( limits ) ) if ( rectGeometry.intersects( limitsEnlarged ) )
{ {
// expand rect and draw inner border // expand rect and draw inner border
rectGeometry.addCoords( -1,-1,1,1 ); rectGeometry.addCoords( -1,-1,1,1 );
......
...@@ -54,17 +54,18 @@ class KPDFPage ...@@ -54,17 +54,18 @@ class KPDFPage
const QString getTextInRect( const QRect & rect, double zoom = 1.0 ) const; const QString getTextInRect( const QRect & rect, double zoom = 1.0 ) const;
const KPDFLink * getLink( int mouseX, int mouseY ) const; const KPDFLink * getLink( int mouseX, int mouseY ) const;
// operations (not const methods caled by KPDFDocument) // operations (by KPDFDocument)
inline void setAttribute( int att ) { m_attributes |= att; } inline void setAttribute( int att ) { m_attributes |= att; }
inline void clearAttribute( int att ) { m_attributes &= ~att; } inline void clearAttribute( int att ) { m_attributes &= ~att; }
inline void toggleAttribute( int att ) { m_attributes ^= att; } inline void toggleAttribute( int att ) { m_attributes ^= att; }
bool hasText( const QString & text, bool strictCase, bool fromTop ); bool hasText( const QString & text, bool strictCase, bool fromTop );
// set contents (not const methods caled by KPDFDocument) // set contents (by KPDFDocument)
void setPixmap( int id, QPixmap * pixmap ); void setPixmap( int id, QPixmap * pixmap );
void setSearchPage( TextPage * text ); void setSearchPage( TextPage * text );
void setLinks( const QValueList<KPDFLink *> links ); void setLinks( const QValueList<KPDFLink *> links );
void setActiveRects( const QValueList<KPDFActiveRect *> rects ); void setActiveRects( const QValueList<KPDFActiveRect *> rects );
void deletePixmapsAndLinks();
private: private:
friend class PagePainter; friend class PagePainter;
......
...@@ -194,6 +194,25 @@ void PageView::setupActions( KActionCollection * ac ) ...@@ -194,6 +194,25 @@ void PageView::setupActions( KActionCollection * ac )
//BEGIN KPDFDocumentObserver inherited methods //BEGIN KPDFDocumentObserver inherited methods
void PageView::notifyPixmapChanged( int pageNumber )
{
QValueVector< PageViewItem * >::iterator iIt = d->items.begin(), iEnd = d->items.end();
for ( ; iIt != iEnd; ++iIt )
if ( (*iIt)->pageNumber() == pageNumber )
{
// update item's rectangle plus the little outline
QRect expandedRect = (*iIt)->geometry();
expandedRect.addCoords( -1, -1, 3, 3 );
updateContents( expandedRect );
break;
}
}
void PageView::notifyPixmapsCleared()
{
slotRequestVisiblePixmaps();
}
void PageView::pageSetup( const QValueVector<KPDFPage*> & pageSet, bool documentChanged ) void PageView::pageSetup( const QValueVector<KPDFPage*> & pageSet, bool documentChanged )
{ {
// reuse current pages if nothing new // reuse current pages if nothing new
...@@ -263,20 +282,6 @@ void PageView::pageSetCurrent( int pageNumber, const QRect & viewport ) ...@@ -263,20 +282,6 @@ void PageView::pageSetCurrent( int pageNumber, const QRect & viewport )
if ( d->zoomMode != ZoomFixed ) if ( d->zoomMode != ZoomFixed )
updateZoomText(); updateZoomText();
} }
void PageView::notifyPixmapChanged( int pageNumber )
{
QValueVector< PageViewItem * >::iterator iIt = d->items.begin(), iEnd = d->items.end();
for ( ; iIt != iEnd; ++iIt )
if ( (*iIt)->pageNumber() == pageNumber )
{
// update item's rectangle plus the little outline
QRect expandedRect = (*iIt)->geometry();
expandedRect.addCoords( -1, -1, 3, 3 );
updateContents( expandedRect );
break;
}
}
//END KPDFDocumentObserver inherited methods //END KPDFDocumentObserver inherited methods
//BEGIN widget events //BEGIN widget events
......
...@@ -53,9 +53,10 @@ class PageView : public QScrollView, public KPDFDocumentObserver ...@@ -53,9 +53,10 @@ class PageView : public QScrollView, public KPDFDocumentObserver
// inherited from KPDFDocumentObserver // inherited from KPDFDocumentObserver
uint observerId() const { return PAGEVIEW_ID; } uint observerId() const { return PAGEVIEW_ID; }
void notifyPixmapChanged( int pageNumber );
void notifyPixmapsCleared();
void pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged ); void pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged );
void pageSetCurrent( int pageNumber, const QRect & viewport ); void pageSetCurrent( int pageNumber, const QRect & viewport );
void notifyPixmapChanged( int pageNumber );
signals: signals:
void urlDropped( const KURL& ); void urlDropped( const KURL& );
......
...@@ -75,6 +75,22 @@ ThumbnailList::ThumbnailList( QWidget *parent, KPDFDocument *document ) ...@@ -75,6 +75,22 @@ ThumbnailList::ThumbnailList( QWidget *parent, KPDFDocument *document )
//BEGIN KPDFDocumentObserver inherited methods //BEGIN KPDFDocumentObserver inherited methods
void ThumbnailList::notifyPixmapChanged( int pageNumber )
{
QValueVector<ThumbnailWidget *>::iterator thumbIt = m_thumbnails.begin(), thumbEnd = m_thumbnails.end();
for (; thumbIt != thumbEnd; ++thumbIt)
if ( (*thumbIt)->pageNumber() == pageNumber )
{
(*thumbIt)->update();
break;
}
}
void ThumbnailList::notifyPixmapsCleared()
{
slotRequestPixmaps();
}
void ThumbnailList::pageSetup( const QValueVector<KPDFPage*> & pages, bool /*documentChanged*/ ) void ThumbnailList::pageSetup( const QValueVector<KPDFPage*> & pages, bool /*documentChanged*/ )
{ {
// delete all the Thumbnails // delete all the Thumbnails
...@@ -149,16 +165,6 @@ void ThumbnailList::pageSetCurrent( int pageNumber, const QRect & /*viewport*/ ) ...@@ -149,16 +165,6 @@ void ThumbnailList::pageSetCurrent( int pageNumber, const QRect & /*viewport*/ )
} }
} }
void ThumbnailList::notifyPixmapChanged( int pageNumber )
{
QValueVector<ThumbnailWidget *>::iterator thumbIt = m_thumbnails.begin(), thumbEnd = m_thumbnails.end();
for (; thumbIt != thumbEnd; ++thumbIt)
if ( (*thumbIt)->pageNumber() == pageNumber )
{
(*thumbIt)->update();
break;
}
}
void ThumbnailList::updateWidgets() void ThumbnailList::updateWidgets()
{ {
......
...@@ -33,15 +33,18 @@ Q_OBJECT ...@@ -33,15 +33,18 @@ Q_OBJECT
// return thumbnails observer id // return thumbnails observer id
uint observerId() const { return THUMBNAILS_ID; } uint observerId() const { return THUMBNAILS_ID; }
// redraw thumbnail ( inherited as DocumentObserver )
void notifyPixmapChanged( int pageNumber );
// request all visible pixmap (due to a global shange or so..)
void notifyPixmapsCleared();
// create thumbnails ( inherited as a DocumentObserver ) // create thumbnails ( inherited as a DocumentObserver )
void pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged ); void pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged );
// hilihght current thumbnail ( inherited as DocumentObserver ) // hilihght current thumbnail ( inherited as DocumentObserver )
void pageSetCurrent( int pageNumber, const QRect & viewport ); void pageSetCurrent( int pageNumber, const QRect & viewport );
// redraw thumbnail ( inherited as DocumentObserver )
void notifyPixmapChanged( int pageNumber );
// redraw visible widgets (useful for refreshing contents...) // redraw visible widgets (useful for refreshing contents...)
void updateWidgets(); void updateWidgets();
......
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