mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
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:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#define SEARCH_RADIUS_NEAR 3
|
#define SEARCH_RADIUS_NEAR 3
|
||||||
#define SEARCH_RADIUS_FAR 5
|
#define SEARCH_RADIUS_FAR 5
|
||||||
#define SEARCH_RADIUS_TEXT_HANDICAP 3
|
#define SEARCH_RADIUS_TEXT_HANDICAP 5
|
||||||
|
|
||||||
CaptureToolObjects::CaptureToolObjects(QObject* parent)
|
CaptureToolObjects::CaptureToolObjects(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@@ -85,6 +85,7 @@ int CaptureToolObjects::findWithRadius(QPainter& painter,
|
|||||||
useCache = false;
|
useCache = false;
|
||||||
}
|
}
|
||||||
for (; index >= 0; --index) {
|
for (; index >= 0; --index) {
|
||||||
|
int currentRadius = radius;
|
||||||
QImage image;
|
QImage image;
|
||||||
auto toolItem = m_captureToolObjects.at(index);
|
auto toolItem = m_captureToolObjects.at(index);
|
||||||
if (useCache) {
|
if (useCache) {
|
||||||
@@ -93,19 +94,28 @@ int CaptureToolObjects::findWithRadius(QPainter& painter,
|
|||||||
// create transparent image in memory and draw toolItem on it
|
// create transparent image in memory and draw toolItem on it
|
||||||
toolItem->drawSearchArea(painter, pixmap);
|
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();
|
image = pixmap.toImage();
|
||||||
m_imageCache.insert(0, image);
|
m_imageCache.insert(0, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolItem->nameID() == ToolType::TEXT) {
|
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
|
// 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 x = pos.x() - currentRadius; x <= pos.x() + currentRadius;
|
||||||
for (int y = pos.y() - radius; y <= pos.y() + radius; ++y) {
|
++x) {
|
||||||
|
for (int y = pos.y() - currentRadius; y <= pos.y() + currentRadius;
|
||||||
|
++y) {
|
||||||
QRgb rgb = image.pixel(x, y);
|
QRgb rgb = image.pixel(x, y);
|
||||||
if (rgb != 0) {
|
if (rgb != 0) {
|
||||||
// object was found, return it index (layer index)
|
// object was found, return it index (layer index)
|
||||||
|
|||||||
Reference in New Issue
Block a user