24 #include "viewmanager.h"
25 #include "toolmanager.h"
26 #include "scribblearea.h"
27 #include "strokemanager.h"
28 #include "pointerevent.h"
31 qreal BaseTool::msOriginalPropertyValue;
32 bool BaseTool::msIsAdjusting =
false;
35 QString BaseTool::TypeName(ToolType type)
37 static std::array<QString, TOOL_TYPE_COUNT> map;
41 map[PENCIL] =
tr(
"Pencil");
42 map[ERASER] =
tr(
"Eraser");
43 map[SELECT] =
tr(
"Select");
44 map[MOVE] =
tr(
"Move");
45 map[HAND] =
tr(
"Hand");
46 map[SMUDGE] =
tr(
"Smudge");
48 map[POLYLINE] =
tr(
"Polyline");
49 map[BUCKET] =
tr(
"Bucket");
50 map[EYEDROPPER] =
tr(
"Eyedropper");
51 map[BRUSH] =
tr(
"Brush");
58 mPropertyEnabled.insert(WIDTH,
false);
59 mPropertyEnabled.insert(FEATHER,
false);
60 mPropertyEnabled.insert(USEFEATHER,
false);
61 mPropertyEnabled.insert(PRESSURE,
false);
62 mPropertyEnabled.insert(INVISIBILITY,
false);
63 mPropertyEnabled.insert(PRESERVEALPHA,
false);
64 mPropertyEnabled.insert(BEZIER,
false);
65 mPropertyEnabled.insert(ANTI_ALIASING,
false);
66 mPropertyEnabled.insert(STABILIZATION,
false);
74 void BaseTool::initialize(
Editor* editor)
78 mScribbleArea = editor->getScribbleArea();
79 Q_ASSERT(mScribbleArea);
81 mStrokeManager = mEditor->getScribbleArea()->getStrokeManager();
100 void BaseTool::pointerDoubleClickEvent(
PointerEvent* event)
102 pointerPressEvent(event);
112 if (type() == ToolType::HAND || type() == ToolType::MOVE || type() == ToolType::SELECT )
125 float propWidth = width * scalingFac;
126 float propFeather = feather * scalingFac;
128 float cursorWidth = 0.0f;
136 cursorWidth = propWidth + 0.5 * propFeather;
137 xyA = 1 + propFeather / 2;
138 xyB = 1 + propFeather / 8;
139 whA = qMax<float>(0, propWidth - xyA - 1);
140 whB = qMax<float>(0, cursorWidth - propFeather / 4 - 2);
144 cursorWidth = (propWidth + 0.5);
145 whA = qMax<float>(0, propWidth - 1);
146 whB = qMax<float>(0, cursorWidth / 4 - 2);
149 float radius = cursorWidth / 2;
152 if (cursorWidth > windowWidth * 2)
157 if (cursorWidth < 1) { cursorWidth = 1; }
160 if (!cursorPixmap.
isNull())
163 QPainter cursorPainter(&cursorPixmap);
164 QPen cursorPen = cursorPainter.
pen();
170 cursorPainter.
setPen(cursorPen);
179 cursorPainter.
setPen(cursorPen);
183 cursorPainter.
setPen(cursorPen);
190 cursorPainter.
setPen(cursorPen);
194 cursorPainter.
setPen(cursorPen);
202 QCursor BaseTool::selectMoveCursor(MoveMode mode, ToolType type)
205 if (!cursorPixmap.
isNull())
208 QPainter cursorPainter(&cursorPixmap);
213 case MoveMode::MIDDLE:
215 if (type == SELECT) {
216 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/new/arrow-selectmove.png"));
222 case MoveMode::TOPLEFT:
223 case MoveMode::BOTTOMRIGHT:
225 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/new/arrow-diagonalleft.png"));
228 case MoveMode::TOPRIGHT:
229 case MoveMode::BOTTOMLEFT:
231 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/new/arrow-diagonalright.png"));
245 return strokeManager()->isActive();
254 qreal propSize = qMax(0., properties.width) * scalingFac;
255 qreal propFeather = qMax(0., properties.feather) * scalingFac;
256 QRectF cursorRect(0, 0, propSize+2, propSize+2);
259 qreal featherRadius = (1 - propFeather / 100) * propSize / 2.;
262 if (!cursorPixmap.
isNull())
265 QPainter cursorPainter(&cursorPixmap);
292 if (mQuickSizingProperties.
contains(modifiers))
294 switch (mQuickSizingProperties.
value(modifiers)) {
296 msOriginalPropertyValue = properties.width;
299 msOriginalPropertyValue = properties.feather;
302 msOriginalPropertyValue = properties.tolerance;
305 qDebug() <<
"Unhandled quick sizing property for tool" << typeName();
310 msIsAdjusting =
true;
311 mAdjustmentStep = step;
312 mScribbleArea->updateCanvasCursor();
318 void BaseTool::stopAdjusting()
320 msIsAdjusting =
false;
322 msOriginalPropertyValue = 0;
323 mEditor->getScribbleArea()->updateCanvasCursor();
328 qreal inc = qPow(msOriginalPropertyValue * 100, 0.5);
329 qreal newValue = inc + getCurrentPoint().
x();
336 newValue = qPow(newValue, 2) / 100;
337 if (mAdjustmentStep > 0)
339 int tempValue = (int)(newValue / mAdjustmentStep);
340 newValue = tempValue * mAdjustmentStep;
343 switch (mQuickSizingProperties.
value(modifiers))
346 mEditor->tools()->setWidth(qBound(1., newValue, 200.));
349 mEditor->tools()->setFeather(qBound(2., newValue, 200.));
352 mEditor->tools()->setTolerance(qBound(0., newValue, 100.));
355 qDebug() <<
"Unhandled quick sizing property for tool" << typeName();
361 QPointF BaseTool::getCurrentPressPixel()
363 return strokeManager()->getCurrentPressPixel();
366 QPointF BaseTool::getCurrentPressPoint()
368 return mEditor->view()->mapScreenToCanvas(strokeManager()->getCurrentPressPixel());
371 QPointF BaseTool::getCurrentPixel()
373 return strokeManager()->getCurrentPixel();
376 QPointF BaseTool::getCurrentPoint()
378 return mEditor->view()->mapScreenToCanvas(getCurrentPixel());
381 QPointF BaseTool::getLastPixel()
383 return strokeManager()->getLastPixel();
386 QPointF BaseTool::getLastPoint()
388 return mEditor->view()->mapScreenToCanvas(getLastPixel());
391 QPointF BaseTool::getLastPressPixel()
393 return strokeManager()->getLastPressPixel();
396 QPointF BaseTool::getLastPressPoint()
398 return mEditor->view()->mapScreenToCanvas(getLastPressPixel());
401 void BaseTool::setWidth(
const qreal width)
403 properties.width = width;
406 void BaseTool::setFeather(
const qreal feather)
408 properties.feather = feather;
411 void BaseTool::setUseFeather(
const bool usingFeather)
413 properties.useFeather = usingFeather;
416 void BaseTool::setInvisibility(
const bool invisibility)
418 properties.invisibility = invisibility;
421 void BaseTool::setBezier(
const bool _bezier_state)
423 properties.bezier_state = _bezier_state;
426 void BaseTool::setPressure(
const bool pressure)
428 properties.pressure = pressure;
431 void BaseTool::setPreserveAlpha(
const bool preserveAlpha)
433 properties.preserveAlpha = preserveAlpha;
436 void BaseTool::setVectorMergeEnabled(
const bool vectorMergeEnabled)
438 properties.vectorMergeEnabled = vectorMergeEnabled;
441 void BaseTool::setAA(
const int useAA)
443 properties.useAA = useAA;
446 void BaseTool::setStabilizerLevel(
const int level)
448 properties.stabilizerLevel = level;
451 void BaseTool::setTolerance(
const int tolerance)
453 properties.tolerance = tolerance;
456 void BaseTool::setUseFillContour(
const bool useFillContour)
458 properties.useFillContour = useFillContour;
typedef KeyboardModifiers
void setStyle(Qt::PenStyle style)
void setCompositionMode(QPainter::CompositionMode mode)
void setRenderHint(QPainter::RenderHint hint, bool on)
void fill(const QColor &color)
QSizeF size() const const
void drawLine(const QLineF &line)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
QSize toSize() const const
void setBrush(const QBrush &brush)
QPointF center() const const
void setColor(const QColor &color)
const T value(const Key &key) const const
bool isNull() const const
void setRenderHints(QPainter::RenderHints hints, bool on)
QRectF adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const const
bool contains(const Key &key) const const
const QPen & pen() const const
void setDashOffset(qreal offset)