void QCairoPaintEngine::drawPolygon(const QPointF *points, int pointCount, QPaintEngine::PolygonDrawMode mode)
{
    if (!cr || !surface) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPolygon]: no cairo or no surface!";
        return;
    }
    /*if (cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPolygon]: no pen set!";
        return;
    }*/
    if (mode!=QPaintEngine::PolylineMode && cbrush.style()==Qt::NoBrush && cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPolygon]: no pen and no brush set!";
        return;
    }
    //updatePen();

    //qDebug()<<"drawPolygon n="<<pointCount;
    if (pointCount>1) {
        cairo_new_path(cr);
        cairo_move_to(cr, points[0].x(), points[0].y());
        for (int i=1; i<pointCount; i++) {
            cairo_line_to(cr, points[i].x(), points[i].y());
        }
        if (points[0].x()==points[pointCount-1].x() && points[0].y()==points[pointCount-1].y()){
            cairo_close_path(cr);
        } else if (mode!=QPaintEngine::PolylineMode) {
            cairo_close_path(cr);
        }
        if (mode==QPaintEngine::PolylineMode) {
            updatePen();
            cairo_stroke(cr);
        } else {
            switch (mode) {
                case QPaintEngine::WindingMode:
                    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
                    break;
                default:
                case QPaintEngine::OddEvenMode:
                    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
                    break;
            }


            updateBrush();
            if (cpen.style()!=Qt::NoPen) {
                cairo_fill_preserve(cr);
                updatePen();
                cairo_stroke(cr);
            } else cairo_fill(cr);
        }
    }

}
Exemplo n.º 2
0
void setPenStyle(ACL_Pen_Style newStyle)
{
	ACL_ASSERT_BEGIN_PAINT;

	switch(newStyle)
	{
	case PEN_STYLE_SOLID:
		g_penStyle = PS_SOLID; break;
	case PEN_STYLE_DASH:
		g_penStyle = PS_DASH; break;
	case PEN_STYLE_DOT:	
		g_penStyle = PS_DOT; break;
	case PEN_STYLE_DASHDOT:
		g_penStyle = PS_DASHDOT; break;
	case PEN_STYLE_DASHDOTDOT:	
		g_penStyle = PS_DASHDOTDOT; break;
	case PEN_STYLE_NULL:
		g_penStyle = -1;
		setPenColor(EMPTY);
		return;
	default:
		break;
	}
	updatePen();
}
void QCairoPaintEngine::drawLines(const QLineF *lines, int lineCount)
{
    if (!cr || !surface) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawLines]: no cairo or no surface!";
        return;
    }
    if (cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawLines]: no pen set!";
        return;
    }
    updatePen();
    //qDebug()<<"drawLines n="<<lineCount;
    cairo_new_path(cr);
    for (int i=0; i<lineCount; i++) {
        cairo_move_to(cr, lines[i].x1(), lines[i].y1());
        cairo_line_to(cr, lines[i].x2(), lines[i].y2());
    }
    //cairo_close_path(cr);
    updatePen();
    cairo_stroke(cr);
}
Exemplo n.º 4
0
void beginPaint() {
  HDC hdc;

  ACL_ASSERT_HWND;

  hdc = GetDC(g_hWnd);
  g_hmemdc = CreateCompatibleDC(hdc);
  SelectObject(g_hmemdc, g_HBITMAP);

  updatePen();
  updateBrush();
  updateFont();
  setTextColor(g_textColor);
  setTextBkColor(g_textBkColor);
}
void QCairoPaintEngine::drawPoints(const QPointF *points, int pointCount)
{


    if (!cr || !surface) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPoints]: no cairo or no surface!";
        return;
    }
    if (cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPoints]: no pen set!";
        return;
    }
    updatePen();
    for (int i=0; i<pointCount; i++) {
        cairo_new_path(cr);
        cairo_move_to (cr, points[i].x(), points[i].y());

        cairo_close_path (cr);
    }
    //cairo_close_path(cr);
    updatePen();
    cairo_stroke(cr);

}
void QPicturePaintEngine::updateState(const QPaintEngineState &state)
{
    QPaintEngine::DirtyFlags flags = state.state();
    if (flags & DirtyPen) updatePen(state.pen());
    if (flags & DirtyBrush) updateBrush(state.brush());
    if (flags & DirtyBrushOrigin) updateBrushOrigin(state.brushOrigin());
    if (flags & DirtyFont) updateFont(state.font());
    if (flags & DirtyBackground) updateBackground(state.backgroundMode(), state.backgroundBrush());
    if (flags & DirtyTransform) updateMatrix(state.transform());
    if (flags & DirtyClipEnabled) updateClipEnabled(state.isClipEnabled());
    if (flags & DirtyClipRegion) updateClipRegion(state.clipRegion(), state.clipOperation());
    if (flags & DirtyClipPath) updateClipPath(state.clipPath(), state.clipOperation());
    if (flags & DirtyHints) updateRenderHints(state.renderHints());
    if (flags & DirtyCompositionMode) updateCompositionMode(state.compositionMode());
    if (flags & DirtyOpacity) updateOpacity(state.opacity());
}
void QCairoPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
{
    if (!exportText) {
        QPaintEngine::drawTextItem(p, textItem);
    } else {
        //cairo_matrix_t cm, cmBak;
        //cairo_get_matrix(cr, &cmBak);
        //cairo_translate(cr, p.x(), p.y());
        QFont oldF=cfont;
        cfont=textItem.font();
        updateFont();
        updatePen();

        cairo_move_to (cr, p.x(), p.y());
        cairo_show_text(cr, textItem.text().toUtf8().data());

        cfont=oldF;
        //cairo_set_matrix(cr, &cmBak);
    }
}
Exemplo n.º 8
0
void setPenWidth(int width)
{
	ACL_ASSERT_BEGIN_PAINT;
	g_penWidth = width;
	updatePen();
}
Exemplo n.º 9
0
void setPenColor(ACL_Color newColor)
{
	ACL_ASSERT_BEGIN_PAINT;
    g_penColor = newColor;    
    updatePen();
}
Exemplo n.º 10
0
void ContourLinesEditor::showPenDialog(int row, int col)
{
	if (!d_spectrogram || col != 1)
		return;

	enableButtons(row);

	QPen pen = d_pen_list[row];

	if (!penDialog){
		penDialog = new QDialog(this);
		penDialog->setWindowTitle(tr("MantidPlot - Edit pen"));

		QGroupBox *gb1 = new QGroupBox();
		QGridLayout *hl1 = new QGridLayout(gb1);

		hl1->addWidget(new QLabel(tr("Color")), 0, 0);
		penColorBox = new ColorButton();
		penColorBox->setColor(pen.color());
		hl1->addWidget(penColorBox, 0, 1);

		applyAllColorBox = new QCheckBox(tr("Apply to all"));
		hl1->addWidget(applyAllColorBox, 0, 2);

		hl1->addWidget(new QLabel(tr("Style")), 1, 0);
		penStyleBox = new PenStyleBox;
		penStyleBox->setStyle(pen.style());
		hl1->addWidget(penStyleBox, 1, 1);

		applyAllStyleBox = new QCheckBox(tr("Apply to all"));
		hl1->addWidget(applyAllStyleBox, 1, 2);

		hl1->addWidget(new QLabel(tr("Width")), 2, 0);
		penWidthBox = new DoubleSpinBox();
		penWidthBox->setValue(pen.widthF());
		hl1->addWidget(penWidthBox, 2, 1);
		hl1->setRowStretch(3, 1);

		applyAllWidthBox = new QCheckBox(tr("Apply to all"));
		hl1->addWidget(applyAllWidthBox, 2, 2);

		QPushButton *acceptPenBtn = new QPushButton(tr("&Ok"));
		connect(acceptPenBtn, SIGNAL(clicked()), this, SLOT(updatePen()));

		QPushButton *closeBtn = new QPushButton(tr("&Close"));
		connect(closeBtn, SIGNAL(clicked()), penDialog, SLOT(reject()));

		QHBoxLayout *hl2 = new QHBoxLayout();
		hl2->addStretch();
		hl2->addWidget(acceptPenBtn);
		hl2->addWidget(closeBtn);

		QVBoxLayout *vl = new QVBoxLayout(penDialog);
		vl->addWidget(gb1);
		vl->addLayout(hl2);
	} else {
		penColorBox->setColor(pen.color());
		penStyleBox->setStyle(pen.style());
		penWidthBox->setValue(pen.widthF());
	}

	d_pen_index = row;
	penDialog->exec();
}
void QCairoPaintEngine::drawPath(const QPainterPath &path)
{
    if (!cr || !surface) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPath]: no cairo or no surface!";
        return;
    }
    if (cbrush.style()==Qt::NoBrush && cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPath]: no pen and no brush set!";
        return;
    }
    //qDebug()<<"drawPath n="<<path;

    bool fill;
    updatePath(path, fill);
    /*cairo_new_path(cr);

    int start = -1, elmCount = path.elementCount();
    for (int index = 0; index < elmCount; index++)
    {
      const QPainterPath::Element elm = path.elementAt(index);
      switch (elm.type)
      {
        case QPainterPath::MoveToElement:
          cairo_move_to(cr, elm.x, elm.y);
          start = index;
          break;

        case QPainterPath::LineToElement:
          cairo_line_to(cr, elm.x, elm.y);
          break;

        case QPainterPath::CurveToElement:
          cairo_curve_to(cr, elm.x, elm.y,
              path.elementAt(index + 1).x, path.elementAt(index + 1).y,
              path.elementAt(index + 2).x, path.elementAt(index + 2).y);
          index += 2;
          break;

        default:
          break;
      }
    }

    bool fill=false;
    if (start != -1 && start != elmCount - 1
          && path.elementAt(start).x == path.elementAt(elmCount - 1).x
            && path.elementAt(start).y == path.elementAt(elmCount - 1).y){
        cairo_close_path(cr);
        //qDebug()<<"closing path";
        fill=cbrush.style()!=Qt::NoBrush;
    }*/
    if (fill) fill=cbrush.style()!=Qt::NoBrush;


    if (fill) {
        switch (path.fillRule()) {
            case Qt::WindingFill:
                cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
                break;
            default:
            case Qt::OddEvenFill:
                cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
                break;
        }


        updateBrush();
        if (cpen.style()!=Qt::NoPen) cairo_fill_preserve(cr);
        else cairo_fill(cr);
    }
    if (cpen.style()!=Qt::NoPen) {
        updatePen();
        cairo_stroke(cr);
    } else {

    }


}