Commit 4baa91df authored by Enrico Ros's avatar Enrico Ros
Browse files

PagePainter: painting code for images/links boundaries and added a flag for

enabling painting features. Adapt PageView and ThumbnailList to use flags
(PageView: all on, ThumbnailList: no links/images boundaries.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=361183
parent ab5fd168
......@@ -446,9 +446,6 @@
<property name="name">
<cstring>groupBox1</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>5</hsizetype>
......@@ -458,7 +455,7 @@
</sizepolicy>
</property>
<property name="title">
<string>Enhance &amp;Visibility</string>
<string>&amp;Visual Enhance</string>
</property>
<vbox>
<property name="name">
......
......@@ -267,9 +267,9 @@ void KPDFDocument::requestPixmap( int id, uint page, int width, int height, bool
// setup kpdf output device: text page is generated only if we are at 72dpi.
// since we can pre-generate the TextPage at the right res.. why not?
bool genTextPage = !kp->hasSearchPage() && (width == kp->width()) && (height == kp->height());
// generate links if rendering pages on pageview
// generate links and activeRects if rendering pages on pageview
bool genLinks = id == PAGEVIEW_ID;
d->kpdfOutputDev->setParams( width, height, genTextPage, genLinks );
d->kpdfOutputDev->setParams( width, height, genTextPage, genLinks, genLinks );
d->docLock.lock();
d->pdfdoc->displayPage( d->kpdfOutputDev, page + 1, fakeDpiX, fakeDpiY, 0, true, genLinks );
......@@ -279,8 +279,10 @@ void KPDFDocument::requestPixmap( int id, uint page, int width, int height, bool
if ( genTextPage )
kp->setSearchPage( d->kpdfOutputDev->takeTextPage() );
if ( genLinks )
{
kp->setLinks( d->kpdfOutputDev->takeLinks() );
kp->setActiveRects( d->kpdfOutputDev->takeActiveRects() );
kp->setActiveRects( d->kpdfOutputDev->takeActiveRects() );
}
d->observers[id]->notifyPixmapChanged( page );
}
......
......@@ -157,7 +157,7 @@ void KPDFPage::setActiveRects( const QValueList<KPDFActiveRect *> rects )
}
void PagePainter::paintPageOnPainter( const KPDFPage * page, int id,
void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags,
QPainter * destPainter, const QRect & limits, int width, int height )
{
QPixmap * pixmap = 0;
......@@ -189,8 +189,10 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id,
return;
}
// we have a pixmap to paint, now let's paint it handling accessibility settings
// we have a pixmap to paint, now let's paint it using a direct or buffered painter
bool backBuffer = Settings::renderMode() != Settings::EnumRenderMode::Normal;
// if PagePainter::Accessibility is not in 'flags', disable backBuffer
backBuffer = backBuffer && (flags & Accessibility);
QPixmap * backPixmap = 0;
QPainter * p = destPainter;
if ( backBuffer )
......@@ -218,7 +220,7 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id,
}
// modify pixmap following accessibility settings
if ( backBuffer )
if ( (flags & Accessibility) && backBuffer )
{
QImage backImage = backPixmap->convertToImage();
switch ( Settings::renderMode() )
......@@ -258,8 +260,56 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id,
backPixmap->convertFromImage( backImage );
}
// visually enchance links active area if requested
if ( ( flags & EnhanceLinks ) && Settings::highlightLinks() )
{
QColor normalColor = QApplication::palette().active().highlight();
QColor lightColor = normalColor.light( 140 );
// 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();
for ( ; lIt != lEnd; ++lIt )
{
QRect linkGeometry = (*lIt)->geometry();
if ( linkGeometry.intersects( limits ) )
{
// expand rect and draw inner border
linkGeometry.addCoords( -1,-1,1,1 );
p->setPen( lightColor );
p->drawRect( linkGeometry );
// expand rect to draw outer border
linkGeometry.addCoords( -1,-1,1,1 );
p->setPen( normalColor );
p->drawRect( linkGeometry );
}
}
}
// visually enchance image borders if requested
if ( ( flags & EnhanceRects ) && Settings::highlightImages() )
{
QColor normalColor = QApplication::palette().active().highlight();
QColor lightColor = normalColor.light( 140 );
// 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();
for ( ; rIt != rEnd; ++rIt )
{
QRect rectGeometry = (*rIt)->geometry();
if ( rectGeometry.intersects( limits ) )
{
// expand rect and draw inner border
rectGeometry.addCoords( -1,-1,1,1 );
p->setPen( lightColor );
p->drawRect( rectGeometry );
// expand rect to draw outer border
rectGeometry.addCoords( -1,-1,1,1 );
p->setPen( normalColor );
p->drawRect( rectGeometry );
}
}
}
// draw selection (note: it is rescaled since the text page is at 100% scale)
if ( page->attributes() & KPDFPage::Highlight )
if ( ( flags & Highlight ) && ( page->attributes() & KPDFPage::Highlight ) )
{
int x = (int)( page->m_sLeft * width / page->m_width ),
y = (int)( page->m_sTop * height / page->m_height ),
......@@ -385,6 +435,11 @@ void KPDFLink::copyString( char * &dest, const char * src ) const
}
}
QRect KPDFLink::geometry() const
{
return QRect( x_min, y_min, x_max - x_min, y_max - y_min );
}
KPDFLink::LinkType KPDFLink::type() const
{
......@@ -431,3 +486,8 @@ bool KPDFActiveRect::contains(int x, int y)
{
return (x > m_left) && (x < m_right) && (y > m_top) && (y < m_bottom);
}
QRect KPDFActiveRect::geometry() const
{
return QRect( m_left, m_top, m_right - m_left, m_bottom - m_top );
}
......@@ -23,6 +23,7 @@ class KPDFActiveRect;
/**
* @short Collector for all the data belonging to a page.
* ### MERGE: definition and implementation must be moved to kpdfpage.h/.cpp
*
* The KPDFPage class contains pixmaps (referenced using obsedvers id as key),
* a search page (a class used internally for searching data), link classes
......@@ -77,16 +78,31 @@ class KPDFPage
QValueList< KPDFActiveRect * > m_rects;
};
/**
* @short Paints a KPDFPage to an open painter using given flags.
* ### MERGE: since this file will be empty, we might consider renaming
* ### definition and implementation to pagepainter.*
*/
class PagePainter
{
public:
static void paintPageOnPainter( const KPDFPage * page, int id,
// list of flags passed to the painting function. by OR-ing those flags
// you can decide wether or not to permit drawing of a certain feature.
enum PagePainterFlags { Accessibility = 1, EnhanceLinks = 2,
EnhanceRects = 4, Highlight = 8 };
// draw (using painter 'p') the 'page' requested by 'id' using features
// in 'flags'. 'limits' is the bounding rect of the paint operation,
// 'width' and 'height' the expected size of page contents (used only
// to pick up an alternative pixmap if the pixmap of 'id' is missing.
static void paintPageOnPainter( const KPDFPage * page, int id, int flags,
QPainter * p, const QRect & limits, int width = -1, int height = -1 );
};
/**
* @short Encapsulates data that describes a link.
* ### MERGE: MOVE definition/implementation to kpdflink.h/.cpp
* ### NOTE: KPDFActiveRect and KPDFLink SHOULD BE MERGED !!
*
* There are many types of PDF links, here we provide accessors to set the
* link to be of the given type. Other functions are for asking if a point
......@@ -109,6 +125,7 @@ public:
// query / others
bool contains( int x, int y ) const;
void copyString( char * &dest, const char * src ) const;
QRect geometry() const; //TODO add intersects( qrect )
// action queries
enum LinkType { Goto, Execute, URI, Named, Movie, Unknown };
......@@ -123,7 +140,7 @@ public:
private:
// general
LinkType m_type;
float x_min, x_max, y_min, y_max;
int x_min, x_max, y_min, y_max;
// actions related
LinkDest * m_dest;
......@@ -137,19 +154,22 @@ private:
/**
* @short Describes an 'active' rectange on the page.
* ### MERGE: MOVE definition/implementation to kpdflink.h/.cpp
* ### NOTE: KPDFActiveRect and KPDFLink SHOULD BE MERGED !!
*
* ...
*/
class KPDFActiveRect
{
public:
KPDFActiveRect(int left, int top, int width, int height);
public:
KPDFActiveRect(int left, int top, int width, int height);
// query
bool contains(int x, int y);
// query
bool contains(int x, int y);
QRect geometry() const;
private:
int m_left, m_top, m_right, m_bottom;
private:
int m_left, m_top, m_right, m_bottom;
};
#endif
......@@ -890,7 +890,10 @@ void PageView::paintItems( QPainter * p, const QRect & contentsRect )
{
QRect pixmapRect = contentsRect.intersect( pixmapGeometry );
pixmapRect.moveBy( -pixmapGeometry.left(), -pixmapGeometry.top() );
PagePainter::paintPageOnPainter( item->page(), PAGEVIEW_ID, p, pixmapRect, pixmapGeometry.width(), pixmapGeometry.height() );
int flags = PagePainter::Accessibility | PagePainter::EnhanceLinks |
PagePainter::EnhanceRects | PagePainter::Highlight;
PagePainter::paintPageOnPainter( item->page(), PAGEVIEW_ID, flags, p, pixmapRect,
pixmapGeometry.width(), pixmapGeometry.height() );
}
// remove painted area from 'remainingArea' and restore painter
......
......@@ -379,7 +379,11 @@ void ThumbnailWidget::paintEvent( QPaintEvent * e )
clipRect.moveBy( -2, -2 );
clipRect = clipRect.intersect( QRect( 0, 0, m_pixmapWidth, m_pixmapHeight ) );
if ( clipRect.isValid() )
PagePainter::paintPageOnPainter( m_page, THUMBNAILS_ID, &p, clipRect, m_pixmapWidth, m_pixmapHeight );
{
int flags = PagePainter::Accessibility | PagePainter::Highlight;
PagePainter::paintPageOnPainter( m_page, THUMBNAILS_ID, flags, &p,
clipRect, m_pixmapWidth, m_pixmapHeight );
}
}
}
......
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