diff options
Diffstat (limited to 'src/quickcontrols2/imagine/impl/qquickninepatchimage.cpp')
-rw-r--r-- | src/quickcontrols2/imagine/impl/qquickninepatchimage.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/quickcontrols2/imagine/impl/qquickninepatchimage.cpp b/src/quickcontrols2/imagine/impl/qquickninepatchimage.cpp index 54547cf1f2..934eb887d6 100644 --- a/src/quickcontrols2/imagine/impl/qquickninepatchimage.cpp +++ b/src/quickcontrols2/imagine/impl/qquickninepatchimage.cpp @@ -87,6 +87,9 @@ QList<qreal> QQuickNinePatchData::coordsForSize(qreal size) const return coords; } +/* + Adds the 0 index coordinate if appropriate, and the one at "size". +*/ void QQuickNinePatchData::fill(const QList<qreal> &coords, qreal size) { data.clear(); @@ -207,6 +210,31 @@ public: QQuickNinePatchData yDivs; }; +/* + Examines each pixel in a horizontal or vertical (if offset is equal to the image's width) + line, storing the start and end index ("coordinate") of each 9-patch line. + + For instance, in the 7x3 (9x5 actual size) 9-patch image below, which has no horizontal + stretchable area, it would return {}: + + +-----+ + | | + +-----+ + + If indices 3 to 5 were marked, it would return {2, 5}: + + xxx + +-----+ + | | + +-----+ + + If indices 3 and 5 were marked, it would store {0, 2, 3, 4, 5, 7}: + + x x + +-----+ + | | + +-----+ +*/ static QList<qreal> readCoords(const QRgb *data, int from, int count, int offset, QRgb color) { int p1 = -1; @@ -215,12 +243,16 @@ static QList<qreal> readCoords(const QRgb *data, int from, int count, int offset int p2 = from + i * offset; if (data[p2] == color) { // colored pixel - if (p1 == -1) + if (p1 == -1) { + // This is the start of a 9-patch line. p1 = i; + } } else { // empty pixel if (p1 != -1) { + // This is the end of a 9-patch line; add the start and end indices as coordinates... coords << p1 << i; + // ... and reset p1 so that we can search for the next one. p1 = -1; } } @@ -228,6 +260,12 @@ static QList<qreal> readCoords(const QRgb *data, int from, int count, int offset return coords; } +/* + Called whenever a 9-patch image is set as the image's source. + + Reads the 9-patch lines from the source image and sets the + inset and padding properties accordingly. +*/ void QQuickNinePatchImagePrivate::updatePatches() { if (ninePatch.isNull()) @@ -332,6 +370,8 @@ void QQuickNinePatchImagePrivate::updateInsets(const QList<qreal> &horizontal, c QQuickNinePatchImage::QQuickNinePatchImage(QQuickItem *parent) : QQuickImage(*(new QQuickNinePatchImagePrivate), parent) { + Q_D(QQuickNinePatchImage); + d->smooth = qEnvironmentVariableIntValue("QT_QUICK_CONTROLS_IMAGINE_SMOOTH"); } qreal QQuickNinePatchImage::topPadding() const @@ -465,6 +505,8 @@ QSGNode *QQuickNinePatchImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNode QSGTexture *texture = window()->createTextureFromImage(image); patchNode->initialize(texture, sz * d->devicePixelRatio, image.size(), d->xDivs, d->yDivs, d->devicePixelRatio); + auto patchNodeMaterial = static_cast<QSGTextureMaterial *>(patchNode->material()); + patchNodeMaterial->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest); return patchNode; } |