summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@jollamobile.com>2014-04-04 17:07:02 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-07 11:28:37 +0200
commit19d76d5d7799aa3b98a1e3e0e6e569df14886a54 (patch)
treebce6be1767756c076d2792befe6390f3307b9223
parent6a2bd5f43f1b1a3504b4431e15fc0c0fa216c3bc (diff)
Avoid excessive QImage::fill/copy in copyright handler
This fixes two problems. The first is that an empty copyright string would result in the image being regenerated over and over again. The second problem is that the code would allocate a fullscreen image regardless of the size of the copyright watermark and then do QImage::copy() to crop it to the displayed size. Needless to say, this took a bit more time than strictly required. Change-Id: Ia8d76e1cb34793439f92e7bb3ae00a8e99ffdc5e Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp76
1 files changed, 25 insertions, 51 deletions
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
index 563d8270..6aa97762 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
@@ -69,78 +69,52 @@ QT_BEGIN_NAMESPACE
*/
QGeoTiledMapDataNokia::QGeoTiledMapDataNokia(QGeoTiledMappingManagerEngineNokia *engine, QObject *parent /*= 0*/) :
QGeoTiledMapData(engine, parent),
- logo(":/images/logo.png"), // HERE logo image
- copyrightsSlab(1, 1, QImage::Format_ARGB32) {}
+ logo(":/images/logo.png") // HERE logo image
+{}
QGeoTiledMapDataNokia::~QGeoTiledMapDataNokia() {}
void QGeoTiledMapDataNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
{
const int copyrightsMargin = 10;
- const int shadowWidth = 3;
+ const int spaceToLogo = 4;
+ const int blurRate = 1;
const int fontSize = 10;
QGeoTiledMappingManagerEngineNokia *engineNokia = static_cast<QGeoTiledMappingManagerEngineNokia *>(engine());
const QString copyrightsString = engineNokia->evaluateCopyrightsText(activeMapType(), mapController()->zoom(), visibleTiles);
- if (width() > 0 && height() > 0 && (lastCopyrightsString.isNull() || copyrightsString != lastCopyrightsString)) {
- copyrightsSlab = copyrightsSlab.copy(0, 0, width(), height());
-
- // Blank image with full alpha
- copyrightsSlab.fill(Qt::transparent);
-
- QPainter painter(&copyrightsSlab);
- painter.drawImage(QPoint(0, copyrightsSlab.height() - logo.height()), logo);
-
- QColor fontColor(Qt::black);
- fontColor.setAlpha(64);
+ if (width() > 0 && height() > 0 && ((copyrightsString.isNull() && copyrightsSlab.isNull()) || copyrightsString != lastCopyrightsString)) {
QFont font("Sans Serif");
font.setPixelSize(fontSize);
font.setStyleHint(QFont::SansSerif);
font.setWeight(QFont::Bold);
+ QRect textBounds = QFontMetrics(font).boundingRect(0, 0, width(), height(), Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, copyrightsString);
+
+ copyrightsSlab = QImage(logo.width() + textBounds.width() + spaceToLogo + blurRate * 2,
+ qMax(logo.height(), textBounds.height() + blurRate * 2),
+ QImage::Format_ARGB32_Premultiplied);
+ copyrightsSlab.fill(Qt::transparent);
+
+ QPainter painter(&copyrightsSlab);
+ painter.drawImage(QPoint(0, copyrightsSlab.height() - logo.height()), logo);
painter.setFont(font);
- painter.setPen(fontColor);
- QRect textLimitsRect(logo.width(),
- 0,
- copyrightsSlab.width() - (logo.width() + copyrightsMargin * 2),
- copyrightsSlab.height());
-
- // Drawing the copyrights base shadow (watermark)
- QRect textBoundingRect;
- QRect wmRect(textLimitsRect);
- int x, y;
- for (x = 0; x < shadowWidth; x++) {
- wmRect.setLeft(textLimitsRect.left() + x);
- for (y = 0; y < shadowWidth; y++) {
- wmRect.setBottom(textLimitsRect.bottom() - y);
- painter.drawText(wmRect,
- Qt::AlignLeft | Qt::AlignBottom | Qt::TextWordWrap,
- copyrightsString,
- &textBoundingRect);
+ painter.setPen(QColor(0, 0, 0, 64));
+ painter.translate(spaceToLogo + logo.width(), -blurRate);
+ for (int x=-blurRate; x<=blurRate; ++x) {
+ for (int y=-blurRate; y<=blurRate; ++y) {
+ painter.drawText(x, y, textBounds.width(), copyrightsSlab.height(),
+ Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap,
+ copyrightsString);
}
}
-
- // Drawing the copyrights text top face
- font.setWeight(QFont::Bold);
- fontColor = Qt::white;
- painter.setFont(font);
- painter.setPen(fontColor);
- wmRect.setLeft(textLimitsRect.left() + 1);
- wmRect.setBottom(textLimitsRect.bottom() - 1);
- painter.drawText(wmRect,
- Qt::AlignLeft | Qt::AlignBottom | Qt::TextWordWrap,
- copyrightsString,
- &textBoundingRect);
-
+ painter.setPen(Qt::white);
+ painter.drawText(0, 0, textBounds.width(), copyrightsSlab.height(),
+ Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap,
+ copyrightsString);
painter.end();
- int newHeight = qMax(logo.height(), textBoundingRect.height());
-
- copyrightsSlab = copyrightsSlab.copy(0, copyrightsSlab.height() - newHeight,
- logo.width() + textBoundingRect.width() + shadowWidth + copyrightsMargin * 2,
- newHeight);
-
QPoint copyrightsPos(copyrightsMargin, height() - (copyrightsSlab.height() + copyrightsMargin));
lastCopyrightsPos = copyrightsPos;
emit copyrightsChanged(copyrightsSlab, copyrightsPos);