本文整理汇总了C++中QPainterPath::addEllipse方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::addEllipse方法的具体用法?C++ QPainterPath::addEllipse怎么用?C++ QPainterPath::addEllipse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::addEllipse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawChart
void SessionPositionsChart::drawChart(QPainter *p)
{
int firstLap = 99, lastLap = 0;
int chartMin = tMin == 1 ? 0 : tMin;
double left = paintRect.left();
double x = left;
double y;
double yFactor = (((double)paintRect.height()) / (double)(tMax-chartMin));
int size;
findFirstAndLastLap(firstLap, lastLap, size);
firstLap = first; lastLap = last;
double xFactor = ((double)paintRect.width()) / (double)(lastLap - firstLap);
if (firstLap == 1)
{
firstLap = 0;
xFactor = ((double)paintRect.width()) / (double)(lastLap);
}
if (/*lastLap - firstLap == 0 ||*/ lapDataArray.isEmpty())
return;
drawAxes(p, firstLap, lastLap);
p->setRenderHint(QPainter::Antialiasing);
int lastPaintedSC = -1;
for (int i = 0; i < lapDataArray.size(); ++i)
{
if (lapDataArray[i].getLapNumber() >= firstLap && lapDataArray[i].getLapNumber() <= lastLap)// && lapDataArray[i].getTime().isValid())
{
// if (lapDataArray[i].getRaceLapExtraData().isSCLap() && lapDataArray[i].getLapNumber() > lastPaintedSC)
// {
// double sc_x1 = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + left;
// double sc_x2 = (double)(lapDataArray[i].getLapNumber()+1 - firstLap) * xFactor + left;
// if (sc_x1 < paintRect.left())
// sc_x1 = paintRect.left();
// if (lastPaintedSCPixel == -1)
// lastPaintedSCPixel = round(sc_x2);
// else if (abs(round(sc_x1) - lastPaintedSCPixel) <= 5)
// {
// sc_x1 = (double)lastPaintedSCPixel;
// lastPaintedSCPixel = round(sc_x2);
// }
// p->setPen(QColor(255, 255, 0, 0));
// p->setBrush(QBrush(QColor(255, 255, 0, 35)));
// p->drawRect(round(sc_x1), paintRect.top(), round(sc_x2-sc_x1), paintRect.height()-10);
// lastPaintedSC = lapDataArray[i].getLapNumber();
//// lastSCLap = lapDataArray[i].getLapNumber();
// }
if (lapDataArray[i].getRaceLapExtraData().isSCLap() && !lapDataArray[i].getGap().contains("L") && lapDataArray[i].getLapNumber() > lastPaintedSC)
{
int tmp = first;
if (firstLap == 0)
first -= 1;
drawSCLap(p, lapDataArray[i], xFactor);
lastPaintedSC = lapDataArray[i].getLapNumber();
first = tmp;
}
y = (double)(paintRect.top() + (double)(lapDataArray[i].getPosition()-tMin) * yFactor);
x = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + left;
//int no = EventData::getInstance()lapDataArray[i].getCarID()
QColor color = getCarColor(lapDataArray[i]);
QPen pen;
pen.setWidth(3);
pen.setColor(color);
p->setPen(pen);
if (y <= paintRect.bottom())
{
if (lapDataArray[i].getTime().toString() == "IN PIT")
{
QPainterPath path;
p->setBrush(QBrush(color));
path.addEllipse(QPoint(x, y), 7, 7);
p->drawPath(path);
}
}
if (lapDataArray[i].getLapNumber()-1 >= firstLap)//&& i > 0)
{
double x1 = x;
double y1 = y;
if (firstLap == 0 && lapDataArray[i].getLapNumber() == 1)
//.........这里部分代码省略.........
示例2: closing
void tst_QPainterPath::closing()
{
// lineto's
{
QPainterPath triangle(QPoint(100, 100));
triangle.lineTo(200, 100);
triangle.lineTo(200, 200);
QCOMPARE(triangle.elementCount(), 3);
triangle.closeSubpath();
QCOMPARE(triangle.elementCount(), 4);
QCOMPARE(triangle.elementAt(3).type, QPainterPath::LineToElement);
triangle.moveTo(300, 300);
QCOMPARE(triangle.elementCount(), 5);
QCOMPARE(triangle.elementAt(4).type, QPainterPath::MoveToElement);
triangle.lineTo(400, 300);
triangle.lineTo(400, 400);
QCOMPARE(triangle.elementCount(), 7);
triangle.closeSubpath();
QCOMPARE(triangle.elementCount(), 8);
// this will should trigger implicit moveto...
triangle.lineTo(600, 300);
QCOMPARE(triangle.elementCount(), 10);
QCOMPARE(triangle.elementAt(8).type, QPainterPath::MoveToElement);
QCOMPARE(triangle.elementAt(9).type, QPainterPath::LineToElement);
triangle.lineTo(600, 700);
QCOMPARE(triangle.elementCount(), 11);
}
// curveto's
{
QPainterPath curves(QPoint(100, 100));
curves.cubicTo(200, 100, 100, 200, 200, 200);
QCOMPARE(curves.elementCount(), 4);
curves.closeSubpath();
QCOMPARE(curves.elementCount(), 5);
QCOMPARE(curves.elementAt(4).type, QPainterPath::LineToElement);
curves.moveTo(300, 300);
QCOMPARE(curves.elementCount(), 6);
QCOMPARE(curves.elementAt(5).type, QPainterPath::MoveToElement);
curves.cubicTo(400, 300, 300, 400, 400, 400);
QCOMPARE(curves.elementCount(), 9);
curves.closeSubpath();
QCOMPARE(curves.elementCount(), 10);
// should trigger implicit moveto..
curves.cubicTo(100, 800, 800, 100, 800, 800);
QCOMPARE(curves.elementCount(), 14);
QCOMPARE(curves.elementAt(10).type, QPainterPath::MoveToElement);
QCOMPARE(curves.elementAt(11).type, QPainterPath::CurveToElement);
}
{
QPainterPath rects;
rects.addRect(100, 100, 100, 100);
QCOMPARE(rects.elementCount(), 5);
QCOMPARE(rects.elementAt(0).type, QPainterPath::MoveToElement);
QCOMPARE(rects.elementAt(4).type, QPainterPath::LineToElement);
rects.addRect(300, 100, 100,100);
QCOMPARE(rects.elementCount(), 10);
QCOMPARE(rects.elementAt(5).type, QPainterPath::MoveToElement);
QCOMPARE(rects.elementAt(9).type, QPainterPath::LineToElement);
rects.lineTo(0, 0);
QCOMPARE(rects.elementCount(), 12);
QCOMPARE(rects.elementAt(10).type, QPainterPath::MoveToElement);
QCOMPARE(rects.elementAt(11).type, QPainterPath::LineToElement);
}
{
QPainterPath ellipses;
ellipses.addEllipse(100, 100, 100, 100);
QCOMPARE(ellipses.elementCount(), 13);
QCOMPARE(ellipses.elementAt(0).type, QPainterPath::MoveToElement);
QCOMPARE(ellipses.elementAt(10).type, QPainterPath::CurveToElement);
ellipses.addEllipse(300, 100, 100,100);
QCOMPARE(ellipses.elementCount(), 26);
QCOMPARE(ellipses.elementAt(13).type, QPainterPath::MoveToElement);
QCOMPARE(ellipses.elementAt(23).type, QPainterPath::CurveToElement);
ellipses.lineTo(0, 0);
QCOMPARE(ellipses.elementCount(), 28);
QCOMPARE(ellipses.elementAt(26).type, QPainterPath::MoveToElement);
QCOMPARE(ellipses.elementAt(27).type, QPainterPath::LineToElement);
}
//.........这里部分代码省略.........
示例3: addRoundedRectClip
void GraphicsContext::addRoundedRectClip(const IntRect& rect, const IntSize& topLeft,
const IntSize& topRight, const IntSize& bottomLeft,
const IntSize& bottomRight)
{
if (paintingDisabled())
return;
// Need sufficient width and height to contain these curves. Sanity check our top/bottom
// values and our width/height values to make sure the curves can all fit.
int requiredWidth = qMax(topLeft.width() + topRight.width(), bottomLeft.width() + bottomRight.width());
if (requiredWidth > rect.width())
return;
int requiredHeight = qMax(topLeft.height() + bottomLeft.height(), topRight.height() + bottomRight.height());
if (requiredHeight > rect.height())
return;
// Clip to our rect.
clip(rect);
// OK, the curves can fit.
QPainterPath path;
// Add the four ellipses to the path. Technically this really isn't good enough, since we could end up
// not clipping the other 3/4 of the ellipse we don't care about. We're relying on the fact that for
// normal use cases these ellipses won't overlap one another (or when they do the curvature of one will
// be subsumed by the other).
path.addEllipse(QRectF(rect.x(), rect.y(), topLeft.width() * 2, topLeft.height() * 2));
path.addEllipse(QRectF(rect.right() - topRight.width() * 2, rect.y(),
topRight.width() * 2, topRight.height() * 2));
path.addEllipse(QRectF(rect.x(), rect.bottom() - bottomLeft.height() * 2,
bottomLeft.width() * 2, bottomLeft.height() * 2));
path.addEllipse(QRectF(rect.right() - bottomRight.width() * 2,
rect.bottom() - bottomRight.height() * 2,
bottomRight.width() * 2, bottomRight.height() * 2));
int topLeftRightHeightMax = qMax(topLeft.height(), topRight.height());
int bottomLeftRightHeightMax = qMax(bottomLeft.height(), bottomRight.height());
int topBottomLeftWidthMax = qMax(topLeft.width(), bottomLeft.width());
int topBottomRightWidthMax = qMax(topRight.width(), bottomRight.width());
// Now add five rects (one for each edge rect in between the rounded corners and one for the interior).
path.addRect(QRectF(rect.x() + topLeft.width(),
rect.y(),
rect.width() - topLeft.width() - topRight.width(),
topLeftRightHeightMax));
path.addRect(QRectF(rect.x() + bottomLeft.width(), rect.bottom() - bottomLeftRightHeightMax,
rect.width() - bottomLeft.width() - bottomRight.width(), bottomLeftRightHeightMax));
path.addRect(QRectF(rect.x(),
rect.y() + topLeft.height(),
topBottomLeftWidthMax,
rect.height() - topLeft.height() - bottomLeft.height()));
path.addRect(QRectF(rect.right() - topBottomRightWidthMax,
rect.y() + topRight.height(),
topBottomRightWidthMax,
rect.height() - topRight.height() - bottomRight.height()));
path.addRect(QRectF(rect.x() + topBottomLeftWidthMax,
rect.y() + topLeftRightHeightMax,
rect.width() - topBottomLeftWidthMax - topBottomRightWidthMax,
rect.height() - topLeftRightHeightMax - bottomLeftRightHeightMax));
path.setFillRule(Qt::WindingFill);
m_data->p().setClipPath(path, Qt::IntersectClip);
}
示例4: drawPainterPath
QPainterPath QGIViewPart::drawPainterPath(TechDrawGeometry::BaseGeom *baseGeom) const
{
QPainterPath path;
switch(baseGeom->geomType) {
case TechDrawGeometry::CIRCLE: {
TechDrawGeometry::Circle *geom = static_cast<TechDrawGeometry::Circle *>(baseGeom);
double x = geom->center.fX - geom->radius;
double y = geom->center.fY - geom->radius;
path.addEllipse(x, y, geom->radius * 2, geom->radius * 2); //[email protected](x,y) radx,rady
//Base::Console().Message("TRACE -drawPainterPath - making an CIRCLE @(%.3f,%.3f) R:%.3f\n",x, y, geom->radius);
} break;
case TechDrawGeometry::ARCOFCIRCLE: {
TechDrawGeometry::AOC *geom = static_cast<TechDrawGeometry::AOC *>(baseGeom);
//double x = geom->center.fX - geom->radius;
//double y = geom->center.fY - geom->radius;
pathArc(path, geom->radius, geom->radius, 0., geom->largeArc, geom->cw,
geom->endPnt.fX, geom->endPnt.fY,
geom->startPnt.fX, geom->startPnt.fY);
//Base::Console().Message("TRACE -drawPainterPath - making an ARCOFCIRCLE @(%.3f,%.3f) R:%.3f\n",x, y, geom->radius);
} break;
case TechDrawGeometry::ELLIPSE: {
TechDrawGeometry::Ellipse *geom = static_cast<TechDrawGeometry::Ellipse *>(baseGeom);
// Calculate start and end points as ellipse with theta = 0 and pi
double startX = geom->center.fX + geom->major * cos(geom->angle),
startY = geom->center.fY + geom->major * sin(geom->angle),
endX = geom->center.fX - geom->major * cos(geom->angle),
endY = geom->center.fY - geom->major * sin(geom->angle);
pathArc(path, geom->major, geom->minor, geom->angle, false, false,
endX, endY, startX, startY);
pathArc(path, geom->major, geom->minor, geom->angle, false, false,
startX, startY, endX, endY);
//Base::Console().Message("TRACE -drawPainterPath - making an ELLIPSE @(%.3f,%.3f) R1:%.3f R2:%.3f\n",x, y, geom->major, geom->minor);
} break;
case TechDrawGeometry::ARCOFELLIPSE: {
TechDrawGeometry::AOE *geom = static_cast<TechDrawGeometry::AOE *>(baseGeom);
pathArc(path, geom->major, geom->minor, geom->angle, geom->largeArc, geom->cw,
geom->endPnt.fX, geom->endPnt.fY,
geom->startPnt.fX, geom->startPnt.fY);
//Base::Console().Message("TRACE -drawPainterPath - making an ARCOFELLIPSE R1:%.3f R2:%.3f From: (%.3f,%.3f) To: (%.3f,%.3f)\n",geom->major, geom->minor,geom->startPnt.fX, geom->startPnt.fY,geom->endPnt.fX, geom->endPnt.fY);
} break;
case TechDrawGeometry::BSPLINE: {
TechDrawGeometry::BSpline *geom = static_cast<TechDrawGeometry::BSpline *>(baseGeom);
std::vector<TechDrawGeometry::BezierSegment>::const_iterator it = geom->segments.begin();
// Move painter to the beginning of our first segment
path.moveTo(it->pnts[0].fX, it->pnts[0].fY);
//Base::Console().Message("TRACE -drawPainterPath - making an BSPLINE From: (%.3f,%.3f)\n",it->pnts[0].fX,it->pnts[0].fY);
for ( ; it != geom->segments.end(); ++it) {
// At this point, the painter is either at the beginning
// of the first segment, or end of the last
if ( it->poles == 2 ) {
// Degree 1 bezier = straight line...
path.lineTo(it->pnts[1].fX, it->pnts[1].fY);
} else if ( it->poles == 3 ) {
path.quadTo(it->pnts[1].fX, it->pnts[1].fY,
it->pnts[2].fX, it->pnts[2].fY);
} else if ( it->poles == 4 ) {
path.cubicTo(it->pnts[1].fX, it->pnts[1].fY,
it->pnts[2].fX, it->pnts[2].fY,
it->pnts[3].fX, it->pnts[3].fY);
} else { //can only handle lines,quads,cubes
Base::Console().Error("Bad pole count (%d) for BezierSegment of BSpline geometry\n",it->poles);
path.lineTo(it->pnts[1].fX, it->pnts[1].fY); //show something for debugging
}
}
} break;
case TechDrawGeometry::GENERIC: {
TechDrawGeometry::Generic *geom = static_cast<TechDrawGeometry::Generic *>(baseGeom);
path.moveTo(geom->points[0].fX, geom->points[0].fY);
std::vector<Base::Vector2D>::const_iterator it = geom->points.begin();
//Base::Console().Message("TRACE -drawPainterPath - making an GENERIC From: (%.3f,%.3f)\n",geom->points[0].fX, geom->points[0].fY);
for(++it; it != geom->points.end(); ++it) {
path.lineTo((*it).fX, (*it).fY);
//Base::Console().Message(">>>> To: (%.3f,%.3f)\n",(*it).fX, (*it).fY);
}
} break;
default:
Base::Console().Error("Error - drawPainterPath - UNKNOWN geomType: %d\n",baseGeom->geomType);
break;
}
double rot = getViewObject()->Rotation.getValue();
if (rot) {
QTransform t;
//.........这里部分代码省略.........
示例5: contains_QPointF_data
void tst_QPainterPath::contains_QPointF_data()
{
QTest::addColumn<QPainterPath>("path");
QTest::addColumn<QPointF>("pt");
QTest::addColumn<bool>("contained");
QPainterPath path;
path.addRect(0, 0, 100, 100);
// #####
// # #
// # #
// # #
// #####
QTest::newRow("[0,0] in [0,0,100,100]") << path << QPointF(0, 0) << true;
QTest::newRow("[99,0] in [0,0,100,100]") << path << QPointF(99, 0) << true;
QTest::newRow("[0,99] in [0,0,100,100]") << path << QPointF(0, 99) << true;
QTest::newRow("[99,99] in [0,0,100,100]") << path << QPointF(99, 99) << true;
QTest::newRow("[99.99,0] in [0,0,100,100]") << path << QPointF(99.99, 0) << true;
QTest::newRow("[0,99.99] in [0,0,100,100]") << path << QPointF(0, 99.99) << true;
QTest::newRow("[99.99,99.99] in [0,0,100,100]") << path << QPointF(99.99, 99.99) << true;
QTest::newRow("[0.01,0.01] in [0,0,100,100]") << path << QPointF(0.01, 0.01) << true;
QTest::newRow("[0,0.01] in [0,0,100,100]") << path << QPointF(0, 0.01) << true;
QTest::newRow("[0.01,0] in [0,0,100,100]") << path << QPointF(0.01, 0) << true;
QTest::newRow("[-0.01,-0.01] in [0,0,100,100]") << path << QPointF(-0.01, -0.01) << false;
QTest::newRow("[-0,-0.01] in [0,0,100,100]") << path << QPointF(0, -0.01) << false;
QTest::newRow("[-0.01,0] in [0,0,100,100]") << path << QPointF(-0.01, 0) << false;
QTest::newRow("[-10,0] in [0,0,100,100]") << path << QPointF(-10, 0) << false;
QTest::newRow("[100,0] in [0,0,100,100]") << path << QPointF(100, 0) << false;
QTest::newRow("[0,-10] in [0,0,100,100]") << path << QPointF(0, -10) << false;
QTest::newRow("[0,100] in [0,0,100,100]") << path << QPointF(0, 100) << false;
QTest::newRow("[100.1,0] in [0,0,100,100]") << path << QPointF(100.1, 0) << false;
QTest::newRow("[0,100.1] in [0,0,100,100]") << path << QPointF(0, 100.1) << false;
path.addRect(50, 50, 100, 100);
// #####
// # #
// # #####
// # # # #
// ##### #
// # #
// #####
QTest::newRow("[49,49] in 2 rects") << path << QPointF(49,49) << true;
QTest::newRow("[50,50] in 2 rects") << path << QPointF(50,50) << false;
QTest::newRow("[100,100] in 2 rects") << path << QPointF(100,100) << true;
path.setFillRule(Qt::WindingFill);
QTest::newRow("[50,50] in 2 rects (winding)") << path << QPointF(50,50) << true;
path.addEllipse(0, 0, 150, 150);
// #####
// ## ##
// # #####
// # # # #
// ##### #
// ## ##
// #####
QTest::newRow("[50,50] in complex (winding)") << path << QPointF(50, 50) << true;
path.setFillRule(Qt::OddEvenFill);
QTest::newRow("[50,50] in complex (windinf)") << path << QPointF(50, 50) << true;
QTest::newRow("[49,49] in complex") << path << QPointF(49,49) << false;
QTest::newRow("[100,100] in complex") << path << QPointF(49,49) << false;
// unclosed triangle
path = QPainterPath();
path.moveTo(100, 100);
path.lineTo(130, 70);
path.lineTo(150, 110);
QTest::newRow("[100,100] in triangle") << path << QPointF(100, 100) << true;
QTest::newRow("[140,100] in triangle") << path << QPointF(140, 100) << true;
QTest::newRow("[130,80] in triangle") << path << QPointF(130, 80) << true;
QTest::newRow("[110,80] in triangle") << path << QPointF(110, 80) << false;
QTest::newRow("[150,100] in triangle") << path << QPointF(150, 100) << false;
QTest::newRow("[120,110] in triangle") << path << QPointF(120, 110) << false;
QRectF base_rect(0, 0, 20, 20);
path = QPainterPath();
path.addEllipse(base_rect);
// not strictly precise, but good enougth to verify fair precision.
QPainterPath inside;
inside.addEllipse(base_rect.adjusted(5, 5, -5, -5));
//.........这里部分代码省略.........
示例6: eventFilter
bool HoverPoints::eventFilter(QObject *object, QEvent *event)
{
if (object == m_widget && m_enabled) {
switch (event->type()) {
case QEvent::MouseButtonPress:
{
if (!m_fingerPointMapping.isEmpty())
return true;
QMouseEvent *me = (QMouseEvent *) event;
QPointF clickPos = me->pos();
int index = -1;
for (int i=0; i<m_points.size(); ++i) {
QPainterPath path;
if (m_shape == CircleShape)
path.addEllipse(pointBoundingRect(i));
else
path.addRect(pointBoundingRect(i));
if (path.contains(clickPos)) {
index = i;
break;
}
}
if (me->button() == Qt::LeftButton) {
if (index == -1) {
if (!m_editable)
return false;
int pos = 0;
// Insert sort for x or y
if (m_sortType == XSort) {
for (int i=0; i<m_points.size(); ++i)
if (m_points.at(i).x() > clickPos.x()) {
pos = i;
break;
}
} else if (m_sortType == YSort) {
for (int i=0; i<m_points.size(); ++i)
if (m_points.at(i).y() > clickPos.y()) {
pos = i;
break;
}
}
m_points.insert(pos, clickPos);
m_locks.insert(pos, 0);
m_currentIndex = pos;
firePointChange();
} else {
m_currentIndex = index;
}
return true;
} else if (me->button() == Qt::RightButton) {
if (index >= 0 && m_editable) {
if (m_locks[index] == 0) {
m_locks.remove(index);
m_points.remove(index);
}
firePointChange();
return true;
}
}
}
break;
case QEvent::MouseButtonRelease:
if (!m_fingerPointMapping.isEmpty())
return true;
m_currentIndex = -1;
break;
case QEvent::MouseMove:
if (!m_fingerPointMapping.isEmpty())
return true;
if (m_currentIndex >= 0)
movePoint(m_currentIndex, ((QMouseEvent *)event)->pos());
break;
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
{
const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event);
const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints();
const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height());
foreach (const QTouchEvent::TouchPoint &touchPoint, points) {
const int id = touchPoint.id();
switch (touchPoint.state()) {
case Qt::TouchPointPressed:
{
// find the point, move it
QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
int activePoint = -1;
qreal distance = -1;
const int pointsCount = m_points.size();
const int activePointCount = activePoints.size();
if (pointsCount == 2 && activePointCount == 1) { // only two points
activePoint = activePoints.contains(0) ? 1 : 0;
//.........这里部分代码省略.........
示例7: shape
QPainterPath Place::shape () const
{
QPainterPath shape;
shape.addEllipse(0, 0, place_diameter , place_diameter);
return shape;
}
示例8: shape
QPainterPath Puck::shape() const
{
QPainterPath path;
path.addEllipse(QRectF(-0.5*dimension, -0.5*dimension, dimension, dimension));
return path;
}
示例9: shape
QPainterPath MeshGraphItemVelocityHandle::shape() const
{
QPainterPath path;
path.addEllipse(-5, -5, 10, 10);
return path;
}
示例10: shape
QPainterPath State::shape() {
QPainterPath path;
path.addEllipse(this->boundingRect());
return path;
}
示例11: draw
void Lib_dialog::draw (){
QPainter painter;
painter.begin(ui->widget);
if (fx.getCount()==0 && fx.getinicialize()) {painter.end(); return;}
painter.setRenderHint(QPainter::Antialiasing);
QPen pen;
pen.setStyle(Qt::SolidLine); //��� ����� �� �����������
pen.setWidth(1);//������� �����
pen.setBrush(Qt::green); //����
pen.setCapStyle(Qt::RoundCap); //������������ � �����
pen.setJoinStyle(Qt::RoundJoin); //������ ����
painter.setPen(pen);
//QColor currentColor ();
QRect geom;
geom=ui->widget->geometry();
int hght=geom.height();
int wdth=geom.width();
float minx=fx.getMinX();
float miny=fx.getMinY();
float maxx=fx.getMaxX();
float maxy=fx.getMaxY();
float wd=maxx-minx;
float hd=maxy-miny;
StructXY grid;
if (fx.getGrid(&grid)) {
float dfs=round(minx/grid.x)*grid.x;
do {
float n=(dfs-minx)/wd;
int x1=n*wdth;
QLine ln (x1,0,x1,hght);
dfs+=grid.x;
painter.drawLine (ln);}
while (dfs<maxx+grid.x);
dfs=round(miny/grid.y)*grid.y;
do {
float n=(dfs-miny)/hd;
int y1=n*hght;
QLine ln (0,y1,wdth,y1);
dfs+=grid.y;
painter.drawLine (ln);}
while (dfs<maxy+grid.y);
}
pen.setBrush(Qt::black);
painter.setPen(pen);
float n=(fx[0].x-minx)/wd;
int x1=n*wdth;
n=(fx[0].y-miny)/hd;
int y1=hght-n*hght;
int i;
{
QPainterPath path;
path.addEllipse(x1-4,y1-4,8,8);
painter.fillPath(path, Qt::red);
int x2,y2;
int i;
for (i=1; i<fx.getCount(); i++){
n=(fx[i].x-minx)/wd;
x1=n*wdth;
n=(fx[i-1].x-minx)/wd;
x2=n*wdth;
n=(fx[i].y-miny)/hd;
y1=hght-n*hght;
n=(fx[i-1].y-miny)/hd;
y2=hght-n*hght;
path.addEllipse(x1-4,y1-4,8,8);
painter.fillPath(path, Qt::red);
QLine ln ( x1,y1,x2,y2);
painter.drawLine (ln);
}}
QPainterPath path;
if (fx.getCurPoint(&i)) {
n=(fx[i].x-minx)/wd;
int x=n*wdth;
n=(fx[i].y-miny)/hd;
int y=hght-n*hght;
path.addEllipse(x-5,y-5,10,10);
painter.fillPath(path, Qt::blue);
}
painter.end();
}
示例12: shape
QPainterPath Node::shape() const{
QPainterPath path;
path.addEllipse((-1)*ellipseSide/2, (-1)*ellipseSide/2, ellipseSide, ellipseSide);
return path;
}
示例13: drawPressed
void Ckeyb::drawPressed(QImage *_img)
{
if (keyPressedList.isEmpty()) {
return;
}
keyPressing.lock();
QMapIterator<int, quint64> i(keyPressedList);
keyPressing.unlock();
while (i.hasNext()) {
i.next();
QRect _rect = getKey(i.key()).Rect;
_rect.setCoords(_rect.x()*pPC->internalImageRatio,
_rect.y()*pPC->internalImageRatio,
(_rect.x()+_rect.width())*pPC->internalImageRatio,
(_rect.y()+_rect.height())*pPC->internalImageRatio);
int _m = qMin(_rect.width(), _rect.height())*.25;
_rect+= QMargins(_m,_m,_m,_m);
int dim = qMax(_rect.width(), _rect.height());
int magnifierSize = dim * 2;
int radius = magnifierSize / 2;
int ring = radius - 15;
QSize box = QSize(magnifierSize, magnifierSize);
QPixmap maskPixmap;
maskPixmap = QPixmap(box);
maskPixmap.fill(Qt::transparent);
QRadialGradient g;
g.setCenter(radius, radius);
g.setFocalPoint(radius, radius);
g.setRadius(radius);
g.setColorAt(1.0, QColor(64, 64, 64, 0));
g.setColorAt(0.5, QColor(0, 0, 0, 255));
QPainter mask(&maskPixmap);
mask.setRenderHint(QPainter::Antialiasing);
mask.setCompositionMode(QPainter::CompositionMode_Source);
mask.setBrush(g);
mask.setPen(Qt::NoPen);
mask.drawRect(maskPixmap.rect());
mask.setBrush(QColor(Qt::transparent));
mask.drawEllipse(g.center(), ring, ring);
mask.end();
QPoint center = _rect.center() - QPoint(0, radius);
center = center + QPoint(0, radius / 2);
QPoint corner = center - QPoint(radius, radius);
QPoint xy = center * 2 - QPoint(radius, radius);
// only set the dimension to the magnified portion
QPixmap zoomPixmap = QPixmap(box);
zoomPixmap.fill(Qt::lightGray);
QPainter pz(&zoomPixmap);
// pz.translate(-xy);
QRect target=QRect(QPoint(0,0),box);
pz.drawImage(target, *_img,_rect);
pz.end();
QPainterPath clipPath;
clipPath.addEllipse(center, ring, ring);
QPainter p(_img);
p.setRenderHint(QPainter::Antialiasing);
p.setClipPath(clipPath);
p.drawPixmap(corner, zoomPixmap);
p.setClipping(false);
p.drawPixmap(corner, maskPixmap);
p.setPen(Qt::gray);
p.drawPath(clipPath);
p.end();
}
}
示例14: shape
QPainterPath PointGraphicsItem::shape() const
{
QPainterPath path;
path.addEllipse(boundingRect().adjusted(-4,-4, 4, 4));
return path;
}
示例15: shape
QPainterPath shape() const
{
QPainterPath path;
path.addEllipse(boundingRect());
return path;
}