18 #include "eyedroppertool.h"
23 #include "pencilsettings.h"
25 #include "layervector.h"
26 #include "layerbitmap.h"
27 #include "colormanager.h"
30 #include "layermanager.h"
31 #include "scribblearea.h"
34 EyedropperTool::EyedropperTool(QObject *parent) :
39 void EyedropperTool::loadSettings()
41 properties.width = -1;
42 properties.feather = -1;
43 properties.useFeather =
false;
44 properties.useAA = -1;
47 QCursor EyedropperTool::cursor()
49 if ( mEditor->preference()->isOn( SETTING::TOOL_CURSOR ) )
51 return QCursor(QPixmap(
":icons/eyedropper.png"), 0, 15);
55 return Qt::CrossCursor;
59 QCursor EyedropperTool::cursor(
const QColor colour)
61 QPixmap icon(
":icons/eyedropper.png");
63 QPixmap pixmap(32, 32);
64 pixmap.fill(Qt::transparent);
66 QPainter painter(&pixmap);
67 painter.drawPixmap(0, 0, icon);
68 painter.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
69 painter.setBrush(colour);
70 painter.drawRect(16, 16, 15, 15);
73 return QCursor(pixmap, 0, 15);
76 void EyedropperTool::mousePressEvent(QMouseEvent *event)
81 void EyedropperTool::mouseReleaseEvent(QMouseEvent *event)
83 Layer* layer = mEditor->layers()->currentLayer();
84 if (layer == NULL) {
return; }
86 if (event->button() == Qt::LeftButton)
88 if (layer->type() == Layer::BITMAP)
93 pickedColour.setRgba( targetImage->pixel( getLastPoint().x(), getLastPoint().y() ) );
94 int transp = 255 - pickedColour.alpha();
95 pickedColour.setRed( pickedColour.red() + transp );
96 pickedColour.setGreen( pickedColour.green() + transp );
97 pickedColour.setBlue( pickedColour.blue() + transp );
98 if (pickedColour.alpha() != 0)
100 mEditor->color()->setColor(pickedColour);
103 else if (layer->type() == Layer::VECTOR)
106 int colourNumber = vectorImage->getColourNumber(getLastPoint());
107 if (colourNumber != -1)
109 mEditor->color()->setColorNumber(colourNumber);
115 void EyedropperTool::mouseMoveEvent(QMouseEvent *event)
119 Layer* layer = mEditor->layers()->currentLayer();
120 if (layer == NULL) {
return; }
122 if (layer->type() == Layer::BITMAP)
125 if (targetImage->contains(getCurrentPoint()))
129 pickedColour.setRgba( targetImage->pixel( getCurrentPoint().x(), getCurrentPoint().y() ) );
130 int transp = 255 - pickedColour.alpha();
131 pickedColour.setRed( pickedColour.red() + transp );
132 pickedColour.setGreen( pickedColour.green() + transp );
133 pickedColour.setBlue( pickedColour.blue() + transp );
134 if (pickedColour.alpha() != 0)
136 mScribbleArea->setCursor(cursor(pickedColour));
140 mScribbleArea->setCursor(cursor());
145 mScribbleArea->setCursor(cursor());
148 if (layer->type() == Layer::VECTOR)
151 int colourNumber = vectorImage->getColourNumber(getCurrentPoint());
152 if (colourNumber != -1)
154 mScribbleArea->setCursor(cursor(mEditor->object()->getColour(colourNumber).colour));
158 mScribbleArea->setCursor(cursor());