[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Tue Jun 8 22:24:55 CEST 2004


CVS commit by staikos: 

half of data mode, for what it's worth. :-)


  M +1 -1      kst.cpp   1.141
  M +64 -1     kst2dplot.cpp   1.65
  M +1 -0      kst2dplot.h   1.28


--- kdeextragear-2/kst/kst/kst.cpp  #1.140:1.141
@@ -1128,5 +1128,5 @@ bool KstApp::dataMode() const {
 
 void KstApp::toggleDataMode() {
-  DataMode->setChecked(!DataMode->isChecked());
+  //DataMode->setChecked(!DataMode->isChecked());
 }
 

--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.64:1.65
@@ -171,4 +171,5 @@ void Kst2DPlot::commonConstructor(const 
                                 bool y_log) {
 
+  _copy_x = _copy_y = KST::NOPOINT;
   _standardActions |= Delete | Edit | Zoom | Pause;
   _type = "plot";
@@ -1889,5 +1890,67 @@ void Kst2DPlot::mouseMoveEvent(QWidget *
     }
   } else if (KstApp::inst()->dataMode()) {
-    // FIXME data mode implementation
+    double near_x, near_y;
+    double newxpos = 0, newypos = 0;
+    double d, best_d = 1.0E300;
+    int i_near_x;
+    KstBaseCurvePtr curve;
+    QPoint pos = e->pos();
+    QRect plot_rect = GetPlotRegion();
+
+    double xmin, ymin, xmax, ymax, xpos, ypos, dx_per_pix;
+    getLScale(xmin, ymin, xmax, ymax);
+
+    // find mouse location in plot units
+    xpos = (double)(pos.x() - plot_rect.left())/(double)plot_rect.width() *
+           (xmax - xmin) + xmin;
+    if (isXLog()) {
+      xpos = pow(10.0, xpos);
+    }
+
+    // convert 1 pixel to plot units.
+    dx_per_pix = (double)(pos.x()+2 - plot_rect.left())/
+                 (double)plot_rect.width() *
+                 (xmax - xmin) + xmin;
+    if (isXLog()) {
+      dx_per_pix = pow(10.0, dx_per_pix);
+    }
+    dx_per_pix -= xpos;
+
+    ypos = (double)(pos.y() - plot_rect.top())/(double)plot_rect.height();
+    ypos = ypos * (ymin - ymax) + ymax;
+
+    if (isYLog()) {
+      ypos = pow(10.0, ypos);
+    }
+
+    for (KstBaseCurveList::Iterator i = Curves.begin(); i != Curves.end(); ++i) {
+      i_near_x = (*i)->getIndexNearXY(xpos, dx_per_pix, ypos);
+      (*i)->getPoint(i_near_x, near_x, near_y);
+      d = fabs(ypos - near_y);
+      if (d < best_d) {
+        newypos = near_y;
+        newxpos = near_x;
+        best_d = d;
+        curve = *i;
+      }
+    }
+
+    if (curve.data()) {
+      //msg = i18n("%3 (%1, %2)").arg(newxpos).arg(newypos,0,'G').arg(curve->tagName());
+      if (_copy_x != newxpos || _copy_y != newypos) {
+        _copy_x = newxpos;
+        _copy_y = newypos;
+
+        //repaint(false);
+        QPainter p(view);
+        drawDotAt(p, newxpos, newypos);
+        //emit newDataMsg(msg);
+      }
+    } else {
+      _copy_x = KST::NOPOINT;
+      _copy_y = KST::NOPOINT;
+      //repaint(false);
+      //emit newDataMsg(QString::null);
+    }
   }
 

--- kdeextragear-2/kst/kst/kst2dplot.h  #1.27:1.28
@@ -250,4 +250,5 @@ private:
 
   KstBackBuffer _buffer;
+  double _copy_x, _copy_y;
 };
 





More information about the Kst mailing list