[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1228: Plot the send and receive data in the bandwidth graph as sem (trunk/src/gui/bwgraph)



Author: edmanm
Date: 2006-09-22 22:26:47 -0400 (Fri, 22 Sep 2006)
New Revision: 1228

Modified:
   trunk/src/gui/bwgraph/graphframe.cpp
   trunk/src/gui/bwgraph/graphframe.h
Log:
Plot the send and receive data in the bandwidth graph as semi-transparent,
alpha-blended integrals with opaque outlines.


Modified: trunk/src/gui/bwgraph/graphframe.cpp
===================================================================
--- trunk/src/gui/bwgraph/graphframe.cpp	2006-09-22 23:04:30 UTC (rev 1227)
+++ trunk/src/gui/bwgraph/graphframe.cpp	2006-09-23 02:26:47 UTC (rev 1228)
@@ -146,10 +146,8 @@
 
   /* Paint the scale */
   paintScale();
-
-  /* Paint the send/receive lines */
-  paintLines();
-
+  /* Plot the send/receive data */
+  paintData();
   /* Paint the send/recv totals */
   paintTotals();
 
@@ -157,31 +155,72 @@
   _painter->end();
 }
 
-/**
- Calls paint function for each line that is supposed to 
- be painted.
-*/
+/** Paints an integral and an outline of that integral for each data set (send
+ * and/or receive) that is to be displayed. The integrals will be drawn first,
+ * followed by the outlines, since we want the area of overlapping integrals
+ * to blend, but not the outlines of those integrals. */
 void
-GraphFrame::paintLines()
+GraphFrame::paintData()
 {
-  /* If show received rate is selected */
+  /* Draw the integrals using an alpha-blending, giving the background
+   * integral a little more weight than the foreground. This could probably be
+   * tweaked more to make overlapping more apparent, including tweaking the 
+   * colors`. */
   if (_showRecv) {
-    _painter->setPen(QPen(RECV_COLOR, 2));
-    paintLine(_recvData);
+    paintIntegral(_recvData, RECV_COLOR, 0.6);
   }
-
+  if (_showSend) {
+    paintIntegral(_sendData, SEND_COLOR, 0.4);
+  }
+  
+  /* Outline the integrals in their appropriate colors. */
+  if (_showRecv) {
+    paintLine(_recvData, RECV_COLOR);
+  }
   /* If show send rate is selected */
   if (_showSend) {
-    _painter->setPen(QPen(SEND_COLOR, 2));
-    paintLine(_sendData);
+    paintLine(_sendData, SEND_COLOR);
   }
 }
 
+/** Plots an integral using the data points in <b>list</b>. The area will be
+ * filled in using <b>color</b> and an alpha-blending level of <b>alpha</b>
+ * (default is opaque). */
+void
+GraphFrame::paintIntegral(QList<qreal>* list, QColor color, qreal alpha)
+{
+  QVector<QPointF> points;
+  int x = _rec.width();
+  int y = _rec.height();
+  qreal scale = (y - (y/10)) / _maxValue;
+  qreal currValue;
+  
+  /* Translate all data points to points on the graph frame */
+  points << QPointF(x, y);
+  for (int i = 0; i < list->size(); i++) {
+    currValue = y - (list->at(i) * scale);
+    if (x - SCROLL_STEP < SCALE_WIDTH) {
+      points << QPointF(SCALE_WIDTH, currValue);
+      break;
+    }
+    points << QPointF(x, currValue);
+    x -= SCROLL_STEP;
+  }
+  points << QPointF(SCALE_WIDTH, y);
+  
+  /* Save the current brush, plot the integral, and restore the old brush */
+  QBrush oldBrush = _painter->brush();
+  color.setAlphaF(alpha);
+  _painter->setBrush(QBrush(color));
+  _painter->drawPolygon(points.data(), points.size());
+  _painter->setBrush(oldBrush);
+}
+
 /** Iterates the input list and draws a line on the graph
  in the appropriate color
 */
 void
-GraphFrame::paintLine(QList<qreal>* list)
+GraphFrame::paintLine(QList<qreal>* list, QColor color, Qt::PenStyle lineStyle) 
 {
   int x = _rec.width() + SCROLL_STEP;
   int y = _rec.height();
@@ -189,7 +228,10 @@
   
   qreal prevValue = y - (list->at(0) * scale);
   qreal currValue;
-  
+ 
+  /* Save the current pen, set the new pen and plot the data lines */
+  QPen oldPen = _painter->pen();
+  _painter->setPen(QPen(color, lineStyle));
   for (int i = 0; i < list->size(); ++i) {
     currValue = y - (list->at(i) * scale);
     
@@ -207,6 +249,7 @@
     prevValue = currValue;
     x -= SCROLL_STEP;
   }
+  _painter->setPen(oldPen);
 }
 
 /**

Modified: trunk/src/gui/bwgraph/graphframe.h
===================================================================
--- trunk/src/gui/bwgraph/graphframe.h	2006-09-22 23:04:30 UTC (rev 1227)
+++ trunk/src/gui/bwgraph/graphframe.h	2006-09-23 02:26:47 UTC (rev 1228)
@@ -70,8 +70,10 @@
 private:
   /** Gets the width of the desktop, the max # of points **/
   int getNumPoints();
-  /** Paints appropriate lines on the graph **/
-  void paintLines();
+  
+  /** Paints an integral and an outline of that integral for each data set
+   * (send and/or receive) that is to be displayed. */
+  void paintData();
   /** Paints the send/receive totals **/
   void paintTotals();
   /** Paints the scale in the graph **/
@@ -79,7 +81,10 @@
   /** Returns a formatted string representation of total **/
   QString totalToStr(qreal total);
   /** Paints a line with the data in list **/
-  void paintLine(QList<qreal>* list);
+  void paintLine(QList<qreal>* list, QColor color, 
+                 Qt::PenStyle lineStyle = Qt::SolidLine);
+  /** Paints an integral using the supplied data. */
+  void paintIntegral(QList<qreal>* list, QColor color, qreal alpha = 1.0);
 
   /** A QPainter object that handles drawing the various graph elements */
   QPainter* _painter;