NC/fix - Text object selection (#1635)

* fix - It is possible to edit previously created text by clicking editing frame of another one & search optimization

(cherry picked from commit 749c968f0bfe1ea4b54c0f2e58c0766365f9fc01)

* fix - It is possible to edit previously created text by clicking editing frame of another one (final fix)

(cherry picked from commit f80de3137b2a364d39021440c812fc97c81423ea)

Co-authored-by: Yuriy Puchkov <yuriy.puchkov@namecheap.com>
This commit is contained in:
Yurii Puchkov
2021-05-20 22:40:04 +03:00
committed by GitHub
parent 401e6277eb
commit efa233692d

View File

@@ -5,7 +5,7 @@
#define SEARCH_RADIUS_NEAR 3
#define SEARCH_RADIUS_FAR 5
#define SEARCH_RADIUS_TEXT_HANDICAP 3
#define SEARCH_RADIUS_TEXT_HANDICAP 5
CaptureToolObjects::CaptureToolObjects(QObject* parent)
: QObject(parent)
@@ -85,6 +85,7 @@ int CaptureToolObjects::findWithRadius(QPainter& painter,
useCache = false;
}
for (; index >= 0; --index) {
int currentRadius = radius;
QImage image;
auto toolItem = m_captureToolObjects.at(index);
if (useCache) {
@@ -93,19 +94,28 @@ int CaptureToolObjects::findWithRadius(QPainter& painter,
// create transparent image in memory and draw toolItem on it
toolItem->drawSearchArea(painter, pixmap);
// get color at mouse clicked position in area +/- radius
// get color at mouse clicked position in area +/- currentRadius
image = pixmap.toImage();
m_imageCache.insert(0, image);
}
if (toolItem->nameID() == ToolType::TEXT) {
// Text has spaces inside to need to take a bigger radius for
if (currentRadius > SEARCH_RADIUS_NEAR) {
// Text already has a big currentRadius and no need to search
// with a bit bigger currentRadius than
// SEARCH_RADIUS_TEXT_HANDICAP + SEARCH_RADIUS_NEAR
continue;
}
// Text has spaces inside to need to take a bigger currentRadius for
// text objects search
radius += SEARCH_RADIUS_TEXT_HANDICAP;
currentRadius += SEARCH_RADIUS_TEXT_HANDICAP;
}
for (int x = pos.x() - radius; x <= pos.x() + radius; ++x) {
for (int y = pos.y() - radius; y <= pos.y() + radius; ++y) {
for (int x = pos.x() - currentRadius; x <= pos.x() + currentRadius;
++x) {
for (int y = pos.y() - currentRadius; y <= pos.y() + currentRadius;
++y) {
QRgb rgb = image.pixel(x, y);
if (rgb != 0) {
// object was found, return it index (layer index)