[PATCH 2/2] In "Brush Outline and Crosshair" mode Paint the crosshair instead of using the crosshair cursor

Silvio Heinrich plassy at web.de
Mon Jan 3 23:32:33 CET 2011


---
 krita/image/kis_global.h           |    1 +
 krita/ui/tool/kis_tool_freehand.cc |   29 +++++++++++++++++++++--
 krita/ui/tool/kis_tool_freehand.h  |    4 ++-
 krita/ui/tool/kis_tool_paint.cc    |   43 +++--------------------------------
 4 files changed, 34 insertions(+), 43 deletions(-)

diff --git a/krita/image/kis_global.h b/krita/image/kis_global.h
index beb8717..e74d7ef 100644
--- a/krita/image/kis_global.h
+++ b/krita/image/kis_global.h
@@ -1,6 +1,7 @@
 /*
  *  Copyright (c) 2000 Matthias Elter <elter at kde.org>
  *  Copyright (c) 2002 Patrick Julien <freak at codepimps.org>
+ *  Copyright (c) 2011 Silvio Heinrich <plassy at web.de>
  *
  *  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
diff --git a/krita/ui/tool/kis_tool_freehand.cc b/krita/ui/tool/kis_tool_freehand.cc
index 7077bca..7079fab 100644
--- a/krita/ui/tool/kis_tool_freehand.cc
+++ b/krita/ui/tool/kis_tool_freehand.cc
@@ -5,6 +5,7 @@
  *  Copyright (c) 2004 Bart Coppens <kde at bartcoppens.be>
  *  Copyright (c) 2007,2008,2010 Cyrille Berger <cberger at cberger.net>
  *  Copyright (c) 2009 Lukáš Tvrdý <lukast.dev at gmail.com>
+ *  Copyright (c) 2011 Silvio Heinrich <plassy at web.de>
  *
  *  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
@@ -578,7 +579,8 @@ void KisToolFreehand::paint(QPainter& gc, const KoViewConverter &converter)
             outlineMode = KisPaintOpSettings::CursorIsOutline;
         }
 
-        QPainterPath path = getOutlinePath(m_outlineDocPoint, outlineMode);
+        bool         withCrossHair = (cfg.cursorStyle() == CURSOR_STYLE_CROSS_OUTLINE);
+        QPainterPath path          = getOutlinePath(m_outlineDocPoint, outlineMode, withCrossHair);
         paintToolOutline(&gc,pixelToView(path));
     }
 }
@@ -593,8 +595,20 @@ QPointF KisToolFreehand::adjustPosition(const QPointF& point, const QPointF& str
 }
 
 QPainterPath KisToolFreehand::getOutlinePath(const QPointF &documentPos,
-                                             KisPaintOpSettings::OutlineMode outlineMode)
+                                             KisPaintOpSettings::OutlineMode outlineMode,
+                                             bool withCrossHair)
 {
+    static const int off = 1;
+    static const int len = 5;
+    static const int spc = 3;
+    
+    static const QPointF crossHairPts[8] = {
+        QPointF(-off,0), QPointF(-len,0),
+        QPointF(+off,0), QPointF(+len,0),
+        QPointF(0,-off), QPointF(0,-len),
+        QPointF(0,+off), QPointF(0,+len)
+    };
+    
     qreal scale = 1.0;
     qreal rotation = 0;
     if (m_painter && m_painter->paintOp()){
@@ -605,6 +619,15 @@ QPainterPath KisToolFreehand::getOutlinePath(const QPointF &documentPos,
     QPointF imagePos = currentImage()->documentToPixel(documentPos);
     QPainterPath path = currentPaintOpPreset()->settings()->
         brushOutline(imagePos, outlineMode, scale, rotation);
+    
+    qreal brushExtend = qMax(path.boundingRect().width(), path.boundingRect().height());
+    
+    if(brushExtend >= (len+spc)*2 && withCrossHair) {
+        for(int i=0; i<8; i+=2) {
+            path.moveTo(imagePos + crossHairPts[i+0]);
+            path.lineTo(imagePos + crossHairPts[i+1]);
+        }
+    }
 
     return path;
 }
@@ -623,7 +646,7 @@ void KisToolFreehand::decreaseBrushSize()
 
 void KisToolFreehand::updateOutlineRect()
 {
-    QRectF outlinePixelRect = getOutlinePath(m_outlineDocPoint, KisPaintOpSettings::CursorIsOutline).boundingRect();
+    QRectF outlinePixelRect = getOutlinePath(m_outlineDocPoint, KisPaintOpSettings::CursorIsOutline, false).boundingRect();
     QRectF outlineDocRect = currentImage()->pixelToDocument(outlinePixelRect);
 
     if(!m_oldOutlineRect.isEmpty()) {
diff --git a/krita/ui/tool/kis_tool_freehand.h b/krita/ui/tool/kis_tool_freehand.h
index f03c577..0d820fc 100644
--- a/krita/ui/tool/kis_tool_freehand.h
+++ b/krita/ui/tool/kis_tool_freehand.h
@@ -1,5 +1,6 @@
 /*
  *  Copyright (c) 2003-2008 Boudewijn Rempt <boud at valdyas.org>
+ *  Copyright (c) 2011 Silvio Heinrich <plassy at web.de>
  *
  *  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
@@ -107,7 +108,8 @@ private:
 
     void updateOutlineRect();
     QPainterPath getOutlinePath(const QPointF &documentPos,
-                                KisPaintOpSettings::OutlineMode outlineMode);
+                                KisPaintOpSettings::OutlineMode outlineMode,
+                                bool withCrossHair);
 
 private slots:
     void increaseBrushSize();
diff --git a/krita/ui/tool/kis_tool_paint.cc b/krita/ui/tool/kis_tool_paint.cc
index 1121985..0d36d25 100644
--- a/krita/ui/tool/kis_tool_paint.cc
+++ b/krita/ui/tool/kis_tool_paint.cc
@@ -1,5 +1,6 @@
 /*
  *  Copyright (c) 2003-2009 Boudewijn Rempt <boud at valdyas.org>
+ *  Copyright (c) 2011 Silvio Heinrich <plassy at web.de>
  *
  *  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
@@ -353,51 +354,17 @@ void KisToolPaint::resetCursorStyle()
 {
     KisTool::resetCursorStyle();
     KisConfig cfg;
-    
-    switch(cfg.cursorStyle())
-    {
-    case CURSOR_STYLE_OUTLINE:
-        if (m_supportOutline) {
-            useCursor(KisCursor::blankCursor());
-            break;
-        }
-        
-    case CURSOR_STYLE_CROSS_OUTLINE:
-        if (m_supportOutline) {
-            useCursor(KisCursor::crossCursor());
-            break;
-        }
-        
-#if defined(HAVE_OPENGL)
-    case CURSOR_STYLE_3D_MODEL:
-        if(isCanvasOpenGL()) {
-            if (m_supportOutline) {
-                useCursor(KisCursor::blankCursor());
-                break;
-            }
-        } else {
-            useCursor(KisCursor::arrowCursor());
-            break;
-        }
-#endif
-
-    default:
-        useCursor(cursor());
-        break;
-    }
-/*
     if (cfg.cursorStyle() == CURSOR_STYLE_OUTLINE || cfg.cursorStyle() == CURSOR_STYLE_CROSS_OUTLINE) {
         if (m_supportOutline) {
             // do not show cursor, tool will paint outline
             useCursor(KisCursor::blankCursor());
-            useCursor(KisCursor::crossCursor());
         } else {
             // if the tool does not support outline, use tool icon cursor
             useCursor(cursor());
         }
     }
-
-#if defined(HAVE_OPENGL)
+    
+    #if defined(HAVE_OPENGL)
     // TODO: maybe m_support 3D outline would be cooler. So far just freehand tool support 3D_MODEL cursor style
     if (cfg.cursorStyle() == CURSOR_STYLE_3D_MODEL) {
         if(isCanvasOpenGL()) {
@@ -410,9 +377,7 @@ void KisToolPaint::resetCursorStyle()
             useCursor(KisCursor::arrowCursor());
         }
     }
-#endif
-//*/
-
+    #endif
 }
 
 void KisToolPaint::updateTabletPressureSamples()
-- 
1.7.1


--------------050807040200040302070800--


More information about the kimageshop mailing list