[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/krita/ui/tool
From:       Lukáš Tvrdý <lukast.dev () gmail ! com>
Date:       2010-08-11 13:59:48
Message-ID: 20100811140135.1BF43AC7E9 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1162146 by lukast:

Improve color selecting strategy for freehand tool.

The behaviour regarding shortcuts is the same.
Now cursor for precision is showed (as requested by deevad).
Also the color is changed when you move with the tool around
canvas and you see the actual color picked in color selectors.

 M  +42 -21    kis_tool_freehand.cc  
 M  +3 -0      kis_tool_freehand.h  
 M  +2 -1      kis_tool_paint.h  


--- trunk/koffice/krita/ui/tool/kis_tool_freehand.cc #1162145:1162146
@@ -163,26 +163,18 @@
         return;
 
     // control-click gets the color at the current point. For now, only with a ratio \
                of 1
-    if (e->modifiers() & Qt::AltModifier && e->modifiers() & Qt::ControlModifier) {
-        if (e->button() == Qt::LeftButton)
-            canvas()->resourceManager()->setResource(KoCanvasResource::ForegroundColor,
                
-                                                     \
                KisToolUtils::pick(currentNode()->paintDevice(),
-                                                                        \
                convertToIntPixelCoord(e)));
-        else
-            canvas()->resourceManager()->setResource(KoCanvasResource::BackgroundColor,
                
-                                                     \
                KisToolUtils::pick(currentNode()->paintDevice(),
-                                                                        \
                convertToIntPixelCoord(e)));
-    } else if ( e->modifiers() & Qt::ControlModifier ) {
         // get the current color of the project, as per Deevad's suggestion.
         // this shouldn't be changed back to the current node :-)
-        KisPaintDeviceSP projection = image()->projection();
-        if (e->button() == Qt::LeftButton)
-            canvas()->resourceManager()->setResource(KoCanvasResource::ForegroundColor,
                
-                                                     KisToolUtils::pick(projection, \
                convertToIntPixelCoord(e)));
-        else
-            canvas()->resourceManager()->setResource(KoCanvasResource::BackgroundColor,
                
-                                                     KisToolUtils::pick(projection, \
convertToIntPixelCoord(e))); +    // CTRL+ALT picks color from current layer
+    // CTRL picks color from projection
+    if (e->modifiers() & Qt::ControlModifier) {
 
+        m_toForegroundColor = (e->button() == Qt::LeftButton);
+        pickColor(convertToIntPixelCoord(e),e->modifiers() & Qt::AltModifier);
+        m_mode = COLOR_PICKING;
+        useCursor(KisCursor::pickerCursor());
+        e->accept();
+        
     } else if (e->modifiers() == Qt::ShiftModifier) {
         m_mode = EDIT_BRUSH;
         m_prevMousePos = e->point;
@@ -262,6 +254,17 @@
     case PAN: {
             pan(e);
         }
+        break;
+    case COLOR_PICKING:{
+            useCursor(KisCursor::pickerCursor());
+            if (e->modifiers() & Qt::ControlModifier) {
+                pickColor(convertToIntPixelCoord(e), e->modifiers() & \
Qt::AltModifier); +            }else {
+                // DO Nothing
+            }
+            
+        }
+        break;
     default:
         ;
     }
@@ -304,15 +307,16 @@
 void KisToolFreehand::mouseReleaseEvent(KoPointerEvent* e)
 {
     KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2 *>(canvas());
-
-    if (canvas2->handlePopupPaletteIsVisible(e)) return;
+    if (canvas2->handlePopupPaletteIsVisible(e)) {
+        return;
+    }
     else if (e->button() == Qt::LeftButton) {
-
         //TODO: There is a bug here. If pop up palette is visible and a new colour \
                is selected,
         //the new colour will be added when the user clicks on the canvas to hide \
                the palette
         //This is used to handle recently used colour (KoFavoriteResourceManager)
         emit sigPainting();
     }
+    
     switch (m_mode) {
     case PAINT:
         if (!m_hasPaintAtLeastOnce)
@@ -330,7 +334,11 @@
     default:
         ;
     };
+    
+    if (m_mode != COLOR_PICKING){ 
     KisToolPaint::mouseReleaseEvent(e);
+    }
+    
     m_mode = HOVER;
     resetCursorStyle();
 }
@@ -345,7 +353,9 @@
         useCursor(Qt::OpenHandCursor);
 
         event->accept();
-    } else {
+    }/* else if (event->key() == Qt::Key_Control){ // we need to reset the cursor \
back when the user does not hold any key so commented so far +        \
useCursor(KisCursor::pickerCursor()); +    }*/else {
         event->ignore();
     }
 }
@@ -730,5 +740,16 @@
 }
 
 
+void KisToolFreehand::pickColor(const QPoint &pos, bool fromCurrentNode)
+{
+    int key = m_toForegroundColor ? KoCanvasResource::ForegroundColor : \
KoCanvasResource::BackgroundColor; +    if (fromCurrentNode){
+            canvas()->resourceManager()->setResource(key,KisToolUtils::pick( \
currentNode()->paintDevice(),pos)); +    } else /* projection */{
+            canvas()->resourceManager()->setResource(key,KisToolUtils::pick( \
image()->projection(), pos)); +    }
+}
+
+
 #include "kis_tool_freehand.moc"
 
--- trunk/koffice/krita/ui/tool/kis_tool_freehand.h #1162145:1162146
@@ -97,6 +97,7 @@
     QPointF adjustPosition(const QPointF& point);
     void queuePaintJob(FreehandPaintJob* job, FreehandPaintJob* previousJob);
     void showOutlineTemporary();
+    void pickColor(const QPoint &pos, bool currentNode);
     
 private slots:
 
@@ -160,6 +161,8 @@
     
     QTimer m_timer;
     bool m_showOutline;
+    
+    bool m_toForegroundColor;
 };
 
 
--- trunk/koffice/krita/ui/tool/kis_tool_paint.h #1162145:1162146
@@ -58,7 +58,8 @@
     PAINT,
     HOVER,
     EDIT_BRUSH,
-    PAN
+    PAN,
+    COLOR_PICKING
 };
 
 // wacom 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic