예제 #1
0
/*!
  \brief Draw dots
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::drawPolyline, QwtCurve::drawLine, 
      QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps
      QwtCurve::drawPolyline, QwtCurve::drawPolygon
*/
void QwtCurve::drawDots(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    const bool doFill = painter->brush().style() != Qt::NoBrush;

    QPointArray polyline;
    if ( doFill )
        polyline.resize(to - from + 1);

    for (int i = from; i <= to; i++)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));
        QwtPainter::drawPoint(painter, xi, yi);

        if ( doFill )
            polyline.setPoint(i - from, xi, yi);
    }

    if ( doFill )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
예제 #2
0
void paintCar( QPainter *p )			// paint a car
{
    QPointArray a;
    QBrush brush( Qt::yellow, Qt::SolidPattern );
    p->setBrush( brush );			// use solid, yellow brush

    a.setPoints( 5, 50,50, 350,50, 450,120, 450,250, 50,250 );
    p->drawPolygon( a );			// draw car body

    QFont f( "courier", 12, QFont::Bold );
    p->setFont( f );

    QColor windowColor( 120, 120, 255 );	// a light blue color
    brush.setColor( windowColor );		// set this brush color
    p->setBrush( brush );			// set brush
    p->drawRect( 80, 80, 250, 70 );		// car window
    p->drawText( 180, 80, 150, 70, Qt::AlignCenter, "--  Qt  --\nTrolltech AS" );

    QPixmap pixmap;
    if ( pixmap.load("flag.bmp") )		// load and draw image
	p->drawPixmap( 100, 85, pixmap );

    p->setBackgroundMode( Qt::OpaqueMode );		// set opaque mode
    p->setBrush( Qt::DiagCrossPattern );		// black diagonal cross pattern
    p->drawEllipse( 90, 210, 80, 80 );		// back wheel
    p->setBrush( Qt::CrossPattern );		// black cross fill pattern
    p->drawEllipse( 310, 210, 80, 80 );		// front wheel
}
예제 #3
0
void ClusterView::customEvent(QCustomEvent* event){
 if(event->type() == QEvent::User + 700){
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  
  ComputeEvent* computeEvent = (ComputeEvent*) event;
  //Get the polygon
  QPointArray polygon = computeEvent->polygon();
  QRegion selectionArea;
  QPointArray reviewPolygon;
  long Xdimension = 0;
  long Ydimension = 0;

   //The QRegion uses rectangles to define its area and the number of rectangles
   //increases with the height of the region (y axis). The more rectangles the longer
   //the search of one point in the region will take. With a dimension like the time
   //the height has an order of the millon (at least 5 going to 80 or more) given a huge amount
   //of rectangles. A way of speeding the search of points is to reduce the number of rectangles.
   //To do so, if the y dimension is the time, x and y axis are inverted.
   //Caution: in Qt graphical coordinate system, the Y axis is inverted (increasing downwards),
   //thus a point (x,y) is drawn as (x,-y), before creating the region the points are reset to there raw value (x,y).
     
  if(view.ordinateDimension() != timeDimension){
    for(uint i = 0; i< polygon.size();++i){
     reviewPolygon.putPoints(i, 1,polygon.point(i).x(),-polygon.point(i).y());
     Xdimension = dimensionX;
     Ydimension = dimensionY;    
    }
  }
  else{    
    for(uint i = 0; i< polygon.size();++i){
     reviewPolygon.putPoints(i, 1,-polygon.point(i).y(),polygon.point(i).x());

     Xdimension = dimensionY;
     Ydimension = dimensionX;         
   }
  }
  //Create a QRegion with the new selection area in order to use the research facilities offer by a QRegion.  
  selectionArea = QRegion(reviewPolygon);
  if(!selectionArea.isNull()){
    //Call any appropriate method
    switch(mode){
     case DELETE_NOISE:
        doc.deleteNoise(selectionArea,view.clusters(),Xdimension,Ydimension);        
        break;
     case DELETE_ARTEFACT:
       doc.deleteArtifact(selectionArea,view.clusters(),Xdimension,Ydimension);
       break;
     case NEW_CLUSTER:
       doc.createNewCluster(selectionArea,view.clusters(),Xdimension,Ydimension);
       break;
     case NEW_CLUSTERS:
        doc.createNewClusters(selectionArea,view.clusters(),Xdimension,Ydimension);
       break;
     case ZOOM:
       break; //nothing to do   
    }
  }
  QApplication::restoreOverrideCursor(); 
 }
}
예제 #4
0
//
// The clock is painted using a 1000x1000 square coordinate system, in
// the a centered square, as big as possible.  The painter's pen and
// brush colors are used.
//
void QTodoClock::drawClock( QPainter *paint )
{
	paint->save();

	paint->setWindow( -500,-500, 1000,1000 );

	QRect v = paint->viewport();
	int d = QMIN( v.width(), v.height() );
	paint->setViewport( v.left() + (v.width()-d)/2,
	                    v.top() + (v.height()-d)/2, d, d );

	QPointArray pts;

	paint->save();
	paint->rotate( 30*(time.hour()%12-3) + time.minute()/2 );
	pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );
	paint->drawConvexPolygon( pts );
	paint->restore();

	paint->save();
	paint->rotate( (time.minute()-15)*6 );
	pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
	paint->drawConvexPolygon( pts );
	paint->restore();

	for ( int i=0; i<12; i++ )
	{
		paint->drawLine( 440,0, 460,0 );
		paint->rotate( 30 );
	}

	paint->restore();
}
예제 #5
0
void BlastAlignPainter::drawArrow(int xs, int xe, int y, int w, QPainter* p, QColor c){
  int aw = (int)((float)w*1.25);
  int al = (int)((float)w*3);
  
  int tx;

  QPointArray head;
  if(xe > xs){
    head.putPoints(0, 4, 0, 0, -al/3, -aw, al, 0, -al/3, aw);  // forward arrow
  }else{
    head.putPoints(0, 4, 0, 0, al/3, -aw, -al, 0, al/3, aw);
  }
  p->setPen(QPen(c, w));
  if(xe > xs){     // again if forward arrow
    p->drawLine(xs, y, xe-al, y);
    p->translate((double)xe-al, (double)y);
    tx = xe-al;
  }else{
    p->drawLine(xs, y, xe+al, y);
    p->translate((double)xe+al, (double)y);
    tx = xe+al;
  }
  // draw Head.
  p->setPen(QPen(c, 0));
  p->setBrush(c);
  p->drawPolygon(head);
  p->translate(-tx, 0);    // put back to where we came from, and return..
}
예제 #6
0
QRegion::QRegion( const QPointArray &a, bool winding )
{
    data = new QRegionData;
    CHECK_PTR( data );
    data->is_null = FALSE;
    data->rgn = XPolygonRegion( (XPoint*)a.data(), a.size(),
				winding ? WindingRule : EvenOddRule );
}
예제 #7
0
QPointArray KoChild::oldPointArray( const QWMatrix &matrix )
{
  QPointArray arr = d->m_old;

  for( int i = 0; i < 4; ++i )
      arr.setPoint( i, matrix.map( arr.point( i ) ) );

  return arr;
}
예제 #8
0
QPointArray Reversi::availableSpaces(const int player) const
{
	QPointArray spaces;
	for (int r = 0; r < size().height(); r++)
		for (int c = 0; c < size().width(); c++)
			if (available(QPoint(c, r), player))
				spaces.putPoints(spaces.size(), 1, c, r);
	return spaces;
}
예제 #9
0
QPointArray QWMatrix::map( const QPointArray &a ) const
{
    QPointArray result = a.copy();
    int x, y;
    for ( int i=0; i<(int)result.size(); i++ ) {
	result.point( i, &x, &y );
	map( x, y, &x, &y );
	result.setPoint( i, x, y );
    }
    return result;
}
예제 #10
0
파일: MontageView.cpp 프로젝트: Zitrax/peru
void MontageView::drawPoints(const QPointArray& pa, QValueList<int>& corners, int correct)
{
  if(ccv::debug) std::cerr << "MontageView::drawPoints - pa = " << pa.count() << " corners = " << corners.count() << "\n";

  QIconViewItem* item = firstItem();
  if( !item )
    return;

  m_dirty = true;

  QImage img = item->pixmap()->convertToImage();
  
  int item_nr = 0;

  bool failed = corners[item_nr] != correct;

  for( uint i=0; i<pa.count()+1; ++i ){

    if( corners[item_nr] == 0 ) {

      QPixmap pm(img);
      item->setPixmap( pm );
      item = item->nextItem();
      if( !item )
	return;

      img = item->pixmap()->convertToImage();

      item_nr++;
      failed = corners[item_nr] != correct;
    }    

    if(ccv::debug) std::cerr << " Point: " << i << " Image: " << item_nr 
			     << " (" << pa[i].x() << "," << pa[i].y() << ")" 
			     << " Corners: " << corners[item_nr] << "\n"; 

    if( !failed ) {
      img.setPixel( pa[i].x()  , pa[i].y()-1, qRgb(255,255,0) );
      img.setPixel( pa[i].x()-1, pa[i].y()  , qRgb(255,255,0) );
      img.setPixel( pa[i].x()  , pa[i].y()  , qRgb(255,0,0)   );
      img.setPixel( pa[i].x()+1, pa[i].y()  , qRgb(255,255,0) );
      img.setPixel( pa[i].x()  , pa[i].y()+1, qRgb(255,255,0) );
    }
    else {
      img.setPixel( pa[i].x()  , pa[i].y()-1, qRgb(255,0,0)   );
      img.setPixel( pa[i].x()-1, pa[i].y()  , qRgb(255,0,0)   );
      img.setPixel( pa[i].x()  , pa[i].y()  , qRgb(255,255,0) );
      img.setPixel( pa[i].x()+1, pa[i].y()  , qRgb(255,0,0)   );
      img.setPixel( pa[i].x()  , pa[i].y()+1, qRgb(255,0,0)   );
    }
    corners[item_nr]--;
  }
}
예제 #11
0
파일: rs_painter.cpp 프로젝트: Akaur/qdraw
void RS_Painter::createEllipse(QPointArray& pa,
                             const RS_Vector& cp,
                             double radius1, double radius2,
                             double angle,
                             double angle1, double angle2,
                             bool reversed)
{


    double aStep;         // Angle Step (rad)
    double a;             // Current Angle (rad)

    aStep=0.01;

    RS_Vector vp;
    RS_Vector vc(cp.x, cp.y);
    vp.set(cp.x+cos(angle1)*radius1,
           cp.y-sin(angle1)*radius2);
    vp.rotate(vc, -angle);

    int i=0;
    pa.resize(i+1);
    pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));

    if(!reversed) {
        // Arc Counterclockwise:
        if(angle1>angle2-RS_TOLERANCE) {
            angle2+=2*M_PI;
        }
        for(a=angle1+aStep; a<=angle2; a+=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y-sin(a)*radius2);
            vp.rotate(vc, -angle);

	    pa.resize(i+1);
            pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));
        }
    } else {
        // Arc Clockwise:
        if(angle1<angle2+RS_TOLERANCE) {
            angle2-=2*M_PI;
        }
        for(a=angle1-aStep; a>=angle2; a-=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y-sin(a)*radius2);
            vp.rotate(vc, -angle);

	    pa.resize(i+1);
            pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));
        }
    }
    vp.set(cp.x+cos(angle2)*radius1,
           cp.y-sin(angle2)*radius2);
    vp.rotate(vc, -angle);

    pa.resize(i+1);
    pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));

}
예제 #12
0
void
QWindowsStyle::drawArrow( QPainter *p, ArrowType type, bool down,
		 int x, int y, int w, int h,
		 const QColorGroup &g, bool enabled, const QBrush *fill )
{
    QPointArray a;				// arrow polygon
    switch ( type ) {
    case UpArrow:
	a.setPoints( 7, -4,1, 2,1, -3,0, 1,0, -2,-1, 0,-1, -1,-2 );
	break;
    case DownArrow:
	a.setPoints( 7, -4,-2, 2,-2, -3,-1, 1,-1, -2,0, 0,0, -1,1 );
	break;
    case LeftArrow:
	a.setPoints( 7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0 );
	break;
    case RightArrow:
	a.setPoints( 7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0 );
	break;
    }
    if ( a.isNull() )
	return;

    if ( down ) {
	x++;
	y++;
    }

    QPen savePen = p->pen();			// save current pen
    if (down)
	p->setBrushOrigin(p->brushOrigin() + QPoint(1,1));
    if ( fill )
	p->fillRect( x, y, w, h, *fill );
    if (down)
	p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));
    if ( enabled ) {
	a.translate( x+w/2, y+h/2 );
	p->setPen( g.buttonText() );
	p->drawLineSegments( a, 0, 3 );		// draw arrow
	p->drawPoint( a[6] );
    } else {
	a.translate( x+w/2+1, y+h/2+1 );
	p->setPen( g.light() );
	p->drawLineSegments( a, 0, 3 );		// draw arrow
	p->drawPoint( a[6] );
	a.translate( -1, -1 );
	p->setPen( g.mid() );
	p->drawLineSegments( a, 0, 3 );		// draw arrow
	p->drawPoint( a[6] );
    }
    p->setPen( savePen );			// restore pen

}
예제 #13
0
void TimelineSubItem::showItem( bool show, int coordY )
{
  KDGanttViewTaskItem::showItem( show, coordY );
  int y;
  if ( coordY != 0 ) {
    y = coordY;
  } else {
    y = getCoordY();
  }
  int startX = myGanttView->timeHeaderWidget()->getCoordX( myStartTime );
  int endX = myGanttView->timeHeaderWidget()->getCoordX( myEndTime );

  const int mw = qMax( 1, qMin( 4, endX - startX ) );
  if ( !mLeft || mw != mMarkerWidth ) {
    if ( !mLeft ) {
      mLeft = new KDCanvasPolygon( myGanttView->timeTableWidget(), this, Type_is_KDGanttViewItem );
      mLeft->setBrush( Qt::black );
    }
    QPointArray a = QPointArray( 4 );
    a.setPoint( 0, 0, -mw -myItemSize / 2 - 2 );
    a.setPoint( 1, mw, -myItemSize / 2 - 2 );
    a.setPoint( 2, mw, myItemSize / 2 + 2 );
    a.setPoint( 3, 0, myItemSize / 2 + mw + 2 );
    mLeft->setPoints( a );
  }
  if ( !mRight || mw != mMarkerWidth ) {
    if ( !mRight ) {
      mRight = new KDCanvasPolygon( myGanttView->timeTableWidget(), this, Type_is_KDGanttViewItem );
      mRight->setBrush( Qt::black );
    }
    QPointArray a = QPointArray( 4 );
    a.setPoint( 0, -mw, -myItemSize / 2 - 2 );
    a.setPoint( 1, 0, -myItemSize / 2 - mw - 2 );
    a.setPoint( 2, 0, myItemSize / 2 + mw + 2 );
    a.setPoint( 3, -mw, myItemSize / 2 + 2 );
    mRight->setPoints( a );
  }
  mMarkerWidth = mw;
  mLeft->setX( startX );
  mLeft->setY( y );
  mLeft->setZ( startShape->z() - 1 );
  mLeft->show();
  mRight->setX( endX );
  mRight->setY( y );
  mRight->setZ( startShape->z() - 1 );
  mRight->show();
}
예제 #14
0
// --------------------------------------------------------------------------------
void QmvCanvasGrid::drawEllipses( const QPointArray & pa,
                                  int w, int h, const QPen & pen )
{

    QPainter pt;
    pt.begin(&work_pixmap);
    pt.setPen( pen );
    
        // we want the centre at pa.point
    for ( int i = 0; i < pa.count(); i++ )
        pt.drawEllipse( pa.point(i).x() - w/2,
                        pa.point(i).y() - h/2, w, h );
    pt.end();
    
    updateGridImage( work_pixmap );
        
}
예제 #15
0
void OutputFlowNode::drawShape ( QPainter &p )
{
	const int _x = ( int ) x();
	const int _y = ( int ) y();



	if	( m_dir == 0 )		p.drawLine ( _x, _y, _x-8, _y );
	else if ( m_dir == 90 )		p.drawLine ( _x, _y, _x, _y-8 );
	else if ( m_dir == 180 )	p.drawLine ( _x, _y, _x+8, _y );
	else if ( m_dir == 270 )	p.drawLine ( _x, _y, _x, _y+8 );

	QPointArray pa ( 3 );

	switch ( m_dir )
	{
		case 0: // right
			pa = arrowPoints ( 0 );
			break;
		case 180: // left
			pa = arrowPoints ( 180 );
			break;
		case 90: // down
			pa = arrowPoints ( 90 );
			break;
		case 270: // up
			pa = arrowPoints ( 270 );
			break;
		default:
			kdError() << k_funcinfo << "BUG: m_dir = " << m_dir << endl;
	}


	// Note: I have not tested the positioning of the arrows for all combinations.
	// In fact, most almost definitely do not work. So feel free to change the code
	// as you see fit if necessary.

	if	( m_dir == 0 ) pa.translate ( -5, 0 );
	else if ( m_dir == 90 ) pa.translate ( 0, -5 );
	else if ( m_dir == 180 ) pa.translate ( 5, 0 );
	else if ( m_dir == 270 ) pa.translate ( 0, 5 );

	pa.translate ( _x, _y );
	p.drawPolygon ( pa );
}
예제 #16
0
void KIconEditGrid::drawPointArray(QPointArray a, DrawAction action)
{
  QRect rect = a.boundingRect();
  bool update = false;

  int s = a.size(); //((rect.size().width()) * (rect.size().height()));
  for(int i = 0; i < s; i++)
  {
    int x = a[i].x();
    int y = a[i].y();
    //if(img->valid(x, y) && !QSize(x, y).isNull() && rect.contains(QPoint(x, y)))
    if(img->valid(x, y) && rect.contains(QPoint(x, y)))
    {
      //debug("x: %d - y: %d", x, y);
      switch( action )
      {
        case Draw:
        {
          *((uint*)img->scanLine(y) + x) = currentcolor; //colors[cell]|OPAQUE;
          int cell = y * numCols() + x;
          setColor( cell, currentcolor, false );
          modified = true;
          update = true;
          //updateCell( y, x, FALSE );
          break;
        }
        case Mark:
        case UnMark:
          repaint(x*cellsize,y*cellsize, cellsize, cellsize, false);
          //updateCell( y, x, true );
          break;
        default:
          break;
      }
    }
  }
  if(update)
  {
    updateColors();
    repaint(rect.x()*cellSize()-1, rect.y()*cellSize()-1,
        rect.width()*cellSize()+1, rect.height()*cellSize()+1, false);
    pntarray.resize(0);
  }

}
예제 #17
0
static void qDrawWinArrow( QPainter *p, Qt::ArrowType type, bool down,
			   int x, int y, int w, int h,
			   const QColorGroup &g, bool enabled )
{
    QPointArray a;				// arrow polygon
    switch ( type ) {
    case Qt::UpArrow:
	a.setPoints( 7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2 );
	break;
    case Qt::DownArrow:
	a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 );
	break;
    case Qt::LeftArrow:
	a.setPoints( 7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0 );
	break;
    case Qt::RightArrow:
	a.setPoints( 7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0 );
	break;
    }
    if ( a.isNull() )
	return;

    if ( down ) {
	x++;
	y++;
    }

    QPen savePen = p->pen();			// save current pen
    if (down)
	p->setBrushOrigin(p->brushOrigin() + QPoint(1,1));
    p->fillRect( x, y, w, h, g.brush( QColorGroup::Button ) );
    if (down)
	p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));
    if ( enabled ) {
	a.translate( x+w/2, y+h/2 );
	p->setPen( g.foreground() );
	p->drawLineSegments( a, 0, 3 );		// draw arrow
	p->drawPoint( a[6] );
    } else {
	a.translate( x+w/2+1, y+h/2+1 );
	p->setPen( g.light() );
	p->drawLineSegments( a, 0, 3 );		// draw arrow
	p->drawPoint( a[6] );
	a.translate( -1, -1 );
	p->setPen( g.mid() );
	p->drawLineSegments( a, 0, 3 );		// draw arrow
	p->drawPoint( a[6] );
    }
    p->setPen( savePen );			// restore pen
}
	void KviCanvasView::beginDragPolygon(KviCanvasPolygon * it,const QPoint &p,bool bShift,bool bCtrl)
	{
		m_dragBegin = QPoint((int)(p.x() - it->x()),(int)(p.y() - it->y()));

		QPointArray pa = it->areaPoints();

		for(unsigned int i=0;i<pa.size();i++)
		{
			QPoint pnt = pa.point(i);
			double dX = pnt.x() - p.x();
			double dY = pnt.y() - p.y();
			double dHypot = sqrt((dX * dX) + (dY * dY));
			if(dHypot < 3.0)
			{
				// We're dragging a point
				m_dragMode = SinglePoint;
				m_dragPointIndex = i;
				setCursor(crossCursor);
				return;
			}
		}

		if(bShift)
		{
			m_dragMode = Scale;
			m_dragScaleFactor = it->scaleFactor();
			setCursor(sizeAllCursor);
			return;
		}

		if(bCtrl)
		{
			m_dragMode = Rotate;
			m_dragPointArray = it->internalPoints();
	//		qDebug("Here");
			setCursor(sizeHorCursor);
			return;
		}

		m_dragMode = All;
		setCursor(pointingHandCursor);
	}
예제 #19
0
QRegion::QRegion( const QRect &r, RegionType t )
{
    QRect rr = r.normalize();
    data = new QRegionData;
    CHECK_PTR( data );
    data->is_null = FALSE;
    if ( t == Rectangle ) {			// rectangular region
	data->rgn = XCreateRegion();
	XRectangle xr;
	xr.x = rr.x();
	xr.y = rr.y();
	xr.width  = rr.width();
	xr.height = rr.height();
	XUnionRectWithRegion( &xr, data->rgn, data->rgn );
    } else if ( t == Ellipse ) {		// elliptic region
	QPointArray a;
	a.makeEllipse( rr.x(), rr.y(), rr.width(), rr.height() );
	data->rgn = XPolygonRegion( (XPoint*)a.data(), a.size(), EvenOddRule );
    }
}
	static void calcPolygonPoints(QPointArray &pnts,unsigned int nVertices)
	{
		double dDelta = (2 * M_PI) / nVertices;
		for(unsigned int i=0;i<nVertices;i++)
		{
			double dAng = dDelta * i;
			double theX = 300 * sin(dAng);
			double theY = 300 * cos(dAng);
			pnts.setPoint(i,(int)theX,(int)theY);
		}
	}
예제 #21
0
/*!
  Paints the resize grip - small diagonal textured lines in the
  lower right-hand corner.
*/
void QSizeGrip::paintEvent( QPaintEvent *e )
{
    QPainter painter( this );
    painter.setClipRegion(e->region());
    painter.translate( width()-13, height()-13 ); // paint in the corner
    QPointArray a;
    a.setPoints( 3, 1,12, 12,1, 12,12 );
    painter.setPen( QPen( colorGroup().dark(), 1 ) );
    painter.setBrush( colorGroup().dark() );
    painter.drawPolygon( a );
    painter.setPen( QPen( colorGroup().light(), 1 ) );
    painter.drawLine(  0, 12, 13,  -1 );
    painter.drawLine(  4, 12, 13,  3 );
    painter.drawLine( 8, 12, 13, 7 );
    painter.setPen( QPen( colorGroup().background(), 1 ) );
    painter.drawLine( 3, 12, 13, 2 );
    painter.drawLine( 7, 12, 13, 6 );
    painter.drawLine( 11, 12, 13, 10 );
    painter.drawLine( 12, 12, 13, 11 );
}
예제 #22
0
QPoint Reversi::ai(const int player)
{
	const int choices[8][8] = {
		{100,	-100,	50,	30,	30,	50,	-100,	100,},
		{-100,	-100,	-50,	-50,	-50,	-50,	-100,	-100,},
		{50,	-50,	10,	10,	10,	10,	-50,	50,},
		{30,	-50,	10,	0,	0,	10,	-50,	30,},
		{30,	-50,	10,	0,	0,	10,	-50,	30,},
		{50,	-50,	10,	10,	10,	10,	-50,	50,},
		{-100,	-100,	-50,	-50,	-50,	-50,	-100,	-100,},
		{100,	-100,	50,	30,	30,	50,	-100,	100,},
	};
	QPointArray spaces = availableSpaces(player);
	if (spaces.size() == 0)
		return BoardGame::ai(player);
	int values[spaces.size()];
	for (unsigned int i = 0; i < spaces.size(); i++) {
		QPoint p(spaces[i]);
		values[i] = choices[p.y()][p.x()] + reversible(p, player) * 5;
	}
	int max = 0;
	for (unsigned int i = 0; i < spaces.size(); i++)
		if (values[i] > values[max])
			max = i;
	QList<int> equals;
	equals.setAutoDelete(true);
	for (unsigned int i = 0; i < spaces.size(); i++)
		if (values[i] == values[max])
			equals.append(new int(i));
	return spaces[*equals.at(rand() % equals.count())];
}
예제 #23
0
QRegion::QRegion( const QPointArray &a, bool winding )
{
    data = new QRegionData;
    Q_CHECK_PTR( data );
    data->hgt = 0;
    data->is_null = FALSE;
    QRect r = a.boundingRect();
    if ( a.isEmpty() || r.isEmpty() ) {
	data->rgn = 0;
    } else {
        HPS hps = qt_display_ps();
        POINTL *pts = new POINTL[ a.size() ]; 
        for ( uint i = 0; i < a.size(); ++ i ) {
            pts[i].x = a[i].x();
            pts[i].y = - (a[i].y() + 1);
        }
        // GpiCreatePolygonRegion() is bogus and always starts a poligon from
        // the current position. Make the last point the current one and reduce
        // the number of points by one.
        GpiMove( hps, &pts[ a.size() - 1 ] );
        POLYGON poly = { a.size() - 1, pts };
        ULONG opts = winding ? POLYGON_WINDING : POLYGON_ALTERNATE;
        data->rgn = GpiCreatePolygonRegion( hps, 1, &poly, opts );
        delete[] pts;
    }
}
예제 #24
0
QRegion::QRegion( const QRect &r, RegionType t )
{
    data = new QRegionData;
    Q_CHECK_PTR( data );
    data->hgt = 0;
    data->is_null = FALSE;
    if ( r.isEmpty() ) {
	data->rgn = 0;
    } else {
        HPS hps = qt_display_ps();
	if ( t == Rectangle ) {			// rectangular region
            RECTL rcl = { r.left(), -(r.bottom()+1), r.right()+1, -r.top() };
            data->rgn = GpiCreateRegion( hps, 1, &rcl );
	} else if ( t == Ellipse ) {		// elliptic region
            // if the width or height of the ellipse is odd, GPI always
            // converts it to a nearest even value, which is obviously stupid
            // (see also QPainter::drawArcInternal()). So, we don't use
            // GpiCreateEllipticRegion(), but create an array of points to
            // call GpiCreatePolygonRegion() instead.
            QPointArray a;
            a.makeArc( r.x(), r.y(), r.width(), r.height(), 0, 360 * 16 );
            for ( uint i = 0; i < a.size(); ++ i )
                a[i].ry() = -(a[i].y() + 1);
            // GpiCreatePolygonRegion() is bogus and always starts a poligon from
            // the current position. Make the last point the current one and reduce
            // the number of points by one.
            GpiMove( hps, (PPOINTL) &a[ a.size() - 1 ] );
            POLYGON poly = { a.size() - 1, (PPOINTL) a.data() };
            data->rgn = GpiCreatePolygonRegion( hps, 1, &poly, POLYGON_ALTERNATE );
	}
    }
}
예제 #25
0
void AnalogClock::paintEvent( QPaintEvent * )	// paint clock
{
    if ( !isVisible() )				// is is invisible
	return;
    time = QTime::currentTime();		// save current time

    QPointArray pts;
    QPainter paint( this );
    paint.setBrush( foregroundColor() );	// fill with foreground color

    QPoint cp = rect().center();		// widget center point
    int d = QMIN(width(),height());		// we want a circular clock

    QWMatrix matrix;				// setup transformation matrix
    matrix.translate( cp.x(), cp.y() );		// origin at widget center
    matrix.scale( d/1000.0F, d/1000.0F );	// scale coordinate system

    float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
    matrix.rotate( h_angle );			// rotate to draw hour hand
    paint.setWorldMatrix( matrix );
    pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );
    paint.drawPolygon( pts );			// draw hour hand
    matrix.rotate( -h_angle );			// rotate back to zero

    float m_angle = (time.minute()-15)*6;
    matrix.rotate( m_angle );			// rotate to draw minute hand
    paint.setWorldMatrix( matrix );
    pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
    paint.drawPolygon( pts );			// draw minute hand
    matrix.rotate( -m_angle );			// rotate back to zero

    for ( int i=0; i<12; i++ ) {		// draw hour lines
	paint.setWorldMatrix( matrix );
	paint.drawLine( 450,0, 500,0 );
	matrix.rotate( 30 );
    }
}
예제 #26
0
// --------------------------------------------------------------------------------
void QmvCanvasGrid::drawText( const QPointArray & pa,
                              const QPen & pen, const QFont font, QString text, int w, int h )
{

    QPainter pt;
    pt.begin(&work_pixmap);
    
    pt.setPen( pen );
    pt.setFont( font );
    
        // we want the centre at pa.point
    int x, y;
    for ( int i = 0; i < pa.count(); i++ )
    {
        x = pa.point(i).x() - w/2;
        y = pa.point(i).y() - h/2;
        pt.drawText( x, y, w, h,
                     AlignHCenter | AlignVCenter,
                     text, text.length() );
    }
    pt.end();
    
    updateGridImage( work_pixmap );
}
예제 #27
0
void MarkerBar::DrawMap()
{
  QPixmap *pix=new QPixmap(size());
  QPainter *p=new QPainter(pix);
  QPointArray *pt;
  p->fillRect(0,0,size().width(),size().height(),backgroundColor());
  if(marker_length>0) {
    p->setPen(EVENT_EDITOR_START_MARKER);
    p->setBrush(EVENT_EDITOR_START_MARKER);
    p->fillRect(size().width()*marker_pos[MarkerBar::Start]/marker_length-2,0,
		4,size().height(),EVENT_EDITOR_START_MARKER);
    pt=new QPointArray(3);
    pt->setPoint(0,size().width()*marker_pos[MarkerBar::Start]/marker_length-2,
		 size().height()/2-1);
    pt->setPoint(1,size().width()*marker_pos[MarkerBar::Start]/marker_length-12,
		 size().height()-2);
    pt->setPoint(2,size().width()*marker_pos[MarkerBar::Start]/marker_length-12,
		 1);
    p->drawPolygon(*pt);

    p->fillRect(size().width()*marker_pos[MarkerBar::End]/marker_length-2,0,
		4,size().height(),EVENT_EDITOR_START_MARKER);
    pt->setPoint(0,size().width()*marker_pos[MarkerBar::End]/marker_length+2,
		 size().height()/2-1);
    pt->setPoint(1,size().width()*marker_pos[MarkerBar::End]/marker_length+12,
		 size().height()-2);
    pt->setPoint(2,size().width()*marker_pos[MarkerBar::End]/marker_length+12,
		 1);
    p->drawPolygon(*pt);
    delete pt;

    p->setPen(EVENT_EDITOR_PLAY_MARKER);
    p->setBrush(EVENT_EDITOR_PLAY_MARKER);
    p->fillRect(size().width()*marker_pos[MarkerBar::Play]/marker_length-1,0,
		2,size().height(),EVENT_EDITOR_PLAY_MARKER);
  }
  p->end();
  setPixmap(*pix);
  delete p;
  delete pix;
}
	void KviCanvasView::dragPolygon(KviCanvasPolygon * it,const QPoint &p)
	{
		switch(m_dragMode)
		{
			case All:
				it->move(p.x() - m_dragBegin.x(),p.y() - m_dragBegin.y());
			break;
			case SinglePoint:
			{
				QPointArray pnt = it->internalPoints();
				pnt.setPoint(m_dragPointIndex,(int)((p.x() - it->x()) / it->scaleFactor()),(int)((p.y() - it->y()) / it->scaleFactor()));
				it->setInternalPoints(pnt);
			}
			break;
			case Scale:
			{
				double dDistance = ssm_hypot(p.x() - it->x(),p.y() - it->y());
				double dOriginal = ssm_hypot(m_dragBegin.x(),m_dragBegin.y());
				if(dOriginal < 1)dOriginal = 1;
				if(dDistance < 0.1)dDistance = 0.1;
				it->setScaleFactor(m_dragScaleFactor * dDistance / dOriginal);
			}
			break;
			case Rotate:
			{
				QPoint act((int)(p.x() - it->x()),(int)(p.y() - it->y()));
				double dAngle = ssm_2d_rotationAngle(m_dragBegin.x(),m_dragBegin.y(),act.x(),act.y());
	//			qDebug("%d,%d %d,%d %f",m_dragBegin.x(),m_dragBegin.y(),act.x(),act.y(),dAngle);
				QPointArray thePoints = m_dragPointArray.copy();
				for(unsigned int i=0;i<thePoints.size();i++)
				{
					QPoint tmp = thePoints.point(i);
					double dx = tmp.x();
					double dy = tmp.y();
					ssm_2d_rotate(dx,dy,dAngle);
					thePoints.setPoint(i,(int)dx,(int)dy);
				}
				it->setInternalPoints(thePoints);
			}
			break;
			default:
			break;
		}
		canvas()->update();
	}
예제 #29
0
void KdmClock::paintEvent( QPaintEvent * )
{
	if (!isVisible())
		return;

	QPainter p( this );
	drawFrame( &p );

	QPixmap pm( contentsRect().size() );
	QPainter paint;
	paint.begin( &pm );
	paint.fillRect( contentsRect(), mBackgroundBrush );

	// get current time
	QTime time = QTime::currentTime();

/*
	if (mDigital) {
		QString buf;
		if (mSecond)
			buf.sprintf( "%02d:%02d:%02d", time.hour(), time.minute(),
			             time.second() );
		else
			buf.sprintf( "%02d:%02d", time.hour(), time.minute() );
		mFont.setPointSize( QMIN( (int)(width()/buf.length()*1.5),height() ) );
		paint.setFont( mFont );
		paint.setPen( backgroundColor() );
		paint.drawText( contentsRect(),AlignHCenter|AlignVCenter, buf,-1,0,0 );
	} else {
*/
		QPointArray pts;
		QPoint cp = contentsRect().center() - QPoint( 2,2 );
		int d = QMIN( contentsRect().width()-15,contentsRect().height()-15 );
		paint.setPen( foregroundColor() );
		paint.setBrush( foregroundColor() );

		QWMatrix matrix;
		matrix.translate( cp.x(), cp.y() );
		matrix.scale( d/1000.0F, d/1000.0F );

		// Hour
		float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
		matrix.rotate( h_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );
		paint.drawPolygon( pts );
		matrix.rotate( -h_angle );

		// Minute
		float m_angle = (time.minute()-15)*6;
		matrix.rotate( m_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
		paint.drawPolygon( pts );
		matrix.rotate( -m_angle );

		// Second
		float s_angle = (time.second()-15)*6;
		matrix.rotate( s_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4,0,0,0,0,400,0,0,0 );
		if (mSecond)
			paint.drawPolygon( pts );
		matrix.rotate( -s_angle );

		// quadrante
		for (int i=0 ; i < 60 ; i++) {
			paint.setWorldMatrix( matrix );
			if ((i % 5) == 0)
				paint.drawLine( 450,0, 500,0 ); // draw hour lines
			else
				paint.drawPoint( 480,0 ); // draw second lines
			matrix.rotate( 6 );
		}

//	} // if (mDigital)
	paint.end();

	// flicker free code by Remi Guyomarch <*****@*****.**>
	bitBlt( this, contentsRect().topLeft(), &pm );
}
예제 #30
0
void KDGanttViewTaskLink::initTaskLink()
{
  horLineList = new QPtrList<KDCanvasLine>;
  verLineList = new QPtrList<KDCanvasLine>;
  horLineList2 = new QPtrList<KDCanvasLine>;
  verLineList2 = new QPtrList<KDCanvasLine>;
  horLineList3 = new QPtrList<KDCanvasLine>;
  topList = new QPtrList<KDCanvasPolygon>;
  topLeftList = new QPtrList<KDCanvasPolygon>;
  topRightList = new QPtrList<KDCanvasPolygon>;
  horLineList->setAutoDelete( true );
  verLineList->setAutoDelete( true );
  horLineList2->setAutoDelete( true );
  verLineList2->setAutoDelete( true );
  horLineList3->setAutoDelete( true );
  topList->setAutoDelete( true );
  topLeftList->setAutoDelete( true );
  topRightList->setAutoDelete( true );
  myTimeTable = fromList.getFirst()->myGanttView->myTimeTable;
  KDCanvasLine* horLine,*verLine;
  KDCanvasLine* horLine2,*verLine2;
  KDCanvasLine* horLine3;
  KDCanvasPolygon* top;
  KDCanvasPolygon* topLeft;
  KDCanvasPolygon* topRight;
  unsigned int i, j;
  for ( i = 0;i < fromList.count();++i) {
    for ( j = 0;j < toList.count();++j) {
      horLine = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
      verLine = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
      horLine2 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
      verLine2 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
      horLine3 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
      top = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
      topLeft = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
      topRight = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
      QPointArray arr = QPointArray(3);
      arr.setPoint(0,-4,-5);
      arr.setPoint(1,4,-5);
      arr.setPoint(2,0,0);
      top->setPoints(arr);
      arr.setPoint(0,5,-5); // need an extra y pixel, canvas bug?
      arr.setPoint(1,5,5);  // need an extra y pixel, canvas bug?
      arr.setPoint(2,0,0);
      topLeft->setPoints(arr);
      arr.setPoint(0,-5,-4);
      arr.setPoint(1,-5,4);
      arr.setPoint(2,0,0);
      topRight->setPoints(arr);
      horLineList->append(horLine);
      verLineList->append(verLine);
      horLineList2->append(horLine2);
      verLineList2->append(verLine2);
      horLineList3->append(horLine3);
      topList->append(top);
      topLeftList->append(topLeft);
      topRightList->append(topRight);
      horLine->setZ(1);
      verLine->setZ(1);
      horLine2->setZ(1);
      verLine2->setZ(1);
      horLine3->setZ(1);
      top->setZ(1);
      topLeft->setZ(1);
      topRight->setZ(1);
    }
  }

  setTooltipText( "Tasklink" );
  setWhatsThisText( "Tasklink" );
  myTimeTable->myTaskLinkList.append(this);
  setHighlight( false);
  setHighlightColor(Qt::red );
  setColor(Qt::black);
  setVisible(true);
}