Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit e97ac5e3 authored by Adrian Page's avatar Adrian Page

- Use KisPainter for the ellipse selection tool.

- Fix the ellipse and rectangle selection tools feedback painting.
- Update and document the KisPainter paint rectangle and ellipse methods.
- Remove KisRect as it's not needed.

svn path=/trunk/koffice/; revision=659144
parent bde6a08f
......@@ -64,7 +64,6 @@ set(kritaimage_LIB_SRCS
kis_pattern.cc
kis_random_accessor.cpp
kis_random_sub_accessor.cpp
kis_rect.cc
kis_resource.cc
kis_rotate_visitor.cc
kis_selected_transaction.cc
......@@ -125,7 +124,7 @@ install(TARGETS kritaimage DESTINATION ${LIB_INSTALL_DIR})
#kis_imagepipe_brush.h kis_iterator.h kis_iterators_pixel.h
#kis_iteratorpixeltrait.h kis_layer.h kis_meta_registry.h
#kis_nameserver.h kis_paint_device.h kis_painter.h kis_paintop.h
#kis_paintop_registry.h kis_palette.h kis_pattern.h kis_rect.h
#kis_paintop_registry.h kis_palette.h kis_pattern.h
#kis_resource.h kis_selection.h kis_transaction.h kis_types.h
#kis_vec.h kis_filter_config_widget.h kis_filter_configuration.h
#kis_exif_info.h kis_exif_value.h kis_perspective_grid.h
......
......@@ -48,7 +48,6 @@
#include "kis_paint_device.h"
#include "kis_painter.h"
#include "kis_pattern.h"
#include "kis_rect.h"
#include "KoColorSpace.h"
#include "kis_types.h"
#include "kis_vec.h"
......
......@@ -45,7 +45,6 @@
#include "kis_paint_device.h"
#include "kis_painter.h"
#include "kis_pattern.h"
#include "kis_rect.h"
#include "KoColorSpace.h"
#include "kis_transaction.h"
#include "kis_types.h"
......
......@@ -44,7 +44,6 @@
#include "kis_layer.h"
#include "kis_paint_device.h"
#include "kis_pattern.h"
#include "kis_rect.h"
#include "KoColorSpace.h"
#include "kis_types.h"
#include "kis_vec.h"
......
......@@ -42,7 +42,6 @@
#include "kis_paint_device.h"
#include "kis_painter.h"
#include "kis_pattern.h"
#include "kis_rect.h"
#include "KoColorSpace.h"
#include "kis_transaction.h"
#include "kis_types.h"
......@@ -661,13 +660,12 @@ double KisPainter::paintBezierCurve(const QPointF &pos1,
return newDistance;
}
void KisPainter::paintRect (const QPointF &startPoint,
const QPointF &endPoint,
const double /*pressure*/,
const double /*xTilt*/,
const double /*yTilt*/)
void KisPainter::paintRect(const QRectF &rect,
const double /*pressure*/,
const double /*xTilt*/,
const double /*yTilt*/)
{
QRectF normalizedRect = KisRect (startPoint.x(),startPoint.y(), endPoint.x(),endPoint.y()).normalized ();
QRectF normalizedRect = rect.normalized();
vQPointF points;
......@@ -679,13 +677,23 @@ void KisPainter::paintRect (const QPointF &startPoint,
paintPolygon(points);
}
void KisPainter::paintEllipse (const QPointF &startPoint,
const QPointF &endPoint,
const double /*pressure*/,
const double /*xTilt*/,
const double /*yTilt*/)
void KisPainter::paintRect(const double x,
const double y,
const double w,
const double h,
const double pressure,
const double xTilt,
const double yTilt)
{
KisRect r = KisRect(startPoint.x(),startPoint.y(), endPoint.x(),endPoint.y()).normalized();
paintRect(QRectF(x, y, w, h), pressure, xTilt, yTilt);
}
void KisPainter::paintEllipse(const QRectF &rect,
const double /*pressure*/,
const double /*xTilt*/,
const double /*yTilt*/)
{
QRectF r = rect.normalized();
// See http://www.whizkidtech.redprince.net/bezier/circle/ for explanation.
// kappa = (4/3*(sqrt(2)-1))
......@@ -724,6 +732,17 @@ void KisPainter::paintEllipse (const QPointF &startPoint,
paintPolygon(points);
}
void KisPainter::paintEllipse(const double x,
const double y,
const double w,
const double h,
const double pressure,
const double xTilt,
const double yTilt)
{
paintEllipse(QRectF(x, y, w, h), pressure, xTilt, yTilt);
}
void KisPainter::paintAt(const QPointF & pos,
const double pressure,
const double xTilt,
......
......@@ -412,23 +412,52 @@ public:
/**
* Paint the rectangle with given begin and end points
* Paint a rectangle.
* @param rect the rectangle to paint.
*/
void paintRect(const QPointF &startPoint,
const QPointF &endPoint,
const double pressure,
const double xTilt,
const double yTilt);
void paintRect(const QRectF &rect,
const double pressure,
const double xTilt,
const double yTilt);
/**
* Paint a rectangle.
* @param x x coordinate of the top-left corner
* @param y y coordinate of the top-left corner
* @param w the rectangle width
* @param h the rectangle height
*/
void paintRect(const double x,
const double y,
const double w,
const double h,
const double pressure,
const double xTilt,
const double yTilt);
/**
* Paint the ellipse with given begin and end points
* Paint the ellipse that fills the given rectangle.
* @param rect the rectangle containing the ellipse to paint.
*/
void paintEllipse(const QPointF &startPoint,
const QPointF &endPoint,
void paintEllipse(const QRectF &rect,
const double pressure,
const double xTilt,
const double yTilt);
/**
* Paint the ellipse that fills the given rectangle.
* @param x x coordinate of the top-left corner
* @param y y coordinate of the top-left corner
* @param w the rectangle width
* @param h the rectangle height
*/
void paintEllipse(const double x,
const double y,
const double w,
const double h,
const double pressure,
const double /*xTilt*/,
const double /*yTilt*/);
const double xTilt,
const double yTilt);
/**
* Paint the polygon with the points given in points. It automatically closes the polygon
......
/*
* Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <cmath>
#include <cfloat>
#include "kis_rect.h"
QRect KisRect::qRect() const
{
return QRect(static_cast<int>(floor(left())), static_cast<int>(floor(top())), static_cast<int>(ceil(right()) - floor(left())), static_cast<int>(ceil(bottom()) - floor(top())));
}
/*
* Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_RECT_H_
#define KIS_RECT_H_
#include <QRect>
/**
* A double-based rect class that can return a QRect that encloses the KisRect.
*/
class KisRect : public QRectF
{
typedef QRectF super;
public:
KisRect() {}
KisRect(double x, double y, double w, double h) : super(x, y, w, h) {}
//KisRect(const QPointF& topLeft, const QPointF& bottomRight) : super(topLeft, bottomRight) {}
KisRect(const QRect& qr) : super(qr.x(), qr.y(), qr.width(), qr.height()) {}
KisRect(const QRectF& r) : super(r) {}
/**
* Return the QRect that encloses this KisRect.
*/
QRect qRect() const;
private:
// Use qRect() which uses ceil() and floor() to return a rectangle
// 'enclosing' the rectangle, whereas toQRect rounds the points.
QRect toQRect() const;
};
#endif // KIS_RECT_H_
......@@ -159,10 +159,10 @@ void KisToolEllipse::mouseReleaseEvent(KoPointerEvent *event)
m_painter->setPattern(m_currentPattern);
m_painter->setOpacity(m_opacity);
m_painter->setCompositeOp(m_compositeOp);
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_currentPaintOp, m_currentPaintOpSettings, m_painter);
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_currentPaintOp, m_currentPaintOpSettings, m_painter);
m_painter->setPaintOp(op); // Painter takes ownership
m_painter->paintEllipse(m_dragStart, m_dragEnd-m_dragStart, PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt());
m_painter->paintEllipse(QRectF(m_dragStart, m_dragEnd), PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt());
QRegion bound = m_painter->dirtyRegion();
device->setDirty( bound );
notifyModified();
......
......@@ -159,7 +159,7 @@ void KisToolRectangle::mouseReleaseEvent(KoPointerEvent *event)
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_currentPaintOp, m_currentPaintOpSettings, m_painter);
m_painter->setPaintOp(op);
m_painter->paintRect(m_dragStart, m_dragEnd-m_dragStart, PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt());
m_painter->paintRect(QRectF(m_dragStart, m_dragEnd), PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt());
QRegion bound = m_painter->dirtyRegion();
device->setDirty( bound );
notifyModified();
......
......@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_tool_select_elliptical.h"
#include <QApplication>
#include <QPainter>
#include <QPen>
......@@ -27,13 +29,13 @@
#include <kdebug.h>
#include <klocale.h>
#include "kis_autobrush_resource.h"
#include "KoPointerEvent.h"
#include "kis_cursor.h"
#include "kis_image.h"
#include "kis_painter.h"
#include "kis_tool_select_elliptical.h"
#include "kis_paintop_registry.h"
#include "kis_layer.h"
#include "KoPointerEvent.h"
#include "kis_selection.h"
#include "kis_selection_options.h"
#include "kis_selected_transaction.h"
......@@ -63,24 +65,16 @@ void KisToolSelectElliptical::activate()
m_optWidget->slotActivated();
}
void KisToolSelectElliptical::paint(QPainter& gc, KoViewConverter &converter)
{
double sx, sy;
converter.zoom(&sx, &sy);
Q_UNUSED(converter);
gc.scale( sx/m_currentImage->xRes(), sy/m_currentImage->yRes() );
if (m_selecting) {
QPen old = gc.pen();
QPen pen(Qt::DotLine);
QPoint start;
QPoint end;
gc.setPen(pen);
start = QPoint(static_cast<int>(m_startPos.x()), static_cast<int>(m_startPos.y()));
end = QPoint(static_cast<int>(m_endPos.x()), static_cast<int>(m_endPos.y()));
gc.drawEllipse(QRect(start, end));
gc.setPen(old);
gc.save();
gc.setPen(Qt::DotLine);
gc.drawEllipse(pixelToView(QRectF(m_startPos, m_endPos)));
gc.restore();
}
}
......@@ -114,10 +108,7 @@ void KisToolSelectElliptical::mousePressEvent(KoPointerEvent *e)
void KisToolSelectElliptical::mouseMoveEvent(KoPointerEvent *e)
{
if (m_canvas && m_selecting) {
QRectF bound;
bound.setTopLeft(m_startPos);
bound.setBottomRight(m_endPos);
m_canvas->updateCanvas(convertToPt(bound.normalized()));
QRectF updateRect(m_startPos, m_endPos);
// move (alt) or resize ellipse
if (e->modifiers() & Qt::AltModifier) {
......@@ -143,9 +134,11 @@ void KisToolSelectElliptical::mouseMoveEvent(KoPointerEvent *e)
m_endPos = m_startPos + diag;
}
}
bound.setTopLeft(m_startPos);
bound.setBottomRight(m_endPos);
m_canvas->updateCanvas(convertToPt(bound.normalized()));
updateRect |= QRectF(m_startPos, m_endPos);
updateRect = updateRect.normalized();
updateRect.adjust(-1, -1, 1, 1);
m_canvas->updateCanvas(convertToPt(updateRect));
m_centerPos = QPointF((m_startPos.x() + m_endPos.x()) / 2,
(m_startPos.y() + m_endPos.y()) / 2);
......@@ -164,56 +157,47 @@ void KisToolSelectElliptical::mouseReleaseEvent(KoPointerEvent *e)
if (!m_currentImage)
return;
if (m_endPos.y() < 0)
m_endPos.setY(0);
if (m_endPos.y() > m_currentImage->height())
m_endPos.setY(m_currentImage->height());
if (m_endPos.x() < 0)
m_endPos.setX(0);
if (m_endPos.x() > m_currentImage->width())
m_endPos.setX(m_currentImage->width());
if (m_currentImage && m_currentImage->activeDevice()) {
KisPaintDeviceSP dev = m_currentImage->activeDevice();
KisSelectionSP selection = dev->selection();
KisSelectedTransaction *t = new KisSelectedTransaction(i18n("Elliptical Selection"), dev);
bool hasSelection = dev->hasSelection();
if(! hasSelection)
if (!hasSelection)
{
dev->selection()->clear();
if(m_selectAction==SELECTION_SUBTRACT)
dev->selection()->invert();
selection->clear();
if(m_selectAction == SELECTION_SUBTRACT)
selection->invert();
}
QRect rc( m_startPos.toPoint(), m_endPos.toPoint());
rc = rc.normalized();
KisSelectionSP tmpSel = KisSelectionSP(new KisSelection(dev));
KisAutobrushCircleShape shape(rc.width(),rc.height(), 1, 1);
quint8 value;
for (int y = 0; y <= rc.height(); y++)
for (int x = 0; x <= rc.width(); x++)
{
value = MAX_SELECTED - shape.valueAt(x,y);
tmpSel->setSelected( x+rc.x(), y+rc.y(), value);
}
KisPainter painter(selection);
painter.setPaintColor(KoColor(Qt::black, selection->colorSpace()));
painter.setFillStyle(KisPainter::FillStyleForegroundColor);
painter.setStrokeStyle(KisPainter::StrokeStyleNone);
painter.setAntiAliasPolygonFill(m_optWidget->antiAliasSelection());
painter.setOpacity(OPACITY_OPAQUE);
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("paintbrush", 0, &painter);
painter.setPaintOp(op); // And now the painter owns the op and will destroy it.
switch(m_selectAction)
{
case SELECTION_ADD:
dev->addSelection(tmpSel);
painter.setCompositeOp(selection->colorSpace()->compositeOp(COMPOSITE_OVER));
break;
case SELECTION_SUBTRACT:
dev->subtractSelection(tmpSel);
painter.setCompositeOp(selection->colorSpace()->compositeOp(COMPOSITE_SUBTRACT));
break;
default:
break;
}
painter.paintEllipse(QRectF(m_startPos, m_endPos), PRESSURE_DEFAULT/*e->pressure()*/,
e->xTilt(), e->yTilt());
if(hasSelection) {
dev->setDirty(rc);
dev->emitSelectionChanged(rc);
QRect rect(painter.dirtyRegion().boundingRect());
dev->emitSelectionChanged(rect);
} else {
dev->setDirty();
dev->emitSelectionChanged();
}
......@@ -238,7 +222,6 @@ QWidget* KisToolSelectElliptical::createOptionWidget()
m_optWidget = new KisSelectionOptions(canvas);
Q_CHECK_PTR(m_optWidget);
m_optWidget->setWindowTitle(i18n("Elliptical Selection"));
m_optWidget->disableAntiAliasSelectionOption();
connect (m_optWidget, SIGNAL(actionChanged(int)), this, SLOT(slotSetAction(int)));
......
......@@ -113,10 +113,7 @@ void KisToolSelectRectangular::mousePressEvent(KoPointerEvent *e)
void KisToolSelectRectangular::mouseMoveEvent(KoPointerEvent *e)
{
if (m_canvas && m_selecting) {
QRectF bound;
bound.setTopLeft(m_startPos);
bound.setBottomRight(m_endPos);
m_canvas->updateCanvas(convertToPt(bound.normalized()));
QRectF updateRect(m_startPos, m_endPos);
// move (alt) or resize rectangle
if (e->modifiers() & Qt::AltModifier) {
......@@ -142,9 +139,11 @@ void KisToolSelectRectangular::mouseMoveEvent(KoPointerEvent *e)
m_endPos = m_startPos + diag;
}
}
bound.setTopLeft(m_startPos);
bound.setBottomRight(m_endPos);
m_canvas->updateCanvas(convertToPt(bound.normalized()));
updateRect |= QRectF(m_startPos, m_endPos);
updateRect = updateRect.normalized();
updateRect.adjust(-1, -1, 1, 1);
m_canvas->updateCanvas(convertToPt(updateRect));
m_centerPos = QPointF((m_startPos.x() + m_endPos.x()) / 2,
(m_startPos.y() + m_endPos.y()) / 2);
......
......@@ -34,7 +34,6 @@ class KisCanvas;
class KisDoc;
class KisPainter;
class KisView;
class KisRect;
class KisToolPolyline : public KisToolPaint {
......
......@@ -29,7 +29,6 @@ class KisCanvas;
class KisDoc;
class KisPainter;
class KisView;
class KisRect;
class WdgToolStar : public QWidget, public Ui::WdgToolStar
{
......
......@@ -189,9 +189,9 @@ void Painter::paintBezierCurve(double x1, double y1, double p1, double cx1, doub
m_painter->paintBezierCurve( QPointF(x1,y1), p1, 0.0, 0.0, QPointF(cx1,cy1), QPointF(cx2,cy2), QPointF(x2,y2), p2, 0.0, 0.0);
}
void Painter::paintEllipse(double x1, double y1, double x2, double y2, double pressure)
void Painter::paintEllipse(double x, double y, double w, double h, double pressure)
{
m_painter->paintEllipse( QPointF(x1,y1), QPointF(x2,y2), pressure, 0.0, 0.0 );
m_painter->paintEllipse( x, y, w, h, pressure, 0.0, 0.0 );
}
void Painter::paintPolygon(QVariantList pointsX, QVariantList pointsY)
......@@ -205,7 +205,7 @@ void Painter::paintPolygon(QVariantList pointsX, QVariantList pointsY)
void Painter::paintRect(double x, double y, double width, double height, double pressure)
{
m_painter->paintRect( QPointF(x, y), QPointF(width, height), pressure, 0, 0);
m_painter->paintRect( x, y, width, height, pressure, 0, 0);
}
void Painter::paintAt(double x, double y, double pressure)
......
......@@ -172,15 +172,15 @@ class Painter : public QObject
/**
* This function will paint an ellipse.
* It takes five arguments :
* - x1
* - y1
* - x2
* - y2
* - x
* - y
* - w
* - h
* - pressure
*
* Where (x1,y1) and (x2,y2) are the position of the two centers.
* Where x, y, w, and h define the rectangle containing the ellipse.
*/
void paintEllipse(double x1, double y1, double x2, double y2, double pressure);
void paintEllipse(double x, double y, double w, double h, double pressure);
/**
* This function will paint a polygon.
......
......@@ -37,7 +37,6 @@
#include "kis_double_widget.h"
#include "kis_canvas2.h"
#include "kis_image.h"
#include "kis_rect.h"
#include "kis_iterators_pixel.h"
#include "kis_resource_provider.h"
#include "kobirdeyepanel.h"
......
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