22 #include <QCoreApplication>
31 mHtmlUnitsToMM( 1.0 ),
33 mUseSmartBreaks( true ),
34 mMaxBreakDistance( 10 )
39 QObject::connect(
mWebPage, SIGNAL( loadFinished(
bool ) ),
this, SLOT(
frameLoaded(
bool ) ) );
50 mHtmlUnitsToMM( 1.0 ),
52 mUseSmartBreaks( true ),
53 mMaxBreakDistance( 10 )
85 qApp->processEvents();
90 QSize contentsSize =
mWebPage->mainFrame()->contentsSize();
92 mWebPage->setViewportSize( contentsSize );
93 mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
94 mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
120 mWebPage->mainFrame()->render( &painter );
162 if ( recalcFrameSizes )
170 if ( c1.second < c2.second )
172 else if ( c1.second > c2.second )
174 else if ( c1.first > c2.first )
203 QList< QPair<int, int> > candidates;
204 int minRow = qMax( idealPos - maxSearchDistance, 0 );
205 for (
int candidateRow = idealPos; candidateRow >= minRow; --candidateRow )
208 currentColor = qRgba( 0, 0, 0, 0 );
217 if ( pixelColor != currentColor )
220 currentColor = pixelColor;
224 candidates.append( qMakePair( candidateRow, changes ) );
228 qSort( candidates.begin(), candidates.end(),
candidateSort );
235 int maxCandidateRow = candidates[0].first;
236 int minCandidateRow = maxCandidateRow + 1;
237 int minCandidateChanges = candidates[0].second;
239 QList< QPair<int, int> >::iterator it;
240 for ( it = candidates.begin(); it != candidates.end(); ++it )
242 if (( *it ).second != minCandidateChanges || ( *it ).first != minCandidateRow - 1 )
247 return ( minCandidateRow + ( maxCandidateRow - minCandidateRow ) / 2 ) /
htmlUnitsToMM();
249 minCandidateRow = ( *it ).first;
273 QDomElement htmlElem = doc.createElement(
"ComposerHtml" );
274 htmlElem.setAttribute(
"url",
mUrl.toString() );
275 htmlElem.setAttribute(
"useSmartBreaks",
mUseSmartBreaks ?
"true" :
"false" );
276 htmlElem.setAttribute(
"maxBreakDistance", QString::number(
mMaxBreakDistance ) );
278 bool state =
_writeXML( htmlElem, doc, ignoreFrames );
279 elem.appendChild( htmlElem );
288 if ( !
_readXML( itemElem, doc, ignoreFrames ) )
293 mUseSmartBreaks = itemElem.attribute(
"useSmartBreaks",
"true" ) ==
"true" ?
true :
false;
297 QString urlString = itemElem.attribute(
"url" );
298 if ( !urlString.isEmpty() )
300 setUrl( QUrl( urlString ) );
void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of it's component frames...
double findNearbyPageBreak(double yPos)
Finds the optimal position to break a frame at.
void frameLoaded(bool ok)
A item that forms part of a map composition.
QgsComposition * mComposition
bool useSmartBreaks() const
Returns whether html item is using smart breaks.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)
int printResolution() const
Abstract base class for composer entries with the ability to distribute the content to several frames...
QList< QgsComposerFrame * > mFrameItems
bool _writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const
void setMaxBreakDistance(double maxBreakDistance)
Sets the maximum distance allowed when calculating where to place page breaks in the html...
void setUseSmartBreaks(bool useSmartBreaks)
Sets whether the html item should use smart breaks.
int frameCount() const
Return the number of frames associated with this multiframeset.
Graphics scene for map printing.
Frame for html, table, text which can be divided onto several frames.
void loadHtml()
Reloads the html source from the url and redraws the item.
void deleteFrames()
Removes and deletes all frames from mComposition.
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const
double maxBreakDistance() const
Returns the maximum distance allowed when calculating where to place page breaks in the html...
void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true)
void addComposerHtmlFrame(QgsComposerHtml *html, QgsComposerFrame *frame)
Adds composer html frame and advices composer to create a widget for it (through signal) ...
void setUrl(const QUrl &url)
void render(QPainter *p, const QRectF &renderExtent)
void handleFrameRemoval(QgsComposerItem *item)
Called before a frame is going to be removed (update frame list)
bool candidateSort(const QPair< int, int > &c1, const QPair< int, int > &c2)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)