Bug 136125 - remove points in curve by dragging them out of the area
Summary: remove points in curve by dragging them out of the area
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: General (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: Camilla Boemann
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-22 11:00 UTC by Thomas Zander
Modified: 2007-01-10 00:25 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Zander 2006-10-22 11:00:08 UTC
Version:           1.6.0 (using KDE 3.5.1 Level "a" , SUSE 10.1)
Compiler:          Target: i586-suse-linux
OS:                Linux (i686) release 2.6.16.13-4-default

Some people found that the removing of a point in a curve widget (like used in the Color Adjustment filter) was too hard to find.
One solution would be to add a method which is used in other software.  I would like to suggest we also remove a point when its dragged well outside of the curve widget.

Suggested behavior;

I click somewhere in the center of the curve widget, which adds a new point.
I realize I don't need it anymore so I drag the point to the edge of the widget. The curve adjusts to show the point is at the edge.
I keep dragging the point further out of the widget and after about 15 pixels the point is removed from the curve.  The curve is redrawn without the point.

If I do not release the mouse and keep dragging it back into the curve widget then a point is added to the location my mouse is at.

As a sidenote; pressing escape while dragging should undo the entire drag. Which is a bug in general for that widget.
Comment 1 Camilla Boemann 2006-10-22 11:43:34 UTC
I like that suggestion and will implement it soon
Comment 2 Camilla Boemann 2006-10-22 15:21:01 UTC
SVN commit 598084 by boemann:

When hitting escape during dragging a point the drag will be canceled

When dragging a point more than 15 pixels outside the widget the point 
is deleted (unless you drag it back inside)

hitting exacpe while dragging outside will probably crash at the moment

Can't test it as krita is not working at the moment

CCBUG: 136125


 M  +54 -12    kcurve.cc  
 M  +4 -0      kcurve.h  


--- trunk/koffice/krita/ui/kcurve.cc #598083:598084
@@ -118,6 +118,18 @@
         }
         repaint();
     }
+    else if(e->key() == Qt::Key_Escape)
+    {
+        if(m_dragging)
+        {
+            m_points[m_grab_point_index].first = m_grabOriginalX;
+            m_points[m_grab_point_index].second = m_grabOriginalY;
+            setCursor( KCursor::arrowCursor() );
+            m_dragging = false;
+            repaint();
+            emit modified();
+        }
+    }
     else
         QWidget::keyPressEvent(e);
 }
@@ -250,11 +262,14 @@
         m_grab_point_index = closest_point_index;
     }
 
+    m_grabOriginalX = m_points[m_grab_point_index].first;
+    m_grabOriginalY = m_points[m_grab_point_index].second;
     m_grabOffsetX = m_points[m_grab_point_index].first - x;
     m_grabOffsetY = m_points[m_grab_point_index].second - y;
     m_points[m_grab_point_index].first = x + m_grabOffsetX;
     m_points[m_grab_point_index].second = y + m_grabOffsetY;
     m_dragging = true;
+    m_draggedawaypointindex = -1;
 
     setCursor( KCursor::crossCursor() );
     repaint();
@@ -291,35 +306,54 @@
     }
     else  // Else, drag the selected point
     {
+        bool removepoint = e->pos().x() - width() >15 || e->pos().x()< -15 || e->pos().y() - height() >15 || e->pos().y()< -15;
+
+        if (removepoint == false && m_draggedawaypointindex != -1)
+        {
+            // point is no longer dragged away so reinsert it
+            QPair<double,double> newPoint(m_draggedawaypoint);
+            m_points.insert(m_draggedawaypointindex, newPoint);
+            m_grab_point_index = m_draggedawaypointindex;
+            m_draggedawaypointindex = -1;
+        }
+
+        if (removepoint == true && m_draggedawaypointindex != -1)
+            return;
+
         setCursor( KCursor::crossCursor() );
 
         x += m_grabOffsetX;
         y += m_grabOffsetY;
 
+        double leftX;
+        double rightX;
         if (m_grab_point_index == 0)
         {
-            x = 0;
+            leftX = 0.0;
+            rightX = m_points[m_grab_point_index + 1].first + 1E-4;
         }
         else if (m_grab_point_index == m_points.count() - 1)
         {
-            x = 1;
+            leftX = m_points[m_grab_point_index - 1].first + 1E-4;
+            rightX = 0.0;
         }
         else
         {
             Q_ASSERT(m_grab_point_index > 0 && m_grab_point_index < m_points.count() - 1);
 
-            double leftX = m_points[m_grab_point_index - 1].first;
-            double rightX = m_points[m_grab_point_index + 1].first;
+            // the 1E-4 addition so we can grab the dot later.
+            leftX = m_points[m_grab_point_index - 1].first + 1E-4;
+            rightX = m_points[m_grab_point_index + 1].first + 1E-4;
+        }
 
-            if (x <= leftX)
-            {
-                x = leftX + 1E-4; // the addition so we can grab the dot later.
-            }
-            else if (x >= rightX)
-            {
-                x = rightX - 1E-4;
-            }
+        if (x <= leftX)
+        {
+            x = leftX;
         }
+        else if (x >= rightX)
+        {
+            x = rightX;
+        }
 
         if(y > 1.0)
             y = 1.0;
@@ -330,6 +364,14 @@
         m_points[m_grab_point_index].first = x;
         m_points[m_grab_point_index].second = y;
 
+        if (removepoint)
+        {
+            m_draggedawaypoint.first = m_points[m_grab_point_index].first;
+            m_draggedawaypoint.second = m_points[m_grab_point_index].second;
+            m_draggedawaypointindex = m_grab_point_index;
+            m_points.removeAt(m_grab_point_index);
+        }
+
         emit modified();
     }
 
--- trunk/koffice/krita/ui/kcurve.h #598083:598084
@@ -74,6 +74,10 @@
     bool m_dragging;
     double m_grabOffsetX;
     double m_grabOffsetY;
+    double m_grabOriginalX;
+    double m_grabOriginalY;
+    QPair<double,double>m_draggedawaypoint;
+    int m_draggedawaypointindex;
 
     bool m_readOnlyMode;
     bool m_guideVisible;
Comment 3 Camilla Boemann 2007-01-10 00:25:40 UTC
Implemented and tested (will be part of koffice 2.0)