ArmCircleWidget.cpp
Go to the documentation of this file.
00001 
00002 #include "ArmCircleWidget.h"
00003 
00004 #include <QtGui>
00005 
00006 
00007 ArmCircleWidget::ArmCircleWidget(QWidget *parent)
00008     : QGraphicsView(parent)
00009 {
00010 
00011     QGraphicsScene *scene = new QGraphicsScene(this);
00012     scene->setItemIndexMethod(QGraphicsScene::NoIndex);
00013     scene->setSceneRect(0, 0, 40, 40);
00014 
00015 
00016     setScene(scene);
00017     setCacheMode(CacheBackground);
00018     setViewportUpdateMode(BoundingRectViewportUpdate);
00019     setRenderHint(QPainter::Antialiasing);
00020     setTransformationAnchor(AnchorUnderMouse);
00021     scale(qreal(1), qreal(1));
00022     setMinimumSize(49, 49);
00023     setWindowTitle(tr("Arm Position"));
00024 
00025 
00026     QGraphicsEllipseItem *circle = new QGraphicsEllipseItem(25-5,25-5,10,10);
00027 
00028     scene->addItem(circle);
00029 
00030 
00031 
00032  }
00033 
00034 void ArmCircleWidget::Corobot(bool value)
00035 // value is true of a Corobot, false if is an Explorer, Explorer doesn't have an arm therefore the Widget is white
00036 {
00037             if(value == true){
00038                 scene()->items().at(0)->show();
00039             }
00040             else{
00041                 scene()->items().at(0)->hide();
00042             }
00043 }
00044 
00045 void ArmCircleWidget::setpos(float x, float y)
00046 // set the position of the circle in the widget. x,y is the position of the gripper, in meters.
00047 {
00048     QGraphicsEllipseItem * e = qgraphicsitem_cast<QGraphicsEllipseItem  *>(scene()->items().at(0));
00049     float r = 18/(2*x+1);
00050     float ybis = 22 - 47*y;
00051     e->setRect(20-r/2,ybis-r/2,r,r);
00052 }
00053 
00054 
00055 
00056 
00057  void ArmCircleWidget::drawBackground(QPainter *painter, const QRectF &rect)
00058  //draw the background of the widget
00059  {
00060      Q_UNUSED(rect);
00061 
00062      // Shadow
00063      QRectF sceneRect = this->sceneRect();
00064      QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
00065      QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
00066      if (rightShadow.intersects(rect) || rightShadow.contains(rect))
00067          painter->fillRect(rightShadow, Qt::darkGray);
00068      if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
00069          painter->fillRect(bottomShadow, Qt::darkGray);
00070 
00071 
00072      // Fill
00073      QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
00074      gradient.setColorAt(0, Qt::white);
00075      gradient.setColorAt(1, Qt::lightGray);
00076      painter->fillRect(rect.intersect(sceneRect), gradient);
00077      painter->setBrush(Qt::NoBrush);
00078      painter->drawRect(sceneRect);
00079  }
00080 
00081  void ArmCircleWidget::scaleView(qreal scaleFactor)
00082  //change the scale of the view
00083  {
00084      qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
00085      if (factor < 0.07 || factor > 100)
00086          return;
00087 
00088      scale(scaleFactor, scaleFactor);
00089  }
00090 
00091 
00092 


corobot_teleop
Author(s): Morgan Cormier/Gang Li/mcormier@coroware.com
autogenerated on Tue Jan 7 2014 11:39:41