Skip to content

Commit

Permalink
Merge pull request #1540 from manisandro/composer_html_fixes
Browse files Browse the repository at this point in the history
Recompute webpage viewport dimensions when resizing html frames
  • Loading branch information
nyalldawson committed Sep 22, 2014
2 parents 86cbc2e + 788575e commit d85f625
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions python/core/composer/qgscomposerhtml.sip
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class QgsComposerHtml: QgsComposerMultiFrame
*/
void loadHtml();

/**Recalculates the frame sizes for the current viewport dimensions*/
void recalculateFrameSizes();

void refreshExpressionContext();

virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties );
Expand Down
29 changes: 16 additions & 13 deletions src/core/composer/qgscomposerhtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ):
{
mHtmlUnitsToMM = htmlUnitsToMM();
mWebPage = new QWebPage();
mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );
if ( mComposition )
Expand Down Expand Up @@ -187,6 +189,19 @@ void QgsComposerHtml::loadHtml()
qApp->processEvents();
}

recalculateFrameSizes();
//trigger a repaint
emit contentsChanged();
}

void QgsComposerHtml::frameLoaded( bool ok )
{
Q_UNUSED( ok );
mLoaded = true;
}

void QgsComposerHtml::recalculateFrameSizes()
{
if ( frameCount() < 1 ) return;

QSize contentsSize = mWebPage->mainFrame()->contentsSize();
Expand All @@ -202,23 +217,11 @@ void QgsComposerHtml::loadHtml()
contentsSize.setWidth( maxFrameWidth * mHtmlUnitsToMM );

mWebPage->setViewportSize( contentsSize );
mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
mSize.setWidth( contentsSize.width() / mHtmlUnitsToMM );
mSize.setHeight( contentsSize.height() / mHtmlUnitsToMM );

renderCachedImage();

recalculateFrameSizes();
QgsComposerMultiFrame::recalculateFrameSizes();
emit changed();
//trigger a repaint
emit contentsChanged();
}

void QgsComposerHtml::frameLoaded( bool ok )
{
Q_UNUSED( ok );
mLoaded = true;
}

void QgsComposerHtml::renderCachedImage()
Expand Down
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposerhtml.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
*/
void loadHtml();

/**Recalculates the frame sizes for the current viewport dimensions*/
void recalculateFrameSizes();
void refreshExpressionContext();

virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties );
Expand Down

0 comments on commit d85f625

Please sign in to comment.