Example #1
0
void AnnotationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
{
	Q_UNUSED(options);
	Q_UNUSED(widget);

	const paintcore::Annotation *state = _image->getAnnotation(_id);
	Q_ASSERT(state);
	if(!state)
		return;

	painter->save();
	painter->setClipRect(boundingRect().adjusted(-1, -1, 1, 1));

	state->paint(painter, _rect);

	if(_showborder || state->isEmpty()) {
		QColor border = QApplication::palette().color(QPalette::Highlight);
		border.setAlpha(255);

		QPen bpen(_highlight && _showborder ? Qt::DashLine : Qt::DotLine);
		bpen.setCosmetic(true);
		bpen.setColor(border);
		painter->setPen(bpen);
		painter->drawRect(_rect);

		// Draw resizing handles
		if(_highlight) {
			QPen pen(border);
			pen.setCosmetic(true);
			painter->setPen(pen);

			drawTriangle(painter, RS_TOPLEFT, _rect.topLeft() + QPointF(2, 2));
			drawTriangle(painter, RS_TOP, _rect.topLeft() + QPointF(_rect.width()/ 2 + 2, 2));
			drawTriangle(painter, RS_TOPRIGHT, _rect.topRight() + QPointF(-2, 2));

			drawTriangle(painter, RS_LEFT, _rect.center() - QPointF(_rect.width()/2 - 2, 0));
			drawTriangle(painter, RS_RIGHT, _rect.center() + QPointF(_rect.width()/2 - 2, 0));

			drawTriangle(painter, RS_BOTTOMLEFT, _rect.bottomLeft() + QPointF(2, -2));
			drawTriangle(painter, RS_BOTTOM, _rect.bottomLeft() + QPointF(_rect.width()/ 2 + 2, -2));
			drawTriangle(painter, RS_BOTTOMRIGHT, _rect.bottomRight() + QPointF(-2, -2));
		}
	}
	if(!_oldrect.isNull()) {
		// Annotation has been reshaped, but the shape changed command hasn't made the roundtrip yet
		QPen bpen(Qt::DotLine);
		bpen.setCosmetic(true);
		bpen.setColor(Qt::red);
		painter->setPen(bpen);
		painter->drawRect(_oldrect);
	}

	painter->restore();
}
Example #2
0
void AnnotationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
{
	Q_UNUSED(options);
	Q_UNUSED(widget);

	const qreal devicePixelRatio = qApp->devicePixelRatio();

	painter->save();
	painter->setClipRect(boundingRect().adjusted(-1, -1, 1, 1));

	painter->fillRect(m_rect, m_color);

	painter->save();
	painter->translate(m_rect.x(), m_rect.y());
	QRect docrect(0, 0, m_rect.width(), m_rect.height());
	m_doc.drawContents(painter, docrect);
	painter->restore();

	if(m_showborder || m_doc.isEmpty()) {
		QColor border = QApplication::palette().color(QPalette::Highlight);
		border.setAlpha(255);

		QPen bpen(m_highlight && m_showborder ? Qt::DashLine : Qt::DotLine);
		bpen.setWidth(devicePixelRatio);
		bpen.setCosmetic(true);
		bpen.setColor(border);
		painter->setPen(bpen);
		painter->drawRect(m_rect);

		// Draw resizing handles
		if(m_highlight) {
			QPen pen(border);
			pen.setCosmetic(true);
			pen.setWidth(HANDLE);
			painter->setPen(pen);
			painter->drawPoint(m_rect.topLeft());
			painter->drawPoint(m_rect.topLeft() + QPointF(m_rect.width()/2, 0));
			painter->drawPoint(m_rect.topRight());

			painter->drawPoint(m_rect.topLeft() + QPointF(0, m_rect.height()/2));
			painter->drawPoint(m_rect.topRight() + QPointF(0, m_rect.height()/2));

			painter->drawPoint(m_rect.bottomLeft());
			painter->drawPoint(m_rect.bottomLeft() + QPointF(m_rect.width()/2, 0));
			painter->drawPoint(m_rect.bottomRight());
		}
	}

	painter->restore();
}
Example #3
0
void AnnotationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
{
    Q_UNUSED(options);
    Q_UNUSED(widget);

    const qreal devicePixelRatio = qApp->devicePixelRatio();

    const paintcore::Annotation *state = _image->getAnnotation(_id);
    Q_ASSERT(state);
    if(!state)
        return;

    painter->save();
    painter->setClipRect(boundingRect().adjusted(-1, -1, 1, 1));

    state->paint(painter, _rect);

    if(_showborder || state->isEmpty()) {
        QColor border = QApplication::palette().color(QPalette::Highlight);
        border.setAlpha(255);

        QPen bpen(_highlight && _showborder ? Qt::DashLine : Qt::DotLine);
        bpen.setWidth(devicePixelRatio);
        bpen.setCosmetic(true);
        bpen.setColor(border);
        painter->setPen(bpen);
        painter->drawRect(_rect);

        // Draw resizing handles
        if(_highlight) {
            QPen pen(border);
            pen.setCosmetic(true);
            pen.setWidth(HANDLE);
            painter->setPen(pen);
            painter->drawPoint(_rect.topLeft());
            painter->drawPoint(_rect.topLeft() + QPointF(_rect.width()/2, 0));
            painter->drawPoint(_rect.topRight());

            painter->drawPoint(_rect.topLeft() + QPointF(0, _rect.height()/2));
            painter->drawPoint(_rect.topRight() + QPointF(0, _rect.height()/2));

            painter->drawPoint(_rect.bottomLeft());
            painter->drawPoint(_rect.bottomLeft() + QPointF(_rect.width()/2, 0));
            painter->drawPoint(_rect.bottomRight());
        }
    }

    painter->restore();
}
Example #4
0
void AnnotationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
{
	Q_UNUSED(options);
	Q_UNUSED(widget);

	painter->save();
	painter->setClipRect(boundingRect().adjusted(0, 0, 1, 1));

	render(painter, _rect);

	if(_showborder || _text.isEmpty()) {
		QColor border = QApplication::palette().color(QPalette::Highlight);
		border.setAlpha(255);

		QPen bpen(_highlight && _showborder ? Qt::DashLine : Qt::DotLine);
		bpen.setCosmetic(true);
		bpen.setColor(border);
		painter->setPen(bpen);
		painter->drawRect(_rect);

		// Draw resizing handles
		if(_highlight) {
			QPen pen(border);
			pen.setCosmetic(true);
			painter->setPen(pen);

			drawTriangle(painter, RS_TOPLEFT, _rect.topLeft() + QPoint(2, 2));
			drawTriangle(painter, RS_TOP, _rect.topLeft() + QPoint(_rect.width()/ 2 + 2, 2));
			drawTriangle(painter, RS_TOPRIGHT, _rect.topRight() + QPoint(-2, 2));

			drawTriangle(painter, RS_LEFT, _rect.center() - QPoint(_rect.width()/2 - 2, 0));
			drawTriangle(painter, RS_RIGHT, _rect.center() + QPoint(_rect.width()/2 - 2, 0));

			drawTriangle(painter, RS_BOTTOMLEFT, _rect.bottomLeft() + QPoint(2, -2));
			drawTriangle(painter, RS_BOTTOM, _rect.bottomLeft() + QPoint(_rect.width()/ 2 + 2, -2));
			drawTriangle(painter, RS_BOTTOMRIGHT, _rect.bottomRight() + QPoint(-2, -2));
		}
	}
	painter->restore();
}
///
/// floating message
///
void FigurePainter::floatingMessage(PaintingContext& pc, const QString& message)
{
    //create background pen
    QPen bpen(QColor(pc.backColor.red(),
                     pc.backColor.green(),
                     pc.backColor.blue(),
                     pc.transparency),
              pc.lineWidth,
              pc.penStyle,
              pc.capStyle);

    QBrush brush(QColor(pc.backColor.red(),
                        pc.backColor.green(),
                        pc.backColor.blue(),
                        pc.transparency));
    //set canvas
    assert(pc.canvas);
    QPainter painter(pc.canvas);
    painter.setPen(bpen);
    painter.setBrush(brush);
    //paint rectangle
    painter.drawRect(pc.region);

    //create text pen
    QPen tpen(QColor(pc.textColor.red(),
                     pc.textColor.green(),
                     pc.textColor.blue(),
                     255/*pc.transparency*/),
              pc.lineWidth,
              pc.penStyle,
              pc.capStyle);
    //set canvas
    painter.setPen(tpen);
    //paint text
    painter.drawText(pc.region, Qt::AlignCenter, message);

    //end
    painter.end();
}
Example #6
0
void Ui::Ui_MainWindow::saveAsImage(QString path){
	QString str = textEdit->toPlainText();
	QFontMetrics fm(cFont);
	QSize textSize = fm.size(0,str);
	QImage pixmap(textSize, QImage::Format_RGB32);
	QPalette pal(textEdit->palette());
	QBrush bpen(pal.color(QPalette::Base));
	QPen fpen(pal.color(QPalette::Text));
	QPainter *pa=new QPainter(&pixmap);
	//pa->begin(&pixmap);
	pa->setFont(cFont);
	pa->setBrush(bpen);
	pa->drawRect(0,0,textSize.width(),textSize.height());
	pa->setPen(fpen);
	//pa->setBackground(bpen);
	//pa->setBackgroundMode(Qt::OpaqueMode);
	pa->drawText(0,fm.height(),textSize.width(),textSize.height(), Qt::AlignLeft | Qt::TextIncludeTrailingSpaces,str);
	//pa->drawLine(0,140,320,140);
	pa->end();
	pixmap.save(path);
	delete pa; pa = 0;
}
Example #7
0
void ChessBoard::renderBoard( QPainter &p, const QRectF &rc, bool flip,
    const std::vector<cheng4::Square> *excludeSquares )
{
    qreal maxh = std::max( rc.width(), rc.height() )/14;
    maxh = 18;
	qreal bordersz = maxh;
	if ( !border )
		bordersz = 0;
	qreal sw = (rc.width() - 2*bordersz) / 8;
	qreal sh = (rc.height() - 2*bordersz) / 8;
    sh = sw = std::min(sw, sh);

    QColor wb[2] = { QColor(255, 255, 255, 255), QColor(0, 0, 0, 255) };

	QColor bord = borderColor;

	QBrush lightb(lightColor);
	QBrush darkb(darkColor);
    p.setPen(Qt::transparent);
    // render border...
    p.setBrush( QBrush(bord) );
	p.drawRect(QRectF(rc.left(), rc.top(), 8*sw + 2*bordersz+1, 8*sh + 2*bordersz+1));

    QPen bpen( QColor(0, 0, 0, 128) );
    bpen.setWidth(1);
    p.setPen( bpen );
    p.setBrush( Qt::transparent );
    QRectF brect;
	brect.setTopLeft( QPoint(bordersz-1, bordersz-1) );
    brect.setSize( QSizeF(8*sw+2, 8*sh+2) );
    p.drawRect( brect );

    brect.setTopLeft( QPoint(0, 0) );
	brect.setSize( QSizeF(8*sw+2*bordersz, 8*sh+2*bordersz) );
    p.drawRect( brect );

    p.setPen( Qt::transparent );

    for (cheng4::Square s = 0; s < 64; s++)
    {
        cheng4::File f = cheng4::SquarePack::file(s);
        cheng4::Rank r = cheng4::SquarePack::rank(s);
		QRectF sub(rc.left() + sw*f + bordersz, rc.top() + sh*r + bordersz, sw, sh);
        cheng4::Square sq = flip ? cheng4::SquarePack::flipH(cheng4::SquarePack::flipV(s)) : s;


        p.setBrush( ((f+r) & 1) ? darkb : lightb );
        p.drawRect( sub );
        if ( excludeSquares && std::find(excludeSquares->begin(), excludeSquares->end(), sq)
             != excludeSquares->end() )
            continue;

        cheng4::Piece pc = board.piece(sq);
        cheng4::Piece pt = cheng4::PiecePack::type(pc);
        if ( pt == cheng4::ptNone )
            continue;
        cheng4::Color c = cheng4::PiecePack::color(pc);
		if ( !pieceSet || !pieceSet->pieces[c][pt-1] )
			continue;
        pieceSet->pieces[c][pt-1]->renderer()->render(&p, sub);
	}

	// FIXME: better!!!
	for (cheng4::Square s = 0; s < 64; s++)
	{
		cheng4::File f = cheng4::SquarePack::file(s);
		cheng4::Rank r = cheng4::SquarePack::rank(s);
		QRectF sub(rc.left() + sw*f + bordersz, rc.top() + sh*r + bordersz, sw, sh);
		cheng4::Square sq = flip ? cheng4::SquarePack::flipH(cheng4::SquarePack::flipV(s)) : s;
		// now highlight!!!
		if ( highlight == cheng4::mcNone || highlight == cheng4::mcNull )
			continue;
		cheng4::Square from, to;
		from = cheng4::MovePack::from(highlight);
		to = cheng4::MovePack::to(highlight);
		if ( sq != from && sq != to )
			continue;

		QPen hpen( highlightColor );
		hpen.setWidth(2);
		p.setPen( hpen );
		p.setBrush( Qt::transparent );
		p.drawRect( sub );
		p.setPen( Qt::transparent );
	}

	if ( !border )
		return;

    // draw board letters
	p.setPen( letterColor );
    QTextOption opt;
    opt.setAlignment(Qt::AlignCenter);
    QFont font;
    font.setBold(0);
    font.setPixelSize(12);
    p.setFont(font);
    for (uint i=0; i<8; i++)
    {
        // rows:
		QPointF pt( 0, bordersz + sh*i );
        QRectF rct;
        rct.setTopLeft( pt );
		rct.setSize( QSizeF( bordersz, sh ) );
        QString text;
        int irow = 7-(int)i;
        if ( flip )
            irow = 8-1-irow;
        text.sprintf("%d", irow+1);
        p.drawText(rct, text, opt);
		pt.setX( bordersz+sw*8 );
        rct.setTopLeft( pt );
		rct.setSize( QSizeF( bordersz, sh ) );
        p.drawText(rct, text, opt);
        // cols:
        int icol = (int)i;
        if ( flip )
            icol = 8-1-i;
        text.sprintf("%c", 'a' + icol);
		pt.setX( bordersz + sw*i );
        pt.setY( 0 );
        rct.setTopLeft(pt);
		rct.setSize( QSizeF( sw, bordersz ) );
        p.drawText(rct, text, opt);
		pt.setY( bordersz+sh*8 );
        rct.setTopLeft( pt );
		rct.setSize( QSizeF( sw, bordersz ) );
        p.drawText(rct, text, opt);
    }
    // draw stm
    QRectF upr;
	upr.setTopLeft( QPointF( bordersz + sw*8 + bordersz/8, bordersz/8 ) );
	upr.setSize( QSizeF( bordersz - 2*bordersz/8, bordersz - 2*bordersz/8 ) );

    bool upper = board.turn() == (flip ? cheng4::ctWhite : cheng4::ctBlack);

    p.setPen( wb[ cheng4::flip(board.turn()) ] );
    p.setBrush( wb[ board.turn() ] );

    if ( upper )
        p.drawRect( upr );

    QRectF lwr;
	lwr.setTopLeft( QPointF( bordersz + sw*8 + bordersz/8, bordersz + sh*8 + bordersz/8 ) );
	lwr.setSize( QSizeF( bordersz - 2*bordersz/8, bordersz - 2*bordersz/8 ) );

    if ( !upper )
        p.drawRect( lwr );
}