0.2 version add desktop components multitouch, joystick, multicast
[mardrone] / mardrone / gauges / gaugetape.cpp
diff --git a/mardrone/gauges/gaugetape.cpp b/mardrone/gauges/gaugetape.cpp
new file mode 100644 (file)
index 0000000..039026a
--- /dev/null
@@ -0,0 +1,116 @@
+
+#include "gaugetape.h"
+#include <stdio.h>
+#include <math.h>
+#include <qdebug.h>
+
+GaugeTape::GaugeTape(QGraphicsItem *parent) :
+    Gauge(parent)
+{
+}
+
+void GaugeTape::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
+                      QWidget *widget)
+{
+  int tpix;  // tick division in pixels
+
+  int fval;     // First value visible
+
+  int ntic;
+  float v;
+  float t;
+  float ti;
+  int h=size().height();
+  int w=size().width();
+  int xd;
+  int yd;
+  int th=10;
+  //  int y = pgs->y;
+  //  int x = pgs->x;
+  char s[80];
+
+  //  linc = pgs->linc ? pgs->linc: 10;
+  // tpix = m_tspc ? m_tspc: 20;
+  //  tinc = pgs->tinc ? pgs->tinc: 5;
+
+  painter->save();
+  painter->setTransform(QTransform().translate(scenePos().x(),scenePos().y()).scale(m_scale,m_scale));
+  QPen pen(m_color);
+  QBrush brush(m_backColor);
+  painter->setFont(m_font);
+  painter->setPen(pen);
+  painter->setBrush(brush);
+  QFontMetrics fm(m_font);
+  int fontHeight=fm.ascent();
+
+ if (m_style == UP) {
+    xd = 1;
+    yd = 0;
+  }
+
+  if (m_style == RIGHT) {
+    xd = 0;
+    yd = 1;
+  }
+
+  if (m_style == DOWN) {
+    xd = 1;
+    yd = 0;
+  }
+
+  if (m_style == LEFT) {
+    xd = 0;
+    yd = 1;
+  }
+  //  printf("draw_tape 1 %s x=%3d y=%3d h=%3d w=%3d linc=%d tpix=%d tinc=%d\n",name.c_str(),x,y,h,w,linc,tpix,tinc);
+
+
+
+
+//  float low = floor(m_value - ((h * m_tickIncrement)/(m_tickSpacing * 2))/m_tickIncrement)*m_tickIncrement; // Lowest value to display
+  float vof = floor(m_value / m_tickIncrement) * m_tickIncrement; // Value rounded to lover tick increment
+  float tmod= fmod (m_value,m_tickIncrement) * m_tickSpacing/m_tickIncrement;   // Modulus as pixels
+  ntic=ceil(h/(m_tickSpacing));
+  float low=vof-(ntic/2)*m_tickIncrement;
+//  fval = (m_value - ((tin + 1) * m_tickIncrement)) - (m_value%m_tickIncrement);
+  // t = h - tin * m_tickSpacing - ((m_value%m_tickIncrement) * tpix/m_tickIncrement);
+  // ntic=h/(m_tickSpacing/m_tickMinor);
+  // printf("paintTape %s val=%d tin=%d tpix=%d tinc=%d h2=%d tio=%d fval=%d t=%d low=%d yd=%d\n",m_name.toStdString().c_str(),m_value,tin,tpix,m_tickIncrement,h2,tio,fval,t,low,yd);
+
+
+  v = low;
+  int vpix=tmod+(ntic+1)*m_tickSpacing;
+  if(yd) {
+    QBrush brush(m_backColor);
+    painter->setBrush(brush);
+    painter->drawRect(0,0, w,h);
+    painter->drawLine(0,h/2,w,h/2);
+    painter->setClipRect(QRect(0,0,w,h));
+  }
+
+
+  //qDebug() << "m_value=" << m_value << " vof=" << vof << " low=" << low << " vpix=" << vpix << " ntic=" << ntic << " tmod=" <<tmod;
+  int i=0;
+  while(vpix >0) {
+
+      sprintf(s,"%3.0f",v);
+      v+=m_tickIncrement;
+      vpix-=m_tickSpacing;
+      i++;
+    //  qDebug() << v << vpix;
+      if(yd)   {
+          painter->drawText(QPoint(20, vpix+fontHeight/2),s);
+           painter->drawLine(0,vpix,th,vpix);
+           for(i=0;i<m_tickMinor;i++) painter->drawLine(0,vpix+i*(m_tickSpacing/m_tickMinor),th/2,vpix+i*(m_tickSpacing/m_tickMinor));
+      }
+      else painter->drawText(QPoint(vpix-20,30),s);
+
+      //       printf("t=%d v=%d x=%d y=%d %s\n",t,v,x+20,y+t,s);
+
+  }
+  painter->restore();  // Restore and remove clicping rectabgle
+
+}
+
+
+