Ejemplo n.º 1
0
void regionselection::HandleMiddle()
{
  QColor color, arrow;
  
  color = Qt::green;
  arrow = Qt::black;

  QBrush brush( color, Qt::SolidPattern );
  painter->setBrush( brush );
  painter->setPen( QPen( Qt::black, penWidth ) );
  
  QRect rect( ( width() - borderLeft - borderRight ) / 2 + borderLeft - radius, 
              ( height() - borderTop - borderBottom ) / 2 + borderTop - radius,
                2 * radius,
                2 * radius );
  
  painter->drawEllipse ( rect );
  
  //Begin Pfeil zeichnen
  painter->setPen( QPen( arrow, 2 ) );

  QPainterPath * painterPath = new QPainterPath();
  //arrow left
  painterPath->moveTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,                        ( height() - borderTop - borderBottom ) / 2 + borderTop );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft - radius + penWidth,    ( height() - borderTop - borderBottom ) / 2 + borderTop );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft - radius + penWidth + 7,( height() - borderTop - borderBottom ) / 2 + borderTop + 3 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft - radius + penWidth + 7,( height() - borderTop - borderBottom ) / 2 + borderTop - 3 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft - radius + penWidth,    ( height() - borderTop - borderBottom ) / 2 + borderTop );
  
  //arrow top
  painterPath->moveTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,     ( height() - borderTop - borderBottom ) / 2 + borderTop );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,     ( height() - borderTop - borderBottom ) / 2 + borderTop - radius + penWidth );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft + 3, ( height() - borderTop - borderBottom ) / 2 + borderTop - radius + penWidth + 7 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft - 3, ( height() - borderTop - borderBottom ) / 2 + borderTop - radius + penWidth + 7 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,     ( height() - borderTop - borderBottom ) / 2 + borderTop - radius + penWidth );
  
  //arrow right
  painterPath->moveTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,                         ( height() - borderTop - borderBottom ) / 2 + borderTop );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft + radius - penWidth,     ( height() - borderTop - borderBottom ) / 2 + borderTop );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft + radius - penWidth - 7, ( height() - borderTop - borderBottom ) / 2 + borderTop + 3 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft + radius - penWidth - 7, ( height() - borderTop - borderBottom ) / 2 + borderTop - 3 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft + radius - penWidth,     ( height() - borderTop - borderBottom ) / 2 + borderTop );

  //arrow bottom
  painterPath->moveTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,     ( height() - borderTop - borderBottom ) / 2 + borderTop );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,     ( height() - borderTop - borderBottom ) / 2 + borderTop + radius - penWidth );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft + 3, ( height() - borderTop - borderBottom ) / 2 + borderTop + radius - penWidth - 7 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft - 3, ( height() - borderTop - borderBottom ) / 2 + borderTop + radius - penWidth - 7 );
  painterPath->lineTo( ( width() - borderLeft - borderRight ) / 2 + borderLeft,     ( height() - borderTop - borderBottom ) / 2 + borderTop + radius - penWidth );
  
  painterPath->setFillRule( Qt::OddEvenFill );
  
  painter->drawPath( *painterPath );
  // End Pfeil zeichnen
  
  rect.setLeft( rect.left() - 2 );
  rect.setTop( rect.top() - 2 );
  rect.setWidth( rect.width() + 2 );
  rect.setHeight( rect.height() + 2 );
  setHandleMiddleForMask( rect );
}
void OpenInfraPlatform::UserInterface::Alignment2DScene::drawAxis(
	QPainterPath& diagPainter, 
	double at, 
	double from, 
	double to, 
	double scaling, 
	double desiredStepSize, 
	bool doubleLine /*= true*/, 
	bool vertical /*= false*/)
{
#define A(X) if(!vertical) { a = X;}else{ b = X;}
#define B(Y) if(!vertical) { b = Y;}else{ a = Y;}

	if(to - from == 0)
		return;

	QString text;
	int width = 80;
	double a, b;
	int sign = vertical ? -1 : 1;
	
	A(from * scaling);
	B(at + 10 * sign);
	diagPainter.moveTo(a,b);

	A(to * scaling);
	B(at + 10 * sign);
	diagPainter.lineTo(a,b);

	if(doubleLine)
	{
		A(from * scaling);
		B(at + (width + 10) * sign);
		diagPainter.moveTo(a,b);

		A(to * scaling)
		B(at + (width + 10) * sign);
		diagPainter.lineTo(a,b);
	}

	std::vector<double> drawStaions;
	drawStaions.push_back(from);
	drawStaions.push_back(to);

	// calculate stations to draw
	{
		double size = (to - from) * scaling;
		int count = size / desiredStepSize;
		count = std::min(count, 10);

		if(count != 0)
		{
			double stepSize = size / count;
			double step = stepSize / scaling;

			double allowedsteps[4] = { 1, 2.5, 5.0, 10.0};
			double dimension = 100000;
			while(step / dimension < 1)
			{
				dimension /= 10;
			}

			double min =  std::numeric_limits<double>().max();
			int index;
			for(int i=0; i<4; i++)
			{
				allowedsteps[i] *= dimension;
				double diff = std::abs(allowedsteps[i] - step);
				if(diff < min)
				{
					min = diff;
					index = i;
				}
			}

			step = allowedsteps[index];

			for(double s = (int)(from/step) * step; s < to; s+= step)
			{
				double spacing;
				if(vertical)
					spacing = (QFontMetrics(diagramFont).height() + 2 ) / scalingY;
				else
					spacing = (QFontMetrics(diagramFont).width("0+000") + 2) / scalingX;

				if(	abs(drawStaions[0] - s) > spacing && abs(drawStaions[1] - s) > spacing )
					drawStaions.push_back(s);
			}
		}
	}

	for(double x : drawStaions)
	{
		double X = x * scaling;
		A(X); 
		B(at + 10 * sign);
		diagPainter.moveTo(a,b);

		A(X);
		B(at + (width + 10) * sign);
		diagPainter.lineTo(a,b);
					
		auto stationLabel = vertical ? v_labelY(sign * x) : v_labelX(sign * x);

		double offsetX = 0;
		double offsetY = 0;
		if(!vertical)
		{
			offsetX = QFontMetrics(diagramFont).width(stationLabel->toPlainText()) / 2;
			offsetY = - width;
		}
		else
		{
			offsetX = 10 + QFontMetrics(diagramFont).width(stationLabel->toPlainText());
			offsetY = QFontMetrics(diagramFont).height() + 4;
		}

		A(X);
		B(at + 10 * sign);
		stationLabel->setPos(a - offsetX, b - offsetY);
		stationLabel->setDefaultTextColor(diagramFontColor);
	}

#undef B
#undef A
}
Ejemplo n.º 3
0
void ArthurStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                QPainter *painter, const QWidget *widget) const
{

    Q_ASSERT(option);
    switch (element) {
    case PE_FrameFocusRect:
        break;

    case PE_IndicatorRadioButton:
        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
            bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
            painter->save();
            QPixmap radio;
            if (hover)
                drawHoverRect(painter, widget->rect());

            if (button->state & State_Sunken)
                radio = cached(":res/images/radiobutton-on.png");
            else if (button->state & State_On)
                radio = cached(":res/images/radiobutton_on.png");
            else
                radio = cached(":res/images/radiobutton_off.png");
            painter->drawPixmap(button->rect.topLeft(), radio);

            painter->restore();
        }
        break;

    case PE_PanelButtonCommand:
        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
            bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);

            painter->save();
            const QPushButton *pushButton = qobject_cast<const QPushButton *>(widget);
            Q_ASSERT(pushButton);
            QWidget *parent = pushButton->parentWidget();
            if (parent && qobject_cast<QGroupBox *>(parent)) {
                QLinearGradient lg(0, 0, 0, parent->height());
                lg.setColorAt(0, QColor(224,224,224));
                lg.setColorAt(1, QColor(255,255,255));
                painter->setPen(Qt::NoPen);
                painter->setBrush(lg);
                painter->setBrushOrigin(-widget->mapToParent(QPoint(0,0)));
                painter->drawRect(button->rect);
                painter->setBrushOrigin(0,0);
            }

            bool down = (button->state & State_Sunken) || (button->state & State_On);

            QPixmap left, right, mid;
            if (down) {
                left = cached(":res/images/button_pressed_cap_left.png");
                right = cached(":res/images/button_pressed_cap_right.png");
                mid = cached(":res/images/button_pressed_stretch.png");
            } else {
                left = cached(":res/images/button_normal_cap_left.png");
                right = cached(":res/images/button_normal_cap_right.png");
                mid = cached(":res/images/button_normal_stretch.png");
            }
            painter->drawPixmap(button->rect.topLeft(), left);
            painter->drawTiledPixmap(QRect(button->rect.x() + left.width(),
                                           button->rect.y(),
                                           button->rect.width() - left.width() - right.width(),
                                           left.height()),
                                     mid);
            painter->drawPixmap(button->rect.x() + button->rect.width() - right.width(),
                                button->rect.y(),
                                right);
            if (hover)
                painter->fillRect(widget->rect().adjusted(3,5,-3,-5), QColor(31,127,31,63));
            painter->restore();
        }
        break;

    case PE_FrameGroupBox:
        if (const QStyleOptionFrameV2 *group
                = qstyleoption_cast<const QStyleOptionFrameV2 *>(option)) {
            const QRect &r = group->rect;

            painter->save();
            int radius = 14;
            int radius2 = radius*2;
            QPainterPath clipPath;
            clipPath.moveTo(radius, 0);
            clipPath.arcTo(r.right() - radius2, 0, radius2, radius2, 90, -90);
            clipPath.arcTo(r.right() - radius2, r.bottom() - radius2, radius2, radius2, 0, -90);
            clipPath.arcTo(r.left(), r.bottom() - radius2, radius2, radius2, 270, -90);
            clipPath.arcTo(r.left(), r.top(), radius2, radius2, 180, -90);
            painter->setClipPath(clipPath);
            QPixmap titleStretch = cached(":res/images/title_stretch.png");
            QPixmap topLeft = cached(":res/images/groupframe_topleft.png");
            QPixmap topRight = cached(":res/images/groupframe_topright.png");
            QPixmap bottomLeft = cached(":res/images/groupframe_bottom_left.png");
            QPixmap bottomRight = cached(":res/images/groupframe_bottom_right.png");
            QPixmap leftStretch = cached(":res/images/groupframe_left_stretch.png");
            QPixmap topStretch = cached(":res/images/groupframe_top_stretch.png");
            QPixmap rightStretch = cached(":res/images/groupframe_right_stretch.png");
            QPixmap bottomStretch = cached(":res/images/groupframe_bottom_stretch.png");
            QLinearGradient lg(0, 0, 0, r.height());
            lg.setColorAt(0, QColor(224,224,224));
            lg.setColorAt(1, QColor(255,255,255));
            painter->setPen(Qt::NoPen);
            painter->setBrush(lg);
            painter->drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0));
            painter->setClipping(false);

            int topFrameOffset = titleStretch.height()/2 - 2;
            painter->drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft);
            painter->drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0)
                                + QPoint(0, topFrameOffset), topRight);
            painter->drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft);
            painter->drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1,
                                bottomRight.height()-1), bottomRight);

            QRect left = r;
            left.setY(r.y() + topLeft.height() + topFrameOffset);
            left.setWidth(leftStretch.width());
            left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset);
            painter->drawTiledPixmap(left, leftStretch);

            QRect top = r;
            top.setX(r.x() + topLeft.width());
            top.setY(r.y() + topFrameOffset);
            top.setWidth(r.width() - topLeft.width() - topRight.width());
            top.setHeight(topLeft.height());
            painter->drawTiledPixmap(top, topStretch);

            QRect right = r;
            right.setX(r.right() - rightStretch.width()+1);
            right.setY(r.y() + topRight.height() + topFrameOffset);
            right.setWidth(rightStretch.width());
            right.setHeight(r.height() - topRight.height()
                            - bottomRight.height() - topFrameOffset);
            painter->drawTiledPixmap(right, rightStretch);

            QRect bottom = r;
            bottom.setX(r.x() + bottomLeft.width());
            bottom.setY(r.bottom() - bottomStretch.height()+1);
            bottom.setWidth(r.width() - bottomLeft.width() - bottomRight.width());
            bottom.setHeight(bottomLeft.height());
            painter->drawTiledPixmap(bottom, bottomStretch);
            painter->restore();
        }
        break;

    default:
        QWindowsStyle::drawPrimitive(element, option, painter, widget);
        break;
    }
    return;
}
Ejemplo n.º 4
0
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode)
{
	encode();
	bool textdone;
	int comp_offset = 0, xoffset = m_whitespace, j, main_width = 0, addon_text_height = 0;
	int yoffset = 0;
	QString caption = QString::fromUtf8((const char *)m_zintSymbol->text, -1);
	QFont fontSmall(fontstyle);
	fontSmall.setPixelSize(fontPixelSizeSmall);
	QFont fontLarge(fontstyle);
	fontLarge.setPixelSize(fontPixelSizeLarge);

	if (m_lastError.length())
	{
		painter.setFont(fontLarge);
		painter.drawText(paintRect,Qt::AlignCenter,m_lastError);
		return;
	}

	painter.save();
	painter.setClipRect(paintRect,Qt::IntersectClip);
	qreal xtr=paintRect.x();
	qreal ytr=paintRect.y();

	int zrow_height=m_zintSymbol->height;
	int zrows=0;
	for (int i=0;i<m_zintSymbol->rows;i++)
	{
		zrow_height-=m_zintSymbol->row_height[i];
		if (!m_zintSymbol->row_height[i])
			zrows++;
	}
	if (zrows)
	{
		zrow_height/=zrows;
		for (int i=0;i<m_zintSymbol->rows;i++)
			if (!m_zintSymbol->row_height[i])
				m_zintSymbol->row_height[i]=zrow_height;
	}
	else
		m_zintSymbol->height-=zrow_height;


	qreal gwidth=m_zintSymbol->width;
	qreal gheight=m_zintSymbol->height;
	if (m_zintSymbol->symbology == BARCODE_MAXICODE)
	{
		gheight*=(maxi_width);
		gwidth*=(maxi_width+1);
	}

	qreal xsf=1;
	qreal ysf=1;
	qreal textoffset = 0;

	gwidth+=((m_border==BOX)?m_borderWidth*2:0);
	gheight+=((m_border!=NO_BORDER)?m_borderWidth*2:0);
	if(QString((const char*)m_zintSymbol->text).isEmpty() == false) {
		textoffset = 9;
		gheight += textoffset;
	} else {
		textoffset = 0;
	}
    gwidth+=m_zintSymbol->whitespace_width*2;
	switch(mode)
	{
		case IgnoreAspectRatio:
				xsf=(qreal)paintRect.width()/gwidth;
				ysf=(qreal)paintRect.height()/gheight;
			break;

		case KeepAspectRatio:
			if (paintRect.width()/gwidth<paintRect.height()/gheight)
			{
				ysf=xsf=(qreal)paintRect.width()/gwidth;
				ytr+=(qreal)(paintRect.height()-gheight*ysf)/2;
			}
			else
			{
				ysf=xsf=(qreal)paintRect.height()/gheight;
				xtr+=(qreal)(paintRect.width()-gwidth*xsf)/2;
			}
			break;

		case CenterBarCode:
				xtr+=((qreal)paintRect.width()-gwidth*xsf)/2;
				ytr+=((qreal)paintRect.height()-gheight*ysf)/2;
			break;
	}

	painter.setBackground(QBrush(m_bgColor));
	painter.fillRect(paintRect,QBrush(m_bgColor));
	painter.translate(xtr,ytr);
	painter.scale(xsf,ysf);

	QPen p;
	p.setColor(m_fgColor);
	p.setWidth(m_borderWidth);
	painter.setPen(p);

	QPainterPath pt;
	if(m_zintSymbol->symbology != BARCODE_MAXICODE) {
		/* Draw boundary bars or boxes around the symbol */
		switch(m_border)
		{
			case BOX:
				painter.fillRect(0,m_borderWidth,m_borderWidth,m_zintSymbol->height,QBrush(m_fgColor));
				painter.fillRect(m_zintSymbol->width + xoffset + xoffset + m_borderWidth,m_borderWidth,m_borderWidth,m_zintSymbol->height,QBrush(m_fgColor));
				painter.fillRect(0,0,m_zintSymbol->width + xoffset + xoffset + m_borderWidth + m_borderWidth,m_borderWidth,QBrush(m_fgColor));
				painter.fillRect(0,m_zintSymbol->height + m_borderWidth,m_zintSymbol->width + xoffset + xoffset + m_borderWidth + m_borderWidth, m_borderWidth,QBrush(m_fgColor));
				painter.translate(m_borderWidth+m_zintSymbol->whitespace_width,m_borderWidth);
				yoffset = m_borderWidth;
				break;
			case BIND:
				painter.fillRect(0,0,m_zintSymbol->width + xoffset + xoffset,m_borderWidth,QBrush(m_fgColor));
				painter.fillRect(0,m_zintSymbol->height + m_borderWidth,m_zintSymbol->width + xoffset + xoffset, m_borderWidth,QBrush(m_fgColor));
				painter.translate(m_zintSymbol->whitespace_width,m_borderWidth);
				yoffset = m_borderWidth;
				break;
	
			default:
				painter.translate(m_zintSymbol->whitespace_width,0);
				break;;
		}
	}

	while(!(module_set(m_zintSymbol->rows - 1, comp_offset))) {
		comp_offset++;
	}
	xoffset = comp_offset;
	
	/* Set up some values for displaying EAN and UPC symbols correctly */
	main_width = m_zintSymbol->width;
	if ((((m_zintSymbol->symbology == BARCODE_EANX) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_EANX_CC))
		|| (m_zintSymbol->symbology == BARCODE_ISBNX)) {
		switch(caption.size()) {
			case 13: /* EAN 13 */
			case 16:
			case 19:
				if(m_zintSymbol->whitespace_width == 0) {
					m_zintSymbol->whitespace_width = 10;
				}
				main_width = 96 + comp_offset;
				break;
			default:
				main_width = 68 + comp_offset;
				break;
		}
	}
	
	if (((m_zintSymbol->symbology == BARCODE_UPCA) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_UPCA_CC)) {
		if(m_zintSymbol->whitespace_width == 0) {
			m_zintSymbol->whitespace_width = 10;
		}
		main_width = 96 + comp_offset;
	}
	
	if (((m_zintSymbol->symbology == BARCODE_UPCE) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_UPCE_CC)) {
		if(m_zintSymbol->whitespace_width == 0) {
			m_zintSymbol->whitespace_width = 10;
		}
		main_width = 51 + comp_offset;
	}
	
	p.setWidth(1);
	painter.setPen(p);

	if (m_zintSymbol->symbology == BARCODE_MAXICODE)
	{
		/* Draw Maxicode with hexagons */
		painter.save();
		painter.setRenderHint(QPainter::Antialiasing);
		for (int r=0;r<m_zintSymbol->rows;r++)
		{
			for (int c=0;c<m_zintSymbol->width;c++)
			{
				if (module_set(r, c))
				{
					qreal col=(qreal)c*(maxi_width+1)+(r%2)*((maxi_width+1)/2);
					qreal row=(qreal)r*(maxi_width+1)*0.868;
					QPainterPath pt;
					pt.moveTo(col+maxi_width/2, 	row);
					pt.lineTo(col+maxi_width, 	row+maxi_diagonal/4);
					pt.lineTo(col+maxi_width, 	row+(maxi_diagonal-maxi_diagonal/4));
					pt.lineTo(col+maxi_width/2, 	row+maxi_diagonal);
					pt.lineTo(col, 			row+(maxi_diagonal-maxi_diagonal/4));
					pt.lineTo(col, 			row+maxi_diagonal/4);
					pt.lineTo(col+maxi_width/2, 	row);
					painter.fillPath(pt,QBrush(m_fgColor));
				}
			}
		}
		p.setWidth(maxi_width);
		painter.setPen(p);
		const qreal w=maxi_width+1;
		painter.drawEllipse(QPointF(14.5*w,16.5*w*0.868),w,w);
		painter.drawEllipse(QPointF(14.5*w,16.5*w*0.868),w+w*1.5,w+w*1.5);
		painter.drawEllipse(QPointF(14.5*w,16.5*w*0.868),w+w*3,w+w*3);
		painter.restore();
	}
	else
	{
		/* Draw all other symbols with rectangles */
		int y=0;
		for (int row=0;row<m_zintSymbol->rows;row++)
		{
			for (int i=0;i<m_zintSymbol->width;i++) {
				if (module_set(row, i))
				{
					int ed = module_set(row, i);
					int linewidth=0;
					for (int j=i;j<m_zintSymbol->width;j++,linewidth++)
						if (ed != module_set(row, j))
							break;
					QColor color;
					color=m_fgColor;
					
					if(!((i > main_width) && (row == m_zintSymbol->rows - 1)))  {
						painter.fillRect(i,y,linewidth,m_zintSymbol->row_height[row],QBrush(color));
					} else {
						painter.fillRect(i,y + 8,linewidth,m_zintSymbol->row_height[row] - 3,QBrush(color));
						addon_text_height = y;
					}
				}
			}
			/* Add row binding */
			if(((m_zintSymbol->symbology == BARCODE_CODE16K) || (m_zintSymbol->symbology == BARCODE_CODE49)) && (row != 0)) {
				painter.fillRect(0,y - 1,m_zintSymbol->width,2,QBrush(m_fgColor));
			}
			y+=m_zintSymbol->row_height[row];
		}
	}

	textdone = false;
	
	if(m_hidetext == false) {
		painter.setFont(fontSmall);
		if(((m_zintSymbol->symbology == BARCODE_EANX) || (m_zintSymbol->symbology == BARCODE_EANX_CC)) ||
			(m_zintSymbol->symbology == BARCODE_ISBNX)) {
			/* Add bridge and format text for EAN */
			switch(caption.size()) {
				case 8:
				case 11:
				case 14:
					painter.fillRect(0 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(2 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(32 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(34 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(64 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(66 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.setFont(fontLarge);
					painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 29, 9,Qt::AlignCenter, caption.mid(0,4));
					painter.drawText(35 + xoffset, m_zintSymbol->height + yoffset, 29, 9,Qt::AlignCenter, caption.mid(4,4));
					if(caption.size() == 11) { /* EAN-2 */ painter.drawText(76 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(9,2)); };
					if(caption.size() == 14) { /* EAN-5 */ painter.drawText(76 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); };
					painter.setFont(fontSmall);
					textdone = true;
					break;
				case 13:
				case 16:
				case 19:
					painter.fillRect(0 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(2 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(46 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(48 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(92 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.fillRect(94 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
					painter.setFont(fontLarge);
					painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset, 7, 9,Qt::AlignCenter, caption.mid(0,1));
					painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 43, 9,Qt::AlignCenter, caption.mid(1,6));
					painter.drawText(49 + xoffset, m_zintSymbol->height + yoffset, 43, 9,Qt::AlignCenter, caption.mid(7,6));
					if(caption.size() == 16) { /* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(14,2)); };
					if(caption.size() == 19) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(14,5)); };
					painter.setFont(fontSmall);
					textdone = true;
					break;
			}
			if(textdone == false) {
				painter.setFont(fontLarge);
				painter.drawText(0, m_zintSymbol->height, m_zintSymbol->width, 9,Qt::AlignCenter, caption);
				painter.setFont(fontSmall);
				textdone = true;
			}
		}
		
		if((m_zintSymbol->symbology == BARCODE_UPCA) || (m_zintSymbol->symbology == BARCODE_UPCA_CC)) {
			/* Add bridge and format text for UPC-A */
			int block_width;
			bool latch = true;
			
			j = 0 + comp_offset;
			do {
				block_width = 0;
				do {
					block_width++;
				} while (module_set(m_zintSymbol->rows - 1, j + block_width) == module_set(m_zintSymbol->rows - 1, j));
				if(latch == true) {
					/* a bar */
					painter.fillRect(j + xoffset - comp_offset,m_zintSymbol->height,block_width,5,QBrush(m_fgColor));
					latch = false;
				} else {
					/* a space */
					latch = true;
				}
				j += block_width;
			} while (j < 11 + comp_offset);
			painter.fillRect(46 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
			painter.fillRect(48 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
			latch = true;
			j = 85 + comp_offset;
			do {
				block_width = 0;
				do {
					block_width++;
				} while (module_set(m_zintSymbol->rows - 1, j + block_width) == module_set(m_zintSymbol->rows - 1, j));
				if(latch == true) {
					/* a bar */
					painter.fillRect(j + xoffset - comp_offset,m_zintSymbol->height,block_width,5,QBrush(m_fgColor));
					latch = false;
				} else {
					/* a space */
					latch = true;
				}
				j += block_width;
			} while (j < 96 + comp_offset);
			painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(0,1));
			painter.drawText(96 + xoffset, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(11,1));
			painter.setFont(fontLarge);
			painter.drawText(11 + xoffset, m_zintSymbol->height + yoffset, 35, 9,Qt::AlignCenter, caption.mid(1,5));
			painter.drawText(49 + xoffset, m_zintSymbol->height + yoffset, 35, 9,Qt::AlignCenter, caption.mid(6,5));
			if(caption.size() == 15) { /* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(13,2)); };
			if(caption.size() == 18) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(13,5)); };
			painter.setFont(fontSmall);
			textdone = true;
		}
		
		if((m_zintSymbol->symbology == BARCODE_UPCE) || (m_zintSymbol->symbology == BARCODE_UPCE_CC)) {
			/* Add bridge and format text for UPC-E */
			painter.fillRect(0 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
			painter.fillRect(2 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
			painter.fillRect(46 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
			painter.fillRect(48 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
			painter.fillRect(50 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
			painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(0,1));
			painter.drawText(51 + xoffset, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(7,1));
			painter.setFont(fontLarge);
			painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 43, 9,Qt::AlignCenter, caption.mid(1,6));
			if(caption.size() == 11) { /* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(9,2)); };
			if(caption.size() == 14) { /* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); };
			painter.setFont(fontSmall);
			textdone = true;
		}
	} /* if (m_hidetext == false) */
	
	if((m_hidetext == false) && (textdone == false)) {
		/* Add text to any other symbol */
		painter.drawText(0, m_zintSymbol->height + yoffset, m_zintSymbol->width, 7, Qt::AlignCenter, caption);
	}
	painter.restore();
}
void XFormView::drawVectorType(QPainter *painter)
{
    QPainterPath path;
    painter->translate(ctrlPoints.at(0) - QPointF(250,250));

    painter->scale(0.77, 0.77);
    painter->translate(98.9154 + 30 , -217.691 - 20);

    QRect br(-55, 275, 500, 590);
    QPoint center = br.center();
    painter->translate(center.x(), center.y());
    painter->rotate(m_rotation);
    painter->scale(m_scale, m_scale);
    painter->shear(0, m_shear);
    painter->translate(-center.x(), -center.y());

    painter->setPen(Qt::NoPen);
    path.moveTo(120, 470);
    path.lineTo(60+245, 470);
    path.lineTo(60+245, 470+350);
    path.lineTo(60, 470+350);
    path.lineTo(60, 470+80);

    painter->setBrush(Qt::white);
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor( 193, 193, 191, 255));
    path.moveTo(329.336, 727.552);
    path.cubicTo(QPointF(315.224, 726.328), QPointF(304.136, 715.816), QPointF(303.128, 694.936));
    path.cubicTo(QPointF(306.368, 639.496), QPointF(309.608, 582.112), QPointF(271.232, 545.104));
    path.cubicTo(QPointF(265.256, 499.024), QPointF(244.016, 482.104), QPointF(234.008, 452.512));
    path.lineTo(218.24, 441.208);
    path.lineTo(237.104, 411.688);
    path.lineTo(245.168, 411.904);
    path.lineTo(323.936, 571.168);
    path.lineTo(340.424, 651.448);
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(136.232, 439.696);
    path.cubicTo(QPointF(133.856, 455.248), QPointF(132.56, 470.512), QPointF(134.792, 485.272));
    path.cubicTo(QPointF(118.376, 507.592), QPointF(105.92, 530.128), QPointF(104.48, 553.312));
    path.cubicTo(QPointF(92.024, 586.504), QPointF(62.432, 614.584), QPointF(67.544, 680.104));
    path.cubicTo(QPointF(84.176, 697.456), QPointF(107.432, 713.584), QPointF(127.376, 730.36));
    path.cubicTo(QPointF(152.432, 751.312), QPointF(137.528, 778.96), QPointF(102.248, 772.408));
    path.cubicTo(QPointF(94.4, 763.768), QPointF(76.616, 709.624), QPointF(42.92, 676.288));
    path.lineTo(49.544, 632.584);
    path.lineTo(81.368, 547.408);
    path.lineTo(120.968, 484.048);
    path.lineTo(125.36, 456.688);
    path.lineTo(119.816, 386.776);
    path.lineTo(124.424, 361.216);
    path.lineTo(136.232, 439.696);
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(115.64, 341.416);
    path.cubicTo(QPointF(116.576, 336.376), QPointF(117.8, 331.624), QPointF(119.312, 327.16));
    path.lineTo(121.688, 342.784);
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(120.968, 500.464);
    path.cubicTo(QPointF(108.368, 523.792), QPointF(103.976, 546.256), QPointF(132.92, 550.216));
    path.cubicTo(QPointF(117.008, 553.888), QPointF(97.208, 568.648), QPointF(77.192, 593.488));
    path.lineTo(77.624, 543.016);
    path.lineTo(101.456, 503.272);
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(-33.256, 818.488);
    path.cubicTo(QPointF(10.52, 838.144), QPointF(41.408, 837.064), QPointF(69.272, 850.96));
    path.cubicTo(QPointF(91.304, 862.552), QPointF(113.552, 861.184), QPointF(126.944, 847.144));
    path.cubicTo(QPointF(138.32, 832.456), QPointF(146.744, 831.736), QPointF(163.52, 830.224));
    path.cubicTo(QPointF(190.952, 828.568), QPointF(217.736, 828.28), QPointF(241.928, 830.8));
    path.lineTo(269.576, 833.032);
    path.cubicTo(QPointF(269.072, 864.064), QPointF(328.04, 867.88), QPointF(345.392, 844.336));
    path.cubicTo(QPointF(366.344, 819.424), QPointF(395.144, 808.264), QPointF(419.84, 790.192));
    path.lineTo(289.304, 725.536);
    path.cubicTo(QPointF(255.824, 806.464), QPointF(131.048, 827.632), QPointF(113.768, 763.264));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(286.424, 711.568);
    path.cubicTo(QPointF(273.824, 711.496), QPointF(260.936, 715.6), QPointF(261.944, 732.16));
    path.lineTo(266.192, 776.44);
    path.lineTo(304.424, 756.64);
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(0, 0, 0, 255));
    path.moveTo(-37.36, 821.224);
    path.cubicTo(QPointF(7.136, 840.88), QPointF(38.6, 839.728), QPointF(66.968, 853.696));
    path.cubicTo(QPointF(89.36, 865.216), QPointF(111.968, 863.92), QPointF(125.648, 849.808));
    path.cubicTo(QPointF(137.24, 835.192), QPointF(145.808, 834.472), QPointF(162.872, 832.96));
    path.cubicTo(QPointF(190.736, 831.232), QPointF(218.024, 831.016), QPointF(242.648, 833.464));
    path.lineTo(270.728, 835.768);
    path.cubicTo(QPointF(270.224, 866.8), QPointF(330.272, 870.544), QPointF(347.912, 847));
    path.cubicTo(QPointF(369.224, 822.088), QPointF(398.528, 811), QPointF(423.656, 792.856));
    path.lineTo(290.816, 728.272);
    path.cubicTo(QPointF(256.76, 809.128), QPointF(129.824, 830.296), QPointF(112.256, 766));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(183, 114, 0, 255));
    path.moveTo(382.328, 691.984);
    path.cubicTo(QPointF(403.64, 698.968), QPointF(389.888, 720.28), QPointF(400.76, 732.52));
    path.cubicTo(QPointF(405.44, 742.888), QPointF(415.304, 752.032), QPointF(431.792, 760.528));
    path.cubicTo(QPointF(459.368, 774.424), QPointF(426.248, 799.336), QPointF(392.768, 812.08));
    path.cubicTo(QPointF(351.944, 825.616), QPointF(344.024, 862.912), QPointF(299.312, 851.896));
    path.cubicTo(QPointF(283.112, 846.496), QPointF(278.36, 831.808), QPointF(278.864, 809.128));
    path.cubicTo(QPointF(284.264, 762.76), QPointF(277.784, 730.432), QPointF(278.792, 698.824));
    path.cubicTo(QPointF(278.72, 686.152), QPointF(283.544, 684.64), QPointF(307.232, 687.952));
    path.cubicTo(QPointF(310.04, 726.328), QPointF(352.376, 727.336), QPointF(382.328, 691.984));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(242, 183, 0, 255));
    path.moveTo(339.632, 826.624);
    path.cubicTo(QPointF(371.6, 814.312), QPointF(403.856, 798.112), QPointF(429.848, 782.128));
    path.cubicTo(QPointF(437.84, 777.448), QPointF(438.92, 765.928), QPointF(427.688, 762.328));
    path.cubicTo(QPointF(403.352, 748.504), QPointF(390.104, 731.224), QPointF(392.912, 708.76));
    path.cubicTo(QPointF(393.344, 700.912), QPointF(383.696, 692.56), QPointF(381.104, 700.048));
    path.cubicTo(QPointF(359.864, 771.472), QPointF(291.32, 767.656), QPointF(300.752, 696.952));
    path.cubicTo(QPointF(301.256, 694.864), QPointF(301.76, 692.776), QPointF(302.264, 690.76));
    path.cubicTo(QPointF(289.952, 688.24), QPointF(285.2, 690.976), QPointF(285.776, 700.408));
    path.lineTo(295.28, 806.608);
    path.cubicTo(QPointF(297.656, 830.8), QPointF(317.312, 836.128), QPointF(339.632, 826.624));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(0, 0, 0, 255));
    path.moveTo(354.464, 537.544);
    path.cubicTo(QPointF(379.16, 569.8), QPointF(404.432, 651.088), QPointF(384.416, 691.552));
    path.cubicTo(QPointF(360.944, 737.776), QPointF(307.808, 743.248), QPointF(305.504, 695.8));
    path.cubicTo(QPointF(308.816, 639.64), QPointF(311.984, 581.536), QPointF(273.68, 544.096));
    path.cubicTo(QPointF(267.704, 497.368), QPointF(246.392, 480.232), QPointF(236.384, 450.28));
    path.lineTo(203.12, 426.088);
    path.lineTo(133.568, 435.088);
    path.cubicTo(QPointF(130.76, 452.152), QPointF(129.104, 468.784), QPointF(131.552, 484.912));
    path.cubicTo(QPointF(115.064, 507.376), QPointF(102.608, 530.056), QPointF(101.168, 553.312));
    path.cubicTo(QPointF(88.712, 586.648), QPointF(59.12, 614.944), QPointF(64.232, 680.752));
    path.cubicTo(QPointF(80.864, 698.248), QPointF(104.12, 714.448), QPointF(124.064, 731.296));
    path.cubicTo(QPointF(149.12, 752.392), QPointF(135.512, 776.296), QPointF(100.232, 769.672));
    path.cubicTo(QPointF(78.848, 746.056), QPointF(56.744, 722.872), QPointF(35.288, 699.328));
    path.cubicTo(QPointF(12.392, 683.056), QPointF(3.896, 662.176), QPointF(27.368, 630.496));
    path.cubicTo(QPointF(43.424, 609.04), QPointF(47.96, 562.456), QPointF(62, 543.664));
    path.cubicTo(QPointF(74.312, 525.16), QPointF(92.24, 508.6), QPointF(105.272, 490.096));
    path.cubicTo(QPointF(112.184, 477.928), QPointF(114.344, 468.568), QPointF(113.264, 454.456));
    path.lineTo(110.312, 369.136);
    path.cubicTo(QPointF(108.368, 307.216), QPointF(142.424, 274.24), QPointF(189.8, 275.248));
    path.cubicTo(QPointF(243.512, 275.752), QPointF(287.576, 312.472), QPointF(288.152, 378.28));
    path.cubicTo(QPointF(292.688, 410.32), QPointF(283.256, 428.68), QPointF(308.672, 474.472));
    path.cubicTo(QPointF(334.52, 522.712), QPointF(338.552, 520.12), QPointF(354.464, 537.544));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(261.296, 503.632);
    path.lineTo(263.528, 512.2);
    path.cubicTo(QPointF(257.696, 501.688), QPointF(250.712, 483.616), QPointF(241.928, 475.696));
    path.cubicTo(QPointF(239.264, 473.536), QPointF(235.808, 473.608), QPointF(233.72, 475.624));
    path.cubicTo(QPointF(222.056, 486.928), QPointF(193.112, 510.112), QPointF(169.928, 507.088));
    path.cubicTo(QPointF(152.072, 505.288), QPointF(134.648, 493.264), QPointF(130.832, 480.232));
    path.cubicTo(QPointF(128.816, 470.872), QPointF(129.752, 463.168), QPointF(130.976, 455.32));
    path.lineTo(240.704, 453.52);
    path.cubicTo(QPointF(238.472, 463.168), QPointF(253.088, 487), QPointF(261.296, 503.632));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(143.144, 363.232);
    path.cubicTo(QPointF(154.088, 363.232), QPointF(163.88, 376.84), QPointF(163.808, 395.632));
    path.cubicTo(QPointF(163.736, 408.232), QPointF(155.528, 411.472), QPointF(149.336, 417.016));
    path.cubicTo(QPointF(146.6, 419.536), QPointF(145.952, 433.144), QPointF(142.568, 433.144));
    path.cubicTo(QPointF(131.696, 433.144), QPointF(123.488, 413.776), QPointF(123.488, 395.632));
    path.cubicTo(QPointF(123.488, 377.56), QPointF(132.272, 363.232), QPointF(143.144, 363.232));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(255, 255, 255, 255));
    path.moveTo(144.368, 375.04);
    path.cubicTo(QPointF(154.088, 375.04), QPointF(160.856, 379.936), QPointF(161.648, 391.312));
    path.cubicTo(QPointF(162.224, 399.16), QPointF(160.136, 411.76), QPointF(154.664, 414.424));
    path.cubicTo(QPointF(152.144, 415.648), QPointF(143.432, 426.664), QPointF(140.408, 426.52));
    path.cubicTo(QPointF(128.096, 425.944), QPointF(125, 402.112), QPointF(125.936, 390.736));
    path.cubicTo(QPointF(126.8, 379.36), QPointF(134.72, 375.04), QPointF(144.368, 375.04));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(0, 0, 0, 255));
    path.moveTo(141.848, 382.672);
    path.cubicTo(QPointF(148.544, 382.096), QPointF(154.736, 389.728), QPointF(155.6, 399.664));
    path.cubicTo(QPointF(156.464, 409.6), QPointF(151.64, 418.24), QPointF(144.944, 418.816));
    path.cubicTo(QPointF(138.248, 419.392), QPointF(132.056, 411.76), QPointF(131.192, 401.752));
    path.cubicTo(QPointF(130.328, 391.816), QPointF(135.152, 383.248), QPointF(141.848, 382.672));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(151.064, 397.288);
    path.cubicTo(QPointF(151.424, 399.088), QPointF(149.408, 400.024), QPointF(148.832, 398.224));
    path.cubicTo(QPointF(148.256, 395.992), QPointF(146.888, 393.328), QPointF(145.088, 391.168));
    path.cubicTo(QPointF(143.936, 389.872), QPointF(145.088, 388.432), QPointF(146.528, 389.44));
    path.cubicTo(QPointF(149.048, 391.528), QPointF(150.488, 394.12), QPointF(151.064, 397.288));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(216.944, 360.712);
    path.cubicTo(QPointF(232.712, 360.712), QPointF(245.6, 377.416), QPointF(245.6, 397.792));
    path.cubicTo(QPointF(245.6, 418.24), QPointF(232.712, 434.872), QPointF(216.944, 434.872));
    path.cubicTo(QPointF(201.176, 434.872), QPointF(188.432, 418.24), QPointF(188.432, 397.792));
    path.cubicTo(QPointF(188.432, 377.416), QPointF(201.176, 360.712), QPointF(216.944, 360.712));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(255, 255, 255, 255));
    path.moveTo(224.792, 374.968);
    path.cubicTo(QPointF(235.664, 378.856), QPointF(241.928, 387.424), QPointF(242.72, 396.568));
    path.cubicTo(QPointF(243.656, 407.08), QPointF(239.408, 418.96), QPointF(230.264, 425.944));
    path.cubicTo(QPointF(227.672, 427.888), QPointF(197.72, 416.08), QPointF(195.992, 411.616));
    path.cubicTo(QPointF(193.4, 405.208), QPointF(191.816, 392.896), QPointF(193.76, 385.624));
    path.cubicTo(QPointF(194.552, 382.744), QPointF(197.216, 378.568), QPointF(201.176, 376.336));
    path.cubicTo(QPointF(207.44, 372.808), QPointF(216.656, 372.088), QPointF(224.792, 374.968));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(0, 0, 0, 255));
    path.moveTo(216.872, 380.944);
    path.cubicTo(QPointF(225.584, 380.944), QPointF(232.712, 389.296), QPointF(232.712, 399.448));
    path.cubicTo(QPointF(232.712, 409.672), QPointF(225.584, 418.024), QPointF(216.872, 418.024));
    path.cubicTo(QPointF(208.16, 418.024), QPointF(201.032, 409.672), QPointF(201.032, 399.448));
    path.cubicTo(QPointF(201.032, 389.296), QPointF(208.16, 380.944), QPointF(216.872, 380.944));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(227.096, 392.392);
    path.cubicTo(QPointF(228.104, 394.048), QPointF(226.448, 395.776), QPointF(225.224, 394.12));
    path.cubicTo(QPointF(223.784, 392.104), QPointF(221.408, 389.944), QPointF(218.888, 388.432));
    path.cubicTo(QPointF(217.232, 387.568), QPointF(217.808, 385.624), QPointF(219.68, 386.2));
    path.cubicTo(QPointF(222.92, 387.28), QPointF(225.368, 389.368), QPointF(227.096, 392.392));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(183, 114, 0, 255));
    path.moveTo(164.96, 404.488);
    path.cubicTo(QPointF(172.376, 402.328), QPointF(184.112, 403.048), QPointF(192.248, 404.632));
    path.cubicTo(QPointF(200.384, 406.792), QPointF(222.056, 418.24), QPointF(245.024, 430.696));
    path.cubicTo(QPointF(247.976, 432.208), QPointF(248.84, 437.104), QPointF(245.024, 438.688));
    path.cubicTo(QPointF(239.12, 439.12), QPointF(249.272, 453.664), QPointF(238.904, 458.848));
    path.cubicTo(QPointF(223.352, 462.88), QPointF(198.44, 485.992), QPointF(186.128, 487.864));
    path.cubicTo(QPointF(179.288, 489.376), QPointF(172.232, 489.592), QPointF(164.6, 487.864));
    path.cubicTo(QPointF(140.552, 482.968), QPointF(134.216, 455.608), QPointF(122.912, 450.064));
    path.cubicTo(QPointF(119.816, 446.824), QPointF(121.4, 441.208), QPointF(122.408, 440.056));
    path.cubicTo(QPointF(123.632, 434.224), QPointF(149.696, 406.216), QPointF(164.96, 404.488));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(242, 183, 0, 255));
    path.moveTo(185.408, 405.856);
    path.cubicTo(QPointF(198.44, 407.296), QPointF(226.088, 423.928), QPointF(239.408, 430.624));
    path.cubicTo(QPointF(242.72, 432.424), QPointF(242.504, 437.824), QPointF(239.552, 438.688));
    path.cubicTo(QPointF(236.384, 440.488), QPointF(235.448, 438.256), QPointF(232.928, 437.896));
    path.cubicTo(QPointF(228.896, 435.736), QPointF(222.272, 440.92), QPointF(217.016, 444.88));
    path.cubicTo(QPointF(186.704, 467.776), QPointF(180.656, 465.256), QPointF(156.176, 462.664));
    path.cubicTo(QPointF(147.68, 460.576), QPointF(142.136, 457.984), QPointF(139.688, 455.968));
    path.cubicTo(QPointF(141.488, 445.888), QPointF(160.496, 407.656), QPointF(166.76, 406.792));
    path.cubicTo(QPointF(168.344, 404.704), QPointF(179.936, 404.632), QPointF(185.408, 405.856));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(183, 114, 0, 255));
    path.moveTo(190.664, 412.048);
    path.lineTo(193.76, 413.416);
    path.cubicTo(QPointF(196.064, 414.712), QPointF(193.256, 418.168), QPointF(190.736, 417.088));
    path.lineTo(186.2, 415.504);
    path.cubicTo(QPointF(183.536, 413.272), QPointF(186.704, 410.104), QPointF(190.664, 412.048));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(268.568, 452.368);
    path.cubicTo(QPointF(273.032, 454.384), QPointF(279.224, 457.192), QPointF(282.536, 460.144));
    path.cubicTo(QPointF(285.488, 464.104), QPointF(286.784, 468.064), QPointF(286.424, 472.024));
    path.cubicTo(QPointF(285.776, 474.544), QPointF(284.12, 476.344), QPointF(281.24, 477.424));
    path.cubicTo(QPointF(277.856, 478.216), QPointF(273.68, 477.424), QPointF(271.376, 474.112));
    path.cubicTo(QPointF(269.864, 471.448), QPointF(265.256, 462.16), QPointF(263.96, 460.576));
    path.cubicTo(QPointF(262.232, 457.12), QPointF(261.944, 454.456), QPointF(262.88, 452.368));
    path.cubicTo(QPointF(264.032, 451.288), QPointF(266.048, 451), QPointF(268.568, 452.368));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(255, 255, 255, 255));
    path.moveTo(273.752, 461.584);
    path.cubicTo(QPointF(275.48, 462.376), QPointF(277.928, 463.456), QPointF(279.224, 464.68));
    path.cubicTo(QPointF(280.376, 466.264), QPointF(280.88, 467.776), QPointF(280.736, 469.36));
    path.cubicTo(QPointF(280.52, 470.296), QPointF(279.8, 471.016), QPointF(278.72, 471.448));
    path.cubicTo(QPointF(277.352, 471.808), QPointF(275.768, 471.448), QPointF(274.832, 470.152));
    path.cubicTo(QPointF(274.256, 469.144), QPointF(272.456, 465.472), QPointF(271.952, 464.824));
    path.cubicTo(QPointF(271.232, 463.456), QPointF(271.088, 462.448), QPointF(271.448, 461.584));
    path.cubicTo(QPointF(271.952, 461.152), QPointF(272.744, 461.08), QPointF(273.752, 461.584));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(238.616, 358.552);
    path.cubicTo(QPointF(239.048, 359.2), QPointF(238.976, 359.776), QPointF(238.4, 360.28));
    path.cubicTo(QPointF(237.896, 360.784), QPointF(237.176, 360.712), QPointF(236.24, 360.208));
    path.lineTo(231.632, 356.248);
    path.cubicTo(QPointF(231.056, 355.744), QPointF(230.912, 354.952), QPointF(231.272, 354.088));
    path.cubicTo(QPointF(232.28, 353.44), QPointF(233.144, 353.44), QPointF(233.936, 354.088));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(235.592, 305.992);
    path.cubicTo(QPointF(239.624, 308.224), QPointF(240.848, 313.912), QPointF(238.184, 318.592));
    path.cubicTo(QPointF(235.592, 323.2), QPointF(230.12, 325.144), QPointF(226.016, 322.84));
    path.cubicTo(QPointF(221.984, 320.536), QPointF(220.76, 314.92), QPointF(223.424, 310.24));
    path.cubicTo(QPointF(226.016, 305.56), QPointF(231.488, 303.688), QPointF(235.592, 305.992));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(374.912, 680.536);
    path.cubicTo(QPointF(378.296, 683.128), QPointF(373.256, 687.376), QPointF(371.024, 686.296));
    path.cubicTo(QPointF(369.152, 685.648), QPointF(367.784, 683.488), QPointF(366.92, 682.408));
    path.cubicTo(QPointF(366.128, 681.184), QPointF(366.2, 679.168), QPointF(366.92, 678.448));
    path.cubicTo(QPointF(367.712, 677.44), QPointF(369.728, 677.656), QPointF(371.024, 678.52));
    path.cubicTo(QPointF(372.32, 679.168), QPointF(373.616, 679.888), QPointF(374.912, 680.536));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(297.44, 551.512);
    path.cubicTo(QPointF(338.984, 572.896), QPointF(350, 611.56), QPointF(332.072, 664.192));
    path.cubicTo(QPointF(330.992, 666.64), QPointF(334.16, 668.368), QPointF(335.24, 666.064));
    path.cubicTo(QPointF(354.824, 610.336), QPointF(341.432, 571.312), QPointF(299.024, 548.56));
    path.cubicTo(QPointF(296.864, 547.552), QPointF(295.28, 550.432), QPointF(297.44, 551.512));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(72.008, 569.512);
    path.cubicTo(QPointF(38.312, 627.256), QPointF(38.096, 662.68), QPointF(62.504, 681.328));
    path.cubicTo(QPointF(63.728, 682.264), QPointF(64.448, 680.032), QPointF(63.296, 679.168));
    path.cubicTo(QPointF(36.296, 655.48), QPointF(48.896, 615.52), QPointF(74.168, 570.88));
    path.cubicTo(QPointF(74.888, 569.584), QPointF(72.512, 568.432), QPointF(72.008, 569.512));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(289.376, 586.864);
    path.cubicTo(QPointF(289.232, 589.168), QPointF(288.368, 589.528), QPointF(286.424, 587.368));
    path.cubicTo(QPointF(279.8, 575.848), QPointF(235.088, 551.44), QPointF(213.344, 548.704));
    path.cubicTo(QPointF(209.24, 547.264), QPointF(209.456, 545.392), QPointF(213.488, 544.816));
    path.cubicTo(QPointF(229.184, 544.816), QPointF(241.28, 537.904), QPointF(254.96, 537.904));
    path.cubicTo(QPointF(258.704, 538.048), QPointF(262.304, 539.488), QPointF(264.392, 541.648));
    path.cubicTo(QPointF(269.504, 544.96), QPointF(288.08, 570.592), QPointF(289.376, 586.864));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(180.152, 546.832);
    path.cubicTo(QPointF(180.872, 550.792), QPointF(163.808, 545.68), QPointF(164.744, 556.696));
    path.cubicTo(QPointF(165.032, 559.72), QPointF(160.496, 561.376), QPointF(160.64, 556.696));
    path.cubicTo(QPointF(160.64, 548.272), QPointF(161.072, 548.416), QPointF(152.72, 546.832));
    path.cubicTo(QPointF(151.208, 546.76), QPointF(151.352, 544.528), QPointF(152.72, 544.816));
    path.lineTo(152.72, 544.816);
    path.cubicTo(QPointF(158.696, 546.472), QPointF(166.76, 542.872), QPointF(166.4, 538.84));
    path.cubicTo(QPointF(166.256, 537.472), QPointF(168.56, 537.688), QPointF(168.488, 538.84));
    path.cubicTo(QPointF(167.984, 545.248), QPointF(181.664, 542.152), QPointF(180.152, 546.832));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(193, 193, 191, 255));
    path.moveTo(151.568, 705.376);
    path.cubicTo(QPointF(151.64, 708.328), QPointF(148.76, 707.68), QPointF(148.544, 705.592));
    path.cubicTo(QPointF(140.192, 680.536), QPointF(143.72, 618.832), QPointF(151.856, 598.96));
    path.cubicTo(QPointF(152.432, 596.08), QPointF(156.248, 596.944), QPointF(155.744, 598.96));
    path.cubicTo(QPointF(147.104, 635.464), QPointF(147.248, 673.048), QPointF(151.568, 705.376));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(183, 114, 0, 255));
    path.moveTo(51.704, 684.424);
    path.cubicTo(QPointF(75.68, 707.824), QPointF(91.376, 743.248), QPointF(114.632, 775.288));
    path.cubicTo(QPointF(148.472, 816.04), QPointF(121.472, 858.304), QPointF(66.464, 845.56));
    path.cubicTo(QPointF(38.888, 835.192), QPointF(-0.784, 836.344), QPointF(-32.68, 825.832));
    path.cubicTo(QPointF(-55.072, 820.36), QPointF(-55.864, 809.272), QPointF(-44.416, 787.6));
    path.cubicTo(QPointF(-40.384, 773.776), QPointF(-40.024, 751.312), QPointF(-43.768, 732.592));
    path.cubicTo(QPointF(-45.784, 718.408), QPointF(-39.232, 710.488), QPointF(-24.112, 708.832));
    path.lineTo(-24.112, 708.832);
    path.cubicTo(QPointF(-11.296, 708.688), QPointF(6.56, 713.872), QPointF(16.28, 686.44));
    path.cubicTo(QPointF(23.552, 673.336), QPointF(40.976, 672.976), QPointF(51.704, 684.424));
    path.closeSubpath();
    painter->drawPath(path);
    path = QPainterPath();

    painter->setBrush(QColor(242, 183, 0, 255));
    path.moveTo(24.632, 699.04);
    path.cubicTo(QPointF(23.84, 680.968), QPointF(39.32, 677.296), QPointF(49.688, 688.312));
    path.cubicTo(QPointF(68.192, 710.992), QPointF(85.112, 736.048), QPointF(100.376, 764.992));
    path.cubicTo(QPointF(124.712, 804.16), QPointF(104.624, 842.68), QPointF(67.904, 828.064));
    path.cubicTo(QPointF(49.688, 817.84), QPointF(6.128, 813.304), QPointF(-17.344, 809.128));
    path.cubicTo(QPointF(-33.04, 807.832), QPointF(-35.128, 797.608), QPointF(-29.152, 791.848));
    path.cubicTo(QPointF(-20.944, 782.416), QPointF(-20.08, 759.808), QPointF(-27.856, 740.512));
    path.cubicTo(QPointF(-35.56, 728.56), QPointF(-21.088, 715.384), QPointF(-9.712, 720.856));
    path.cubicTo(QPointF(0.8, 727.048), QPointF(25.64, 713.08), QPointF(24.632, 699.04));
    path.closeSubpath();
    painter->drawPath(path);

    painter->setPen(QPen(QColor(255, 0, 0, alpha), 0.25, Qt::SolidLine, Qt::FlatCap, Qt::BevelJoin));
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(br.adjusted(-1, -1, 1, 1));
}
Ejemplo n.º 6
0
int Nightcharts::draw(QPainter *painter)
{
    painter->setRenderHint(QPainter::Antialiasing);
    painter->setPen(Qt::NoPen);

    if (this->ctype == Nightcharts::Pie)
    {
        pW = 0;
        double pdegree = 0;

        //Options
        QLinearGradient gradient(cX+0.5*cW,cY,cX+0.5*cW,cY+cH*2.5);
        gradient.setColorAt(1,Qt::black);

        //Draw
        //pdegree = (360/100)*pieces[i].pPerc;
        if (shadows)
        {
            double sumangle = 0;
            for (int i = 0; i < pieces.size(); i++)
            {
                sumangle += 3.6 * pieces[i].pPerc;
            }
            painter->setBrush(Qt::darkGray);
            painter->drawPie(cX,cY+pW+5,cW,cH,palpha*16,sumangle*16);
        }

        QPen pen;
        pen.setWidth(2);

        for (int i = 0; i < pieces.size(); i++)
        {
            gradient.setColorAt(0, pieces[i].rgbColor);
            painter->setBrush(gradient);
            pen.setColor(pieces[i].rgbColor);
            painter->setPen(pen);
            pdegree = 3.6 * pieces[i].pPerc;
            painter->drawPie(cX, cY, cW, cH, palpha*16, pdegree*16);
            palpha += pdegree;
        }
    }
    else if (this->ctype == Nightcharts::Dpie)
    {
        pW = 50;
        double pdegree = 0;
        QPointF p;

        QLinearGradient gradient(cX - 0.5 * cW, cY + cH/2, cX + 1.5 * cW, cY + cH/2);
        gradient.setColorAt(0,Qt::black);
        gradient.setColorAt(1,Qt::white);
        QLinearGradient gradient_side(cX, cY + cH, cX + cW, cY + cH);
        gradient_side.setColorAt(0,Qt::black);

        double sumangle = 0;

        for (int i = 0; i < pieces.size(); i++)
        {
            sumangle += 3.6 * pieces[i].pPerc;
        }
        if (shadows)
        {
            painter->setBrush(Qt::darkGray);
            painter->drawPie(cX, cY + pW + 5, cW, cH, palpha * 16, sumangle * 16);
        }

        int q = GetQuater(palpha+sumangle);

        if (q ==2 || q==3)
        {
            QPointF p = GetPoint(palpha+sumangle);
            QPointF points[4] =
            {
                QPointF(p.x(), p.y()),
                QPointF(p.x(), p.y() + pW),
                QPointF(cX + cW/2, cY + cH/2 + pW),
                QPointF(cX + cW/2, cY + cH/2)
            };
            gradient_side.setColorAt(1, pieces[pieces.size()-1].rgbColor);
            painter->setBrush(gradient_side);
            painter->drawPolygon(points, 4);
        }
        p = GetPoint(palpha);
        q = GetQuater(palpha);

        if (q ==1 || q==4)
        {
            QPointF points[4] =
            {
                QPointF(p.x(), p.y()),
                QPointF(p.x(), p.y() + pW),
                QPointF(cX + cW/2, cY + cH/2 + pW),
                QPointF(cX + cW/2, cY + cH/2)
            };
            gradient_side.setColorAt(1, pieces[0].rgbColor);
            painter->setBrush(gradient_side);
            painter->drawPolygon(points, 4);
        }

        for (int i = 0;i < pieces.size(); i++)
        {
            gradient.setColorAt(0.5, pieces[i].rgbColor);
            painter->setBrush(gradient);
            pdegree = 3.6 * pieces[i].pPerc;
            painter->drawPie(cX, cY, cW, cH, palpha * 16, pdegree * 16);

            double a_ = Angle360(palpha);
            int q_ = GetQuater(palpha);

            palpha += pdegree;

            double a = Angle360(palpha);
            int q = GetQuater(palpha);

            QPainterPath path;
            p = GetPoint(palpha);

            if((q == 3 || q == 4) && (q_ == 3 || q_ == 4))
            {
                // 1)
                if (a>a_)
                {
                    QPointF p_old = GetPoint(palpha-pdegree);
                    path.moveTo(p_old.x() - 1, p_old.y());
                    path.arcTo(cX, cY, cW, cH, palpha-pdegree, pdegree);
                    path.lineTo(p.x(), p.y() + pW);
                    path.arcTo(cX, cY + pW, cW, cH, palpha, -pdegree);
                }
                // 2)
                else
                {
                    path.moveTo(cX, cY + cH/2);
                    path.arcTo(cX, cY, cW, cH, 180, Angle360(palpha) - 180);
                    path.lineTo(p.x(), p.y() + pW);
                    path.arcTo(cX, cY + pW, cW, cH, Angle360(palpha), -Angle360(palpha) + 180);
                    path.lineTo(cX, cY + cH/2);

                    path.moveTo(p.x(), p.y());
                    path.arcTo(cX, cY, cW, cH, palpha-pdegree, 360 - Angle360(palpha - pdegree));
                    path.lineTo(cX + cW, cY + cH/2 + pW);
                    path.arcTo(cX, cY + pW, cW, cH, 0, -360 + Angle360(palpha - pdegree));
                }

            }
            // 3)
            else if((q == 3 || q == 4) && (q_ == 1 || q_ == 2) && a>a_ )
            {
                path.moveTo(cX,cY+cH/2);
                path.arcTo(cX,cY,cW,cH,180,Angle360(palpha)-180);
                path.lineTo(p.x(),p.y()+pW);
                path.arcTo(cX,cY+pW,cW,cH,Angle360(palpha),-Angle360(palpha)+180);
                path.lineTo(cX,cY+cH/2);
            }
            // 4)
            else if((q == 1 || q == 2) && (q_ == 3 || q_ == 4) && a<a_)
            {
                p = GetPoint(palpha-pdegree);
                path.moveTo(p.x(),p.y());
                path.arcTo(cX,cY,cW,cH,palpha-pdegree,360-Angle360(palpha-pdegree));
                path.lineTo(cX+cW,cY+cH/2+pW);
                path.arcTo(cX,cY+pW,cW,cH,0,-360+Angle360(palpha-pdegree));
            }
            // 5)
            else if((q ==1 || q==2) && (q_==1 || q_==2) && a<a_)
            {
                path.moveTo(cX,cY+cH/2);
                path.arcTo(cX,cY,cW,cH,180,180);
                path.lineTo(cX+cW,cY+cH/2+pW);
                path.arcTo(cX,cY+pW,cW,cH,0,-180);
                path.lineTo(cX,cY+cH/2);
            }
            if (!path.isEmpty())
            {
                gradient_side.setColorAt(1,pieces[i].rgbColor);
                painter->setBrush(gradient_side);
                painter->drawPath(path);
            }
        }
    }
    else if (this->ctype==Nightcharts::Histogramm)
    {
        double pDist = 15;
        double pW = (cW-(pieces.size())*pDist)/pieces.size();

        QLinearGradient gradient(cX + cW/2, cY, cX + cW/2, cY + cH);
        gradient.setColorAt(0,Qt::black);
        QPen pen;
        pen.setWidth(3);

        for (int i = 0;i < pieces.size(); i++)
        {
            if (shadows)
            {
                painter->setPen(Qt::NoPen);
                painter->setBrush(Qt::darkGray);
                painter->drawRect(cX+pDist+i*(pW + pDist)-pDist/2,cY+cH-1,pW,-cH/100*pieces[i].pPerc+pDist/2-5);
            }
            gradient.setColorAt(1,pieces[i].rgbColor);
            painter->setBrush(gradient);
            pen.setColor(pieces[i].rgbColor);
            painter->setPen(pen);
            painter->drawRect(cX+pDist+i*(pW + pDist),cY+cH,pW,-cH/100*pieces[i].pPerc-5);
            QString label = QString::number(pieces[i].pPerc)+"%";
            painter->setPen(Qt::SolidLine);
            painter->drawText(cX+pDist+i*(pW + pDist)+pW/2-painter->fontMetrics().width(label)/2,cY+cH-cH/100*pieces[i].pPerc-painter->fontMetrics().height()/2,label);
        }
        painter->setPen(Qt::SolidLine);
        for (int i = 1; i < 10; i++)
        {
            painter->drawLine(cX - 3, cY + cH/10 * i, cX + 3, cY + cH/10 * i);    //§Õ§Ö§Ý§Ö§ß§Ú§ñ §á§à §à§ã§Ú Y
            //painter->drawText(cX-20,cY+cH/10*i,QString::number((10-i)*10)+"%");
        }
        painter->drawLine(cX,cY+cH,cX,cY);         //§à§ã§î Y
        painter->drawLine(cX,cY,cX+4,cY+10);       //§ã§ä§â§Ö§Ý§Ü§Ú
        painter->drawLine(cX,cY,cX-4,cY+10);
        painter->drawLine(cX,cY+cH,cX+cW,cY+cH);   //§à§ã§î §·

    }
    return 0;
}
Ejemplo n.º 7
0
void PathStrokeRenderer::paint(QPainter *painter)
{
    if (m_points.isEmpty())
        initializePoints();

    painter->setRenderHint(QPainter::Antialiasing);

    QPalette pal = palette();
    painter->setPen(Qt::NoPen);

    // Construct the path
    QPainterPath path;
    path.moveTo(m_points.at(0));

    if (m_pathMode == LineMode) {
        for (int i=1; i<m_points.size(); ++i)
            path.lineTo(m_points.at(i));
    } else {
        int i=1;
        while (i + 2 < m_points.size()) {
            path.cubicTo(m_points.at(i), m_points.at(i+1), m_points.at(i+2));
            i += 3;
        }
        while (i < m_points.size()) {
            path.lineTo(m_points.at(i));
            ++i;
        }
    }

    // Draw the path
    {
        QColor lg = Qt::red;

        // The "custom" pen
        if (m_penStyle == Qt::NoPen) {
            QPainterPathStroker stroker;
            stroker.setWidth(m_penWidth);
            stroker.setJoinStyle(m_joinStyle);
            stroker.setCapStyle(m_capStyle);

            QVector<qreal> dashes;
            qreal space = 4;
            dashes << 1 << space
                   << 3 << space
                   << 9 << space
                   << 27 << space
                   << 9 << space
                   << 3 << space;
            stroker.setDashPattern(dashes);
            QPainterPath stroke = stroker.createStroke(path);
            painter->fillPath(stroke, lg);

        } else {
            QPen pen(lg, m_penWidth, m_penStyle, m_capStyle, m_joinStyle);
            painter->strokePath(path, pen);
        }
    }

    if (1) {
        // Draw the control points
        painter->setPen(QColor(50, 100, 120, 200));
        painter->setBrush(QColor(200, 200, 210, 120));
        for (int i=0; i<m_points.size(); ++i) {
            QPointF pos = m_points.at(i);
            painter->drawEllipse(QRectF(pos.x() - m_pointSize,
                                       pos.y() - m_pointSize,
                                       m_pointSize*2, m_pointSize*2));
        }
        painter->setPen(QPen(Qt::lightGray, 0, Qt::SolidLine));
        painter->setBrush(Qt::NoBrush);
        painter->drawPolyline(m_points);
    }

}
Ejemplo n.º 8
0
QIcon QSparkLineIconFactory::create(const QList< double > &_observations,
                                    const double _minimum,
                                    const double _minRange,
                                    const QColor &_color,
                                    const QColor &_bgColor,
                                    const int _width,
                                    const int _height,
                                    const int _leftPadding,
                                    const int _rightPadding,
                                    const int _topPadding,
                                    const int _bottomPadding)
{
    QPixmap pixmap(_width, _height);
    pixmap.fill(_bgColor);
    QPainter painter(&pixmap);

    int graphHeight = pixmap.rect().height() - _topPadding - _bottomPadding;
    int graphWidth = pixmap.rect().width() - _leftPadding - _rightPadding;
    QPoint bl = pixmap.rect().bottomLeft();

    QPainterPath path;

    if (_observations.size() > 1)
    {
        double min =
            *std::min_element(_observations.begin(), _observations.end());
        min = std::min(min, _minimum);
        double max =
            *std::max_element(_observations.begin(), _observations.end());

        double range = max - min;

        if (range < _minRange)
        {
            max += _minRange - range;
        }

        double skip = 0;

        if (min != max)
        {
            skip = double(graphHeight - 1) / (max - min);

            double width = graphWidth / double(_observations.size() - 1);

            double x = _leftPadding;
            double y = -_bottomPadding;

            bool first = true;

            QList< double >::const_iterator i = _observations.begin();
            QList< double >::const_iterator iend = _observations.end();

            for (; i != iend; ++i)
            {
                double height = (*i - min) * skip;

                if (first)
                {
                    y -= height;
                    first = false;
                    path.moveTo(bl.x() + int(x), bl.y() + int(y));
                }
                else
                {
                    x += width;
                    y = -_bottomPadding - height;

                    path.lineTo(bl.x() + int(x), bl.y() + int(y));
                }
            }
        }
    }

    if (!path.isEmpty())
    {
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.setPen(
            QPen(_color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
        painter.drawPath(path);
    }

    return QIcon(pixmap);
}
Ejemplo n.º 9
0
QPainterPath Paths::deer()
{
    QPainterPath path;

    path.moveTo(39.88,31.658);
    path.cubicTo(35.632,31.658, 31.398,31.004, 27.871,32.82);
    path.cubicTo(25.015,34.29, 19.608,34.158, 16.297,34.158);
    path.cubicTo(14.722,34.158, 17.755,37.718, 17.709,38.922);
    path.cubicTo(17.578,42.396, 24.612,43.15, 26.755,44.058);
    path.cubicTo(30.062,45.46, 28.682,47.701, 28.963,50.574);
    path.cubicTo(29.715,58.243, 26.887,63.745, 24.182,70.589);
    path.cubicTo(23.365,72.657, 21.772,75.56, 21.972,77.866);
    path.cubicTo(22.333,82.029, 15.803,77.207, 13.894,76.535);
    path.cubicTo(10.977,75.508, 5.507,74.071, 2.424,75.331);
    path.cubicTo(-1.532,76.947, 0.076,80.491, 2.169,82.806);
    path.cubicTo(6.17,87.234, 2.703,90.713, 3.895,95.363);
    path.cubicTo(4.321,97.026, 11.682,104.683, 12.858,103.668);
    path.cubicTo(16.706,100.347, 11.464,98.692, 10.105,96.164);
    path.cubicTo(9.487,95.015, 8.616,83.742, 8.866,83.759);
    path.cubicTo(10.018,83.837, 12.591,85.867, 13.671,86.392);
    path.cubicTo(16.889,87.954, 20.066,89.63, 22.963,91.741);
    path.cubicTo(29.156,94.47, 35.543,96.965, 42.102,98.676);
    path.cubicTo(51.085,101.02, 59.407,102.003, 68.009,106.005);
    path.cubicTo(72.92,108.289, 72.05,113.282, 75.744,117.004);
    path.cubicTo(79.422,120.709, 84.733,123.053, 88.978,126.053);
    path.cubicTo(92.402,128.473, 95.422,132.308, 97.334,135.998);
    path.cubicTo(99.551,140.279, 99.071,146.004, 99.838,150.674);
    path.cubicTo(100.369,153.91, 104.378,156.321, 106.302,158.859);
    path.cubicTo(110.471,164.355, 109.86,155.112, 108.163,154.412);
    path.cubicTo(104.97,153.094, 103.991,146.625, 103.812,143.439);
    path.cubicTo(103.525,138.336, 105.568,134.331, 101.918,130.346);
    path.cubicTo(95.104,122.907, 89.488,114.182, 94.711,103.742);
    path.cubicTo(96.889,99.388, 91.191,95.497, 96.94,94.368);
    path.cubicTo(99.551,93.856, 102.49,94.367, 104.326,92.034);
    path.cubicTo(106.639,89.095, 105.063,85.343, 102.943,82.798);
    path.cubicTo(102.686,82.417, 102.359,82.121, 101.962,81.909);
    path.cubicTo(102.331,81.909, 101.923,86.98, 100.981,87.628);
    path.cubicTo(98.868,89.082, 95.569,91.586, 92.88,91.672);
    path.cubicTo(90.569,91.745, 86.738,89.184, 85.212,87.658);
    path.cubicTo(84.092,86.538, 80.176,86.157, 78.598,85.83);
    path.cubicTo(74.737,85.031, 71.741,84.326, 68.012,82.806);
    path.cubicTo(63.318,80.893, 58.687,78.672, 54.555,75.71);
    path.cubicTo(44.573,68.555, 42.755,56.146, 44.022,44.495);
    path.cubicTo(44.295,41.987, 43.169,38.057, 44.617,35.915);
    path.cubicTo(44.961,35.406, 46.52,35.553, 47.119,35.024);
    path.cubicTo(47.882,34.35, 49.574,31.822, 49.878,30.792);
    path.cubicTo(51.126,26.569, 44.36,32.002, 45.336,31.938);
    path.cubicTo(43.861,32.036, 47.011,22.934, 47.191,22.574);
    path.cubicTo(47.555,21.846, 52.489,13.123, 49.511,13.222);
    path.cubicTo(47.643,13.284, 48.563,18.667, 46.354,18.227);
    path.cubicTo(43.964,17.751, 40.522,11.396, 41.566,9.011);
    path.cubicTo(43.4,4.819, 39.743,3.905, 39.214,7.564);
    path.cubicTo(39.112,8.269, 40.893,13.438, 38.159,12.665);
    path.cubicTo(35.335,11.866, 35.748,-0.125, 34.38,-8.0352391e-15);
    path.cubicTo(31.991,0.219, 34.074,10.836, 33.361,12.176);
    path.cubicTo(33.144,12.584, 29.68,8.66, 29.459,7.718);
    path.cubicTo(28.48,3.558, 28.031,5.106, 26.87,7.752);
    path.cubicTo(25.333,11.254, 37.159,17.423, 39.292,18.663);
    path.cubicTo(40.993,19.651, 42.39,20.504, 42.973,22.48);
    path.cubicTo(43.482,24.205, 44.098,26.568, 42.926,28.191);
    path.cubicTo(42.092,29.346, 39.88,29.982, 39.88,31.658);
    return path;
}
Ejemplo n.º 10
0
//! [8]
void RenderArea::paintEvent(QPaintEvent * /* event */)
{
    //! [9]
        QPainter painter(this);
        painter.setPen(pen);
        painter.setBrush(brush);
        painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, antialiased);

    //! [9]

        if (doRunTest)
       {
            QPoint ptCenter = this->rect().center();
            if (transformed) {
                painter.translate(ptCenter);
                //painter.rotate(60.0);
                painter.scale(0.99, 0.99);
                painter.translate(-ptCenter );
            }

            if (this->deviceType4Draw == QInternal::Widget) {
                qDebug() << "RenderArea: painter.device(): " << g_paintDeviceType[painter.device()->devType()]
                                << ", painter.paintEngine(): " << g_paintEngineType[painter.paintEngine()->type()];
                painter.fillRect(this->rect(), Qt::white);
                KQtTester tester(&painter);
                tester.runTest();
            } else if (this->deviceType4Draw == QInternal::Pixmap) {
                QPixmap pix(this->width(), this->height());
                pix.fill(Qt::white);
                QPainter pixPainter(&pix);
                pixPainter.setPen(pen);
                pixPainter.setBrush(brush);
                pixPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, antialiased);
                qDebug() << "Pixmap: pixPainter.device(): " << g_paintDeviceType[pixPainter.device()->devType()]
                                 << ", pixPainter.paintEngine(): " << g_paintEngineType[pixPainter.paintEngine()->type()];

                KQtTester tester(&pixPainter);
                tester.runTest();
                pixPainter.end();

                painter.fillRect(0, 0, 2000, 2000, Qt::white);
                painter.drawPixmap(0, 0, pix);
            } else if (this->deviceType4Draw == QInternal::Image) {
                QImage img(this->width(), this->height(), QImage::Format_ARGB32_Premultiplied);
                img.fill(0xffffffff);
                QPainter imgPainter(&img);
                imgPainter.setPen(pen);
                imgPainter.setBrush(brush);
                imgPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, antialiased);
                qDebug() << "Image: imgPainter.device(): " << g_paintDeviceType[imgPainter.device()->devType()]
                                << ", imgPainter.paintEngine(): " << g_paintEngineType[imgPainter.paintEngine()->type()];

                KQtTester tester(&imgPainter);
                tester.runTest();
                imgPainter.end();

                painter.fillRect(0, 0, 2000, 2000, Qt::white);
                painter.drawImage(0, 0, img);
            } else
                Q_ASSERT(0);


            return;
        }

    static const QPoint points[4] = {
        QPoint(10, 80),
        QPoint(20, 10),
        QPoint(80, 30),
        QPoint(90, 70)
    };

    QRect rect(10, 20, 80, 60);

    QPainterPath path;
    path.moveTo(20, 80);
    path.lineTo(20, 30);
    path.cubicTo(80, 0, 50, 50, 80, 80);

    int startAngle = 20 * 16;
    int arcLength = 120 * 16;
//! [8]

//! [10]
    for (int x = 0; x < width(); x += 100) {
        for (int y = 0; y < height(); y += 100) {
            painter.save();
            painter.translate(x, y);
//! [10] //! [11]
            if (transformed) {
                painter.translate(50, 50);
                painter.rotate(60.0);
                painter.scale(0.6, 0.9);
                painter.translate(-50, -50);
            }
//! [11]

//! [12]
            switch (shape) {
            case Line:
                painter.drawLine(rect.bottomLeft(), rect.topRight());
                break;
            case Points:
                painter.drawPoints(points, 4);
                break;
            case Polyline:
                painter.drawPolyline(points, 4);
                break;
            case Polygon:
                painter.drawPolygon(points, 4);
                break;
            case Rect:
                painter.drawRect(rect);
                break;
            case RoundedRect:
                painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
                break;
            case Ellipse:
                painter.drawEllipse(rect);
                break;
            case Arc:
                painter.drawArc(rect, startAngle, arcLength);
                break;
            case Chord:
                painter.drawChord(rect, startAngle, arcLength);
                break;
            case Pie:
                painter.drawPie(rect, startAngle, arcLength);
                break;
            case Path:
                painter.drawPath(path);
                break;
            case Text:
                painter.drawText(rect, Qt::AlignCenter, tr("hello,oken! "));
                break;
            case Pixmap:
                painter.drawPixmap(10, 10, pixmap);
            }
//! [12] //! [13]
            painter.restore();
        }
    }

    painter.setRenderHint(QPainter::Antialiasing, false);
    painter.setPen(palette().dark().color());
    painter.setBrush(Qt::NoBrush);
    painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
}
Ejemplo n.º 11
0
QIcon QSparkLineIconFactory::create(
    const QList< QPair< double, time_t > > &_observations,
    const QColor &_color,
    QList< QPair< time_t, QColor > > _divisions,
    const QColor &_bgColor,
    const double _minimum,
    const double _minRange,
    const int _width,
    const int _height,
    const int _leftPadding,
    const int _rightPadding,
    const int _topPadding,
    const int _bottomPadding)
{
    QPixmap pixmap(_width, _height);
    pixmap.fill(_bgColor);
    QPainter painter(&pixmap);

    int graphHeight = pixmap.rect().height() - _topPadding - _bottomPadding;
    int graphWidth = pixmap.rect().width() - _leftPadding - _rightPadding;
    QPoint bl = pixmap.rect().bottomLeft();

    _divisions.push_front(QPair< time_t, QColor >(0, _color));
    QList< QPair< time_t, QColor > >::iterator color = _divisions.begin();

    QPainterPath path;

    if (_observations.size() > 1)
    {
        double min =
            std::min_element(_observations.begin(), _observations.end())->first;
        min = std::min(min, _minimum);
        double max =
            std::max_element(_observations.begin(), _observations.end())->first;

        double range = max - min;

        if (range < _minRange)
        {
            max += _minRange - range;
        }

        double skip = 0;

        if (min != max)
        {
            skip = double(graphHeight - 1) / (max - min);

            double width = graphWidth / double(_observations.size() - 1);

            double x = _leftPadding;
            double y = -_bottomPadding;

            bool first = true;

            QList< QPair< double, time_t > >::const_iterator i =
                _observations.begin();
            QList< QPair< double, time_t > >::const_iterator iend =
                _observations.end();

            for (; i != iend; ++i)
            {
                QList< QPair< time_t, QColor > >::iterator j = color;
                QList< QPair< time_t, QColor > >::iterator jend =
                    _divisions.end();
                QList< QPair< time_t, QColor > >::iterator newColor = color;

                for (; j != jend; ++j)
                {
                    if (i->second >= j->first)
                    {
                        newColor = j;
                    }
                }

                if (newColor != color)
                {
                    if (!path.isEmpty())
                    {
                        painter.setRenderHint(QPainter::Antialiasing, true);
                        painter.setPen(QPen(color->second,
                                            2,
                                            Qt::SolidLine,
                                            Qt::RoundCap,
                                            Qt::RoundJoin));
                        painter.drawPath(path);
                        QPainterPath newPath;
                        newPath.moveTo(path.currentPosition());
                        path = newPath;
                    }

                    color = newColor;
                }

                double height = (i->first - min) * skip;

                if (first)
                {
                    y -= height;
                    first = false;
                    path.moveTo(bl.x() + int(x), bl.y() + int(y));
                }
                else
                {
                    x += width;
                    y = -_bottomPadding - height;

                    path.lineTo(bl.x() + int(x), bl.y() + int(y));
                }
            }
        }
    }

    if (!path.isEmpty())
    {
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.setPen(
            QPen(color->second, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
        painter.drawPath(path);
    }

    return QIcon(pixmap);
}
Ejemplo n.º 12
0
//=============================================================================
void sstQt01TestPaintWidgetCls::paintEvent(QPaintEvent * /* event */)
{
    static const QPoint points[4] = {
        QPoint(10, 80),
        QPoint(20, 10),
        QPoint(80, 30),
        QPoint(90, 70)
    };

    QRect rect(10, 20, 80, 60);

    QPainterPath path;
    path.moveTo(20, 80);
    path.lineTo(20, 30);
    path.cubicTo(80, 0, 50, 50, 80, 80);

    int startAngle = 20 * 16;
    int arcLength = 120 * 16;

    QPainter painter(this);
    painter.setPen(pen);
    painter.setBrush(brush);
    if (antialiased)
        painter.setRenderHint(QPainter::Antialiasing, true);

    for (int x = 0; x < width(); x += 100) {
        for (int y = 0; y < height(); y += 100) {
            painter.save();
            painter.translate(x, y);
            if (transformed) {
                painter.translate(50, 50);
                painter.rotate(60.0);
                painter.scale(0.6, 0.9);
                painter.translate(-50, -50);
            }

            switch (shape) {
            case Line:
                painter.drawLine(rect.bottomLeft(), rect.topRight());
                break;
            case Points:
                painter.drawPoints(points, 4);
                break;
            case Polyline:
                painter.drawPolyline(points, 4);
                break;
            case Polygon:
                painter.drawPolygon(points, 4);
                break;
            case Rect:
                painter.drawRect(rect);
                break;
            case RoundedRect:
                painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
                break;
            case Ellipse:
                painter.drawEllipse(rect);
                break;
            case Arc:
                painter.drawArc(rect, startAngle, arcLength);
                break;
            case Chord:
                painter.drawChord(rect, startAngle, arcLength);
                break;
            case Pie:
                painter.drawPie(rect, startAngle, arcLength);
                break;
            case Path:
                painter.drawPath(path);
                break;
            case Text:
                painter.drawText(rect,
                                 Qt::AlignCenter,
                                 tr("Qt by\nThe Qt Company"));
                break;
            case Pixmap:
                painter.drawPixmap(10, 10, pixmap);
            }
            painter.restore();
        }
    }

    painter.setRenderHint(QPainter::Antialiasing, false);
    painter.setPen(palette().dark().color());
    painter.setBrush(Qt::NoBrush);
    painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
}
Ejemplo n.º 13
0
//! [0]
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
                         QGraphicsItem *parent, QGraphicsScene *scene)
    : QGraphicsPolygonItem(parent, scene)
{
    myDiagramType = diagramType;
    myContextMenu = contextMenu;
    myGText = new QGraphicsSimpleTextItem(this,scene);

    QPainterPath path;
    switch (myDiagramType) {
    case StartEnd:
        path.moveTo(200, 50);
        path.arcTo(150, 0, 50, 50, 0, 90);
        path.arcTo(50, 0, 50, 50, 90, 90);
        path.arcTo(50, 50, 50, 50, 180, 90);
        path.arcTo(150, 50, 50, 50, 270, 90);
        path.lineTo(200, 25);
        myPolygon = path.toFillPolygon();
        myText = "StartEnd";
        break;
    case Conditional:
        myPolygon << QPointF(-50, 0) << QPointF(0, 50)
                  << QPointF(50, 0) << QPointF(0, -50)
                  << QPointF(-50, 0);
        myText = "Conditional";
        break;
    case Step:
        myPolygon << QPointF(-50, -50) << QPointF(50, -50)
                  << QPointF(50, 50) << QPointF(-50, 50)
                  << QPointF(-50, -50);
        myText = "Step";
        break;
    case Compo:
        myPolygon << QPointF(-50, 0) << QPointF(0, 50)
                  << QPointF(50, 0) << QPointF(0, -50)
                  << QPointF(-50, 0);
        myText = /*"Composition " + */QString::fromUtf8("  \u2229");
        myGText->setScale(3);
        break;
    case Union:
        myPolygon << QPointF(-50, 0) << QPointF(0, 50)
                  << QPointF(50, 0) << QPointF(0, -50)
                  << QPointF(-50, 0);
        myText = /*"Union " +*/QString::fromUtf8("  \u222A");
        myGText->setScale(3);
        break;
    case Constraint:
        myPolygon << QPointF(-50, -50) << QPointF(50, -50)
                  << QPointF(50, 50) << QPointF(-50, 50)
                  << QPointF(-50, -50);
        myText = "Constraint";
        break;
    case Io:
        myPolygon << QPointF(-60, -40) << QPointF(-35, 40)
                  << QPointF(60, 40) << QPointF(35, -40)
                  << QPointF(-60, -40);
        myText = "Input/Output";
        break;
    default:
        myPolygon << QPointF(-60, -40) << QPointF(-35, 40)
                  << QPointF(60, 40) << QPointF(35, -40)
                  << QPointF(-60, -40);
        myText = "Default";
        break;
    }
    setPolygon(myPolygon);
    setFlag(QGraphicsItem::ItemIsMovable, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

    myGText->setText(myText);

    myGText->setPos(this->boundingRect().topLeft());

    ub = 0;
    lb = 0;
}
Ejemplo n.º 14
0
void ProcessorGraphicsItem::paint(QPainter* p, const QStyleOptionGraphicsItem* options,
                                  QWidget* widget) {
    IVW_UNUSED_PARAM(options);
    IVW_UNUSED_PARAM(widget);
    p->save();
    p->setPen(Qt::NoPen);
    p->setRenderHint(QPainter::Antialiasing, true);
    QColor topColor(140, 140, 140);
    QColor middleColor(59, 61, 61);
    QColor bottomColor(40, 40, 40);
    // paint processor
    QLinearGradient grad(rect().topLeft(), rect().bottomLeft());

    if (isSelected()) {
        grad.setColorAt(0.0f, topColor);
        grad.setColorAt(0.2f, middleColor);
        grad.setColorAt(0.5f, Qt::darkRed);
        grad.setColorAt(1.0f, bottomColor);
    } else {
        grad.setColorAt(0.0f, topColor);
        grad.setColorAt(0.2f, middleColor);
        grad.setColorAt(1.0f, bottomColor);
    }

    QRectF bRect = rect();
    QPainterPath roundRectPath = makeRoundedBox(rect(), roundedCorners);

    p->setBrush(grad);
    p->drawPath(roundRectPath);
    QLinearGradient highlightGrad(rect().topLeft(), rect().bottomLeft());

    if (isSelected()) {
        highlightGrad.setColorAt(0.0f, bottomColor);
        highlightGrad.setColorAt(0.1f, bottomColor);
        highlightGrad.setColorAt(0.5f, Qt::darkRed);
        highlightGrad.setColorAt(1.0f, bottomColor);
    } else {
        highlightGrad.setColorAt(0.0f, bottomColor);
        highlightGrad.setColorAt(1.0f, bottomColor);
    }

    QPainterPath highlightPath;
    float highlightLength = bRect.width() / 8.0;
    highlightPath.moveTo(bRect.left(), bRect.top() + roundedCorners);
    highlightPath.lineTo(bRect.left(), bRect.bottom() - roundedCorners);
    highlightPath.arcTo(bRect.left(), bRect.bottom() - (2 * roundedCorners), (2 * roundedCorners),
                        (2 * roundedCorners), 180.0, 90.0);
    highlightPath.lineTo(bRect.left() + (bRect.width() / 2.0) + highlightLength, bRect.bottom());
    highlightPath.lineTo(bRect.left() + (bRect.width() / 2.0) - highlightLength, bRect.top());
    highlightPath.lineTo(bRect.left() + roundedCorners, bRect.top());
    highlightPath.arcTo(bRect.left(), bRect.top(), (2 * roundedCorners), (2 * roundedCorners), 90.0,
                        90.0);

    p->setBrush(highlightGrad);
    p->drawPath(highlightPath);
    p->setPen(QPen(QColor(164, 164, 164), 1.0));
    p->setBrush(Qt::NoBrush);
    p->drawPath(roundRectPath);

    p->restore();
}
void EventsSceneArrowTmpItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    
    QRectF rect = boundingRect();
    
    //painter->fillRect(rect, QColor(255, 0, 0, 30));
    
    painter->setRenderHint(QPainter::Antialiasing);
    int penWidth = 2;
    QColor color = Qt::black;
    
    switch(mState)
    {
        case eNormal:
            color = Qt::black;
            break;
        case eAllowed:
            color = QColor(77, 180, 62);
            break;
        case eForbidden:
            color = Qt::red;
            break;
        default:
            break;
    }
    painter->setPen(QPen(color, penWidth, Qt::DashLine));
    painter->drawLine(mXFrom, mYFrom, mXTo, mYTo);
    
    // arrows
    
    float angle_rad = atanf(rect.width() / rect.height());
    float angle_deg = angle_rad * 180. / M_PI;
    
    QPainterPath path;
    int arrow_w = 10;
    int arrow_l = 15;
    path.moveTo(-arrow_w/2, arrow_l/2);
    path.lineTo(arrow_w/2, arrow_l/2);
    path.lineTo(0, -arrow_l/2);
    path.closeSubpath();
    
    float posX = rect.width()/2;
    float posY = rect.height()/2;
    
    if(mXFrom < mXTo && mYFrom > mYTo)
    {
        painter->save();
        painter->translate(rect.x() + posX, rect.y() + posY);
        painter->rotate(angle_deg);
        painter->fillPath(path, color);
        painter->restore();
    }
    else if(mXFrom < mXTo && mYFrom < mYTo)
    {
        painter->save();
        painter->translate(rect.x() + posX, rect.y() + posY);
        painter->rotate(180 - angle_deg);
        painter->fillPath(path, color);
        painter->restore();
    }
    else if(mXFrom > mXTo && mYFrom < mYTo)
    {
        painter->save();
        painter->translate(rect.x() + posX, rect.y() + posY);
        painter->rotate(180 + angle_deg);
        painter->fillPath(path, color);
        painter->restore();
    }
    else if(mXFrom > mXTo && mYFrom > mYTo)
    {
        painter->save();
        painter->translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2);
        painter->rotate(-angle_deg);
        painter->fillPath(path, color);
        painter->restore();
    }
    
    // Message
    
    switch(mState)
    {
        case eAllowed:
        case eForbidden:
        {
            float w = 40;
            float h = 40;
            QRectF r(rect.x() + (rect.width() - w)/2, rect.y() + (rect.height() - h)/2, w, h);
            painter->setBrush(Qt::white);
            painter->drawEllipse(r);
            
            if(mState == eAllowed)
            {
                painter->drawText(r, Qt::AlignCenter, "OK");
            }
            else
            {
                painter->setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap));
                painter->drawLine(r.x() + r.width()/4, r.y() + r.height()/4, r.x() + 3*r.width()/4, r.y() + 3*r.height()/4);
                painter->drawLine(r.x() + r.width()/4, r.y() + 3*r.height()/4, r.x() + 3*r.width()/4, r.y() + r.height()/4);
            }
        }
        default:
            break;
    }
}
void OpenInfraPlatform::UserInterface::VerticalAlignmentScene::v_drawDiagram(QPainterPath& diagPainter, QPainterPath& diagDashedPainter)
{		
	QString text;
	
	// 
	if(displayPoints_)
	{
		for(int i=0; i<arcPoints.size(); i++)
		{
			buw::vector2d start, end;
			int ai = std::get<0>(arcPoints[i]);
			start = std::get<1>(arcPoints[i]);
			end = std::get<2>(arcPoints[i]);

			text = "AA" + QString::number(ai+1);;
			auto startLabel = addText(text, diagramFont);
			startLabel->setPos(start.x() * scalingX, start.y() * scalingY - 25);
			startLabel->setDefaultTextColor(Qt::lightGray);

			diagDashedPainter.moveTo(start.x() * scalingX, start.y() * scalingY);
			diagDashedPainter.lineTo(start.x() * scalingX, bounds[3] * scalingY + 5);

			text = "AE" + QString::number(ai+1);
			auto endLabel = addText(text, diagramFont);
			endLabel->setPos(end.x() * scalingX, end.y() * scalingY - 25);
			endLabel->setDefaultTextColor(Qt::lightGray);

			diagDashedPainter.moveTo(end.x() * scalingX, end.y() * scalingY);
			diagDashedPainter.lineTo(end.x() * scalingX, bounds[3] * scalingY + 5);
		}
		for (int i = 0; i<parabolaPoints.size(); i++)
		{
			buw::vector2d start, end, pvi;
			int ai = std::get<0>(parabolaPoints[i]);
			start = std::get<1>(parabolaPoints[i]);
			end = std::get<2>(parabolaPoints[i]);
			pvi = std::get<3>(parabolaPoints[i]);

			text = "AA" + QString::number(ai + 1);;
			auto startLabel = addText(text, diagramFont);
			startLabel->setPos(start.x() * scalingX, start.y() * scalingY - 25);
			startLabel->setDefaultTextColor(Qt::lightGray);

			diagDashedPainter.moveTo(start.x() * scalingX, start.y() * scalingY);
			diagDashedPainter.lineTo(start.x() * scalingX, bounds[3] * scalingY + 5);

			text = "AE" + QString::number(ai + 1);
			auto endLabel = addText(text, diagramFont);
			endLabel->setPos(end.x() * scalingX, end.y() * scalingY - 25);
			endLabel->setDefaultTextColor(Qt::lightGray);

			diagDashedPainter.moveTo(end.x() * scalingX, end.y() * scalingY);
			diagDashedPainter.lineTo(end.x() * scalingX, bounds[3] * scalingY + 5);

			text = "VB" + QString::number(ai + 1);;
			auto pviLabel = addText(text, diagramFont);
			pviLabel->setPos(pvi.x() * scalingX, pvi.y() * scalingY - 25);
			pviLabel->setDefaultTextColor(Qt::lightGray);

			diagDashedPainter.moveTo(pvi.x() * scalingX, pvi.y() * scalingY);
			diagDashedPainter.lineTo(pvi.x() * scalingX, bounds[3] * scalingY + 5);
		}
	}

}
Ejemplo n.º 17
0
void ChordLine::editDrag(const EditData& ed)
      {
      int n = path.elementCount();
      QPainterPath p;
      qreal sp = spatium();
      _lengthX += ed.delta.x();
      _lengthY += ed.delta.y();

      // used to limit how grips can affect the slide, stops the user from being able to turn one kind of slide into another
      int slideBoundary = 5;
      if ((_chordLineType == ChordLineType::PLOP || _chordLineType == ChordLineType::FALL) && _lengthY < -slideBoundary)
            _lengthY = -slideBoundary;
      else if ((_chordLineType == ChordLineType::FALL || _chordLineType == ChordLineType::DOIT) && _lengthX < -slideBoundary)
            _lengthX = -slideBoundary;
      else if ((_chordLineType == ChordLineType::DOIT || _chordLineType == ChordLineType::SCOOP) && _lengthY > slideBoundary)
            _lengthY = slideBoundary;
      else if ((_chordLineType == ChordLineType::SCOOP || _chordLineType == ChordLineType::PLOP)  && _lengthX > slideBoundary)
            _lengthX = slideBoundary;

      qreal dx = ed.delta.x() / sp;
      qreal dy = ed.delta.y() / sp;
      for (int i = 0; i < n; ++i) {
            const QPainterPath::Element& e = (_straight ? path.elementAt(1) : path.elementAt(i));
            if (_straight) {
                  if (i > 0)
                        break;
                  // check the gradient of the line
                  const QPainterPath::Element& startPoint = path.elementAt(0);
                  if ( (_chordLineType == ChordLineType::FALL && (e.x + dx < startPoint.x || e.y + dy < startPoint.y))  ||
                       (_chordLineType == ChordLineType::DOIT && (e.x + dx < startPoint.x || e.y + dy > startPoint.y))  ||
                       (_chordLineType == ChordLineType::SCOOP && (e.x + dx > startPoint.x || e.y + dy < startPoint.y)) ||
                       (_chordLineType == ChordLineType::PLOP && (e.x + dx > startPoint.x || e.y + dy > startPoint.y)) )
                              return;
                  }

            qreal x = e.x;
            qreal y = e.y;
            if (ed.curGrip == Grip(i)) {
                  x += dx;
                  y += dy;
                  }
            switch(e.type) {
                  case QPainterPath::CurveToDataElement:
                        break;
                  case QPainterPath::MoveToElement:
                        p.moveTo(x, y);
                        break;
                  case QPainterPath::LineToElement:
                        p.lineTo(x, y);
                        break;
                  case QPainterPath::CurveToElement:
                        {
                        qreal x2 = path.elementAt(i+1).x;
                        qreal y2 = path.elementAt(i+1).y;
                        qreal x3 = path.elementAt(i+2).x;
                        qreal y3 = path.elementAt(i+2).y;
                        if (Grip(i + 1) == ed.curGrip) {
                              x2 += dx;
                              y2 += dy;
                              }
                        else if (Grip(i + 2) == ed.curGrip) {
                              x3 += dx;
                              y3 += dy;
                              }
                        p.cubicTo(x, y, x2, y2, x3, y3);
                        i += 2;
                        }
                        break;
                  }
            }
      path = p;
      modified = true;
      }
Ejemplo n.º 18
0
void PianoKeyItem::setType(int val)
      {
      type = val;
      QPainterPath path;

      switch(type) {
            case 0:
                  path.moveTo(0,0);
                  path.lineTo(0,   KEY_HEIGHT-2);
                  path.lineTo(2.0, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH-2, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH, KEY_HEIGHT-2);
                  path.lineTo(KEY_WIDTH, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, 0);
                  break;
            case 1:
                  path.moveTo(BKEY_WIDTH * 4/9, 0);
                  path.lineTo(BKEY_WIDTH * 4/9, BKEY_HEIGHT);
                  path.lineTo(0, BKEY_HEIGHT);
                  path.lineTo(0,   KEY_HEIGHT-2);
                  path.lineTo(2.0, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH-2, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH, KEY_HEIGHT-2);
                  path.lineTo(KEY_WIDTH, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, 0);
                  break;
            case 2:
                  path.moveTo(BKEY_WIDTH * 5/9, 0);
                  path.lineTo(BKEY_WIDTH * 5/9, BKEY_HEIGHT);
                  path.lineTo(0,   BKEY_HEIGHT);
                  path.lineTo(0,   KEY_HEIGHT-2);
                  path.lineTo(2.0, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH-2, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH,  KEY_HEIGHT-2);
                  path.lineTo(KEY_WIDTH,  BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH, 0);
                  break;
            case 3:
                  path.moveTo(BKEY_WIDTH * 4/9, 0);
                  path.lineTo(BKEY_WIDTH * 4/9, BKEY_HEIGHT);
                  path.lineTo(0, BKEY_HEIGHT);
                  path.lineTo(0,   KEY_HEIGHT-2);
                  path.lineTo(2.0, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH-2, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH, KEY_HEIGHT-2);
                  path.lineTo(KEY_WIDTH, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, 0);
                  break;
            case 4:
                  path.moveTo(BKEY_WIDTH * 5/9, 0);
                  path.lineTo(BKEY_WIDTH * 5/9, BKEY_HEIGHT);
                  path.lineTo(0, BKEY_HEIGHT);
                  path.lineTo(0,   KEY_HEIGHT-2);
                  path.lineTo(2.0, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH-2, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH, KEY_HEIGHT-2);
                  path.lineTo(KEY_WIDTH, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, 0);
                  break;
            case 5:
                  path.moveTo(0,0);
                  path.lineTo(0,   KEY_HEIGHT-2);
                  path.lineTo(2.0, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH-2, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH, KEY_HEIGHT-2);
                  path.lineTo(KEY_WIDTH, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, BKEY_HEIGHT);
                  path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, 0);
                  break;
            case 6:
                  path.moveTo(0,0);
                  path.lineTo(0,   KEY_HEIGHT-2);
                  path.lineTo(2.0, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH-2, KEY_HEIGHT);
                  path.lineTo(KEY_WIDTH, KEY_HEIGHT-2);
                  path.lineTo(KEY_WIDTH, 0);
                  break;
            case 7:
                  path.moveTo(0,0);
                  path.lineTo(0,            BKEY_HEIGHT-1);
                  path.lineTo(1.0,          BKEY_HEIGHT);
                  path.lineTo(BKEY_WIDTH-1, BKEY_HEIGHT);
                  path.lineTo(BKEY_WIDTH,   BKEY_HEIGHT-1);
                  path.lineTo(BKEY_WIDTH, 0);
                  break;
            default:
                  break;
            }
      path.closeSubpath();
      setPath(path);
      }
Ejemplo n.º 19
0
void ConnectorGraphics::updatePosition()
{
  QPainterPath Path;

  QPointF FromPos;
  QPointF ToPos;

  if (m_FromOutNode == NODE_PROD)
    FromPos = mp_FromItem->getProducedIOPosition();
  else
    FromPos = mp_FromItem->getUpOutIOPosition();

  if (m_ToInNode == NODE_REQ)
    ToPos = mp_ToItem->getRequiredIOPosition();
  else if (m_ToInNode == NODE_US)
    ToPos = mp_ToItem->getUsedIOPosition();
  else
    ToPos = mp_ToItem->getUpInIOPosition();


  Path.moveTo(FromPos);

  // intermediate position helps for correct bezier curve shape
  // and for positionning of variable names as curve label
  QPointF InterPos;


  if (FromPos.y() < ToPos.y()) // "From" slot (source) is upper than "To" slot (destination)
  {

    InterPos = QPointF(FromPos.x()+((ToPos.x()-FromPos.x())/2.0),
                        FromPos.y()+((ToPos.y()-FromPos.y())/2.0));

    Path.quadTo(QPointF(FromPos.x(),InterPos.y()),InterPos);
    Path.quadTo(QPointF(ToPos.x(),InterPos.y()),ToPos);
  }
  else // "From" slot (source) is lower than "To" slot (destination)
  {
    InterPos = QPointF(FromPos.x()+((ToPos.x()-FromPos.x())/2.0)-200,
                       FromPos.y()+((ToPos.y()-FromPos.y())/2.0));

    Path.quadTo(QPointF(FromPos.x()-200,FromPos.y()+200),
                InterPos);
    Path.quadTo(QPointF(ToPos.x()-200,ToPos.y()-200),
                ToPos);
  }

  setPath(Path);



  // variables names
  mp_VarsText->setText(m_Variables.join("\n"));

  QPointF TextPos(InterPos.x()-mp_VarsText->boundingRect().width()/2,
                  InterPos.y()-mp_VarsText->boundingRect().height()/2);

  mp_VarsText->setPos(TextPos);



  // variables names background box
  mp_VarsTextBox->setRect(TextPos.x()-2,TextPos.y()-2,
                          mp_VarsText->boundingRect().width()+4, mp_VarsText->boundingRect().height()+4);
}
void createPaths(const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath &path, QPainterPath &lastPath, QPointF &ellipsePos, QPointF &markerPosition, QString &amplitude, const QVector<float> &data, const QVector<float> &lastData)
{
    const RealTimeMultiSampleArrayModel* t_pModel = static_cast<const RealTimeMultiSampleArrayModel*>(index.model());

    //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
    qint32 kind = t_pModel->getKind(index.row());
    float fMaxValue = 1e-9f;

    switch(kind) {
        case FIFFV_MEG_CH: {
            qint32 unit =t_pModel->getUnit(index.row());
            if(unit == FIFF_UNIT_T_M) { //gradiometers
                fMaxValue = 1e-10f;
                if(t_pModel->getScaling().contains(FIFF_UNIT_T_M))
                    fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T_M];
            }
            else if(unit == FIFF_UNIT_T) //magnitometers
            {
//                if(t_pModel->getCoil(index.row()) == FIFFV_COIL_BABY_MAG)
//                    fMaxValue = 1e-11f;
//                else
                fMaxValue = 1e-11f;

                if(t_pModel->getScaling().contains(FIFF_UNIT_T))
                    fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T];
            }
            break;
        }

        case FIFFV_REF_MEG_CH: {  /*11/04/14 Added by Limin: MEG reference channel */
            fMaxValue = 1e-11f;
            if(t_pModel->getScaling().contains(FIFF_UNIT_T))
                fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T];
            break;
        }
        case FIFFV_EEG_CH: {
            fMaxValue = 1e-4f;
            if(t_pModel->getScaling().contains(FIFFV_EEG_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_EEG_CH];
            break;
        }
        case FIFFV_EOG_CH: {
            fMaxValue = 1e-3f;
            if(t_pModel->getScaling().contains(FIFFV_EOG_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_EOG_CH];
            break;
        }
        case FIFFV_STIM_CH: {
            fMaxValue = 5;
            if(t_pModel->getScaling().contains(FIFFV_STIM_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_STIM_CH];
            break;
        }
        case FIFFV_MISC_CH: {
            fMaxValue = 1e-3f;
            if(t_pModel->getScaling().contains(FIFFV_MISC_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_MISC_CH];
            break;
        }
    }

    float fValue;
    float fScaleY = option.rect.height()/(2*fMaxValue);

    float y_base = path.currentPosition().y();
    QPointF qSamplePosition;

    float fDx = ((float)option.rect.width()) / t_pModel->getMaxSamples();

    //Move to initial starting point
    if(data.size() > 0)
    {
//        float val = data[0];
        fValue = 0;//(val-data[0])*fScaleY;

        float newY = y_base-fValue;//Reverse direction -> plot the right way

        qSamplePosition.setY(newY);
        qSamplePosition.setX(path.currentPosition().x());

        path.moveTo(qSamplePosition);
    }

    //create lines from one to the next sample
    qint32 i;
    for(i = 1; i < data.size(); ++i) {
        float val = data[i] - data[0]; //remove first sample data[0] as offset
        fValue = val*fScaleY;
        //qDebug()<<"val"<<val<<"fScaleY"<<fScaleY<<"fValue"<<fValue;

        float newY = y_base-fValue;//Reverse direction -> plot the right way

        qSamplePosition.setY(newY);
        qSamplePosition.setX(path.currentPosition().x()+fDx);

        path.lineTo(qSamplePosition);

        //Create ellipse position
        if(i == (qint32)(markerPosition.x()/fDx)) {
            ellipsePos.setX(path.currentPosition().x()+fDx);
            ellipsePos.setY(newY+(option.rect.height()/2));

            amplitude = QString::number(data[i]);
        }
    }

    //create lines from one to the next sample for last path
    qint32 sample_offset = t_pModel->numVLines() + 1;
    qSamplePosition.setX(qSamplePosition.x() + fDx*sample_offset);

    //start painting from first sample value
    float val = lastData[i] - lastData[0]; //remove first sample lastData[0] as offset
    fValue = val*fScaleY;
    float newY = y_base-fValue;
    qSamplePosition.setY(newY);

    lastPath.moveTo(qSamplePosition);

    for(i += sample_offset; i < lastData.size(); ++i) {
        val = lastData[i] - lastData[0]; //remove first sample lastData[0] as offset
        fValue = val*fScaleY;

        newY = y_base-fValue;

        qSamplePosition.setY(newY);
        qSamplePosition.setX(lastPath.currentPosition().x()+fDx);

        lastPath.lineTo(qSamplePosition);

        //Create ellipse position
        if(i == (qint32)(markerPosition.x()/fDx)) {
            ellipsePos.setX(lastPath.currentPosition().x()+fDx);
            ellipsePos.setY(newY+(option.rect.height()/2));

            amplitude = QString::number(lastData[i]);
        }
    }
}
Ejemplo n.º 21
0
void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow)
{
    QRect scr = QApplication::desktop()->screenGeometry(pos);
    QSize sh = sizeHint();
    const int border = 1;
    const int ah = 18, ao = 18, aw = 18, rc = 7;
    bool arrowAtTop = (pos.y() + sh.height() + ah < scr.height());
    bool arrowAtLeft = (pos.x() + sh.width() - ao < scr.width());
    setContentsMargins(border + 3,  border + (arrowAtTop ? ah : 0) + 2, border + 3, border + (arrowAtTop ? 0 : ah) + 2);
    updateGeometry();
    sh  = sizeHint();

    int ml, mr, mt, mb;
    QSize sz = sizeHint();
    if (!arrowAtTop) {
        ml = mt = 0;
        mr = sz.width() - 1;
        mb = sz.height() - ah - 1;
    } else {
        ml = 0;
        mt = ah;
        mr = sz.width() - 1;
        mb = sz.height() - 1;
    }

    QPainterPath path;
#if defined(QT_NO_XSHAPE) && defined(Q_WS_X11)
    // XShape is required for setting the mask, so we just
    // draw an ugly square when its not available
    path.moveTo(0, 0);
    path.lineTo(sz.width() - 1, 0);
    path.lineTo(sz.width() - 1, sz.height() - 1);
    path.lineTo(0, sz.height() - 1);
    path.lineTo(0, 0);
    move(qMax(pos.x() - sz.width(), scr.left()), pos.y());
#else
    path.moveTo(ml + rc, mt);
    if (arrowAtTop && arrowAtLeft) {
        if (showArrow) {
            path.lineTo(ml + ao, mt);
            path.lineTo(ml + ao, mt - ah);
            path.lineTo(ml + ao + aw, mt);
        }
        move(qMax(pos.x() - ao, scr.left() + 2), pos.y());
    } else if (arrowAtTop && !arrowAtLeft) {
        if (showArrow) {
            path.lineTo(mr - ao - aw, mt);
            path.lineTo(mr - ao, mt - ah);
            path.lineTo(mr - ao, mt);
        }
        move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), pos.y());
    }
    path.lineTo(mr - rc, mt);
    path.arcTo(QRect(mr - rc*2, mt, rc*2, rc*2), 90, -90);
    path.lineTo(mr, mb - rc);
    path.arcTo(QRect(mr - rc*2, mb - rc*2, rc*2, rc*2), 0, -90);
    if (!arrowAtTop && !arrowAtLeft) {
        if (showArrow) {
            path.lineTo(mr - ao, mb);
            path.lineTo(mr - ao, mb + ah);
            path.lineTo(mr - ao - aw, mb);
        }
        move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2),
             pos.y() - sh.height());
    } else if (!arrowAtTop && arrowAtLeft) {
        if (showArrow) {
            path.lineTo(ao + aw, mb);
            path.lineTo(ao, mb + ah);
            path.lineTo(ao, mb);
        }
        move(qMax(pos.x() - ao, scr.x() + 2), pos.y() - sh.height());
    }
    path.lineTo(ml + rc, mb);
    path.arcTo(QRect(ml, mb - rc*2, rc*2, rc*2), -90, -90);
    path.lineTo(ml, mt + rc);
    path.arcTo(QRect(ml, mt, rc*2, rc*2), 180, -90);

    // Set the mask
    QBitmap bitmap = QBitmap(sizeHint());
    bitmap.fill(Qt::color0);
    QPainter painter1(&bitmap);
    painter1.setPen(QPen(Qt::color1, border));
    painter1.setBrush(QBrush(Qt::color1));
    painter1.drawPath(path);
    setMask(bitmap);
#endif

    // Draw the border
    pixmap = QPixmap(sz);
    QPainter painter2(&pixmap);
    painter2.setPen(QPen(palette().color(QPalette::Window).darker(160), border));
    painter2.setBrush(palette().color(QPalette::Window));
    painter2.drawPath(path);

    if (msecs > 0)
        timerId = startTimer(msecs);
    show();
}
void RealTimeMultiSampleArrayDelegate::createPlotPath(const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath& path, QPointF &ellipsePos, QString &amplitude, RowVectorPair &data) const
{
    const RealTimeMultiSampleArrayModel* t_pModel = static_cast<const RealTimeMultiSampleArrayModel*>(index.model());

    //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
    qint32 kind = t_pModel->getKind(index.row());
    float fMaxValue = 1e-9f;

    switch(kind) {
        case FIFFV_MEG_CH: {
            qint32 unit =t_pModel->getUnit(index.row());
            if(unit == FIFF_UNIT_T_M) { //gradiometers
                fMaxValue = 1e-10f;
                if(t_pModel->getScaling().contains(FIFF_UNIT_T_M))
                    fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T_M];
            }
            else if(unit == FIFF_UNIT_T) //magnetometers
            {
                fMaxValue = 1e-11f;

                //TODO: Debug this
//                if(t_pModel->getCoil(index.row()) == FIFFV_COIL_BABY_MAG)
//                    fMaxValue = 1e-11f;
//                else
//                    fMaxValue = 1e-11f;

                if(t_pModel->getScaling().contains(FIFF_UNIT_T))
                    fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T];
            }
            break;
        }

        case FIFFV_REF_MEG_CH: {  /*11/04/14 Added by Limin: MEG reference channel */
            fMaxValue = 1e-11f;
            if(t_pModel->getScaling().contains(FIFF_UNIT_T))
                fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T];
            break;
        }
        case FIFFV_EEG_CH: {
            fMaxValue = 1e-4f;
            if(t_pModel->getScaling().contains(FIFFV_EEG_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_EEG_CH];
            break;
        }
        case FIFFV_EOG_CH: {
            fMaxValue = 1e-3f;
            if(t_pModel->getScaling().contains(FIFFV_EOG_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_EOG_CH];
            break;
        }
        case FIFFV_STIM_CH: {
            fMaxValue = 5;
            if(t_pModel->getScaling().contains(FIFFV_STIM_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_STIM_CH];
            break;
        }
        case FIFFV_MISC_CH: {
            fMaxValue = 1e-3f;
            if(t_pModel->getScaling().contains(FIFFV_MISC_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_MISC_CH];
            break;
        }
    }

    float fValue;
    float fScaleY = option.rect.height()/(2*fMaxValue);

    float y_base = path.currentPosition().y();
    QPointF qSamplePosition;

    float fDx = ((float)option.rect.width()) / t_pModel->getMaxSamples();

    int currentSampleIndex = t_pModel->getCurrentSampleIndex();
    float lastFirstValue = t_pModel->getLastBlockFirstValue(index.row());

    //Move to initial starting point
    if(data.second > 0)
    {
//        float val = data[0];
        fValue = 0;//(val-data[0])*fScaleY;

        float newY = y_base-fValue;//Reverse direction -> plot the right way

        qSamplePosition.setY(newY);
        qSamplePosition.setX(path.currentPosition().x());

        path.moveTo(qSamplePosition);
    }

    float val;

    for(qint32 j=0; j < data.second; ++j)
    {
        if(j<currentSampleIndex)
            val = *(data.first+j) - *(data.first); //remove first sample data[0] as offset
        else
            val = *(data.first+j) - lastFirstValue; //do not remove first sample data[0] as offset because this is the last data part

        fValue = val*fScaleY;
        //qDebug()<<"val"<<val<<"fScaleY"<<fScaleY<<"fValue"<<fValue;

        float newY = y_base-fValue;//Reverse direction -> plot the right way

        qSamplePosition.setY(newY);
        qSamplePosition.setX(path.currentPosition().x()+fDx);
        path.lineTo(qSamplePosition);

        //Create ellipse position
        if(j == (qint32)(m_markerPosition.x()/fDx)) {
            ellipsePos.setX(path.currentPosition().x()+fDx);
            ellipsePos.setY(newY/*+(option.rect.height()/2)*/);

            amplitude = QString::number(*(data.first+j));
        }
    }
}
Ejemplo n.º 23
0
/*! Paints the gantt item \a idx using \a painter and \a opt
 */
void ItemDelegate::paintGanttItem( QPainter* painter,
                                   const StyleOptionGanttItem& opt,
                                   const QModelIndex& idx )
{
    if ( !idx.isValid() ) return;
    const ItemType typ = static_cast<ItemType>( idx.model()->data( idx, ItemTypeRole ).toInt() );
    const QString& txt = opt.text;
    QRectF itemRect = opt.itemRect;
    QRectF boundingRect = opt.boundingRect;
    boundingRect.setY( itemRect.y() );
    boundingRect.setHeight( itemRect.height() );
    //qDebug() << "itemRect="<<itemRect<<", boundingRect="<<boundingRect;

    painter->save();

    QPen pen = defaultPen( typ );
    if ( opt.state & QStyle::State_Selected ) pen.setWidth( 2*pen.width() );
    painter->setPen( pen );
    painter->setBrush( defaultBrush( typ ) );

    qreal pw = painter->pen().width()/2.;
    switch( typ ) {
    case TypeTask:
        if ( itemRect.isValid() ) {
            // TODO
            qreal pw = painter->pen().width()/2.;
            pw-=1;
            QRectF r = itemRect;
            r.translate( 0., r.height()/6. );
            r.setHeight( 2.*r.height()/3. );
            painter->setBrushOrigin( itemRect.topLeft() );
            painter->save();
            painter->translate( 0.5, 0.5 );
            painter->drawRect( r );
            bool ok;
            qreal completion = idx.model()->data( idx, KDGantt::TaskCompletionRole ).toDouble( &ok );
            if ( ok ) {
                qreal h = r.height();
                QRectF cr( r.x(), r.y()+h/4. + 1,
                           r.width()*completion/100., h/2. - 2 );
                painter->fillRect( cr, painter->pen().brush() );
            }
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta, txt );
        }
        break;
    case TypeSummary:
        if ( opt.itemRect.isValid() ) {
            // TODO
            pw-=1;
            const QRectF r = QRectF( opt.itemRect ).adjusted( -pw, -pw, pw, pw );
            QPainterPath path;
            const qreal deltaY = r.height()/2.;
            const qreal deltaX = qMin( r.width()/qreal(2), deltaY );
            path.moveTo( r.topLeft() );
            path.lineTo( r.topRight() );
            path.lineTo( QPointF( r.right(), r.top() + 2.*deltaY ) );
            //path.lineTo( QPointF( r.right()-3./2.*delta, r.top() + delta ) );
            path.quadTo( QPointF( r.right()-.5*deltaX, r.top() + deltaY ), QPointF( r.right()-2.*deltaX, r.top() + deltaY ) );
            //path.lineTo( QPointF( r.left()+3./2.*delta, r.top() + delta ) );
            path.lineTo( QPointF( r.left() + 2.*deltaX, r.top() + deltaY ) );
            path.quadTo( QPointF( r.left()+.5*deltaX, r.top() + deltaY ), QPointF( r.left(), r.top() + 2.*deltaY ) );
            path.closeSubpath();
            painter->setBrushOrigin( itemRect.topLeft() );
            painter->save();
            painter->translate( 0.5, 0.5 );
            painter->drawPath( path );
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
        }
        break;
    case TypeEvent: /* TODO */
        //qDebug() << opt.boundingRect << opt.itemRect;
        if ( opt.boundingRect.isValid() ) {
            const qreal pw = painter->pen().width() / 2. - 1;
            const QRectF r = QRectF( opt.rect ).adjusted( -pw, -pw, pw, pw );
            QPainterPath path;
            const qreal delta = static_cast< int >( r.height() / 2 );
            path.moveTo( delta, 0. );
            path.lineTo( 2.*delta, delta );
            path.lineTo( delta, 2.*delta );
            path.lineTo( 0., delta );
            path.closeSubpath();
            painter->save();
            painter->translate( r.topLeft() );
            painter->translate( 0.5, 0.5 );
            painter->drawPath( path );
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
        }
        break;
    default:
        break;
    }
    painter->restore();
}
Ejemplo n.º 24
0
void NMGChartSeries::paintArea(QPainter* painter,
                               const QStyleOptionGraphicsItem* option, 
                               QWidget* widget)
{
  int maxValuesInPartialPath = 1000;
  QColor hsv = baseColor.toHsv();
  hsv.setHsv(hsv.hue(), (int)(hsv.saturation()*0.25), hsv.value());

  if(isAveraged || isAccumulated)
  {
    painter->setBrush(hsv);
    paintLine(painter, option, widget); 
  }
  else
  { // not average nor accumulated
        
    /* NOTE A specific implementation is needed in this case because Graphics View doesn't
    * support correctly huge amount of points (X11 crashes). The design has been based in 
    * partial paths that are painted with brush (to paint the area), and later they are 
    * added to the complete path (to paint the boundary line).*/
    
    painter->setPen(Qt::NoPen);
    painter->setBrush(hsv);

    QPainterPath completedPath;
    double closingYpixel = ((minValues.y < 0.0 && 0.0 < maxValues.y) ? yWindowToViewport(0.0) :
                           ((minValues.y >= 0.0) ? yWindowToViewport(minValues.y) : 
                           yWindowToViewport(maxValues.y)));

    QList<Vertex>::const_iterator it = vertexList.constBegin();
    do
    {
      QPainterPath partialPath;
      QPainterPath partialPathModif;
      partialPath.moveTo(xWindowToViewport(it->x), -yWindowToViewport(it->y));
      
      for(int i = 1; i <= maxValuesInPartialPath && it != vertexList.constEnd(); i++, it++)
      {
        partialPath.lineTo(xWindowToViewport(it->x),-yWindowToViewport(it->y));
      }
      if(completedPath.isEmpty()) 
      {
        partialPathModif = partialPath;
        partialPathModif.lineTo(partialPathModif.currentPosition().rx(), -closingYpixel);
        partialPathModif.lineTo(xWindowToViewport(vertexList.first().x), -closingYpixel);
        
        completedPath = partialPath;
      }
      else
      {
        partialPathModif = partialPath;
        
        partialPathModif.lineTo(partialPath.currentPosition().rx(), -closingYpixel);
        partialPathModif.lineTo(completedPath.currentPosition().rx(), -closingYpixel);
        partialPathModif.lineTo(completedPath.currentPosition().rx(), 
                                completedPath.currentPosition().ry());
        
        completedPath.connectPath(partialPath);
      }
      partialPathModif.closeSubpath();
      painter->drawPath(partialPathModif);
    }
    while(it != vertexList.constEnd());
    
    painter->setPen(Qt::SolidLine);
    painter->setPen(baseColor);
    painter->setBrush(Qt::NoBrush);
    
    completedPath.lineTo(xWindowToViewport(vertexList.last().x), -closingYpixel);
    completedPath.lineTo(xWindowToViewport(vertexList.first().x), -closingYpixel);
    completedPath.closeSubpath();
    painter->drawPath(completedPath);
  }
}
Ejemplo n.º 25
0
void CreateMode::drawControls(QPainter* p)
{
    if (!inItemCreation) return;

    QPointF topLeft(createObjectPos.x(), createObjectPos.y());
    QPointF btRight(canvasCurrCoord.x(), canvasCurrCoord.y());
    QColor  drawColor = qApp->palette().color(QPalette::Active, QPalette::Highlight);

    if (createObjectMode != modeDrawLine)
    {
        QRectF bounds = QRectF(topLeft, btRight).normalized();
        //Lock Height to Width for Control Modifier for region drawing
        if (modifiers==Qt::ControlModifier)
        {
            bounds.setHeight(bounds.width());
            if (btRight.y()<topLeft.y())
                bounds.moveBottom(topLeft.y());
            if (btRight.x()<topLeft.x() && btRight.y()>topLeft.y())
                bounds.moveTop(topLeft.y());
        }
        QRect localRect = m_canvas->canvasToLocal(bounds);
        if (localRect.width() <= 0 || localRect.height() <= 0)
            return;
        p->setRenderHint(QPainter::Antialiasing);

        p->save();
        p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
        drawColor.setAlpha(64);
        p->setBrush(drawColor);
        p->drawRect(localRect);

        drawColor.setAlpha(255);
        p->setBrush(Qt::NoBrush);
        p->setPen(QPen(drawColor, 1, Qt::DashLine, Qt::FlatCap, Qt::MiterJoin));

        int frameType = 0, itemType = 0;
        getFrameItemTypes(itemType, frameType);
        if (frameType == PageItem::Ellipse)
        {
            p->drawEllipse(localRect);
        }
        else if (createObjectMode == modeDrawArc)
        {
            QPainterPath path;
            path.moveTo(localRect.width() / 2.0, localRect.height() / 2.0);
            path.arcTo(0.0, 0.0, localRect.width(), localRect.height(), m_doc->itemToolPrefs().arcStartAngle, m_doc->itemToolPrefs().arcSweepAngle);
            path.closeSubpath();
            p->translate(localRect.left(), localRect.top());
            p->drawPath(path);
        }
        else if (createObjectMode == modeDrawRegularPolygon)
        {
            QPainterPath path = RegularPolygonPath(localRect.width(), localRect.height(), m_doc->itemToolPrefs().polyCorners, m_doc->itemToolPrefs().polyUseFactor, m_doc->itemToolPrefs().polyFactor, m_doc->itemToolPrefs().polyRotation, m_doc->itemToolPrefs().polyCurvature, m_doc->itemToolPrefs().polyInnerRot, m_doc->itemToolPrefs().polyOuterCurvature);
            p->translate(localRect.left(), localRect.top());
            p->drawPath(path);
        }
        else if (createObjectMode == modeDrawSpiral)
        {
            QPainterPath path = SpiralPath(localRect.width(), localRect.height(), m_doc->itemToolPrefs().spiralStartAngle, m_doc->itemToolPrefs().spiralEndAngle, m_doc->itemToolPrefs().spiralFactor);
            p->translate(localRect.left(), localRect.top());
            p->drawPath(path);
        }
        else if ((createObjectMode == modeDrawShapes) && (createObjectSubMode > 1))
        {
            FPointArray poly;
            int valCount = m_doc->ValCount;
            double *vals = m_doc->ShapeValues;
            for (int a = 0; a < valCount-3; a += 4)
            {
                if (vals[a] < 0)
                {
                    poly.setMarker();
                    continue;
                }
                double x1 = localRect.width()  * vals[a] / 100.0;
                double y1 = localRect.height() * vals[a+1] / 100.0;
                double x2 = localRect.width()  * vals[a+2] / 100.0;
                double y2 = localRect.height() * vals[a+3] / 100.0;
                poly.addPoint(x1, y1);
                poly.addPoint(x2, y2);
            }
            QPainterPath path = poly.toQPainterPath(false);
            p->translate(localRect.left(), localRect.top());
            p->drawPath(path);
        }
        p->restore();
    }
    else
    {
        QPoint p1 = m_canvas->canvasToLocal(topLeft);
        QPoint p2 = m_canvas->canvasToLocal(btRight);

        p->save();
        p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
        p->setBrush(drawColor);
        p->drawLine(p1, p2);
        p->restore();
    }
}
Ejemplo n.º 26
0
void Cqtpainter::Paint()
{
    static const QPoint points[4] = {
        QPoint(10, 80),
        QPoint(20, 10),
        QPoint(80, 30),
        QPoint(90, 70)
    };

    QRect rect(10, 20, 80, 60);

    QPainterPath path;
    path.moveTo(20, 80);
    path.lineTo(20, 30);
    path.cubicTo(80, 0, 50, 50, 80, 80);

    int startAngle = 20 * 16;//ÓëGDI+²»Í¬
    int arcLength = 120 * 16;

    QFont myfont = m_painter->font();
    myfont.setBold(m_fontOptions.blod);
    myfont.setItalic(m_fontOptions.italic);
    myfont.setUnderline(m_fontOptions.underline);
    myfont.setStrikeOut(m_fontOptions.strikeout);
    m_painter->setFont(myfont);

//! [10]
    for (int x = 0; x < m_nWidth; x += 100) {
        for (int y = 0; y < m_nHeigth; y += 100) {
            m_painter->save();
            m_painter->translate(x, y);
//! [10] //! [11]
            if (m_transformed) {
                m_painter->translate(50, 50);
                m_painter->rotate(60.0);
                m_painter->scale(0.6, 0.9);
                m_painter->translate(-50, -50);
            }

            switch (m_shape) {
            case TypeLine:
                m_painter->drawLine(rect.bottomLeft(), rect.topRight());
                break;
            case Points:
                m_painter->drawPoints(points, 4);
                break;
            case TypePolyline:
                m_painter->drawPolyline(points, 4);
                break;
            case TypePolygon:
                m_painter->drawPolygon(points, 4);
                break;
            case TypeRect:
                m_painter->drawRect(rect);
                break;
            case RoundedRect:
                m_painter->drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
                break;
            case TypeEllipse:
                m_painter->drawEllipse(rect);
                break;
            case TypeArc:
                m_painter->drawArc(rect, startAngle, arcLength);
                break;
            case TypeChord:
                m_painter->drawChord(rect, startAngle, arcLength);
                break;
            case TypePie:
                m_painter->drawPie(rect, startAngle, arcLength);
                break;
            case Path:
                m_painter->drawPath(path);
                break;
            case Text:
                m_painter->drawText(rect, Qt::AlignCenter, QString("hello\nÄãºÃ\n"));
                break;
            case TypePixmap:
                m_painter->drawPixmap(10, 10, pixmap);
            }
//! [12] //! [13]
            m_painter->restore();
        }
    }

    m_painter->setRenderHint(QPainter::Antialiasing, false);
    QColor clr(200);
    if (m_painter->device()->devType() == QInternal::Widget)
       clr = static_cast<QWidget*>(m_painter->device())->palette().dark().color();

    m_painter->setPen(clr);
    m_painter->setBrush(Qt::NoBrush);
    m_painter->drawRect(QRect(0, 0, m_nWidth - 1, m_nHeigth - 1));
}
Ejemplo n.º 27
0
QPainterPath BezierCurve::getStrokedPath(qreal width, bool usePressure)
{
    QPainterPath path;
    QPointF tangentVec, normalVec, normalVec2, normalVec2_1, normalVec2_2;
    qreal width2 = width;
    path.setFillRule(Qt::WindingFill);
    int n = vertex.size();
    normalVec = QPointF(-(c1.at(0) - origin).y(), (c1.at(0) - origin).x());
    normalise(normalVec);
    if (usePressure) width2 = width * 0.5 * pressure.at(0);
    if (n==1 && width2 == 0.0)  width2 = 0.15 * width;
    path.moveTo(origin + width2*normalVec);
    for(int i=0; i<n; i++)
    {
        if (i==n-1)
        {
            normalVec2 = QPointF(-(vertex.at(i) - c2.at(i)).y(), (vertex.at(i) - c2.at(i)).x());
        }
        else
        {
            normalVec2_1 = QPointF(-(vertex.at(i) - c2.at(i)).y(), (vertex.at(i) - c2.at(i)).x());
            normalise(normalVec2_1);
            normalVec2_2 = QPointF(-(c1.at(i+1) - vertex.at(i)).y(), (c1.at(i+1) - vertex.at(i)).x());
            normalise(normalVec2_2);
            normalVec2 = normalVec2_1 + normalVec2_2;
        }
        normalise(normalVec2);
        if (usePressure) width2 = width * 0.5 * pressure.at(i);
        if (n==1 && width2 == 0.0)  width2 = 0.15 * width;
        //if (i==n-1) width2 = 0.0;
        path.cubicTo(c1.at(i) + width2*normalVec, c2.at(i) + width2*normalVec2, vertex.at(i) + width2*normalVec2);
        //path.moveTo(vertex.at(i) + width*normalVec2);
        //path.lineTo(vertex.at(i) - width*normalVec2);
        normalVec = normalVec2;
    }
    if (usePressure) width2 = width * 0.5 * pressure.at(n-1);
    if (n==1 && width2 == 0.0)  width2 = 0.15 * width;

    //path.lineTo(vertex.at(n-1) - width2*normalVec);
    tangentVec = (vertex.at(n-1)-c2.at(n-1));
    normalise(tangentVec);
    path.cubicTo(vertex.at(n-1) + width2*(normalVec+1.8*tangentVec), vertex.at(n-1) + width2*(-normalVec+1.8*tangentVec), vertex.at(n-1) - width2*normalVec);

    for(int i=n-2; i>-1; i--)
    {
        normalVec2_1 = QPointF((vertex.at(i) - c1.at(i+1)).y(), -(vertex.at(i) - c1.at(i+1)).x());
        normalise(normalVec2_1);
        normalVec2_2 = QPointF((c2.at(i) - vertex.at(i)).y(), -(c2.at(i) - vertex.at(i)).x());
        normalise(normalVec2_2);
        normalVec2 = normalVec2_1 + normalVec2_2;
        normalise(normalVec2);
        if (usePressure) width2 = width * 0.5 * pressure.at(i);
        if (n==1 && width2 == 0.0)  width2 = 0.15 * width;
        path.cubicTo(c2.at(i+1) - width2*normalVec, c1.at(i+1) - width2*normalVec2, vertex.at(i) - width2*normalVec2);
        normalVec = normalVec2;
    }
    normalVec2 = QPointF((origin - c1.at(0)).y(), -(origin - c1.at(0)).x());
    normalise(normalVec2);
    if (usePressure) width2 = width * 0.5 * pressure.at(0);
    if (n==1 && width2 == 0.0)  width2 = 0.15 * width;
    path.cubicTo(c2.at(0) - width2*normalVec, c1.at(0) - width2*normalVec2, origin - width2*normalVec2);
    path.closeSubpath();
    return path;
}
Ejemplo n.º 28
0
        void Breakpoints::paintPoints()
        {
            const std::map<ElVisFloat, ColorMapBreakpoint>& breakpoints = m_model->GetBreakpoints();
            if( breakpoints.size() == 0) return;

            QPainter p;
            p.begin(m_widget);
            p.setRenderHint(QPainter::Antialiasing);

            p.setPen(m_connectionPen);
            QPainterPath path;

            typedef std::map<ElVisFloat, ColorMapBreakpoint>::const_iterator IterType;
            IterType iter = breakpoints.begin();
            double px = (*iter).first;
            double py = (*iter).second.Col.Alpha();

            double x,y;
            CalculatePosition(px, py, x, y);
            path.moveTo( x, y );

            for( ; iter != breakpoints.end(); ++iter)
            {
                px = (*iter).first;
                py = (*iter).second.Col.Alpha();
                CalculatePosition(px, py, x, y);

                path.lineTo(x, y);
            }
            p.drawPath(path);


            p.setPen(m_pointPen);
            p.setBrush(m_pointBrush);

            for(iter = breakpoints.begin() ; iter != breakpoints.end(); ++iter)
            {
                if( iter == m_selectedBreakpoint )
                {
                    p.setPen(m_selectedPointPen);
                }
                else
                {
                    p.setPen(m_pointPen);
                }

                QRectF bounds = pointBoundingRect(iter);
                p.drawEllipse(bounds);
            }

            //if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) 
            //{
            //    p.setPen(m_connectionPen);

            //    QPainterPath path;
            //    path.moveTo(m_points.at(0));
            //    for (int i=1; i<m_points.size(); ++i) {
            //        path.lineTo(m_points.at(i));
            //    }
            //    p.drawPath(path);
            //}

            //p.setPen(m_pointPen);
            //p.setBrush(m_pointBrush);

            //for (int i=0; i<m_points.size(); ++i) 
            //{
            //    if( i == m_currentIndex ) continue;
            //    QRectF bounds = pointBoundingRect(i);
            //    p.drawEllipse(bounds);
            //}

            //if( m_currentIndex >= 0 && m_currentIndex < m_points.size() )
            //{
            //    p.setPen(m_selectedPointPen);
            //    QRectF bounds = pointBoundingRect(m_currentIndex);
            //    p.drawEllipse(bounds);
            //}
        }
Ejemplo n.º 29
0
void MapWidget::mousePressEvent(QMouseEvent* e)
{
   if (e->button()==Qt::LeftButton)
   {
      if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
      {
         start_x_ = e->x();
         start_y_ = e->y();
         drag_=true;
      }
      else if (cur_tool_==Info)
      {
         if (map_)
         {
            QVector<QPair<QString,QString> > info;

            projection map_proj(map_->srs()); // map projection
            double scale_denom = scale_denominator(map_->scale(),map_proj.is_geographic());
            CoordTransform t(map_->width(),map_->height(),map_->get_current_extent());

            for (unsigned index = 0; index <  map_->layer_count();++index)
            {
               if (int(index) != selectedLayer_) continue;

               layer & layer = map_->layers()[index];
               if (!layer.visible(scale_denom)) continue;
               std::string name = layer.name();
               double x = e->x();
               double y = e->y();
               std::cout << "query at " << x << "," << y << "\n";
               projection layer_proj(layer.srs());
               mapnik::proj_transform prj_trans(map_proj,layer_proj);
               //std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
               mapnik::featureset_ptr fs = map_->query_map_point(index,x,y);

               if (fs)
               {
                  feature_ptr feat  = fs->next();
                  if (feat)
                  {

                      feature_kv_iterator itr(*feat,true);
                      feature_kv_iterator end(*feat);

                      for ( ;itr!=end; ++itr)
                      {
                          info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
                                                                std::get<1>(*itr).to_string().c_str()));
                      }

                      typedef mapnik::coord_transform<mapnik::CoordTransform,mapnik::geometry_type> path_type;

                     for  (unsigned i=0; i<feat->num_geometries();++i)
                     {
                        mapnik::geometry_type & geom = feat->get_geometry(i);
                        path_type path(t,geom,prj_trans);
                        if (geom.size() > 0)
                        {
                           QPainterPath qpath;
                           double x,y;
                           path.vertex(&x,&y);
                           qpath.moveTo(x,y);
                           for (unsigned j = 1; j < geom.size(); ++j)
                           {
                              path.vertex(&x,&y);
                              qpath.lineTo(x,y);
                           }
                           QPainter painter(&pix_);
                           QPen pen(QColor(255,0,0,96));
                           pen.setWidth(3);
                           pen.setCapStyle(Qt::RoundCap);
                           pen.setJoinStyle(Qt::RoundJoin);
                           painter.setPen(pen);
                           painter.drawPath(qpath);
                           update();
                        }
                     }
                  }
               }

               if (info.size() > 0)
               {
                  info_dialog info_dlg(info,this);
                  info_dlg.exec();
                  break;
               }
            }

            // remove annotation layer
            map_->layers().erase(remove_if(map_->layers().begin(),
                                           map_->layers().end(),
                                           bind(&layer::name,_1) == "*annotations*")
                                 , map_->layers().end());
         }
      }
   }
   else if (e->button()==Qt::RightButton)
   {
      //updateMap();
   }
}
Ejemplo n.º 30
0
void MVTemplatesView2Panel::paint(QPainter* painter)
{
    painter->setRenderHint(QPainter::Antialiasing);

    QSize ss = this->windowSize();
    QPen pen = painter->pen();

    d->m_bottom_section_height = qMax(20.0, ss.height() * 0.1);

    if (!d->m_draw_disks)
        d->m_bottom_section_height = 0;

    QRect R(0, 0, ss.width(), ss.height());

    //BACKGROUND
    if (!this->exportMode()) {
        if (d->m_current) {
            painter->fillRect(R, d->m_colors["view_background_highlighted"]);
        }
        else if (d->m_selected) {
            painter->fillRect(R, d->m_colors["view_background_selected"]);
        }
        //else if (d->m_hovered) {
        //    painter->fillRect(R, d->m_colors["view_background_hovered"]);
        //}
        else {
            painter->fillRect(R, d->m_colors["view_background"]);
        }
    }

    if (!this->exportMode()) {
        //FRAME
        if (d->m_selected) {
            painter->setPen(QPen(d->m_colors["view_frame_selected"], 1));
        }
        else {
            painter->setPen(QPen(d->m_colors["view_frame"], 1));
        }
        painter->drawRect(R);
    }

    //TOP SECTION
    {
        QString txt = d->m_title;
        QFont fnt = this->font();
        QRectF R(5, 3, ss.width() - 10, fnt.pixelSize());
        //fnt.setPixelSize(qMin(16.0, qMax(10.0, qMin(d->m_top_section_height, ss.width() * 1.0) - 4)));
        //fnt.setPixelSize(14);
        painter->setFont(fnt);

        QPen pen = painter->pen();
        pen.setColor(d->m_colors["cluster_label"]);
        painter->setPen(pen);
        painter->drawText(R, Qt::AlignLeft | Qt::AlignVCenter, txt);
    }

    //BOTTOM SECTION
    if (d->m_bottom_section_height) {
        if (d->m_firing_rate_disk_diameter) {
            QPen pen_hold = painter->pen();
            QBrush brush_hold = painter->brush();
            painter->setPen(Qt::NoPen);
            painter->setBrush(QBrush(d->m_colors["firing_rate_disk"]));
            QRectF R(0, ss.height() - d->m_bottom_section_height, ss.width(), d->m_bottom_section_height);
            double tmp = qMin(R.width(), R.height());
            double rad = tmp * d->m_firing_rate_disk_diameter / 2 * 0.9;
            painter->drawEllipse(R.center(), rad, rad);
            painter->setPen(pen_hold);
            painter->setBrush(brush_hold);
        }
    }

    //SETUP ELECTRODE LOCATIONS
    d->setup_electrode_boxes(ss.width(), ss.height());

    //ELECTRODES AND WAVEFORMS
    int M = d->m_template.N1();
    int T = d->m_template.N2();
    d->m_clip_size = T;
    for (int m = 0; m < M; m++) {
        QPainterPath path;
        for (int t = 0; t < T; t++) {
            double val = d->m_template.value(m, t);
            QPointF pt = d->coord2pix(m, t, val);
            if (t == 0)
                path.moveTo(pt);
            else
                path.lineTo(pt);
        }
        pen.setColor(d->m_channel_colors.value(m, Qt::black));
        pen.setWidth(2);
        if (this->exportMode())
            pen.setWidth(6);
        painter->strokePath(path, pen);
        QRectF box = d->m_electrode_boxes.value(m);
        pen.setColor(QColor(180, 200, 200));
        pen.setWidth(1);
        painter->setPen(pen);
        //if (d->m_draw_ellipses)
        if (true)
            painter->drawEllipse(box);
    }
}