aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@gmail.com>2016-02-06 19:28:06 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-02-06 18:34:12 +0000
commit4a7fcac5f17b0f968b162e847b4f40c39de506df (patch)
tree89bfb8d2ccf92e0e1ff2bb378e30ce918ab3fea4 /src/imports
parentc28dfd06c823f0b104d68f4ed4e7b2e2f61f911f (diff)
Optimize QQuickUniversalFocusRectangle::paint()
Change-Id: I75cc70df9f5eef5a1e0132ea8ec90938305dfde2 Task-number: QTBUG-50575 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/controls/universal/qquickuniversalfocusrectangle.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp b/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp
index 40388eff..554b8607 100644
--- a/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp
+++ b/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp
@@ -36,7 +36,9 @@
#include "qquickuniversalfocusrectangle_p.h"
+#include <QtGui/qpixmap.h>
#include <QtGui/qpainter.h>
+#include <QtGui/qpixmapcache.h>
#include <QtQuick/private/qquickitem_p.h>
QT_BEGIN_NAMESPACE
@@ -52,20 +54,29 @@ void QQuickUniversalFocusRectangle::paint(QPainter *painter)
if (!isVisible() || width() <= 0 || height() <= 0)
return;
- const QRect bounds = boundingRect().toAlignedRect().adjusted(0, 0, -1, -1);
+ QRect bounds = boundingRect().toAlignedRect();
+ const QString key = QStringLiteral("qquickuniversalfocusrectangle_%1_%2").arg(bounds.width()).arg(bounds.height());
- QPen pen;
- pen.setWidth(1);
- pen.setDashPattern(QVector<qreal>() << 1 << 1);
+ QPixmap pixmap(bounds.width(), bounds.height());
+ if (!QPixmapCache::find(key, &pixmap)) {
+ bounds.adjust(0, 0, -1, -1);
+ pixmap.fill(Qt::transparent);
+ QPainter p(&pixmap);
- pen.setColor(Qt::white);
- painter->setPen(pen);
- painter->drawRect(bounds);
+ QPen pen;
+ pen.setWidth(1);
+ pen.setColor(Qt::white);
+ p.setPen(pen);
+ p.drawRect(bounds);
- pen.setColor(Qt::black);
- pen.setDashOffset(1);
- painter->setPen(pen);
- painter->drawRect(bounds);
+ pen.setColor(Qt::black);
+ pen.setDashPattern(QVector<qreal>() << 1 << 1);
+ p.setPen(pen);
+ p.drawRect(bounds);
+
+ QPixmapCache::insert(key, pixmap);
+ }
+ painter->drawPixmap(0, 0, pixmap);
}
QT_END_NAMESPACE