[Kst] branches/work/kst/portto4/kst/src

Barth Netterfield netterfield at astro.utoronto.ca
Sat Mar 3 18:25:12 UTC 2012


SVN commit 1283406 by netterfield:

- Only show 'lock pos to data' when it is relevant (ie, parent is a plot
render item).

- Lock the location of the bottom right of a text label, not the center. 
Also add low level code for this to be the bottom left instead.  The
ability to switch this awaits a UI.


 M  +1 -0      libkstapp/cartesianrenderitem.h  
 M  +6 -0      libkstapp/dimensionstab.cpp  
 M  +16 -9     libkstapp/labelitem.cpp  
 M  +2 -0      libkstapp/labelitem.h  
 M  +5 -1      libkstapp/viewitem.cpp  
 M  +1 -0      libkstapp/viewitem.h  
 M  +1 -1      libkstmath/builtinpalettes.h  


--- branches/work/kst/portto4/kst/src/libkstapp/cartesianrenderitem.h #1283405:1283406
@@ -28,6 +28,7 @@
 
     bool configureFromXml(QXmlStreamReader &xml, ObjectStore *store);
     const QString defaultsGroupName() const {return QString("plot");}
+    virtual bool dataPosLockable() const {return false;}
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/dimensionstab.cpp #1283405:1283406
@@ -10,6 +10,7 @@
  *                                                                         *
  ***************************************************************************/
 #include "dimensionstab.h"
+#include "plotitem.h"
 #include <QDebug>
 
 namespace Kst {
@@ -59,7 +60,12 @@
     _fixAspectRatio->setHidden(true);
   }
   _lockPosToData->setChecked(_viewItem->lockPosToData());
+  if (_viewItem->dataPosLockable()) {
+      _lockPosToData->show();
+  } else {
+      _lockPosToData->hide();
 }
+}
 
 
 void DimensionsTab::updateButtons() {
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #1283405:1283406
@@ -32,7 +32,7 @@
 namespace Kst {
 
 LabelItem::LabelItem(View *parent, const QString& txt)
-  : ViewItem(parent), _labelRc(0), _dirty(true), _text(txt), _height(0), _resized(false) {
+  : ViewItem(parent), _labelRc(0), _dirty(true), _text(txt), _height(0), _resized(false), _dataRelativeDimValid(false), _fixleft(false) {
   setTypeName("Label");
   setFixedSize(true);
   setLockAspectRatio(true);
@@ -368,12 +368,16 @@
 void LabelItem::updateDataRelativeRect( bool force) {
   CartesianRenderItem* plot = dynamic_cast<CartesianRenderItem*>(parentViewItem());
   if (plot) {
-    if ((!lockPosToData()) || force) {
-      QPointF P1 = (rect().topLeft() + rect().bottomLeft())/2;
-      QPointF P2 = (rect().topRight() + rect().bottomRight())/2;
+    if ((!lockPosToData()) || force || (!_dataRelativeDimValid)) {
+      _dataRelativeDimValid = ((fabs(rect().width())>1.1) && (fabs(rect().height())>1.1));
+      //QPointF P1 = (rect().topLeft() + rect().bottomLeft())/2;
+      //QPointF P2 = (rect().topRight() + rect().bottomRight())/2;
+      QPointF P1 = rect().bottomLeft();
+      QPointF P2 = rect().bottomRight();
       _dataRelativeRect.setTopLeft(plot->plotItem()->mapToProjection(mapToParent(P1)));
       _dataRelativeRect.setBottomRight(plot->plotItem()->mapToProjection(mapToParent(P2)));
-      _dataRelativeRect.moveCenter(plot->plotItem()->mapToProjection(mapToParent(rect().center())));
+      //qDebug() << "rel rect tl" << _dataRelativeRect.topLeft() << "rel rect br" << _dataRelativeRect.bottomRight();
+      //_dataRelativeRect.moveCenter(plot->plotItem()->mapToProjection(mapToParent(rect().center())));
     }
   }
 }
@@ -397,14 +401,17 @@
     QPointF P2(parentX + parentWidth*(drP2.x()-render_item->plotItem()->xMin())/parentDX,
                        parentY + parentHeight*(render_item->plotItem()->yMax() - drP2.y())/parentDY);
 
-    QPointF centerP = (P1 + P2) * 0.5;
     qreal theta = atan2(P2.y() - P1.y(), P2.x() - P1.x());
     qreal height = rect().height();
     qreal width = rect().width();
 
-    setPos(centerP.x(), centerP.y());
-    setViewRect(-width*0.5, -height*0.5, width, height);
-
+    if (_fixleft) {
+      setPos(P1);
+      setViewRect(0, -height, width, height);
+    } else {
+      setPos(P2);
+      setViewRect(-width, -height, width, height);
+    }
     QTransform transform;
     transform.rotateRadians(theta);
 
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.h #1283405:1283406
@@ -83,6 +83,8 @@
     QFont _font;
     qreal _height;
     bool _resized;
+    bool _dataRelativeDimValid;
+    bool _fixleft;
 };
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1283405:1283406
@@ -1133,15 +1133,19 @@
     menu.addSeparator();
     menu.addAction(_deleteAction);
   }
+  if (dataPosLockable()) {
   menu.addSeparator();
   menu.addAction(_lockPosToDataAction);
+  }
 
-
   addToMenuForContextEvent(menu);
 
   menu.exec(event->screenPos());
 }
 
+bool ViewItem::dataPosLockable() const {
+  return bool(qgraphicsitem_cast<PlotRenderItem *>(parentViewItem()));
+}
 
 void ViewItem::addToMenuForContextEvent(QMenu &menu) {
   Q_UNUSED(menu);
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #1283405:1283406
@@ -239,6 +239,7 @@
     void applyDialogDefaultsLockPosToData();
 
     virtual void applyDataLockedDimensions();
+    virtual bool dataPosLockable() const;
 
   Q_SIGNALS:
     void geometryChanged();
--- branches/work/kst/portto4/kst/src/libkstmath/builtinpalettes.h #1283405:1283406
@@ -36,7 +36,7 @@
 static const QString KstColorsName = "Kst Colors";
 
 static const int CycleCount = 1021;
-static const QString CycleName = "Cyclical Spectrum";
+static const QString CycleName = "Spectrum (Cyclical)";
 static unsigned char Cycle[1022][3] = {
 {128, 238, 17},
 {128, 238, 16},


More information about the Kst mailing list