Esempio n. 1
0
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));
    }
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
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
Esempio n. 6
0
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;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
//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;
}
Esempio n. 9
0
void tst_QRegion::polygonRegion()
{
    QPolygon pa;
    {
	QRegion region ( pa );
	QVERIFY( region.isEmpty() );
    }
    {
	pa.setPoints( 8, 10, 10, //  a____________b
			 40, 10, //  |            |
			 40, 20, //  |___      ___|
			 30, 20, //      |    |
			 30, 40, //      |    |
			 20, 40, //      |    |
			 20, 20, //      |____c
			 10, 20 );

	QRegion region ( pa );
	QVERIFY( !region.isEmpty() );

	// These should not be inside the circle
	QVERIFY( !region.contains( QPoint(  9,  9 ) ) );
	QVERIFY( !region.contains( QPoint( 30, 41 ) ) );
	QVERIFY( !region.contains( QPoint( 41, 10 ) ) );
	QVERIFY( !region.contains( QPoint( 31, 21 ) ) );

	// These should be inside
	QVERIFY( region.contains( QPoint( 10, 10 ) ) ); // Upper-left  (a)

    }
}
Esempio n. 10
0
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 );
*/
}
Esempio n. 11
0
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);
}
Esempio n. 12
0
// 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;
}
Esempio n. 13
0
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);
}
Esempio n. 14
0
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);
}
Esempio n. 15
0
	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);
		}
	}
Esempio n. 16
0
//将位置转换成字符串
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;
}
Esempio n. 17
0
void Dialog::paintEvent(QPaintEvent *event)
{
    bool animation = true;
    if (animation) {
        QPainter painter(this);
        m_ball.render(painter, m_counter);
        m_counter++;
    }
    else {
        QPainter painter(this);
        QPen pen;
        pen.setWidth(3);
        pen.setColor(Qt::black);
        QBrush brush(Qt::yellow);

        painter.setPen (pen);
        painter.setBrush(brush);
        painter.drawEllipse(30, 30, 100, 100);

        brush.setColor("#C36241");
        painter.setBrush(brush);
        pen.setWidth(1);

        QPolygon roof;
        roof.putPoints(0, 3, 250, 260, 290, 220, 330, 260);
        painter.drawPolygon(roof);

        brush.setColor("#835C3B");
        painter.setBrush(brush);

        QPolygon house;
        house.putPoints(0, 4, 260, 260, 260, 299, 320, 299, 320, 260);
        painter.drawPolygon(house);
    }
}
Esempio n. 18
0
void
Zoomer::drawRubberBand( QPainter *painter ) const
{
    if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen )
		return;

	const QPolygon pa = adjustedPoints( pickedPoints() );
    if ( pa.count() < 1 )
        return;

    const QRectF& rc = pickArea().boundingRect(); // view rect
    const QPoint p2 = pa[int( pa.count() - 1 )];

    QwtPainter::drawLine( painter, p2.x(), rc.top(), p2.x(), rc.bottom() );  // vertical @ 2nd point (automaticall drawn by picker)
    QwtPainter::drawLine( painter, rc.left(), p2.y(), rc.right(), p2.y() );  // horizontal @ 2nd point

	if ( pa.count() >= 2 ) {
        const QPoint p1 = pa[0];
        const QRect rect = QRect( p1, p2 ).normalized();
        
        if ( autoYScale_ || rect.height() < minY ) { // select horizontal (indicate by 2 vertical lines)
            QwtPainter::drawLine( painter, p1.x(), rc.top(), p1.x(), rc.bottom() );  // vertical @ 1st point
        } else if ( rect.width() < minX ) {
            QwtPainter::drawLine( painter, rc.left(), p1.y(), rc.right(), p1.y() );  // horizontal @ 1st point
        } else {
            QwtPainter::drawLine( painter, p1.x(), rc.top(), p1.x(), rc.bottom() );  // vertical @ 1st point
            QwtPainter::drawLine( painter, rc.left(), p1.y(), rc.right(), p1.y() );  // horizontal @ 1st point
        }
    }
}
Esempio n. 19
0
QRect toRect(QPolygon polygon)
{
    if(polygon.size() != 4)
        return QRect();

    return QRect(polygon.first(), polygon.at(2));
}
Esempio n. 20
0
QImage * SeamCarver::extendWidth(int w_extent,bool compression,bool afficheLignes)
{
    QPolygon *ligneBest;// = listLignesMostSuitable.first();
    QRgb color1,color2;
    int y_ligneBest;
    QPoint pp;
    int extendedSize = 0;//2*w_extent;
    if (!afficheLignes)
        extendedSize = (compression) ? -w_extent : w_extent;
    QImage *dataRet = new QImage(imgOrigine->width(),imgOrigine->height()+extendedSize,imgOrigine->format());
    ImageResizer *resizer = new ImageResizer;
    int delta_y,tmp_lect;
    QList<int> list_y_val;
    int counterExtractLignes = w_extent;
    QListIterator<QPolygon *> qit(listLignesMostSuitable);

    for (int x=0; x < imgOrigine->width() ; x++)
    {
        qit.toFront();
        list_y_val.clear();
        counterExtractLignes = w_extent;
        while ((qit.hasNext()) && (counterExtractLignes >0))
        {
            ligneBest=qit.next();
            list_y_val << (ligneBest->point(x)).y();
            counterExtractLignes--;
        }
        qSort(list_y_val);
        list_y_val << imgOrigine->height() + 1000;
        y_ligneBest = list_y_val.takeFirst();

        //        pp=ligneBest->takeFirst();
        //y_ligneBest=pp.y();
        delta_y=0;
        for (int y=0; y < imgOrigine->height() ; y++) {
            color1=imgOrigine->pixel(x,y);
            if ((afficheLignes) || (y != y_ligneBest))
            {
                int w_newPosition = y+delta_y;
                if (w_newPosition < dataRet->height())
                    dataRet->setPixel(x,w_newPosition,color1);
            } else
            {
                if (compression)
                {
                    delta_y -= 1;
                } else
                {
                    dataRet->setPixel(x,y_ligneBest+delta_y,color1);
                    color2=imgOrigine->pixel(x,y+1);
                    resizer->interpol(dataRet,x,y_ligneBest+delta_y+1,1,color1,color2,false);
                    delta_y += 1;
                }
                y_ligneBest = list_y_val.takeFirst();
            }
        }
    }
    return dataRet;
}
Esempio n. 21
0
QDebug operator<<(QDebug dbg, const QPolygon &a)
{
    dbg.nospace() << "QPolygon(";
    for (int i = 0; i < a.count(); ++i)
        dbg.nospace() << a.at(i);
    dbg.nospace() << ')';
    return dbg.space();
}
Esempio n. 22
0
QPolygon QPolygonF::toPolygon() const
{
    QPolygon a;
    a.reserve(size());
    for (int i=0; i<size(); ++i)
        a.append(at(i).toPoint());
    return a;
}
Esempio n. 23
0
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);
}
Esempio n. 24
0
void KisTransformMaskTest::testSafeTransformSingleVanishingPoint()
{
    // rotation around 0X has a single vanishing point for 0Y axis
    QTransform transform(1, 0, 0,
                         -0.870208, -0.414416, -0.000955222,
                         132.386, 1082.91, 1.99439);

    QTransform R; R.rotateRadians(M_PI / 4.0);
    //transform *= R;

    QRectF testRect(1536, 1024, 512, 512);
    KisSafeTransform t2(transform, QRect(0, 0, 2048, 2048), testRect.toRect());

    QPolygonF fwdPoly = t2.mapForward(testRect);
    QRectF fwdRect = t2.mapRectForward(testRect);

    QPolygonF bwdPoly = t2.mapBackward(fwdPoly);
    QRectF bwdRect = t2.mapRectBackward(fwdRect);

    /**
     * A special weird rect that crosses the vanishing point,
     * which is (911.001, 433.84) in this case
     */
    QRectF fwdNastyRect(800, 100, 400, 600);
    //QRectF fwdNastyRect(100, 400, 1000, 800);
    QRectF bwdNastyRect = t2.mapRectBackward(fwdNastyRect);

/*
    dbgKrita << ppVar(testRect);
    dbgKrita << ppVar(fwdPoly);
    dbgKrita << ppVar(fwdRect);
    dbgKrita << ppVar(bwdPoly);
    dbgKrita << ppVar(bwdRect);
    dbgKrita << ppVar(bwdNastyRect);
*/

    QPolygon ref;

    ref.clear();
    ref << QPoint(765,648);
    ref << QPoint(1269, 648);
    ref << QPoint(1601, 847);
    ref << QPoint(629, 847);
    ref << QPoint(765, 648);
    QCOMPARE(fwdPoly.toPolygon(), ref);
    QCOMPARE(fwdRect.toRect(), QRect(629,648,971,199));

    ref.clear();
    ref << QPoint(1536,1024);
    ref << QPoint(2048,1024);
    ref << QPoint(2048,1536);
    ref << QPoint(1536,1536);
    ref << QPoint(1536,1024);
    QCOMPARE(bwdPoly.toPolygon(), ref);
    QCOMPARE(bwdRect.toRect(), QRect(1398,1024,650,512));

    QCOMPARE(bwdNastyRect.toRect(), QRect(1463,0,585,1232));
}
Esempio n. 25
0
QPixmap ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight, int _iColorMode ) {
#ifdef DEBUG_CLSBASEQSTATEARRAYVIEW
    cout << "ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight)" << endl;
#endif

//    int iColorMode = ClsBaseQStateArrayView::GRAY;
//    int iColorMode = ClsBaseQStateArrayView::BLUE2RED;
//    int iColorMode = ClsBaseQStateArrayView::HSV;

    QPixmap pmGradient;
    QPainter* paintGradient = new QPainter();
    QWMatrix mxRot;
    int iDiag = (int)(sqrt(double(iImgWidth * iImgWidth + iImgHeight * iImgHeight))/2.);

    pmGradient.resize(2 * iDiag, 2 * iDiag);
    paintGradient->begin(&pmGradient);

    paintGradient->setWindow( 0, 0, 2 * iDiag, 2 * iDiag );

    int iNrSices = 50;
    for ( int i=0; i<iNrSices; i++ ) {
	paintGradient->setWorldMatrix( mxRot );
	QColor c;
	if(_iColorMode == ClsBaseQStateArrayView::GRAY){
	    c.setRgb( i* 255 / iNrSices,  i* 255 / iNrSices,  i* 255 / iNrSices );
	}
	else if(_iColorMode == ClsBaseQStateArrayView::BLUE2RED){
	    if(i<iNrSices/2){
		/* BLUE */
		c.setRgb(0, 0,  255 - i * 510/iNrSices);
	    }
	    else {
		/* RED */
		c.setRgb( (i - iNrSices/2) * 255/(iNrSices/2),  0,0);
	    }
	}
	else {
	    c.setHsv( i* 360 / iNrSices, 255, 255 );
	}
	paintGradient->setBrush( c );
	paintGradient->setPen( c );
//zzz	QPointArray a;
	QPolygon a;

	a.setPoints( 4,
		     0, 0,
		     iDiag * 2 / iNrSices, 0,
		     iDiag * 2 / iNrSices, iDiag * 2,
		     0, iDiag * 2 );
	paintGradient->drawPolygon( a );
	mxRot.translate( (double)iDiag * 2.0 / (double)iNrSices, 0.0  );
    }

    paintGradient->end();
    return pmGradient;

}
Esempio n. 26
0
QPolygon sdraw::normalizePolygon(const QPolygon &polygon, int offset)
{
   QPolygon ret = polygon;
   QRect boundingRect = ret.boundingRect();
   QPoint transPt(-boundingRect.topLeft().x() + offset,
      -boundingRect.topLeft().y() + offset);
   ret.translate(transPt);
   return ret;
}
Esempio n. 27
0
QPolygon Zoomer::getZoomedPolygon(const QPolygon &poly)
{
   QPolygon newPoly;
   for(int i=0; i<poly.size(); i++)
   {
      newPoly << getZoomedPoint(poly.at(i));
   }
   return newPoly;
}
QVariant PdfFrameHandle::itemChange (GraphicsItemChange change,
                                     const QVariant &value)
{
  QVariant valueFiltered = value;

  if (change == ItemPositionChange && scene()) {

    QPointF sizeAsPointF (boundingRect().size().width(),
                          boundingRect().size().height());

    // New position is in the value argument
    QPointF newPos = valueFiltered.toPointF();
    QPointF oldPos = pos ();

    // This sequence is from http://www.qtcentre.org/threads/47248-How-to-efficiently-get-position-of-a-QGraphicsItem-in-view-coordinates
    QRectF newRectItem (newPos,
                        QSize (boundingRect().size().width(),
                               boundingRect().size().height()));
    QPolygonF newRectScene = mapToScene (newRectItem);
    QPolygon newRectView = m_view.mapFromScene (newRectScene.boundingRect());

    // Skip moving of this handle if it will go outside of the window
    QRectF rectWindow = m_scene.sceneRect();
    if (!rectWindow.contains (newRectView.boundingRect())) {

      // Keep the item inside the scene rectangle
      newPos.setX (qMin (rectWindow.right(), qMax (newPos.x(), rectWindow.left())));
      newPos.setY (qMin (rectWindow.bottom(), qMax (newPos.y(), rectWindow.top())));

      valueFiltered = (newPos);

    }

    // Skip moving of other handles, in response to the move of this handle, if event handling is (temporarily) off,
    // to prevent an infinite loop
    if (!m_disableEventsWhileMovingAutomatically) {

      bool left   = ((m_orientationFlags & PdfCropping::PDF_CROPPING_LEFT  ) != 0);
      bool right  = ((m_orientationFlags & PdfCropping::PDF_CROPPING_RIGHT ) != 0);
      bool top    = ((m_orientationFlags & PdfCropping::PDF_CROPPING_TOP   ) != 0);
      bool bottom = ((m_orientationFlags & PdfCropping::PDF_CROPPING_BOTTOM) != 0);

      if (left && top) {
        m_pdfCropping.moveTL (newPos, oldPos);
      } else if (right && top) {
        m_pdfCropping.moveTR (newPos, oldPos);
      } else if (right && bottom) {
        m_pdfCropping.moveBR (newPos, oldPos);
      } else if (left && bottom) {
        m_pdfCropping.moveBL (newPos, oldPos);
      }
    }
  }

  return QGraphicsItem::itemChange(change, valueFiltered);
}
Esempio n. 29
0
	QPolygon PointListWidget::points() const
	{
		QPolygon back;

		for(int index = 0; index < ui->list->rowCount(); ++index)
			back.append(QPoint(ui->list->item(index, 0)->text().toInt(),
							   ui->list->item(index, 1)->text().toInt()));

		return back;
	}
Esempio n. 30
0
void PanWidget::
recreatePolygon ()
{
    QPoint o = rect().center();
    QPoint x = (rect().topRight() - rect().topLeft())/4;
    QPoint y = (rect().bottomLeft() - rect().topLeft())/4;

    QPolygon poly;
    float R = 1.5;
    float r = 0.25;
    poly.push_back( o - R*y );
    poly.push_back( o + r*x - r*y);
    poly.push_back( o + R*x );
    poly.push_back( o + r*x + r*y);
    poly.push_back( o + R*y );
    poly.push_back( o - r*x + r*y);
    poly.push_back( o - R*x );
    poly.push_back( o - r*x - r*y);

    path_ = QPainterPath();
    path_.addPolygon(poly);

    setMask(HudGlWidget::growRegion(poly));
    update();
}