Commit fd68d6ed authored by Halla Rempt's avatar Halla Rempt
Browse files

Show brush outline in line tool (and other tools)

BUG: 300160
CCMAIL: salilkapur93@gmail.com
Patch by Salil Kapur (salilkapur93@gmail.com)
parent dee7f49d
......@@ -41,6 +41,7 @@ KisToolEllipse::KisToolEllipse(KoCanvasBase * canvas)
: KisToolEllipseBase(canvas, KisToolEllipseBase::PAINT, KisCursor::load("tool_ellipse_cursor.png", 6, 6))
{
setObjectName("tool_ellipse");
setSupportOutline(true);
}
KisToolEllipse::~KisToolEllipse()
......
......@@ -51,6 +51,8 @@ KisToolLine::KisToolLine(KoCanvasBase * canvas)
setObjectName("tool_line");
m_painter = 0;
currentImage() = 0;
setSupportOutline(true);
}
KisToolLine::~KisToolLine()
......@@ -89,11 +91,30 @@ void KisToolLine::paint(QPainter& gc, const KoViewConverter &converter)
{
Q_UNUSED(converter);
if (mode() == KisTool::PAINT_MODE) {
paintLine(gc, QRect());
if(mode() == KisTool::PAINT_MODE) {
paintLine(gc,QRect());
}
KisToolPaint::paint(gc,converter);
}
void KisToolLine::keyPressEvent(QKeyEvent *event)
{
if (mode() != KisTool::PAINT_MODE) {
KisToolPaint::keyPressEvent(event);
return;
}
event->accept();
}
void KisToolLine::keyReleaseEvent(QKeyEvent *event)
{
if (mode() != KisToolPaint::PAINT_MODE) {
KisToolPaint::keyReleaseEvent(event);
return;
}
event->accept();
}
void KisToolLine::mousePressEvent(KoPointerEvent *event)
{
......@@ -149,6 +170,7 @@ void KisToolLine::mouseMoveEvent(KoPointerEvent *event)
m_maxPressure = qMax(m_maxPressure, float(pressureToCurve(event->pressure())));
updatePreview();
KisToolPaint::requestUpdateOutline(event->point);
}
else {
KisToolPaint::mouseMoveEvent(event);
......
......@@ -52,7 +52,8 @@ public:
virtual void mousePressEvent(KoPointerEvent *event);
virtual void mouseMoveEvent(KoPointerEvent *event);
virtual void mouseReleaseEvent(KoPointerEvent *event);
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void paint(QPainter& gc, const KoViewConverter &converter);
virtual QString quickHelp() const;
......
......@@ -43,6 +43,7 @@
KisToolRectangle::KisToolRectangle(KoCanvasBase * canvas)
: KisToolRectangleBase(canvas, KisToolRectangleBase::PAINT, KisCursor::load("tool_rectangle_cursor.png", 6, 6))
{
setSupportOutline(true);
setObjectName("tool_rectangle");
}
......
......@@ -42,6 +42,7 @@ KisToolPolygon::KisToolPolygon(KoCanvasBase *canvas)
: KisToolPolylineBase(canvas, KisToolPolylineBase::PAINT, KisCursor::load("tool_polygon_cursor.png", 6, 6))
{
setObjectName("tool_polygon");
setSupportOutline(true);
}
KisToolPolygon::~KisToolPolygon()
......
......@@ -41,6 +41,7 @@ KisToolPolyline::KisToolPolyline(KoCanvasBase * canvas)
: KisToolPolylineBase(canvas, KisToolPolylineBase::PAINT, KisCursor::load("tool_polyline_cursor.png", 6, 6))
{
setObjectName("tool_polyline");
setSupportOutline(true);
}
KisToolPolyline::~KisToolPolyline()
......
......@@ -44,6 +44,7 @@ void KisToolEllipseBase::paint(QPainter& gc, const KoViewConverter &converter)
Q_ASSERT(currentImage());
if (mode() == KisTool::PAINT_MODE)
paintEllipse(gc, QRect());
KisToolPaint::paint(gc,converter);
}
void KisToolEllipseBase::deactivate()
......@@ -113,6 +114,7 @@ void KisToolEllipseBase::mouseMoveEvent(KoPointerEvent *event)
m_dragCenter = QPointF((m_dragStart.x() + m_dragEnd.x()) / 2,
(m_dragStart.y() + m_dragEnd.y()) / 2);
KisToolPaint::requestUpdateOutline(event->point);
}
else {
KisToolShape::mouseMoveEvent(event);
......
......@@ -83,23 +83,6 @@ KisToolFreehand::KisToolFreehand(KoCanvasBase * canvas, const QCursor & cursor,
m_prevyTilt = 0.0;
#endif
KActionCollection *collection = this->canvas()->canvasController()->actionCollection();
if (!collection->action("increase_brush_size")) {
KAction *increaseBrushSize = new KAction(i18n("Increase Brush Size"), collection);
increaseBrushSize->setShortcut(Qt::Key_BracketRight);
collection->addAction("increase_brush_size", increaseBrushSize);
}
if (!collection->action("decrease_brush_size")) {
KAction *decreaseBrushSize = new KAction(i18n("Decrease Brush Size"), collection);
decreaseBrushSize->setShortcut(Qt::Key_BracketLeft);
collection->addAction("decrease_brush_size", decreaseBrushSize);
}
addAction("increase_brush_size", dynamic_cast<KAction*>(collection->action("increase_brush_size")));
addAction("decrease_brush_size", dynamic_cast<KAction*>(collection->action("decrease_brush_size")));
m_outlineTimer.setSingleShot(true);
connect(&m_outlineTimer, SIGNAL(timeout()), this, SLOT(hideOutline()));
......@@ -139,8 +122,6 @@ int KisToolFreehand::flags() const
void KisToolFreehand::activate(ToolActivation activation, const QSet<KoShape*> &shapes)
{
KisToolPaint::activate(activation, shapes);
connect(actions().value("increase_brush_size"), SIGNAL(triggered()), SLOT(increaseBrushSize()), Qt::UniqueConnection);
connect(actions().value("decrease_brush_size"), SIGNAL(triggered()), SLOT(decreaseBrushSize()), Qt::UniqueConnection);
}
void KisToolFreehand::deactivate()
......@@ -149,8 +130,6 @@ void KisToolFreehand::deactivate()
endStroke();
setMode(KisTool::HOVER_MODE);
}
disconnect(actions().value("increase_brush_size"), 0, this, 0);
disconnect(actions().value("decrease_brush_size"), 0, this, 0);
KisToolPaint::deactivate();
}
......@@ -240,7 +219,7 @@ void KisToolFreehand::mousePressEvent(KoPointerEvent *e)
}
else {
KisToolPaint::mousePressEvent(e);
requestUpdateOutline(e->point);
//requestUpdateOutline(e->point);
}
}
......@@ -266,7 +245,14 @@ void KisToolFreehand::mouseMoveEvent(KoPointerEvent *e)
}
if (mode() != KisTool::PAINT_MODE) {
KisToolPaint::mouseMoveEvent(e);
if(mode() == KisTool::SECONDARY_PAINT_MODE) {
KisToolPaint::pickColor(e->point, e->modifiers() & Qt::AltModifier,
m_toForegroundColor);
e->accept();
}
else {
KisTool::mouseMoveEvent(e);
}
return;
}
......@@ -444,55 +430,6 @@ qreal KisToolFreehand::calculatePerspective(const QPointF &documentPoint)
return perspective;
}
QPainterPath KisToolFreehand::getOutlinePath(const QPointF &documentPos,
KisPaintOpSettings::OutlineMode outlineMode)
{
qreal scale = 1.0;
qreal rotation = 0;
const KisPaintOp *paintOp = m_helper->currentPaintOp();
if (paintOp){
scale = paintOp->currentScale();
rotation = paintOp->currentRotation();
}
if (mode() == KisTool::HOVER_MODE) {
rotation += static_cast<KisCanvas2*>(canvas())->rotationAngle() * M_PI / 180.0;
}
QPointF imagePos = currentImage()->documentToPixel(documentPos);
QPainterPath path = currentPaintOpPreset()->settings()->
brushOutline(imagePos, outlineMode, scale, rotation);
return path;
}
void KisToolFreehand::increaseBrushSize()
{
int paintopSize = currentPaintOpPreset()->settings()->paintOpSize().width();
int increment = 1;
if (paintopSize > 100) {
increment = 30;
} else if (paintopSize > 10){
increment = 10;
}
currentPaintOpPreset()->settings()->changePaintOpSize(increment, 0);
showOutlineTemporary();
}
void KisToolFreehand::decreaseBrushSize()
{
int paintopSize = currentPaintOpPreset()->settings()->paintOpSize().width();
int decrement = -1;
if (paintopSize > 100) {
decrement = -30;
} else if (paintopSize > 20){
decrement = -10;
}
currentPaintOpPreset()->settings()->changePaintOpSize(decrement, 0);
showOutlineTemporary();
}
void KisToolFreehand::requestUpdateOutline(const QPointF &outlineDocPoint)
{
KisConfig cfg;
......
......@@ -104,14 +104,9 @@ private:
void showOutlineTemporary();
QPainterPath getOutlinePath(const QPointF &documentPos,
KisPaintOpSettings::OutlineMode outlineMode);
private slots:
void increaseBrushSize();
void decreaseBrushSize();
void hideOutline();
protected:
......@@ -132,10 +127,7 @@ private:
QString m_brushModelName;
#endif
QPointF m_outlineDocPoint;
QTimer m_outlineTimer;
QRectF m_oldOutlineRect;
QPainterPath m_currentOutline;
bool m_explicitShowOutline;
KisPaintingInformationBuilder *m_infoBuilder;
......
......@@ -69,6 +69,7 @@
#include <recorder/kis_recorded_paint_action.h>
#include "kis_tool_utils.h"
#include <kis_paintop.h>
#include <kis_paintop_preset.h>
const int STEP = 25;
......@@ -116,6 +117,20 @@ KisToolPaint::KisToolPaint(KoCanvasBase * canvas, const QCursor & cursor)
addAction("decrease_opacity", dynamic_cast<KAction*>(collection->action("decrease_opacity")));
addAction("increase_opacity", dynamic_cast<KAction*>(collection->action("increase_opacity")));
if (!collection->action("increase_brush_size")) {
KAction *increaseBrushSize = new KAction(i18n("Increase Brush Size"), collection);
increaseBrushSize->setShortcut(Qt::Key_BracketRight);
collection->addAction("increase_brush_size", increaseBrushSize);
}
if (!collection->action("decrease_brush_size")) {
KAction *decreaseBrushSize = new KAction(i18n("Decrease Brush Size"), collection);
decreaseBrushSize->setShortcut(Qt::Key_BracketLeft);
collection->addAction("decrease_brush_size", decreaseBrushSize);
}
addAction("increase_brush_size", dynamic_cast<KAction*>(collection->action("increase_brush_size")));
addAction("decrease_brush_size", dynamic_cast<KAction*>(collection->action("decrease_brush_size")));
KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas);
connect(this, SIGNAL(sigFavoritePaletteCalled(const QPoint&)), kiscanvas, SIGNAL(favoritePaletteCalled(const QPoint&)));
......@@ -157,6 +172,8 @@ void KisToolPaint::activate(ToolActivation toolActivation, const QSet<KoShape*>
connect(actions().value("make_brush_color_darker"), SIGNAL(triggered()), SLOT(makeColorDarker()), Qt::UniqueConnection);
connect(actions().value("increase_opacity"), SIGNAL(triggered()), SLOT(increaseOpacity()), Qt::UniqueConnection);
connect(actions().value("decrease_opacity"), SIGNAL(triggered()), SLOT(decreaseOpacity()), Qt::UniqueConnection);
connect(actions().value("increase_brush_size"), SIGNAL(triggered()), SLOT(increaseBrushSize()), Qt::UniqueConnection);
connect(actions().value("decrease_brush_size"), SIGNAL(triggered()), SLOT(decreaseBrushSize()), Qt::UniqueConnection);
}
void KisToolPaint::deactivate()
......@@ -165,12 +182,16 @@ void KisToolPaint::deactivate()
disconnect(actions().value("make_brush_color_darker"), 0, this, 0);
disconnect(actions().value("increase_opacity"), 0, this, 0);
disconnect(actions().value("decrease_opacity"), 0, this, 0);
disconnect(actions().value("increase_brush_size"), 0, this, 0);
disconnect(actions().value("decrease_brush_size"), 0, this, 0);
KisTool::deactivate();
}
void KisToolPaint::paint(QPainter&, const KoViewConverter &)
void KisToolPaint::paint(QPainter &gc, const KoViewConverter &converter)
{
Q_UNUSED(converter);
paintToolOutline(&gc,pixelToView(m_currentOutline));
}
void KisToolPaint::setMode(ToolMode mode)
......@@ -201,6 +222,7 @@ void KisToolPaint::mousePressEvent(KoPointerEvent *event)
}
else {
KisTool::mousePressEvent(event);
requestUpdateOutline(event->point);
}
}
......@@ -213,6 +235,7 @@ void KisToolPaint::mouseMoveEvent(KoPointerEvent *event)
}
else {
KisTool::mouseMoveEvent(event);
requestUpdateOutline(event->point);
}
}
......@@ -224,6 +247,7 @@ void KisToolPaint::mouseReleaseEvent(KoPointerEvent *event)
event->accept();
} else {
KisTool::mouseReleaseEvent(event);
requestUpdateOutline(event->point);
}
}
......@@ -486,5 +510,88 @@ void KisToolPaint::decreaseOpacity()
stepAlpha(-0.1f);
}
void KisToolPaint::increaseBrushSize()
{
int paintopSize = currentPaintOpPreset()->settings()->paintOpSize().width();
int increment = 1;
if (paintopSize > 100) {
increment = 30;
} else if (paintopSize > 10){
increment = 10;
}
currentPaintOpPreset()->settings()->changePaintOpSize(increment, 0);
requestUpdateOutline(m_outlineDocPoint);
}
void KisToolPaint::decreaseBrushSize()
{
int paintopSize = currentPaintOpPreset()->settings()->paintOpSize().width();
int decrement = -1;
if (paintopSize > 100) {
decrement = -30;
} else if (paintopSize > 20){
decrement = -10;
}
currentPaintOpPreset()->settings()->changePaintOpSize(decrement, 0);
requestUpdateOutline(m_outlineDocPoint);
}
void KisToolPaint::requestUpdateOutline(const QPointF &outlineDocPoint)
{
KisConfig cfg;
KisPaintOpSettings::OutlineMode outlineMode;
outlineMode = KisPaintOpSettings::CursorIsNotOutline;
if (mode() == KisTool::GESTURE_MODE ||
(cfg.cursorStyle() == CURSOR_STYLE_OUTLINE &&
((mode() == HOVER_MODE && !specialHoverModeActive()) ||
(mode() == PAINT_MODE && cfg.showOutlineWhilePainting())))) {
outlineMode = KisPaintOpSettings::CursorIsOutline;
}
m_outlineDocPoint = outlineDocPoint;
m_currentOutline = getOutlinePath(m_outlineDocPoint, outlineMode);
QRectF outlinePixelRect = m_currentOutline.boundingRect();
QRectF outlineDocRect = currentImage()->pixelToDocument(outlinePixelRect);
// This adjusted call is needed as we paint with a 3 pixel wide brush and the pen is outside the bounds of the path
// Pen uses view coordinates so we have to zoom the document value to match 2 pixel in view coordiates
// See BUG 275829
qreal zoomX;
qreal zoomY;
canvas()->viewConverter()->zoom(&zoomX, &zoomY);
qreal xoffset = 2.0/zoomX;
qreal yoffset = 2.0/zoomY;
QRectF newOutlineRect = outlineDocRect.adjusted(-xoffset,-yoffset,xoffset,yoffset);
if (!m_oldOutlineRect.isEmpty()) {
canvas()->updateCanvas(m_oldOutlineRect);
}
if (!newOutlineRect.isEmpty()) {
canvas()->updateCanvas(newOutlineRect);
}
m_oldOutlineRect = newOutlineRect;
}
QPainterPath KisToolPaint::getOutlinePath(const QPointF &documentPos,
KisPaintOpSettings::OutlineMode outlineMode)
{
qreal scale = 1.0;
qreal rotation = 0;
if (mode() == KisTool::HOVER_MODE) {
rotation += static_cast<KisCanvas2*>(canvas())->rotationAngle() * M_PI / 180.0;
}
QPointF imagePos = currentImage()->documentToPixel(documentPos);
QPainterPath path = currentPaintOpPreset()->settings()->
brushOutline(imagePos, outlineMode, scale, rotation);
return path;
}
#include "kis_tool_paint.moc"
......@@ -37,6 +37,7 @@
#include <kis_types.h>
#include <kis_image.h>
#include <kis_paintop_settings.h>
#include <kis_pattern.h>
......@@ -83,7 +84,7 @@ protected:
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void requestUpdateOutline(const QPointF &outlineDocPoint);
/** If the paint tool support outline like brushes, set to true.
* If not (e.g. gradient tool), set to false. Default is false.
......@@ -91,11 +92,14 @@ protected:
void setSupportOutline(bool supportOutline) {
m_supportOutline = supportOutline;
}
QPainterPath getOutlinePath(const QPointF &documentPos,
KisPaintOpSettings::OutlineMode outlineMode);
protected:
bool specialHoverModeActive() const;
void pickColor(const QPointF &documentPixel, bool fromCurrentNode,
bool toForegroundColor);
/// Add the tool-specific layout to the default option widget layout.
void addOptionWidgetLayout(QLayout *layout);
......@@ -144,6 +148,9 @@ private slots:
void increaseOpacity();
void decreaseOpacity();
void increaseBrushSize();
void decreaseBrushSize();
protected slots:
virtual void resetCursorStyle();
virtual void updateTabletPressureSamples();
......@@ -153,10 +160,12 @@ protected:
quint8 m_opacity;
bool m_paintOutline;
QVector<qreal> m_pressureSamples;
QPointF m_outlineDocPoint;
QPainterPath m_currentOutline;
QRectF m_oldOutlineRect;
bool m_toForegroundColor;
private:
void pickColor(const QPointF &documentPixel, bool fromCurrentNode,
bool toForegroundColor);
void transformColor(int step);
void stepAlpha(float step);
......@@ -171,7 +180,7 @@ private:
/**
* Used as a switch for pickColor
*/
bool m_toForegroundColor;
// used to skip some of the tablet events and don't update the colour that often
QTimer m_colorPickerDelayTimer;
......
......@@ -103,6 +103,7 @@ void KisToolPolylineBase::mouseMoveEvent(KoPointerEvent *event)
(basePoint - pixelToView(m_dragEnd)).manhattanLength() < SNAPPING_THRESHOLD;
updateCanvasViewRect(QRectF(basePoint, 2 * QSize(SNAPPING_HANDLE_RADIUS + PREVIEW_LINE_WIDTH, SNAPPING_HANDLE_RADIUS + PREVIEW_LINE_WIDTH)).translated(-SNAPPING_HANDLE_RADIUS + PREVIEW_LINE_WIDTH,-SNAPPING_HANDLE_RADIUS + PREVIEW_LINE_WIDTH));
KisToolPaint::requestUpdateOutline(event->point);
}
KisToolShape::mouseMoveEvent(event);
......@@ -176,6 +177,7 @@ void KisToolPolylineBase::paint(QPainter& gc, const KoViewConverter &converter)
}
paintToolOutline(&gc, path);
KisToolPaint::paint(gc,converter);
}
void KisToolPolylineBase::updateArea()
......
......@@ -34,8 +34,10 @@ void KisToolRectangleBase::paint(QPainter& gc, const KoViewConverter &converter)
Q_UNUSED(converter);
Q_ASSERT(currentImage());
if (mode() == KisTool::PAINT_MODE)
paintRectangle(gc, QRect());
if(mode() == KisTool::PAINT_MODE) {
paintRectangle(gc,QRect());
}
KisToolPaint::paint(gc,converter);
}
void KisToolRectangleBase::deactivate()
......@@ -102,6 +104,8 @@ void KisToolRectangleBase::mouseMoveEvent(KoPointerEvent *event)
m_dragCenter = QPointF((m_dragStart.x() + m_dragEnd.x()) / 2,
(m_dragStart.y() + m_dragEnd.y()) / 2);
KisToolPaint::requestUpdateOutline(event->point);
}
else {
KisToolShape::mouseMoveEvent(event);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment