[kolourpaint] /: Add setting for anti-aliased drawing; lots of code cleanup

Martin Koller null at kde.org
Sun Feb 5 19:19:03 UTC 2017


Git commit 4ac4fa0bebc4b73b0774b8fe5b3d561ce9686375 by Martin Koller.
Committed on 05/02/2017 at 19:14.
Pushed by mkoller into branch 'master'.

Add setting for anti-aliased drawing; lots of code cleanup

The mentioned bug is about rounded rectangle and anti-aliased drawing.
This patch fixes both: rounded-rectangles are now drawn with the same
radius in x and y direction, which makes it look much better and
avoids the mentioned problem in the bug report.
An additional option in the settings menu allows now to define if
the tools draw with anti-aliasing (default) or not.
BUG: 270203
GUI: added a new option in the settings menu for anti-aliased drawing

M  +5    -0    environments/tools/kpToolEnvironment.cpp
M  +2    -0    environments/tools/kpToolEnvironment.h
M  +0    -81   imagelib/kpPainter.cpp
M  +0    -50   imagelib/kpPainter.h
M  +2    -1    kolourpaintui.rc
M  +1    -0    kpDefs.h
M  +4    -6    layers/selections/kpAbstractSelection.cpp
M  +5    -7    mainWindow/kpMainWindow.cpp
M  +1    -0    mainWindow/kpMainWindow.h
M  +20   -4    mainWindow/kpMainWindow_Settings.cpp
M  +5    -36   pixmapfx/kpPixmapFX.h
M  +8    -222  pixmapfx/kpPixmapFX_DrawShapes.cpp
M  +5    -6    tools/kpToolZoom.cpp
M  +26   -9    tools/polygonal/kpToolCurve.cpp
M  +6    -25   tools/polygonal/kpToolLine.cpp
M  +0    -1    tools/polygonal/kpToolLine.h
M  +37   -9    tools/polygonal/kpToolPolygon.cpp
M  +2    -7    tools/polygonal/kpToolPolygonalBase.cpp
M  +0    -8    tools/polygonal/kpToolPolygonalBase.h
M  +22   -13   tools/polygonal/kpToolPolyline.cpp
M  +1    -2    tools/polygonal/kpToolPolyline.h
M  +39   -4    tools/rectangular/kpToolEllipse.cpp
M  +5    -0    tools/rectangular/kpToolEllipse.h
M  +40   -5    tools/rectangular/kpToolRectangle.cpp
M  +5    -0    tools/rectangular/kpToolRectangle.h
M  +1    -5    tools/rectangular/kpToolRectangularBase.cpp
M  +1    -0    tools/rectangular/kpToolRectangularBase.h
M  +44   -5    tools/rectangular/kpToolRoundedRectangle.cpp
M  +5    -0    tools/rectangular/kpToolRoundedRectangle.h

https://commits.kde.org/kolourpaint/4ac4fa0bebc4b73b0774b8fe5b3d561ce9686375

diff --git a/environments/tools/kpToolEnvironment.cpp b/environments/tools/kpToolEnvironment.cpp
index c2255e5c..206ca452 100644
--- a/environments/tools/kpToolEnvironment.cpp
+++ b/environments/tools/kpToolEnvironment.cpp
@@ -39,6 +39,11 @@
 #include <QPoint>
 #include <QString>
 
+//--------------------------------------------------------------------------------
+
+bool kpToolEnvironment::drawAntiAliased = true;
+
+//--------------------------------------------------------------------------------
 
 struct kpToolEnvironmentPrivate
 {
diff --git a/environments/tools/kpToolEnvironment.h b/environments/tools/kpToolEnvironment.h
index cc5080c0..3455fae9 100644
--- a/environments/tools/kpToolEnvironment.h
+++ b/environments/tools/kpToolEnvironment.h
@@ -151,6 +151,8 @@ public:
 
     void fitToPage () const;
 
+    static bool drawAntiAliased;
+
 
 private:
     struct kpToolEnvironmentPrivate * const d;
diff --git a/imagelib/kpPainter.cpp b/imagelib/kpPainter.cpp
index a8dd33dc..79fd2744 100644
--- a/imagelib/kpPainter.cpp
+++ b/imagelib/kpPainter.cpp
@@ -178,53 +178,6 @@ QList <QPoint> kpPainter::interpolatePoints (const QPoint &startPoint,
 //---------------------------------------------------------------------
 
 // public static
-void kpPainter::drawLine (kpImage *image,
-        int x1, int y1, int x2, int y2,
-        const kpColor &color, int penWidth)
-{
-    kpPixmapFX::drawLine (image, x1, y1, x2, y2, color, penWidth);
-}
-
-//---------------------------------------------------------------------
-
-// public static
-void kpPainter::drawPolyline (kpImage *image,
-        const QPolygon &points,
-        const kpColor &color, int penWidth)
-{
-    kpPixmapFX::drawPolyline (image, points, color, penWidth);
-}
-
-//---------------------------------------------------------------------
-
-// public static
-void kpPainter::drawPolygon (kpImage *image,
-        const QPolygon &points,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor,
-        bool isFinal)
-{
-    kpPixmapFX::drawPolygon (image, points, fcolor, penWidth, bcolor, isFinal);
-}
-
-//---------------------------------------------------------------------
-
-
-// public static
-void kpPainter::drawCurve (kpImage *image,
-    const QPoint &startPoint,
-    const QPoint &controlPointP, const QPoint &controlPointQ,
-    const QPoint &endPoint,
-    const kpColor &color, int penWidth)
-{
-    kpPixmapFX::drawCurve (image,
-        startPoint, controlPointP, controlPointQ, endPoint, color, penWidth);
-}
-
-//---------------------------------------------------------------------
-
-
-// public static
 void kpPainter::fillRect (kpImage *image,
         int x, int y, int width, int height,
         const kpColor &color)
@@ -235,40 +188,6 @@ void kpPainter::fillRect (kpImage *image,
 //---------------------------------------------------------------------
 
 
-// public static
-void kpPainter::drawRect (kpImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor)
-{
-    kpPixmapFX::drawRect (image, x, y, width, height, fcolor, penWidth, bcolor);
-}
-
-//---------------------------------------------------------------------
-
-// public static
-void kpPainter::drawRoundedRect (kpImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor)
-{
-    kpPixmapFX::drawRoundedRect (image, x, y, width, height, fcolor, penWidth, bcolor);
-}
-
-//---------------------------------------------------------------------
-
-// public static
-void kpPainter::drawEllipse (kpImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor)
-{
-    kpPixmapFX::drawEllipse (image, x, y, width, height, fcolor, penWidth, bcolor);
-}
-
-//---------------------------------------------------------------------
-
-
 // <rgbPainter> are operating on the original image
 // (the original image is not passed to this function).
 //
diff --git a/imagelib/kpPainter.h b/imagelib/kpPainter.h
index 5fb51001..bae42ceb 100644
--- a/imagelib/kpPainter.h
+++ b/imagelib/kpPainter.h
@@ -98,60 +98,10 @@ public:
         bool cardinalAdjacency = false,
         double probability = 1.0);
 
-    // Draws a line from (x1,y1) to (x2,y2) onto <image>, with <color>
-    // and <penWidth>.  The corners are rounded and centred at those
-    // coordinates so if <width> > 1, the line is likely to extend past
-    // a rectangle with those corners.
-    static void drawLine (kpImage *image,
-        int x1, int y1, int x2, int y2,
-        const kpColor &color, int penWidth);
-    static void drawPolyline (kpImage *image,
-        const QPolygon &points,
-        const kpColor &color, int penWidth);
-    // <isFinal> = shape completed else drawing but haven't finalised.
-    // If not <isFinal>, the edge that would form the closure, if the
-    // shape were finalised now, is highlighted specially.  Unfortunately,
-    // the argument is currently ignored.
-    //
-    // Odd-even fill.
-    static void drawPolygon (kpImage *image,
-        const QPolygon &points,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor = kpColor::Invalid,
-        bool isFinal = true);
-    // Cubic Beizer.
-    static void drawCurve (kpImage *image,
-        const QPoint &startPoint,
-        const QPoint &controlPointP, const QPoint &controlPointQ,
-        const QPoint &endPoint,
-        const kpColor &color, int penWidth);
-
     static void fillRect (kpImage *image,
         int x, int y, int width, int height,
         const kpColor &color);
 
-    // Draws a rectangle / rounded rectangle / ellipse with top-left at
-    // (x, y) with width <width> and height <height>.  Unlike QPainter,
-    // this rectangle will really fit inside <width>x<height> and won't
-    // be one pixel higher or wider etc.
-    //
-    // <width> and <height> must be >= 0.
-    //
-    // <fcolor> must not be invalid.  However, <bcolor> may be invalid
-    // to signify an unfilled rectangle / rounded rectangle /ellipse.
-    static void drawRect (kpImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth = 1,
-        const kpColor &bcolor = kpColor::Invalid);
-    static void drawRoundedRect (kpImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth = 1,
-        const kpColor &bcolor = kpColor::Invalid);
-    static void drawEllipse (kpImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth = 1,
-        const kpColor &bcolor = kpColor::Invalid);
-
     // Replaces all pixels of <colorToReplace> on the line
     // from (x1,y1) to (x2,y2) of <image>, with a pen of <color> with
     // dimensions <penWidth>x<penHeight>.
diff --git a/kolourpaintui.rc b/kolourpaintui.rc
index 98864cdd..01e79767 100644
--- a/kolourpaintui.rc
+++ b/kolourpaintui.rc
@@ -4,7 +4,7 @@ SYNC: Do not change the number of quotes before the version number
       - it is parsed by the KolourPaint wrapper shell script (in standalone
       backport releases of KolourPaint)
 -->
-<gui name="kolourpaint" version="74">
+<gui name="kolourpaint" version="75">
 
 <!--
 SYNC: Check for duplicate actions in menus caused by some of our actions
@@ -112,6 +112,7 @@ SYNC: Check for duplicate actions in menus caused by some of our actions
 
     <Menu name="settings">
         <Action name="settings_show_path" append="show_merge" />
+        <Action name="settings_draw_antialiased" append="show_merge" />
     </Menu>
 
     <!-- HACK: See kpmainwindow.cpp:kpMainWindow::createGUI(). -->
diff --git a/kpDefs.h b/kpDefs.h
index 6d4881b5..1ab5572f 100644
--- a/kpDefs.h
+++ b/kpDefs.h
@@ -71,6 +71,7 @@
 #define kpSettingFirstTime "First Time"
 #define kpSettingShowGrid "Show Grid"
 #define kpSettingShowPath "Show Path"
+#define kpSettingDrawAntiAliased "Draw AntiAliased"
 #define kpSettingColorSimilarity "Color Similarity"
 #define kpSettingDitherOnOpen "Dither on Open if Screen is 15/16bpp and Image Num Colors More Than"
 #define kpSettingPrintImageCenteredOnPage "Print Image Centered On Page"
diff --git a/layers/selections/kpAbstractSelection.cpp b/layers/selections/kpAbstractSelection.cpp
index 2e58c1ca..8d3e96c2 100644
--- a/layers/selections/kpAbstractSelection.cpp
+++ b/layers/selections/kpAbstractSelection.cpp
@@ -258,13 +258,12 @@ void kpAbstractSelection::paintRectangularBorder (QImage *destPixmap,
               << " h=" << boundingRect ().height ()
               << endl;
 #endif
-    kpPixmapFX::drawRect(destPixmap,
+    kpPixmapFX::drawStippleRect(destPixmap,
         boundingRect ().x () - docRect.x (),
         boundingRect ().y () - docRect.y (),
         boundingRect ().width (),
         boundingRect ().height (),
-        kpColor::Blue, 1/*pen width*/,
-        kpColor::Invalid/*no background*/,
+        kpColor::Blue,
         kpColor::Yellow);
 }
 
@@ -298,13 +297,12 @@ void kpAbstractSelection::paintPolygonalBorder (const QPolygon &points,
           true/*is final*/,
           kpColor::Yellow);
 
-      kpPixmapFX::drawRect(destPixmap,
+      kpPixmapFX::drawStippleRect(destPixmap,
           boundingRect ().x () - docRect.x (),
           boundingRect ().y () - docRect.y (),
           boundingRect ().width (),
           boundingRect ().height (),
-          kpColor::LightGray, 1/*pen width*/,
-          kpColor::Invalid/*no background*/,
+          kpColor::LightGray,
           kpColor::DarkGray);
     }
 }
diff --git a/mainWindow/kpMainWindow.cpp b/mainWindow/kpMainWindow.cpp
index 673b48a5..b06ad132 100644
--- a/mainWindow/kpMainWindow.cpp
+++ b/mainWindow/kpMainWindow.cpp
@@ -31,6 +31,7 @@
 
 #include "layers/selections/image/kpAbstractImageSelection.h"
 #include "environments/commands/kpCommandEnvironment.h"
+#include "environments/tools/kpToolEnvironment.h"
 #include "widgets/kpColorCells.h"
 #include "widgets/toolbars/kpColorToolBar.h"
 #include "commands/kpCommandHistory.h"
@@ -47,19 +48,15 @@
 #include "views/kpZoomedThumbnailView.h"
 #include "views/kpZoomedView.h"
 
-#include <kconfig.h>
+#include <KSharedConfig>
 #include <kconfiggroup.h>
-#include "kpLogCategories.h"
-#include <klocale.h>
-#include <krecentfilesaction.h>
+#include <KLocalizedString>
 
 #include <qevent.h>
 #include <qmenu.h>
 #include <qtimer.h>
 
-#if DEBUG_KP_MAIN_WINDOW
-    #include <qdatetime.h>
-#endif
+#include "kpLogCategories.h"
 
 
 //---------------------------------------------------------------------
@@ -113,6 +110,7 @@ void kpMainWindow::readGeneralSettings ()
     d->configShowGrid = cfg.readEntry (kpSettingShowGrid, false);
     d->configShowPath = cfg.readEntry (kpSettingShowPath, false);
     d->moreEffectsDialogLastEffect = cfg.readEntry (kpSettingMoreEffectsLastEffect, 0);
+    kpToolEnvironment::drawAntiAliased = cfg.readEntry(kpSettingDrawAntiAliased, true);
 
     if (cfg.hasKey (kpSettingOpenImagesInSameWindow))
     {
diff --git a/mainWindow/kpMainWindow.h b/mainWindow/kpMainWindow.h
index 79889448..2c49a4c1 100644
--- a/mainWindow/kpMainWindow.h
+++ b/mainWindow/kpMainWindow.h
@@ -635,6 +635,7 @@ private slots:
 
     void slotEnableSettingsShowPath ();
     void slotShowPathToggled ();
+    void slotDrawAntiAliasedToggled(bool on);
 
     void slotKeyBindings ();
 
diff --git a/mainWindow/kpMainWindow_Settings.cpp b/mainWindow/kpMainWindow_Settings.cpp
index 1732ae1e..b27252fd 100644
--- a/mainWindow/kpMainWindow_Settings.cpp
+++ b/mainWindow/kpMainWindow_Settings.cpp
@@ -28,20 +28,21 @@
 
 #include "mainWindow/kpMainWindow.h"
 #include "kpMainWindowPrivate.h"
+#include "kpLogCategories.h"
 
 #include <kactioncollection.h>
-#include <kconfig.h>
+#include <KSharedConfig>
 #include <kconfiggroup.h>
-#include "kpLogCategories.h"
-#include <klocale.h>
 #include <kshortcutsdialog.h>
 #include <kstandardaction.h>
 #include <ktogglefullscreenaction.h>
+#include <KLocalizedString>
 
 #include "kpDefs.h"
 #include "document/kpDocument.h"
 #include "tools/kpToolAction.h"
 #include "widgets/toolbars/kpToolToolBar.h"
+#include "environments/tools/kpToolEnvironment.h"
 
 //---------------------------------------------------------------------
 
@@ -65,9 +66,12 @@ void kpMainWindow::setupSettingsMenuActions ()
     d->actionShowPath = ac->add<KToggleAction> ("settings_show_path");
     d->actionShowPath->setText (i18n ("Show &Path"));
     connect(d->actionShowPath, SIGNAL(triggered(bool) ), SLOT (slotShowPathToggled ()));
-    //d->actionShowPath->setCheckedState (KGuiItem(i18n ("Hide &Path")));
     slotEnableSettingsShowPath ();
 
+    KToggleAction *action = ac->add<KToggleAction>("settings_draw_antialiased");
+    action->setText(i18n("Draw Anti-Aliased"));
+    action->setChecked(kpToolEnvironment::drawAntiAliased);
+    connect(action, SIGNAL(triggered(bool)), SLOT(slotDrawAntiAliasedToggled(bool)));
 
     d->actionKeyBindings = KStandardAction::keyBindings (this, SLOT (slotKeyBindings ()), ac);
 
@@ -128,6 +132,18 @@ void kpMainWindow::slotShowPathToggled ()
 
 //---------------------------------------------------------------------
 
+void kpMainWindow::slotDrawAntiAliasedToggled(bool on)
+{
+    kpToolEnvironment::drawAntiAliased = on;
+
+    KConfigGroup cfg(KSharedConfig::openConfig(), kpSettingsGroupGeneral);
+
+    cfg.writeEntry(kpSettingDrawAntiAliased, kpToolEnvironment::drawAntiAliased);
+    cfg.sync();
+}
+
+//---------------------------------------------------------------------
+
 // private slot
 void kpMainWindow::slotKeyBindings ()
 {
diff --git a/pixmapfx/kpPixmapFX.h b/pixmapfx/kpPixmapFX.h
index a5d4c069..1b3920b9 100644
--- a/pixmapfx/kpPixmapFX.h
+++ b/pixmapfx/kpPixmapFX.h
@@ -208,6 +208,7 @@ public:
     // <qtWidth> is passed straight to QPen without modification.
     static QPen QPainterDrawLinePen (const QColor &color, int qtWidth);
 
+    static bool Only1PixelInPointArray(const QPolygon &points);
 
     // Draws a line from (x1,y1) to (x2,y2) onto <image>, with <color>
     // and <width>.  The corners are rounded and centred at those
@@ -221,11 +222,6 @@ public:
         const kpColor &color, int penWidth,
         const kpColor &stippleColor = kpColor::Invalid);
 
-    static void drawLine (QImage *image,
-        int x1, int y1, int x2, int y2,
-        const kpColor &color, int penWidth,
-        const kpColor &stippleColor = kpColor::Invalid);
-
     // <isFinal> = shape completed else drawing but haven't finalised.
     // If not <isFinal>, the edge that would form the closure, if the
     // shape were finalised now, is highlighted specially.
@@ -237,44 +233,17 @@ public:
         const kpColor &bcolor = kpColor::Invalid,
         bool isFinal = true,
         const kpColor &fStippleColor = kpColor::Invalid);
-    // Cubic Beizer.
-    static void drawCurve (QImage *image,
-        const QPoint &startPoint,
-        const QPoint &controlPointP, const QPoint &controlPointQ,
-        const QPoint &endPoint,
-        const kpColor &color, int penWidth);
 
     static void fillRect (QImage *image,
         int x, int y, int width, int height,
         const kpColor &color,
         const kpColor &stippleColor = kpColor::Invalid);
 
-    // Draws a rectangle / rounded rectangle / ellipse with top-left at
-    // (x, y) with width <width> and height <height>.  Unlike QPainter,
-    // this rectangle will really fit inside <width>x<height> and won't
-    // be one pixel higher or wider etc.
-    //
-    // <width> and <height> must be >= 0.
-    //
-    // <fcolor> must not be invalid.  However, <bcolor> may be invalid
-    // to signify an unfilled rectangle / rounded rectangle /ellipse.
-    static void drawRect (QImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth = 1,
-        const kpColor &bcolor = kpColor::Invalid,
-        const kpColor &fStippleColor = kpColor::Invalid);
+    static void drawStippleRect(QImage *image,
+            int x, int y, int width, int height,
+            const kpColor &fcolor,
+            const kpColor &fStippleColor);
 
-    static void drawRoundedRect (QImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth = 1,
-        const kpColor &bcolor = kpColor::Invalid,
-        const kpColor &fStippleColor = kpColor::Invalid);
-
-    static void drawEllipse (QImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth = 1,
-        const kpColor &bcolor = kpColor::Invalid,
-        const kpColor &fStippleColor = kpColor::Invalid);
 };
 
 
diff --git a/pixmapfx/kpPixmapFX_DrawShapes.cpp b/pixmapfx/kpPixmapFX_DrawShapes.cpp
index f5a31e93..10dfb8ae 100644
--- a/pixmapfx/kpPixmapFX_DrawShapes.cpp
+++ b/pixmapfx/kpPixmapFX_DrawShapes.cpp
@@ -48,7 +48,7 @@
 //---------------------------------------------------------------------
 
 // Returns whether there is only 1 distinct point in <points>.
-static bool Only1PixelInPointArray (const QPolygon &points)
+bool kpPixmapFX::Only1PixelInPointArray (const QPolygon &points)
 {
     if (points.count () == 0)
         return false;
@@ -173,24 +173,6 @@ void kpPixmapFX::drawPolyline (QImage *image,
 }
 
 //---------------------------------------------------------------------
-
-// public static
-void kpPixmapFX::drawLine (QImage *image,
-        int x1, int y1, int x2, int y2,
-        const kpColor &color, int penWidth,
-        const kpColor &stippleColor)
-{
-    QPolygon points;
-    points.append (QPoint (x1, y1));
-    points.append (QPoint (x2, y2));
-
-    drawPolyline (image,
-        points,
-        color, penWidth,
-        stippleColor);
-}
-
-//---------------------------------------------------------------------
 //
 // drawPolygon()
 //
@@ -240,39 +222,8 @@ void kpPixmapFX::drawPolygon (QImage *image,
 }
 
 //---------------------------------------------------------------------
-
 // public static
-void kpPixmapFX::drawCurve (QImage *image,
-    const QPoint &startPoint,
-    const QPoint &controlPointP, const QPoint &controlPointQ,
-    const QPoint &endPoint,
-    const kpColor &color, int penWidth)
-{
-    QPainter p(image);
-    ::QPainterSetPenWithStipple (&p,
-        color, penWidth);
 
-    // SYNC: Qt bug: single point doesn't show up depending on penWidth.
-    if (startPoint == controlPointP &&
-        controlPointP == controlPointQ &&
-        controlPointQ == endPoint)
-    {
-    #if DEBUG_KP_PIXMAP_FX
-        qCDebug(kpLogPixmapfx) << "\tinvoking single point hack";
-    #endif
-        p.drawPoint (startPoint);
-        return;
-    }
-
-    QPainterPath curvePath;
-    curvePath.moveTo(startPoint);
-    curvePath.cubicTo(controlPointP, controlPointQ, endPoint);
-
-    p.strokePath(curvePath, p.pen());
-}
-
-//---------------------------------------------------------------------
-// public static
 void kpPixmapFX::fillRect (QImage *image,
         int x, int y, int width, int height,
         const kpColor &color,
@@ -310,183 +261,18 @@ void kpPixmapFX::fillRect (QImage *image,
 }
 
 //---------------------------------------------------------------------
-// Calls to drawRect(), drawRoundedRect() and drawEllipse() are
-// forwarded here.  <func> is the respective QPainter function and
-// may or may not be called.
-static void DrawGenericRect (QImage *image,
-        int x, int y, int width, int height,
-        void (*func) (QPainter * /*p*/, int /*x*/, int /*y*/,
-                int /*width*/, int/*height*/),
-        const kpColor &fcolor, int penWidth,
-        kpColor bcolor,
-        const kpColor &fStippleColor,
-        bool isEllipseLike)
-{
-#if DEBUG_KP_PIXMAP_FX
-    qCDebug(kpLogPixmapfx) << "kppixmapfx.cpp:DrawGenericRect(" << x << "," << y << ","
-        << width << "," << height << ",func=" << func << ")"
-        << " pen.color=" << (int *) fcolor.toQRgb ()
-        << " penWidth=" << penWidth
-        << " bcolor="
-        << (int *) (bcolor.isValid () ?
-                       bcolor.toQRgb () :
-                       0xabadcafe)
-        << " isEllipseLike=" << isEllipseLike
-        << endl;
- #endif
-
-
-    if ( (width == 0) || (height == 0) )
-      return;
-
-    Q_ASSERT (func);
-
-    // Check foreground colour valid.
-    // Background is allowed to be invalid (no fill).
-    Q_ASSERT (fcolor.isValid ());
-
-
-    if (width == 1 || height == 1)
-    {
-    #if DEBUG_KP_PIXMAP_FX
-        qCDebug(kpLogPixmapfx) << "\twidth=1 or height=1 - draw line";
-    #endif
-
-        kpPixmapFX::drawLine (image,
-            x, y, x + width - 1, y + height - 1,
-            fcolor, 1/*force pen width to 1*/,
-            fStippleColor);
-        return;
-    }
-
-
-    // Outline is so big that fill won't be seen?
-    if (penWidth * 2 >= width || penWidth * 2 >= height)
-    {
-    #if DEBUG_KP_PIXMAP_FX
-        qCDebug(kpLogPixmapfx) << "\toutline dominates fill - fill with outline";
-    #endif
-
-        // Fill with outline.
-        // TODO: doesn't emulate non-Qt::SolidLine pens
-        // TODO: Transition from this hack to normal drawing makes the
-        //       ellipse look like it moves 1 pixel to the right due to
-        //       Qt missing a pixel on the left of some sizes of ellipses.
-        penWidth = 1;
-        bcolor = fcolor;  // Outline colour.
-    }
-
-    QPainter painter(image);
-
-    ::QPainterSetPenWithStipple(&painter,
-        fcolor, penWidth,
-        fStippleColor,
-        isEllipseLike);
 
-    QPen pen = painter.pen();
-    pen.setJoinStyle(Qt::MiterJoin);  // rectangle shall always have square corners
-    painter.setPen(pen);
-
-    if (bcolor.isValid ())
-        painter.setBrush (QBrush (bcolor.toQColor()));
-    // HACK: seems to be needed if set_Pen_(Qt::color0) else fills with Qt::color0.
-    else
-        painter.setBrush (Qt::NoBrush);
-
-    // Fight Qt behaviour of painting width = fill width + pen width
-    // and height = fill height + pen height.  Get rid of pen width.
-    (*func) (&painter,
-        x + penWidth / 2,
-        y + penWidth / 2,
-        width - penWidth,
-        height - penWidth);
-}
-
-//---------------------------------------------------------------------
-
-
-static void DrawRectHelper (QPainter *p,
-        int x, int y, int width, int height)
-{
-  // workaround for QTBUG-38617
-  QPainterPath path;
-  path.addRect(x, y, width, height);
-  p->drawPath(path);
-}
-
-//---------------------------------------------------------------------
-
-// public static
-void kpPixmapFX::drawRect (QImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor,
-        const kpColor &fStippleColor)
-{
-    ::DrawGenericRect (image,
-        x, y, width, height,
-        &::DrawRectHelper,
-        fcolor, penWidth,
-        bcolor,
-        fStippleColor,
-        false/*not ellipse-like*/);
-}
-
-//---------------------------------------------------------------------
-
-
-static void DrawRoundedRectHelper (QPainter *p,
-        int x, int y, int width, int height)
-{
-    // (has default arguments for the roundness i.e. different prototype
-    //  to QPainter::draw{Rect,Ellipse}(), therefore need pointer to these
-    //  helpers instead of directly to a QPainter member function)
-    p->drawRoundedRect(x, y, width, height, 25, 25, Qt::RelativeSize);
-}
-
-//---------------------------------------------------------------------
-
-// public static
-void kpPixmapFX::drawRoundedRect (QImage *image,
+void kpPixmapFX::drawStippleRect(QImage *image,
         int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor,
+        const kpColor &fColor,
         const kpColor &fStippleColor)
 {
-    ::DrawGenericRect (image,
-        x, y, width, height,
-        &::DrawRoundedRectHelper,
-        fcolor, penWidth,
-        bcolor,
-        fStippleColor,
-        true/*ellipse like*/);
-}
-
-//---------------------------------------------------------------------
-
-
-static void DrawEllipseHelper (QPainter *p,
-        int x, int y, int width, int height)
-{
-    p->drawEllipse (x, y, width, height);
-}
+  QPainter painter(image);
 
-//---------------------------------------------------------------------
-
-// public static
-void kpPixmapFX::drawEllipse (QImage *image,
-        int x, int y, int width, int height,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor,
-        const kpColor &fStippleColor)
-{
-    ::DrawGenericRect (image,
-        x, y, width, height,
-        &::DrawEllipseHelper,
-        fcolor, penWidth,
-        bcolor,
-        fStippleColor,
-        true/*ellipse like*/);
+  painter.setPen(QPen(fColor.toQColor(), 1, Qt::DashLine));
+  painter.setBackground(fStippleColor.toQColor());
+  painter.setBackgroundMode(Qt::OpaqueMode);
+  painter.drawRect(x, y, width - 1, height - 1);
 }
 
 //---------------------------------------------------------------------
diff --git a/tools/kpToolZoom.cpp b/tools/kpToolZoom.cpp
index 0c7775ee..b46c9e7f 100644
--- a/tools/kpToolZoom.cpp
+++ b/tools/kpToolZoom.cpp
@@ -38,13 +38,13 @@
 #include "environments/tools/kpToolEnvironment.h"
 #include "tools/kpToolAction.h"
 #include "views/manager/kpViewManager.h"
-
 #include "kpLogCategories.h"
-#include <klocale.h>
-#include <kiconloader.h>
 
 #include <QWidget>
 
+#include <kiconloader.h>
+#include <KLocalizedString>
+
 //---------------------------------------------------------------------
 
 struct DrawZoomRectPackage
@@ -58,10 +58,9 @@ static void DrawZoomRect (kpImage *destImage,
 {
     DrawZoomRectPackage *pack = static_cast <DrawZoomRectPackage *> (userData);
 
-    kpPixmapFX::drawRect(destImage,
+    kpPixmapFX::drawStippleRect(destImage,
         topLeft.x (), topLeft.y (), pack->normalizedRect.width (), pack->normalizedRect.height (),
-        kpColor::Yellow, 1/*pen width*/,
-        kpColor::Invalid/*no background*/,
+        kpColor::Yellow,
         kpColor::Green);
 }
 
diff --git a/tools/polygonal/kpToolCurve.cpp b/tools/polygonal/kpToolCurve.cpp
index c23c5d77..63d2c8ab 100644
--- a/tools/polygonal/kpToolCurve.cpp
+++ b/tools/polygonal/kpToolCurve.cpp
@@ -1,6 +1,6 @@
-
 /*
    Copyright (c) 2003-2007 Clarence Dang <dang at kde.org>
+   Copyright (c) 2017      Martin Koller <kollix at aon.at>
    All rights reserved.
 
    Redistribution and use in source and binary forms, with or without
@@ -30,12 +30,17 @@
 
 
 #include "kpToolCurve.h"
-
 #include "kpLogCategories.h"
-#include <klocale.h>
+#include "environments/tools/kpToolEnvironment.h"
+#include "pixmapfx/kpPixmapFX.h"
+
+#include <QPainter>
+#include <QPen>
+#include <QPainterPath>
 
-#include "imagelib/kpPainter.h"
+#include <KLocalizedString>
 
+//--------------------------------------------------------------------------------
 
 static void DrawCurveShape (kpImage *image,
         const QPolygon &points,
@@ -73,13 +78,25 @@ static void DrawCurveShape (kpImage *image,
         break;
     }
 
-    kpPainter::drawCurve (image,
-        startPoint,
-        controlPointP, controlPointQ,
-        endPoint,
-        fcolor, penWidth);
+    QPainter painter(image);
+    painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased);
+
+    painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+
+    if ( kpPixmapFX::Only1PixelInPointArray(points) )
+    {
+      painter.drawPoint(points[0]);
+      return;
+    }
+
+    QPainterPath curvePath;
+    curvePath.moveTo(startPoint);
+    curvePath.cubicTo(controlPointP, controlPointQ, endPoint);
+
+    painter.strokePath(curvePath, painter.pen());
 }
 
+//--------------------------------------------------------------------------------
 
 kpToolCurve::kpToolCurve (kpToolEnvironment *environ, QObject *parent)
     : kpToolPolygonalBase (
diff --git a/tools/polygonal/kpToolLine.cpp b/tools/polygonal/kpToolLine.cpp
index afbc6c9b..b250480e 100644
--- a/tools/polygonal/kpToolLine.cpp
+++ b/tools/polygonal/kpToolLine.cpp
@@ -1,4 +1,3 @@
-
 /*
    Copyright (c) 2003-2007 Clarence Dang <dang at kde.org>
    All rights reserved.
@@ -30,44 +29,25 @@
 
 
 #include "kpToolLine.h"
-
 #include "kpToolPolyline.h"
-
 #include "kpLogCategories.h"
-#include <klocale.h>
 
+#include <KLocalizedString>
 
-static void DrawLineShape (kpImage *image,
-        const QPolygon &points,
-        const kpColor &fcolor, int penWidth,
-        const kpColor &bcolor,
-        bool isFinal)
-{
-    Q_ASSERT (points.count () == 2);
-
-    kpToolPolyline::DrawShape (image,
-        points,
-        fcolor, penWidth,
-        bcolor,
-        isFinal);
-}
-
+//--------------------------------------------------------------------------------
 
 kpToolLine::kpToolLine (kpToolEnvironment *environ, QObject *parent)
     : kpToolPolygonalBase (
         i18n ("Line"),
         i18n ("Draws lines"),
-        &::DrawLineShape,
+        &kpToolPolyline::drawShape,
         Qt::Key_L,
         environ, parent,
         "tool_line")
 {
 }
 
-kpToolLine::~kpToolLine ()
-{
-}
-
+//--------------------------------------------------------------------------------
 
 // private virtual [base kpToolPolygonalBase]
 QString kpToolLine::haventBegunShapeUserMessage () const
@@ -75,6 +55,7 @@ QString kpToolLine::haventBegunShapeUserMessage () const
     return i18n ("Drag to draw.");
 }
 
+//--------------------------------------------------------------------------------
 
 // public virtual [base kpTool]
 void kpToolLine::endDraw (const QPoint &, const QRect &)
@@ -89,4 +70,4 @@ void kpToolLine::endDraw (const QPoint &, const QRect &)
     endShape ();
 }
 
-
+//--------------------------------------------------------------------------------
diff --git a/tools/polygonal/kpToolLine.h b/tools/polygonal/kpToolLine.h
index 43914a91..4d14e074 100644
--- a/tools/polygonal/kpToolLine.h
+++ b/tools/polygonal/kpToolLine.h
@@ -39,7 +39,6 @@ Q_OBJECT
 
 public:
     kpToolLine (kpToolEnvironment *environ, QObject *parent);
-    virtual ~kpToolLine ();
 
 private:
     virtual QString haventBegunShapeUserMessage () const;
diff --git a/tools/polygonal/kpToolPolygon.cpp b/tools/polygonal/kpToolPolygon.cpp
index d7d3729f..629f07e0 100644
--- a/tools/polygonal/kpToolPolygon.cpp
+++ b/tools/polygonal/kpToolPolygon.cpp
@@ -1,6 +1,6 @@
-
 /*
    Copyright (c) 2003-2007 Clarence Dang <dang at kde.org>
+   Copyright (c) 2017      Martin Koller <kollix at aon.at>
    All rights reserved.
 
    Redistribution and use in source and binary forms, with or without
@@ -30,12 +30,17 @@
 
 
 #include "kpToolPolygon.h"
+#include "widgets/toolbars/kpToolToolBar.h"
+#include "environments/tools/kpToolEnvironment.h"
+#include "imagelib/kpColor.h"
+#include "pixmapfx/kpPixmapFX.h"
 
-#include <klocale.h>
+#include <KLocalizedString>
 
-#include "imagelib/kpPainter.h"
-#include "widgets/toolbars/kpToolToolBar.h"
+#include <QPainter>
+#include <QPen>
 
+//--------------------------------------------------------------------------------
 
 static void DrawPolygonShape (kpImage *image,
         const QPolygon &points,
@@ -43,13 +48,36 @@ static void DrawPolygonShape (kpImage *image,
         const kpColor &bcolor,
         bool isFinal)
 {
-    kpPainter::drawPolygon (image,
-        points,
-        fcolor, penWidth,
-        bcolor,
-        isFinal);
+  QPainter painter(image);
+  painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased);
+
+  painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+
+  if ( kpPixmapFX::Only1PixelInPointArray(points) )
+  {
+    painter.drawPoint(points[0]);
+    return;
+  }
+
+  if ( bcolor.isValid() )
+    painter.setBrush(QBrush(bcolor.toQColor()));
+  else
+    painter.setBrush(Qt::NoBrush);
+
+  painter.drawPolygon(points, Qt::OddEvenFill);
+
+  if ( isFinal )
+    return;
+
+  if ( points.count() <= 2 )
+    return;
+
+  painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
+  painter.setPen(QPen(Qt::white));
+  painter.drawLine(points[0], points[points.count() - 1]);
 }
 
+//--------------------------------------------------------------------------------
 
 struct kpToolPolygonPrivate
 {
diff --git a/tools/polygonal/kpToolPolygonalBase.cpp b/tools/polygonal/kpToolPolygonalBase.cpp
index f2f1c38d..2a60ca1c 100644
--- a/tools/polygonal/kpToolPolygonalBase.cpp
+++ b/tools/polygonal/kpToolPolygonalBase.cpp
@@ -34,19 +34,14 @@
 #include <float.h>
 #include <math.h>
 
-#include <qbitmap.h>
 #include <qcursor.h>
-#include <qlayout.h>
-#include <qpainter.h>
-#include <qpixmap.h>
 #include <qpoint.h>
 #include <qpolygon.h>
-#include <qpushbutton.h>
 #include <qrect.h>
 
-#include "kpLogCategories.h"
-#include <klocale.h>
+#include <KLocalizedString>
 
+#include "kpLogCategories.h"
 #include "commands/kpCommandHistory.h"
 #include "document/kpDocument.h"
 #include "kpDefs.h"
diff --git a/tools/polygonal/kpToolPolygonalBase.h b/tools/polygonal/kpToolPolygonalBase.h
index 5c6214cb..91023896 100644
--- a/tools/polygonal/kpToolPolygonalBase.h
+++ b/tools/polygonal/kpToolPolygonalBase.h
@@ -30,12 +30,7 @@
 #define kpToolPolygonalBase_H
 
 
-#include <qbrush.h>
-#include <qpen.h>
-#include <qobject.h>
-#include <qpixmap.h>
 #include <qpoint.h>
-#include <qpolygon.h>
 #include <qrect.h>
 
 #include "imagelib/kpColor.h"
@@ -44,9 +39,7 @@
 #include "widgets/toolbars/options/kpToolWidgetFillStyle.h"
 
 
-class QPoint;
 class QPolygon;
-class QRect;
 class QString;
 
 class kpView;
@@ -94,7 +87,6 @@ class kpToolPolygonalBase : public kpTool
 Q_OBJECT
 
 public:
-    // (all arguments are as per kpPainter::drawPolygon())
     typedef void (*DrawShapeFunc) (kpImage * /*image*/,
         const QPolygon &/*points*/,
         const kpColor &/*fcolor*/, int /*penWidth = 1*/,
diff --git a/tools/polygonal/kpToolPolyline.cpp b/tools/polygonal/kpToolPolyline.cpp
index 1369e97f..3feb841a 100644
--- a/tools/polygonal/kpToolPolyline.cpp
+++ b/tools/polygonal/kpToolPolyline.cpp
@@ -30,28 +30,29 @@
 
 
 #include "kpToolPolyline.h"
-
 #include "kpLogCategories.h"
-#include <klocale.h>
+#include "environments/tools/kpToolEnvironment.h"
+#include "pixmapfx/kpPixmapFX.h"
+
+#include <KLocalizedString>
 
-#include "imagelib/kpPainter.h"
+#include <QPainter>
+#include <QPen>
 
+//--------------------------------------------------------------------------------
 
 kpToolPolyline::kpToolPolyline (kpToolEnvironment *environ, QObject *parent)
     : kpToolPolygonalBase (
         i18n ("Connected Lines"),
         i18n ("Draws connected lines"),
-        &DrawShape,
+        &drawShape,
         Qt::Key_N,
         environ, parent,
         "tool_polyline")
 {
 }
 
-kpToolPolyline::~kpToolPolyline ()
-{
-}
-
+//--------------------------------------------------------------------------------
 
 // private virtual [base kpToolPolygonalBase]
 QString kpToolPolyline::haventBegunShapeUserMessage () const
@@ -59,9 +60,10 @@ QString kpToolPolyline::haventBegunShapeUserMessage () const
     return i18n ("Drag to draw the first line.");
 }
 
-
+//--------------------------------------------------------------------------------
 // public static
-void kpToolPolyline::DrawShape (kpImage *image,
+
+void kpToolPolyline::drawShape(kpImage *image,
         const QPolygon &points,
         const kpColor &fcolor, int penWidth,
         const kpColor &bcolor,
@@ -70,11 +72,18 @@ void kpToolPolyline::DrawShape (kpImage *image,
     (void) bcolor;
     (void) isFinal;
 
-    kpPainter::drawPolyline (image,
-        points,
-        fcolor, penWidth);
+  QPainter painter(image);
+  painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased);
+
+  painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+
+  if ( kpPixmapFX::Only1PixelInPointArray(points) )
+    painter.drawPoint(points[0]);
+  else
+    painter.drawPolyline(points);
 }
 
+//--------------------------------------------------------------------------------
 
 // public virtual [base kpTool]
 void kpToolPolyline::endDraw (const QPoint &, const QRect &)
diff --git a/tools/polygonal/kpToolPolyline.h b/tools/polygonal/kpToolPolyline.h
index 0ba189af..86648277 100644
--- a/tools/polygonal/kpToolPolyline.h
+++ b/tools/polygonal/kpToolPolyline.h
@@ -39,14 +39,13 @@ Q_OBJECT
 
 public:
     kpToolPolyline (kpToolEnvironment *environ, QObject *parent);
-    virtual ~kpToolPolyline ();
 
 private:
     virtual QString haventBegunShapeUserMessage () const;
 
 public:
     // (used by kpToolLine)
-    static void DrawShape (kpImage *image,
+    static void drawShape(kpImage *image,
         const QPolygon &points,
         const kpColor &fcolor, int penWidth,
         const kpColor &bcolor,
diff --git a/tools/rectangular/kpToolEllipse.cpp b/tools/rectangular/kpToolEllipse.cpp
index f33a422f..34a1af4a 100644
--- a/tools/rectangular/kpToolEllipse.cpp
+++ b/tools/rectangular/kpToolEllipse.cpp
@@ -1,6 +1,6 @@
-
 /*
    Copyright (c) 2003-2007 Clarence Dang <dang at kde.org>
+   Copyright (c) 2017      Martin Koller <kollix at aon.at>
    All rights reserved.
 
    Redistribution and use in source and binary forms, with or without
@@ -27,17 +27,21 @@
 
 
 #include "kpToolEllipse.h"
+#include "environments/tools/kpToolEnvironment.h"
+#include "imagelib/kpColor.h"
 
-#include "imagelib/kpPainter.h"
+#include <KLocalizedString>
 
-#include <klocale.h>
+#include <QPainter>
+#include <QPen>
+#include <QBrush>
 
 //---------------------------------------------------------------------
 
 kpToolEllipse::kpToolEllipse (kpToolEnvironment *environ, QObject *parent)
     : kpToolRectangularBase (i18n ("Ellipse"),
         i18n ("Draws ellipses and circles"),
-        &kpPainter::drawEllipse,
+        &kpToolEllipse::drawEllipse,
         Qt::Key_E,
         environ, parent, "tool_ellipse")
 {
@@ -45,3 +49,34 @@ kpToolEllipse::kpToolEllipse (kpToolEnvironment *environ, QObject *parent)
 
 //---------------------------------------------------------------------
 
+void kpToolEllipse::drawEllipse(kpImage *image,
+        int x, int y, int width, int height,
+        const kpColor &fcolor, int penWidth,
+        const kpColor &bcolor)
+{
+  if ( (width == 0) || (height == 0) )
+    return;
+
+  QPainter painter(image);
+  painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased);
+
+  if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) )
+    penWidth = qMin(width, height) / 2;
+
+  painter.setPen(QPen(fcolor.toQColor(), penWidth));
+
+  if ( bcolor.isValid() )
+    painter.setBrush(QBrush(bcolor.toQColor()));
+  else
+    painter.setBrush(Qt::NoBrush);
+
+  int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0;
+
+  painter.drawEllipse(
+        x + penWidth / 2 + offset,
+        y + penWidth / 2 + offset,
+        qMax(1, width - penWidth - offset),
+        qMax(1, height - penWidth - offset));
+}
+
+//---------------------------------------------------------------------
diff --git a/tools/rectangular/kpToolEllipse.h b/tools/rectangular/kpToolEllipse.h
index 97fd6cb1..5c90f1c8 100644
--- a/tools/rectangular/kpToolEllipse.h
+++ b/tools/rectangular/kpToolEllipse.h
@@ -39,6 +39,11 @@ Q_OBJECT
 
 public:
     kpToolEllipse (kpToolEnvironment *environ, QObject *parent);
+
+    static void drawEllipse(kpImage *image,
+        int x, int y, int width, int height,
+        const kpColor &fcolor, int penWidth,
+        const kpColor &bcolor);
 };
 
 
diff --git a/tools/rectangular/kpToolRectangle.cpp b/tools/rectangular/kpToolRectangle.cpp
index c8820261..d214d993 100644
--- a/tools/rectangular/kpToolRectangle.cpp
+++ b/tools/rectangular/kpToolRectangle.cpp
@@ -1,6 +1,6 @@
-
 /*
    Copyright (c) 2003-2007 Clarence Dang <dang at kde.org>
+   Copyright (c) 2017      Martin Koller <kollix at aon.at>
    All rights reserved.
 
    Redistribution and use in source and binary forms, with or without
@@ -28,17 +28,21 @@
 
 #include "kpToolRectangle.h"
 
-#include "imagelib/kpPainter.h"
+#include "environments/tools/kpToolEnvironment.h"
+#include "imagelib/kpColor.h"
 
-#include <klocale.h>
+#include <KLocalizedString>
 
-//---------------------------------------------------------------------
+#include <QPainter>
+#include <QPen>
+#include <QBrush>
 
+//---------------------------------------------------------------------
 
 kpToolRectangle::kpToolRectangle (kpToolEnvironment *environ, QObject *parent)
     : kpToolRectangularBase (i18n ("Rectangle"),
         i18n ("Draws rectangles and squares"),
-        &kpPainter::drawRect,
+        &kpToolRectangle::drawRect,
         Qt::Key_R,
         environ, parent, "tool_rectangle")
 {
@@ -46,3 +50,34 @@ kpToolRectangle::kpToolRectangle (kpToolEnvironment *environ, QObject *parent)
 
 //---------------------------------------------------------------------
 
+void kpToolRectangle::drawRect(kpImage *image,
+        int x, int y, int width, int height,
+        const kpColor &fcolor, int penWidth,
+        const kpColor &bcolor)
+{
+  if ( (width == 0) || (height == 0) )
+    return;
+
+  QPainter painter(image);
+  painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased);
+
+  if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) )
+    penWidth = qMin(width, height) / 2;
+
+  painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
+
+  if ( bcolor.isValid() )
+    painter.setBrush(QBrush(bcolor.toQColor()));
+  else
+    painter.setBrush(Qt::NoBrush);
+
+  int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0;
+
+  painter.drawRect(
+        x + penWidth / 2 + offset,
+        y + penWidth / 2 + offset,
+        qMax(1, width - penWidth - offset),
+        qMax(1, height - penWidth - offset));
+}
+
+//---------------------------------------------------------------------
diff --git a/tools/rectangular/kpToolRectangle.h b/tools/rectangular/kpToolRectangle.h
index 6dab3f04..e43b0101 100644
--- a/tools/rectangular/kpToolRectangle.h
+++ b/tools/rectangular/kpToolRectangle.h
@@ -39,6 +39,11 @@ Q_OBJECT
 
 public:
     kpToolRectangle (kpToolEnvironment *environ, QObject *parent);
+
+    static void drawRect(kpImage *image,
+        int x, int y, int width, int height,
+        const kpColor &fcolor, int penWidth,
+        const kpColor &bcolor);
 };
 
 
diff --git a/tools/rectangular/kpToolRectangularBase.cpp b/tools/rectangular/kpToolRectangularBase.cpp
index 96865494..45313f00 100644
--- a/tools/rectangular/kpToolRectangularBase.cpp
+++ b/tools/rectangular/kpToolRectangularBase.cpp
@@ -31,14 +31,10 @@
 
 #include "tools/rectangular/kpToolRectangularBase.h"
 
-#include <qbitmap.h>
 #include <qcursor.h>
-#include <qevent.h>
-#include <qpainter.h>
-#include <qpixmap.h>
 
 #include "kpLogCategories.h"
-#include <klocale.h>
+#include <KLocalizedString>
 
 #include "imagelib/kpColor.h"
 #include "commands/kpCommandHistory.h"
diff --git a/tools/rectangular/kpToolRectangularBase.h b/tools/rectangular/kpToolRectangularBase.h
index 7adb3072..48b9a4d6 100644
--- a/tools/rectangular/kpToolRectangularBase.h
+++ b/tools/rectangular/kpToolRectangularBase.h
@@ -62,6 +62,7 @@ public:
         int key,
         kpToolEnvironment *environ, QObject *parent,
         const QString &name);
+
     virtual ~kpToolRectangularBase ();
 
     virtual bool careAboutModifierState () const { return true; }
diff --git a/tools/rectangular/kpToolRoundedRectangle.cpp b/tools/rectangular/kpToolRoundedRectangle.cpp
index f5ba4662..e02c3247 100644
--- a/tools/rectangular/kpToolRoundedRectangle.cpp
+++ b/tools/rectangular/kpToolRoundedRectangle.cpp
@@ -1,5 +1,6 @@
 /*
    Copyright (c) 2003-2007 Clarence Dang <dang at kde.org>
+   Copyright (c) 2017      Martin Koller <kollix at aon.at>
    All rights reserved.
 
    Redistribution and use in source and binary forms, with or without
@@ -26,17 +27,21 @@
 
 #include "kpToolRoundedRectangle.h"
 
-#include "imagelib/kpPainter.h"
+#include "environments/tools/kpToolEnvironment.h"
+#include "imagelib/kpColor.h"
 
-#include <klocale.h>
+#include <KLocalizedString>
+
+#include <QPainter>
+#include <QPen>
+#include <QBrush>
 
 //---------------------------------------------------------------------
 
-kpToolRoundedRectangle::kpToolRoundedRectangle (kpToolEnvironment *environ,
-        QObject *parent)
+kpToolRoundedRectangle::kpToolRoundedRectangle (kpToolEnvironment *environ, QObject *parent)
     : kpToolRectangularBase (i18n ("Rounded Rectangle"),
         i18n ("Draws rectangles and squares with rounded corners"),
-        &kpPainter::drawRoundedRect,
+        &kpToolRoundedRectangle::drawRoundedRect,
         Qt::Key_U,
         environ, parent, "tool_rounded_rectangle")
 {
@@ -44,3 +49,37 @@ kpToolRoundedRectangle::kpToolRoundedRectangle (kpToolEnvironment *environ,
 
 //---------------------------------------------------------------------
 
+void kpToolRoundedRectangle::drawRoundedRect(kpImage *image,
+        int x, int y, int width, int height,
+        const kpColor &fcolor, int penWidth,
+        const kpColor &bcolor)
+{
+  if ( (width == 0) || (height == 0) )
+    return;
+
+  QPainter painter(image);
+  painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased);
+
+  if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) )
+    penWidth = qMin(width, height) / 2;
+
+  painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
+
+  if ( bcolor.isValid() )
+    painter.setBrush(QBrush(bcolor.toQColor()));
+  else
+    painter.setBrush(Qt::NoBrush);
+
+  int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0;
+
+  int radius = qMin(width, height) / 4;
+
+  painter.drawRoundedRect(
+        x + penWidth / 2 + offset,
+        y + penWidth / 2 + offset,
+        qMax(1, width - penWidth - offset),
+        qMax(1, height - penWidth - offset),
+        radius, radius);
+}
+
+//---------------------------------------------------------------------
diff --git a/tools/rectangular/kpToolRoundedRectangle.h b/tools/rectangular/kpToolRoundedRectangle.h
index 22b4fe76..6b5f74ae 100644
--- a/tools/rectangular/kpToolRoundedRectangle.h
+++ b/tools/rectangular/kpToolRoundedRectangle.h
@@ -39,6 +39,11 @@ Q_OBJECT
 
 public:
     kpToolRoundedRectangle (kpToolEnvironment *environ, QObject *parent);
+
+    static void drawRoundedRect(kpImage *image,
+        int x, int y, int width, int height,
+        const kpColor &fcolor, int penWidth,
+        const kpColor &bcolor);
 };
 
 


More information about the kde-doc-english mailing list