Skip to content
Permalink
Browse files

Test multiple frame html rendering

  • Loading branch information
mhugent committed Jul 25, 2012
1 parent 0ed3d47 commit a928d57be54ceda6f2d4f14ad25a2d1541bf8632
@@ -59,9 +59,8 @@ void QgsComposerHtml::setUrl( const QUrl& url )
QSize contentsSize = mWebPage->mainFrame()->contentsSize();
mWebPage->setViewportSize( contentsSize );

double pixelPerMM = mComposition->printResolution() / 25.4;
mSize.setWidth( contentsSize.width() / pixelPerMM );
mSize.setHeight( contentsSize.height() / pixelPerMM );
mSize.setWidth( contentsSize.width() / mHtmlUnitsToMM );
mSize.setHeight( contentsSize.height() / mHtmlUnitsToMM );
}

void QgsComposerHtml::frameLoaded( bool ok )
@@ -83,7 +82,8 @@ void QgsComposerHtml::render( QPainter* p, const QRectF& renderExtent )

p->save();
p->scale( 1.0 / mHtmlUnitsToMM, 1.0 / mHtmlUnitsToMM );
mWebPage->mainFrame()->render( p, QRegion( renderExtent.left(), renderExtent.top(), renderExtent.width() * mHtmlUnitsToMM, renderExtent.height() * mHtmlUnitsToMM ) );
p->translate( 0.0, -renderExtent.top() * mHtmlUnitsToMM );
mWebPage->mainFrame()->render( p, QRegion( renderExtent.left(), renderExtent.top() * mHtmlUnitsToMM, renderExtent.width() * mHtmlUnitsToMM, renderExtent.height() * mHtmlUnitsToMM ) );
p->restore();
}

@@ -16,11 +16,13 @@
#include "qgscomposermultiframe.h"
#include "qgscomposerframe.h"

QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c )
QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
{
//debug
mResizeMode = ExtendToNextPage;
}

QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 )
QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
{
}

@@ -30,12 +32,65 @@ QgsComposerMultiFrame::~QgsComposerMultiFrame()

void QgsComposerMultiFrame::recalculateFrameSizes()
{
if ( mFrameItems.size() < 1 )
{
return;
}

QSizeF size = totalSize();
double totalHeight = size.height();
double currentY = 0;
double currentHeight = 0;
QgsComposerFrame* currentItem = 0;

QList<QgsComposerFrame*>::iterator frameIt = mFrameItems.begin();
for ( ; frameIt != mFrameItems.end(); ++frameIt )
{
if ( currentY >= totalHeight )
{
return;
}
currentItem = *frameIt;
currentHeight = currentItem->rect().height();
currentItem->setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) );
currentItem->update();
currentY += currentHeight;
}

//at end of frames but there is still content left. Add other pages if ResizeMode ==
if ( mResizeMode == ExtendToNextPage )
{
while ( currentY < totalHeight )
{
//find out on which page the lower left point of the last frame is
int page = currentItem->transform().dy() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() );
//double offset = currentItem->transform().dy() - page * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() );

//e.v. add a new page
if ( mComposition->numPages() < ( page + 2 ) )
{
mComposition->setNumPages( page + 2 );
}

//copy last frame
QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, 0, currentItem->transform().dy() + mComposition->paperHeight() + mComposition->spaceBetweenPages(),
currentItem->rect().width(), currentItem->rect().height() );
newFrame->setContentSection( QRectF( 0, currentY, newFrame->rect().width(), newFrame->rect().height() ) );
currentY += newFrame->rect().height();
currentItem = newFrame;
addFrame( newFrame );
mComposition->addItem( newFrame );
}
}

#if 0
if ( mFrameItems.size() > 0 )
{
QSizeF size = totalSize();
QgsComposerFrame* item = mFrameItems[0];
item->setContentSection( QRectF( 0, 0, item->rect().width(), item->rect().height() ) );
}
#endif //0
}

void QgsComposerMultiFrame::addFrame( QgsComposerFrame* frame )
@@ -32,8 +32,8 @@ class QgsComposerMultiFrame: public QObject

enum ResizeMode
{
ExtendToNextPage = 0, //duplicates last frame to next page to fit the total size
UseExistingFrames //
UseExistingFrames = 0,
ExtendToNextPage //duplicates last frame to next page to fit the total size
};

QgsComposerMultiFrame( QgsComposition* c );
@@ -43,9 +43,13 @@ class QgsComposerMultiFrame: public QObject

void addFrame( QgsComposerFrame* frame );

void setResizeMode( ResizeMode mode ) { mResizeMode = mode; }
ResizeMode resizeMode() const { return mResizeMode; }

protected:
QgsComposition* mComposition;
QList<QgsComposerFrame*> mFrameItems;
ResizeMode mResizeMode;

protected slots:
void recalculateFrameSizes();

0 comments on commit a928d57

Please sign in to comment.
You can’t perform that action at this time.