Ejemplo n.º 1
0
void EBackGroundFore::initElement()
{
    this->clearAllPolygon();
    QPolygon polygon;

//    switch(GameInfo::gameStatus)
//    {
//    case MainMenu:
//    case ModeSelect:
//    case GamePlay:
//    case GameOver:
        polygon.putPoints(0, 3,  0,0,   -884,0,     -442,-765);
        this->addPolygon(polygon);
        polygon.clear();
        polygon.putPoints(0, 3,  0,0,   442,-765,   884,0);
        this->addPolygon(polygon);
        polygon.clear();
        polygon.putPoints(0, 3,  0,0,   442,765,     -442,765);
        this->addPolygon(polygon);
        polygon.clear();
//        break;
//    }

    this->pen.setWidth(1);
    this->brush.setStyle(Qt::SolidPattern);
}
Ejemplo n.º 2
0
void KisTransformMaskTest::testSafeTransformSingleVanishingPoint()
{
    // rotation around 0X has a single vanishing point for 0Y axis
    QTransform transform(1, 0, 0,
                         -0.870208, -0.414416, -0.000955222,
                         132.386, 1082.91, 1.99439);

    QTransform R; R.rotateRadians(M_PI / 4.0);
    //transform *= R;

    QRectF testRect(1536, 1024, 512, 512);
    KisSafeTransform t2(transform, QRect(0, 0, 2048, 2048), testRect.toRect());

    QPolygonF fwdPoly = t2.mapForward(testRect);
    QRectF fwdRect = t2.mapRectForward(testRect);

    QPolygonF bwdPoly = t2.mapBackward(fwdPoly);
    QRectF bwdRect = t2.mapRectBackward(fwdRect);

    /**
     * A special weird rect that crosses the vanishing point,
     * which is (911.001, 433.84) in this case
     */
    QRectF fwdNastyRect(800, 100, 400, 600);
    //QRectF fwdNastyRect(100, 400, 1000, 800);
    QRectF bwdNastyRect = t2.mapRectBackward(fwdNastyRect);

/*
    dbgKrita << ppVar(testRect);
    dbgKrita << ppVar(fwdPoly);
    dbgKrita << ppVar(fwdRect);
    dbgKrita << ppVar(bwdPoly);
    dbgKrita << ppVar(bwdRect);
    dbgKrita << ppVar(bwdNastyRect);
*/

    QPolygon ref;

    ref.clear();
    ref << QPoint(765,648);
    ref << QPoint(1269, 648);
    ref << QPoint(1601, 847);
    ref << QPoint(629, 847);
    ref << QPoint(765, 648);
    QCOMPARE(fwdPoly.toPolygon(), ref);
    QCOMPARE(fwdRect.toRect(), QRect(629,648,971,199));

    ref.clear();
    ref << QPoint(1536,1024);
    ref << QPoint(2048,1024);
    ref << QPoint(2048,1536);
    ref << QPoint(1536,1536);
    ref << QPoint(1536,1024);
    QCOMPARE(bwdPoly.toPolygon(), ref);
    QCOMPARE(bwdRect.toRect(), QRect(1398,1024,650,512));

    QCOMPARE(bwdNastyRect.toRect(), QRect(1463,0,585,1232));
}
Ejemplo n.º 3
0
/**
 * Overrides drawing of subentities. This is only ever called for solid fills.
 */
void RS_Hatch::draw(RS_Painter* painter, RS_GraphicView* view, double& /*patternOffset*/) {

    if (!data.solid) {
		for(auto se: entities){

            view->drawEntity(painter,se);
        }
        return;
    }

    //area of solid fill. Use polygon approximation, except trivial cases
    QPainterPath path;
    QList<QPolygon> paClosed;
    QPolygon pa;
//    QPolygon jp;   // jump points

    // loops:
    if (needOptimization==true) {
		for(auto l: entities){

            if (l->rtti()==RS2::EntityContainer) {
                RS_EntityContainer* loop = (RS_EntityContainer*)l;

                loop->optimizeContours();
            }
        }
        needOptimization = false;
    }

    // loops:
	for(auto l: entities){
        l->setLayer(getLayer());

        if (l->rtti()==RS2::EntityContainer) {
            RS_EntityContainer* loop = (RS_EntityContainer*)l;

            // edges:
			for(auto e: *loop){

                e->setLayer(getLayer());
                switch (e->rtti()) {
                case RS2::EntityLine: {
                    QPoint pt1(RS_Math::round(view->toGuiX(e->getStartpoint().x)),
                               RS_Math::round(view->toGuiY(e->getStartpoint().y)));
                    QPoint pt2(RS_Math::round(view->toGuiX(e->getEndpoint().x)),
                               RS_Math::round(view->toGuiY(e->getEndpoint().y)));

//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }
                    if(pa.size() && (pa.last()-pt1).manhattanLength()>=1)
                        pa<<pt1;
                    pa<<pt2;
                }
                    break;

                case RS2::EntityArc: {
//                    QPoint pt1(RS_Math::round(view->toGuiX(e->getStartpoint().x)),
//                               RS_Math::round(view->toGuiY(e->getStartpoint().y)));
//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    QPolygon pa2;
                    RS_Arc* arc=static_cast<RS_Arc*>(e);

                    painter->createArc(pa2, view->toGui(arc->getCenter()),
                                       view->toGuiDX(arc->getRadius())
                                       ,arc->getAngle1(),arc->getAngle2(),arc->isReversed());
                    if(pa.size() &&pa2.size()&&(pa.last()-pa2.first()).manhattanLength()<1)
                        pa2.remove(0,1);
                    pa<<pa2;

                }
                    break;

                case RS2::EntityCircle: {
                    RS_Circle* circle = static_cast<RS_Circle*>(e);
//                    QPoint pt1(RS_Math::round(view->toGuiX(circle->getCenter().x+circle->getRadius())),
//                               RS_Math::round(view->toGuiY(circle->getCenter().y)));
//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    RS_Vector c=view->toGui(circle->getCenter());
                    double r=view->toGuiDX(circle->getRadius());
#if QT_VERSION >= 0x040400
                    path.addEllipse(QPoint(c.x,c.y),r,r);
#else
                    path.addEllipse(c.x - r, c.y + r, 2.*r, 2.*r);
//                    QPolygon pa2;
//                    painter->createArc(pa2, view->toGui(circle->getCenter()),
//                                       view->toGuiDX(circle->getRadius()),
//                                       0.0,
//                                       2*M_PI,
//                                       false);
//                    pa<<pa2;
#endif
                }
                    break;
                case RS2::EntityEllipse:
                if(static_cast<RS_Ellipse*>(e)->isArc()) {
                    QPolygon pa2;
                    auto ellipse=static_cast<RS_Ellipse*>(e);

                    painter->createEllipse(pa2,
                                           view->toGui(ellipse->getCenter()),
                                           view->toGuiDX(ellipse->getMajorRadius()),
                                           view->toGuiDX(ellipse->getMinorRadius()),
                                           ellipse->getAngle()
                                           ,ellipse->getAngle1(),ellipse->getAngle2(),ellipse->isReversed()
                                           );
//                    qDebug()<<"ellipse: "<<ellipse->getCenter().x<<","<<ellipse->getCenter().y;
//                    qDebug()<<"ellipse: pa2.size()="<<pa2.size();
//                    qDebug()<<"ellipse: pa2="<<pa2;
                    if(pa.size() && pa2.size()&&(pa.last()-pa2.first()).manhattanLength()<1)
                        pa2.remove(0,1);
                    pa<<pa2;
                }else{
                    QPolygon pa2;
                    auto ellipse=static_cast<RS_Ellipse*>(e);
                    painter->createEllipse(pa2,
                                           view->toGui(ellipse->getCenter()),
                                           view->toGuiDX(ellipse->getMajorRadius()),
                                           view->toGuiDX(ellipse->getMinorRadius()),
                                           ellipse->getAngle(),
                                           ellipse->getAngle1(), ellipse->getAngle2(),
                                           ellipse->isReversed()
                                           );
                    path.addPolygon(pa2);
                }
                    break;
                default:
                    break;
                }
//                qDebug()<<"pa="<<pa;
                if( pa.size()>2 && pa.first() == pa.last()) {
                    paClosed<<pa;
                    pa.clear();
                }

            }

        }
    }
    if(pa.size()>2){
        pa<<pa.first();
        paClosed<<pa;
    }

    for(auto& p:paClosed){
        path.addPolygon(p);
    }

    //bug#474, restore brush after solid fill
    const QBrush brush(painter->brush());
    const RS_Pen pen=painter->getPen();
    painter->setBrush(pen.getColor());
    painter->disablePen();
    painter->drawPath(path);
    painter->setBrush(brush);
    painter->setPen(pen);


}
Ejemplo n.º 4
0
void
Text::init()
{
    _fontSize.setX((qreal)widget()->_inst->font_width);
    _fontSize.setY((qreal)widget()->_inst->font_height);

    _ldcMap.clear();

    QPolygon polygon;

    // -
    polygon << QPoint(0,_fontSize.y()/2) << QPoint(_fontSize.x(),_fontSize.y()/2);
    _ldcMap.insert(lh,polygon);

    // |
    polygon.clear();
    polygon << QPoint(_fontSize.x()/2,0) << QPoint(_fontSize.x()/2,_fontSize.y());
    _ldcMap.insert(lv,polygon);

    //  _
    // |
    polygon.clear();
    polygon << QPoint(_fontSize.x()/2,_fontSize.y()/2) << QPoint(_fontSize.x()/2,_fontSize.y());
    polygon << QPoint(_fontSize.x()/2,_fontSize.y()/2) << QPoint(_fontSize.x(),_fontSize.y()/2);
    _ldcMap.insert(ldlr,polygon);

    //  _
    //  | 
    polygon.clear();
    polygon << QPoint(_fontSize.x()/2,_fontSize.y()/2) << QPoint(_fontSize.x()/2,_fontSize.y());
    polygon << QPoint(0,_fontSize.y()/2) << QPoint(_fontSize.x()/2,_fontSize.y()/2);            
    _ldcMap.insert(ldll,polygon);

    // |_
    polygon.clear();
    polygon << QPoint(_fontSize.x()/2,0) << QPoint(_fontSize.x()/2,_fontSize.y()/2);
    polygon << QPoint(_fontSize.x()/2,_fontSize.y()/2) << QPoint(_fontSize.x(),_fontSize.y()/2);
    _ldcMap.insert(lulr,polygon);

    // _|
    polygon.clear();
    polygon << QPoint(_fontSize.x()/2,0) << QPoint(_fontSize.x()/2,_fontSize.y()/2);
    polygon << QPoint(0,_fontSize.y()/2) << QPoint(_fontSize.x()/2,_fontSize.y()/2);
    _ldcMap.insert(lull,polygon);

    // |-
    polygon.clear();
    polygon << QPoint(_fontSize.x()/2,0) << QPoint(_fontSize.x()/2,_fontSize.y());
    polygon << QPoint(_fontSize.x()/2,_fontSize.y()/2) << QPoint(_fontSize.x(),_fontSize.y()/2);
    _ldcMap.insert(lvlr,polygon);

    // -|
    polygon.clear();
    polygon << QPoint(_fontSize.x()/2,0) << QPoint(_fontSize.x()/2,_fontSize.y());
    polygon << QPoint(0,_fontSize.y()/2) << QPoint(_fontSize.x()/2,_fontSize.y()/2);
    _ldcMap.insert(lvll,polygon);

    // _
    // |
    polygon.clear();
    polygon << QPoint(0,_fontSize.y()/2) << QPoint(_fontSize.x(),_fontSize.y()/2);
    polygon << QPoint(_fontSize.x()/2,_fontSize.y()/2) << QPoint(_fontSize.x()/2,_fontSize.y());
    _ldcMap.insert(lhld,polygon);

    // |
    // - 
    polygon.clear();
    polygon << QPoint(0,_fontSize.y()/2) << QPoint(_fontSize.x(),_fontSize.y()/2);
    polygon << QPoint(_fontSize.x()/2,0) << QPoint(_fontSize.x()/2,_fontSize.y()/2);
    _ldcMap.insert(lhlu,polygon);

    // +
    polygon.clear();
    polygon << QPoint(0,_fontSize.y()/2) << QPoint(_fontSize.x(),_fontSize.y()/2);
    polygon << QPoint(_fontSize.x()/2,0) << QPoint(_fontSize.x()/2,_fontSize.y());
    _ldcMap.insert(lhlv,polygon);
}
Ejemplo n.º 5
0
/**
 * Overrides drawing of subentities. This is only ever called for solid fills.
 */
void RS_Hatch::draw(RS_Painter* painter, RS_GraphicView* view, double& /*patternOffset*/) {

    if (!data.solid) {
        for (RS_Entity* se=firstEntity();
                se!=NULL;
                se = nextEntity()) {

            view->drawEntity(painter,se);
        }
        return;
    }

    QPainterPath path;
    QList<QPolygon> paClosed;
    QPolygon pa;
//    QPolygon jp;   // jump points

    // loops:
    if (needOptimization==true) {
        for (RS_Entity* l=firstEntity(RS2::ResolveNone);
                l!=NULL;
                l=nextEntity(RS2::ResolveNone)) {

            if (l->rtti()==RS2::EntityContainer) {
                RS_EntityContainer* loop = (RS_EntityContainer*)l;

                loop->optimizeContours();
            }
        }
        needOptimization = false;
    }

    // loops:
    for (RS_Entity* l=firstEntity(RS2::ResolveNone);
         l!=NULL;
         l=nextEntity(RS2::ResolveNone)) {

        l->setLayer(getLayer());

        if (l->rtti()==RS2::EntityContainer) {
            RS_EntityContainer* loop = (RS_EntityContainer*)l;

            // edges:
            for (RS_Entity* e=loop->firstEntity(RS2::ResolveNone);
                 e!=NULL;
                 e=loop->nextEntity(RS2::ResolveNone)) {

                e->setLayer(getLayer());
                switch (e->rtti()) {
                case RS2::EntityLine: {
                    QPoint pt1(RS_Math::round(view->toGuiX(e->getStartpoint().x)),
                               RS_Math::round(view->toGuiY(e->getStartpoint().y)));
                    QPoint pt2(RS_Math::round(view->toGuiX(e->getEndpoint().x)),
                               RS_Math::round(view->toGuiY(e->getEndpoint().y)));

//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    pa<<pt1<<pt2;
                }
                    break;

                case RS2::EntityArc: {
//                    QPoint pt1(RS_Math::round(view->toGuiX(e->getStartpoint().x)),
//                               RS_Math::round(view->toGuiY(e->getStartpoint().y)));
//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    QPolygon pa2;
                    RS_Arc* arc=static_cast<RS_Arc*>(e);
                    painter->createArc(pa2, view->toGui(arc->getCenter()),
                                       view->toGuiDX(arc->getRadius()),
                                       arc->getAngle1(),
                                       arc->getAngle2(),
                                       arc->isReversed());
                    pa<<pa2;

                }
                    break;

                case RS2::EntityCircle: {
                    RS_Circle* circle = static_cast<RS_Circle*>(e);
//                    QPoint pt1(RS_Math::round(view->toGuiX(circle->getCenter().x+circle->getRadius())),
//                               RS_Math::round(view->toGuiY(circle->getCenter().y)));
//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    RS_Vector c=view->toGui(circle->getCenter());
                    double r=view->toGuiDX(circle->getRadius());
#if QT_VERSION >= 0x040400
                    path.addEllipse(QPoint(c.x,c.y),r,r);
#else
                    path.addEllipse(c.x - r, c.y + r, 2.*r, 2.*r);
//                    QPolygon pa2;
//                    painter->createArc(pa2, view->toGui(circle->getCenter()),
//                                       view->toGuiDX(circle->getRadius()),
//                                       0.0,
//                                       2*M_PI,
//                                       false);
//                    pa<<pa2;
#endif
                }
                    break;
                case RS2::EntityEllipse:
                if(static_cast<RS_Ellipse*>(e)->isArc()) {
                    QPolygon pa2;
                    auto ellipse=static_cast<RS_Ellipse*>(e);
                    painter->createEllipse(pa2,
                                           view->toGui(ellipse->getCenter()),
                                           view->toGuiDX(ellipse->getMajorRadius()),
                                           view->toGuiDX(ellipse->getMinorRadius()),
                                           ellipse->getAngle(),
                                           ellipse->getAngle1(), ellipse->getAngle2(),
                                           ellipse->isReversed()
                                           );
                    pa<<pa2;
                }else{
                    QPolygon pa2;
                    auto ellipse=static_cast<RS_Ellipse*>(e);
                    painter->createEllipse(pa2,
                                           view->toGui(ellipse->getCenter()),
                                           view->toGuiDX(ellipse->getMajorRadius()),
                                           view->toGuiDX(ellipse->getMinorRadius()),
                                           ellipse->getAngle(),
                                           ellipse->getAngle1(), ellipse->getAngle2(),
                                           ellipse->isReversed()
                                           );
                    path.addPolygon(pa2);
                }
                    break;
                default:
                    break;
                }
                if( pa.size()>2 && pa.first() == pa.last()) {
                    paClosed<<pa;
                    pa.clear();
                }

            }

        }
    }
    if(pa.size()>2){
        pa<<pa.first();
        paClosed<<pa;
    }
    for(int i=0;i<paClosed.size();i++){
        path.addPolygon(paClosed.at(i));
    }
        painter->setBrush(painter->getPen().getColor());
        painter->disablePen();
        painter->drawPath(path);

//    pa<<jp;

//    painter->setBrush(painter->getPen().getColor());
//    painter->disablePen();
//    painter->drawPolygon(pa);

}
Ejemplo n.º 6
0
void KisTransformMaskTest::testSafeTransform()
{
    QTransform transform(-0.177454, -0.805953, -0.00213713,
                         -1.9295, -0.371835, -0.00290463,
                         3075.05, 2252.32, 7.62371);

    QRectF testRect(0, 1024, 512, 512);
    KisSafeTransform t2(transform, QRect(0, 0, 2048, 2048), testRect.toRect());

    QPolygonF fwdPoly = t2.mapForward(testRect);
    QRectF fwdRect = t2.mapRectForward(testRect);

    QPolygonF bwdPoly = t2.mapBackward(fwdPoly);
    QRectF bwdRect = t2.mapRectBackward(fwdRect);

    QPolygon ref;

    ref.clear();
    ref << QPoint(284, 410);
    ref << QPoint(10, 613);
    ref << QPoint(35, 532);
    ref << QPoint(236, 403);
    ref << QPoint(284, 410);
    QCOMPARE(fwdPoly.toPolygon(), ref);
    QCOMPARE(fwdRect.toRect(), QRect(10,403,274,211));

    ref.clear();
    ref << QPoint(512, 1024);
    ref << QPoint(512, 1536);
    ref << QPoint(0, 1536);
    ref << QPoint(0, 1024);
    ref << QPoint(512, 1024);
    QCOMPARE(bwdPoly.toPolygon(), ref);
    QCOMPARE(bwdRect.toRect(), QRect(0, 994, 1198, 584));

/*
    QImage image(2500, 2500, QImage::Format_ARGB32);
    QPainter gc(&image);
    gc.setPen(Qt::cyan);

    gc.setOpacity(0.7);

    gc.setBrush(Qt::red);
    gc.drawPolygon(t2.srcClipPolygon());

    gc.setBrush(Qt::green);
    gc.drawPolygon(t2.dstClipPolygon());

    dbgKrita << ppVar(testRect);
    dbgKrita << ppVar(fwdPoly);
    dbgKrita << ppVar(fwdRect);
    dbgKrita << ppVar(bwdPoly);
    dbgKrita << ppVar(bwdRect);

    gc.setBrush(Qt::yellow);
    gc.drawPolygon(testRect);

    gc.setBrush(Qt::red);
    gc.drawPolygon(fwdRect);
    gc.setBrush(Qt::blue);
    gc.drawPolygon(fwdPoly);

    gc.setBrush(Qt::magenta);
    gc.drawPolygon(bwdRect);
    gc.setBrush(Qt::cyan);
    gc.drawPolygon(bwdPoly);

    gc.end();
    image.save("polygons_safety.png");
*/
}
Ejemplo n.º 7
0
int
MarkerRetracement::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &, void *m)
{
  Marker *ret = (Marker *) m;
  Entity *e = ret->settings();
  
  QVariant *date = e->get(QString("date"));
  if (! date)
    return 0;
  
  QVariant *date2 = e->get(QString("date2"));
  if (! date2)
    return 0;

  QVariant *high = e->get(QString("high"));
  if (! high)
    return 0;

  QVariant *low = e->get(QString("low"));
  if (! low)
    return 0;

  QVariant *tset = e->get(QString("color"));
  if (! tset)
    return 0;
  QColor color(tset->toString());

  QVariant *extend = e->get(QString("extend"));
  if (! extend)
    return 0;

  QVariant *l1 = e->get(QString("level1"));
  if (! l1)
    return 0;

  QVariant *l2 = e->get(QString("level2"));
  if (! l2)
    return 0;

  QVariant *l3 = e->get(QString("level3"));
  if (! l3)
    return 0;

  QVariant *l4 = e->get(QString("level4"));
  if (! l4)
    return 0;

  QVariant *l5 = e->get(QString("level5"));
  if (! l5)
    return 0;

  QVariant *l6 = e->get(QString("level6"));
  if (! l6)
    return 0;
  
  PlotDateScaleDraw *dsd = (PlotDateScaleDraw *) ret->plot()->axisScaleDraw(QwtPlot::xBottom);
  int x = xMap.transform(dsd->dateToX(date->toDateTime()));

  QDateTime dt = date2->toDateTime();
  if (extend->toBool())
  {
    int s, e;
    g_symbol->startEndRange(s, e);
    Bar *bar = g_symbol->bar(e);
    if (! bar)
      return 0;
    
    dt = bar->date();
  }

  int x2 = xMap.transform(dsd->dateToX(dt));

  p->setPen(color);

  ret->clearSelectionArea();

  QList<double> lineList;
  lineList.append(l1->toDouble());
  lineList.append(l2->toDouble());
  lineList.append(l3->toDouble());
  lineList.append(l4->toDouble());
  lineList.append(l5->toDouble());
  lineList.append(l6->toDouble());

  for (int loop = 0; loop < lineList.size(); loop++)
  {
    double td = lineList.at(loop);
    if (td != 0)
    {
      double range = high->toDouble() - low->toDouble();
      double r = 0;
      if (td < 0)
        r = low->toDouble() + (range * td);
      else
      {
        if (td > 0)
          r = low->toDouble() + (range * td);
        else
        {
          if (td < 0)
            r = high->toDouble();
          else
            r = low->toDouble();
        }
      }

      int y = yMap.transform(r);
      p->drawLine (x, y, x2, y);
      p->drawText(x, y - 1, QString::number(td * 100) + "% - " + QString::number(r));

      QPolygon array;
      array.putPoints(0, 4, x, y - 4, x, y + 4, x2, y + 4, x2, y - 4);
      ret->appendSelectionArea(QRegion(array));
    }
  }

  // draw the low line
  int y = yMap.transform(low->toDouble());
  p->drawLine (x, y, x2, y);
  
  Strip strip;
  QString ts;
  strip.strip(low->toDouble(), 4, ts);
  p->drawText(x, y - 1, "0% - " + ts);

  // store the selectable area the low line occupies
  QPolygon array;
  array.putPoints(0, 4, x, y - 4, x, y + 4, x2, y + 4, x2, y - 4);
  ret->appendSelectionArea(QRegion(array));

  // draw the high line
  int y2 = yMap.transform(high->toDouble());
  p->drawLine (x, y2, x2, y2);
  
  strip.strip(high->toDouble(), 4, ts);
  p->drawText(x, y2 - 1, "100% - " + ts);

  // store the selectable area the high line occupies
  array.clear();
  array.putPoints(0, 4, x, y2 - 4, x, y2 + 4, x2, y2 + 4, x2, y2 - 4);
  ret->appendSelectionArea(QRegion(array));

  if (ret->selected())
  {
    int handleWidth = ret->handleWidth();
    
    ret->clearGrabHandles();

    //top left corner
    ret->appendGrabHandle(QRegion(x, y2 - (handleWidth / 2),
                          handleWidth,
                          handleWidth,
                          QRegion::Rectangle));

    p->fillRect(x,
                y2 - (handleWidth / 2),
                handleWidth,
                handleWidth,
                color);

    //bottom right corner
    ret->appendGrabHandle(QRegion(x2, y - (handleWidth / 2),
                          handleWidth,
                          handleWidth,
                          QRegion::Rectangle));

    p->fillRect(x2,
                y - (handleWidth / 2),
                handleWidth,
                handleWidth,
                color);
  }
  
  return 1;
}
Ejemplo n.º 8
0
Altimeter::Altimeter(QWidget *parent) :
    QGraphicsView(parent),
    feets(0)
{
    QPolygon polygon; // helper

    this->setGeometry(0,0, WIDGETSIZE, WIDGETSIZE);

    // Style Setting
    backgroundBrush = QBrush(Qt::black);//QBrush(QColor(0x53, 0x54, 0x48));
    circlePen       = QPen(Qt::white);
    circlePen.setWidth(CIRCLEPENWIDTH);
    graduationPen   = QPen(Qt::white);
    graduationPen.setWidth(2);
    graduationFont  = QFont("lucida");
    graduationFont.setPointSize(12);
    graduationFont.setBold(true);
    handPenFront    = QPen(Qt::black);
    handPenFront.setWidth(2);
    handPenBack     = QPen(Qt::white);
    handPenBack.setWidth(2);
    handBrushBack   = QBrush(Qt::black);
    handBrushFront  = QBrush(Qt::white);

    // BACKGROUND PIXMAP
    backgroundPixmap = QPixmap(WIDGETSIZE,WIDGETSIZE);
    QPainter painter;
    painter.begin(&(this->backgroundPixmap));
    painter.setRenderHint(QPainter::Antialiasing);
    // Background
    painter.fillRect(QRect(0,0,WIDGETSIZE,WIDGETSIZE), backgroundBrush);
    // Circle
    painter.translate(WIDGETSIZE/2, WIDGETSIZE/2);
    painter.setBrush(Qt::NoBrush);
    painter.setPen(circlePen);
    painter.drawEllipse(QPoint(0,0),
                        (WIDGETSIZE/2-CIRCLEPENWIDTH),
                        (WIDGETSIZE/2-CIRCLEPENWIDTH)
                        );
    // Graduation
    painter.save();
    painter.setFont(graduationFont);
    for(int i=0 ; i<10 ; ++i)
    {
        graduationPen.setWidth(2);
        painter.setPen(graduationPen);
        painter.drawLine(QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+5),
                         QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+13));

        graduationPen.setWidth(1);
        painter.setPen(graduationPen);
        painter.drawText(
                    QPoint(-5, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+28),
                    QString::number(i));
        for(int j=1 ; j<5 ; ++j)
        {
            painter.rotate(7.2);
            painter.drawLine(QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+5),
                             QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+10));
        }
        painter.rotate(7.2);
    }
    painter.restore();
    painter.end();


    // HAND, FEETS
    feetsHand = QPixmap(HANDWIDTH, HANDHEIGHT);
    painter.begin(&(this->feetsHand));
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(feetsHand.rect(), backgroundBrush);
    // Hand front
    painter.setBrush(handBrushFront);
    painter.setPen(handPenFront);
    painter.drawRect(QRect(HANDCENTERX-2, CIRCLEPENWIDTH+5, 4, 16));
    painter.drawRect(QRect(
                         QPoint(HANDCENTERX-3, CIRCLEPENWIDTH+5+15),
                         QPoint(HANDCENTERX+3, HANDCENTERY))
                     );
    // Hand back
    painter.setBrush(handBrushBack);
    painter.setPen(handPenBack);
    painter.drawRect(HANDCENTERX-3, HANDCENTERY, 6, 25);
    painter.drawEllipse(QPoint(HANDCENTERX, HANDCENTERY+25), 6, 6);
    painter.end();
    // Mask
    feetsHand.setMask(feetsHand.createMaskFromColor(
                          backgroundBrush.color(),
                          Qt::MaskInColor)
                      );


    // HAND, TENTH of FEETS
    tenthHand = QPixmap(HANDWIDTH, HANDHEIGHT);
    painter.begin(&(this->tenthHand));
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(tenthHand.rect(), backgroundBrush);
    // Hand front
    painter.setBrush(handBrushFront);
    painter.setPen(handPenFront);
    polygon.append(HANDCENTER);
    polygon.append(QPoint(HANDCENTERX-10, HANDCENTERY-25));
    polygon.append(QPoint(HANDCENTERX, HANDCENTERY-75));
    polygon.append(QPoint(HANDCENTERX+10, HANDCENTERY-25));
    painter.drawPolygon(polygon);
    // Hand back
    painter.setBrush(handBrushBack);
    painter.setPen(handPenBack);
    polygon.clear();
    polygon.append(HANDCENTER);
    polygon.append(QPoint(HANDCENTERX-10, HANDCENTERY+25));
    polygon.append(QPoint(HANDCENTERX+10, HANDCENTERY+25));
    painter.drawPolygon(polygon);
    painter.end();
    // Mask
    tenthHand.setMask(tenthHand.createMaskFromColor(
                          backgroundBrush.color(),
                          Qt::MaskInColor)
                      );


    // HAND, HUNDREDS of FEETS
    hundredsHand = QPixmap(HANDWIDTH, HANDHEIGHT);
    painter.begin(&(this->hundredsHand));
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(hundredsHand.rect(), backgroundBrush);
    // Hand front
    painter.setBrush(handBrushFront);
    painter.setPen(handPenFront);
    painter.drawRect(QRect(
                         HANDCENTERX-2,
                         CIRCLEPENWIDTH+5,
                         4,
                         HANDCENTERY-CIRCLEPENWIDTH-5)
                     );
    polygon.clear();
    polygon.append(QPoint(HANDCENTERX-10, CIRCLEPENWIDTH+5));
    polygon.append(QPoint(HANDCENTERX+10, CIRCLEPENWIDTH+5));
    polygon.append(QPoint(HANDCENTERX, CIRCLEPENWIDTH+5+15));
    painter.drawPolygon(polygon);
    // Hand back
    painter.setBrush(handBrushBack);
    painter.setPen(handPenBack);
    painter.end();
    // Mask
    hundredsHand.setMask(hundredsHand.createMaskFromColor(
                             backgroundBrush.color(),
                             Qt::MaskInColor)
                         );

}
Ejemplo n.º 9
0
void TraceWidget::sideBarPaintEvent(QPaintEvent * event)
{
  // don't paint anything if there are no cycles
  if (cycle_.first < 0 || cycle_.second < 0)
    return;

  QPainter painter(cbar_);

  QRect rct, first_rct, last_rct;
  int first_id = -1, last_id = -1;

  for (int i = 0; i < count(); ++i) {
    rct = visualItemRect(item(i));

    if (rct.top() > event->rect().bottom())
      break;

    if (rct.bottom() <= event->rect().top())
      continue;

    if (i >= cycle_.second && i <= cycle_.first) {
      if (first_id == -1) {
        first_id = i;
        first_rct = rct;
      }

      last_id = i;
      last_rct = rct;
    }
  }

  // draw nothing
  if (first_id == -1)
    return;

  QList<QPolygon> lines;
  QPolygon line;

  // start of the cycle
  if (last_id == cycle_.first) {
    const int base_off = last_rct.top() + (last_rct.height() - cycleBaseSize) / 2;
    const int line_off = last_rct.top() + last_rct.height() / 2;

    line.push_back(QPoint(cycleBarWidth - 2, base_off));
    line.push_back(QPoint(cycleBarWidth - 2, base_off + cycleBaseSize));
    lines.append(line);

    line.clear();
    line.push_back(QPoint(cycleBarWidth - 2, line_off));
    line.push_back(QPoint(cycleLeftOffset, line_off));
  } else {
    line.push_back(QPoint(cycleLeftOffset, last_rct.bottom()));
  }

  const int line_off = first_rct.top() + first_rct.height() / 2;

  // end

  if (first_id == cycle_.second) {
    line.push_back(QPoint(cycleLeftOffset, line_off));
    line.push_back(QPoint(cycleBarWidth - 2, line_off));
    lines.append(line);

    // arrow
    line.clear();
    line.push_back(QPoint(cycleBarWidth - 4, line_off - 2));
    line.push_back(QPoint(cycleBarWidth - 2, line_off));
    line.push_back(QPoint(cycleBarWidth - 4, line_off + 2));
    lines.append(line);
  } else {
    line.push_back(QPoint(cycleLeftOffset, first_rct.top()));
    lines.append(line);
  }

  QPen pen;

  painter.setPen(pen);
  foreach(QPolygon itr, lines) {
    painter.drawPolyline(itr);
  }