18#include "eyedroppertool.h"
24#include "pointerevent.h"
26#include "vectorimage.h"
27#include "layervector.h"
28#include "layerbitmap.h"
29#include "colormanager.h"
32#include "layermanager.h"
33#include "scribblearea.h"
40void EyedropperTool::loadSettings()
42 properties.width = -1;
43 properties.feather = -1;
44 properties.useFeather =
false;
45 properties.useAA = -1;
50 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
52 return QCursor(
QPixmap(
":icons/general/cursor-eyedropper.svg"), 0, 15);
62 QPixmap icon(
":icons/general/cursor-eyedropper.svg");
68 painter.drawPixmap(0, 0, icon);
71 painter.drawRect(17, 17, 13, 13);
73 painter.setBrush(color);
74 painter.drawRect(16, 16, 15, 15);
83void EyedropperTool::pointerMoveEvent(
PointerEvent* event)
85 Layer* layer = mEditor->layers()->currentLayer();
86 if (layer ==
nullptr) {
return; }
88 if (layer->type() == Layer::BITMAP)
93 mScribbleArea->
setCursor(cursor(pickedColor));
100 if (layer->type() == Layer::VECTOR)
103 if (pickedColor >= 0)
105 mScribbleArea->
setCursor(cursor(mEditor->object()->getColor(pickedColor).color));
114void EyedropperTool::pointerReleaseEvent(
PointerEvent* event)
127 Layer* layer = mEditor->layers()->currentLayer();
128 if (layer ==
nullptr) {
return; }
130 if (layer->type() == Layer::BITMAP)
135 mEditor->color()->setFrontColor(pickedColor);
138 else if (layer->type() == Layer::VECTOR)
141 if (pickedColor >= 0)
143 mEditor->color()->setColorNumber(pickedColor);
150 BitmapImage* targetImage = layer->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0);
151 if (targetImage ==
nullptr || !targetImage->contains(pos))
return QColor();
154 const QRgb pixelColor = targetImage->constScanLine(qFloor(pos.
x()),
156 pickedColour.
setRgba(pixelColor);
158 if (pickedColour.
alpha() <= 0) pickedColour =
QColor();
164 auto vectorImage =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
165 if (vectorImage ==
nullptr)
return -1;
168 const qreal toleranceDistance = 10.0;
169 const QList<int> closestCurves = vectorImage->getCurvesCloseTo(pos, toleranceDistance);
170 const QList<int> visibleClosestCurves = filter(closestCurves, [vectorImage](
int i) {
return vectorImage->isCurveVisible(i); });
172 if (!visibleClosestCurves.
isEmpty())
174 return vectorImage->getCurvesColor(visibleClosestCurves.
last());
178 int colorNumber = vectorImage->getColorNumber(pos);
bool isValid() const const
bool isEmpty() const const
virtual bool event(QEvent *e)