QGraphicsItem *addSmiley() { QPen thickPen(Qt::black); thickPen.setWidth(2); // add face QGraphicsEllipseItem *face = new QGraphicsEllipseItem(QRect(-50, -50, 100, 100)); face->setPen(Qt::NoPen); face->setBrush(Qt::yellow); // add eyes QGraphicsEllipseItem *leftEye = new QGraphicsEllipseItem(QRectF(-6, -12, 12, 24), face); leftEye->setPen(thickPen); leftEye->setBrush(Qt::white); leftEye->setPos(-15, -25); QGraphicsEllipseItem *rightEye = new QGraphicsEllipseItem(QRectF(-6, -12, 12, 24), face); rightEye->setPen(thickPen); rightEye->setBrush(Qt::white); rightEye->setPos(15, -25); // add smile QPainterPath smileArc; QRect rect(-33, -15, 66, 50); smileArc.arcMoveTo(rect, 0); smileArc.arcTo(rect, 0, -180); QGraphicsPathItem *smile = new QGraphicsPathItem(smileArc, face); smile->setPen(thickPen); return face; }
Knob::Knob() : QGraphicsEllipseItem(-50, -50, 100, 100) { setAcceptTouchEvents(true); setBrush(Qt::lightGray); QGraphicsEllipseItem *leftItem = new QGraphicsEllipseItem(0, 0, 20, 20, this); leftItem->setPos(-40, -10); leftItem->setBrush(Qt::darkGreen); QGraphicsEllipseItem *rightItem = new QGraphicsEllipseItem(0, 0, 20, 20, this); rightItem->setPos(20, -10); rightItem->setBrush(Qt::darkRed); }
void subObservationVisualiserBase::constructStandardPoints(const observation& subObs) { assert(standardPointsItem); std::size_t nVertices = boost::num_vertices(contextObj.getGraph()); const std::vector<context::vertexPosition>& vertexPositions = contextObj.getVertexPositions(); const vertexState* state = subObs.getState(); QPen blackPen(QColor("black")); QBrush blackBrush(QColor("black")); QPen redPen(QColor("red")); QBrush redBrush(QColor("red")); QBrush noBrush; noBrush.setStyle(Qt::NoBrush); for(std::size_t vertexCounter = 0; vertexCounter < nVertices; vertexCounter++) { context::vertexPosition currentPosition = vertexPositions[vertexCounter]; float x = currentPosition.first; float y = currentPosition.second; QGraphicsEllipseItem* newItem = new QGraphicsEllipseItem(x - pointSize/2, y - pointSize/2, pointSize, pointSize, standardPointsItem); if(state[vertexCounter].state == FIXED_OFF) { newItem->setBrush(noBrush); newItem->setPen(blackPen); } else if(state[vertexCounter].state == FIXED_ON) { newItem->setBrush(blackBrush); newItem->setPen(blackPen); } else if(state[vertexCounter].state == UNFIXED_OFF) { newItem->setBrush(noBrush); newItem->setPen(redPen); } else if(state[vertexCounter].state == UNFIXED_ON) { newItem->setBrush(redBrush); newItem->setPen(redPen); } else { throw std::runtime_error("Internal error"); } } }
void PSV_CircularIndicatorItem::drawColorPie(int zValue) { double colorCircleRadius = m_colorCircleRadiusRatio * m_outerRadius; QPointF topLeftPot(m_rect.center().x()-colorCircleRadius, m_rect.center().y()-colorCircleRadius); QPointF bottomRightPot(m_rect.center().x()+colorCircleRadius, m_rect.center().y()+colorCircleRadius); QRectF colorCircleRect=QRectF(topLeftPot, bottomRightPot); QMapIterator<double,QColor> iter(m_levelInfos); int startAngle = 225 * 16; double dValue = m_max -m_min; if(qAbs(dValue) < PSV_ZEOR) { dValue = 100; m_max = 100; m_min = 0; } int spanAngle = 0; int topAngle = 0; while(iter.hasNext()) { iter.next(); spanAngle = (int)(16 * 270 * iter.key()) - topAngle; topAngle += spanAngle; QGraphicsEllipseItem* item = new QGraphicsEllipseItem(this); item->setRect(colorCircleRect); item->setStartAngle(startAngle - spanAngle); item->setSpanAngle(spanAngle); item->setPen(QPen(Qt::NoPen)); item->setBrush(QBrush(iter.value())); item->setZValue(zValue); startAngle = startAngle - spanAngle; } }
QGraphicsItemGroup* SDefaultBrush::renderPath(QPainterPath path){ QGraphicsItemGroup* pGroup = new QGraphicsItemGroup(); QPen pen; QColor c1 = mColor; QColor c2 = mColor; int alpha1 = 3*mColor.alpha()/4; c1.setAlpha(alpha1); int alpha2 = alpha1*mHardness/100; c2.setAlpha(alpha2); pen.setColor(QColor(Qt::transparent)); QRadialGradient gradient(500, 500, 500, 500, 500); gradient.setColorAt(0, c1); gradient.setColorAt(1, c2); QBrush brush(gradient); for(int i=0; i<path.length(); i+=(mWidth/2)*mSpacing){ QGraphicsEllipseItem* pEllipse = new QGraphicsEllipseItem(); pEllipse->setPen(pen); pEllipse->setBrush(brush); QPointF pt = path.pointAtPercent(path.percentAtLength(i)); pEllipse->setRect(pt.x()-mWidth/2, pt.y()-mWidth/2, mWidth, mWidth); pGroup->addToGroup(pEllipse); } return pGroup; }
void GraphicsBoard::setHighlights(const QList<Chess::Square>& squares) { clearHighlights(); if (squares.isEmpty()) return; TargetHighlights* targets = new TargetHighlights(this); QRectF rect; rect.setSize(QSizeF(m_squareSize / 3, m_squareSize / 3)); rect.moveCenter(QPointF(0, 0)); QPen pen(Qt::white, m_squareSize / 20); QBrush brush(Qt::black); for (const auto& sq : squares) { QGraphicsEllipseItem* dot = new QGraphicsEllipseItem(rect, targets); dot->setCacheMode(DeviceCoordinateCache); dot->setPen(pen); dot->setBrush(brush); dot->setPos(squarePos(sq)); } m_highlightAnim = new QPropertyAnimation(targets, "opacity"); targets->setParent(m_highlightAnim); m_highlightAnim->setStartValue(0.0); m_highlightAnim->setEndValue(1.0); m_highlightAnim->setDuration(500); m_highlightAnim->setEasingCurve(QEasingCurve::InOutQuad); m_highlightAnim->start(QAbstractAnimation::KeepWhenStopped); }
QGraphicsEllipseItem * GalaGV::makeMarkerItem(const QString &cords,const QString& sysid, ItemTyps itemtyp,QColor color, Typs typ) { QStringList cord = cords.split('/'); qreal x1 = cord.at(0).toFloat(); //qreal y1 = cord.at(1).toFloat(); qreal z1 = -1*cord.at(2).toFloat(); QGraphicsEllipseItem *item = new QGraphicsEllipseItem(); int size; switch(typ){ case GalaGV::Plani: item->setBrush(QBrush(Qt::white)); size = 2; break; case GalaGV::Mark: size = 6; break; case GalaGV::BigMarker: size = 10; break; } item->setRect(x1-(size/2),z1-(size/2),size,size); item->setPen(QPen(color)); item->setData(ID,sysid); item->setData(Cords,cords); item->setData(ItemTyp,itemtyp); return item; }
static QGraphicsEllipseItem* createPointItem() { QGraphicsEllipseItem* item = new QGraphicsEllipseItem(-pointRadius, -pointRadius, 2.0 * pointRadius, 2.0 * pointRadius); item->setBrush(pointBrush); item->setPen(pointPen); item->setZValue(1); return item; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), iScore1(0), iScore2(0) { ui->setupUi(this); QGraphicsScene *scene = new QGraphicsScene(this); scene->setSceneRect(0, 0, ui->boardView->size().width()-30, ui->boardView->size().height()-30); QGraphicsRectItem *p1 = new QGraphicsRectItem(0, 0, 20, 80); p1->setBrush(QBrush(Qt::blue)); QGraphicsRectItem *p2 = new QGraphicsRectItem(0, 0, 20, 80); p2->setBrush(QBrush(Qt::green)); QGraphicsEllipseItem *ball = new QGraphicsEllipseItem(0, 0, 15, 15); ball->setBrush(QBrush(Qt::magenta)); ui->boardView->setScene(scene); iLoop = new Gameplay(*scene, p1, p2, ball, this); QSize m(scene->sceneRect().size().width() + 10, scene->sceneRect().size().height() + 10); ui->boardView->setMinimumSize(m); ui->boardView->installEventFilter(iLoop); QObject::connect(iLoop, SIGNAL(goal(int)), this, SLOT(addScore(int))); panel = new ControlPanel(this); connect(panel, SIGNAL(pointsReady(std::vector<glm::vec2>)), iLoop, SLOT(setPoints(std::vector<glm::vec2>))); panel->show(); }
void QGraphicsGuideView::pathEndEvent(QMouseEvent *event) { cout << "Drawing Path (Before Simplification): " << _drawingPath.elementCount() << endl; // simplifyPainterPath(); if (_pathMode == FillMode) { QPainter painter(&_userDrawingCanvas); painter.setRenderHints(0); painter.setBrush(QBrush(Qt::yellow,Qt::SolidPattern)); painter.setPen(Qt::NoPen); painter.drawPath(_drawingPath); painter.end(); this->scene()->removeItem(_drawingPathItem); _drawingPathItem = NULL; _updateRect = _drawingPath.boundingRect(); userDrawingToSlice(); sliceToLabelImage(true); updateLabelItem(); sliceToVolume(true); } else { simplifyPainterPath(); cout << "Drawing Path (After Simplification): " << _drawingPath.elementCount() << endl; for (int i = 0; i < _drawingPath.elementCount(); i++) { QPainterPath::Element e = _drawingPath.elementAt(i); QGraphicsEllipseItem* el = new QGraphicsEllipseItem(e.x-2,e.y-2,5,5,_drawingPathItem); el->setBrush(QBrush(0xFFFFBBDD, Qt::SolidPattern)); el->setOpacity(1); el->setZValue(2); } } }
void PSV_CircularIndicatorItem::drawCoverCircle(int zValue) { double coverCircleRadius = m_coverCircleRadiusRatio * m_outerRadius; QRectF rect(m_rect.center().x()-coverCircleRadius, m_rect.center().y()-coverCircleRadius, coverCircleRadius*2, coverCircleRadius*2); QGraphicsEllipseItem* item = new QGraphicsEllipseItem(rect, this); item->setPen(QPen(Qt::NoPen)); item->setBrush(QBrush(QColor(130, 130, 130))); item->setZValue(zValue); }
void MainWindow::slotAddEllipseItem() //在场景中加入一个椭圆形图元 { QGraphicsEllipseItem *item = new QGraphicsEllipseItem(QRectF(0,0,80, 60)); item->setPen(Qt::NoPen); item->setBrush(QColor(qrand()%256,qrand()%256,qrand()%256)); item->setFlag(QGraphicsItem::ItemIsMovable); scene->addItem(item); item->setPos((qrand()%int(scene->sceneRect().width()))-200,(qrand()%int(scene->sceneRect().height()))-200); }
GameBoardScene::GameBoardScene(int newWidth, int newHeight, QObject *parent) : QGraphicsScene(parent), width(newWidth), height(newHeight), acceptEvents(true) { //kDebug() << "GameBoardScene::GameBoardScene()"; for(int i = 0; i < (2*width*height + width + height); i++) { lineList.append(false); //simply fill array with 'false's } spacing = 40; //this hard coding doesn't matter since auto-resizing exists :) for(int iWidth = 0; iWidth <= width; iWidth++) { for(int iHeight = 0; iHeight <= height; iHeight++) { int x = iWidth*spacing; int y = iHeight*spacing; QGraphicsEllipseItem *dot = new QGraphicsEllipseItem(QRectF(-2,-2,4,4)); dot->moveBy(x,y); dot->setBrush(Qt::SolidPattern); dot->setZValue(20); // set the elevation, the dot's are on top addItem(dot); } } QPen feintPen(Qt::DotLine); //for the guidelines between dots feintPen.setWidth(1); feintPen.setColor(Qt::lightGray); for(int iWidth = 0; iWidth <= width; iWidth++) { addLine(QLineF(spacing*iWidth, 0, spacing*iWidth, spacing*height), feintPen); } for(int iHeight = 0; iHeight <= height; iHeight++) { addLine(QLineF(0, spacing*iHeight, spacing*width, spacing*iHeight), feintPen); } setBackgroundBrush(QBrush(Qt::white)); indicatorLine = new QGraphicsLineItem(1,1,1,1); indicatorLine->setZValue(10); indicatorLine->setPen(QPen(Qt::yellow, 2.5)); indicatorLine->hide(); addItem(indicatorLine); QGraphicsEllipseItem tempItem; QGraphicsEllipseItemType = tempItem.type(); qreal border = 10; QRectF rect = sceneRect(); rect.setLeft(rect.left() - border); rect.setRight(rect.right() + border); rect.setTop(rect.top() - border); rect.setBottom(rect.bottom() + border); setSceneRect(rect); }
PacMan::PacMan(int radius, QColor color, int layer , double startX, double startY, double endX, double endY, int startSec, int endSec) : radius(radius) , color(color) , layer(layer) , startX(startX) , startY(startY) , endX(endX) , endY(endY) , startSec(startSec) , endSec(endSec) { moveScale = 1; QGraphicsEllipseItem * ellipse = new QGraphicsEllipseItem(this); ellipse->setRect ( -radius , -radius , radius*2 , radius*2 ); ellipse->setBrush (QBrush(color)); liveSec = endSec - startSec; setZValue(layer); }
SEXP qt_qgraphicsEllipseItem(SEXP x, SEXP y, SEXP width, SEXP height, SEXP pars) { double px = asReal(x), py = asReal(y), pw = asReal(width), ph = asReal(height); QGraphicsEllipseItem *item = new QGraphicsEllipseItem(px - pw/2, py - ph/2, pw, ph, 0); item->setBrush(asQBrush(pars)); item->setPen(asQPen(pars)); return wrapQGraphicsItem(item); }
void PSV_CircularIndicatorItem::drawCoverBall(int zValue) { qreal ballRadius=m_outerRadius * m_coverBallRadiusRatio; QRadialGradient ballGradient(m_rect.center(), ballRadius, m_rect.center()); ballGradient.setColorAt(0.0, QColor(140, 140, 140)); ballGradient.setColorAt(0.7, QColor(140, 140, 140)); ballGradient.setColorAt(1.0, QColor(60, 60, 60)); //================== QRectF rect(m_rect.center().x()-ballRadius, m_rect.center().y()-ballRadius, ballRadius*2, ballRadius*2); QGraphicsEllipseItem* item = new QGraphicsEllipseItem(rect, this); item->setPen(QPen(Qt::NoPen)); item->setBrush(ballGradient); item->setZValue(zValue); }
void PSV_CircularIndicatorItem::drawInnerCircle(int zValue) { qreal innerRadius = m_innerRadiusRatio * m_outerRadius; QRadialGradient innerGradient(m_rect.center(), innerRadius, m_rect.center()); innerGradient.setColorAt(0.0, QColor(130, 130, 130)); innerGradient.setColorAt(0.7, QColor(130, 130, 130)); innerGradient.setColorAt(1.0, QColor(80, 80, 80)); //== QPen pen(Qt::NoPen); QRectF rect(m_rect.center().x()-innerRadius, m_rect.center().y()-innerRadius, innerRadius*2, innerRadius*2); QGraphicsEllipseItem* item = new QGraphicsEllipseItem(rect, this); item->setPen(pen); item->setBrush(innerGradient); item->setZValue(zValue); }
void HostItem::updateHalos() { int count = 1; QMap<Job,QGraphicsEllipseItem*>::Iterator it; for(it = m_jobHalos.begin(); it != m_jobHalos.end(); ++it) { QGraphicsEllipseItem *halo = it.value(); halo->setRect(halo->x() - 5 - count * 3, halo->y() - 5 - count * 3, m_baseWidth + count * 6, m_baseHeight + count * 6); halo->setBrush(m_hostInfoManager->hostColor(it.key().client())); halo->setPen(Qt::NoPen); ++count; } }
void fillItemFromEllipse(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLEllipse *pEllipse, const CLGroup *group, const CLRenderResolver* resolver) { double x = pBB->getPosition().getX() + pEllipse->getCX().getAbsoluteValue() + pEllipse->getCX().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth(); double y = pBB->getPosition().getY() + pEllipse->getCY().getAbsoluteValue() + pEllipse->getCY().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight(); double rx = pEllipse->getRX().getAbsoluteValue() + pEllipse->getRX().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth(); double ry = pEllipse->getRY().getAbsoluteValue() + pEllipse->getRY().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight(); QGraphicsEllipseItem* ellipseItem = new QGraphicsEllipseItem( x - rx, y - ry, rx * 2, ry * 2); QPen *pen = getPen(pEllipse, group, resolver, pBB); ellipseItem->setPen(*pen); delete pen; QBrush *brush = getBrush(pEllipse, group, resolver, pBB); ellipseItem->setBrush(*brush); delete brush; transform(ellipseItem, pEllipse, group); item->addToGroup(ellipseItem); }
Peg::Peg(const QPoint& hole, Board* board, QGraphicsItem* parent) : QGraphicsEllipseItem(0, 0, 20, 20, parent), m_hole(hole), m_board(board) { setPen(Qt::NoPen); QGraphicsEllipseItem* gloss = new QGraphicsEllipseItem(3, 1.5, 14, 9, this); QLinearGradient gradient2(0, 0, 0, 9); gradient2.setColorAt(0, QColor(255, 255, 255)); gradient2.setColorAt(1, QColor(255, 255, 255, 0)); gloss->setBrush(gradient2); gloss->setPen(Qt::NoPen); setZValue(2); setPos(hole.x() * 20, hole.y() * 20); setFlag(QGraphicsItem::ItemIsMovable, true); setCursor(Qt::OpenHandCursor); }
void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *sEvent) { if (isActive()) { if (isEllipse() && isEllipsePainting() && startPoint != endPoint) if (sEvent->button() == Qt::LeftButton) { QGraphicsEllipseItem *finishedEllipseItem = new QGraphicsEllipseItem(ellipseItem->rect()); setEllipsePainting(false); finishedEllipseItem->setPen(QPen(QColor(0, 0, 200), 4)); finishedEllipseItem->setBrush(QBrush(QColor(0, 0, 200, 50))); finishedEllipseItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); removeItem(ellipseItem); addItem(finishedEllipseItem); ellipseVector << finishedEllipseItem; } QGraphicsScene::mouseReleaseEvent(sEvent); } }
void PSV_CircularIndicatorItem::drawOuterCircle(int zValue) { QRadialGradient outerGradient(m_rect.center(), m_outerRadius, m_rect.center()); outerGradient.setColorAt(0.0, QColor(200, 200, 200)); outerGradient.setColorAt(0.9, QColor(80, 80, 80)); outerGradient.setColorAt(0.95, QColor(180, 180, 180)); outerGradient.setColorAt(1.0, QColor(80, 80, 80)); //========================== QPen pen(Qt::NoPen); QGraphicsEllipseItem* item = new QGraphicsEllipseItem(this); item->setRect(m_rect.center().x() - m_outerRadius, m_rect.center().y() - m_outerRadius, m_outerRadius*2, m_outerRadius*2); item->setPen(pen); item->setBrush(outerGradient); item->setZValue(zValue); {//TEST QGraphicsRectItem *item = new QGraphicsRectItem(m_rect, this); item->setPen(QPen(Qt::blue)); // item->setPen(); } }
void MainWindow::graphicalInit() { scene = new QGraphicsScene(-50,-90,95,95); ui->graphicsView->setScene(scene); ui->graphicsView->setRenderHint(QPainter::Antialiasing); scene->setBackgroundBrush(QBrush(QColor(12,20,30))); scene->addPixmap(QPixmap("data/img/title.png"))->setPos(-280,-500); QGraphicsEllipseItem* lbr = scene->addEllipse(-360,-360,720,720); lbr->setPen(QPen(QBrush(QColor(255,255,255)),85)); QGraphicsEllipseItem* contour = scene->addEllipse(-340,-340,680,680); contour->setBrush(QBrush(QColor(230,230,255))); contour->setPen(QPen(QBrush(QColor(0,0,0)),5)); roue_g = new QGraphicsItemGroup(contour); // roue_g->addToGroup(contour); for(int i=0;i<playersList.size();i++) { float angle = (float)i/(float)playersList.size()*2*3.14159- 3.14159/2; QGraphicsLineItem* l = scene->addLine(10*cos(angle),10*sin(angle),340*cos(angle),340*sin(angle),QPen(QColor(i%2 == 0 ? 192: 0,0,0,192))); roue_g->addToGroup(l); QGraphicsPixmapItem* p = scene->addPixmap(photos[i]); p->setScale(0.18f); p->setPos(395*cos(angle+0.02),395*sin(angle+0.02)); p->setRotation(angle/(2*3.14159)*360 + 90+3*360/48/4); roue_g->addToGroup(p); } }
void MyQGraphicsView::mousePressEvent(QMouseEvent * e) { qreal rad = 1; QPointF pt = mapToScene(e->pos()); //QPointF pt = (e->pos()); qDebug()<<pt.x(); qDebug()<<pt.y(); if(pt.y()>=650) return; listofpoints.append(pt); qDebug()<<listofpoints.size(); // path.lineTo(pt.x(),pt.y()); // qDebug()<<"element count"<<path.elementCount(); qDebug()<<"element count"<<listofpoints.size(); QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem(pt.x()-rad, pt.y()-rad, rad*3.0, rad*3.0); ellipse->setPen(QPen()); ellipse->setBrush(QBrush(Qt::SolidPattern)); scene->addItem(ellipse); }
/*protected*/ void DrawCircle::makeFigure() { ControlPanelEditor* ed = _parent->getEditor(); QRectF r = ed->getSelectRect(); if (!r.isValid()) { return; } _radius = qMax(r.width(), r.height()); QGraphicsEllipseItem* rr = new QGraphicsEllipseItem(0, 0, _radius, _radius); rr->setBrush(QBrush(_fillColor)); rr->setPen(QPen(QBrush(_lineColor),_lineWidth)); PositionableCircle* ps = new PositionableCircle(ed, rr); ps->_itemGroup = new MyGraphicsItemGroup(); ps->_itemGroup->setName("PositionableCircle"); ps->_itemGroup->addToGroup(rr); ps->setLocation(r.x(), r.y()); // ps->setHeight(_height); // ps->setWidth(_width); ps->setDisplayLevel(ControlPanelEditor::MARKERS); setDisplayParams(ps); ps->updateSize(); ed->putItem(ps); DrawFrame::closingEvent(true); }
void MapBox::testDateline() { m_mapWidget->setCenter(QGeoCoordinate(0.0, 180.0)); m_mapWidget->setZoomLevel(5.0); QList<QGeoCoordinate> dateline; dateline << QGeoCoordinate(-15.0, 180.0); dateline << QGeoCoordinate(15.0, 180.0); QGeoMapPolylineObject *datelineObject = new QGeoMapPolylineObject(); datelineObject->setPath(dateline); QPen p(Qt::DashLine); p.setColor(Qt::black); p.setWidth(2); //p.setCosmetic(true); datelineObject->setPen(p); m_mapWidget->addMapObject(datelineObject); addRectangle(QGeoCoordinate(-5.0, 179.0), QGeoCoordinate(-6.0, -179.0)); addCircle(QGeoCoordinate(-7.0, 180.0), 50000.0); QList<QGeoCoordinate> polyline; polyline << QGeoCoordinate(-3.0, 180.0); polyline << QGeoCoordinate(-4.0, 179.0); polyline << QGeoCoordinate(-4.0, -179.0); addPolyline(polyline); QList<QGeoCoordinate> polygon; polygon << QGeoCoordinate(0.0, 180.0); polygon << QGeoCoordinate(-2.0, 179.0); polygon << QGeoCoordinate(-2.0, -179.0); addPolygon(polygon); QPixmap pixmap(48, 48); QPainter pixmapPainter(&pixmap); pixmapPainter.fillRect(pixmap.rect(), Qt::yellow); pixmapPainter.setPen(QPen(Qt::black)); pixmapPainter.setBrush(QBrush(Qt::black)); QFont font = pixmapPainter.font(); font.setPointSize(8); pixmapPainter.setFont(font); pixmapPainter.drawText(pixmap.rect(), Qt::AlignCenter, "Pixmap"); addPixmap(QGeoCoordinate(6.0, 180.0), QPoint(-1 * pixmap.width() / 2, -1 * pixmap.width() / 2), pixmap); addText(QGeoCoordinate(4.0, 180.0), QString("Text")); QList<QGeoCoordinate> route; route << QGeoCoordinate(3.0, 180.0); route << QGeoCoordinate(2.5, 179.0); route << QGeoCoordinate(1.5, 179.0); route << QGeoCoordinate(1.0, 180.0); route << QGeoCoordinate(1.5, -179.0); route << QGeoCoordinate(2.5, -179.0); addFakeRoute(route, 3); QGraphicsEllipseItem *ellipseItem = new QGraphicsEllipseItem(QRectF(0.0, 0.0, 96.0, 48.0)); ellipseItem->setBrush(Qt::red); addCustom(QGeoCoordinate(10.0, 180.0), QPoint(-48, -24), ellipseItem); }
void ShapeFormulaNode::AddFillCircle(qreal x, qreal y, qreal radius, QColor& color) { QGraphicsEllipseItem* i = new QGraphicsEllipseItem(x, y, radius, radius, item); i->setBrush(QBrush(color)); ((QGraphicsItemGroup*)item)->addToGroup(i); }
void BaseDrawingWidget::handleDrawingState(DrawingState state, QPointF lastPoint) { // handle drawing start/update/end events for the current drawing mode QPainter::CompositionMode prevCompMode; if(state == DRAWINGSTATE_START) { // start a new series of paint operations on the picture picturePainter.begin(&picture); // set the drawing style for the painter picturePainter.setPen(drawingPen); picturePainter.setBrush(drawingBrush); } switch(drawingMode) { case DRAWINGMODE_FREEHAND: if(state == DRAWINGSTATE_START) { QGraphicsLineItem * newLine = new QGraphicsLineItem(QLineF(lastPoint, lastPoint), 0, getDrawingData()); currentItem = newLine; newLine->setPen(drawingPen); } else if(state == DRAWINGSTATE_UPDATE) { QGraphicsLineItem * newLine = new QGraphicsLineItem(currentItem, getDrawingData()); newLine->setLine(QLineF(mousePrevPoint, lastPoint)); newLine->setPen(drawingPen); picturePainter.drawLine(mousePrevPoint, lastPoint); } else { QGraphicsLineItem * newLine = new QGraphicsLineItem(currentItem, getDrawingData()); newLine->setLine(QLineF(mousePrevPoint, lastPoint)); newLine->setPen(drawingPen); // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); picturePainter.drawLine(mousePrevPoint, lastPoint); } break; case DRAWINGMODE_RECTANGLE: if(state == DRAWINGSTATE_START) { // create a temporary QGraphicsItem // will be committed to the drawing when the mouse is released QGraphicsRectItem * newRect = new QGraphicsRectItem(lastPoint.x(), lastPoint.y(),0,0); currentItem = (QGraphicsItem *) newRect; newRect->setPen(drawingPen); newRect->setBrush(drawingBrush); drawingData->addItem(currentItem); } else if(state == DRAWINGSTATE_UPDATE) // update the temporary QGraphicsItem ((QGraphicsRectItem*)currentItem)->setRect(QRectF(mouseDownPoint,lastPoint).normalized()); else { // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); // commit the drawing to the stage pixmap picturePainter.drawRect(QRectF(mouseDownPoint,lastPoint).normalized()); } break; case DRAWINGMODE_STRAIGHTLINE: if(state == DRAWINGSTATE_START) { // create a temporary QGraphicsItem // will be committed to the drawing when the mouse is released QGraphicsLineItem * newLine = new QGraphicsLineItem(QLineF(lastPoint, lastPoint)); currentItem = (QGraphicsItem*) newLine; newLine->setPen(drawingPen); getDrawingData()->addItem(newLine); } else if(state == DRAWINGSTATE_UPDATE) { // update the temporary QGraphicsItem ((QGraphicsLineItem*)currentItem)->setLine(QLineF(mouseDownPoint, lastPoint)); } else { // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); // commit the drawing to the stage pixmap picturePainter.drawLine(QLineF(mouseDownPoint, lastPoint)); } break; case DRAWINGMODE_ELLIPSE: if(state == DRAWINGSTATE_START) { // create a temporary QGraphicsItem // will be committed to the drawing when the mouse is released QGraphicsEllipseItem * newRect = new QGraphicsEllipseItem(lastPoint.x(), lastPoint.y(),0,0); currentItem = (QGraphicsItem *) newRect; newRect->setPen(drawingPen); newRect->setBrush(drawingBrush); drawingData->addItem(currentItem); } else if(state == DRAWINGSTATE_UPDATE) // update the temporary QGraphicsItem ((QGraphicsRectItem*)currentItem)->setRect(QRectF(mouseDownPoint,lastPoint).normalized()); else { // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); // commit the drawing to the stage pixmap picturePainter.drawEllipse(QRectF(mouseDownPoint,lastPoint).normalized()); } break; case DRAWINGMODE_ERASER: if(state == DRAWINGSTATE_START) { QGraphicsRectItem * newEraseRect = new QGraphicsRectItem(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5)), 0, getDrawingData()); currentItem = newEraseRect; newEraseRect->setPen(QPen(Qt::transparent)); newEraseRect->setBrush(QBrush(Qt::white)); } else if(state == DRAWINGSTATE_UPDATE) { QGraphicsRectItem * newEraseRect = new QGraphicsRectItem(currentItem, getDrawingData()); newEraseRect->setRect(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5))); newEraseRect->setPen(QPen(Qt::transparent)); newEraseRect->setBrush(QBrush(Qt::white)); } else { QGraphicsRectItem * newEraseRect = new QGraphicsRectItem(currentItem, getDrawingData()); newEraseRect->setRect(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5))); newEraseRect->setPen(QPen(Qt::transparent)); newEraseRect->setBrush(QBrush(Qt::white)); // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); } // common in all cases for the eraser: // we have to set a specific composition mode for the eraser // back up the current value prevCompMode = picturePainter.compositionMode(); picturePainter.setCompositionMode(QPainter::CompositionMode_SourceIn); // fill the region to be erased with transparent color picturePainter.fillRect(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5)),Qt::transparent); // restore the old composition mode picturePainter.setCompositionMode(prevCompMode); break; case DRAWINGMODE_ARROW: // TODO not yet implemented - implement this as well break; } if(state == DRAWINGSTATE_END) { // finalize the painting on the QPicture picturePainter.end(); commitDrawing(picture); } }
void B2WorldView::createWorldItems() { qDebug() << "~ " << __PRETTY_FUNCTION__; if(_world && _scene) { // create world ground QGraphicsRectItem *groundItem = _scene->addRect(-100, -0.5, 200, 1); groundItem->setBrush(Qt::gray); groundItem->setPos(0, -0.5); // ground body define b2BodyDef groundBD; groundBD.type = b2_staticBody; groundBD.position.Set(0.0f, 0.5f); // ground shape define b2PolygonShape groundSD; groundSD.SetAsBox(100.0f, 0.5f, b2Vec2(0.0f, 0.0f), 0); // ground fixture define b2FixtureDef groundFD; groundFD.shape = &groundSD; groundFD.density = 0.1f; groundFD.friction = 5.0f; b2Body* groundBody = _world->CreateBody(&groundBD); groundBody->CreateFixture(&groundFD); groundItem = _scene->addRect(-1.0, -2.0, 2.0, 4.0); groundItem->setBrush(Qt::blue); groundItem->setPos(-100.0, -1.0); groundSD.SetAsBox(1.0f, 2.0f, b2Vec2(-100.0f, 0.5f), 0); groundBody->CreateFixture(&groundFD); groundItem = _scene->addRect(-1.0, -2.0, 2.0, 4.0); groundItem->setBrush(Qt::blue); groundItem->setPos(100.0, -0.5); groundSD.SetAsBox(1.0f, 2.0f, b2Vec2(100.0f, 1.0f), 0); groundBody->CreateFixture(&groundFD); groundItem = _scene->addRect(-3.0, -0.5, 6.0, 1.0); groundItem->setBrush(Qt::blue); groundItem->setPos(5, -2.0); groundItem->setRotation(-(PI / 4.0 * 360.0) / (2 * PI)); groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(5.0f, 1.5f), PI/4.0); groundBody->CreateFixture(&groundFD); groundItem = _scene->addRect(-3.0, -0.5, 6.0, 1.0); groundItem->setBrush(Qt::blue); groundItem->setPos(3.5, -1.5); groundItem->setRotation(-(PI / 8.0 * 360.0) / (2 * PI)); groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(3.5f, 1.0f), PI/8.0); groundBody->CreateFixture(&groundFD); groundItem = _scene->addRect(-3.0, -0.5, 6, 1.0); groundItem->setBrush(Qt::blue); groundItem->setPos(9, -2.0); groundItem->setRotation(-(-PI / 4.0 * 360.0) / (2 * PI)); groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(9.0f, 1.5f), -PI/4.0); groundBody->CreateFixture(&groundFD); groundItem = _scene->addRect(-3, -0.5, 6, 1.0); groundItem->setBrush(Qt::blue); groundItem->setPos(10.5, -1.5); groundItem->setRotation(-(-PI / 8.0 * 360.0) / (2 * PI)); groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(10.5f, 1.0f), -PI/8.0); groundBody->CreateFixture(&groundFD); // add random shit // b2CircleShape circleShape; b2FixtureDef circleFixture; circleFixture.shape = &circleShape; circleFixture.density = 0.01; circleFixture.friction = 0.1; circleFixture.restitution = 0.5; for (int i = 0; i < 30; i++) { qreal radius = qrand()%20*0.01+0.02; QGraphicsEllipseItem* circle = _scene->addEllipse(-radius, -radius, radius*2, radius*2); circle->setBrush(Qt::green); circle->setPos(qrand()%35+15.0, -1.5); _circles << circle; circleShape.m_radius = radius; b2BodyDef circleBD; circleBD.type = b2_dynamicBody; circleBD.position.Set(circle->pos().x(), -circle->pos().y()); circleBD.allowSleep = true; circleBD.linearDamping = 0.1; circleBD.angularDamping = 0.1; b2Body* circleBody = _world->CreateBody(&circleBD); circleBody->CreateFixture(&circleFixture); _circleBodies << circleBody; } // create kart _kart = new B2Kart(_world, _scene); } }
void KMapScene::updatePath() { if(pathLength == 0){ return; } QGraphicsLineItem *path; QGraphicsEllipseItem *ellipse; QGraphicsLineItem *smallLine; QPoint toP (0, 0), fromP (0, 0); int r, s, o; pathLineListRectReset(); //setup up in the background the path line and then in the foreground the robot positions for (int ways = 0; ways < pathLength; ways++) { if (pathR[ways] == -1 && pathS[ways] == -1) break; r = pathR[ways]; s = pathS[ways]; if(r == 255 || s == 255){ toP.setX (toGrid(0)); toP.setY (toGrid(0)); }else{ toP.setX (cellCenterX[r][s]); toP.setY (cellCenterY[r][s]); } if(ways == 0 || ways == 1){ fromP.setX (toGrid(0)); fromP.setY (toGrid(0)); }else{ fromP.setX (cellCenterX[pathR[ways-1]][pathS[ways-1]]); fromP.setY (cellCenterY[pathR[ways-1]][pathS[ways-1]]); } path = pathLineList.at (ways); path->setLine (fromP.x(), fromP.y(), toP.x(), toP.y() ); if(ways < pathLength){ ellipse = pathEllipseList.at (ways); QPoint ellipseCenter;// ( cellCenterX[pathR[ways]][pathS[ways]] , cellCenterY[pathR[ways]][pathS[ways]] ); if(r == 255 || s == 255){ ellipseCenter.setX(toGrid(0)); ellipseCenter.setY(toGrid(0)); }else{ ellipseCenter.setX(cellCenterX[r][s]); ellipseCenter.setY(cellCenterY[r][s]); } ellipse->setRect (ellipseCenter.x() - 5, ellipseCenter.y() - 5, 10, 10); float color = 100.0f + 155.0f*((float)(ways+1)/(float)pathLength); ellipse->setBrush (QColor ((int) color, 0, 0) ); int pix = 7; smallLine = pathSmallLineList.at (ways); int orientation = pathO[ways]; //orientation = orientation*2*M_PI/8; //cout << "Mpika " << toGrid (targetRing*moveStepInMeters)/2 << " " << toGrid (targetCell*moveStepInMeters)/2 << endl; float angle = orientation*2*M_PI/8.0f; int newX = -KMath::toCartesianY ( 10, angle); int newY = -KMath::toCartesianX ( 10, angle); toP.setX ( ellipseCenter.x() + newX); toP.setY (ellipseCenter.y() + newY ); smallLine->setLine (ellipseCenter.x(), ellipseCenter.y(), toP.x(), toP.y() ); //cout << ways << " " << orientation << endl; } } }