void QgsHighlight::paintPolygon( QPainter *p, QgsPolygon polygon ) { // OddEven fill rule by default QPainterPath path; p->setPen( mPen ); p->setBrush( mBrush ); for ( int i = 0; i < polygon.size(); i++ ) { if ( polygon[i].empty() ) continue; QPolygonF ring; ring.reserve( polygon[i].size() + 1 ); for ( int j = 0; j < polygon[i].size(); j++ ) { //adding point only if it is more than a pixel appart from the previous one const QPointF cur = toCanvasCoordinates( polygon[i][j] ) - pos(); if ( 0 == j || std::abs( ring.back().x() - cur.x() ) > 1 || std::abs( ring.back().y() - cur.y() ) > 1 ) { ring.push_back( cur ); } } ring.push_back( ring[ 0 ] ); path.addPolygon( ring ); } p->drawPath( path ); }
void NodeBackDrop::resize(int w,int h) { QMutexLocker l(&_imp->bboxMutex); QPointF p = pos(); QPointF thisItemPos = mapFromParent(p); QRectF textBbox = _imp->name->boundingRect(); if (w < textBbox.width()) { w = textBbox.width(); } int minH = (textBbox.height() * 1.5) + 20; if (h < minH) { h = minH; } setRect(QRectF(thisItemPos.x(),thisItemPos.y(),w,h)); _imp->header->setRect(QRect(thisItemPos.x(),thisItemPos.y(),w,textBbox.height() * 1.5)); _imp->name->setPos(thisItemPos.x() + w / 2 - textBbox.width() / 2,thisItemPos.y() + 0.25 * textBbox.height()); _imp->label->setPos(thisItemPos.x(), thisItemPos.y() + textBbox.height() * 1.5 + 10); _imp->label->setTextWidth(w); QPolygonF resizeHandle; QPointF bottomRight(thisItemPos.x() + w,thisItemPos.y() + h); resizeHandle.push_back(QPointF(bottomRight.x() - 20,bottomRight.y())); resizeHandle.push_back(bottomRight); resizeHandle.push_back(QPointF(bottomRight.x(), bottomRight.y() - 20)); _imp->resizeHandle->setPolygon(resizeHandle); }
void Triangle::transformerEnPolygone(QPolygonF &polygone , QVector<QPointF>& points) { polygone.clear(); polygone.push_back(points[this->sommets[0]]); polygone.push_back(points[this->sommets[1]]); polygone.push_back(points[this->sommets[2]]); }
/** * whether a given point is within image region *@ coord, a point *@ returns true, if the point is within borders of image */ bool RS_Image::containsPoint(const RS_Vector& coord) const{ QPolygonF paf; RS_VectorSolutions corners =getCorners(); for(const RS_Vector& vp: corners){ paf.push_back(QPointF(vp.x, vp.y)); } paf.push_back(paf.at(0)); return paf.containsPoint(QPointF(coord.x,coord.y),Qt::OddEvenFill); }
std::vector<QPolygonF> GraphicsArrowItem::compose() { const qreal pi = 3.14; QLineF l = QLineF(line()); double arrowSize = (l.length() < 200.0) ? 10.0 : l.length()/20.0; //double arrowSize = 10.0; int dx = l.p2().x() - l.p1().x(); int dy = l.p2().y() - l.p1().y(); double angle = ::acos(dx/l.length()); if (dx >= 0 && dy > 0) angle = (pi * 2) - angle; else if (dx >= 0 && dy <= 0) { } else if (dx < 0 && dy > 0) angle = (pi * 2) - angle; else if (dx < 0 && dy <= 0) { } QPointF P1 = l.p1() + QPointF(::sin(angle+pi/3.0)*arrowSize, ::cos(angle+pi/3.0)*arrowSize); QPointF P2 = l.p1() + QPointF(::sin(angle+pi-pi/3.0)*arrowSize, ::cos(angle+pi-pi/3.0)*arrowSize); QPointF P3 = l.p2() + QPointF(::sin(angle-pi/3.0)*arrowSize, ::cos(angle-pi/3.0)*arrowSize); QPointF P4 = l.p2() + QPointF(::sin(angle+pi+pi/3.0)*arrowSize, ::cos(angle+pi+pi/3.0)*arrowSize); std::vector<QPolygonF> cont; //double off = 0.5*arrowSize*1.732; //QPointF offset(off, off); if (arrowHead == Start) { QPolygonF polybuilder; polybuilder.push_back(P1); polybuilder.push_back(l.p1()); polybuilder.push_back(P2); polybuilder.push_back(P1); cont.push_back(polybuilder); //QLineF newline(line()); //newline.setP1(newline.p1()-offset); } else if (arrowHead == End) { QPolygonF polybuilder; polybuilder.push_back(P3); polybuilder.push_back(l.p2()); polybuilder.push_back(P4); polybuilder.push_back(P3); cont.push_back(polybuilder); } else if (arrowHead == Both) { QPolygonF polybuilder; polybuilder.push_back(P1); polybuilder.push_back(l.p1()); polybuilder.push_back(P2); polybuilder.push_back(P1); QPolygonF polybuilder2; polybuilder2.push_back(P3); polybuilder2.push_back(l.p2()); polybuilder2.push_back(P4); polybuilder2.push_back(P3); cont.push_back(polybuilder); cont.push_back(polybuilder2); } return cont; }
void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { // We don't have enougth data to calculate things, quit. if (!shouldCalculateStuff(topLeft, bottomRight)) return; int last_index = -1; QPolygonF boundingPoly; // This is the "Whole Item", but a pressure can be divided in N Polygons. polygons.clear(); for (int i = 0, count = dataModel->rowCount(); i < count; i++) { plot_data *entry = dataModel->data().entry + i; int mbar = GET_PRESSURE(entry); if (entry->cylinderindex != last_index) { polygons.append(QPolygonF()); // this is the polygon that will be actually drawned on screen. last_index = entry->cylinderindex; } if (!mbar) { continue; } QPointF point(hAxis->posAtValue(entry->sec), vAxis->posAtValue(mbar)); boundingPoly.push_back(point); // The BoundingRect polygons.last().push_back(point); // The polygon thta will be plotted. } setPolygon(boundingPoly); qDeleteAll(texts); texts.clear(); int mbar, cyl; int seen_cyl[MAX_CYLINDERS] = { false, }; int last_pressure[MAX_CYLINDERS] = { 0, }; int last_time[MAX_CYLINDERS] = { 0, }; struct plot_data *entry; cyl = -1; for (int i = 0, count = dataModel->rowCount(); i < count; i++) { entry = dataModel->data().entry + i; mbar = GET_PRESSURE(entry); if (!mbar) continue; if (cyl != entry->cylinderindex) { cyl = entry->cylinderindex; if (!seen_cyl[cyl]) { plotPressureValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignTop); plotGasValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom, displayed_dive.cylinder[cyl].gasmix); seen_cyl[cyl] = true; } } last_pressure[cyl] = mbar; last_time[cyl] = entry->sec; } for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { if (last_time[cyl]) { plotPressureValue(last_pressure[cyl], last_time[cyl], Qt::AlignLeft | Qt::AlignTop); } } }
void AccumulateEnergy::DrawAccumulateEnergy(QPainter &painter) { float y = draw_area_range.bottom() - dheight_ - 15; float x = draw_area_range.left(); QPolygonF points; float accumulateenergydata = 0; float maxaccumulateenergy = maxaccumulateenergy_; if (maxaccumulateenergy == 0) { maxaccumulateenergy = 1; } for(int i = 0;i<datas_.size();i++) { EnergyData ei = datas_.value(i); accumulateenergydata += ei.energy; float xt = x + i* draw_area_range.width() / days_; float yt = y - accumulateenergydata*(uheight_ - 15) / maxaccumulateenergy; points.push_back(QPointF(xt,yt)); } painter.save(); QPen pen; pen.setColor(Qt::blue); painter.setPen(pen); painter.drawPolyline(points); painter.restore(); }
QPolygonF fillLine(const QPointF &first_, const QPointF &second_) { QPolygonF filled; QPointF first = first_, second = second_; double m = 0; double x1 = first.x(); double y1 = first.y(); double x2 = second.x(); double y2 = second.y(); filled << first; if (x2 == x1) return filled; m = (y2 - y1) / (x2 - x1); for (double x = x1; x < qMax(first.x(), second.x()); x += 1) { QPointF point; point.setX(x); point.setY(y1+m*(x-x1)); if (m < 0) filled.push_back(point); else if (m > 0) filled << point; } return filled; }
void PartialPressureGasItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) { //AbstractProfilePolygonItem::modelDataChanged(); if (!shouldCalculateStuff(topLeft, bottomRight)) return; plot_data *entry = dataModel->data().entry; QPolygonF poly; alertPoly.clear(); QSettings s; s.beginGroup("TecDetails"); double threshould = s.value(threshouldKey).toDouble(); for(int i = 0; i < dataModel->rowCount(); i++, entry++){ double value = dataModel->index(i, vDataColumn).data().toDouble(); int time = dataModel->index(i, hDataColumn).data().toInt(); QPointF point(hAxis->posAtValue(time), vAxis->posAtValue(value)); poly.push_back( point ); if (value >= threshould) alertPoly.push_back(point); } setPolygon(poly); /* createPPLegend(trUtf8("pN" UTF8_SUBSCRIPT_2),getColor(PN2), legendPos); */ }
QPolygonF ObstacleBitmap::minusPolygon(const QPolygonF& polygon)const{ QPolygonF ret; for (int i = 0; i < polygon.size(); i++) { ret.push_back(polygon.at(i) * -1.0); } return ret; }
void get_part_polygon(const PartBBox &part_bbox, QPolygonF &polygon) { polygon.clear(); boost_math::double_vector t(2); t = part_bbox.part_x_axis*part_bbox.min_proj_x + part_bbox.part_y_axis*part_bbox.min_proj_y + part_bbox.part_pos; polygon.push_back(QPointF(t(0), t(1))); t = part_bbox.part_x_axis*part_bbox.max_proj_x + part_bbox.part_y_axis*part_bbox.min_proj_y + part_bbox.part_pos; polygon.push_back(QPointF(t(0), t(1))); t = part_bbox.part_x_axis*part_bbox.max_proj_x + part_bbox.part_y_axis*part_bbox.max_proj_y + part_bbox.part_pos; polygon.push_back(QPointF(t(0), t(1))); t = part_bbox.part_x_axis*part_bbox.min_proj_x + part_bbox.part_y_axis*part_bbox.max_proj_y + part_bbox.part_pos; polygon.push_back(QPointF(t(0), t(1))); }
QPolygonF read_line(uint8_t byte_order, InputIterator& itr, const frame& fr) { const uint32_t count(brig::detail::ogc::read<uint32_t>(byte_order, itr)); QPolygonF line; line.reserve(count); for (uint32_t i(0); i < count; ++i) line.push_back( read_point(byte_order, itr, fr) ); return line; }
void FormView::showForm(AbstractForm * form) { QGraphicsScene *s = scene(); s->clear(); resetTransform(); if(form == 0){ return; } if(form->get_number_of_points() <= 0) { return; } int factor = 100; QPolygonF polygon; for(int i=0; i<form->get_number_of_points(); ++i){ Point point = form->get_point_at_index(i); polygon.push_back(QPointF(point.get_x()*factor, point.get_y()*factor)); } s->addPolygon(polygon, QPen(), QBrush(Qt::SolidPattern)); QRectF bound = polygon.boundingRect(); s->setSceneRect(bound); float realwidth = container->width() - 50; float width = bound.width(); float realheight = container->height() - 50; float height = bound.height(); float relw = 1; if(width > 0){ relw = realwidth / width; } float relh = 1; if(height > 0){ relh = realheight / height; } float rel = relw; if(relh < relw){ rel = relh; } scale(rel,rel); }
void KisCategorizedItemDelegate::paintTriangle(QPainter* painter, qint32 x, qint32 y, qint32 size, bool rotate) const { QPolygonF triangle; triangle.push_back(QPointF(-0.2,-0.2)); triangle.push_back(QPointF( 0.2,-0.2)); triangle.push_back(QPointF( 0.0, 0.2)); QTransform transform; transform.translate(x + size/2, y + size/2); transform.scale(size, size); if(rotate) transform.rotate(-90); QPalette palette = QApplication::palette(); painter->setBrush(palette.buttonText()); painter->drawPolygon(transform.map(triangle)); }
static QPolygonF createShape(QSize const& image_size, double radius) { QPointF const center(0.5 * image_size.width(), 0.5 * image_size.height()); double const PI = 3.14159265; double angle = PI / 2.0; int const num_steps = 5; double const step = PI * 2.0 / num_steps; QPolygonF poly; poly.push_back(center + QPointF(cos(angle), sin(angle)) * radius); for (int i = 1; i < num_steps; ++i) { angle += step * 2; poly.push_back(center + QPointF(cos(angle), sin(angle)) * radius); } return poly; }
QPolygonF DkRotatingRect::getClosedPoly() { if (rect.isEmpty()) return QPolygonF(); QPolygonF closedPoly = rect; closedPoly.push_back(closedPoly[0]); return closedPoly; }
QPainterPath ItemPhysEnv::shape() const { QPainterPath path; QPolygonF lineBoarder; QVector<qreal> points = {0.0, 0.0, this->data(ITEM_WIDTH).toReal(), this->data(ITEM_HEIGHT).toReal()}; #define PLEFT 0 #define PTOP 1 #define PRIGHT 2 #define PBOTTOM 3 lineBoarder.push_back(QPointF(points[PLEFT], points[PTOP])); lineBoarder.push_back(QPointF(points[PRIGHT], points[PTOP])); lineBoarder.push_back(QPointF(points[PRIGHT], points[PBOTTOM])); lineBoarder.push_back(QPointF(points[PLEFT], points[PBOTTOM])); lineBoarder.push_back(QPointF(points[PLEFT], points[PTOP])); lineBoarder.push_back(QPointF(points[PLEFT] + 4, points[PTOP])); lineBoarder.push_back(QPointF(points[PLEFT] + 4, points[PBOTTOM] - 4)); lineBoarder.push_back(QPointF(points[PRIGHT] - 4,points[PBOTTOM] - 4)); lineBoarder.push_back(QPointF(points[PRIGHT] - 4,points[PTOP] + 4)); lineBoarder.push_back(QPointF(points[PLEFT], points[PTOP] + 4)); #undef PLEFT #undef PTOP #undef PRIGHT #undef PBOTTOM path.addPolygon(lineBoarder); return path; }
void fonctionsCommunes::Frame(QGraphicsScene *scene, QVector<Triangle> &triangles, QVector<QPointF> &points) { QPointF p1 = QPointF(240 , 0 ) ; QPointF p2 = QPointF(0 , 440 ) ; QPointF p3 = QPointF(-240 ,0 ) ; //---intiialiser le triangle à dessiner QPolygonF P ; P.push_back(p1); P.push_back(p2); P.push_back(p3); //---initialiser l'ensemble des points points.clear(); points.push_back(p1); points.push_back(p2); points.push_back(p3); //---initialiser le réseau de triangles triangles.clear(); Triangle T ; T.id = 0 ; T.sommets[0] = 0 ; T.sommets[1] = 1 ; T.sommets[2] = 2 ; T.adjacents[0] = -1 ; T.adjacents[1] = -1 ; T.adjacents[2] = -1 ; T.caclulerCentreCirconscrit(points); triangles.push_back(T); //---initialiser la scène dans le viewer scene->clear(); scene->addPolygon(P , QPen(Qt::red , 1 , Qt::DashLine )) ; }
void ViewPort::drawPoligono(QPainter* painter, Poligono* poligono){ if(!poligono->aberto){ QPolygonF polygon = QPolygonF(false); list<Coordenada*>::iterator it = poligono->getCPPCoordenadas()->begin(); for (; it!= poligono->getCPPCoordenadas()->end(); it++) { calculeCoordenadaVP(*it); polygon.push_back(QPointF((*it)->getX(), (*it)->getY())); } painter->setBrush(QBrush(*poligono->color, Qt::SolidPattern)); painter->drawPolygon(polygon, Qt::OddEvenFill); painter->setBrush(QBrush()); } }
QPolygonF ObstacleBitmap::minkowskiSums(const QPolygonF& polygonV, const QPolygonF& polygonW){ std::vector<QPointF> vertexV = initPolygonVertex(findFirstVertex(polygonV), polygonV); std::vector<QPointF> vertexW = initPolygonVertex(findFirstVertex(polygonW), polygonW); QPolygonF ret; int i = 0; int j = 0; size_t vSize = vertexV.size(); size_t wSize = vertexW.size(); do{ qreal x = vertexV.at(i%vSize).x() + vertexW.at(j%wSize).x(); qreal y = vertexV.at(i%vSize).y() + vertexW.at(j%wSize).y(); ret.push_back(QPointF(x, y)); QPointF V = vertexV.at((i+1)%vSize) - vertexV.at(i%vSize); QPointF W = vertexW.at((j+1)%wSize) - vertexW.at(j%wSize); double angle1 = CoordinateTransform::toPositiveDegree(std::atan2(V.y(), V.x())); double angle2 = CoordinateTransform::toPositiveDegree(std::atan2(W.y(), W.x())); if(i == polygonV.size()){ //if(angle1 == 0.0){ angle1 = 360.0; //} } if(j == polygonW.size()){ //if(angle2 == 0.0){ angle2 = 360.0; //} } if(angle1 < angle2){ ++i; } else if(angle1 > angle2){ ++j; } else{ ++i; ++j; } }while((i < polygonV.size()) || (j < polygonW.size())); return ret; }
// draw an arrowhead QGraphicsPolygonItem* GAction::makeArrowHead(const GVEdge& e, const QColor& color) { // arrow pointing to the right QPointF p = e.path.pointAtPercent(1); QPointF* q = new QPointF(p.x() - 8, p.y() - 5); QPointF* r = new QPointF(p.x() - 8, p.y() + 5); QPolygonF polygon; polygon.push_back(p); polygon.push_back(*q); polygon.push_back(*r); // rotate arrow QMatrix matrix; matrix.translate(p.x(), p.y()); matrix.rotate(-e.path.angleAtPercent(1)); matrix.translate(-p.x(), -p.y()); polygon = matrix.map(polygon); // turn into QGraphicsPolygonItem QGraphicsPolygonItem* res = new QGraphicsPolygonItem (polygon, display); res->setPen(QPen(color)); res->setBrush(QBrush(color)); return res; }
MapEditor::MapEditor(QGraphicsScene* scene) : scene_(scene) { copypaste_items_.clear(); selection_stage_ = 0; first_selection_x_ = 0; first_selection_y_ = 0; second_selection_x_ = 0; second_selection_y_ = 0; QPolygonF p; p.push_back(QPointF(0.0, 0.0)); p.push_back(QPointF(0.0, 32.0)); p.push_back(QPointF(32.0, 32.0)); p.push_back(QPointF(32.0, 0.0)); QPen pen(QColor(200, 0, 0)); QBrush brush(QColor(100, 0, 100, 100)); pointer_.image = scene->addPolygon(p, pen, brush); pointer_.image->setZValue(100); QPolygonF p2; p2.push_back(QPointF(0.0, 0.0)); p2.push_back(QPointF(0.0, 10 * 32.0)); p2.push_back(QPointF(10 * 32.0, 10 * 32.0)); p2.push_back(QPointF(10 * 32.0, 0.0)); QPen pen2(QColor(0, 100, 200)); pen2.setWidth(2); border_image_ = scene->addPolygon(p2, pen2); border_image_->setZValue(99); }
QPolygonF XmlUnmarshaller::polygonF(QDomElement const& el) { QPolygonF poly; QString const point_tag_name("point"); QDomNode node(el.firstChild()); for (; !node.isNull(); node = node.nextSibling()) { if (!node.isElement()) { continue; } if (node.nodeName() != point_tag_name) { continue; } poly.push_back(pointF(node.toElement())); } return poly; }
void ComboBox::paintEvent(QPaintEvent* /*e*/) { QStyleOption opt; opt.initFrom(this); QPainter p(this); QRectF bRect = rect(); { ///Now draw the frame QColor fillColor; if (_clicked || _dirty) { fillColor = Qt::black; } else { double r, g, b; switch (_animation) { case 0: default: { appPTR->getCurrentSettings()->getRaisedColor(&r, &g, &b); break; } case 1: { appPTR->getCurrentSettings()->getInterpolatedColor(&r, &g, &b); break; } case 2: { appPTR->getCurrentSettings()->getKeyframeColor(&r, &g, &b); break; } case 3: { appPTR->getCurrentSettings()->getExprColor(&r, &g, &b); break; } } fillColor.setRgb( Color::floatToInt<256>(r), Color::floatToInt<256>(g), Color::floatToInt<256>(b) ); } double fw = frameWidth(); QPen pen; if ( !hasFocus() ) { pen.setColor(Qt::black); } else { double r, g, b; appPTR->getCurrentSettings()->getSelectionColor(&r, &g, &b); QColor c; c.setRgb( Color::floatToInt<256>(r), Color::floatToInt<256>(g), Color::floatToInt<256>(b) ); fw = 2; } p.setPen(pen); QRectF roundedRect = bRect.adjusted(fw / 2., fw / 2., -fw, -fw); bRect.adjust(fw, fw, -fw, -fw); p.fillRect(bRect, fillColor); double roundPixels = 3; QPainterPath path; path.addRoundedRect(roundedRect, roundPixels, roundPixels); p.drawPath(path); } QColor textColor; if (_readOnly) { textColor.setRgb(100, 100, 100); } else if (_altered) { double aR, aG, aB; appPTR->getCurrentSettings()->getAltTextColor(&aR, &aG, &aB); textColor.setRgbF(aR, aG, aB); } else if (!_enabled) { textColor = Qt::black; } else { double r, g, b; appPTR->getCurrentSettings()->getTextColor(&r, &g, &b); textColor.setRgb( Color::floatToInt<256>(r), Color::floatToInt<256>(g), Color::floatToInt<256>(b) ); } { Qt::Alignment align = QStyle::visualAlignment( Qt::LeftToRight, QFlag(_align) ); int flags = align | Qt::TextForceLeftToRight; ///Draw the text QPen pen = p.pen(); if (_currentIndex == -1) { QFont f = p.font(); f.setItalic(true); p.setFont(f); } pen.setColor(textColor); p.setPen(pen); QRectF lr = layoutRect().toAlignedRect(); p.drawText(lr.toRect(), flags, _currentText); } { ///Draw the dropdown icon QPainterPath path; QPolygonF poly; poly.push_back( QPointF(bRect.right() - DROP_DOWN_ICON_SIZE * 3. / 2., bRect.height() / 2. - DROP_DOWN_ICON_SIZE / 2.) ); poly.push_back( QPointF(bRect.right() - DROP_DOWN_ICON_SIZE / 2., bRect.height() / 2. - DROP_DOWN_ICON_SIZE / 2.) ); poly.push_back( QPointF(bRect.right() - DROP_DOWN_ICON_SIZE, bRect.height() / 2. + DROP_DOWN_ICON_SIZE / 2.) ); path.addPolygon(poly); p.fillPath(path, textColor); } } // ComboBox::paintEvent
// CalculateBoorNet - inserts new control points with de Boor algorithm for // transformation of B-spline into composite Bezier curve. void BezierInterpolator::CalculateBoorNet(const QVector<QPointF *> &controlPoints, const QVector<qreal> &knotVector, QPolygonF &boorNetPoints) const { Q_ASSERT(controlPoints.size() > 2); Q_ASSERT(knotVector.size() > 4); // We draw uniform cubic B-spline that passes through endpoints, so we assume // that multiplicity of first and last knot is 4 and 1 for knots between. QVector<qreal> newKnotVector = knotVector; boorNetPoints.clear(); for (int counter = 0; counter < controlPoints.size(); ++counter) boorNetPoints.push_back(*controlPoints[counter]); // Insert every middle knot 2 times to increase its multiplicity from 1 to 3. const int curveDegree = 3; const int increaseMultiplicity = 2; for (int knotCounter = 4; knotCounter < newKnotVector.size() - 4; knotCounter += 3) { QHash< int, QHash<int, QPointF> > tempPoints; for (int counter = knotCounter - curveDegree; counter <= knotCounter; ++counter) tempPoints[counter][0] = boorNetPoints[counter]; for (int insertCounter = 1; insertCounter <= increaseMultiplicity; ++insertCounter) for (int i = knotCounter - curveDegree + insertCounter; i < knotCounter; ++i) { double coeff = (newKnotVector[knotCounter] - newKnotVector[i]) / (newKnotVector[i + curveDegree - insertCounter + 1] - newKnotVector[i]); QPointF newPoint = (1.0 - coeff) * tempPoints[i - 1][insertCounter - 1] + coeff * tempPoints[i][insertCounter - 1]; tempPoints[i][insertCounter] = newPoint; } for (int counter = 0; counter < increaseMultiplicity; ++counter) newKnotVector.insert(knotCounter, newKnotVector[knotCounter]); // Fill new control points. QPolygonF newBoorNetPoints; for (int counter = 0; counter <= knotCounter - curveDegree; ++counter) newBoorNetPoints.push_back(boorNetPoints[counter]); for (int counter = 1; counter <= increaseMultiplicity; ++counter) { QPointF &newP = tempPoints[knotCounter - curveDegree + counter][counter]; newBoorNetPoints.push_back(newP); } for (int counter = -curveDegree + increaseMultiplicity + 1; counter <= -1; ++counter) { QPointF &newP = tempPoints[knotCounter + counter][increaseMultiplicity]; newBoorNetPoints.push_back(newP); } for (int counter = increaseMultiplicity - 1; counter >= 1; --counter) newBoorNetPoints.push_back(tempPoints[knotCounter - 1][counter]); for (int counter = knotCounter - 1; counter < boorNetPoints.size(); ++counter) newBoorNetPoints.push_back(boorNetPoints[counter]); boorNetPoints = newBoorNetPoints; } }
void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { // We don't have enougth data to calculate things, quit. if (!shouldCalculateStuff(topLeft, bottomRight)) return; int plotted_cyl[MAX_CYLINDERS] = { false, }; int last_plotted[MAX_CYLINDERS] = { 0, }; QPolygonF poly[MAX_CYLINDERS]; QPolygonF boundingPoly; polygons.clear(); for (int i = 0, count = dataModel->rowCount(); i < count; i++) { struct plot_data *entry = dataModel->data().entry + i; for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { int mbar = GET_PRESSURE(entry, cyl); int time = entry->sec; if (!mbar) continue; QPointF point(hAxis->posAtValue(time), vAxis->posAtValue(mbar)); boundingPoly.push_back(point); if (plotted_cyl[cyl]) { /* Have we used this culinder in the last two minutes? Continue */ if (time - last_plotted[cyl] <= 2*60) { poly[cyl].push_back(point); last_plotted[cyl] = time; continue; } /* Finish the previous one, start a new one */ polygons.append(poly[cyl]); poly[cyl] = QPolygonF(); } plotted_cyl[cyl] = true; last_plotted[cyl] = time; poly[cyl].push_back(point); } } for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { if (!plotted_cyl[cyl]) continue; polygons.append(poly[cyl]); } setPolygon(boundingPoly); qDeleteAll(texts); texts.clear(); int seen_cyl[MAX_CYLINDERS] = { false, }; int last_pressure[MAX_CYLINDERS] = { 0, }; int last_time[MAX_CYLINDERS] = { 0, }; // These are offset values used to print the gas lables and pressures on a // dive profile at appropriate Y-coordinates. We alternate aligning the // label and the gas pressure above and under the pressure line. // The values are historical, and we could try to pick the over/under // depending on whether this pressure is higher or lower than the average. // Right now it's just strictly alternating when you have multiple gas // pressures. QFlags<Qt::AlignmentFlag> alignVar = Qt::AlignTop; QFlags<Qt::AlignmentFlag> align[MAX_CYLINDERS]; double axisRange = (vAxis->maximum() - vAxis->minimum())/1000; // Convert axis pressure range to bar double axisLog = log10(log10(axisRange)); for (int i = 0, count = dataModel->rowCount(); i < count; i++) { struct plot_data *entry = dataModel->data().entry + i; for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { int mbar = GET_PRESSURE(entry, cyl); if (!mbar) continue; if (!seen_cyl[cyl]) { double value_y_offset, label_y_offset; // Magic Y offset depending on whether we're aliging // the top of the text or the bottom of the text to // the pressure line. value_y_offset = -0.5; if (alignVar & Qt::AlignTop) { label_y_offset = 5 * axisLog; } else { label_y_offset = -7 * axisLog; } plotPressureValue(mbar, entry->sec, alignVar, value_y_offset); plotGasValue(mbar, entry->sec, displayed_dive.cylinder[cyl].gasmix, alignVar, label_y_offset); seen_cyl[cyl] = true; /* Alternate alignment as we see cylinder use.. */ align[cyl] = alignVar; alignVar ^= Qt::AlignTop | Qt::AlignBottom; } last_pressure[cyl] = mbar; last_time[cyl] = entry->sec; } } // For each cylinder, on right hand side of profile, write cylinder pressure for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { if (last_time[cyl]) { double value_y_offset = -0.5; plotPressureValue(last_pressure[cyl], last_time[cyl], align[cyl] | Qt::AlignLeft, value_y_offset); } } }
std::vector<QPolygonF> ObstacleBitmap::drawCSpace(const Robot& robot, const Configuration& config){ std::vector<QPolygonF> ret; for (size_t i = 0; i < obstacles.size(); i++){ for(size_t j = 0; j < obstacles.at(i).NPolygons(); j++){ QPolygonF transObstacle(CoordinateTransform::toPlannerPoints(obstacles.at(i).getPolygonF(j), obstacles.at(i).getInitialConfiguration(), Constant::SWP)); for(size_t k = 0; k < robot.NPolygons(); k++){ QPolygonF transRobot(minusPolygon(QPolygonF(CoordinateTransform::toPlannerPoints(robot.getPolygonF(k), config, Constant::SWP)))); //qDebug() << "robot: " << transRobot; //qDebug() << "Obstacle: " << transObstacle; QPolygonF result = minkowskiSums(transObstacle, transRobot); //qDebug() << "result: " << result; ret.push_back(result); drawObstacle(result); } } } QPolygonF top; top.push_back(QPointF(0, -1)); top.push_back(QPointF(0, -2)); top.push_back(QPointF(Constant::BITMAPSIZE, -2)); top.push_back(QPointF(Constant::BITMAPSIZE, -1)); QPolygonF bottom; bottom.push_back(QPointF(0, Constant::BITMAPSIZE+1)); bottom.push_back(QPointF(0, Constant::BITMAPSIZE)); bottom.push_back(QPointF(Constant::BITMAPSIZE, Constant::BITMAPSIZE)); bottom.push_back(QPointF(Constant::BITMAPSIZE, Constant::BITMAPSIZE+1)); QPolygonF left; left.push_back(QPointF(-2, 0)); left.push_back(QPointF(-1, 0)); left.push_back(QPointF(-1, Constant::BITMAPSIZE)); left.push_back(QPointF(-2, Constant::BITMAPSIZE)); QPolygonF right; right.push_back(QPointF(Constant::BITMAPSIZE, 0)); right.push_back(QPointF(Constant::BITMAPSIZE+1, 0)); right.push_back(QPointF(Constant::BITMAPSIZE+1, Constant::BITMAPSIZE)); right.push_back(QPointF(Constant::BITMAPSIZE, Constant::BITMAPSIZE)); for(size_t k = 0; k < robot.NPolygons(); k++){ QPolygonF transRobot(CoordinateTransform::toPlannerPoints(robot.getPolygonF(k), config, Constant::SWP)); QPolygonF result1 = minkowskiSums(top, transRobot); QPolygonF result2 = minkowskiSums(bottom, transRobot); QPolygonF result3 = minkowskiSums(left, transRobot); QPolygonF result4 = minkowskiSums(right, transRobot); ret.push_back(result1); drawObstacle(result1); ret.push_back(result2); drawObstacle(result2); ret.push_back(result3); drawObstacle(result3); ret.push_back(result4); drawObstacle(result4); } return ret; }
void FormView::showSetting(Setting setting) { QGraphicsScene *s = scene(); s->clear(); resetTransform(); int scale_fac = 10; int spacing = 20; int planeWidth = setting.get_problem()->get_plane_width()*scale_fac; int planeHeight = setting.get_problem()->get_plane_height()*scale_fac; QRectF bound; for (int i=0; i<setting.get_number_of_planes(); ++i) { int x_offset = i*(planeWidth+spacing)+(spacing/2); int y_offset = (spacing/2); QRectF plane(x_offset,y_offset,planeWidth, planeHeight); s->addRect(plane,QPen(), QBrush(QColor(188, 198, 204),Qt::SolidPattern)); for (int j=0; j<setting.get_plane_at(i)->get_number_of_forms(); ++j) { QPolygonF polygon; Form form; setting.get_plane_at(i)->get_form_at(j, form); vector<Point> points_of_current_form = *(form.get_points()); for (int k=0; k<points_of_current_form.size(); ++k){ Point point = points_of_current_form[k]; polygon.push_back(QPointF(point.get_x()*scale_fac, point.get_y()*scale_fac)); } QGraphicsPolygonItem * polyitem = s->addPolygon(polygon, QPen(QColor(Qt::red)), QBrush(Qt::SolidPattern)); polyitem->setPos(x_offset, y_offset); bound = polygon.boundingRect(); } } float realwidth = container->width() - 50; float width = setting.get_number_of_planes()*(planeWidth+spacing); float realheight = container->height() - 50; float height = planeHeight+spacing; s->setSceneRect(0,0,width,height); float relw = 1; if(width > 0){ relw = realwidth / width; } float relh = 1; if(height > 0){ relh = realheight / height; } float rel = relw; if(relh < relw){ rel = relh; } scale(rel,rel); }
void TimelineWidget::paintEvent(QPaintEvent* event) { if (similar(mStart,mStop)) return; QWidget::paintEvent(event); QPainter painter(this); // QPen pointPen, pointLinePen; painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); QColor gray0(240, 240, 240); QColor gray01(220, 220, 220); QColor gray1(200, 200, 200); QColor gray2(170, 170, 170); // darker QColor gray3(150, 150, 150); // even darker QColor gray4(100, 100, 100); // even darker QColor highlight(110, 214, 255); // color around highlighted circle in qslider on KDE. // Fill with white background color and grey plot area background color QBrush brush(Qt::SolidPattern); // = painter.brush(); brush.setColor(gray2); painter.setBrush(brush); painter.drawRoundedRect(this->mFullArea, 4, 4); // brush.setColor(gray01); brush.setColor(gray1); painter.setBrush(brush); painter.drawRoundedRect(this->mPlotArea, 4, 4); int margin = 1; // draw noncompacted interval for (unsigned i = 0; i < mNoncompactedIntervals.size(); ++i) { int start_p = this->mapTime2PlotX(mNoncompactedIntervals[i].mStartTime); int stop_p = this->mapTime2PlotX(mNoncompactedIntervals[i].mEndTime); QColor color = gray01; painter.fillRect(QRect(start_p, mPlotArea.top(), stop_p - start_p, mPlotArea.height()), color); } // draw all continous events for (unsigned i = 0; i < mEvents.size(); ++i) { if (!mContinousEvents.contains(mEvents[i].mGroup)) continue; int start_p = this->mapTime2PlotX(mEvents[i].mStartTime); int stop_p = this->mapTime2PlotX(mEvents[i].mEndTime); int level = std::distance(mContinousEvents.begin(), std::find(mContinousEvents.begin(), mContinousEvents.end(), mEvents[i].mGroup)); int level_max = mContinousEvents.size(); int thisHeight = (mPlotArea.height()) / level_max - margin * (level_max - 1) / level_max; int thisTop = mPlotArea.top() + level * thisHeight + level * margin; // QColor color = mEventColors[level % mEventColors.size()]; QColor color = mEvents[i].mColor; painter.fillRect(QRect(start_p, thisTop, stop_p - start_p, thisHeight), color); } // draw all singular events for (unsigned i = 0; i < mEvents.size(); ++i) { if (mContinousEvents.contains(mEvents[i].mGroup)) continue; int start_p = this->mapTime2PlotX(mEvents[i].mStartTime); // int stop_p = this->mapTime2PlotX(mEvents[i].mEndTime); int glyphWidth = 3; QRect rect(start_p - glyphWidth / 2, mPlotArea.top(), glyphWidth, mPlotArea.height()); brush.setColor(QColor(50, 50, 50)); painter.setBrush(brush); painter.drawRoundedRect(rect, 2, 2); // painter.fillRect(rect, gray4); if (rect.width() > 2 && rect.height() > 2) { rect.adjust(1, 1, -1, -1); painter.fillRect(rect, gray2); } } int offset_p = this->mapTime2PlotX(mPos); QPolygonF glyph; int z = 5; int h = mPlotArea.height(); glyph.push_back(QPointF(-z, 0)); glyph.push_back(QPointF(z, 0)); glyph.push_back(QPointF(z, 0.7 * h)); glyph.push_back(QPointF(0, h)); glyph.push_back(QPointF(-z, 0.7 * h)); glyph.translate(offset_p, 0); if (this->hasFocus() || mCloseToGlyph) painter.setPen(highlight); else painter.setPen(gray4); // QBrush brush(Qt::SolidPattern);// = painter.brush(); QRadialGradient radialGrad(QPointF(offset_p, h / 3), 2 * h / 3); radialGrad.setColorAt(0, gray0); // radialGrad.setColorAt(0.5, Qt::blue); radialGrad.setColorAt(1, gray2); brush = QBrush(radialGrad); // brush.setColor(gray0); painter.setBrush(brush); painter.drawPolygon(glyph); }
void ZoneDefaultInteraction::onPaint(QPainter& painter, InteractionState const& interaction) { painter.setWorldMatrixEnabled(false); painter.setRenderHint(QPainter::Antialiasing); QTransform const to_screen(m_rContext.imageView().imageToWidget()); BOOST_FOREACH(EditableZoneSet::Zone const& zone, m_rContext.zones()) { EditableSpline::Ptr const& spline = zone.spline(); m_visualizer.prepareForSpline(painter, spline); QPolygonF points; if (!interaction.captured() && interaction.proximityLeader(m_vertexProximity) && spline == m_ptrNearestVertexSpline) { SplineVertex::Ptr vertex(m_ptrNearestVertex->next(SplineVertex::LOOP)); for (; vertex != m_ptrNearestVertex; vertex = vertex->next(SplineVertex::LOOP)) { points.push_back(to_screen.map(vertex->point())); } painter.drawPolyline(points); } else if (!interaction.captured() && interaction.proximityLeader(m_segmentProximity) && spline == m_ptrNearestSegmentSpline) { SplineVertex::Ptr vertex(m_nearestSegment.prev); do { vertex = vertex->next(SplineVertex::LOOP); points.push_back(to_screen.map(vertex->point())); } while (vertex != m_nearestSegment.prev); painter.drawPolyline(points); } else { m_visualizer.drawSpline(painter, to_screen, spline); } } if (interaction.proximityLeader(m_vertexProximity)) { // Draw the two adjacent edges in gradient red-to-orange. QLinearGradient gradient; // From inactive to active point. gradient.setColorAt(0.0, m_visualizer.solidColor()); gradient.setColorAt(1.0, m_visualizer.highlightDarkColor()); QPen pen(painter.pen()); QPointF const prev(to_screen.map(m_ptrNearestVertex->prev(SplineVertex::LOOP)->point())); QPointF const pt(to_screen.map(m_ptrNearestVertex->point())); QPointF const next(to_screen.map(m_ptrNearestVertex->next(SplineVertex::LOOP)->point())); gradient.setStart(prev); gradient.setFinalStop(pt); pen.setBrush(gradient); painter.setPen(pen); painter.drawLine(prev, pt); gradient.setStart(next); pen.setBrush(gradient); painter.setPen(pen); painter.drawLine(next, pt); // Visualize the highlighted vertex. QPointF const screen_vertex(to_screen.map(m_ptrNearestVertex->point())); m_visualizer.drawVertex(painter, screen_vertex, m_visualizer.highlightBrightColor()); } else if (interaction.proximityLeader(m_segmentProximity)) { QLineF const line(to_screen.map(m_nearestSegment.toLine())); // Draw the highglighed edge in orange. QPen pen(painter.pen()); pen.setColor(m_visualizer.highlightDarkColor()); painter.setPen(pen); painter.drawLine(line); m_visualizer.drawVertex(painter, m_screenPointOnSegment, m_visualizer.highlightBrightColor()); } else if (!interaction.captured()) { m_visualizer.drawVertex(painter, m_screenMousePos, m_visualizer.solidColor()); } }