Commit a9ab3867 authored by Enrico Ros's avatar Enrico Ros
Browse files

PageView rewrite: new paint logic. Supports internal composting and direct

drawing (to support transparency without overlay hacks and blend in notes
and other stuff). I'm sure this can be simplified a lot, but I can't see
how to cut code now. ThumbnailList still has the old code.
Now we have no wasted repaints. Also per-page allocated memory is less. Now
we need more repaints, since the viewport gfx looks broken. I hope not to
revert this, but find a unique short way to describe composted gfx ops.
Note: there is a swith in config to switch between plain and composted
rendering engines.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=359096
parent c16dd07b
......@@ -9,7 +9,7 @@
<x>0</x>
<y>0</y>
<width>266</width>
<height>109</height>
<height>135</height>
</rect>
</property>
<property name="caption">
......@@ -96,6 +96,17 @@
<string>Alt+H</string>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>kcfg_TempUseComposite</cstring>
</property>
<property name="text">
<string>USE COMPOSITE</string>
</property>
<property name="accel">
<string></string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer3</cstring>
......
......@@ -68,4 +68,9 @@
</values>
</entry>
</group>
<group name="Temp" >
<entry key="TempUseComposite" type="Bool" >
<default>false</default>
</entry>
</group>
</kcfg>
......@@ -142,11 +142,12 @@ void KPDFPage::drawPixmap( int id, QPainter * p, const QRect & limits, int width
else
{
p->save();
// TODO paint only the needed part
p->scale( width / (double)pixmap->width(), height / (double)pixmap->height() );
p->drawPixmap( 0,0, *pixmap, 0,0, pixmap->width(), pixmap->height() );
p->restore();
// draw a red cross (to hilight that the pixmap has not the right size)
p->setPen( Qt::red );
// draw a cross (to that the pixmap has not the right size)
p->setPen( Qt::gray );
p->drawLine( 0, 0, width-1, height-1 );
p->drawLine( 0, height-1, width-1, 0 );
}
......
This diff is collapsed.
......@@ -27,7 +27,7 @@
class KURL;
class KActionCollection;
class PageWidget;
class PageViewItem;
class PageViewPrivate;
/**
......@@ -78,12 +78,16 @@ class PageView : public QScrollView, public KPDFDocumentObserver
void dropEvent( QDropEvent* );
private:
// draw items on the opened qpainter
void paintItems( QPainter * p, const QRect & clipRect );
// update item width and height using current zoom parameters
void updateItemSize( PageViewItem * item, int columnWidth, int rowHeight );
// return the widget placed on a certain point or 0 if clicking on empty space
PageViewItem * pickItemOnPoint( int x, int y );
// update internal zoom values and end in a slotRelayoutPages();
void updateZoom( ZoomMode newZm );
// update the text on the label using global zoom value or current page's one
void updateZoomText();
// return the widget placed on a certain point or 0 if clicking on empty space
PageWidget * pickPageOnPoint( int x, int y );
// don't want to expose classes in here
class PageViewPrivate * d;
......
......@@ -12,10 +12,53 @@
#include <qwidget.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <qrect.h>
class QTimer;
class PageView;
#include "page.h"
class PageViewItem
{
public:
PageViewItem( const KPDFPage * page )
: m_page( page ), m_zoomFactor( 1.0 )
{
// do something
}
void setWHZ( int w, int h, double z )
{
m_geometry.setWidth( w );
m_geometry.setHeight( h );
m_zoomFactor = z;
}
float zoomFactor() { return m_zoomFactor; }
int pageNumber() const { return m_page->number(); }
const KPDFPage * page() const { return m_page; }
const QRect& geometry() const { return m_geometry; }
int width() const { return m_geometry.width(); }
int height() const { return m_geometry.height(); }
void setGeometry( int x, int y, int width, int height )
{
m_geometry.setRect( x, y, width, height );
}
void moveTo( int x, int y )
{
m_geometry.moveLeft( x );
m_geometry.moveTop( y );
}
private:
const KPDFPage * m_page;
double m_zoomFactor;
QRect m_geometry;
};
/**
* @short A widget that displays messages in the top-left corner.
......
......@@ -171,116 +171,3 @@ void ThumbnailWidget::paintEvent( QPaintEvent * e )
p.end();
}
/** PageWidget **/
PageWidget::PageWidget( QWidget *parent, const KPDFPage *page )
: PixmapWidget( parent, page, "pageWidget" ), m_selBeginX( -1 ), m_selBeginY( -1 )
{
// keep bottom equal to right margin
setPixmapMargins( 1, 1, 4, 4 );
}
void PageWidget::clearSelection()
{
if ( !m_selectionRect.isNull() )
update( m_selectionRect );
m_selBeginX = -1;
m_selBeginY = -1;
m_selectionRect = QRect();
}
void PageWidget::setBeginCorner( int x, int y )
{
if ( !m_selectionRect.isNull() )
update( m_selectionRect );
m_selBeginX = x;
m_selBeginY = y;
m_selectionRect.setCoords( x, y, 1, 1 );
update( m_selectionRect );
}
void PageWidget::setEndCorner( int x, int y )
{
QRect newRect( m_selBeginX, m_selBeginY, x - m_selBeginX, y - m_selBeginY );
newRect = newRect.normalize().intersect( QRect( m_marginLeft, m_marginTop, m_pixmapWidth, m_pixmapHeight ) );
if ( newRect != m_selectionRect )
{
if ( !m_selectionRect.isNull() )
update( m_selectionRect );
m_selectionRect = newRect;
update( m_selectionRect );
}
}
QString PageWidget::selectedText() const
{
return m_page->getTextInRect( m_selectionRect );
}
void PageWidget::paintEvent( QPaintEvent * e )
{
QRect clip = e->rect();
QRect pageClip = clip.intersect( QRect( m_marginLeft, m_marginTop, m_pixmapWidth, m_pixmapHeight ) );
// FIXME: this prevents outline-only paints (but saves pixmap repaints!!)
if ( !pageClip.isValid() || pageClip.width() < 1 || pageClip.height() < 1 )
return;
// kdDebug() << "repaint on page " << pageNumber() << " on rect: " << clip << endl;
QPainter p( this );
// if drawn region includes an edge of the page
if ( pageClip != clip && m_pixmapWidth > 10 && m_pixmapWidth > 10 )
{
// draw the black outline
p.drawRect( QRect( 0,0, m_pixmapWidth + 2, m_pixmapHeight + 2 ) );
// draws shadow on left and bottom edges
int levels = m_marginBottom - 1;
p.fillRect( 0, 2 + m_pixmapHeight, levels, levels, Qt::gray );
p.fillRect( 2 + m_pixmapWidth, 0, levels, levels, Qt::gray );
int r = Qt::gray.red() / (levels + 2),
g = Qt::gray.green() / (levels + 2),
b = Qt::gray.blue() / (levels + 2);
for ( int i = 0; i < levels; i++ )
{
p.setPen( QColor( r * (i+2), g * (i+2), b * (i+2) ) );
p.drawLine( 1 + i, m_pixmapHeight+2 + i, m_pixmapWidth+2 + i, m_pixmapHeight+2 + i );
p.drawLine( m_pixmapWidth+2 + i, 1 + i, m_pixmapWidth+2 + i, m_pixmapHeight+2 + i );
}
}
// draw page (inside pageClip rectangle)
p.translate( m_marginLeft, m_marginTop );
pageClip.moveBy( -m_marginLeft, -m_marginTop );
// accessibility setting
if ( Settings::renderMode() == Settings::EnumRenderMode::Inverted )
p.setRasterOp( Qt::NotCopyROP );
// draw the pixmap
m_page->drawPixmap( PAGEVIEW_ID, &p, pageClip, m_pixmapWidth, m_pixmapHeight );
#if 0
// TODO: overlays <ONLY FOR FUN> :-)
#include <qpixmap.h>
#include <kstandarddirs.h>
if ( m_pixmapWidth > 64 && m_pixmapHeight > 64 )
{
QPixmap page( locate("data","kpdf/bookmark_corner.png") );
p.drawPixmap( m_pixmapWidth - page.width(), 0, page );
}
#endif
p.translate( -m_marginLeft, -m_marginTop );
// draw selection rect (uses opaque selection)
if ( !m_selectionRect.isNull() )
{
p.setPen( palette().active().highlight().dark(110) );
//COOL p.setBrush( QBrush( palette().active().highlight(), Qt::Dense4Pattern ) );
p.drawRect( m_selectionRect );
}
p.end();
}
......@@ -72,28 +72,4 @@ private:
int m_labelHeight;
};
/**
* @short PageView's editable page. Renders page, selection and overlay GFX.
* ...
*/
class PageWidget : public PixmapWidget
{
public:
PageWidget( QWidget * parent, const KPDFPage * page );
void clearSelection();
void setBeginCorner( int x, int y );
void setEndCorner( int x, int y );
QString selectedText() const;
protected:
void paintEvent(QPaintEvent *);
private:
int m_selBeginX;
int m_selBeginY;
QRect m_selectionRect;
};
#endif
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