From 1dbdd1511e8a05a1adb212a7b24750d500982462 Mon Sep 17 00:00:00 2001
From: Ben Reynwar <ben@reynwar.net>
Date: Mon, 15 Oct 2012 10:51:39 -0700
Subject: qtgui: Adding hooks to allow appearance customization with
 stylesheets.

---
 gr-qtgui/lib/DisplayPlot.cc | 278 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 214 insertions(+), 64 deletions(-)

(limited to 'gr-qtgui/lib/DisplayPlot.cc')

diff --git a/gr-qtgui/lib/DisplayPlot.cc b/gr-qtgui/lib/DisplayPlot.cc
index ca3f7899be..1c7931accd 100644
--- a/gr-qtgui/lib/DisplayPlot.cc
+++ b/gr-qtgui/lib/DisplayPlot.cc
@@ -27,10 +27,12 @@
 #include <QColor>
 #include <cmath>
 #include <iostream>
+#include <QDebug>
 
 DisplayPlot::DisplayPlot(int nplots, QWidget* parent)
   : QwtPlot(parent), _nplots(nplots), _stop(false)
 {
+  qRegisterMetaType<QColorList>("QColorList");
   resize(parent->width(), parent->height());
 
   // Disable polygon clipping
@@ -46,9 +48,8 @@ DisplayPlot::DisplayPlot(int nplots, QWidget* parent)
   canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
 #endif
 
-  QPalette palette;
-  palette.setColor(canvas()->backgroundRole(), QColor("white"));
-  canvas()->setPalette(palette);
+  QColor default_palette_color = QColor("white");
+  setPaletteColor(default_palette_color);
 
   _panner = new QwtPlotPanner(canvas());
   _panner->setAxisEnabled(QwtPlot::yRight, false);
@@ -59,7 +60,7 @@ DisplayPlot::DisplayPlot(int nplots, QWidget* parent)
 
 #if QWT_VERSION < 0x060000
   connect(_picker, SIGNAL(selected(const QwtDoublePoint &)),
-	  this, SLOT(OnPickerPointSelected(const QwtDoublePoint &)));
+      this, SLOT(OnPickerPointSelected(const QwtDoublePoint &)));
 #else
   _picker->setStateMachine(new QwtPickerDblClickPointMachine());
   connect(_picker, SIGNAL(selected(const QPointF &)),
@@ -90,6 +91,7 @@ DisplayPlot::~DisplayPlot()
   // _zoomer and _panner deleted when parent deleted
 }
 
+
 void
 DisplayPlot::setYaxis(double min, double max)
 {
@@ -117,99 +119,247 @@ DisplayPlot::title(int which)
 }
 
 void
-DisplayPlot::setColor(int which, QString color)
+DisplayPlot::setColor(int which, QColor color)
 {
-  // Set the color of the pen
-  QPen pen(_plot_curve[which]->pen());
-  pen.setColor(color);
-  _plot_curve[which]->setPen(pen);
-
-  // And set the color of the markers
+  if (which < _nplots) {
+    // Set the color of the pen
+    QPen pen(_plot_curve[which]->pen());
+    pen.setColor(color);
+    _plot_curve[which]->setPen(pen);
+    // And set the color of the markers
 #if QWT_VERSION < 0x060000
-  //_plot_curve[which]->setBrush(QBrush(QColor(color)));
-  _plot_curve[which]->setPen(pen);
-
-  QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
-  setLineMarker(which, sym.style());
+    //_plot_curve[which]->setBrush(QBrush(QColor(color)));
+    _plot_curve[which]->setPen(pen);
+    QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
+    setLineMarker(which, sym.style());
 #else
-  QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-  sym->setColor(color);
-  sym->setPen(pen);
-  _plot_curve[which]->setSymbol(sym);
+    QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+    sym->setColor(color);
+    sym->setPen(pen);
+    _plot_curve[which]->setSymbol(sym);
 #endif
+  }
+}
+
+QColor
+DisplayPlot::getColor(int which) const {
+  // If that plot doesn't exist then return black.
+  if (which < _nplots)
+    return _plot_curve[which]->pen().color();
+  return QColor("black");
+}
+
+// Use a preprocessor macro to create a bunch of hooks for Q_PROPERTY and hence the stylesheet.
+#define SETUPLINE(i, im1) \
+    void DisplayPlot::setLineColor ## i (QColor c) {setColor(im1, c);} \
+    const QColor DisplayPlot::getLineColor ## i () const {return getColor(im1);} \
+    void DisplayPlot::setLineWidth ## i (int width) {setLineWidth(im1, width);} \
+    int DisplayPlot::getLineWidth ## i () const {return getLineWidth(im1);} \
+    void DisplayPlot::setLineStyle ## i (Qt::PenStyle ps) {setLineStyle(im1, ps);} \
+    const Qt::PenStyle DisplayPlot::getLineStyle ## i () const {return getLineStyle(im1);} \
+    void DisplayPlot::setLineMarker ## i (QwtSymbol::Style ms) {setLineMarker(im1, ms);} \
+    const QwtSymbol::Style DisplayPlot::getLineMarker ## i () const {return getLineMarker(im1);} \
+    void DisplayPlot::setMarkerAlpha ## i (int alpha) {setMarkerAlpha(im1, alpha);} \
+    int DisplayPlot::getMarkerAlpha ## i () const {return getMarkerAlpha(im1);}
+SETUPLINE(1, 0)
+SETUPLINE(2, 1)
+SETUPLINE(3, 2)
+SETUPLINE(4, 3)
+SETUPLINE(5, 4)
+SETUPLINE(6, 5)
+SETUPLINE(7, 6)
+SETUPLINE(8, 7)
+SETUPLINE(9, 8)
+
+void
+DisplayPlot::setZoomerColor(QColor c) {
+  _zoomer->setRubberBandPen(c);
+  _zoomer->setTrackerPen(c);
+}
+
+QColor
+DisplayPlot::getZoomerColor() const {
+  return _zoomer->rubberBandPen().color();
+}
+
+void
+DisplayPlot::setPaletteColor(QColor c) {
+  QPalette palette;
+  palette.setColor(canvas()->backgroundRole(), c);
+  canvas()->setPalette(palette);
+}
+
+QColor
+DisplayPlot::getPaletteColor() const {
+  return canvas()->palette().color(canvas()->backgroundRole());
+}
+
+void
+DisplayPlot::setAxisLabelFontSize(int axisId, int fs) {
+  QwtText axis_title = QwtText(axisWidget(axisId)->title());
+  QFont font = QFont(axis_title.font());
+  font.setPointSize(fs);
+  axis_title.setFont(font);
+  axisWidget(axisId)->setTitle(axis_title);
+}
+
+int
+DisplayPlot::getAxisLabelFontSize(int axisId) const {
+  return axisWidget(axisId)->title().font().pointSize();
+}
+
+void
+DisplayPlot::setYaxisLabelFontSize(int fs) {
+  setAxisLabelFontSize(QwtPlot::yLeft, fs);
+}
+
+int
+DisplayPlot::getYaxisLabelFontSize() const {
+  int fs = getAxisLabelFontSize(QwtPlot::yLeft);
+  return fs;
+}
+
+void
+DisplayPlot::setXaxisLabelFontSize(int fs) {
+  setAxisLabelFontSize(QwtPlot::xBottom, fs);
+}
+
+int
+DisplayPlot::getXaxisLabelFontSize() const {
+  int fs = getAxisLabelFontSize(QwtPlot::xBottom);
+  return fs;
+}
+
+void
+DisplayPlot::setAxesLabelFontSize(int fs) {
+  setAxisLabelFontSize(QwtPlot::yLeft, fs);
+  setAxisLabelFontSize(QwtPlot::xBottom, fs);
+}
+
+int
+DisplayPlot::getAxesLabelFontSize() const {
+  // Returns 0 if all axes do not have the same font size.
+  int fs = getAxisLabelFontSize(QwtPlot::yLeft);
+  if (getAxisLabelFontSize(QwtPlot::xBottom) != fs)
+    return 0;
+  return fs;
 }
 
 void
 DisplayPlot::setLineWidth(int which, int width)
 {
-  // Set the new line width
-  QPen pen(_plot_curve[which]->pen());
-  pen.setWidth(width);
-  _plot_curve[which]->setPen(pen);
-
-  // Scale the marker size proportionally
+  if (which < _nplots) {
+    // Set the new line width
+    QPen pen(_plot_curve[which]->pen());
+    pen.setWidth(width);
+    _plot_curve[which]->setPen(pen);
+    
+    // Scale the marker size proportionally
 #if QWT_VERSION < 0x060000
-  QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
-  sym.setSize(7+10*log10(1.0*width), 7+10*log10(1.0*width));
-  _plot_curve[which]->setSymbol(sym);
+    QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
+    sym.setSize(7+10*log10(1.0*width), 7+10*log10(1.0*width));
+    _plot_curve[which]->setSymbol(sym);
 #else
-  QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-  sym->setSize(7+10*log10(1.0*width), 7+10*log10(1.0*width));
-  _plot_curve[which]->setSymbol(sym);
+    QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+    sym->setSize(7+10*log10(1.0*width), 7+10*log10(1.0*width));
+    _plot_curve[which]->setSymbol(sym);
 #endif
+  }
+}
+
+int
+DisplayPlot::getLineWidth(int which) const {
+  if (which < _nplots) {
+    return _plot_curve[which]->pen().width();
+  } else {
+    return 0;
+  }
 }
 
 void
 DisplayPlot::setLineStyle(int which, Qt::PenStyle style)
 {
-  QPen pen(_plot_curve[which]->pen());
-  pen.setStyle(style);
-  _plot_curve[which]->setPen(pen);
+  if (which < _nplots) {
+    QPen pen(_plot_curve[which]->pen());
+    pen.setStyle(style);
+    _plot_curve[which]->setPen(pen);
+  }
+}
+
+const Qt::PenStyle
+DisplayPlot::getLineStyle(int which) const
+{
+  if (which < _nplots) {
+    return _plot_curve[which]->pen().style();
+  } else {
+    return Qt::SolidLine;
+  }
 }
 
 void
 DisplayPlot::setLineMarker(int which, QwtSymbol::Style marker)
 {
+  if (which < _nplots) {
 #if QWT_VERSION < 0x060000
-  QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
-  QPen pen(_plot_curve[which]->pen());
-  QBrush brush(pen.color());
-  sym.setStyle(marker);
-  sym.setPen(pen);
-  sym.setBrush(brush);
-  _plot_curve[which]->setSymbol(sym);
+    QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
+    QPen pen(_plot_curve[which]->pen());
+    QBrush brush(pen.color());
+    sym.setStyle(marker);
+    sym.setPen(pen);
+    sym.setBrush(brush);
+    _plot_curve[which]->setSymbol(sym);
 #else
-  QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-  sym->setStyle(marker);
-  _plot_curve[which]->setSymbol(sym);
+    QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+    sym->setStyle(marker);
+    _plot_curve[which]->setSymbol(sym);
 #endif
+  }
+}
+
+const QwtSymbol::Style
+DisplayPlot::getLineMarker(int which) const
+{
+  if (which < _nplots) {
+    return _plot_curve[which]->symbol().style();
+  } else {
+    return QwtSymbol::NoSymbol;
+  }
 }
 
 void
 DisplayPlot::setMarkerAlpha(int which, int alpha)
 {
-  // Get the pen color
-  QPen pen(_plot_curve[which]->pen());
-  QColor color = pen.color();
-
-  // Set new alpha and update pen
-  color.setAlpha(alpha);
-  pen.setColor(color);
-  _plot_curve[which]->setPen(pen);
-
-  // And set the new color for the markers
+  if (which < _nplots) {
+    // Get the pen color
+    QPen pen(_plot_curve[which]->pen());
+    QColor color = pen.color();
+    
+    // Set new alpha and update pen
+    color.setAlpha(alpha);
+    pen.setColor(color);
+    _plot_curve[which]->setPen(pen);
+    
+    // And set the new color for the markers
 #if QWT_VERSION < 0x060000
-  //_plot_curve[which]->setBrush(QBrush(QColor(color)));
-  _plot_curve[which]->setPen(pen);
-
-  QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
-  setLineMarker(which, sym.style());
+    QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
+    setLineMarker(which, sym.style());
 #else
-  QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-  sym->setColor(color);
-  sym->setPen(pen);
-  _plot_curve[which]->setSymbol(sym);
+    QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+    sym->setColor(color);
+    sym->setPen(pen);
+    _plot_curve[which]->setSymbol(sym);
 #endif
+  }
+}
+
+int
+DisplayPlot::getMarkerAlpha(int which) const
+{
+  if (which < _nplots) {
+    return _plot_curve[which]->pen().color().alpha();
+  } else {
+    return 0;
+  }
 }
 
 void
-- 
cgit v1.2.3


From 8740eb0d9460060ae97f9d252cae81cdcf0e20e5 Mon Sep 17 00:00:00 2001
From: Tom Rondeau <trondeau@vt.edu>
Date: Mon, 12 Nov 2012 21:12:18 -0500
Subject: qtgui: fixed a few bugs under qwt6. Made checks around the symbol
 pointers.

---
 gr-qtgui/lib/DisplayPlot.cc | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

(limited to 'gr-qtgui/lib/DisplayPlot.cc')

diff --git a/gr-qtgui/lib/DisplayPlot.cc b/gr-qtgui/lib/DisplayPlot.cc
index 1c7931accd..2b982b77d2 100644
--- a/gr-qtgui/lib/DisplayPlot.cc
+++ b/gr-qtgui/lib/DisplayPlot.cc
@@ -134,9 +134,11 @@ DisplayPlot::setColor(int which, QColor color)
     setLineMarker(which, sym.style());
 #else
     QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-    sym->setColor(color);
-    sym->setPen(pen);
-    _plot_curve[which]->setSymbol(sym);
+    if(sym) {
+      sym->setColor(color);
+      sym->setPen(pen);
+      _plot_curve[which]->setSymbol(sym);
+    }
 #endif
   }
 }
@@ -261,8 +263,10 @@ DisplayPlot::setLineWidth(int which, int width)
     _plot_curve[which]->setSymbol(sym);
 #else
     QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-    sym->setSize(7+10*log10(1.0*width), 7+10*log10(1.0*width));
-    _plot_curve[which]->setSymbol(sym);
+    if(sym) {
+      sym->setSize(7+10*log10(1.0*width), 7+10*log10(1.0*width));
+      _plot_curve[which]->setSymbol(sym);
+    }
 #endif
   }
 }
@@ -310,8 +314,10 @@ DisplayPlot::setLineMarker(int which, QwtSymbol::Style marker)
     _plot_curve[which]->setSymbol(sym);
 #else
     QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-    sym->setStyle(marker);
-    _plot_curve[which]->setSymbol(sym);
+    if(sym) {
+      sym->setStyle(marker);
+      _plot_curve[which]->setSymbol(sym);
+    }
 #endif
   }
 }
@@ -319,9 +325,16 @@ DisplayPlot::setLineMarker(int which, QwtSymbol::Style marker)
 const QwtSymbol::Style
 DisplayPlot::getLineMarker(int which) const
 {
-  if (which < _nplots) {
-    return _plot_curve[which]->symbol().style();
-  } else {
+  if(which < _nplots) {
+#if QWT_VERSION < 0x060000
+    QwtSymbol sym = (QwtSymbol)_plot_curve[which]->symbol();
+    return sym.style();
+#else
+    QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+    return sym->style();
+#endif
+  }
+  else {
     return QwtSymbol::NoSymbol;
   }
 }
@@ -345,9 +358,11 @@ DisplayPlot::setMarkerAlpha(int which, int alpha)
     setLineMarker(which, sym.style());
 #else
     QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
-    sym->setColor(color);
-    sym->setPen(pen);
-    _plot_curve[which]->setSymbol(sym);
+    if(sym) {
+      sym->setColor(color);
+      sym->setPen(pen);
+      _plot_curve[which]->setSymbol(sym);
+    }
 #endif
   }
 }
-- 
cgit v1.2.3