diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-02 10:03:41 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-02 08:50:20 +0000 |
commit | cc6c76a307025595f976e833f3dadbdc7de421e1 (patch) | |
tree | cc5a45e0dffd46ddc2a3d87facddfa7675b842ed | |
parent | da61fcd7890f0e259dd97e056518d504eb99efc6 (diff) |
Native style: improve debugging support
Make it possible to draw the nine patch image for a control
unscaled, to easy the process of debugging them.
Change-Id: I6aef435b54729a511c856afa5a368d9c228e3d8a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.cpp | 34 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.h | 7 |
2 files changed, 29 insertions, 12 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp index 4c2a7c3f..bf6ac25e 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.cpp +++ b/src/imports/nativestyle/items/qquickstyleitem.cpp @@ -116,8 +116,18 @@ QSGNode *QQuickStyleItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePa auto texture = window()->createTextureFromImage(m_paintedImage, QQuickWindow::TextureCanUseAtlas); const QSize padding = m_useNinePatchImage ? m_styleItemGeometry.minimumSize / 2 : QSize(0, 0); - node->setTexture(texture); node->setBounds(boundingRect()); + +#ifdef QT_DEBUG + if (m_debugNinePatchImage) { + const qreal scale = window()->devicePixelRatio(); + const QSizeF ninePatchImageSize = m_paintedImage.rect().size() / scale; + node->setBounds(QRectF(QPointF(), ninePatchImageSize)); + qqc2Debug() << "Setting paint node size to size of image:" << ninePatchImageSize; + } +#endif + + node->setTexture(texture); node->setDevicePixelRatio(window()->devicePixelRatio()); node->setPadding(padding.width(), padding.height(), padding.width(), padding.height()); node->update(); @@ -239,8 +249,15 @@ void QQuickStyleItem::paintControlToImage() paintEvent(&painter); #ifdef QT_DEBUG - if (!m_debug.isEmpty()) + if (m_debug) { painter.fillRect(m_paintedImage.rect(), QColor(rand() % 255, rand() % 255, rand() % 255, 50)); + if (m_debugNinePatchImage) { + const QPoint center = m_paintedImage.rect().center() / scale; + painter.setPen(Qt::red); + painter.drawLine(center.x(), 0, center.x(), m_paintedImage.rect().height()); + painter.drawLine(0, center.y(), m_paintedImage.rect().width(), center.y()); + } + } #endif update(); @@ -263,14 +280,13 @@ void QQuickStyleItem::componentComplete() m_useNinePatchImage = false; if (qEnvironmentVariable("QQC2_DEBUG") == QStringLiteral("true")) { // Set the object name of any QML item to "debug" to print out - // extra information about that item. Optionally add some extra - // text to prefix the output (e.g "debug myButton"). - const QString prefix(QLatin1String("debug")); + // extra information about that item. Optionally add "image" + // to draw the nine patch image (with markers) instead of the + // scaled image. const QString name = m_control->objectName(); - if (name.startsWith(prefix)) { - m_debug = m_control->objectName().mid(prefix.length() + 1); - if (m_debug.isEmpty()) - m_debug = QStringLiteral("-"); + if (name.startsWith(QLatin1String("debug"))) { + m_debug = true; + m_debugNinePatchImage = name.contains(QStringLiteral("image")); } } #endif diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h index 6a9a9e9b..2535abc2 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.h +++ b/src/imports/nativestyle/items/qquickstyleitem.h @@ -55,8 +55,8 @@ #endif #ifdef QT_DEBUG -#define qqc2Debug() if (!m_debug.isEmpty()) qDebug() << m_debug << __FUNCTION__ << ":" -#define qqc2DebugHeading(HEADING) if (!m_debug.isEmpty()) qDebug() << "--------" << HEADING << "--------" +#define qqc2Debug() if (m_debug) qDebug() << __FUNCTION__ << ":" +#define qqc2DebugHeading(HEADING) if (m_debug) qDebug() << "--------" << HEADING << "--------" #else #define qqc2Debug() if (false) qDebug() #define qqc2DebugHeading(HEADING) if (false) qDebug() @@ -212,7 +212,8 @@ protected: template <class T> inline const T* control() const { return static_cast<T *>(m_control.data()); } #ifdef QT_DEBUG - QString m_debug; + bool m_debug = false; + bool m_debugNinePatchImage = false; #endif private: |