コード例 #1
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
コード例 #2
0
ファイル: qdrawutil.cpp プロジェクト: FilipBE/qtextended
static void qDrawWinArrow(QPainter *p, Qt::ArrowType type, bool down,
                           int x, int y, int w, int h,
                           const QPalette &pal, bool enabled)
{
    QPolygon 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;
    default:
        break;
    }
    if (a.isEmpty())
        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, pal.brush(QPalette::Button));
    if (down)
        p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));
    if (enabled) {
        a.translate(x+w/2, y+h/2);
        p->setPen(pal.foreground().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
    } else {
        a.translate(x+w/2+1, y+h/2+1);
        p->setPen(pal.light().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
        a.translate(-1, -1);
        p->setPen(pal.mid().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
    }
    p->setPen(savePen);                        // restore pen
}
コード例 #3
0
ファイル: arrow.cpp プロジェクト: rowhit/qucs
// --------------------------------------------------------------------------
void Arrow::paint(ViewPainter *p)
{
  QPolygon Points;
  int x1_, y1_, x2_, y2_, x3_, y3_;
  if(isSelected) {
    p->Painter->setPen(QPen(Qt::darkGray,Pen.width()+5));
    p->drawLine(cx, cy, cx+x2, cy+y2);
    p->drawLine(cx+x2, cy+y2, cx+xp1, cy+yp1);
    p->drawLine(cx+x2, cy+y2, cx+xp2, cy+yp2);
    if(Style == 0) {   // arrow head with two lines ?
      p->Painter->setPen(QPen(Qt::white, Pen.width(), Pen.style()));
      p->drawLine(cx, cy, cx+x2, cy+y2);
      p->Painter->setPen(QPen(Qt::white, Pen.width(), Qt::SolidLine));
      p->drawLine(cx+x2, cy+y2, cx+xp1, cy+yp1);
      p->drawLine(cx+x2, cy+y2, cx+xp2, cy+yp2);
    }
    else {   // filled arrow head
      p->drawLine(cx+xp1, cy+yp1, cx+xp2, cy+yp2);
      p->Painter->setPen(QPen(Qt::white, Pen.width(), Pen.style()));
      p->drawLine(cx, cy, cx+x2, cy+y2);

      p->Painter->setPen(QPen(Qt::white, Pen.width(), Qt::SolidLine));
      p->Painter->setBrush(Qt::white);
      p->map(cx+xp1, cy+yp1, x1_, y1_);
      p->map(cx+x2, cy+y2, x2_, y2_);
      p->map(cx+xp2, cy+yp2, x3_, y3_);
      Points.setPoints(3, x1_, y1_, x2_, y2_, x3_, y3_);
      p->Painter->drawConvexPolygon(Points);
      p->Painter->setBrush(Qt::NoBrush); // no filling for next paintings
    }

    p->Painter->setPen(QPen(Qt::darkRed,2));
    p->drawResizeRect(cx, cy);  // markers for changing the size
    p->drawResizeRect(cx+x2, cy+y2);
    return;
  }
  p->Painter->setPen(Pen);
  p->drawLine(cx, cy, cx+x2, cy+y2);
  p->Painter->setPen(QPen(Pen.color(), Pen.width(), Qt::SolidLine));
  if(Style == 0) {   // arrow head with two lines ?
    p->drawLine(cx+x2, cy+y2, cx+xp1, cy+yp1);
    p->drawLine(cx+x2, cy+y2, cx+xp2, cy+yp2);
  }
  else {   // filled arrow head
    p->Painter->setBrush(Pen.color());
    p->map(cx+xp1, cy+yp1, x1_, y1_);
    p->map(cx+x2, cy+y2, x2_, y2_);
    p->map(cx+xp2, cy+yp2, x3_, y3_);
    Points.setPoints(3, x1_, y1_, x2_, y2_, x3_, y3_);
    p->Painter->drawConvexPolygon(Points);
    p->Painter->setBrush(Qt::NoBrush); // no filling for next paintings
  }
}
コード例 #4
0
ファイル: scene.cpp プロジェクト: Piolun/ProjektKCK
Scene::Scene(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
{
    Objects = QList<Object*>();
    TempObjects = QList<Object*>();
    ScriptObjects = QList<Object*>();
    PotentialObjects = QList<word*>();
    Dictionary = QList<word*>();
    inputI = QList<word*>();
    SceneInstance = this;
    width = 32;
    height = 32;


    new Color(0,0,255,"niebiesk błękit");
    new Color(0,255,0,"zielon");
    new Color(255,0,0,"czerwon");
    new Color(255,0,255,"róż");
    new Color (255,255,0,"żółt");

    //new Color (65,105,225,"kolor_królewsk"); //tokenizator psuje - trza znaleźć inną metodę






    QPolygon temp;
    temp.setPoints(4, 0, 0, 50, 0, 50, 50, 0, 50);
    new Figure("kwadrat", temp);

    temp.setPoints(3, 25, 0, 0, 50, 50, 50);
    new Figure("trójkąt", temp);

    temp.setPoints(4, 0, 0, 100, 0, 100, 50, 0, 50);
    new Figure("prostokąt", temp);

    temp.setPoints(4, 25, 0, 75, 0, 100, 50, 0, 50);
    new Figure("trapez", temp);


    new Object("trójkąt","różowy",0,250);
    new Object("kwadrat","niebieski",550,250);
    new Object("kwadrat","zielonkawy",100,250);
    new Object("trójkąt","zielony",400,250);
    new Object("prostokąt","żółty",200,250);
    new Object("trapez","niebieski",300,250);


}
コード例 #5
0
void SlopeEditor::paintEvent(QPaintEvent* event) {
	QPainter painter(this);
	QPalette pal = QApplication::palette();
	if(isEnabled()) {
		pal.setCurrentColorGroup(QPalette::Normal);
	} else {
		pal.setCurrentColorGroup(QPalette::Disabled);
	}
	float scale = event->rect().height() / 16;
	QPoint start(0,0), end(event->rect().right(),0);
	start.setY(_left * scale);
	end.setY(_right * scale);
	//qDebug() << (_slope != 0 ? event->rect().height()/_slope : 0);
	QPolygon p;
	painter.setRenderHint(QPainter::Antialiasing);
	painter.fillRect(0, 0, width(), height(), pal.color(QPalette::Base));
	QPen slopePen;
	slopePen.setColor(pal.color(QPalette::Text));
	slopePen.setStyle(Qt::SolidLine);
	slopePen.setWidth(1);
	QBrush brush = pal.highlight();
	painter.setBrush(brush);
	painter.setPen(slopePen);
	if(!_slopeOnBottom) {
		p.setPoints(4, start.x(), start.y(), end.x() + 1, end.y(), event->rect().right() + 1, event->rect().bottom() + 1, event->rect().left(), event->rect().bottom() + 1);
		painter.drawPolygon(p);
	} else {
		p.setPoints(4, start.x(), start.y(), end.x() + 1, end.y(), event->rect().right() + 1, event->rect().top(), event->rect().left(), event->rect().top());
		painter.drawPolygon(p);
	}
	//handles
	painter.setBrush(Qt::NoBrush);
	start.rx() += width()/16;
	end.rx() -= width()/16;
	if(start.y() == height()) {
		start.ry() -= width()/16;
	}
	if(start.y() == 0) {
		start.ry() += width()/16;
	}
	if(end.y() == height()) {
		end.ry() -= width()/16;
	}
	if(end.y() == 0) {
		end.ry() += width()/16;
	}
	painter.drawEllipse(start, width()/16, width()/16);
	painter.drawEllipse(end, width()/16, width()/16);
}
コード例 #6
0
ファイル: hruler.cpp プロジェクト: Fahad-Alsaidi/scribus-svn
void Hruler::drawMarker(QPainter& p)
{
	QPolygon cr;
#ifdef OPTION_SMOOTH_MARKERS
	// draw new marker to pixmap
	static const int SCALE = 16;
	static const QColor BACKGROUND(255, 255, 255);
	static QPixmap pix( 4*SCALE, 16*SCALE );
	static bool initpix = true;
	if (initpix) {
		initpix = false;
		QPainter pp( &pix );
		pp.setBrush( BACKGROUND );
		pp.drawRect( 0, 0, 4*SCALE, 16*SCALE );
		
		pp.setPen(Qt::red);
		pp.setBrush(Qt::red);
		cr.setPoints(3, 2*SCALE, 16*SCALE, 4*SCALE, 0, 0, 0);
		pp.drawPolygon(cr);
	}
	// draw pixmap
	p.save();
	p.translate(-m_view->contentsX(), 0);
	p.scale(1.0/SCALE, 1.0/(SCALE+1));
	p.drawPixmap((where-2)*SCALE, 1, pix);
	p.restore();
	// restore marks
	p.setBrush(Qt::black);
	p.setPen(Qt::black);
	p.setFont(font());
	double sc = m_view->getScale();
	double cc = width() / sc;
	double firstMark = ceil(offs / iter) * iter - offs;
	while (firstMark < cc)
	{
		p.drawLine(qRound(firstMark * sc), 10, qRound(firstMark * sc), 16);
		firstMark += iter;
	}
#else
	// draw slim marker
	p.resetTransform();
	p.translate(-m_view->contentsX(), 0);
	p.setPen(Qt::red);
	p.setBrush(Qt::red);
	cr.setPoints(5,  whereToDraw, 5, whereToDraw, 16, whereToDraw, 5, whereToDraw+2, 0, whereToDraw-2, 0);
	p.drawPolygon(cr);
#endif
}
コード例 #7
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)

    }
}
コード例 #8
0
ファイル: myspeedwatch.cpp プロジェクト: rio-2607/gps_monitor
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);
}
コード例 #9
0
ファイル: mainwindow.cpp プロジェクト: maxxant/qt
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));
    }
}
コード例 #10
0
ファイル: tupluminancepicker.cpp プロジェクト: nanox/tupi
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
0
ファイル: ClsBaseQStateArrayView.cpp プロジェクト: jeez/iqr
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;

}
コード例 #12
0
void QMeter::drawNeedle(QPainter *painter)
{
    // hat shadow
//    painter->setPen(Qt::NoPen);
//    painter->setBrush(QColor(120,120,120,10));
//    painter->drawEllipse(-5, -6, 14, 14);
    // end hat shadow

	painter->save();

	painter->rotate(-90.0); 
	QPolygon pts;
    pts.setPoints( 3, -2,0,  2,0,  0,30 );
    QPolygon shadow;
    shadow.setPoints(3, -1,0, 1,0, 0,29);
	int degRotate=0;

    degRotate = (int)( m_startAngle+(m_endAngle-m_startAngle)/(m_maxValue-m_minValue)*(m_value-m_minValue) );	 
	 
	painter->rotate( -degRotate );
    QRadialGradient haloGradient(0, 0, 20, 0, 0);
    haloGradient.setColorAt(0.0, QColor(255,120,120));
    haloGradient.setColorAt(1.0, QColor(200,20,20));
    QColor color=QColor(Qt::darkRed);
    color.setAlpha(90);
    painter->setPen(color);
	painter->setBrush(haloGradient);
	painter->drawConvexPolygon( pts );

    painter->setBrush(QColor(255,120,120));
    painter->drawConvexPolygon( shadow );

	painter->restore();
	
    // draw needle hat
    QLinearGradient linearGrad(QPointF(-7, -7), QPointF(14, 14));
    linearGrad.setColorAt(0, Qt::white);
    linearGrad.setColorAt(1, Qt::black);
    painter->setPen(Qt::NoPen);
    painter->setBrush(linearGrad);
    painter->drawEllipse(-7, -7, 14, 14);

}
コード例 #13
0
ファイル: main.cpp プロジェクト: AngelTerrones/GA-render
void DrawSVG(Chromosome *dna, const char *svgName){
    QSvgGenerator svgGen;
    svgGen.setFileName(QString(svgName));
    svgGen.setSize(QSize(imgW, imgH));
    svgGen.setViewBox(QRect(0, 0, imgW, imgH));

    QPainter painter(&svgGen);
    painter.setPen(Qt::NoPen);
    painter.setRenderHint(QPainter::Antialiasing);

    // Black background
    painter.setBrush(QBrush(QColor(0, 0, 0, 255)));
    QPolygon polyclean;
    int pointsclean[] = {0, 0, 0, imgH, imgW, imgH, imgW, 0};
    polyclean.setPoints(4, pointsclean);
    painter.drawConvexPolygon(polyclean);

    // Draw all the polygons
    Polygon *poly = dna->DNA();
    for (int n = 0; n < N_POLYGONS; n++) {
        QColor color(poly[n].Red(),
                     poly[n].Green(),
                     poly[n].Blue(),
                     poly[n].Alpha());
        painter.setBrush(QBrush(color));

        int size = poly[n].NPoints();
        int *listPoints = new int[2*size];

        for(int i = 0; i < size; i++){
            listPoints[2*i] = poly[n].Vertex()[i].x();
            listPoints[2*i + 1] = poly[n].Vertex()[i].y();
        }

        QPolygon qPoly;
        qPoly.setPoints(size, listPoints);
        painter.drawConvexPolygon(qPoly);
        delete [] listPoints;
    }
    painter.end();
}
コード例 #14
0
void MusicRemoteWidgetForDiamond::paintEvent(QPaintEvent* event)
{
    MusicRemoteWidget::paintEvent(event);
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    QPolygon pts;
    pts.setPoints(4, 8, 80 , 80, 8, 154, 81, 80, 154);
    QPainterPath path;
    path.addPolygon(pts);
    painter.fillPath(path,QBrush(QColor(0, 0, 0, 50)));
    painter.end();
}
コード例 #15
0
ファイル: main.cpp プロジェクト: AngelTerrones/GA-render
// functions
QImage DrawImage(Chromosome *dna){
    QImage image(imgW, imgH, QImage::Format_RGB32);
    QPainter painter(&image);
    painter.setPen(Qt::NoPen);
    painter.setRenderHint(QPainter::Antialiasing);

    // black background
    painter.setBrush(QBrush(QColor(0, 0, 0, 255)));
    QPolygon polyclean;
    int pointsclean[] = {0, 0, 0, imgH, imgW, imgH, imgW, 0};
    polyclean.setPoints(4, pointsclean);
    painter.drawConvexPolygon(polyclean);

    // Draw all the polygons
    Polygon *poly = dna->DNA();
    for (int n = 0; n < N_POLYGONS; n++) {
        QColor color(poly[n].Red(),
                     poly[n].Green(),
                     poly[n].Blue(),
                     poly[n].Alpha());
        painter.setBrush(QBrush(color));

        int size = poly[n].NPoints();
        int *listPoints = new int[2*size];

        for(int i = 0; i < size; i++){
            listPoints[2*i] = poly[n].Vertex()[i].x();
            listPoints[2*i + 1] = poly[n].Vertex()[i].y();
        }

        QPolygon qPoly;
        qPoly.setPoints(size, listPoints);
        painter.drawConvexPolygon(qPoly);
        delete [] listPoints;
    }
    painter.end();

    return image;
}
コード例 #16
0
void
QvisOpacitySlider::drawSlider(QPainter *p, int x, int y, int w, int h)
{
    // Get some colors from the widget's colorgroup.
    const QColor c0 = palette().color(QPalette::Shadow);
    const QColor c1 = palette().color(QPalette::Dark);
    const QColor c3 = palette().color(QPalette::Mid);
    const QColor c4 = palette().color(QPalette::Light);

    int x1 = x;
    int x2 = x+w-1;
    int y1 = y;
    int y2 = y+h-1;
    int d = 0;
    y1 = y1 + w/2;
    d =  (w + 1) / 2 - 1;

    QPolygon a;
    a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d);

    QBrush oldBrush = p->brush();
    p->setBrush(palette().button());
    p->setPen(Qt::NoPen);
    p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
    p->drawPolygon(a);
    p->setBrush(oldBrush);

    p->setPen(c3);
    p->drawLine(x1+1, y1+1, x1+1, y2);
    p->setPen(c4);
    p->drawLine(x1, y1, x1, y2);
    p->setPen(c0);
    p->drawLine( x2, y1, x2, y2);
    p->setPen(c1);
    p->drawLine( x2-1, y1+1, x2-1, y2-1);
    p->setPen(c0);
    p->drawLine(x1, y2, x2, y2);
    p->setPen(c1);
    p->drawLine(x1+1, y2-1, x2-1, y2-1);
    p->setPen(c4);
    p->drawLine(x1, y1, x1+d, y1-d);
    p->setPen(c0);
    d = w - d - 1;
    p->drawLine(x2, y1, x2-d, y1-d);
    --d;
    p->setPen(c3);
    p->drawLine(x1+1, y1, x1+1+d, y1-d);
    p->setPen(c1);
    p->drawLine(x2-1, y1, x2-1-d, y1-d);
}
コード例 #17
0
ファイル: gaugecompass.cpp プロジェクト: nameqiaohe/quc
void GaugeCompass::drawPointer(QPainter *painter)
{
    int radius = 75;

    QPolygon pts;

    painter->save();
    painter->setOpacity(0.7);
    painter->setPen(Qt::NoPen);
    painter->setBrush(northPointerColor);
    pts.setPoints(3, -10, 0, 10, 0, 0, radius);
    painter->rotate(currentValue + 180);
    painter->drawConvexPolygon(pts);
    painter->restore();

    painter->save();
    painter->setOpacity(0.7);
    painter->setPen(Qt::NoPen);
    painter->setBrush(southPointerColor);
    pts.setPoints(3, -10, 0, 10, 0, 0, radius);
    painter->rotate(currentValue);
    painter->drawConvexPolygon(pts);
    painter->restore();
}
コード例 #18
0
/* Recreate mini-toolbar mask */
void VBoxMiniToolBar::recreateMask()
{
    int iEdgeShift = height();
    int iPoints[8];
    switch (m_alignment)
    {
        case AlignTop:
        {
            iPoints[0] = 0;
            iPoints[1] = 0;

            iPoints[2] = iEdgeShift;
            iPoints[3] = height();

            iPoints[4] = width() - iEdgeShift;
            iPoints[5] = height();

            iPoints[6] = width();
            iPoints[7] = 0;

            break;
        }
        case AlignBottom:
        {
            iPoints[0] = iEdgeShift;
            iPoints[1] = 0;

            iPoints[2] = 0;
            iPoints[3] = height();

            iPoints[4] = width();
            iPoints[5] = height();

            iPoints[6] = width() - iEdgeShift;
            iPoints[7] = 0;

            break;
        }
        default:
            break;
    }
    /* Make sure any old mask is removed first: */
    clearMask();
    /* Set the new mask */
    QPolygon polygon;
    polygon.setPoints(4, iPoints);
    setMask(polygon);
}
コード例 #19
0
void GradientPreview::paintEvent(QPaintEvent *e)
{
	QList<VColorStop*> cstops = fill_gradient.colorStops();
	StopM.clear();
	for (uint a = 0; a < fill_gradient.Stops(); ++a)
	{
		int center = qRound(cstops.at(a)->rampPoint * (width()-20))+10;
		StopM.append(center);
	}
	QImage pixm(width()-20, 37, QImage::Format_ARGB32_Premultiplied);
	QPainter pb;
	QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
	pb.begin(&pixm);
	pb.fillRect(0, 0, pixm.width(), pixm.height(), b);
	pb.end();
	ScPainter *p = new ScPainter(&pixm, width()-20, 37);
//	p->clear(Qt::white);
	p->setPen(Qt::black);
	p->setLineWidth(1);
	p->setFillMode(2);
	p->fill_gradient = fill_gradient;
	p->setGradient(VGradient::linear, FPoint(0,20), FPoint(width()-20,20), FPoint(0, 0), 1.0, 0.0);
	p->drawRect(0, 0, width()-20, 37);
	p->end();
	delete p;
	QPainter pw;
	pw.begin(this);
	pw.drawImage(10, 5, pixm);
	if (isEditable)
	{
		for (uint a = 0; a < fill_gradient.Stops(); ++a)
		{
			int center = qRound(cstops.at(a)->rampPoint * (width()-20))+10;
			pw.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
			if (StopM[qMax(ActStop,0)] == center)
				pw.setBrush(Qt::red);
			else
				pw.setBrush(Qt::blue);
			QPolygon cr;
			cr.setPoints(3, qRound(center), 43, qRound(center-4), 56, qRound(center+4), 56);
			pw.drawPolygon(cr);
		}
	}
	pw.end();
	QFrame::paintEvent(e);
}
コード例 #20
0
ファイル: BoardWidget.cpp プロジェクト: weidendo/qenolaba
/* draw field */
void BoardWidget::drawBoard()
{
    boardPM = QPixmap(width(), height());
    boardPM.fill(*boardColor);

    QPainter p(&boardPM);

    p.setRenderHint(QPainter::Antialiasing);

    QPalette pal( *boardColor );
    QPalette pal2 = QWidget::palette();

    int boardSize = width() *10/12;
    if (boardSize > height()) boardSize = height();

    QMatrix m;
    QPoint cp = rect().center();
    m.translate(cp.x(), cp.y());
    m.scale(boardSize/1100.0, boardSize/1000.0);
    m.rotate(0);

    p.setMatrix(m);
    p.setBrush(pal2.brush(QPalette::Mid));

    QPolygon a;
    int dx=520 /2, dy=(520 *87)/100;
    a.setPoints(6, -dx,-dy, dx,-dy, 2*dx,0, dx,dy, -dx,dy, -2*dx,0 );
    p.drawPolygon(a);

    drawShadedHexagon(&p, 0,0, 505, 1, pal, false);
    drawShadedHexagon(&p, 0,0, 512, 3, pal, true);
    drawShadedHexagon(&p, 0,0, 525, 5, pal2, true);

#define xpos(i,j) (495*(2*(i)-(j))/9)
#define ypos(j)   (500*19*(j)/100)

    int i,j;
    for(j=-4;j<5;j++)
	for(i= ((j>0)?j-4:-4) ; i< ((j<0)?5+j:5) ;i++) {
	    int x=xpos(i,j);
	    int y=ypos(j);

	    drawShadedHexagon(&p, x,y, 50, 2, pal, true);
	    drawShadedHexagon(&p, x,y, 30, 1, pal, false);
	}
}
コード例 #21
0
void
QvisKeyframeDrawer::drawTimeHandle(QPainter *p, const QRect &r, int ci, bool active)
{
    // Draw the background.
    drawBackground(p, r);

    if(currentIndex >= 0)
    {
        p->setBrush(QBrush(active ? kfHandleH : kfHandle));
        p->setPen(kfHandle);
        int x = getX(ci);
        int y = rect.top();
        QPolygon a;
        a.setPoints(3, x, y+8, x-8, y, x+8, y);
        p->drawPolygon(a);
    }
}
コード例 #22
0
ファイル: wizard.cpp プロジェクト: CBApplications/doxygen
void ColorPicker::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 (!m_pix || m_pix->height() != hi || m_pix->width() != wi) 
  {
    delete m_pix;
    QImage img(wi, hi, QImage::Format_RGB32);
    int y;
    uint *pixel = (uint *) img.scanLine(0);
    for (y = 0; y < hi; y++) 
    {
      const uint *end = pixel + wi;
      int yh = y2hue(y+coff);
      int ys = y2sat(y+coff);
      int yg = y2gam(y+coff);
      while (pixel < end) 
      {
        QColor c;
        c.setHsv(yh, ys, (int)(255*pow(0.7,yg/100.0)));
        *pixel = c.rgb();
        ++pixel;
      }
    }
    m_pix = new QPixmap(QPixmap::fromImage(img));
  }
  QPainter p(this);
  p.drawPixmap(1, coff, *m_pix);
  const QPalette &g = palette();
  qDrawShadePanel(&p, r, g, true);
  p.setPen(g.foreground().color());
  p.setBrush(g.foreground());
  QPolygon a;
  int y = m_mode==Hue ?        hue2y(m_hue) : 
          m_mode==Saturation ? sat2y(m_sat) :
                               gam2y(m_gam);
  a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
  p.eraseRect(w, 0, 5, height());
  p.drawPolygon(a);
}
コード例 #23
0
ファイル: playimgthread.cpp プロジェクト: ntuhubin/MatouDemo
void PlayImgThread::run()
{
    QPolygon pts;
    pts.setPoints(4, 856,400, 1046,400,1080,900,840,900);
    QList<QString>::const_iterator it = imgpathlist.begin();
    while(it != imgpathlist.end())
    {
        QString str = "./img/" + *it;
        QImage img = QImage(str);
        if(!img.isNull())
        {
            QPainter painter(&img);
            painter.setPen(QPen(Qt::blue, 4, Qt::DashLine));
            painter.drawConvexPolygon(pts);
            //painter.drawRect(856,400,200, 500);
            emit message(img);
        }
        it++;
        msleep(100);
    }
}
コード例 #24
0
void ColorLuminancePicker::paintEvent(QPaintEvent* /*event*/) {
    int w = width() - 5;

    QRect r(0, foff, w, height() - 2*foff);
    int wi = r.width() - 2;
    int hi = r.height() - 2;
    if (wi <= 1 || hi <= 1)
        return;
    if ((pix_ == 0) || (pix_->height() != hi) || (pix_->width() != wi)) {
        if (!pix_)
            delete pix_;
        QImage img(wi, hi, QImage::Format_RGB32);
        for (int y = 0 ; y < hi ; ++y) {
            QColor c;
            c.setHsv(hue_, sat_, y2val(y+coff));
            QRgb r = c.rgb();
            for (int x = 0 ; x < wi ; ++x)
                img.setPixel(x, y, r);
        }
        pix_ = new QPixmap(QPixmap::fromImage(img));
    }
    // color bar
    QPainter p(this);
    p.drawPixmap(1, coff, *pix_);
    const QPalette &g = palette();
    qDrawShadePanel(&p, r, g, true);
    p.setPen(g.foreground().color());
    p.setBrush(g.foreground());

    // arrow
    QPolygon a;
    int y = val2y(val_);
    a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
    p.eraseRect(w, 0, 5, height());
    p.drawPolygon(a);
}
コード例 #25
0
void YviColorLuminancePicker::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 (!pix || pix->height() != hi || pix->width() != wi) {
        delete pix;
        QImage img(wi, hi, QImage::Format_RGB32);
        int y;
        uint *pixel = (uint *) img.scanLine(0);
        for (y = 0; y < hi; y++) {
            const uint *end = pixel + wi;
            while (pixel < end) {
                QColor c;
                c.setHsv(hue, sat, y2val(y+coff));
                *pixel = c.rgb();
                ++pixel;
            }
        }
        pix = new QPixmap(QPixmap::fromImage(img));
    }
    QPainter p(this);
    p.drawPixmap(1, coff, *pix);
    const QPalette &g = palette();
    qDrawShadePanel(&p, r, g, true);
    p.setPen(g.foreground().color());
    p.setBrush(g.foreground());

    QPolygon a;
    int y = val2y(val);
    a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
    p.eraseRect(w, 0, 5, height());
    p.drawPolygon(a);
}
コード例 #26
0
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                   QPainter *painter, const QWidget *widget) const {
    if (!panelWidget(widget))
        return d->style->drawPrimitive(element, option, painter, widget);

    bool animating = (option->state & State_Animating);
    int state = option->state;
    QRect rect = option->rect;
    QRect oldRect;
    QRect newRect;
    if (widget && (element == PE_PanelButtonTool) && !animating) {
        QWidget *w = const_cast<QWidget *> (widget);
        int oldState = w->property("_q_stylestate").toInt();
        oldRect = w->property("_q_stylerect").toRect();
        newRect = w->rect();
        w->setProperty("_q_stylestate", (int)option->state);
        w->setProperty("_q_stylerect", w->rect());

        // Determine the animated transition
        bool doTransition = ((state & State_On)         != (oldState & State_On)     ||
                             (state & State_MouseOver)  != (oldState & State_MouseOver));
        if (oldRect != newRect) {
            doTransition = false;
            d->animator.stopAnimation(widget);
        }

        if (doTransition) {
            QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            Animation *anim = d->animator.widgetAnimation(widget);
            QStyleOption opt = *option;
            opt.state = (QStyle::State)oldState;
            opt.state |= (State)State_Animating;
            startImage.fill(0);
            Transition *t = new Transition;
            t->setWidget(w);
            QPainter startPainter(&startImage);
            if (!anim) {
                drawPrimitive(element, &opt, &startPainter, widget);
            } else {
                anim->paint(&startPainter, &opt);
                d->animator.stopAnimation(widget);
            }
            QStyleOption endOpt = *option;
            endOpt.state |= (State)State_Animating;
            t->setStartImage(startImage);
            d->animator.startAnimation(t);
            endImage.fill(0);
            QPainter endPainter(&endImage);
            drawPrimitive(element, &endOpt, &endPainter, widget);
            t->setEndImage(endImage);
            t->setDuration(130);
            t->setStartTime(QTime::currentTime());
        }
    }

    switch (element) {
    case PE_PanelLineEdit: {
        painter->save();
        if (option->state & State_Enabled)
            drawCornerImage(d->lineeditImage, painter, option->rect, 2, 2, 2, 2);
        else
            drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 2, 2, 2, 2);

        if (option->state & State_HasFocus || option->state & State_MouseOver) {
            QColor hover = StyleHelper::baseColor();
            if (state & State_HasFocus)
                hover.setAlpha(100);
            else
                hover.setAlpha(50);

            painter->setPen(QPen(hover, 1));
            painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2));
        }
        painter->restore();
    }
    break;

    case PE_FrameStatusBarItem:
        break;

    case PE_PanelButtonTool: {
        Animation *anim = d->animator.widgetAnimation(widget);
        if (!animating && anim) {
            anim->paint(painter, option);
        } else {
            bool pressed = option->state & State_Sunken || option->state & State_On;
            QColor shadow(0, 0, 0, 30);
            painter->setPen(shadow);
            if (pressed) {
                QColor shade(0, 0, 0, 40);
                painter->fillRect(rect, shade);
                painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0));
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
                painter->drawLine(rect.topRight(), rect.bottomRight());
                // painter->drawLine(rect.bottomLeft()  + QPoint(1, 0), rect.bottomRight()  - QPoint(1, 0));
                QColor highlight(255, 255, 255, 30);
                painter->setPen(highlight);
            } else if (option->state & State_Enabled &&
                       option->state & State_MouseOver) {
                QColor lighter(255, 255, 255, 37);
                painter->fillRect(rect, lighter);
            }
        }
    }
    break;

    case PE_PanelStatusBar: {
        painter->save();
        QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom()));
        QColor startColor = StyleHelper::shadowColor().darker(164);
        QColor endColor = StyleHelper::baseColor().darker(130);
        grad.setColorAt(0, endColor);
        grad.setColorAt(1, endColor);
        painter->fillRect(option->rect, grad);
        painter->setPen(QColor(255, 255, 255, 60));
        painter->drawLine(rect.topLeft() + QPoint(0,1),
                          rect.topRight()+ QPoint(0,1));
        painter->setPen(StyleHelper::borderColor().darker(110));
        painter->drawLine(rect.topLeft(), rect.topRight());
        painter->restore();
    }
    break;

    case PE_IndicatorToolBarSeparator: {
        QColor separatorColor = StyleHelper::borderColor();
        separatorColor.setAlpha(100);
        painter->setPen(separatorColor);
        const int margin = 3;
        if (option->state & State_Horizontal) {
            const int offset = rect.width()/2;
            painter->drawLine(rect.bottomLeft().x() + offset,
                              rect.bottomLeft().y() - margin,
                              rect.topLeft().x() + offset,
                              rect.topLeft().y() + margin);
        } else { //Draw vertical separator
            const int offset = rect.height()/2;
            painter->setPen(QPen(option->palette.background().color().darker(110)));
            painter->drawLine(rect.topLeft().x() + margin ,
                              rect.topLeft().y() + offset,
                              rect.topRight().x() - margin,
                              rect.topRight().y() + offset);
        }
    }
    break;

    case PE_IndicatorToolBarHandle: {
        bool horizontal = option->state & State_Horizontal;
        painter->save();
        QPainterPath path;
        int x = option->rect.x() + horizontal ? 2 : 6;
        int y = option->rect.y() + horizontal ? 6 : 2;
        static const int RectHeight = 2;
        if (horizontal) {
            while (y < option->rect.height() - RectHeight - 6) {
                path.moveTo(x, y);
                path.addRect(x, y, RectHeight, RectHeight);
                y += 6;
            }
        } else {
            while (x < option->rect.width() - RectHeight - 6) {
                path.moveTo(x, y);
                path.addRect(x, y, RectHeight, RectHeight);
                x += 6;
            }
        }

        painter->setPen(Qt::NoPen);
        QColor dark = StyleHelper::borderColor();
        dark.setAlphaF(0.4);

        QColor light = StyleHelper::baseColor();
        light.setAlphaF(0.4);

        painter->fillPath(path, light);
        painter->save();
        painter->translate(1, 1);
        painter->fillPath(path, dark);
        painter->restore();
        painter->translate(3, 3);
        painter->fillPath(path, light);
        painter->translate(1, 1);
        painter->fillPath(path, dark);
        painter->restore();
    }
    break;
    case PE_IndicatorArrowUp:
    case PE_IndicatorArrowDown:
    case PE_IndicatorArrowRight:
    case PE_IndicatorArrowLeft: {
        // From windowsstyle but modified to enable AA
        if (option->rect.width() <= 1 || option->rect.height() <= 1)
            break;

        QRect r = option->rect;
        int size = qMin(r.height(), r.width());
        QPixmap pixmap;
        QString pixmapName;
        pixmapName.sprintf("%s-%s-%d-%d-%d-%lld",
                           "$qt_ia", metaObject()->className(),
                           uint(option->state), element,
                           size, option->palette.cacheKey());
        if (!QPixmapCache::find(pixmapName, pixmap)) {
            int border = size/5;
            int sqsize = 2*(size/2);
            QImage image(sqsize, sqsize, QImage::Format_ARGB32);
            image.fill(Qt::transparent);
            QPainter imagePainter(&image);
            imagePainter.setRenderHint(QPainter::Antialiasing, true);
            imagePainter.translate(0.5, 0.5);
            QPolygon a;
            switch (element) {
            case PE_IndicatorArrowUp:
                a.setPoints(3, border, sqsize/2,  sqsize/2, border,  sqsize - border, sqsize/2);
                break;
            case PE_IndicatorArrowDown:
                a.setPoints(3, border, sqsize/2,  sqsize/2, sqsize - border,  sqsize - border, sqsize/2);
                break;
            case PE_IndicatorArrowRight:
                a.setPoints(3, sqsize - border, sqsize/2,  sqsize/2, border,  sqsize/2, sqsize - border);
                break;
            case PE_IndicatorArrowLeft:
                a.setPoints(3, border, sqsize/2,  sqsize/2, border,  sqsize/2, sqsize - border);
                break;
            default:
                break;
            }

            int bsx = 0;
            int bsy = 0;

            if (option->state & State_Sunken) {
                bsx = pixelMetric(PM_ButtonShiftHorizontal);
                bsy = pixelMetric(PM_ButtonShiftVertical);
            }

            QRect bounds = a.boundingRect();
            int sx = sqsize / 2 - bounds.center().x() - 1;
            int sy = sqsize / 2 - bounds.center().y() - 1;
            imagePainter.translate(sx + bsx, sy + bsy);

            if (!(option->state & State_Enabled)) {
                QColor foreGround(150, 150, 150, 150);
                imagePainter.setBrush(option->palette.mid().color());
                imagePainter.setPen(option->palette.mid().color());
            } else {
                QColor shadow(0, 0, 0, 100);
                imagePainter.translate(0, 1);
                imagePainter.setPen(shadow);
                imagePainter.setBrush(shadow);
                QColor foreGround(255, 255, 255, 210);
                imagePainter.drawPolygon(a);
                imagePainter.translate(0, -1);
                imagePainter.setPen(foreGround);
                imagePainter.setBrush(foreGround);
            }
            imagePainter.drawPolygon(a);
            imagePainter.end();
            pixmap = QPixmap::fromImage(image);
            QPixmapCache::insert(pixmapName, pixmap);
        }
        int xOffset = r.x() + (r.width() - size)/2;
        int yOffset = r.y() + (r.height() - size)/2;
        painter->drawPixmap(xOffset, yOffset, pixmap);
    }
    break;

    default:
        d->style->drawPrimitive(element, option, painter, widget);
        break;
    }
}
コード例 #27
0
ファイル: stylehelper.cpp プロジェクト: Pritoj/tomahawk
/*
 * This implementation is from QWindowsStyle (Qt 7.2)
 *
 * It is licensed under the GPL 3:
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * Contact: Nokia Corporation ([email protected])
 */
void StyleHelper::drawArrow( QStyle::PrimitiveElement element, QPainter* p, const QStyleOption* opt )
{
    if ( opt->rect.width() <= 1 || opt->rect.height() <= 1 )
        return;

    QRect r = opt->rect;
    int size = qMin( r.height(), r.width() );
    QPixmap pixmap;
    QString pixmapName;

    pixmapName.sprintf( "arrow-%s-%d-%d-%d-%lld", "$qt_ia", uint(opt->state), element, size, opt->palette.cacheKey() );
    if ( !QPixmapCache::find( pixmapName, pixmap) )
    {
        int border = size / 5;
        int sqsize = 2 * ( size / 2 );

        QImage image( sqsize, sqsize, QImage::Format_ARGB32 );
        image.fill( 0 );
        QPainter imagePainter( &image );
        imagePainter.setRenderHint( QPainter::Antialiasing, true );
        QPolygon a;

        switch ( element )
        {
            case QStyle::PE_IndicatorArrowUp:
                a.setPoints( 3, border, sqsize / 2, sqsize / 2, border, sqsize - border, sqsize / 2 );
                break;

            case QStyle::PE_IndicatorArrowDown:
                a.setPoints( 3, border, sqsize / 2, sqsize / 2, sqsize - border,  sqsize - border, sqsize / 2 );
                break;

            case QStyle::PE_IndicatorArrowRight:
                a.setPoints( 3, sqsize - border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border );
                break;

            case QStyle::PE_IndicatorArrowLeft:
                a.setPoints( 3, border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border );
                break;

            default:
                break;
        }

        int bsx = 0;
        int bsy = 0;

        if ( opt->state & QStyle::State_Sunken )
        {
            bsx = qApp->style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal );
            bsy = qApp->style()->pixelMetric( QStyle::PM_ButtonShiftVertical );
        }

        QRect bounds = a.boundingRect();
        int sx = sqsize / 2 - bounds.center().x() - 1;
        int sy = sqsize / 2 - bounds.center().y() - 1;
        imagePainter.translate( sx + bsx, sy + bsy );
        imagePainter.setPen( opt->palette.buttonText().color() );
        imagePainter.setBrush( opt->palette.buttonText() );

        if ( !( opt->state & QStyle::State_Enabled ) )
        {
            QColor foreGround( 150, 150, 150, 150 );
            imagePainter.setBrush( opt->palette.mid().color() );
            imagePainter.setPen( opt->palette.mid().color() );
        }
        else
        {
            QColor shadow( 0, 0, 0, 100 );
            imagePainter.translate( 0, 1 );
            imagePainter.setPen( shadow );
            imagePainter.setBrush( shadow );
            QColor foreGround( 255, 255, 255, 210 );
            imagePainter.drawPolygon( a );
            imagePainter.translate( 0, -1 );
            imagePainter.setPen( foreGround );
            imagePainter.setBrush( foreGround );
        }

        imagePainter.drawPolygon( a );
        imagePainter.end();

        pixmap = QPixmap::fromImage( image );
        QPixmapCache::insert( pixmapName, pixmap );
    }

    int xOffset = r.x() + ( r.width() - size ) / 2;
    int yOffset = r.y() + ( r.height() - size ) / 2;
    p->drawPixmap( xOffset, yOffset, pixmap );
}
コード例 #28
0
//Returns the average normal of the 10 times 10 grid based on the normals
//image which is calculated from the ground truth in the calibration step
// x and y are in PSCam cord system
QTransform PSTouch::getUiTransformation(int x, int y){

  qDebug() << "calc normal trans for x:  " << x << "y:" << y;

    //int i = x-5;
    //int j = y-5;
    //int count = 0;
    cv::Vec3f normal(0,0,0);

    //if(x < 5 ) i = 0;
    if(x > 630) x = 630;
    //if(y < 5 ) y = 0;
    if(y > 470) y = 470;
    //int jtmp = j;
    for(int i = x; i<x+10; i++){
        for(int j = y; j<y+10; j++){
            normal  += normals->at<cv::Vec3f>(j,i);
        }
    }
    //cv::imshow("bam",*normals);
    normal = normal/cv::norm(normal);
    std::cout << "avg normal: " << normal<< std::endl;

    //Normal is Z
    // TODO (MAYBE) adapt z to orientation of cam system!
    cv::Vec3f zVec(0,0,1);

    //transform this to projector

    cv::Vec3f projectorNormal = transform->transformVectorfromCamtoProjector(normal);
    cv::Vec3f xVec = normal.cross(zVec);
    cv::Vec3f yVec = normal.cross(xVec);

    qDebug()<< normal[0] <<" "<<normal[1]<<" "<<normal[2] << "\n and \n"
                        << projectorNormal[0] << " " << projectorNormal[1] << " "<< projectorNormal[2] ;

    float xn = projectorNormal[0];
    float yn = projectorNormal[1];
    float zn = projectorNormal[2];

    float xrad = asin(xn);
    float yrad = asin(yn);
    float zrad = asin(zn);

    float xAngle = xrad * 180.0/PI;
    float yAngle = yrad * 180.0/PI;
    float zAngle = zrad * 180.0/PI;

    qDebug() << "xANGLE: " << xAngle;
    qDebug() << "yANGLE: " << yAngle;
    qDebug() << "zANGLE: " << zAngle;

    // Normalize
    xVec = xVec/cv::norm(xVec);
    yVec = yVec/cv::norm(yVec);


            if(xVec[0]<0){
                qDebug("Filp X");
                xVec = xVec *(-1);
            }

            if(yVec[1]>0){
                qDebug("Filp Y");
                yVec = yVec * (-1);
            }

       qDebug() << "xVec: " << xVec[0] << " "<< xVec[1] << " "<< xVec[2];
       qDebug() << "yVec: " << yVec[0] << " "<< yVec[1] << " "<< yVec[2];

       //Let xVec Point exactly down !
       float lamda = -xVec[1]/yVec[1];
       qDebug()<< "lamda: " << lamda;

       float lamda2 = -yVec[0]/xVec[0];

       cv::Vec3f tmp  = xVec + lamda*yVec;

       yVec = yVec + lamda2*xVec;
       xVec = tmp;
       xVec = xVec/cv::norm(xVec);
       yVec = yVec/cv::norm(yVec);

       qDebug() << "RESULT: \nxVec: " << xVec[0] << " "<< xVec[1] << " "<< xVec[2];

       qDebug() << "yVec: " << yVec[0] << " "<< yVec[1] << " "<< yVec[2];


       short depthTmp = groundTruth->at<openni::DepthPixel>(y,x);
       qDebug() << "depth" << depthTmp;
       cv::Vec3f pV(x,y,(float)depthTmp);

    // transform pV (in from cam in World (pixel)
    cv::Vec3f worldPoint = transform->transformPointFromCamToWorld(pV);
//    qDebug() << "CamPoint" << pV[0] << " "<< pV[1] << " "<< pV[2];
//    qDebug() <<"worldPoint" << worldPoint[0] << " "<< worldPoint[1] << " "<< worldPoint[2];


    // fixing Vector orientation:

    if(std::abs(xVec[0])<std::abs(yVec[0])){
        qDebug("FLIP VECTORS");
        cv::Vec3f tmp(xVec);
        xVec = yVec;
        yVec = tmp;
    }

    if (xVec[0] < 0){
        xVec = -1 * xVec;
    }

    if(yVec[1] > 0 ){
        yVec = -1 * yVec;
    }


//    qDebug() << "WORKING WITH: ";
//    qDebug() << "xVec: " << xVec[0] << " "<< xVec[1] << " "<< xVec[2];
//    qDebug() << "yVec: " << yVec[0] << " "<< yVec[1] << " "<< yVec[2];


    // Create Trasnformation
    //
    cv::Point2i p0 = transform->transformWorldPointToProjector(worldPoint);
    cv::Point2i p1 = transform->transformWorldPointToProjector(worldPoint + 400* xVec);
    cv::Point2i p2 = transform->transformWorldPointToProjector(worldPoint + 400* xVec - 400* yVec);
    cv::Point2i p3 = transform->transformWorldPointToProjector(worldPoint - 400* yVec);

        QPolygon base;
        base.setPoints(4, 0,0, 100,0, 100,100, 0,100);

        QPolygon world;
        world.setPoints(4, p0.x,p0.y, p1.x,p1.y, p2.x,p2.y, p3.x,p3.y);

        QTransform transformation;
        bool success = false;
        success = QTransform::quadToQuad(base, world, transformation);

        if(!success)
            qDebug("ERROR: Transformation could not be calculated");

    return transformation;
}
コード例 #29
0
ファイル: qdrawutil.cpp プロジェクト: crobertd/qtbase
QT_BEGIN_NAMESPACE

/*!
    \headerfile <qdrawutil.h>
    \title Drawing Utility Functions

    \sa QPainter
*/

/*!
    \fn void qDrawShadeLine(QPainter *painter, int x1, int y1, int x2, int y2,
                     const QPalette &palette, bool sunken,
                     int lineWidth, int midLineWidth)
    \relates <qdrawutil.h>

    Draws a horizontal (\a y1 == \a y2) or vertical (\a x1 == \a x2)
    shaded line using the given \a painter.  Note that nothing is
    drawn if \a y1 != \a y2 and \a x1 != \a x2 (i.e. the line is
    neither horizontal nor vertical).

    The provided \a palette specifies the shading colors (\l
    {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l
    {QPalette::mid()}{middle} colors).  The given \a lineWidth
    specifies the line width for each of the lines; it is not the
    total line width. The given \a midLineWidth specifies the width of
    a middle line drawn in the QPalette::mid() color.

    The line appears sunken if \a sunken is true, otherwise raised.

    \warning This function does not look at QWidget::style() or
    QApplication::style().  Use the drawing functions in QStyle to
    make widgets that follow the current GUI style.


    Alternatively you can use a QFrame widget and apply the
    QFrame::setFrameStyle() function to display a shaded line:

    \snippet code/src_gui_painting_qdrawutil.cpp 0

    \sa qDrawShadeRect(), qDrawShadePanel(), QStyle
*/

void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2,
                     const QPalette &pal, bool sunken,
                     int lineWidth, int midLineWidth)
{
    if (!(p && lineWidth >= 0 && midLineWidth >= 0))        {
        qWarning("qDrawShadeLine: Invalid parameters");
        return;
    }
    int tlw = lineWidth*2 + midLineWidth;        // total line width
    QPen oldPen = p->pen();                        // save pen
    if (sunken)
        p->setPen(pal.color(QPalette::Dark));
    else
        p->setPen(pal.light().color());
    QPolygon a;
    int i;
    if (y1 == y2) {                                // horizontal line
        int y = y1 - tlw/2;
        if (x1 > x2) {                        // swap x1 and x2
            int t = x1;
            x1 = x2;
            x2 = t;
        }
        x2--;
        for (i=0; i<lineWidth; i++) {                // draw top shadow
            a.setPoints(3, x1+i, y+tlw-1-i,
                         x1+i, y+i,
                         x2-i, y+i);
            p->drawPolyline(a);
        }
        if (midLineWidth > 0) {
            p->setPen(pal.mid().color());
            for (i=0; i<midLineWidth; i++)        // draw lines in the middle
                p->drawLine(x1+lineWidth, y+lineWidth+i,
                             x2-lineWidth, y+lineWidth+i);
        }
        if (sunken)
            p->setPen(pal.light().color());
        else
            p->setPen(pal.dark().color());
        for (i=0; i<lineWidth; i++) {                // draw bottom shadow
            a.setPoints(3, x1+i, y+tlw-i-1,
                         x2-i, y+tlw-i-1,
                         x2-i, y+i+1);
            p->drawPolyline(a);
        }
    }
    else if (x1 == x2) {                        // vertical line
        int x = x1 - tlw/2;
        if (y1 > y2) {                        // swap y1 and y2
            int t = y1;
            y1 = y2;
            y2 = t;
        }
        y2--;
        for (i=0; i<lineWidth; i++) {                // draw left shadow
            a.setPoints(3, x+i, y2,
                         x+i, y1+i,
                         x+tlw-1, y1+i);
            p->drawPolyline(a);
        }
        if (midLineWidth > 0) {
            p->setPen(pal.mid().color());
            for (i=0; i<midLineWidth; i++)        // draw lines in the middle
                p->drawLine(x+lineWidth+i, y1+lineWidth, x+lineWidth+i, y2);
        }
        if (sunken)
            p->setPen(pal.light().color());
        else
            p->setPen(pal.dark().color());
        for (i=0; i<lineWidth; i++) {                // draw right shadow
            a.setPoints(3, x+lineWidth, y2-i,
                         x+tlw-i-1, y2-i,
                         x+tlw-i-1, y1+lineWidth);
            p->drawPolyline(a);
        }
    }
    p->setPen(oldPen);
}
コード例 #30
0
void RulerT::paintEvent(QPaintEvent *)
{
	double xl;
	QPainter p;
	p.begin(this);
	p.drawLine(0, 24, width(), 24);
	p.translate(-offset, 0);
	p.setBrush(Qt::black);
	p.setFont(font());
	p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
	for (xl = 0; xl < width()+offset; xl += iter)
	{
		if (xl < offset)
			continue;
		p.drawLine(qRound(xl), 18, qRound(xl), 24);
	}
	for (xl = 0; xl < width()+(iter2/2)+offset; xl += iter2)
	{
		if (xl < offset)
			continue;
		p.drawLine(qRound(xl), 11, qRound(xl), 24);
		switch (unitIndex)
		{
			case 2:
			{
				QString tx = "";
				int num1 = static_cast<int>(xl / iter2);
				if (num1 != 0)
					tx = QString::number(num1);
				double frac = (xl / iter2) - num1;
				if ((frac > 0.24) && (frac < 0.26))
					tx += QChar(0xBC);
				if ((frac > 0.49) && (frac < 0.51))
					tx += QChar(0xBD);
				if ((frac > 0.74) && (frac < 0.76))
					tx += QChar(0xBE);
				p.drawText(qRound(xl+2), 17, tx);
				break;
			}
			case 3:
				p.drawText(qRound(xl+2), 17, QString::number(xl / iter));
				break;
			default:
				p.drawText(qRound(xl+2), 17, QString::number(xl / iter * 10));
				break;
		}
	}
	if (tabValues.count() != 0)
	{
		for (int yg = 0; yg < static_cast<int>(tabValues.count()); yg++)
		{
			if (yg == actTab)
				p.setPen(QPen(Qt::red, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
			else
				p.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
			switch (static_cast<int>(tabValues[yg].tabType))
			{
				case 0:
					p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
					p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition+8), 23);
					break;
				case 1:
					p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
					p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition-8), 23);
					break;
				case 2:
				case 3:
					p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
					p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23);
					p.drawLine(qRound(tabValues[yg].tabPosition+3), 20, qRound(tabValues[yg].tabPosition+2), 20);
					break;
				case 4:
					p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
					p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23);
					break;
				default:
					break;
			}
		}
	}
	if (haveInd)
	{
		p.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
		p.setBrush(Qt::blue);
		QPolygon cr;
		cr.setPoints(3, qRound(firstLine+leftIndent), 12, qRound(firstLine+leftIndent-4), 0, qRound(firstLine+leftIndent+4), 0);
		p.drawPolygon(cr);
		QPolygon cr2;
		cr2.setPoints(3, qRound(leftIndent), 12, qRound(leftIndent+4), 24, qRound(leftIndent-4), 24);
		p.drawPolygon(cr2);
	}
	p.end();
}