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

Barth Netterfield netterfield at astro.utoronto.ca
Wed Aug 11 22:58:46 CEST 2010


SVN commit 1162330 by netterfield:

Correct legend size and placement from the data wizard.



 M  +3 -5      datawizard.cpp  
 M  +14 -8     labelitem.cpp  
 M  +4 -4      legenditem.cpp  
 M  +1 -0      legenditem.h  
 M  +8 -2      plotitem.cpp  
 M  +2 -2      plotitem.h  
 M  +1 -1      plotrenderitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #1162329:1162330
@@ -1027,7 +1027,6 @@
     }
   }
 
-  double fontScale;
   if (plotsInPage==0 || _pagePlot->rescaleFonts()) {
     int np = plotList.count();
     if (np > 0) {
@@ -1047,16 +1046,15 @@
     plot->parentView()->appendToLayout(_pagePlot->layout(), plot, _pagePlot->gridColumns());
 
   }
+  double fontScale;
   fontScale = ApplicationSettings::self()->defaultFontScale();
 
   foreach (PlotItem* plot, plotList) {
     if (_pagePlot->legendsOn()) {
-      plot->setShowLegend(true);
-      plot->legend()->setFontScale(fontScale);
+      plot->setShowLegend(true, true);
     } else if (_pagePlot->legendsAuto()) {
       if (plot->renderItem(PlotRenderItem::Cartesian)->relationList().count() > 1) {
-        plot->setShowLegend(true);
-        plot->legend()->setFontScale(fontScale);
+        plot->setShowLegend(true, true);
       }
     }
   }
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #1162329:1162330
@@ -157,16 +157,18 @@
 
 
 void LabelItem::creationPolygonChanged(View::CreationEvent event) {
-  if (event != View::MouseRelease) {
-    ViewItem::creationPolygonChanged(event);
-    return;
+
+  if (event == View::MouseMove) {
+    if (parentView()->creationPolygon(View::MouseMove).size()>0) {
+      const QPointF P = parentView()->creationPolygon(View::MouseMove).last();
+      setPos(P);
+      setDirty();
   }
-
-  if (event == View::MouseRelease) {
-    const QPolygonF poly = mapFromScene(parentView()->creationPolygon(View::MouseRelease));
+  } else if (event == View::MouseRelease) {
+    const QPointF P = mapFromScene(parentView()->creationPolygon(event).last());
     QRectF newRect(rect().x(), rect().y(),
-                   poly.last().x() - rect().x(),
-                   poly.last().y() - rect().y());
+                   P.x() - rect().x(),
+                   P.y() - rect().y());
 
     if (newRect.isNull()) {
       // Special case for labels that don't need to have a size for creation to ensure proper parenting.
@@ -182,6 +184,8 @@
     emit creationComplete();
     setDirty();
     return;
+  } else if (event != View::MousePress) {
+    ViewItem::creationPolygonChanged(event);
   }
 }
 
@@ -205,10 +209,12 @@
 
     _item = new LabelItem(_view, text);
     LabelItem *label = qobject_cast<LabelItem*>(_item);
+
     label->setLabelScale(dialog.labelScale());
     label->setLabelColor(dialog.labelColor());
     label->setLabelFont(dialog.labelFont());
   }
+  _item->parentView()->scene()->addItem(_item);
 
   _view->setCursor(Qt::IBeamCursor);
 
--- branches/work/kst/portto4/kst/src/libkstapp/legenditem.cpp #1162329:1162330
@@ -35,8 +35,8 @@
 };
 
 
-LegendItem::LegendItem(PlotItem *parent)
-  : ViewItem(parent->parentView()), _plotItem(parent), _auto(true), _verticalDisplay(true) {
+LegendItem::LegendItem(PlotItem *parentPlot)
+  : ViewItem(parentPlot->parentView()), _plotItem(parentPlot), _auto(true), _verticalDisplay(true) {
   setTypeName("Legend");
 
   _initializeShortName();
@@ -46,9 +46,9 @@
 
   setViewRect(0.0, 0.0, 0.0, 0.0);
   parentView()->scene()->addItem(this);
-  setParent(_plotItem);
+  setParent(_plotItem->renderItem());
 
-  QPointF origin = QPointF(parent->width() * 0.15, parent->height() * 0.15);
+  QPointF origin = QPointF(_plotItem->plotRect().width() * 0.15, _plotItem->plotRect().height() * 0.15);
   setPos(origin);
 
   applyDefaults();
--- branches/work/kst/portto4/kst/src/libkstapp/legenditem.h #1162329:1162330
@@ -23,6 +23,7 @@
 namespace Kst {
 
 class PlotItem;
+class PlotRenderItem;
 
 class LegendItem : public ViewItem {
   Q_OBJECT
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1162329:1162330
@@ -790,6 +790,9 @@
 
 
 PlotRenderItem *PlotItem::renderItem(PlotRenderItem::RenderType type) {
+  if ((type == PlotRenderItem::First) && (_renderers.count()>0)) {
+    return _renderers.values().at(0);
+  }
   if (_renderers.contains(type))
     return _renderers.value(type);
 
@@ -2520,19 +2523,22 @@
   if (!_legend) {
     _legend = new LegendItem(this);
     _legend->setVisible(false);
-    _legend->setPos(rect().x() + width()*0.15, rect().y() + height()*0.15);
+    _legend->setPos(rect().x() + plotRect().width()*0.05, rect().y() + plotRect().height()*0.15);
     _legend->updateRelativeSize();
   }
   return _legend;
 }
 
 
-void PlotItem::setShowLegend(const bool show) {
+void PlotItem::setShowLegend(const bool show, const bool resetFonts) {
   if (show != _showLegend) {
     legend()->setVisible(show);
     _showLegend = show;
+    if (show && resetFonts) {
+      legend()->setFontScale(qMax(globalFontScale()*0.6, ApplicationSettings::self()->minimumFontSize()));
   }
 }
+}
 
 
 bool PlotItem::tryShortcut(const QString &keySequence) {
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #1162329:1162330
@@ -127,7 +127,7 @@
     virtual QString plotName() const; //from PlotItemInterface
 
     QList<PlotRenderItem*> renderItems() const;
-    PlotRenderItem *renderItem(PlotRenderItem::RenderType type);
+    PlotRenderItem *renderItem(PlotRenderItem::RenderType type=PlotRenderItem::First);
 
     virtual void save(QXmlStreamWriter &xml);
 
@@ -206,7 +206,7 @@
     void setGlobalFontColor(const QColor &color);
 
     bool showLegend() const;
-    void setShowLegend(const bool show);
+    void setShowLegend(const bool show, const bool resetFonts = false);
 
     qreal mapXToPlot(const qreal &x);
     qreal mapYToPlot(const qreal &y);
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #1162329:1162330
@@ -29,7 +29,7 @@
 {
   Q_OBJECT
   public:
-    enum RenderType { Cartesian, Polar, Sinusoidal };
+    enum RenderType {First, Cartesian, Polar, Sinusoidal };
 
     PlotRenderItem(PlotItem *parentItem);
     virtual ~PlotRenderItem();


More information about the Kst mailing list