本文整理汇总了C++中QPolygon::setPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ QPolygon::setPoint方法的具体用法?C++ QPolygon::setPoint怎么用?C++ QPolygon::setPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPolygon
的用法示例。
在下文中一共展示了QPolygon::setPoint方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addPoint
inline void GraphPolygonClipper::addPoint(
QPolygon &pa, uint pos, const QPoint &point) const
{
if ( uint(pa.size()) <= pos )
pa.resize(pos + 5);
pa.setPoint(pos, point);
}
示例2: mouseMoveEvent
void Storage::mouseMoveEvent(QMouseEvent *anEvent)
{
QPoint pos = anEvent->pos() / scale_;
if (anEvent->pos().x() < 0)
pos.setX(0);
if (width() < anEvent->pos().x())
pos.setX(width() - 1);
if (anEvent->pos().y() < 0)
pos.setY(0);
if (height() < anEvent->pos().y())
pos.setY(height() - 1);
/* изменяем прямоугольник */
if ((anEvent->buttons() & Qt::LeftButton) &&
BoundingBoxTool == tool_ &&
NewSelection == state_ &&
Qt::NoModifier == keyboard_modifier_)
{
triggerBoundBox(pos, prev_cursor_pos_, rect);
}
/* изменяем эллипс */
if ((anEvent->buttons() & Qt::LeftButton) &&
EllipseTool == tool_ &&
NewSelection == state_ &&
Qt::NoModifier == keyboard_modifier_)
{
triggerEllipse(pos, prev_cursor_pos_, ell);
}
/* изменяем стрелу */
if ((anEvent->buttons() & Qt::LeftButton) &&
ArrowTool == tool_ &&
NewSelection == state_ &&
Qt::NoModifier == keyboard_modifier_)
{
triggerArrow(pos, prev_cursor_pos_, arrow);
}
/* перемещаем последнюю точку(курсор) многоугольника до создания(точка зафиксирется кликом) новой */
if (PolygonTool == tool_ &&
NewSelection == state_ &&
(anEvent->buttons() & Qt::LeftButton))
{
QPolygon tmp = poly.getCoordinates();
tmp.setPoint(tmp.count() - 1, pos);
poly.setCoordinates(tmp);
repaint_needed_ = 1;
}
// if (-1 != focused_selection_ &&
// !(anEvent->buttons() & Qt::LeftButton)) {
// checkForPoints(&pos);
// }
//here now 2
/* изменяем многоульник */
// if (-1 != hovered_point_.figureID &&
// !list_polygon_->isEmpty() &&
// PolyFigure == hovered_point_.figure &&
// (anEvent->buttons() & Qt::LeftButton) &&
// hovered_point_.figureID == focused_selection_)
// {
// polygon_.poly.clear();
// polygon_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;
// Polygon *poly = list_polygon_->at(hovered_point_.figureID);
// poly->poly.setPoint(hovered_point_.pointID, pos);
// for(int i=0;i< list_polygon_->at(hovered_point_.figureID)->poly.count();++i)
// {
// if(i!=hovered_point_.pointID)
// polygon_.poly << list_polygon_->at(hovered_point_.figureID)->poly.point(i);
// else
// polygon_.poly << pos;
// }
// qDebug() << "polygon_.poly =" << polygon_.poly;
// repaint_needed_ = 1;
// }
/* изменяем прямоульник */
// if (-1 != hovered_point_.figureID &&
// !list_bounding_box_->isEmpty() &&
// RectFigure == hovered_point_.figure &&
// (anEvent->buttons() & Qt::LeftButton))
// {
// bounding_box_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;
// bounding_box_.rect.setTopLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.topLeft());
// bounding_box_.rect.setTopRight(list_bounding_box_->at(hovered_point_.figureID)->rect.topRight());
// bounding_box_.rect.setBottomRight(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomRight());
// bounding_box_.rect.setBottomLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomLeft());
// BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID);
// if (0 == hovered_point_.pointID)
// {
// rect->rect.setTopLeft(pos);
//.........这里部分代码省略.........
示例3: addPoint
static void addPoint(QPolygon &a, const QPoint &p)
{
uint n = a.size();
a.resize(n + 1);
a.setPoint(n, p);
}
示例4: drawArc
/**
* Draws an arc which starts / ends exactly at the given coordinates.
*
* @param cx center in x
* @param cy center in y
* @param radius Radius
* @param a1 Angle 1 in rad
* @param a2 Angle 2 in rad
* @param x1 startpoint x
* @param y1 startpoint y
* @param x2 endpoint x
* @param y2 endpoint y
* @param reversed true: clockwise, false: counterclockwise
*/
void RS_PainterQt::drawArc(const RS_Vector& cp, double radius,
double a1, double a2,
const RS_Vector& p1, const RS_Vector& p2,
bool reversed) {
/*
QPainter::drawArc(cx-radius, cy-radius,
2*radius, 2*radius,
a1*16, (a2-a1)*16);
*/
if(radius<=0.5) {
drawGridPoint(cp);
} else {
#ifdef __APPLE1__
drawArcMac(cp, radius, a1, a2, reversed);
#else
int cix; // Next point on circle
int ciy; //
double aStep; // Angle Step (rad)
double a; // Current Angle (rad)
double linStep; // linear step (pixels)
if (drawingMode==RS2::ModePreview) {
linStep = 20.0;
} else {
linStep = 6.0;
}
if (fabs(linStep/radius)<=1.0) {
aStep=asin(linStep/radius);
} else {
aStep=1.0;
}
if (aStep<0.05) {
aStep = 0.05;
}
if(!reversed) {
// Arc Counterclockwise:
if(a1>a2-1.0e-10) {
a2+=2*M_PI;
}
//moveTo(toScreenX(p1.x), toScreenY(p1.y));
QPolygon pa;
int i=0;
pa.resize(i+1);
pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));
for(a=a1+aStep; a<=a2; a+=aStep) {
cix = toScreenX(cp.x+cos(a)*radius);
ciy = toScreenY(cp.y-sin(a)*radius);
//lineTo(cix, ciy);
pa.resize(i+1);
pa.setPoint(i++, cix, ciy);
}
//lineTo(toScreenX(p2.x), toScreenY(p2.y));
pa.resize(i+1);
pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));
drawPolyline(pa);
} else {
// Arc Clockwise:
if(a1<a2+1.0e-10) {
a2-=2*M_PI;
}
QPolygon pa;
int i=0;
pa.resize(i+1);
pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));
//moveTo(toScreenX(p1.x), toScreenY(p1.y));
for(a=a1-aStep; a>=a2; a-=aStep) {
cix = toScreenX(cp.x+cos(a)*radius);
ciy = toScreenY(cp.y-sin(a)*radius);
//lineTo(cix, ciy);
pa.resize(i+1);
pa.setPoint(i++, cix, ciy);
}
//lineTo(toScreenX(p2.x), toScreenY(p2.y));
pa.resize(i+1);
pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));
drawPolyline(pa);
}
#endif
}
}
示例5: paintChart
//.........这里部分代码省略.........
{
zMaxValue = round(zMaxValue, true);
MaxValue = zMaxValue;
}
}
paintTitle(p, rect);
paintLegend(p, rect);
paintAxis(p, rect);
std::list<QPolygon> Points;
int cp = 0;
int samples = countSamples();
int zeroy = int(rect.height() - 2 - ( -zMinValue / (zMaxValue - zMinValue) * (rect.height() - 4)));
if (samples > 1)
{
const QMatrix &mtx = p->worldMatrix();
p->setClipRect(int(mtx.dx() + 2), int(mtx.dy() + 2), rect.width() - 3, rect.height() - 3);
if (Zooming)
p->drawText(2, 2, rect.width() - 4, rect.height() - 4,
Qt::AlignLeft | Qt::AlignTop, tr("Zoom"));
std::list<bool>::reverse_iterator e = Enabled.rbegin();
for (std::list<std::list<double> >::reverse_iterator i = Values.rbegin(); i != Values.rend(); i++)
{
if (e == Enabled.rend() || *e)
{
std::list<double> &val = *i;
int count = 0;
int skip = SkipSamples;
QPolygon a(samples + 10);
int x = rect.width() - 2;
for (std::list<double>::reverse_iterator j = val.rbegin(); j != val.rend() && x >=
2;
j++)
{
if (skip > 0)
skip--;
else
{
int val = int(rect.height() - 2 - ((*j - zMinValue) / (zMaxValue - zMinValue) * (rect.height() - 4)));
x = rect.width() - 2 - count * (rect.width() - 4) / (samples - 1);
a.setPoint(count, x, val);
count++;
if (count >= samples)
break;
}
}
a.resize(count * 2);
Points.insert(Points.end(), a);
}
cp++;
if (e != Enabled.rend())
e++;
}
}
std::map<int, int> Bottom;
std::list<bool>::reverse_iterator e = Enabled.rbegin();
for (std::list<QPolygon>::iterator i = Points.begin(); i != Points.end();)
{
while (e != Enabled.rend() && !*e)
{
cp--;
e++;
}
if (e != Enabled.rend())
e++;
cp--;
QPolygon a = *i;
int lx = 0;
int lb = 0;
for (int j = 0; j < a.size() / 2; j++)
{
int x, y;
a.point(j, &x, &y);
if (Bottom.find(x) == Bottom.end())
Bottom[x] = 0;
if (lx != x)
lb = Bottom[x];
a.setPoint(a.size() - 1 - j, x, zeroy - lb);
y -= lb;
a.setPoint(j, x, y);
Bottom[x] = zeroy - y;
lx = x;
}
p->save();
QBrush brush(Utils::toChartBrush(cp));
p->setBrush(brush.color());
p->drawPolygon(a);
if (brush.style() != Qt::SolidPattern)
{
p->setBrush(QBrush(Qt::white, brush.style()));
p->drawPolygon(a);
}
p->restore();
i++;
}
}
示例6: qDrawMotifArrow
// motif arrows look the same whether they are used or not
// is this correct?
static void qDrawMotifArrow(QPainter *p, Qt::ArrowType type, bool down,
int x, int y, int w, int h,
const QPalette &pal, bool)
{
QPolygon bFill; // fill polygon
QPolygon bTop; // top shadow.
QPolygon bBot; // bottom shadow.
QPolygon bLeft; // left shadow.
QTransform matrix; // xform matrix
bool vertical = type == Qt::UpArrow || type == Qt::DownArrow;
bool horizontal = !vertical;
int dim = w < h ? w : h;
int colspec = 0x0000; // color specification array
if (dim < 2) // too small arrow
return;
if (dim > 3) {
if (dim > 6)
bFill.resize(dim & 1 ? 3 : 4);
bTop.resize((dim/2)*2);
bBot.resize(dim & 1 ? dim + 1 : dim);
bLeft.resize(dim > 4 ? 4 : 2);
bLeft.putPoints(0, 2, 0,0, 0,dim-1);
if (dim > 4)
bLeft.putPoints(2, 2, 1,2, 1,dim-3);
bTop.putPoints(0, 4, 1,0, 1,1, 2,1, 3,1);
bBot.putPoints(0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2);
for(int i=0; i<dim/2-2 ; i++) {
bTop.putPoints(i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i);
bBot.putPoints(i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i);
}
if (dim & 1) // odd number size: extra line
bBot.putPoints(dim-1, 2, dim-3,dim/2, dim-1,dim/2);
if (dim > 6) { // dim>6: must fill interior
bFill.putPoints(0, 2, 1,dim-3, 1,2);
if (dim & 1) // if size is an odd number
bFill.setPoint(2, dim - 3, dim / 2);
else
bFill.putPoints(2, 2, dim-4,dim/2-1, dim-4,dim/2);
}
}
else {
if (dim == 3) { // 3x3 arrow pattern
bLeft.setPoints(4, 0,0, 0,2, 1,1, 1,1);
bTop .setPoints(2, 1,0, 1,0);
bBot .setPoints(2, 1,2, 2,1);
}
else { // 2x2 arrow pattern
bLeft.setPoints(2, 0,0, 0,1);
bTop .setPoints(2, 1,0, 1,0);
bBot .setPoints(2, 1,1, 1,1);
}
}
if (type == Qt::UpArrow || type == Qt::LeftArrow) {
matrix.translate(x, y);
if (vertical) {
matrix.translate(0, h - 1);
matrix.rotate(-90);
} else {
matrix.translate(w - 1, h - 1);
matrix.rotate(180);
}
if (down)
colspec = horizontal ? 0x2334 : 0x2343;
else
colspec = horizontal ? 0x1443 : 0x1434;
}
else if (type == Qt::DownArrow || type == Qt::RightArrow) {
matrix.translate(x, y);
if (vertical) {
matrix.translate(w-1, 0);
matrix.rotate(90);
}
if (down)
colspec = horizontal ? 0x2443 : 0x2434;
else
colspec = horizontal ? 0x1334 : 0x1343;
}
const QColor *cols[5];
cols[0] = 0;
cols[1] = &pal.button().color();
cols[2] = &pal.mid().color();
cols[3] = &pal.light().color();
cols[4] = &pal.dark().color();
#define CMID *cols[(colspec>>12) & 0xf]
#define CLEFT *cols[(colspec>>8) & 0xf]
#define CTOP *cols[(colspec>>4) & 0xf]
#define CBOT *cols[colspec & 0xf]
QPen savePen = p->pen(); // save current pen
QBrush saveBrush = p->brush(); // save current brush
QTransform wxm = p->transform();
QPen pen(Qt::NoPen);
const QBrush &brush = pal.brush(QPalette::Button);
//.........这里部分代码省略.........
示例7: createArc
void RS_Painter::createArc(QPolygon& pa,
const RS_Vector& cp, double radius,
double a1, double a2,
bool reversed) {
if (radius<1.0e-6) {
RS_DEBUG->print(RS_Debug::D_WARNING,
"RS_Painter::createArc: invalid radius: %f", radius);
return;
}
int cix; // Next point on circle
int ciy; //
double aStep; // Angle Step (rad)
double a; // Current Angle (rad)
if(fabs(2.0/radius)<=1.0) {
aStep=asin(2.0/radius);
} else {
aStep=1.0;
}
aStep=aStep/2.0;
//if (aStep<0.05) {
// aStep = 0.05;
//}
// less than a pixel long lines:
//if (radius*aStep<1.0) {
// aStep =
//}
//QPointArray pa;
int i=0;
pa.resize(i+1);
pa.setPoint(i++, toScreenX(cp.x+cos(a1)*radius),
toScreenY(cp.y-sin(a1)*radius));
//moveTo(toScreenX(cp.x+cos(a1)*radius),
// toScreenY(cp.y-sin(a1)*radius));
if(!reversed) {
// Arc Counterclockwise:
if(a1>a2-1.0e-10) {
a2+=2*M_PI;
}
for(a=a1+aStep; a<=a2; a+=aStep) {
cix = toScreenX(cp.x+cos(a)*radius);
ciy = toScreenY(cp.y-sin(a)*radius);
//lineTo(cix, ciy);
pa.resize(i+1);
pa.setPoint(i++, cix, ciy);
}
} else {
// Arc Clockwise:
if(a1<a2+1.0e-10) {
a2-=2*M_PI;
}
for(a=a1-aStep; a>=a2; a-=aStep) {
cix = toScreenX(cp.x+cos(a)*radius);
ciy = toScreenY(cp.y-sin(a)*radius);
//lineTo(cix, ciy);
pa.resize(i+1);
pa.setPoint(i++, cix, ciy);
}
}
//lineTo(toScreenX(cp.x+cos(a2)*radius),
// toScreenY(cp.y-sin(a2)*radius));
pa.resize(i+1);
pa.setPoint(i++,
toScreenX(cp.x+cos(a2)*radius),
toScreenY(cp.y-sin(a2)*radius));
//drawPolyline(pa);
}
示例8: showGraph
void cbSimulator::showGraph(int id)
{
unsigned int w,c;
QGraphicsPolygonItem *wallCanvas;
QGraphicsRectItem *grCanvas;
if(id<1 || id > (int)robots.size()) {
cerr << "Cannot show graph of robot " << id << "\n";
return;
}
labCanvasWidth=(int)(lab->Width()*30);
labCanvasHeight=(int)(lab->Height()*30);
labScene=new QGraphicsScene(0, 0, labCanvasWidth,labCanvasHeight);
labView=new cbGraphView(labScene,this);
labView->viewport()->setMouseTracking(true);
QPolygon *pa;
for(w=1; w<lab->nWalls();w++) {
vector<cbPoint> &corners=lab->Wall(w)->Corners();
//pa.resize(corners.size());
pa = new QPolygon(corners.size());
for(c=0; c<corners.size();c++)
pa->setPoint(c,(int)(corners[c].X()*labCanvasWidth/lab->Width()),
(int)(labCanvasHeight-corners[c].Y()*labCanvasHeight/lab->Height()) );
wallCanvas = new QGraphicsPolygonItem(0, labScene);
wallCanvas->setPolygon(*pa);
wallCanvas->setBrush(QBrush(Qt::black));
wallCanvas->setVisible(true);
}
unsigned int x,y;
double distMax=0.0;
//grAux=graph; Tentativa de optimizacao
for(x = 0; x < GRIDSIZE; x++)
for(y = 0; y < GRIDSIZE; y++) {
*grAux=*graph;
//grAux->resetInitState(); Tentativa de optimizacao - testes indicam que fica muito mais lento!!
//grAux->writeGraph();
cbPoint p((0.5+x)*lab->Width()/GRIDSIZE, (GRIDSIZE-0.5-y)*lab->Height()/GRIDSIZE);
grAux->addFinalPoint(id,p);
distGrid[x][y]=grAux->dist(id);
if(distGrid[x][y] < 2000 && distGrid[x][y]>distMax)
distMax=distGrid[x][y];
}
// fprintf(stderr,"distmax=%f labCanvasWidth=%d labCanvasHeight=%d\n",
// distMax,labCanvasWidth,labCanvasHeight);
for(x = 0; x < GRIDSIZE; x++)
for(y = 0; y < GRIDSIZE; y++) {
if(distGrid[x][y]<2000) {
grCanvas = new QGraphicsRectItem(x*labCanvasWidth/GRIDSIZE,y*labCanvasHeight/GRIDSIZE,
(x+1)*labCanvasWidth/GRIDSIZE - x*labCanvasWidth/GRIDSIZE,
(y+1)*labCanvasHeight/GRIDSIZE -y*labCanvasHeight/GRIDSIZE,
0, labScene);
QColor color((int)(0+distGrid[x][y]/distMax*250),
(int)(0+distGrid[x][y]/distMax*250),
(int)(0+distGrid[x][y]/distMax*250));
grCanvas->setBrush(QBrush(color));
grCanvas->setPen(QPen(color));
grCanvas->setVisible(true);
//debug
//distGrid[x][y]=(int)(0+distGrid[x][y]/distMax*250);
}
}
labScene->update();
}