Exemple #1
0
void EditorArea::paintMeshElToBeHigh(QPainter &painter)
{
    qreal radius = size2screen(8);
    float fontSize = size2screen(12);

    qreal width = radius * 2;
    qreal height = radius * 2;

    QPainterPath path;
    QPainterPath text;
    QPainterPath circle;

    path.arcTo(QRectF(-radius, -radius, width, height), 0, 360);
    text.addText(-radius / 2.0, radius / 2.0, QFont("Arial", fontSize), meshElsType.value(meshElToBeHigh));
    circle.arcTo(QRectF(-radius * 3 / 2, -radius * 3 / 2, width * 3 / 2, height * 3 / 2), 0, 360);
    path.translate(meshElsPos.value(meshElToBeHigh));
    text.translate(meshElsPos.value(meshElToBeHigh));
    circle.translate(meshElsPos.value(meshElToBeHigh));

    painter.setPen(Qt::NoPen);
    painter.setBrush(Qt::magenta);
    painter.drawPath(circle);
    painter.setBrush(Qt::darkCyan);
    painter.drawPath(path);
    painter.setPen(Qt::yellow);
    painter.setBrush(Qt::yellow);
    painter.drawPath(text);
}
Exemple #2
0
void Widget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter;
    QPainterPath path;
    QPen pen(Qt::darkGray);
    painter.begin(this);
    pen.setWidth(3);
    pen.setCapStyle(Qt::RoundCap);
    pen.setJoinStyle(Qt::RoundJoin);
    painter.setBrush(Qt::darkGray);
    painter.drawRect(ui->crossBlock->x(),ui->crossBlock->y(),ui->crossBlock->width(),ui->crossBlock->height());
    pen.setColor(Qt::black);
    painter.setPen(pen);
    painter.drawLine(ui->crossBlock->x()+1,ui->crossBlock->y()+1,ui->crossBlock->x()+ui->crossBlock->width(),ui->crossBlock->y()+ui->crossBlock->height());
    painter.drawLine(ui->crossBlock->x()+1,ui->crossBlock->y()+ui->crossBlock->height(),ui->crossBlock->x()+ui->crossBlock->width(),ui->crossBlock->y()+1);
    pen.setColor(Qt::yellow);
    painter.setPen(pen);
    int mca_x = ui->mcaImage->x();
    int mca_y = ui->mcaImage->y();
    int mcb_x = ui->mcbImage->x();
    int mcb_y = ui->mcbImage->y();
    int mc_width = ui->mcaImage->width();
    int mc_height = ui->mcaImage->height();
    painter.setBrush(Qt::NoBrush);
//    painter.drawRoundedRect(mca_x,mca_y,mc_width,mc_height,5,5);
//    painter.drawRoundedRect(mcb_x,mcb_y,mc_width,mc_height,5,5);
    painter.drawRect(mca_x,mca_y,mc_width,mc_height);
    painter.drawRect(mcb_x,mcb_y,mc_width,mc_height);
//    painter.setPen(Qt::NoPen);
    painter.setBrush(Qt::NoBrush);
    painter.eraseRect(mca_x-5,mca_y-5,mc_width*0.1,mc_height*1.2);
    painter.eraseRect(mcb_x+mc_width*0.9+5,mcb_y-5,mc_width*0.1+2,mc_height*1.2);
    path.moveTo(mca_x+mc_width*0.1,mca_y);
    path.arcTo(QRectF(mca_x+mc_width*0.1-mc_height/2,mca_y,mc_height,mc_height),90,180);
    pen.setColor(Qt::yellow);
    painter.setPen(pen);
    painter.drawPath(path);
    path.moveTo(mcb_x+mc_width*0.8,mcb_y);
    path.arcTo(QRectF(mcb_x+mc_width*0.9-mc_height/2,mcb_y,mc_height,mc_height),90,-180);
    painter.drawPath(path);
    int smallRectWidth =mc_width/6;
    int smallRectHeight= mc_height/4;
    painter.setBrush(Qt::yellow);
    painter.drawRect(mca_x+mc_width*0.3-smallRectWidth,mca_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight);
    painter.drawRect(mca_x+mc_width-smallRectWidth*0.5-smallRectWidth,mca_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight);
    painter.drawRect(mca_x+mc_width*0.3-smallRectWidth,mca_y+mc_height-smallRectHeight*1.3,smallRectWidth,smallRectHeight);
    painter.drawRect(mca_x+mc_width-smallRectWidth*0.5-smallRectWidth,mca_y+mc_height-smallRectHeight*1.3,smallRectWidth,smallRectHeight);
    painter.drawRect(QRectF(mcb_x+smallRectWidth*0.5,mcb_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight));
    painter.drawRect(QRectF(mcb_x+smallRectWidth*0.5,mcb_y+mc_height-smallRectHeight*0.3-smallRectHeight,smallRectWidth,smallRectHeight));
    painter.drawRect(QRectF(mcb_x+mc_width*0.7,mcb_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight));
    painter.drawRect(QRectF(mcb_x+mc_width*0.7,mcb_y+mc_height-smallRectHeight*0.3-smallRectHeight,smallRectWidth,smallRectHeight));
    QSize Size = painter.fontMetrics().size(Qt::TextSingleLine, str);
    painter.setPen(Qt::white);
    painter.drawText(QPointF(mca_x+mc_width/2-Size.width()/2,mca_y+mc_height/2+Size.height()/2),str);
    painter.drawText(QPointF(mcb_x+mc_width/2-Size.width()/2,mcb_y+mc_height/2+Size.height()/2),str);
    painter.end();

}
Exemple #3
0
void Plotter::doPaint(QPainter &painter)
{
    QColor c1(127, 0, 0);
    QColor c2(0, 127, 0);
    QColor c3(0, 0, 127);
    QPen p(c1);
    p.setWidth(2);
    painter.setPen(p);

    QPainterPath path_sign;
    QPainterPath path_res;

    //////////////////////////////////
    door_.setMainData(E_, tlim_);
    //////////////////////////////////

    //for rand()
    QTime time = QTime::currentTime();
    qsrand((uint)time.msec());

    //for signal
    QPointF p_sign;
    float sig_end = 6*M_PI;
    float sig_count = width()/2;
    float sig_step = sig_end/sig_count;
    float count = 0;

    for (float i=sig_step; i<sig_end; i+=sig_step) {
        int k = randInt(noise_,-1*noise_);

        //drawing signal
        p_sign.setX(count++);
        p_sign.setY(MyFunc(i)+k);
        path_sign.lineTo(p_sign);

        door_.hadlePoint(p_sign);
        if (door_.storePointChanged()) {
            path_res.lineTo(door_.getLastStoredPoint());
            painter.drawPoint(door_.getLastStoredPoint());
        }
    }

    p.setColor(c2);
    p.setWidth(0.5);
    painter.setPen(p);
    painter.drawPath(path_sign);
    p.setColor(c3);
    p.setWidth(0.5);
    painter.setPen(p);
    painter.drawPath(path_res);
}
void KisColorSelector::drawOutline(QPainter& painter, const QRect& rect)
{
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.resetTransform();
    painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2);
    painter.scale(rect.width()/2, rect.height()/2);
    painter.setPen(QPen(QBrush(Qt::gray), 0.005));
    
    if (getNumPieces() > 1) {
        for(int i=0; i<getNumRings(); ++i) {
            painter.resetTransform();
            painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2);
            painter.scale(rect.width()/2, rect.height()/2);
            painter.rotate(-m_colorRings[i].getShift().degrees());
            
            for(int j=0; j<m_colorRings[i].pieced.size(); ++j)
                painter.drawPath(m_colorRings[i].pieced[j]);
        }
        
        if (m_selectedRing >= 0 && m_selectedPiece >= 0) {
            painter.resetTransform();
            painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2);
            painter.rotate(-m_colorRings[m_selectedRing].getShift().degrees());
            painter.scale(rect.width()/2, rect.height()/2);
            
            painter.setPen(QPen(QBrush(Qt::red), 0.01));
            painter.drawPath(m_colorRings[m_selectedRing].pieced[m_selectedPiece]);
        }
    }
    else {
        for(int i=0; i<getNumRings(); ++i) {
            qreal rad = m_colorRings[i].outerRadius;
            painter.drawEllipse(QRectF(-rad, -rad, rad*2.0, rad*2.0));
        }
    }
    
    if (m_selectedRing >= 0) {
        qreal iRad = m_colorRings[m_selectedRing].innerRadius;
        qreal oRad = m_colorRings[m_selectedRing].outerRadius;
        
        painter.setPen(QPen(QBrush(Qt::red), 0.005));
        painter.drawEllipse(QRectF(-iRad, -iRad, iRad*2.0, iRad*2.0));
        painter.drawEllipse(QRectF(-oRad, -oRad, oRad*2.0, oRad*2.0));
        
        if (getNumPieces() <= 1) {
            float c = std::cos(-m_selectedColor.getH() * PI2);
            float s = std::sin(-m_selectedColor.getH() * PI2);
            painter.drawLine(QPointF(c*iRad, s*iRad), QPointF(c*oRad, s*oRad));
        }
    }
}
//! [paint function]
void DisplayWidget::paint(QPainter &painter)
{
//![paint picture]
    painter.setClipRect(QRect(0, 0, 200, 200));
    painter.setPen(Qt::NoPen);

    switch (background) {
    case Sky:
    default:
        painter.fillRect(QRect(0, 0, 200, 200), Qt::darkBlue);
        painter.translate(145, 10);
        painter.setBrush(Qt::white);
        painter.drawPath(moon);
        painter.translate(-145, -10);
        break;
    case Trees:
    {
        painter.fillRect(QRect(0, 0, 200, 200), Qt::darkGreen);
        painter.setBrush(Qt::green);
        painter.setPen(Qt::black);
        for (int y = -55, row = 0; y < 200; y += 50, ++row) {
            int xs;
            if (row == 2 || row == 3)
                xs = 150;
            else
                xs = 50;
            for (int x = 0; x < 200; x += xs) {
                painter.save();
                painter.translate(x, y);
                painter.drawPath(tree);
                painter.restore();
            }
        }
        break;
    }
    case Road:
        painter.fillRect(QRect(0, 0, 200, 200), Qt::gray);
        painter.setPen(QPen(Qt::white, 4, Qt::DashLine));
        painter.drawLine(QLine(0, 35, 200, 35));
        painter.drawLine(QLine(0, 165, 200, 165));
        break;
    }

    painter.setBrush(shapeColor);
    painter.setPen(Qt::black);
    painter.translate(100, 100);
    painter.drawPath(shapeMap[shape]);
//![paint picture]
}
void ImageDisplayer::drawSavedContour(QPainter &painter) 
{
	//cout << "seeds size: " << seeds.size() << endl;
	//cout << "paths size: " << paths.size() << endl;
	if(seeds.size() ==  paths.size()) {
		for(int i=0; i<seeds.size(); i++) {
			// draw seed
			QBrush o = painter.brush();
			painter.setBrush(QColor(255, 0, 0, 255));
			int x = seeds[i].pos[0];
			int y = seeds[i].pos[1];
			int* tem = img2dis(x, y);
			painter.drawRect(tem[0]-3, tem[1]-3, 7, 7);
			painter.setBrush(o);

			// draw path
			QPainterPath path;
			vector<vec2i> p = paths[i];
			int* tem2 = img2dis(p[0].pos[0], p[0].pos[1]);
			path.moveTo(tem2[0], tem2[1]);
			for(int j=1; j<p.size(); j++) {
				tem2 = img2dis(p[j].pos[0], p[j].pos[1]);
				path.lineTo(tem2[0], tem2[1]);
			}
			QPen op = painter.pen();
			QPen pen(Qt::green, 3);
			painter.setPen(pen);
			painter.drawPath(path);
			painter.setPen(op);
		}
	}
}
void DrawStaticLoading(
		QPainter &p,
		QRectF rect,
		int stroke,
		QPen pen,
		QBrush brush) {
	PainterHighQualityEnabler hq(p);

	p.setBrush(brush);
	pen.setWidthF(stroke);
	pen.setCapStyle(Qt::RoundCap);
	pen.setJoinStyle(Qt::RoundJoin);
	p.setPen(pen);
	p.drawEllipse(rect);

	const auto center = rect.center();
	const auto first = QPointF(center.x(), rect.y() + 1.5 * stroke);
	const auto delta = center.y() - first.y();
	const auto second = QPointF(center.x() + delta * 2 / 3., center.y());
	if (delta > 0) {
		QPainterPath path;
		path.moveTo(first);
		path.lineTo(center);
		path.lineTo(second);
		p.drawPath(path);
	}
}
void QQuickShapeSoftwareRenderNode::render(const RenderState *state)
{
    if (m_sp.isEmpty())
        return;

    QSGRendererInterface *rif = m_item->window()->rendererInterface();
    QPainter *p = static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
    Q_ASSERT(p);

    const QRegion *clipRegion = state->clipRegion();
    if (clipRegion && !clipRegion->isEmpty())
        p->setClipRegion(*clipRegion, Qt::ReplaceClip); // must be done before setTransform

    p->setTransform(matrix()->toTransform());
    p->setOpacity(inheritedOpacity());

    for (const ShapePathRenderData &d : qAsConst(m_sp)) {
        if (d.hidden) {
            continue;
        }

//        QTransform oldTransform = p->transform();
//        p->setTransform(d.transform, true);

//        p->setOpacity(inheritedOpacity() * d.opacity);
        p->setPen(d.strokeWidth >= 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
        p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
        p->drawPath(d.path);

//        p->setTransform(oldTransform);
    }
}
Exemple #9
0
//-----------------------------------------------------------------------------
//! 
//-----------------------------------------------------------------------------
void tBoatWidget::DrawBoat( QPainter& painter )
{
    painter.save();

    // Draw boat
    QColor color;
    if( tSystemSettings::Instance()->NightMode() )
    {
        color = Qt::white;
        painter.setOpacity(0.2);
    }
    else
    {
        color = Qt::black;
        painter.setOpacity(0.5);
    }

    painter.setPen(QPen(color, 6, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
    painter.translate(QPointF((width()/2.0)+0.5, 15.0));
    QPainterPath p;

    p.moveTo( 28, 146 );
    p.cubicTo(  34, 90,  44, 70, 0, 0 );
    p.cubicTo( -44, 70, -34, 90, -28, 146 );
    p.lineTo( 28, 146 );

    painter.drawPath(p);

    painter.restore();
}
Exemple #10
0
void Canvas::paintEvent(QPaintEvent *e)
{
    QPainter *p = new QPainter(this);
    QPen pen(QColor(0,0,0,255));

    if(p->isActive()){
        p->setRenderHint(QPainter::Antialiasing);
        pen.setWidth(1);
        p->setPen(pen);

        p->save();
        pen.setColor(QColor(255,0,0,255));
        p->setPen(pen);

        foreach(QPainterPath t, _ticks)
            p->drawPath(t);

        p->restore();

        p->drawEllipse(PADDING,PADDING,_radiusX*2,_radiusY*2);
        p->end();
    }

    QFrame::paintEvent(e);
}
Exemple #11
0
void QRoundProgressBar::drawValue(QPainter &p, const QRectF &baseRect, double value, double arcLength)
{
    // nothing to draw
    if (value == m_min)
        return;

    // for Line style
    if (m_barStyle == StyleLine)
    {
        p.setPen(QPen(palette().highlight().color(), m_dataPenWidth));
        p.setBrush(Qt::NoBrush);
        p.drawArc(baseRect.adjusted(m_outlinePenWidth/2, m_outlinePenWidth/2, -m_outlinePenWidth/2, -m_outlinePenWidth/2),
                  m_nullPosition * 16,
                  -arcLength * 16);
        return;
    }

    // for Pie and Donut styles
    QPainterPath dataPath;
    dataPath.setFillRule(Qt::WindingFill);

    // pie segment outer
    dataPath.moveTo(baseRect.center());
    dataPath.arcTo(baseRect, m_nullPosition, -arcLength);
    dataPath.lineTo(baseRect.center());

    p.setBrush(palette().highlight());
    p.setPen(QPen(palette().shadow().color(), m_dataPenWidth));
    p.drawPath(dataPath);
}
void TextRenderable::render(QPainter &painter, const RenderConfig &config) const
{
	painter.save();
	
	bool disable_antialiasing = config.options.testFlag(RenderConfig::Screen) && !(Settings::getInstance().getSettingCached(Settings::MapDisplay_TextAntialiasing).toBool());
	if (disable_antialiasing)
	{
		painter.setRenderHint(QPainter::Antialiasing, false);
		painter.setRenderHint(QPainter::TextAntialiasing, false);
	}
	
	if (framing_line)
	{
		QPen pen(painter.pen());
		pen.setJoinStyle(Qt::MiterJoin);
		pen.setMiterLimit(0.5);
		painter.setPen(pen);
	}
	
	painter.translate(anchor_x, anchor_y);
	if (rotation != 0)
		painter.rotate(-rotation * 180 / M_PI);
	painter.scale(scale_factor, scale_factor);
	painter.drawPath(path);
	
	painter.restore();
}
Exemple #13
0
void ColorWheel::drawOuterRing(QPainter &painter) {
    int r = qMin(this->width(), this->height());
    QPointF center(r/2.0, r/2.0);

    // paint hue wheel
    painter.save();
    QConicalGradient conicalGradient(center, 0);
    conicalGradient.setColorAt(0.0, Qt::red);
    conicalGradient.setColorAt(60.0/360.0, Qt::yellow);
    conicalGradient.setColorAt(120.0/360.0, Qt::green);
    conicalGradient.setColorAt(180.0/360.0, Qt::cyan);
    conicalGradient.setColorAt(240.0/360.0, Qt::blue);
    conicalGradient.setColorAt(300.0/360.0, Qt::magenta);
    conicalGradient.setColorAt(1.0, Qt::red);
    QBrush brush(conicalGradient);
    painter.setPen(Qt::NoPen);
    painter.setBrush(brush);

    // outer circle
    QPainterPath path;
    path.addEllipse(center, r/2.0 - margin_, r/2.0 - margin_);
    // inner circle
    path.addEllipse(center, r/2.0 - margin_ - wheelWidth_, r/2.0 - margin_ - wheelWidth_);
    painter.drawPath(path);
    painter.restore();
}
Exemple #14
0
    void GraphPathRenderer::render(QImage *image, QRectF clip, 
            QTransform &t)
    {
        //qDebug() << QString("%1").arg(__PRETTY_FUNCTION__);

        QPainter p(image);
        p.setTransform(t);
        //p.setClipRect(QRect(0, 0, image->width(), image->height())); //显示的图形会有空白的clip 矩形

        QPainter *d = &p;

        //d->setRenderHint(QPainter::Antialiasing, true);
        //d->setRenderHint(QPainter::TextAntialiasing, true);

        QVector<struct GraphPathRenderer::shape>::const_iterator it;
        for (it = m_data->paths.begin(); it != m_data->paths.end(); 
                ++it) {
            d->save();
            const struct GraphPathRenderer::shape &item = *it;
            d->setPen(item.pen);
            d->setBrush(item.brush);
            d->drawPath(item.path);
            d->restore();
        }
    }
		/// Draw.
		void Shape2DFree::drawShape(QPainter& painter) const
		{
			QPainterPath path;
			path.addPolygon(m_polygon);
			painter.fillPath(path, m_fill_color);
			painter.drawPath(m_outline);
		}
void SingleDigit::drawHorizontalSegment(QPainter &painter, const QPointF& startPoint, bool filled,
                          QBrush &brush)
{
    const std::array<QPointF, 7>baseSegment{
        QPointF(0,0),
        QPointF(3,-3),
        QPointF(23,-3),
        QPointF(26,0),
        QPointF(23,3),
        QPointF(3,3),
        QPointF(0,0)
    };

    QPainterPath segmentPath;

    segmentPath.moveTo(baseSegment.at(0)+startPoint);

    for(auto & point : baseSegment)
        segmentPath.lineTo(point*m_scale + startPoint);

    if(filled)
        painter.fillPath(segmentPath,brush);
    else
        painter.drawPath(segmentPath);
}
Exemple #17
0
void KoCreateShapeStrategy::paint(QPainter &painter, const KoViewConverter &converter)
{
    if (m_outline.isEmpty())
        KoShapeRubberSelectStrategy::paint(painter, converter);
    else {
        painter.save();
        painter.setRenderHint(QPainter::Antialiasing, false);

        QColor selectColor(Qt::blue);   // TODO make configurable
        selectColor.setAlphaF(0.5);
        QBrush sb(selectColor, Qt::SolidPattern);
        painter.setPen(QPen(sb, 0));
        painter.setBrush(sb);
        QRectF paintRect = converter.documentToView(selectRect());

        qreal xscale = paintRect.width() / m_outlineBoundingRect.width();
        qreal yscale = paintRect.height() / m_outlineBoundingRect.height();
        QMatrix matrix;
        matrix.translate(-m_outlineBoundingRect.left(), -m_outlineBoundingRect.top());
        matrix.scale(xscale, yscale);
        painter.translate(paintRect.left(), paintRect.top());

        if (painter.hasClipping())
            paintRect = paintRect.intersect(painter.clipRegion().boundingRect());

        painter.setMatrix(matrix, true);
        painter.drawPath(m_outline);
        painter.restore();
    }
}
void CFlightVisualiser::drawPathes(QPainter& painter, const QRect &fieldLimit)
{
    QPainterPath targetPath, chaserPath;
    if(_target.size() == 0 || _chaser.size() == 0)
    {
        std::runtime_error("No path for target and chaser");
    }

    targetPath.moveTo(QPointF(getScreenPoint(_target[0], fieldLimit)));
    chaserPath.moveTo(QPointF(getScreenPoint(_chaser[0], fieldLimit)));

    for(auto iter = _target.begin() + 1; iter != _target.end(); ++iter)
    {
        QPointF res = getScreenPoint(*iter, fieldLimit);
        targetPath.lineTo(res);
    }

    for(auto iter = _chaser.begin() + 1; iter != _chaser.end(); ++iter)
    {
        QPointF res = getScreenPoint(*iter, fieldLimit);
        chaserPath.lineTo(res);
    }

    painter.drawPath(targetPath);
    painter.drawPath(chaserPath);

    painter.drawEllipse(getScreenPoint(*(_target.end() - 1), fieldLimit), 5, 5);
    painter.drawEllipse(getScreenPoint(*(_chaser.end() - 1), fieldLimit), 5, 5);
}
Exemple #19
0
void PanelRadar::paintEvent(QPaintEvent* event) {
    const qreal scale0 = 0.14644660940672623779957781894758;
    const qreal scale1 = (1.0 - scale0);
    
    PanelWidget::paintEvent(event);
    QPainter p;
    p.begin(this);
    setMargins(&p);
    p.setRenderHint(QPainter::Antialiasing, true);
    p.setRenderHint(QPainter::TextAntialiasing, true);
    
    QPen pen = p.pen();
    pen.setWidth(1);
    p.setPen(QColor("black"));
    
    QPainterPath path;
    qreal rx = p.device()->width();
    qreal ry = p.device()->height();
    
    QPointF point(0.5 * rx, 0.5 * ry);
    
    path.addEllipse(point, 0.50 * rx, 0.50 * ry);
    p.fillPath(path, QColor("white"));
    path.addEllipse(point, 0.25 * rx, 0.25 * ry);
    p.drawPath(path);

    p.drawLine(0, 0.5 * ry, rx, 0.5 * ry);
    p.drawLine(0.5 * rx, 0, 0.5 * rx, ry);
    p.drawLine(rx * scale0 + 1, ry * scale0 + 1, rx * scale1 - 1, ry * scale1 - 1);
    p.drawLine(rx * scale0 + 1, ry * scale1 - 1, rx * scale1 - 1, ry * scale0 + 1);
    
    drawItems(&p);
    
    p.end();
}
Exemple #20
0
void MapView::drawCircle(QPainter &painter, const QPoint &center, int diameter)
{
    QPainterPath path, patho;

    path.addEllipse(center, diameter, diameter);
    painter.drawPath(path);
}
void PieChart3D::paintExternal( QPainter& painter, bool top ) {
  for ( int i = 0; i < myAngles.count() - 2; i+=2 ) {
    QModelIndex index = this->model()->index( i/2, 0 );
    bool isSelected = this->selectionModel()->selectedIndexes().contains( index )
                      || this->currentIndex() == index;
    QColor color( this->model()->data( index, Qt::DecorationRole ).toString() );
    if ( !color.isValid() ) {
      color = Marb::predefinedColor( i/2 );
    }
    painter.save();
    qreal a1 = myAngles[i];
    qreal delta = myAngles[i + 1];
    qreal a2 = a1 + delta;
    if ( a1 < 180 && a2 > 180 ) {
      paintLeft( painter, color );
    }
    if ( top == false ) {
      if ( a1 <= 180 && a2 > 180 ) {
        if ( myRender == Plain ) {
          configureColor( painter, color, 1 );
          qreal delta = 180.0 - a1;
          QPointF offset = splittedOffset( myAngles[i], delta );
          QPainterPath path = itemExternalPart( myAngles[i], delta, mySplitted );
          painter.drawPath( path );
          painter.setPen( Qt::NoPen );
          path = side( 180, offset, isSelected );
          painter.drawPath( path );
        }
        painter.restore();
        continue;
      }
      if ( a1 > 180 || a2 > 180 ) {
        painter.restore();
        continue;
      }
    } else {
      if ( a1 < 180 && a2 < 180 ) {
        painter.restore();
        continue;
      }
    }
    QPainterPath path = itemExternalPart( a1, delta, isSelected );
    configureColor( painter, color, 3 );
    painter.drawPath( path );
    painter.restore();
  }
}
Exemple #22
0
void EditorArea::paintEdges(QPainter &painter)
{
    bool firstTime = true;

    QVector<int> edgesIds = workspace->getEdgesIds();

    for (int i=0; i < edgesIds.size(); i++) {
        QPoint nodesOfEdge = workspace->getNodesOfEdge(edgesIds[i]);
        QPointF screenXYFirst = graph2screen(workspace->getNodePosition(nodesOfEdge.x()));
        QPointF screenXYSecond = graph2screen(workspace->getNodePosition(nodesOfEdge.y()));
        QPointF screenMidPoint = graph2screen(workspace->getThirdPointPos(edgesIds[i]));

        QPainterPath path;
        path.moveTo(screenXYFirst);
        path.quadTo(screenMidPoint, screenXYSecond);
        path.quadTo(screenMidPoint, screenXYFirst);
        painter.drawPath(path);

        QVector<QPointF> pointsOnBezier;
        QVector<float> sOnEdge;

        for (int k = 0; k < edgeDiscretization + 1; k++) {
            float t = float(k) / edgeDiscretization;
            QPointF coord = (1 - t) * (1 - t) * screenXYFirst + 2 * (1 - t) * t * screenMidPoint + t * t * screenXYSecond;
            pointsOnBezier << coord;
        }

        for (int k = 0; k < pointsOnBezier.size(); k++) {
            if (k == 0) {
                sOnEdge << 0.0;
            } else {
                float sJesima = workspace->distance(pointsOnBezier[k], pointsOnBezier[k - 1]);
                sOnEdge << sJesima;
            }
        }

        for (int k = 1; k < pointsOnBezier.size(); k++) {
            sOnEdge[k] = sOnEdge[k] + sOnEdge[k - 1];
        }

        float length = sOnEdge.last();

        for (int k = 0; k < sOnEdge.size(); k++) {
            sOnEdge[k] = sOnEdge[k] / length;
        }

        sOnBezier.insert(edgesIds[i], sOnEdge);

        if (path.intersects(QRectF(mouseCurrentPos.x() - 7, mouseCurrentPos.y() - 7, 14, 14))) {
            if (firstTime) {
                firstTime = false;
                hitElements.clear();
            }

            QPoint temp(2, edgesIds[i]);
            hitElements.append(temp);
        }
    }
}
void PhysicalObject::draw(QPainter &painter)
{
    painter.setBrush(QBrush(_color));
    QPainterPath path;
    path.addPolygon(this->getPolygonShape());

    painter.drawPath(path);
}
Exemple #24
0
void QSplineEdit::paintControlLines(QPainter & pnt)
{
	QBrush br(Qt::NoBrush);
	QPen pn(Qt::black);
	pnt.setPen(pn);
	pnt.setBrush(br);
	
	QPainterPath startControl;
	startControl.moveTo(toDrawSpace(0, m_startValue));
	startControl.lineTo(toDrawSpace(m_startCvx, m_startCvy));
	pnt.drawPath(startControl);
	
	QPainterPath endControl;
	endControl.moveTo(toDrawSpace(1, m_endValue));
	endControl.lineTo(toDrawSpace(m_endCvx, m_endCvy));
	pnt.drawPath(endControl);
}
Exemple #25
0
void SquareRootElement::paint( QPainter& painter, AttributeManager* am )
{
    BasicElement::paint(painter, am);
    QPen pen;
    pen.setWidth( 1 );
    painter.setPen( pen );
    painter.drawPath( m_rootSymbol );
}
Exemple #26
0
void plotPathsToPainter(QPainter& painter, QPainterPath& path,
			const Numpy1DObj& x, const Numpy1DObj& y,
			const Numpy1DObj* scaling,
			const QRectF* clip,
			const QImage* colorimg)
{
  QRectF cliprect( QPointF(-32767,-32767), QPointF(32767,32767) );
  if( clip != 0 )
    {
      qreal x1, y1, x2, y2;
      clip->getCoords(&x1, &y1, &x2, &y2);
      cliprect.setCoords(x1, y1, x2, y2);
    }
  QRectF pathbox = path.boundingRect();
  cliprect.adjust(pathbox.left(), pathbox.top(),
		  pathbox.bottom(), pathbox.right());

  // keep track of duplicate points
  QPointF lastpt(-1e6, -1e6);
  // keep original transformation for restoration after each iteration
  QTransform origtrans(painter.worldTransform());

  // number of iterations
  int size = min(x.dim, y.dim);

  // if few color points, trim down number of paths
  if( colorimg != 0 )
    size = min(size, colorimg->width());
  // too few scaling points
  if( scaling != 0 )
    size = min(size, scaling->dim);

  // draw each path
  for(int i = 0; i < size; ++i)
    {
      const QPointF pt(x(i), y(i));
      if( cliprect.contains(pt) && ! smallDelta(lastpt, pt) )
	{
	  painter.translate(pt);
	  if( scaling != 0 )
	    {
	      // scale point if requested
	      const qreal s = (*scaling)(i);
	      painter.scale(s, s);
	    }
	  if( colorimg != 0 )
	    {
	      // get color from pixel and create a new brush
	      QBrush b( QColor::fromRgba(colorimg->pixel(i, 0)) );
	      painter.setBrush(b);
	    }

	  painter.drawPath(path);
	  painter.setWorldTransform(origtrans);
	  lastpt = pt;
	}
    }
}
Exemple #27
0
void VisiblePlacemark::drawLabelText(QPainter &labelPainter, const QString &text,
                                            const QFont &labelFont, LabelStyle labelStyle, const QColor &color )
{
    QFont font = labelFont;
    QFontMetrics metrics = QFontMetrics( font );
    int fontAscent = metrics.ascent();

    switch ( labelStyle ) {
    case Selected: {
        labelPainter.setPen( color );
        labelPainter.setFont( font );
        QRect textRect( 0, 0, metrics.width( text ), metrics.height() );
        labelPainter.fillRect( textRect, QApplication::palette().highlight() );
        labelPainter.setPen( QPen( QApplication::palette().highlightedText(), 1 ) );
        labelPainter.drawText( 0, fontAscent, text );
        break;
    }
    case Glow: {
        font.setWeight( 75 );
        fontAscent = QFontMetrics( font ).ascent();

        QPen outlinepen( color == QColor( Qt::white ) ? Qt::black : Qt::white );
        outlinepen.setWidthF( s_labelOutlineWidth );
        QBrush  outlinebrush( color );

        QPainterPath outlinepath;

        const QPointF  baseline( s_labelOutlineWidth / 2.0, fontAscent );
        outlinepath.addText( baseline, font, text );
        labelPainter.setRenderHint( QPainter::Antialiasing, true );
        labelPainter.setPen( outlinepen );
        labelPainter.setBrush( outlinebrush );
        labelPainter.drawPath( outlinepath );
        labelPainter.setPen( Qt::NoPen );
        labelPainter.drawPath( outlinepath );
        labelPainter.setRenderHint( QPainter::Antialiasing, false );
        break;
    }
    default: {
        labelPainter.setPen( color );
        labelPainter.setFont( font );
        labelPainter.drawText( 0, fontAscent, text );
    }
    }
}
Exemple #28
0
void TurnAndBank::createBall(void){
    QImage _glassImage = QImage(QSize(800,800), QImage::Format_ARGB32);
    _glassImage.fill(0x00ffffff);
    
    QPainter p;
    
    p.setRenderHint(QPainter::Antialiasing, true);
    p.begin(&_glassImage);
    p.translate(400, 400);
    
    // QLinearGradient gradient(0,101,0,199);
    // gradient.setColorAt(0, SKYBLUE);
    // gradient.setColorAt(1, GROUNDBROWN);

    QRadialGradient gradient(0,-4500, 4750, 0, 30000);
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::green);
    gradient.setSpread(QGradient::ReflectSpread);
    
    QBrush gbrush(gradient);
    p.setBrush(gbrush);
    //    p.drawRect(-350, 120, 700, 150);
    
    
    QPainterPath pathBottom;
    pathBottom.moveTo(-310, 150);
    pathBottom.arcTo(-2500+50,-3830-1000,5000,5000, -96, 12);
    //pathBottom.lineTo(310, 250);
    pathBottom.arcTo(-2000,-3700,4000,4000, -81, -18);
    //pathBottom.lineTo(-310, 150);
    
    //    pathBottom.lineTo(-240,0);
    //pathBottom.arcTo(-240,-240,480,480, 180, 180);
    
    //    p.setPen(QPen(QColor(79, 106, 25), 0, Qt::SolidLine,
    //                     Qt::FlatCap, Qt::MiterJoin));
    p.setPen(QPen(Qt::white, 4, Qt::SolidLine,
                  Qt::FlatCap, Qt::MiterJoin));
    p.setPen(Qt::NoPen);
    p.setBrush(gbrush);
    // p.setBrush(GROUNDBROWN);
    
    p.drawPath(pathBottom);
    
    p.setBrush(Qt::black);
    
    
    p.setPen(QPen(Qt::black, 4, Qt::SolidLine,
                  Qt::FlatCap, Qt::MiterJoin));
    p.drawLine(-50,170, -50, 300);
    p.drawLine(50,170, 50, 300);
    
    p.end();
    
    _ball = QPixmap::fromImage(_glassImage, Qt::AutoColor);
    
}    
Exemple #29
0
void KGradientBackground::paint(QPainter &painter, const QPainterPath &fillPath) const
{
    Q_D(const KGradientBackground);
    QBrush brush(*d->gradient);
    brush.setTransform(d->matrix);

    painter.setBrush(brush);
    painter.drawPath(fillPath);
}
void EncloseElement::paint( QPainter& painter, AttributeManager* )
{
    painter.save();
    QPen pen;
    pen.setWidth( 1 );
    painter.setPen( pen );
    painter.drawPath( m_enclosePath );
    painter.restore();
}