示例#1
0
void Kanagram::drawText(QPainter &p, const QString &text, const QPoint &center, bool withMargin, int xMargin, int yMargin, QRect *rect, bool highlight, int fontSize)
{
	QRect r;
	QFont font = m_blackboardFont;
	font.setPointSize(fontSize);
	font.setBold(true);
	p.setFont(font);
	
	r = p.boundingRect(QRect(), Qt::AlignAuto, text);
	r = QRect(0, 0, r.width() + xMargin, r.height() + yMargin);
	r.moveBy(center.x() - r.width() / 2, center.y() - r.height() / 2);

	if (withMargin)
	{
		p.fillRect(r, m_fillColor);
		p.setPen(QPen(black, 3));
		p.drawRoundRect(r.left(), r.top(), r.width(), r.height(), 15, 15);
	}
	
	if (!highlight) p.setPen(m_chalkColor);
	else p.setPen(m_chalkHighlightColor);
	p.drawText(r, Qt::AlignCenter, text);
	
	if(rect) *rect = r;
}
示例#2
0
void PlayField::paintEvent( QPaintEvent * )
{
    QPixmap pm( size() );
    QPainter p;
    p.begin(&pm);
    p.setBrush( Qt::black );
    p.drawRect( 0, 0, width(), height() );
    if ( mode==None ) {
	ItemListConstIterator it = items.begin();
	while( it!=items.end() ) {
	    const PlayFieldItem item = *it;
	    if( item.enabled )
		p.drawPixmap( item.x, item.y, item.pixmap );
	    it++;
	}
    } else {
	p.setPen( Qt::white );
	p.setFont( QFont( "serif", 20 ) );
	QString s = mode==Win ? "You won!!" : "Game over";
	QRect r = p.boundingRect( QRect(), 0, s );
	p.drawText( width()/2-r.width()/2, height()/2-r.height()/2, s );
    }
    p.end();
    
    QPainter(this).drawPixmap(0, 0, pm);
}
示例#3
0
void QUProfileController::drawLoadingMessage(QPainter & p)
{
    if( avail() < m_total || m_total == 0)
    {
        p.save();
        p.setFont ( m_captionFont);
        p.setOpacity(1);
        QString txt = QString( "Loading %1/%2").arg( avail()).arg(m_total);
        QRectF anchor( m_buffer.width()/2.0, m_buffer.height()/2.0, 1, 1);
        QRectF brect = p.boundingRect(
                    anchor,  Qt::AlignCenter | Qt::TextDontClip,
                    txt);
        brect.adjust( -3, -3, 3, 3);
        QColor bg( 255, 255, 255, 225);
        QColor border( 128, 0, 0, 225);
        p.setPen( border);
        p.setBrush( bg);
        p.drawRoundedRect( brect, 5, 5);
        p.setPen( QColor(0, 0, 0));
        p.drawText(anchor,  Qt::AlignCenter | Qt::TextDontClip,
                   txt);
        p.setPen( QPen(QColor( 0, 0, 0, 128), 1, Qt::DashLine));
        p.restore();
    }
}
示例#4
0
void Kanagram::drawSwitcher(QPainter &p, const int xMargin, const int yMargin)
{
	const int padding = 5;
	QString text = m_game->getDocTitle();
	QFont font = m_blackboardFont;
	font.setPointSize(14);
	QFontMetrics fm(font);
	QRect r = innerRect(m_blackboardRect, xMargin, yMargin);
	r.normalize();
	r.moveBy(- padding - (m_overSwitcher ? m_arrowOver : m_arrow )->width(), yMargin);
	r.setHeight( (m_overSwitcher ? m_arrowOver : m_arrow )->height());
	m_switcherRect = p.boundingRect(r, Qt::AlignVCenter|Qt::AlignRight, text);
	p.setFont(font);
	if (m_overSwitcher)
	{
		p.setPen(m_chalkHighlightColor);
		p.drawPixmap(m_switcherRect.right() + padding, m_switcherRect.top(), *m_arrowOver);
	}
	else
	{
		p.setPen(m_chalkColor);
		p.drawPixmap(m_switcherRect.right() + padding, m_switcherRect.top(), *m_arrow);
	}
	m_switcherRect.moveBy(0, -2);
	p.drawText(m_switcherRect, Qt::AlignVCenter|Qt::AlignRight, text);
}
示例#5
0
void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p,
	int h, double start, double end, int y, const ViewItemPaintParams &pp,
	int row_title_width) const
{
	const double top = y + .5 - h / 2;
	const double bottom = y + .5 + h / 2;
	const vector<QString> annotations = a.annotations();

	// If the two ends are within 1 pixel, draw a vertical line
	if (start + 1.0 > end) {
		p.drawLine(QPointF(start, top), QPointF(start, bottom));
		return;
	}

	const double cap_width = min((end - start) / 4, EndCapWidth);

	QPointF pts[] = {
		QPointF(start, y + .5f),
		QPointF(start + cap_width, top),
		QPointF(end - cap_width, top),
		QPointF(end, y + .5f),
		QPointF(end - cap_width, bottom),
		QPointF(start + cap_width, bottom)
	};

	p.drawConvexPolygon(pts, countof(pts));

	if (annotations.empty())
		return;

	const int ann_start = start + cap_width;
	const int ann_end = end - cap_width;

	const int real_start = std::max(ann_start, pp.left() + row_title_width);
	const int real_end = std::min(ann_end, pp.right());
	const int real_width = real_end - real_start;

	QRectF rect(real_start, y - h / 2, real_width, h);
	if (rect.width() <= 4)
		return;

	p.setPen(Qt::black);

	// Try to find an annotation that will fit
	QString best_annotation;
	int best_width = 0;

	for (const QString &a : annotations) {
		const int w = p.boundingRect(QRectF(), 0, a).width();
		if (w <= rect.width() && w > best_width)
			best_annotation = a, best_width = w;
	}

	if (best_annotation.isEmpty())
		best_annotation = annotations.back();

	// If not ellide the last in the list
	p.drawText(rect, Qt::AlignCenter, p.fontMetrics().elidedText(
		best_annotation, Qt::ElideRight, rect.width()));
}
示例#6
0
QImage TextToolDlg::image()
{
    QBitmap bitmap(1000, 100);
    QPainter painter;

    painter.begin(&bitmap);
    QFont font = painter.font();
    font.setFamily(m_font.family());
    font.setPixelSize(m_size);
    painter.setFont(font);
    painter.setPen(QPen(Qt::color0));
    QRect boundingRect = painter.boundingRect(0, 0, 1000, 100, Qt::AlignLeft | Qt::AlignTop, m_text);
    painter.end();

    int boundingWidth = boundingRect.width();
    int boundingHeight = boundingRect.height();
    bitmap = bitmap.copy(0, 0, boundingWidth, boundingHeight); // a resize
    painter.begin(&bitmap);
    painter.setFont(font);
    bitmap.fill(Qt::color0);
    painter.setPen(QPen(Qt::color1));
    painter.drawText(0, 0, boundingWidth, boundingHeight, Qt::AlignLeft | Qt::AlignTop, m_text);
    painter.end();

    QImage image = bitmap.toImage();

    return image;
}
const QPixmap &PlastikClient::captionPixmap() const
{
    bool active = isActive();

    if (m_captionPixmaps[active]) {
        return *m_captionPixmaps[active];
    }

    // not found, create new pixmap...

    const int maxCaptionLength = 300; // truncate captions longer than this!
    QString c(caption() );
    if (c.length() > maxCaptionLength) {
        c.truncate(maxCaptionLength);
        c.append(" [...]");
    }

    QFontMetrics fm(s_titleFont);
    int captionWidth  = fm.width(c);
    int captionDescent = fm.descent();

    QFontMetrics fm_vmname(s_vmnameFont);
    captionWidth  += fm_vmname.width(qubes_vmname);
    if (fm_vmname.descent() > fm.descent()) captionDescent = fm_vmname.descent();

    const int th  = layoutMetric(LM_TitleHeight, false) + layoutMetric(LM_TitleEdgeBottom, false);

    QPainter painter;

    const int thickness = 2;

    QPixmap *captionPixmap = new QPixmap(captionWidth+2*thickness, th);

    painter.begin(captionPixmap);
    painter.drawTiledPixmap(captionPixmap->rect(),
                            Handler()->pixmap(qubes_label, TitleBarTile, active, isToolWindow()) );

    painter.setFont(s_vmnameFont);
    QRect boundingRect1 = painter.boundingRect(captionPixmap->rect(),
                                              Qt::AlignVCenter | Qt::AlignLeft, qubes_vmname);

    QPoint tp1 = boundingRect1.bottomLeft() - QPoint(0, captionDescent);
    QPoint tp2 = tp1 + QPoint (fm_vmname.width(qubes_vmname) + 5, 0);

    QColor fontColor = Handler()->getColor(qubes_label, TitleFont,active);

    painter.setPen(fontColor );

    painter.drawText(tp1, qubes_vmname );

    painter.setFont(s_titleFont);
    painter.drawText(tp2, c );

    painter.end();

    m_captionPixmaps[active] = captionPixmap;
    return *captionPixmap;
}
示例#8
0
//============================================================================================
//void DrawText(QPainter& painter, qreal dopangle, const qreal xoff, const qreal yoff, const QString& text)
//void DrawText(QPainter& painter, const qreal xoff, const qreal yoff, const QString& text)
void DrawText(QPainter& painter, const qreal xoff, const qreal yoff, const qreal angle)
{
  QString text;  text.sprintf(("%.0f"),angle);
//  painter.rotate(dopangle);
  QRectF rectF = painter.boundingRect(QRectF(0,0, 500,500), text, QTextOption(Qt::AlignCenter));
//  painter.drawText(QRectF(-rectF.width()/2.0-0.5 + xoff, -rectF.height()/2.0-0.5 + yoff, rectF.width(),rectF.height()), text, QTextOption(Qt::AlignHCenter | Qt::AlignBottom));
//  painter.drawText(QRectF(-rectF.width()/2.0-0.5 + xoff, -rectF.height() + yoff, rectF.width(),rectF.height()), text, QTextOption(Qt::AlignCenter));
  painter.drawText(QRectF(-rectF.width()/2.0-0.5 + xoff, -rectF.height()/2.0-0.5 + yoff, rectF.width(),rectF.height()), text, QTextOption(Qt::AlignCenter));
}
示例#9
0
void TextPainter::calculate()
{
    QImage image(100, 100, QImage::Format_RGB32);
    QPainter painter;
    painter.begin(&image);
    int textFlags = Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine;
    QRect charRect = painter.boundingRect(image.rect(), textFlags, QString(QChar(48)));
    m_charHeight = charRect.height();
    m_charWidth = charRect.width();
    painter.end();
}
示例#10
0
void DecodeTrace::draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
	int h, double x, int y) const
{
	const QString text = a.annotations().empty() ?
		QString() : a.annotations().back();
	const double w = min((double)p.boundingRect(QRectF(), 0, text).width(),
		0.0) + h;
	const QRectF rect(x - w / 2, y - h / 2, w, h);

	p.drawRoundedRect(rect, h / 2, h / 2);

	p.setPen(Qt::black);
	p.drawText(rect, Qt::AlignCenter | Qt::AlignVCenter, text);
}
示例#11
0
  void Annotation1DTextItem::draw(Spectrum1DCanvas * const canvas, QPainter & painter, bool flipped)
  {
    //translate mz/intensity to pixel coordinates
    QPoint pos;
    canvas->dataToWidget(position_.getX(), position_.getY(), pos, flipped, true);

    // compute bounding box of text_item on the specified painter
    bounding_box_ = painter.boundingRect(QRectF(pos, pos), flags_, text_);

    painter.drawText(bounding_box_, flags_, text_);
    if (selected_)
    {
      drawBoundingBox_(painter);
    }
  }
示例#12
0
//-----------------------------------------------------------------------------
void XAxisWidget::paintEvent(QPaintEvent*)
{
    pixel_per_sec_ = signal_view_settings_->getPixelsPerSample() * signal_view_settings_->getSampleRate();
    intervall_ = pixel_per_sec_ * MathUtils_::round125 (100.0 / pixel_per_sec_);

    if (intervall_ < 1 )
    {
        return; // invalid intervall
    }
    int32 x_end = x_start_ + width();
    int32 font_height = height() - 5;

    QPainter p (this);

    p.setPen (Qt::black);
    p.translate(-x_start_, 0);
    p.drawLine(x_start_, 0, x_end, 0);
    float64 float_x_start = floor((x_start_ + intervall_ / 2) / intervall_) *
                           intervall_;

    float64 float_x_end = ceil((x_end - intervall_ / 2) / intervall_) *
                          intervall_ + intervall_ / 2;

    for (float32 float_x = float_x_start;
         float_x < float_x_end;
         float_x += intervall_)
    {
        int32 x = (int32)(float_x + 0.5);
        p.drawLine(x, 0, x, 5);
        p.drawText((int32)(x - intervall_ / 2), 5, (int32)intervall_, font_height,
                   Qt::AlignHCenter | Qt::AlignVCenter,
                   QString::number(float_x / pixel_per_sec_));
    }

    if (highlighting_enabled_)
    {
        QFont font;
        font.setPointSizeF (font.pointSizeF() * 1.5);
        font.setBold (true);
        p.setFont (font);
        QRect bounding_rect = p.boundingRect (0, 0, 0, font.pixelSize(), Qt::AlignHCenter | Qt::AlignVCenter, QString::number(time_to_highlight_, 'f', 3));
        bounding_rect.moveTo (time_to_highlight_ * pixel_per_sec_, 5);
        p.fillRect (bounding_rect, Qt::white);
        p.setPen (Qt::black);
        p.drawText (bounding_rect, Qt::AlignLeft | Qt::AlignTop, QString::number(time_to_highlight_, 'f', 2));
        last_highlight_rect_ = bounding_rect;
    }
}
示例#13
0
void FieldView::drawText(QPainter& p, QPointF pos, QString text, bool center) {
    p.save();
    p.translate(pos);
    p.rotate(_textRotation);
    p.scale(0.008, -0.008);

    if (center) {
        int flags = Qt::AlignHCenter | Qt::AlignVCenter;
        QRectF r = p.boundingRect(QRectF(), flags, text);
        p.drawText(r, flags, text);
    } else {
        p.drawText(QPointF(), text);
    }

    p.restore();
}
void ResizeViewTool::paintEvent(QPainter &p, QPaintEvent *e) {
    p.save();
    p.setBrush(QBrush(Qt::white, Qt::BDiagPattern));
    p.setPen(Qt::white);
    QSize viewport(parentView->viewport()->size());
    QRect rect(viewport.width()/2-imageSize.width()/2,
            viewport.height()/2-imageSize.height()/2,
            imageSize.width(), imageSize.height());
    p.drawRect(rect);
    p.setPen(Qt::black);
    QString text(tr("This box shows how large the resulting image will be."));
    QRect textRect(p.boundingRect(rect, Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextWordWrap, text));
    p.fillRect(rect.intersect(textRect), QColor(255, 255, 255, 128));
    p.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextWordWrap, text);
    p.restore();
}
示例#15
0
void DecodeTrace::draw_error(QPainter &p, const QString &message,
	const ViewItemPaintParams &pp)
{
	const int y = get_visual_y();

	p.setPen(ErrorBgColour.darker());
	p.setBrush(ErrorBgColour);

	const QRectF bounding_rect =
		QRectF(pp.width(), INT_MIN / 2 + y, pp.width(), INT_MAX);
	const QRectF text_rect = p.boundingRect(bounding_rect,
		Qt::AlignCenter, message);
	const float r = text_rect.height() / 4;

	p.drawRoundedRect(text_rect.adjusted(-r, -r, r, r), r, r,
		Qt::AbsoluteSize);

	p.setPen(Qt::black);
	p.drawText(text_rect, message);
}
QSize QColorTabWidget::calcTabSize( QPainter& p, const TabInfo& ti )
{
    p.setFont(m_fntTab);

    QRectF rectText(0,0,0,0);

    if( isHorzTab() )
    {
        rectText.setHeight((float)m_sizeTabHeader.height());
    }
    else
    {
        rectText.setWidth((float)m_sizeTabHeader.width());
    }

    QString strCaption = ti.strCaption;
    int flags = Qt::AlignLeft|Qt::AlignVCenter|Qt::TextSingleLine;

    QRectF rectBB = p.boundingRect( rectText, flags, strCaption );
    //p.drawText( rectText, flags, strCaption, &rectBB );

    float fImageOffset = 0.f;
    if( ti.pIconImage )
    {
        fImageOffset = ti.pIconImage->width() + 5.f;
    }

    if( isHorzTab() )
    {
        rectBB.setWidth( rectBB.width() + fImageOffset + 15.f );
    }
    else
    {
        rectBB.setWidth( rectBB.width() + fImageOffset );
        rectBB.setHeight( rectBB.height() + 15.f );
    }


    return QSize( (int)(rectBB.width() + .5f), (int)(rectBB.height() + .5f) );
}
示例#17
0
void paint_QPixmapCachedText(QPainter &p)
{
    static bool first = true;
    static QPixmap cacheText[lines];
    if (first) {
        for (int i = 0; i < lines; ++i) {
            QRectF trueSize;
            trueSize = p.boundingRect(QRectF(QPointF(0,0), size), 0, strings[i]);
            cacheText[i] = QPixmap(trueSize.size().toSize());
            cacheText[i].fill(Qt::transparent);
            QPainter paint(&cacheText[i]);
            paint.setPen(Qt::black);
            paint.drawText(QRectF(QPointF(0,0), trueSize.size().toSize()), strings[i]);
        }
        first = false;
    }
    for (int i = 0; i < count; i++) {
        for (int j = 0; j < lines; ++j) {
            p.drawPixmap(0,j*spacing,cacheText[j]);
        }
    }
}
示例#18
0
void GELabel::draw(QPainter& painter)
{
    painter.save();
    painter.setPen(QPen(m_active_color));

    QPointF anchor_latlon = m_anchor->getAnchor();
    QPointF anchor_xy;
    MYASSERT(m_projection->convertLatLonToXY(anchor_latlon, anchor_xy));
    QPointF lefttop_xy = anchor_xy + m_diff_xy;
    
    QRectF text_rect = QRectF(lefttop_xy.x(), lefttop_xy.y(), 500, 100);
    m_rect = painter.boundingRect(text_rect, Qt::AlignLeft|Qt::AlignTop, m_text);

    if (m_draw_line_to_anchor)
    {
        painter.drawLine(anchor_xy, m_rect.center());
        painter.fillRect(m_rect, QBrush(Qt::white));
    }

    if (m_draw_border) painter.drawRect(m_rect);
    painter.drawText(m_rect, m_text);
    painter.restore();
}
示例#19
0
void Matrix::print(QPrinter *printer)
{
	if (!printer)
		return;

	QPainter p;
	if ( !p.begin(printer))
		return; // paint on printer

	int dpiy = printer->logicalDpiY();
	const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins

	if (d_view_type == ImageView){
		p.drawImage (printer->pageRect(), d_matrix_model->renderImage());
		return;
	}

	QHeaderView *vHeader = d_table_view->verticalHeader();

	int rows = numRows();
	int cols = numCols();
	int height = margin;
	int i, vertHeaderWidth = vHeader->width();
	int right = margin + vertHeaderWidth;

	// print header
	p.setFont(QFont());
	QString header_label = d_matrix_model->headerData(0, Qt::Horizontal).toString();
	QRect br = p.boundingRect(br, Qt::AlignCenter, header_label);
	p.drawLine(right, height, right, height+br.height());
	QRect tr(br);

	for(i=0; i<cols; i++){
		int w = d_table_view->columnWidth(i);
		tr.setTopLeft(QPoint(right,height));
		tr.setWidth(w);
		tr.setHeight(br.height());
		header_label = d_matrix_model->headerData(i, Qt::Horizontal).toString();
		p.drawText(tr, Qt::AlignCenter, header_label,-1);
		right += w;
		p.drawLine(right, height, right, height+tr.height());

		if (right >= printer->width()-2*margin )
			break;
	}

	p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
	height += tr.height();
	p.drawLine(margin, height, right-1, height);

	// print table values
	for(i=0;i<rows;i++){
		right = margin;
		QString cell_text = d_matrix_model->headerData(i, Qt::Horizontal).toString()+"\t";
		tr = p.boundingRect(tr, Qt::AlignCenter, cell_text);
		p.drawLine(right, height, right, height+tr.height());

		br.setTopLeft(QPoint(right,height));
		br.setWidth(vertHeaderWidth);
		br.setHeight(tr.height());
		p.drawText(br,Qt::AlignCenter,cell_text,-1);
		right += vertHeaderWidth;
		p.drawLine(right, height, right, height+tr.height());

		for(int j=0; j<cols; j++){
			int w = d_table_view->columnWidth (j);
			cell_text = text(i,j)+"\t";
			tr = p.boundingRect(tr,Qt::AlignCenter,cell_text);
			br.setTopLeft(QPoint(right,height));
			br.setWidth(w);
			br.setHeight(tr.height());
			p.drawText(br, Qt::AlignCenter, cell_text, -1);
			right += w;
			p.drawLine(right, height, right, height+tr.height());

			if (right >= printer->width()-2*margin )
				break;
		}
		height += br.height();
		p.drawLine(margin, height, right-1, height);

		if (height >= printer->height()-margin ){
			printer->newPage();
			height = margin;
			p.drawLine(margin, height, right, height);
		}
	}
	p.end();
}
示例#20
0
void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
{
    (void)prefix;
    _text_size = p.boundingRect(QRect(), 0,
        Ruler::format_real_time(_index, _view.session().cur_samplerate())).size();
}
示例#21
0
void RCDraw::paintEvent ( QPaintEvent * )
{
	QString s;
	QPainter painter ( this );
	painter.setRenderHint(QPainter::HighQualityAntialiasing);

	if ( qimg != NULL )
	{
		painter.drawImage ( QRectF(0., 0., imageScale*width, imageScale*height), *qimg, QRectF(0, 0, width, height) );
	}

	painter.setWindow (effWin.toRect() );

	if ( DRAW_PERIMETER )
	{
		painter.setPen ( Qt::blue );
		painter.drawRect ( 0,0,width-1,height-1 );
	}
	if ( DRAW_AXIS )
	{
		drawAxis(Qt::blue, 2);
	}

	//Draw lines
	while ( !lineQueue.isEmpty() )
	{
		TLine l = lineQueue.dequeue();
		if (invertedVerticalAxis) l.line = QLineF(l.line.x1()-visibleCenter(0), -l.line.y1()+visibleCenter(1), l.line.x2()-visibleCenter(0), -l.line.y2()+visibleCenter(1));
		else l.line.translate(-visibleCenter(0), -visibleCenter(1));
		painter.setPen ( QPen ( QBrush ( l.color ),l.width ) );
		painter.drawLine ( l.line );
	}

	//Draw gradient
	while ( !gradQueue.isEmpty() )
	{
		TGrad g = gradQueue.dequeue();
		if (invertedVerticalAxis) g.line = QLine(g.line.x1()-visibleCenter(0), -g.line.y1()+visibleCenter(1), g.line.x2()-visibleCenter(0), -g.line.y2()+visibleCenter(1));
		else g.line.translate(-visibleCenter(0), -visibleCenter(1));
		linGrad.setColorAt ( 0, g.color );
		linGrad.setColorAt ( 1, g.color1 );
		painter.setBrush ( linGrad );
		painter.setPen ( QPen ( linGrad, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
		painter.drawLine ( g.line );
	}

	//Draw ellipses
	while ( !ellipseQueue.isEmpty() )
	{
		TEllipse e = ellipseQueue.dequeue();
		if (invertedVerticalAxis) e.center.setY(-(e.center.y()-visibleCenter(1)));
		else e.center = QPointF(e.center.x()-visibleCenter(0), e.center.y()-visibleCenter(1));
		if ( e.fill == true )
			painter.setBrush ( e.color );
		else
			painter.setBrush ( Qt::transparent );
		painter.setPen ( e.color );
		if (fabs(e.ang) > 0.1)
		{
			painter.setPen ( e.color );
			painter.translate( e.center );
			painter.rotate( e.ang );
			painter.drawEllipse ( QPointF(0,0), e.rx, e.ry );
			painter.rotate( -e.ang );
			painter.translate( -e.center );
		}
		else
			painter.drawEllipse( e.center, e.rx, e.ry);
	}

	//Draw squares
	{
		QPen pen = painter.pen();
		int penwidth = pen.width();
		while ( !squareQueue.isEmpty() )
		{
			TRect r = squareQueue.dequeue();
			if (invertedVerticalAxis) r.rect = QRect(r.rect.x()-visibleCenter(0), -r.rect.y()+visibleCenter(1)-r.rect.height(), r.rect.width(), r.rect.height());
			else r.rect.translate(-visibleCenter(0),-visibleCenter(1));
			if ( r.fill == true )
				painter.setBrush ( r.color );
			else
				painter.setBrush ( Qt::transparent );
			pen.setColor(r.color);
			pen.setWidth(r.width);
			painter.setPen(pen);
			if (fabs(r.ang) > 0.01 )
			{
				QPointF center = r.rect.center();
				painter.translate( center );
				painter.rotate( r.ang );
				painter.drawRect ( QRectF( r.rect.topLeft() - center, r.rect.size() ));
				painter.rotate( -r.ang );
				painter.translate( -center );
			}
			else
				painter.drawRect( r.rect );
		}
		pen.setWidth(penwidth);
		painter.setPen(pen);
	}


	while ( !lineOnTopQueue.isEmpty() )
	{
		TLine l = lineOnTopQueue.dequeue();
		l.line.translate(-visibleCenter(0), -visibleCenter(1));
		painter.setPen ( QPen ( QBrush ( l.color ),l.width ) );
		painter.drawLine ( l.line );
	}


	//Draw text
	while ( !textQueue.isEmpty() )
	{
		TText t = textQueue.dequeue();
		painter.setWindow ( effWin.normalized().toRect() );
		QFont ant = painter.font();
		QFont temp ( "Helvetica", t.size );
		painter.setFont ( temp );

		QRectF rect = painter.boundingRect(QRectF(t.pos.x(), t.pos.y(), 1, 1), Qt::AlignLeft, t.text);
		if (not t.centered)
		{
			painter.setPen(t.bgc);
			painter.setBrush(t.bgc);
			painter.drawRect(rect);
			painter.setBrush ( Qt::transparent );
			painter.setPen ( t.color );
			painter.drawText( QRectF(t.pos.x(), t.pos.y(), 0.82*t.text.size()*t.size, 1.2*t.size), Qt::AlignCenter, t.text);
		}
		else
		{
			rect.translate(-rect.width()/2., -rect.height()/2.);
			painter.setPen(t.bgc);
			painter.setBrush(t.bgc);
			painter.drawRect(rect);
			painter.setBrush ( Qt::transparent );
			painter.setPen ( t.color );
			painter.drawText(rect, Qt::AlignLeft, t.text);
		}

		painter.setFont ( ant );
		painter.setWindow ( effWin.toRect() );
	}


}
示例#22
0
void CursorPair::compute_text_size(QPainter &p, unsigned int prefix)
{
	_text_size = p.boundingRect(QRectF(), 0, Ruler::format_time(
		_second.time() - _first.time(), prefix, 2)).size();
}
示例#23
0
文件: export.cpp 项目: swpease/Xword
void Export::export_pdf(int columns)
{
    // 1200 dpi -> 200 dpi ~ 12pt font;
    // dims: 9583 x 13699

    int twelve_point = 200;
    int total_width = 9583;
    int total_height = 13699;
    int remaining_height = total_height;
    int puzzle_width = columns > 15 ? 6000 : 5000;
    int puzzle_height = puzzle_width;
    int clues_three_cols_width = total_width - puzzle_width;
    int clues_col_width_w_gap = clues_three_cols_width / 3;
    int col_gap = 225;  // empirically determined
    int clues_col_width = clues_col_width_w_gap - col_gap;
    int col_num = 1;

    //metadata
    QString title = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString date = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString author = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString author_date = author + "          " + date;

    QRect title_rect(0, 0, total_width, (twelve_point * 2));
    remaining_height -= (twelve_point * 2);

    QPoint info_top_left(0, (title_rect.bottom() + 100));
    QSize author_date_size((total_width - puzzle_width), twelve_point);
    QRect author_date_rect(info_top_left, author_date_size);
    remaining_height -= (twelve_point + 100);

    //clues
    QPoint clues_col_top_left(0, (author_date_rect.bottom() + 300));
    remaining_height -= 300;
    QSize clues_col_size(clues_col_width, remaining_height);
    QRect whole_clues_col(clues_col_top_left, clues_col_size);
    QRect eaten_clues_col = whole_clues_col;

    //puzzles
    QImage puzzle = qvariant_cast<QImage>(m_images.takeAt(0));
    QImage puz_ans = qvariant_cast<QImage>(m_images.takeAt(0));
    QSize puz_size(puzzle_width, puzzle_height);
    QPoint puz_top_left((total_width - puzzle_width), title_rect.bottom());
    QRect puz_rect(puz_top_left, puz_size);
    QRect ans_rect(0, 0, (puzzle_width / 2), (puzzle_height / 2));

    //filepath
    QString base_path = QDir::homePath();
    QString file_name = title == "" ? "/untitled.pdf" : "/" + title + ".pdf";

    // PAINTING //
    QPdfWriter pdf(base_path + file_name);
    QPainter painter;

    // getting info on available space in the appropriate units (used for the seemingly random
    // numbers for the constants at the start of the function).
//    QPageLayout layout = pdf.pageLayout();
//    int resolution = pdf.resolution();
//    QRect printable_rect = layout.paintRectPixels(resolution);

    painter.begin(&pdf);

    // make the title
    QFont font = painter.font();
    font.setPixelSize(twelve_point * 2);
    font.setCapitalization(QFont::SmallCaps);
    painter.setFont(font);
    painter.drawText(title_rect, title);

    // make author and date
    font.setPixelSize(twelve_point / 2);
    font.setCapitalization(QFont::MixedCase);
    font.setItalic(true);
    painter.setFont(font);
    painter.drawText(author_date_rect, author_date);

    // across header
    font.setPixelSize(150);
    font.setBold(true);
    font.setItalic(false);
    painter.setFont(font);

    QString across_header = qvariant_cast<QString>(m_acrosses.takeAt(0));
    QRect space_needed = painter.boundingRect(eaten_clues_col, Qt::TextWordWrap, across_header);
    draw_clue(painter, eaten_clues_col, across_header, space_needed, Qt::AlignHCenter);
    eaten_clues_col.setTop(eaten_clues_col.top() + 100);  //ref: Export::paint_clues

    // across clues
    font.setBold(false);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, m_acrosses, col_num, whole_clues_col, col_gap, puz_rect);

    // down header
    QVariantList down_header;
    down_header.append(m_downs.takeAt(0));  // is there a better way?

    font.setBold(true);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, down_header, col_num, whole_clues_col,
                col_gap, puz_rect, Qt::AlignHCenter);

    // down clues
    font.setBold(false);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, m_downs, col_num, whole_clues_col, col_gap, puz_rect);

    // images
    painter.drawImage(puz_rect, puzzle);
    pdf.newPage();
    painter.drawImage(ans_rect, puz_ans);

    painter.end();

    emit export_completed(file_name);
}
示例#24
0
void Trace::compute_text_size(QPainter &p)
{
    _text_size = QSize(
        p.boundingRect(QRectF(), 0, "99").width(),
        p.boundingRect(QRectF(), 0, "99").height());
}
示例#25
0
void Matrix::print(const QString& fileName)
{
	QPrinter printer;
	printer.setColorMode (QPrinter::GrayScale);

	if (!fileName.isEmpty()){
	    printer.setCreator("QtiPlot");
	    printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
	} else {
        QPrintDialog printDialog(&printer, applicationWindow());
        if (printDialog.exec() != QDialog::Accepted)
            return;
    }
		printer.setFullPage( true );
		QPainter p;
		if ( !p.begin(&printer ) )
			return; // paint on printer
		int dpiy = printer.logicalDpiY();
		const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins

        if (d_view_type == ImageView){
            p.drawImage (printer.pageRect(), d_matrix_model->renderImage());
            return;
        }

		QHeaderView *vHeader = d_table_view->verticalHeader();

		int rows = numRows();
		int cols = numCols();
		int height = margin;
		int i, vertHeaderWidth = vHeader->width();
		int right = margin + vertHeaderWidth;

		// print header
		p.setFont(QFont());
		QString header_label = d_matrix_model->headerData(0, Qt::Horizontal).toString();
		QRect br = p.boundingRect(br, Qt::AlignCenter, header_label);
		p.drawLine(right, height, right, height+br.height());
		QRect tr(br);

		for(i=0; i<cols; i++){
			int w = d_table_view->columnWidth(i);
			tr.setTopLeft(QPoint(right,height));
			tr.setWidth(w);
			tr.setHeight(br.height());
			header_label = d_matrix_model->headerData(i, Qt::Horizontal).toString();
			p.drawText(tr, Qt::AlignCenter, header_label,-1);
			right += w;
			p.drawLine(right, height, right, height+tr.height());

			if (right >= printer.width()-2*margin )
				break;
		}

		p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
		height += tr.height();
		p.drawLine(margin, height, right-1, height);

		// print table values
		for(i=0;i<rows;i++){
			right = margin;
			QString cell_text = d_matrix_model->headerData(i, Qt::Horizontal).toString()+"\t";
			tr = p.boundingRect(tr, Qt::AlignCenter, cell_text);
			p.drawLine(right, height, right, height+tr.height());

			br.setTopLeft(QPoint(right,height));
			br.setWidth(vertHeaderWidth);
			br.setHeight(tr.height());
			p.drawText(br,Qt::AlignCenter,cell_text,-1);
			right += vertHeaderWidth;
			p.drawLine(right, height, right, height+tr.height());

			for(int j=0; j<cols; j++){
				int w = d_table_view->columnWidth (j);
				cell_text = text(i,j)+"\t";
				tr = p.boundingRect(tr,Qt::AlignCenter,cell_text);
				br.setTopLeft(QPoint(right,height));
				br.setWidth(w);
				br.setHeight(tr.height());
				p.drawText(br, Qt::AlignCenter, cell_text, -1);
				right += w;
				p.drawLine(right, height, right, height+tr.height());

				if (right >= printer.width()-2*margin )
					break;
			}
			height += br.height();
			p.drawLine(margin, height, right-1, height);

			if (height >= printer.height()-margin ){
				printer.newPage();
				height = margin;
				p.drawLine(margin, height, right, height);
			}
		}
}
示例#26
0
void Matrix::print()
{
QPrinter printer;
printer.setColorMode (QPrinter::GrayScale);
if (printer.setup()) 
	{
        printer.setFullPage( TRUE );
        QPainter p;
        if ( !p.begin(&printer ) )
            return; // paint on printer
        QPaintDeviceMetrics metrics( p.device() );
        int dpiy = metrics.logicalDpiY();
        const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins
		
		QHeader *hHeader = d_table->horizontalHeader();
		QHeader *vHeader = d_table->verticalHeader();

		int rows=d_table->numRows();
		int cols=d_table->numCols();
		int height=margin;
		int i,vertHeaderWidth=vHeader->width();
		int right = margin + vertHeaderWidth;
		
		// print header
		p.setFont(QFont());
		QRect br=p.boundingRect(br,Qt::AlignCenter,	hHeader->label(0),-1,0);
		p.drawLine(right,height,right,height+br.height());
		QRect tr(br);	
		
		for (i=0;i<cols;i++)
			{	
			int w=d_table->columnWidth (i);
			tr.setTopLeft(QPoint(right,height));
			tr.setWidth(w);	
			tr.setHeight(br.height());
			p.drawText(tr,Qt::AlignCenter,hHeader->label(i),-1);
			right+=w;
			p.drawLine(right,height,right,height+tr.height());
			
			if (right >= metrics.width()-2*margin )
				break;
			}
		p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
		height+=tr.height();	
		p.drawLine(margin,height,right-1,height);		
		
		// print d_table values
		for (i=0;i<rows;i++)
			{
			right=margin;
			QString text=vHeader->label(i)+"\t";
			tr=p.boundingRect(tr,Qt::AlignCenter,text,-1,0);
			p.drawLine(right,height,right,height+tr.height());

			br.setTopLeft(QPoint(right,height));	
			br.setWidth(vertHeaderWidth);	
			br.setHeight(tr.height());
			p.drawText(br,Qt::AlignCenter,text,-1);
			right+=vertHeaderWidth;
			p.drawLine(right,height,right,height+tr.height());

			for (int j=0;j<cols;j++)
				{
				int w=d_table->columnWidth (j);
				text=d_table->text(i,j)+"\t";
				tr=p.boundingRect(tr,Qt::AlignCenter,text,-1,0);
				br.setTopLeft(QPoint(right,height));	
				br.setWidth(w);	
				br.setHeight(tr.height());
				p.drawText(br,Qt::AlignCenter,text,-1);
				right+=w;
				p.drawLine(right,height,right,height+tr.height());
				
				if (right >= metrics.width()-2*margin )
					break;
				}
			height+=br.height();
			p.drawLine(margin,height,right-1,height);	
			
			if (height >= metrics.height()-margin )
				{
            	printer.newPage();
				height=margin;
				p.drawLine(margin,height,right,height);
				}
		}	
    }
}
示例#27
0
//============================================================================================
void DrawText(QPainter& painter, const qreal xoff, const qreal yoff, const qreal angle)
{
  QString text;  text.sprintf("%.0f",angle);
  QRectF rectF = painter.boundingRect(QRectF(0.0,0.0, 500.0,500.0), text, QTextOption(Qt::AlignCenter));
  painter.drawText(QRectF(-rectF.width()/2.0-0.5 + xoff, -rectF.height()/2.0-0.5 + yoff, rectF.width(),rectF.height()), text, QTextOption(Qt::AlignCenter));
}
示例#28
0
void PinItem::drawShape( QPainter& p )
{
	if (!m_pinSettings)
		return;
	
	if ( m_pinSettings->state() == PinSettings::ps_on )
	{
		if ( m_pinSettings->type() == PinSettings::pt_output )
			setBrush( QColor( 255, 127, 127 ) );
		else
			setBrush( QColor( 255, 191, 191 ) );
	}
	else
		setBrush( Qt::white );
	
	p.drawRect(rect());
	
	p.setFont(m_font);
	p.setBrush( Qt::NoBrush );
	QRect r = m_textRect;
	if ( onLeft )
		p.drawText( r, Qt::AlignLeft, m_pinSettings->id() );
	else
		p.drawText( r, Qt::AlignRight, m_pinSettings->id() );
	QRect br = p.boundingRect( r, Qt::AlignLeft, m_pinSettings->id() );
	
	int left;
	int right;
	if ( onLeft )
	{
		right = (int)x();
		left = right - 8;
	}
	else
	{
		left = (int)x() + PinLength;
		right = left + 8;
	}
	
	int midY = (int)y() + PinWidth/2;
	Q3PointArray pa(3);
	int midLeft = left + (8-PinDirArrow)/2;
	int midRight = left + (8+PinDirArrow)/2;
	
	if ( onLeft )
	{
		midLeft--;
		midRight--;
	}
	else
	{
		midLeft++;
		midRight++;
	}
	
	p.setBrush( Qt::black );
	
	// Right facing arrow
	if ( (m_pinSettings->type() == PinSettings::pt_input && onLeft) ||
			 (m_pinSettings->type() == PinSettings::pt_output && !onLeft) )
	{
		pa[0] = QPoint( midRight, midY );
		pa[1] = QPoint( midLeft, midY - PinDirArrow );
		pa[2] = QPoint( midLeft, midY + PinDirArrow );
		p.drawPolygon(pa);
		p.drawLine ( left, midY, right, midY );
	}
	else // Left facing arrow
	{
		pa[0] = QPoint( midLeft, midY );
		pa[1] = QPoint( midRight, midY - PinDirArrow );
		pa[2] = QPoint( midRight, midY + PinDirArrow );
		p.drawPolygon(pa);
		p.drawLine ( left, midY, right, midY );
	}
}
示例#29
0
void DecodeTrace::draw_annotations(vector<pv::data::decode::Annotation> annotations,
		QPainter &p, int h, const ViewItemPaintParams &pp, int y,
		size_t base_colour, int row_title_width)
{
	using namespace pv::data::decode;

	vector<Annotation> a_block;
	int p_end = INT_MIN;

	double samples_per_pixel, pixels_offset;
	tie(pixels_offset, samples_per_pixel) =
		get_pixels_offset_samples_per_pixel();

	// Sort the annotations by start sample so that decoders
	// can't confuse us by creating annotations out of order
	stable_sort(annotations.begin(), annotations.end(),
		[](const Annotation &a, const Annotation &b) {
			return a.start_sample() < b.start_sample(); });

	// Gather all annotations that form a visual "block" and draw them as such
	for (const Annotation &a : annotations) {

		const int a_start = a.start_sample() / samples_per_pixel - pixels_offset;
		const int a_end = a.end_sample() / samples_per_pixel - pixels_offset;
		const int a_width = a_end - a_start;

		const int delta = a_end - p_end;

		bool a_is_separate = false;

		// Annotation wider than the threshold for a useful label width?
		if (a_width > 20) {
			for (const QString &ann_text : a.annotations()) {
				const int w = p.boundingRect(QRectF(), 0, ann_text).width();
				// Annotation wide enough to fit a label? Don't put it in a block then
				if (w <= a_width) {
					a_is_separate = true;
					break;
				}
			}
		}

		// Were the previous and this annotation more than a pixel apart?
		if ((abs(delta) > 1) || a_is_separate) {
			// Block was broken, draw annotations that form the current block
			if (a_block.size() == 1) {
				draw_annotation(a_block.front(), p, h, pp, y, base_colour,
					row_title_width);
			}
			else
				draw_annotation_block(a_block, p, h, y, base_colour);

			a_block.clear();
		}

		if (a_is_separate) {
			draw_annotation(a, p, h, pp, y, base_colour, row_title_width);
			// Next annotation must start a new block. delta will be > 1
			// because we set p_end to INT_MIN but that's okay since
			// a_block will be empty, so nothing will be drawn
			p_end = INT_MIN;
		} else {
			a_block.push_back(a);
			p_end = a_end;
		}
	}

	if (a_block.size() == 1)
		draw_annotation(a_block.front(), p, h, pp, y, base_colour,
			row_title_width);
	else
		draw_annotation_block(a_block, p, h, y, base_colour);
}
示例#30
0
QImage* MyTextEffect::drawImage()
{
    QFont myFont;
    QPen myPen;
    myPen.setJoinStyle( Qt::RoundJoin );
    QBrush myBrush( QColor(0,0,0,0) );
    QColor backgroundColor(0,0,0,0);
    int outline = 0;
    int align = 1;

    int arrowType = 0, arrowSize = 0, arrowPos = 0;

    QStringList sl = currentText.split("\n");
    while ( !sl.isEmpty() ) {
        if ( sl.last().trimmed().isEmpty() )
            sl.takeLast();
        else
            break;
    }
    if ( sl.count() ) {
        QStringList desc = sl[0].split("|");
        if ( desc.count() >= 9 ) {
            myFont.fromString( desc[0] );
            myFont.setPointSize( desc[1].toInt() );
            myFont.setBold( desc[2].toInt() );
            myFont.setItalic( desc[3].toInt() );

            QStringList fc = desc[4].split( "." );
            if ( fc.count() == 2 ) {
                QColor col;
                col.setNamedColor( fc[ 0 ] );
                col.setAlpha( fc[ 1 ].toInt() );
                myPen.setColor( col );
                myBrush.setColor( col );
            }

            QStringList bc = desc[5].split( "." );
            if ( bc.count() == 2 ) {
                backgroundColor.setNamedColor( bc[ 0 ] );
                backgroundColor.setAlpha( bc[ 1 ].toInt() );
            }

            align = desc[6].toInt();

            int osize = desc[7].toInt();
            if ( osize > 0 ) {
                QStringList oc = desc[8].split( "." );
                if ( oc.count() == 2 ) {
                    outline = osize;
                    myPen.setWidth( osize );
                    myFont.setStyleStrategy( QFont::ForceOutline );
                    QColor col;
                    col.setNamedColor( oc[ 0 ] );
                    col.setAlpha( oc[ 1 ].toInt() );
                    myPen.setColor( col );
                }
            }
        }
        if ( desc.count() >= 12 ) {
            arrowType = desc[9].toInt();
            arrowSize = desc[10].toInt();
            arrowPos = desc[11].toInt();
        }
        sl.takeFirst();
    }

    QImage *image = new QImage( 10, 10, QImage::Format_ARGB32_Premultiplied );
    QPainter painter;
    painter.begin( image );
    painter.setPen( myPen );
    painter.setBrush( myBrush );
    painter.setFont( myFont );
    QList<QRectF> br;
    QFontMetrics metrics( myFont );
    int h = sl.count() * metrics.lineSpacing();
    int w = 0;
    for ( int i = 0; i < sl.count(); ++i ) {
        QRectF minrect( 0, 0, 1, 1 );
        QRectF r = painter.boundingRect( minrect, Qt::AlignHCenter | Qt::AlignVCenter, sl[i] );
        if ( r.width() > w )
            w = r.width();
        br.append( r );
    }
    QRectF minrect( 0, 0, 1, 1 );
    int margin = qMax( painter.boundingRect( minrect, Qt::AlignHCenter | Qt::AlignVCenter, "M" ).width() / 3.0, 3.0 );

    painter.end();

    double x = ((double)outline + margin * 2) / 2.0;
    double y = x;
    w += 2 * x;
    h += 2 * y;
    if ( w > iwidth ) {
        x -= (w - iwidth) / 2.0;
        w = iwidth;
    }
    if ( h > iheight ) {
        y -= (h - iheight) / 2.0;
        h = iheight;
    }

    QPointF polygon[7];
    arrowSize = h * arrowSize / 100.0;
    int n = 0;
    int leftOffset = 0, topOffset = 0;
    int wMargin = 0, hMargin = 0;
    if (arrowType) {
        switch (arrowType) {
        case 1: {
            leftOffset = arrowSize;
            wMargin = arrowSize;
            polygon[n].setX(1 + arrowSize);
            polygon[n++].setY(1);

            polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 - arrowSize / 2.0) ) );
            polygon[n++].setX(1 + arrowSize);
            polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0) ) );
            polygon[n++].setX(1);
            polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 + arrowSize / 2.0) ) );
            polygon[n++].setX(1 + arrowSize);

            polygon[n].setX(1 + arrowSize);
            polygon[n++].setY(h - 1);
            polygon[n].setX(w - 1 + arrowSize);
            polygon[n++].setY(h - 1);
            polygon[n].setX(w - 1 + arrowSize);
            polygon[n++].setY(1);
            break;
        }
        case 2: {
            wMargin = arrowSize;
            polygon[n].setX(1);
            polygon[n++].setY(1);
            polygon[n].setX(1);
            polygon[n++].setY(h - 1);
            polygon[n].setX(w - 1);
            polygon[n++].setY(h - 1);

            polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 + arrowSize / 2.0) ) );
            polygon[n++].setX(w - 1);
            polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0) ) );
            polygon[n++].setX(w - 1 + arrowSize);
            polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 - arrowSize / 2.0) ) );
            polygon[n++].setX(w - 1);

            polygon[n].setX(w - 1);
            polygon[n++].setY(1);
            break;
        }
        case 3: {
            topOffset = arrowSize;
            hMargin = arrowSize;
            polygon[n].setX(1);
            polygon[n++].setY(1 + arrowSize);
            polygon[n].setX(1);
            polygon[n++].setY(h - 1 + arrowSize);
            polygon[n].setX(w - 1);
            polygon[n++].setY(h - 1 + arrowSize);
            polygon[n].setX(w - 1);
            polygon[n++].setY(1 + arrowSize);

            polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 + arrowSize / 2.0) ) );
            polygon[n++].setY(1 + arrowSize);
            polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0) ) );
            polygon[n++].setY(1);
            polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 - arrowSize / 2.0) ) );
            polygon[n++].setY(1 + arrowSize);
            break;
        }
        case 4: {
            hMargin = arrowSize;
            polygon[n].setX(1);
            polygon[n++].setY(1);
            polygon[n].setX(1);
            polygon[n++].setY(h - 1);

            polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 - arrowSize / 2.0) ) );
            polygon[n++].setY(h - 1);
            polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0) ) );
            polygon[n++].setY(h - 1 + arrowSize);
            polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 + arrowSize / 2.0) ) );
            polygon[n++].setY(h - 1);

            polygon[n].setX(w - 1);
            polygon[n++].setY(h - 1);
            polygon[n].setX(w - 1);
            polygon[n++].setY(1);
            break;
        }
        }
    }

    delete image;
    image = new QImage( w + wMargin, h + hMargin, QImage::Format_ARGB32_Premultiplied );
    image->fill( QColor(0,0,0,0) );
    painter.begin( image );
    painter.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing );
    if ( backgroundColor.alpha() > 0 ) {
        painter.setPen( QColor(0,0,0,0) );
        painter.setBrush( backgroundColor );
        if (arrowType) {
            painter.drawPolygon( polygon, 7 );
        }
        else {
            painter.drawRect( 1, 1, w - 2, h - 2 );
        }
    }
    painter.setPen( myPen );
    painter.setBrush( myBrush );
    painter.setFont( myFont );

    for ( int i = 0; i < sl.count(); ++i ) {
        QPointF point( 0, y + topOffset + metrics.ascent() );
        switch ( align ) {
        case 2: {
            point.setX( leftOffset + (double)w / 2.0 - br[i].width() / 2.0 );
            break;
        }
        case 3: {
            point.setX( leftOffset + w - x - br[i].width() );
            break;
        }
        default: {
            point.setX( leftOffset + x );
            break;
        }
        }
        if ( outline ) {
            QPainterPath myPath;
            myPath.addText( point, myFont, sl[i] );
            painter.drawPath( myPath );
        }
        else
            painter.drawText( point, sl[i] );
        y += metrics.lineSpacing();
    }
    painter.end();

    return image;
}