本文整理汇总了C++中QPolygon类的典型用法代码示例。如果您正苦于以下问题:C++ QPolygon类的具体用法?C++ QPolygon怎么用?C++ QPolygon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPolygon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enableMask
void MainWindow::enableMask(bool enable)
{
if (!enable || Colors::noWindowMask)
this->clearMask();
else {
QPolygon region;
region.setPoints(9,
// north side:
0, 0,
800, 0,
// east side:
// 800, 70,
// 790, 90,
// 790, 480,
// 800, 500,
800, 600,
// south side:
700, 600,
670, 590,
130, 590,
100, 600,
0, 600,
// west side:
// 0, 550,
// 10, 530,
// 10, 520,
// 0, 520,
0, 0);
this->setMask(QRegion(region));
}
}
示例2: polygonQt
QPolygon drawerQt::polygonQt( const std::vector<scigraphics::wpoint> &Points )
{
QPolygon Polygon;
for ( unsigned i = 0; i < Points.size(); i++ )
Polygon.append( pointQt( Points[i] ) );
return Polygon;
}
示例3: small
vector<int> PerimeterWindow::boundaryFromPolygon(QPolygon poly, int xo, int yo, int gw){
// not sure of the best way of doing this, but lets have a go..
vector<int> points;
if(poly.size() < 2){
cerr << "PerimeterWindow::boundaryFromPolygon, points is too small (less than 2) " << poly.size() << endl;
return(points);
}
for(uint i=1; i < poly.size(); i++){
// Fill in the points from i-1 to i
QPoint p1 = poly[i-1];
QPoint p2 = poly[i];
// points.push_back((p1.y() + yo) * gw + p1.x() + xo);
// then work out how to get the other points..
int dx = p2.x() - p1.x();
int dy = p2.y() - p1.y();
int stepNo = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
// in the funny world of pixels a diagonal is only as long as the longer side..
for(int i=0; i < stepNo; i++){
int lx = p1.x() + (i * dx)/stepNo;
int ly = p1.y() + (i * dy)/stepNo;
// then convert and push back..
points.push_back((ly + yo) * gw + lx + xo);
}
}
// but at this point we have not added the last point so we need to do that..
QPoint p = poly.back();
points.push_back( (p.y() + yo) * gw + p.x() + xo);
return(points);
}
示例4:
QPolygon &RegionMask::Mask2QPolygon(const cv::Mat &img, QPolygon &poly, QList<QPolygon> &holes) {
poly.clear();
vector<vector<cv::Point> > contours;
vector<cv::Vec4i> hierarchy;
cv::findContours(img.clone(), contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_TC89_KCOS, cv::Point(0, 0));
//assert(contours.size() > 0);
if (contours.size() > 0) {
for (unsigned int i = 0; i < contours[0].size(); i++) {
poly.append(QPoint(contours[0][i].x, contours[0][i].y));
}
int idHole = hierarchy[0][2];
for (; idHole != -1; idHole = hierarchy[idHole][0]) {
QPolygon pnew;
for (unsigned int i = 0; i < contours[idHole].size(); i++) {
pnew.append(QPoint(contours[idHole][i].x, contours[idHole][i].y));
}
holes.append(pnew);
}
}
return poly;
}
示例5: mask
void KoContextHelpPopup::resizeEvent( QResizeEvent* )
{
QBitmap mask( width(), height() );
QPolygon a;
QPainter p( &mask );
p.fillRect( 0, 0, width(), height(), Qt::color1 );
p.setPen( Qt::color0 );
p.setBrush( Qt::color0 );
p.drawLine( 0, 0, 0, 3 );
p.drawLine( 0, 0, 3, 0 );
p.drawPoint( 1, 1 );
a.setPoints( 3, 0, height() - 5, 4, height() - 1, 0, height() - 1 );
p.drawPolygon( a );
a.setPoints( 3, width() - 5, 0, width() - 1, 4, width() - 1, 0 );
p.drawPolygon( a );
p.drawLine( width() - 1, height() - 1, width() - 4, height() - 1 );
p.drawLine( width() - 1, height() - 1, width() - 1, height() - 4 );
p.drawPoint( width() - 2, height() - 2 );
p.drawPoint( 0, height() - 6 );
p.drawPoint( width() - 6, 0 );
p.drawPoint( width() - 5, height() - 3 );
p.drawPoint( width() - 3, height() - 5 );
p.setPen( Qt::NoPen );
p.setBrush( QBrush( Qt::color0, Qt::Dense4Pattern ) );
p.drawRect( 0, height() - 2, width() - 1, height() - 1 );
p.drawRect( width() - 2, 0, width() - 1, height() - 1 );
p.drawRect( width() - 4, height() - 4, width() - 2, height() - 2 );
p.end();
setMask( QRegion( mask ) );
} // KoContextHelpPopup::resizeEvent
示例6: switch
Area Area::fromString(const QString& str)
{
Area result;
QStringList list = str.split(',', QString::SkipEmptyParts);
if (list.isEmpty())
return result;
AreaTypeFlag type = (AreaTypeFlag) list.takeFirst().toInt();
switch (type)
{
case TypeRectangle:
if (list.size() != 4)
break;
{
int values[4];
values[0] = list.takeFirst().toInt();
values[1] = list.takeFirst().toInt();
values[2] = list.takeFirst().toInt();
values[3] = list.takeFirst().toInt();
result = Area(QRect(values[0],
values[1],
values[2],
values[3]));
}
break;
case TypePolygon:
{
int size = list.takeFirst().toInt();
if (list.size() != 2 * size)
break;
QPolygon poly;
for (int i = 0;i < size;++i)
{
int values[2];
values[0] = list.takeFirst().toInt();
values[1] = list.takeFirst().toInt();
poly.append(QPoint(values[0], values[1]));
}
result = Area(poly);
}
break;
case TypeEllipse:
if (list.size() != 4)
break;
{
int values[4];
values[0] = list.takeFirst().toInt();
values[1] = list.takeFirst().toInt();
values[2] = list.takeFirst().toInt();
values[3] = list.takeFirst().toInt();
result = Area(Ellipse(QPoint(values[0],
values[1]),
values[2],
values[3]));
}
break;
default:
break;
}
return result;
}
示例7: siz
QSize KDChart::TextLayoutItem::calcSizeHint(
QFont fnt, QPoint& topLeftPt, QPoint& topRightPt, QPoint& bottomRightPt, QPoint& bottomLeftPt ) const
{
const QSize siz( unrotatedSizeHint( fnt ));
//qDebug() << "-------- siz: "<<siz;
if( ! mAttributes.rotation() ){
topLeftPt = QPoint(0,0);
topRightPt = QPoint(siz.width(),0);
bottomRightPt = QPoint(siz.width(),siz.height());
bottomLeftPt = QPoint(0,siz.height());
return siz;
}
const QRect rect(QPoint(0, 0), siz + QSize(4,4));
const qreal angle = PI * mAttributes.rotation() / 180.0;
const qreal cosAngle = cos( angle );
const qreal sinAngle = sin( angle );
QMatrix rotationMatrix(cosAngle, sinAngle, -sinAngle, cosAngle, 0, 0);
QPolygon rotPts;
rotPts << rotationMatrix.map(rect.topLeft())
<< rotationMatrix.map(rect.topRight())
<< rotationMatrix.map(rect.bottomRight())
<< rotationMatrix.map(rect.bottomLeft());
QSize rotSiz( rotPts.boundingRect().size() );
//qDebug() << "-------- KDChart::TextLayoutItem::calcSizeHint() returns:"<<rotSiz<<rotPts;
topLeftPt = rotPts[0];
topRightPt = rotPts[1];
bottomRightPt = rotPts[2];
bottomLeftPt = rotPts[3];
return rotSiz;
}
示例8: QRect
//virtual
bool
Zoomer::accept( QPolygon &pa ) const
{
if ( pa.count() < 2 )
return false;
QRect rect = QRect( pa[0], pa[int( pa.count() ) - 1] );
rect = rect.normalized();
if ( rect.width() < 2 && rect.height() < 2 )
return false;
pa.resize( 2 );
const QRectF& rc = pickArea().boundingRect(); // view rect
if ( rect.width() < minX ) {
// make a virtical line
pa[ 0 ] = QPoint( rc.left(), rect.top() );
pa[ 1 ] = QPoint( rc.right(), rect.bottom() );
return true;
} else if ( rect.height() < minY ) {
// make a horizontal line
pa[ 0 ] = QPoint( rect.left(), rc.top() );
pa[ 1 ] = QPoint( rect.right(), rc.bottom() );
} else {
pa[ 0 ] = rect.topLeft();
pa[ 1 ] = rect.bottomRight();
}
return true;
}
示例9: rotatedRect
QRectF rotatedRect( const QRectF& oldRect, qreal angleInt, const QPointF& center )
{
const QRect rect( oldRect.translated( center ).toRect() );
const qreal angle = PI * angleInt / 180.0;
const qreal cosAngle = cos( angle );
const qreal sinAngle = sin( angle );
QMatrix rotationMatrix(cosAngle, sinAngle, -sinAngle, cosAngle, 0, 0);
QPolygon rotPts;
rotPts << rotationMatrix.map(rect.topLeft()) //QPoint(0,0)
<< rotationMatrix.map(rect.topRight())
<< rotationMatrix.map(rect.bottomRight())
<< rotationMatrix.map(rect.bottomLeft());
//<< rotatedPoint(rect.topRight(), angleInt, center).toPoint()
//<< rotatedPoint(rect.bottomRight(), angleInt, center).toPoint()
//<< rotatedPoint(rect.bottomLeft(), angleInt, center).toPoint();
return rotPts.boundingRect();
/*
const QPointF topLeft( rotatedPoint( oldRect.topLeft(), angle, center ) );
const QPointF topRight( rotatedPoint( oldRect.topRight(), angle, center ) );
const QPointF bottomLeft( rotatedPoint( oldRect.bottomLeft(), angle, center ) );
const QPointF bottomRight( rotatedPoint( oldRect.bottomRight(), angle, center ) );
const qreal x = qMin( qMin( topLeft.x(), topRight.x() ), qMin( bottomLeft.x(), topLeft.x() ) );
const qreal y = qMin( qMin( topLeft.y(), topRight.y() ), qMin( bottomLeft.y(), topLeft.y() ) );
const qreal width = qMax( qMax( topLeft.x(), topRight.x() ), qMax( bottomLeft.x(), topLeft.x() ) ) - x;
const qreal height = qMax( qMax( topLeft.y(), topRight.y() ), qMax( bottomLeft.y(), topLeft.y() ) ) - y;
return QRectF( x, y, width, height );
*/
}
示例10: width
void TupLuminancePicker::paintEvent(QPaintEvent *)
{
int w = width() - 5;
QRect r(0, foff, w, height() - 2*foff);
int wi = r.width() - 2;
int hi = r.height() - 2;
if (!k->pix || k->pix->height() != hi || k->pix->width() != wi) {
delete k->pix;
QImage img(wi, hi, QImage::Format_RGB32);
int y;
for (y = 0; y < hi; y++) {
QColor c;
c.setHsv(k->hue, k->sat, y2val(y+coff));
QRgb r = c.rgb();
int x;
for (x = 0; x < wi; x++)
img.setPixel(x, y, r);
}
k->pix = new QPixmap(QPixmap::fromImage(img));
}
QPainter p(this);
p.drawPixmap(1, coff, *k->pix);
const QPalette &g = palette();
qDrawShadePanel(&p, r, g, true);
p.setPen(g.foreground().color());
p.setBrush(g.foreground());
QPolygon a;
int y = val2y(k->value);
a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
p.eraseRect(w, 0, 5, height());
p.drawPolygon(a);
}
示例11: map
// The new function using fixed point multiplication
QPolygon MapMatrix::map(const QPolygon &a) const
{
int size = a.size();
int64_t fx;
int64_t fy;
int32_t curx;
int32_t cury;
int32_t lastx = 0;
int32_t lasty = 0;
QPolygon p;
for( int i = 0; i < size; i++ )
{
a.point(i, &curx, &cury);
fx = itofp24p8( curx );
fy = itofp24p8( cury );
// some cheating involved; multiplication with the "wrong" macro
// after "left shifting" the "m" value in createMatrix
curx = fp24p8toi( mulfp8p24(m11,fx) + mulfp8p24(m21,fy) + dx);
cury = fp24p8toi( mulfp8p24(m22,fy) + mulfp8p24(m12,fx) + dy);
if ( (i==0) | ( ((curx - lastx) | (cury - lasty)) != 0) )
{
p.append(QPoint(curx, cury));
lastx = curx;
lasty = cury;
}
}
return p;
}
示例12: initElement
void ECentralHexagon::initElement()
{
/// init polygon ///
this->clearAllPolygon();
QPolygon polygon;
polygon.putPoints(0, 6, 30,-50, 59,0, 30,50, -30,50, -59,0, -30,-50);
this->addPolygon(polygon);
/// ///
this->isAnimeFinished = false;
if(GameInfo::gameStatus == GameOver)
{
this->isGameOver = true;
this->zoomPolygon(4);
}
else
{
this->isGameOver = false;
}
this->pen.setWidth(6);
this->pen.setJoinStyle(Qt::MiterJoin);
this->brush.setStyle(Qt::SolidPattern);
}
示例13: drawIndicator
void mySpeedWatch::drawIndicator(QPainter *painter)
{
painter->save();
QPolygon pts;
pts.setPoints(3, -2,0, 2,0, 0,60); /* (-2,0)/(2,0)/(0,60) */
painter->rotate(m_startAngle);
double degRotate = (360.0 - m_startAngle - m_endAngle)/(m_maxValue - m_minValue)*(m_value - m_minValue);
//画指针
painter->rotate(degRotate);
QRadialGradient haloGradient(0, 0, 60, 0, 0);
haloGradient.setColorAt(0, QColor(60,60,60));
haloGradient.setColorAt(1, QColor(160,160,160));
painter->setPen(Qt::white);
painter->setBrush(haloGradient);
painter->drawConvexPolygon(pts);
painter->restore();
//画中心点
QColor niceBlue(150, 150, 200);
QConicalGradient coneGradient(0, 0, -90.0);
coneGradient.setColorAt(0.0, Qt::darkGray);
coneGradient.setColorAt(0.2, niceBlue);
coneGradient.setColorAt(0.5, Qt::white);
coneGradient.setColorAt(1.0, Qt::darkGray);
painter->setPen(Qt::NoPen);
painter->setBrush(coneGradient);
painter->drawEllipse(-5, -5, 10, 10);
}
示例14: QPolygon
void LineString::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset)
{
if (!visible)
return;
QPolygon p = QPolygon();
QPointF c;
for (int i=0; i<vertices.size(); i++)
{
c = vertices[i]->coordinate();
p.append(mapadapter->coordinateToDisplay(c));
}
if (mypen != 0)
{
painter->save();
painter->setPen(*mypen);
}
painter->drawPolyline(p);
if (mypen != 0)
{
painter->restore();
}
for (int i=0; i<vertices.size(); i++)
{
vertices[i]->draw(painter, mapadapter, screensize, offset);
}
}
示例15: selection
//将位置转换成字符串
QwtText RectPicker::trackerTextF(const QPointF &pos) const
{
QwtText text;
const QPolygon points = selection();//选择的点
if (!points.isEmpty())
{
QString num;
QPoint point = points[0];
QPointF point2 = invTransform(point);
num = QString("(%1,%2),(,)").arg(point2.x()).arg(point2.y());
QColor bg(Qt::white);
bg.setAlpha(200);
if (points.size() == 2)
{
QPointF point0 = invTransform(points[0]);
QPointF point1 = invTransform(points[1]);
num = QString("(%1,%2),(%3,%4)").arg(point0.x()).arg(point0.y()).arg(point1.x()).arg(point1.y());
}
text.setBackgroundBrush(QBrush(bg));
text.setText(num);
}
return text;
}