Esempio n. 1
0
void LinkStatusWidget::paintEvent(QPaintEvent *event){

    initLines();

    QPainter painter(this);

    QPixmap pic(QString::fromUtf8(":/computer_white.png"));

    QRectF dest(0,0,pic.width(),pic.height());



    QPixmap pic2(QString::fromUtf8(":/honeywell.png"));

    QRectF dest2(0,0,pic2.width(),pic2.height());
    //220*180

    QRectF target_0(this->left_left,this->left_top,this->left_width,this->left_height);

    QRectF target_1(this->width()-this->right_right-this->right_width,this->right_top,this->right_width,this->right_height);

    QRectF target_2(this->width()-this->right_right-this->right_width,this->right_top+this->right_height+this->right_space,this->right_width,this->right_height);

    painter.setPen(Qt::white);
    painter.drawPixmap(target_0,pic2,dest2);

    painter.drawText(this->left_left+this->left_width+this->left_space,this->left_top+painter.fontMetrics().height(),Config::LINKSTATUS_LABEL.split("#").at(2));



    painter.drawPixmap(target_1,pic,dest);

    QString text=Config::LINKSTATUS_LABEL.split("#").at(0);
    int f_w=painter.fontMetrics().width(text);

    painter.drawText(this->width()-this->right_right-this->right_width-this->right_space*2-f_w,this->right_top+painter.fontMetrics().height()+this->right_space,text);

    painter.drawPixmap(target_2,pic,dest);

    text=Config::LINKSTATUS_LABEL.split("#").at(1);
    f_w=painter.fontMetrics().width(text);


    painter.drawText(this->width()-this->right_right-this->right_width-this->right_space*2-f_w,this->right_top+this->right_height+this->right_space*2+painter.fontMetrics().height(),text);



    //draw base line
    painter.save();
    //#353942
    QPen pen1(Qt::white,8,Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    pen1.setColor(QColor(53, 57, 66));

    painter.setPen(pen1);
    painter.drawLines(lines);
    painter.restore();

    if(!this->isConn){
        return;
    }

    int centerHeight=this->right_top+this->right_height+this->right_space/2;

    QColor co1 =QColor(146, 196, 15) ;
    QColor co2 =QColor(0, 255, 0, 0);

    QColor co3 =QColor( 255,0, 0,200);
    QColor co4 =QColor( 255,0,0, 0);


    int mleft=this->width()-this->right_right-this->right_width-this->right_space-this->countMain;
    int mright=mleft+this->line_width_main;

    if(this->isBroken_1){

        QLinearGradient linearGradient = QLinearGradient(mleft,centerHeight,mright,centerHeight);
        linearGradient.setColorAt(0,co3);
        linearGradient.setColorAt(1,co4);

        QPen pen2(linearGradient,5);
        pen2.setCapStyle(Qt::RoundCap);
        painter.setPen(pen2);

    }else{

        QLinearGradient linearGradient = QLinearGradient(mleft,centerHeight,mright,centerHeight);
        linearGradient.setColorAt(0,co1);
        linearGradient.setColorAt(1,co2);

        QPen pen2(linearGradient,5);
        pen2.setCapStyle(Qt::RoundCap);
        painter.setPen(pen2);

    }

    painter.drawLine(mleft,centerHeight,mright,centerHeight);


    int sbottom= this->right_top+this->right_height/2+this->countSub;
    int stop= sbottom-this->line_width_sub;
    int sright=this->width()-this->right_right+this->right_space;

    //message 2
    if(this->isBroken_2){

        QLinearGradient linearGradient2 = QLinearGradient(sright,stop,sright,sbottom);
        linearGradient2.setColorAt(0,co4);
        linearGradient2.setColorAt(1,co3);

        QPen pen3(linearGradient2,4);
        pen3.setCapStyle(Qt::RoundCap);
        painter.setPen(pen3);

    }else{


        QLinearGradient linearGradient2 = QLinearGradient(sright,stop,sright,sbottom);
        linearGradient2.setColorAt(0,co2);
        linearGradient2.setColorAt(1,co1);

        QPen pen3(linearGradient2,4);
        pen3.setCapStyle(Qt::RoundCap);
        painter.setPen(pen3);


    }

    painter.drawLine(sright,stop,sright,sbottom);


}
Esempio n. 2
0
void MyGLWidget::paintGL()
{
    QPainter painter(this);
    drawBubble(&painter);
}
Esempio n. 3
0
QImage VisionDisplayModule::makeOverlay(Camera::Type which)
{
    QImage lineImage(320, 240, QImage::Format_ARGB32);
    lineImage.fill(qRgba(0, 0, 0, 0));
    QPainter painter(&lineImage);
    painter.setPen(QColor(246, 15, 15));
	const messages::VisionField *visField = visMod.vision_field.getMessage(true).get();
	const messages::VisionBall *visBall = visMod.vision_ball.getMessage(true).get();
	const messages::VisionRobot *visRobots = visMod.vision_robot.getMessage(true).get();

	if (which == Camera::TOP) {
		for (int i = 0; i < visField->visual_line_size(); i++) {

			painter.drawLine(visField->visual_line(i).start_x(),
							 visField->visual_line(i).start_y(),
							 visField->visual_line(i).end_x(),
							 visField->visual_line(i).end_y());
		}


		painter.setPen(Qt::magenta);
		for (int i = 0; i < visField->visual_corner_size(); i++) {
			switch(visField->visual_corner(i).corner_type()) {
			case messages::VisualCorner::INNER_L: painter.setPen(Qt::green);
				break;
			case messages::VisualCorner::OUTER_L: painter.setPen(Qt::blue);
				break;
			case messages::VisualCorner::T: painter.setPen(Qt::black);
				break;
			case messages::VisualCorner::CIRCLE: painter.setPen(Qt::magenta);
				break;
			}
			painter.drawLine(visField->visual_corner(i).x() - 5,
							 visField->visual_corner(i).y() - 5,
							 visField->visual_corner(i).x() + 5,
							 visField->visual_corner(i).y() + 5);
			painter.drawLine(visField->visual_corner(i).x() + 5,
							 visField->visual_corner(i).y() - 5,
							 visField->visual_corner(i).x() - 5,
							 visField->visual_corner(i).y() + 5);
		}

		if (visBall->intopcam()) {
			int ball_x = visBall->x();
			int ball_y = visBall->y();
			int ball_radius = visBall->radius();

			painter.setPen(QPen(QColor(0,0,255,200), 1, Qt::SolidLine, Qt::FlatCap));
			painter.setBrush(QBrush(QColor(255,0,0,80),Qt::SolidPattern));
			painter.drawEllipse(ball_x,ball_y,2*ball_radius,2*ball_radius);
		}

		const messages::Robot red1 = visRobots->red1();
		const messages::Robot navy1 = visRobots->navy1();
		const messages::Robot red2 = visRobots->red2();
		const messages::Robot navy2 = visRobots->navy2();

		painter.setPen(QColor(0,0,0));
		painter.setBrush(QBrush(QColor(0, 0, 255, 0), Qt::SolidPattern));
		painter.setPen(QPen(QColor(255,0,0,200), 1, Qt::SolidLine, Qt::FlatCap));
		painter.setBrush(QBrush(QColor(255,0,0,80), Qt::SolidPattern));
		if (red1.on()) {
			QPoint r_points[4] = {
				QPoint(red1.x(), red1.y()),
				QPoint(red1.x()+red1.width(), red1.y()),
				QPoint(red1.x()+red1.width(), red1.y()+red1.height()),
				QPoint(red1.x(), red1.y()+red1.height())
			};
			painter.drawConvexPolygon(r_points, 4);
			if (red2.on()) {
				QPoint r_points[4] = {
					QPoint(red2.x(), red2.y()),
					QPoint(red2.x()+red2.width(), red2.y()),
					QPoint(red2.x()+red2.width(), red2.y()+red2.height()),
					QPoint(red2.x(), red2.y()+red2.height())
				};
				painter.drawConvexPolygon(r_points, 4);
			}
		}
		painter.setPen(QPen(QColor(0,0,255,200), 1, Qt::SolidLine, Qt::FlatCap));
		painter.setBrush(QBrush(QColor(255, 0, 0, 0), Qt::SolidPattern));
		painter.setBrush(QBrush(QColor(0,0,255,80), Qt::SolidPattern));
		if (navy1.on()) {
			QPoint r_points[4] = {
				QPoint(navy1.x(), navy1.y()),
				QPoint(navy1.x()+navy1.width(), navy1.y()),
				QPoint(navy1.x()+navy1.width(), navy1.y()+navy1.height()),
				QPoint(navy1.x(), navy1.y()+navy1.height())
			};
			painter.drawConvexPolygon(r_points, 4);
			if (navy2.on()) {
				QPoint r_points[4] = {
					QPoint(navy2.x(), navy2.y()),
					QPoint(navy2.x()+navy2.width(), navy2.y()),
					QPoint(navy2.x()+navy2.width(), navy2.y()+navy2.height()),
					QPoint(navy2.x(), navy2.y()+navy2.height())
				};
				painter.drawConvexPolygon(r_points, 4);
			}
		}

		const messages::VisualGoalPost yglp = visField->goal_post_l();
		const messages::VisualGoalPost ygrp = visField->goal_post_r();
		// Now we are to draw the goal posts
		painter.setPen(QColor(0,0,0,200));
		painter.setBrush(QBrush(QColor(255,255,0,80), Qt::SolidPattern));
		if (ygrp.visual_detection().certainty() == 2)
			painter.setPen(QColor(0,0,255,200));
		if (ygrp.visual_detection().on() && ygrp.visual_detection().intopcam()) {
			QPoint r_points[4] = {
				QPoint(ygrp.left_top().x(), ygrp.left_top().y()),
				QPoint(ygrp.right_top().x(), ygrp.right_top().y()),
				QPoint(ygrp.right_bot().x(), ygrp.right_bot().y()),
				QPoint(ygrp.left_bot().x(), ygrp.left_bot().y())
			};
			painter.drawConvexPolygon(r_points, 4);
		}
		if (yglp.visual_detection().on() && yglp.visual_detection().intopcam()) {
			painter.setPen(QColor(255,0,0,200));
			QPoint l_points[4] = {
				QPoint(yglp.left_top().x(), yglp.left_top().y()),
				QPoint(yglp.right_top().x(), yglp.right_top().y()),
				QPoint(yglp.right_bot().x(), yglp.right_bot().y()),
				QPoint(yglp.left_bot().x(), yglp.left_bot().y())
			};
			painter.drawConvexPolygon(l_points, 4);
		}

        painter.setPen(Qt::red);
        if (visField->visual_cross().distance() > 0) {
            painter.drawLine(visField->visual_cross().x() + 10,
                             visField->visual_cross().y() + 10,
                             visField->visual_cross().x(),
                             visField->visual_cross().y());
            painter.drawLine(visField->visual_cross().x(),
                             visField->visual_cross().y() + 10,
                             visField->visual_cross().x() + 10,
                             visField->visual_cross().y());
        }


	}
	else { // this is to draw in the bottom camera

		for (int i = 0; i < visField->bottom_line_size(); i++) {

			painter.drawLine(visField->bottom_line(i).start_x(),
							 visField->bottom_line(i).start_y(),
							 visField->bottom_line(i).end_x(),
							 visField->bottom_line(i).end_y());
		}


		painter.setPen(Qt::magenta);
		for (int i = 0; i < visField->bottom_corner_size(); i++) {
			switch(visField->bottom_corner(i).corner_type()) {
			case messages::VisualCorner::INNER_L: painter.setPen(Qt::red);
				break;
			case messages::VisualCorner::OUTER_L: painter.setPen(Qt::blue);
				break;
			case messages::VisualCorner::T: painter.setPen(Qt::black);
				break;
			case messages::VisualCorner::CIRCLE: painter.setPen(Qt::magenta);
				break;
			}
			painter.drawLine(visField->bottom_corner(i).x() - 5,
							 visField->bottom_corner(i).y() - 5,
							 visField->bottom_corner(i).x() + 5,
							 visField->bottom_corner(i).y() + 5);
			painter.drawLine(visField->bottom_corner(i).x() + 5,
							 visField->bottom_corner(i).y() - 5,
							 visField->bottom_corner(i).x() - 5,
							 visField->bottom_corner(i).y() + 5);
		}

		if (!visBall->intopcam()) {
			int ball_x = visBall->x();
			int ball_y = visBall->y();
			int ball_radius = visBall->radius();

			painter.setPen(QPen(QColor(0,0,255,200), 1, Qt::SolidLine, Qt::FlatCap));
			painter.setBrush(QBrush(QColor(255,0,0,80),Qt::SolidPattern));
			painter.drawEllipse(ball_x,ball_y,2*ball_radius,2*ball_radius);
		}
		const messages::VisualGoalPost yglp = visField->goal_post_l();
		const messages::VisualGoalPost ygrp = visField->goal_post_r();
		// Now we are to draw the goal posts
		painter.setPen(QColor(0,0,0,200));
		painter.setBrush(QBrush(QColor(255,255,0,80), Qt::SolidPattern));
		if (ygrp.visual_detection().certainty() == 2)
			painter.setPen(QColor(0,0,255,200));
		if (ygrp.visual_detection().on() && !ygrp.visual_detection().intopcam()) {
			QPoint r_points[4] = {
				QPoint(ygrp.left_top().x(), ygrp.left_top().y()),
				QPoint(ygrp.right_top().x(), ygrp.right_top().y()),
				QPoint(ygrp.right_bot().x(), ygrp.right_bot().y()),
				QPoint(ygrp.left_bot().x(), ygrp.left_bot().y())
			};
			painter.drawConvexPolygon(r_points, 4);
		}
		if (yglp.visual_detection().on() && !yglp.visual_detection().intopcam()) {
			painter.setPen(QColor(255,0,0,200));
			QPoint l_points[4] = {
				QPoint(yglp.left_top().x(), yglp.left_top().y()),
				QPoint(yglp.right_top().x(), yglp.right_top().y()),
				QPoint(yglp.right_bot().x(), yglp.right_bot().y()),
				QPoint(yglp.left_bot().x(), yglp.left_bot().y())
			};
			painter.drawConvexPolygon(l_points, 4);
		}
	}

	return lineImage;

}
Esempio n. 4
0
void ToolButton::paintEvent( QPaintEvent * _pe )
{
	const bool active = isDown() || isChecked();

	QPainter painter(this);
	painter.setRenderHint(QPainter::SmoothPixmapTransform);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setPen(Qt::NoPen);

	QLinearGradient outlinebrush(0, 0, 0, height());
	QLinearGradient brush(0, 0, 0, height());

	brush.setSpread(QLinearGradient::PadSpread);
	QColor highlight(255, 255, 255, 70);
	QColor shadow(0, 0, 0, 70);
	QColor sunken(220, 220, 220, 30);
	QColor normal1(255, 255, 245, 60);
	QColor normal2(255, 255, 235, 10);

	if( active )
	{
		outlinebrush.setColorAt(0.0f, shadow);
		outlinebrush.setColorAt(1.0f, highlight);
		brush.setColorAt(0.0f, sunken);
		painter.setPen(Qt::NoPen);
	}
	else
	{
		outlinebrush.setColorAt(1.0f, shadow);
		outlinebrush.setColorAt(0.0f, highlight);
		brush.setColorAt(0.0f, normal1);
		if( m_mouseOver == false )
		{
			brush.setColorAt(1.0f, normal2);
		}
		painter.setPen(QPen(outlinebrush, 1));
	}

	painter.setBrush(brush);

	painter.drawRoundedRect( 0, 0, width(), height(), 5, 5 );

	const int dd = active ? 1 : 0;
	QPoint pt = QPoint( ( width() - m_img.width() ) / 2 + dd, 3 + dd );
	if( s_iconOnlyMode )
	{
		pt.setY( ( height() - m_img.height() ) / 2 - 1 + dd );
	}
	painter.drawImage( pt, m_img );

	if( s_iconOnlyMode == false )
	{
		const QString l = ( active && m_altLabel.isEmpty() == FALSE ) ?
								m_altLabel : m_label;
		const int w = painter.fontMetrics().width( l );
		painter.setPen( Qt::black );
		painter.drawText( ( width() - w ) / 2 +1+dd, height() - 4+dd, l );
		painter.setPen( Qt::white );
		painter.drawText( ( width() - w ) / 2 +dd, height() - 5+dd, l );
	}
}
Esempio n. 5
0
/*!
   \return Icon representing the curve on the legend

   \param index Index of the legend entry 
                ( ignored as there is only one )
   \param size Icon size

   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
 */
QwtGraphic QwtPlotCurve::legendIcon( int index, 
    const QSizeF &size ) const
{
    Q_UNUSED( index );

    if ( size.isEmpty() )
        return QwtGraphic();

    QwtGraphic graphic;
    graphic.setDefaultSize( size );
    graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true );

    QPainter painter( &graphic );
    painter.setRenderHint( QPainter::Antialiasing,
        testRenderHint( QwtPlotItem::RenderAntialiased ) );

    if ( d_data->legendAttributes == 0 ||
        d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
    {
        QBrush brush = d_data->brush;

        if ( brush.style() == Qt::NoBrush &&
            d_data->legendAttributes == 0 )
        {
            if ( style() != QwtPlotCurve::NoCurve )
            {
                brush = QBrush( pen().color() );
            }
            else if ( d_data->symbol &&
                ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
            {
                brush = QBrush( d_data->symbol->pen().color() );
            }
        }

        if ( brush.style() != Qt::NoBrush )
        {
            QRectF r( 0, 0, size.width(), size.height() );
            painter.fillRect( r, brush );
        }
    }

    if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )
    {
        if ( pen() != Qt::NoPen )
        {
            QPen pn = pen();
            pn.setCapStyle( Qt::FlatCap );

            painter.setPen( pn );

            const double y = 0.5 * size.height();
            QwtPainter::drawLine( &painter, 0.0, y, size.width(), y );
        }
    }

    if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
    {
        if ( d_data->symbol )
        {
            QRectF r( 0, 0, size.width(), size.height() );
            d_data->symbol->drawSymbol( &painter, r );
        }
    }

    return graphic;
}
Esempio n. 6
0
void Screen::paintEvent( QPaintEvent * e ) {
    //qDebug("Screen::paintEvent");
    QPainter painter(this);
    painter.eraseRect( e->rect() );
    //painter.fillRect( e->rect(), QColor(255,0,0) );
}
void MusicWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.drawPixmap(0,0,QPixmap("image/player_skin.png"));
    painter.drawPixmap(QRectF(142,133,ArtistPic.width()/ArtistPic.height()*67,67),ArtistPic,QRectF(0,0,ArtistPic.width(),ArtistPic.height()));
}
Esempio n. 8
0
void AreaDialog::paintEvent(QPaintEvent* e)
{
  Q_UNUSED(e);

  if (mGrabbing) // grabWindow() should just get the background
    return;

  QPainter painter(this);

  QPalette pal = palette();
  QFont font   = QToolTip::font();

  QColor handleColor(85, 160, 188, 220);
  QColor overlayColor(0, 0, 0, mOverlayAlpha);
  QColor textColor = pal.color(QPalette::Active, QPalette::Text);
  QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base);
  painter.drawPixmap(0, 0, mScreenshot->pixmap());
  painter.setFont(font);

  QRect r = mSelection.normalized().adjusted(0, 0, -1, -1);

  QRegion grey(rect());
  grey = grey.subtracted(r);
  painter.setPen(handleColor);
  painter.setBrush(overlayColor);
  painter.setClipRegion(grey);
  painter.drawRect(-1, -1, rect().width() + 1, rect().height() + 1);
  painter.setClipRect(rect());
  painter.setBrush(Qt::NoBrush);
  painter.drawRect(r);

  if (mShowHelp) {
    //Drawing the explanatory text.
    QRect helpRect = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen());
    QString helpTxt = tr("Lightscreen area mode:\nUse your mouse to draw a rectangle to capture.\nPress any key or right click to exit.");

    helpRect.setHeight(qRound((float)(helpRect.height() / 10))); // We get a decently sized rect where the text should be drawn (centered)

    // We draw the white contrasting background for the text, using the same text and options to get the boundingRect that the text will have.
    painter.setPen(QPen(Qt::white));
    painter.setBrush(QBrush(QColor(255, 255, 255, 180), Qt::SolidPattern));
    QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);

    // These four calls provide padding for the rect
    bRect.setWidth(bRect.width() + 12);
    bRect.setHeight(bRect.height() + 10);
    bRect.setX(bRect.x() - 12);
    bRect.setY(bRect.y() - 10);

    painter.drawRoundedRect(bRect, 8, 8);

    // Draw the text:
    painter.setPen(QPen(Qt::black));
    painter.drawText(helpRect, Qt::AlignCenter, helpTxt);
  }

  if (!mSelection.isNull()) {
    // The grabbed region is everything which is covered by the drawn
    // rectangles (border included). This means that there is no 0px
    // selection, since a 0px wide rectangle will always be drawn as a line.
    QString txt = QString("%1x%2").arg(mSelection.width() == 0 ? 2 : mSelection.width())
        .arg(mSelection.height() == 0 ? 2 : mSelection.height());
    QRect textRect = painter.boundingRect(rect(), Qt::AlignLeft, txt);
    QRect boundingRect = textRect.adjusted(-4, 0, 0, 0);

    if (textRect.width() < r.width() - 2*mHandleSize &&
       textRect.height() < r.height() - 2*mHandleSize &&
       (r.width() > 100 && r.height() > 100)) // center, unsuitable for small selections
    {
      boundingRect.moveCenter(r.center());
      textRect.moveCenter(r.center());
    }
    else if (r.y() - 3 > textRect.height() &&
      r.x() + textRect.width() < rect().right()) // on top, left aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3));
      textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3));
    }
    else if (r.x() - 3 > textRect.width()) // left, top aligned
    {
      boundingRect.moveTopRight(QPoint(r.x() - 3, r.y()));
      textRect.moveTopRight(QPoint(r.x() - 5, r.y()));
    }
    else if (r.bottom() + 3 + textRect.height() < rect().bottom() &&
      r.right() > textRect.width()) // at bottom, right aligned
    {
      boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3));
      textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3));
    }
    else if (r.right() + textRect.width() + 3 < rect().width()) // right, bottom aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom()));
      textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom()));
    }
    // if the above didn't catch it, you are running on a very tiny screen...
    painter.setPen(textColor);
    painter.setBrush(textBackgroundColor);
    painter.drawRect(boundingRect);
    painter.drawText(textRect, txt);

    if ((r.height() > mHandleSize*2 && r.width() > mHandleSize*2)
      || !mMouseDown)
    {
      updateHandles();
      painter.setPen(handleColor);
      handleColor.setAlpha(80);
      painter.setBrush(handleColor);
      painter.drawRects(handleMask().rects());
    }
  }

  if (!mScreenshot->options().magnify)
    return;

  // Drawing the magnified version
  QPoint magStart, magEnd, drawPosition;
  QRect newRect;

  QRect pixmapRect = mScreenshot->pixmap().rect();

  if (mMouseMagnifier) {
    drawPosition = mMousePos - QPoint(100, 100);

    magStart = mMousePos - QPoint(50, 50);
    magEnd = mMousePos + QPoint(50, 50);

    newRect = QRect(magStart, magEnd);
  }
  else {
    // So pretty.. oh so pretty.
    if (mMouseOverHandle == &mTLHandle)
      magStart = mSelection.topLeft();
    else if (mMouseOverHandle == &mTRHandle)
      magStart = mSelection.topRight();
    else if (mMouseOverHandle == &mBLHandle)
      magStart = mSelection.bottomLeft();
    else if (mMouseOverHandle == &mBRHandle)
      magStart = mSelection.bottomRight();
    else if (mMouseOverHandle == &mLHandle)
      magStart = QPoint(mSelection.left(), mSelection.center().y());
    else if (mMouseOverHandle == &mTHandle)
      magStart = QPoint(mSelection.center().x(), mSelection.top());
    else if (mMouseOverHandle == &mRHandle)
      magStart = QPoint(mSelection.right(), mSelection.center().y());
    else if (mMouseOverHandle == &mBHandle)
      magStart =  QPoint(mSelection.center().x(), mSelection.bottom());
    else if (mMouseOverHandle == 0)
      magStart = mMousePos;

    magEnd = magStart;
    drawPosition = mSelection.bottomRight();

    magStart -= QPoint(50, 50);
    magEnd   += QPoint(50, 50);

    newRect = QRect(magStart, magEnd);

    if ((drawPosition.x()+newRect.width()*2) > pixmapRect.width())
      drawPosition.setX(drawPosition.x()-newRect.width()*2);

    if ((drawPosition.y()+newRect.height()*2) > pixmapRect.height())
      drawPosition.setY(drawPosition.y()-newRect.height()*2);

    if (drawPosition.y() == mSelection.bottomRight().y()-newRect.height()*2
     && drawPosition.x() == mSelection.bottomRight().x()-newRect.width()*2)
      painter.setOpacity(0.7);
  }

  if (!pixmapRect.contains(newRect, true) || drawPosition.x() <= 0 || drawPosition.y() <= 0)  {
    return;
  }

  QPixmap magnified = mScreenshot->pixmap().copy(newRect).scaled(QSize(newRect.width()*2, newRect.height()*2));

  QPainter magPainter(&magnified);
  magPainter.setPen(QPen(QBrush(QColor(35, 35, 35)), 2)); // Same border pen
  magPainter.drawRect(magnified.rect());

  if (!mMouseMagnifier) {
    magPainter.drawText(magnified.rect().center()-QPoint(4, -4), "+"); //Center minus the 4 pixels wide and across of the "+" -- TODO: Test alternative DPI settings.
  }

  painter.drawPixmap(drawPosition, magnified);
}
Esempio n. 9
0
void Plotter::paintEvent(QPaintEvent *)
{
    QStylePainter painter(this);
    painter.drawPixmap(0 , 0 ,this->pixmap);
    this->refreshImage();
}
Esempio n. 10
0
bool Object::exportFrames1( ExportFrames1Parameters par )
{
    int frameStart = par.frameStart;
    int frameEnd = par.frameEnd;
    QTransform view = par.view;
    Layer* currentLayer = par.currentLayer;
    QSize exportSize = par.exportSize;
    QString filePath = par.filePath;
    const char* format = par.format;
    int quality = par.quality;
    bool background = par.background;
    bool antialiasing = par.antialiasing;
    QProgressDialog* progress = par.progress;
    int progressMax = par.progressMax;
    int fps = par.fps;
    int exportFps = par.exportFps;

    int frameRepeat;
    int frameReminder, frameReminder1;
    int framePutEvery, framePutEvery1;
    int frameSkipEvery, frameSkipEvery1;
    int frameNumber;
    int framePerSecond;

    QSettings settings( "Pencil", "Pencil" );

    QString extension = "";
    QString formatStr = format;
    if ( formatStr == "PNG" || formatStr == "png" )
    {
        format = "PNG";
        extension = ".png";
    }
    if ( formatStr == "JPG" || formatStr == "jpg" || formatStr == "JPEG" )
    {
        format = "JPG";
        extension = ".jpg";
        background = true; // JPG doesn't support transparency so we have to include the background
    }
    if ( filePath.endsWith( extension, Qt::CaseInsensitive ) )
    {
        filePath.chop( extension.size() );
    }
    //qDebug() << "format =" << format << "extension = " << extension;

    qDebug() << "Exporting frames from " << frameStart << "to" << frameEnd << "at size " << exportSize;
    convertNFrames( fps, exportFps, &frameRepeat, &frameReminder, &framePutEvery, &frameSkipEvery );
    qDebug() << "fps " << fps << " exportFps " << exportFps << " frameRepeat " << frameRepeat << " frameReminder " << frameReminder << " framePutEvery " << framePutEvery << " frameSkipEvery " << frameSkipEvery;
    frameNumber = 0;
    framePerSecond = 0;
    frameReminder1 = frameReminder;
    framePutEvery1 = framePutEvery;
    frameSkipEvery1 = frameSkipEvery;
    for ( int currentFrame = frameStart; currentFrame <= frameEnd; currentFrame++ )
    {
        if ( progress != NULL ) progress->setValue( ( currentFrame - frameStart )*progressMax / ( frameEnd - frameStart ) );
        QImage tempImage( exportSize, QImage::Format_ARGB32_Premultiplied );
        QPainter painter( &tempImage );

        // Make sure that old frame is erased before exporting a new one
        tempImage.fill( 0x00000000 );

        if ( currentLayer->type() == Layer::CAMERA )
        {
            QRect viewRect = ( ( LayerCamera* )currentLayer )->getViewRect();
            QTransform mapView = RectMapTransform( viewRect, QRectF( QPointF( 0, 0 ), exportSize ) );
            mapView = ( ( LayerCamera* )currentLayer )->getViewAtFrame( currentFrame ) * mapView;
            painter.setWorldTransform( mapView );
        }
        else
        {
            painter.setTransform( view );
        }
        paintImage( painter, currentFrame, background, antialiasing );

        frameNumber++;
        framePerSecond++;
        QString frameNumberString = QString::number( frameNumber );
        while ( frameNumberString.length() < 4 ) frameNumberString.prepend( "0" );

        tempImage.save( filePath + frameNumberString + extension, format, quality );
        int delta = 0;
        if ( framePutEvery )
        {
            framePutEvery1--;
            qDebug() << "-->framePutEvery1" << framePutEvery1;
            if ( framePutEvery1 )
            {
                delta = 0;
            }
            else
            {
                delta = 1; framePutEvery1 = framePutEvery;
            }
        }
        if ( frameSkipEvery )
        {
            frameSkipEvery1--;
            qDebug() << "-->frameSkipEvery1" << frameSkipEvery1;
            if ( frameSkipEvery1 )
            {
                delta = 1;
            }
            else
            {
                delta = 0; frameSkipEvery1 = frameSkipEvery;
            }
        }
        if ( frameReminder1 )
        {
            frameReminder1 -= delta;
        }
        else
        {
            delta = 0;
        }
        for ( int i = 0; ( i < frameRepeat - 1 + delta ) && ( framePerSecond < exportFps ); i++ )
        {
            frameNumber++;
            framePerSecond++;
            QString frameNumberLink = QString::number( frameNumber );
            while ( frameNumberLink.length() < 4 ) frameNumberLink.prepend( "0" );
            tempImage.save( filePath + frameNumberLink + extension, format, quality );
        }
        if ( framePerSecond == exportFps )
        {
            framePerSecond = 0;
            frameReminder1 = frameReminder;
            framePutEvery1 = framePutEvery;
            frameSkipEvery1 = frameSkipEvery;
        }
    }

    // XXX no error handling yet
    return true;
}
Esempio n. 11
0
/*绘制*/
void CheckersPicture::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setViewport(p.x(),p.y(),side,side);
    painter.setWindow(0, 0, zoom*(n), zoom*(n));

    QColor dark(0xcc,0xcc,0xcc,200);

    QColor endColor(0x78,0xff,0x21,200);            /*终点颜色*/
    QColor startColor(0xea,0x76,0x0f,200);              /*起点颜色*/
    QColor capturedColor(0xed,0x50,0x62,200);       /*捕获颜色*/
    QColor normalColor(0xd6,0xb8,0x2c,200);         /*正常色*/
    QColor black(0x00, 0x00, 0x00, 200);
    QColor white(0xff, 0xff, 0xff, 220);
    QColor light(0xed,0xfc,0xdf,200);
    QColor deep(0x5a,0x61,0x54,200);

    /*绘制棋盘*/
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            QRect rect = pixelRect(i, j);
            if( !((i+j%2)%2) ) {
                    painter.fillRect(rect, deep);
            } else {
                painter.fillRect(rect, light);
            }
        }
    }

    int ix,jx;

    if(v.size()) {
        int type;
        for(unsigned i=0; i< v.size(); i++) {
            color==WHITE ? jx = n-1-v.at(i).y : jx = v.at(i).y;
            color==WHITE ? ix = n-1-v.at(i).x : ix = v.at(i).x;
            QRect rect = pixelRect(ix, jx);
            type = v.at(i).type;
            if(type == MOVEDFROM)
                painter.fillRect(rect, startColor);
            else if(type == MOVEDTO || type == TOKING)
                painter.fillRect(rect, endColor);
            else if(type == MOVEDTHROUGH)
                painter.fillRect(rect, normalColor);
            else if(type == DELETED)
                painter.fillRect(rect, capturedColor);
        }
    }

    int s = zoom*0.4;
    int sd = zoom*0.3;
    /*画白棋*/
    if(curstate){   /*如果棋局状态发生了改变*/
        painter.setPen(QPen(black,zoom*0.025));
        painter.setBrush(QBrush(white));
        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                /*如果是白色则从最后一行开始画*/
                color==WHITE ? jx = j+1 : jx = n-j;
                color==WHITE? ix = n-i : ix = i+1;
                if(curstate->at(i,j)==WHITE)
                    painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s);
                if(curstate->at(i,j)==WHITEKING) {
                    painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s);
                    painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),sd,sd);
                }
            }
        }
        /*画黑棋*/
        painter.setBrush(QBrush(black));
        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                color==WHITE ? jx = j+1 : jx = n-j;
                color==WHITE ? ix = n-i : ix = i+1;
                if(curstate->at(i,j)==BLACK)
                    painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s);
                if(curstate->at(i,j)==BLACKKING) {
                    painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s);
                    painter.setPen(QPen(white,zoom*0.1));
                    painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),sd,sd);
                    painter.setPen(QPen(black,zoom*0.1));
                }
            }
        }
    }
    if (thinking && showHourglass)
    {
        painter.setWindow(painter.viewport());
        painter.drawImage((width() - hourglass.width()) / 2, (height() - hourglass.height()) / 2, hourglass);
    }
}
Esempio n. 12
0
static void drawGlyphsWin(GraphicsContext* graphicsContext,
                          const SimpleFontData* font,
                          const GlyphBuffer& glyphBuffer,
                          int from,
                          int numGlyphs,
                          const FloatPoint& point) {
    TransparencyAwareGlyphPainter painter(graphicsContext, font, glyphBuffer, from, numGlyphs, point);

    // We draw the glyphs in chunks to avoid having to do a heap allocation for
    // the arrays of characters and advances. Since ExtTextOut is the
    // lowest-level text output function on Windows, there should be little
    // penalty for splitting up the text. On the other hand, the buffer cannot
    // be bigger than 4094 or the function will fail.
    const int kMaxBufferLength = 256;
    Vector<WORD, kMaxBufferLength> glyphs;
    Vector<int, kMaxBufferLength> advances;
    int glyphIndex = 0; // The starting glyph of the current chunk.

    // In order to round all offsets to the correct pixel boundary, this code keeps track of the absolute position
    // of each glyph in floating point units and rounds to integer advances at the last possible moment.

    float horizontalOffset = point.x(); // The floating point offset of the left side of the current glyph.
    int lastHorizontalOffsetRounded = lroundf(horizontalOffset); // The rounded offset of the left side of the last glyph rendered.
    while (glyphIndex < numGlyphs) {
        // How many chars will be in this chunk?
        int curLen = min(kMaxBufferLength, numGlyphs - glyphIndex);
        glyphs.resize(curLen);
        advances.resize(curLen);

        float currentWidth = 0;
        for (int i = 0; i < curLen; ++i, ++glyphIndex) {
            glyphs[i] = glyphBuffer.glyphAt(from + glyphIndex);
            horizontalOffset += glyphBuffer.advanceAt(from + glyphIndex);
            advances[i] = lroundf(horizontalOffset) - lastHorizontalOffsetRounded;
            lastHorizontalOffsetRounded += advances[i];
            currentWidth += glyphBuffer.advanceAt(from + glyphIndex);
            
            // Bug 26088 - very large positive or negative runs can fail to
            // render so we clamp the size here. In the specs, negative
            // letter-spacing is implementation-defined, so this should be
            // fine, and it matches Safari's implementation. The call actually
            // seems to crash if kMaxNegativeRun is set to somewhere around
            // -32830, so we give ourselves a little breathing room.
            const int maxNegativeRun = -32768;
            const int maxPositiveRun =  32768;
            if ((currentWidth + advances[i] < maxNegativeRun) || (currentWidth + advances[i] > maxPositiveRun)) 
                advances[i] = 0;
        }

        // Actually draw the glyphs (with retry on failure).
        bool success = false;
        for (int executions = 0; executions < 2; ++executions) {
            success = painter.drawGlyphs(curLen, &glyphs[0], &advances[0], horizontalOffset - point.x() - currentWidth);
            if (!success && !executions) {
                // Ask the browser to load the font for us and retry.
                PlatformSupport::ensureFontLoaded(font->platformData().hfont());
                continue;
            }
            break;
        }

        if (!success)
            LOG_ERROR("Unable to draw the glyphs after second attempt");
    }
}
Esempio n. 13
0
void CWizShadowWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    m_shadow->DrawBorder(&painter, rect());
}
Esempio n. 14
0
/************
 *
 *功能:绘制背景
 *
 *
 *
 **/
void    mainview::paintEvent(QPaintEvent *)
{

    switch(ui->widgetstack->currentIndex())
    {
        case    0:
        case    2:
        logo_y = this->height()/2 - 200;
        logo_x = this->width()/2 - 100;
        break;
        default:
        logo_y = 50;
        logo_x=this->width()/2-100;
        break;
    }
    switch(ui->widgetstack->currentIndex())
    {
        case  0:
        ui->widgetstack->move(logo_x-80,logo_y+50);
        break;
        case  1://networkconfig
        {
        ui->widgetstack->move(logo_x-150,height()/2-325);
        if(height()/2 > 325)
        ui->widgetstack->resize(461,650);
        break;}
        case  3://wifi
        ui->widgetstack->move(logo_x-50,height()/2-283);
        break;
        case  4://vmlist
        {
                if(this->hostlist->nums_vm <= 12)
                    //vmlist display  order  in  the  windows
                {
                    ui->widgetstack->move(width()/20,this->height()/2-100);
                }
                else if(this->hostlist->nums_vm > 12 && this->hostlist->nums_vm <= 18 )
                {
                    ui->widgetstack->move(width()/20,this->height()/2-200);
                }
                else
                {
                    ui->widgetstack->move(width()/20,this->height()/2-300);
                }
        break;
        }
        default:
        ui->widgetstack->move(logo_x-100,height()/2-80);
        break;

    }
    
    
    
    
    QFont font("Arial",10);
    QPainter painter(this);

    painter.drawPixmap(rect(),QPixmap("./images/terminal-bg.png"));
    painter.drawPixmap(QPoint(logo_x,logo_y),QPixmap("./images/terminal-logo.png"));

    QPixmap  *map = new  QPixmap("./images/information.png");
    painter.drawPixmap(QPoint(this->width()-200,this->height()-50),map->copy(0,map->height()/2,map->width(),
                map->height()/14));//down
    painter.drawPixmap(QPoint(this->width()-100,this->height()-50),map->copy(0,map->height()/2+map->height()/7,//reset
                map->width(),map->height()/14));

    painter.drawPixmap(QPoint(this->width()-70,10),map->copy(0,map->height()/14,map->width(),map->height()/14));//?help
    painter.drawPixmap(QPoint(this->width()-230,10),map->copy(0,map->height()/7+map->height()/14,//reflush
                map->width(),map->height()/14));
    painter.drawPixmap(QPoint(this->width()-270,10),map->copy(0,2*(map->height()/7)+map->height()/14,map->width(),
                                                                  map->height()/14));//more operator
    delete map;

    if(wifi->connectedname.length()<=0)
    {
    map = new  QPixmap("./images/wifi.png");
    painter.drawPixmap(QPoint(this->width()-120,5),map->copy(0,map->height()/2,map->width(),map->height()/2));
    }
    else
    {
    map = new  QPixmap("./images/wifi_img.png"/*wifi->CheckSignals(wifi->choice_signal)*/);
    painter.drawPixmap(QPoint(this->width()-120,5),map->copy(0,10*map->height()/14,map->width(),map->height()/14));
    }

    delete map;

    QFont font1("Arial",10,QFont::Normal,true);
    painter.setFont(font1);//????
    painter.setPen(QColor(Qt::white));
    painter.drawText(155+logo_x,15+logo_y,version);
    painter.setFont(font);//????
    painter.drawText(20,this->height()-30,"Copyright (C)2001-2015 Yovole Corporation, All Rights Reserved");

    font.setPixelSize(13);
    painter.setFont(font);//????
    painter.drawText(this->width()-175,this->height()-30,"关机");
    painter.drawText(this->width()-75,this->height()-30,"重启");
    if(http->login_state == true)
    {
        /*************the  username length is not equal to the drawtext length,there have question.*******/
        //if(hostlist->nums_vm > 0)
        painter.drawText(this->width()-350-(login->GetUserName().length()),30,login->GetUserName());
        //else
        //painter.drawText(this->width()-350,30,"更多操作");
        if(open) 
            emit  loadoperator(1);
    }
    else
    {
        if(open) 
            emit  loadoperator(0);
        painter.drawText(this->width()-350,30,"更多操作");
    }
   
    
    painter.drawText(this->width()-200,30,"刷新列表");
    painter.drawText(this->width()-40,30,"帮助");
    font.setPixelSize(8);
    font.setBold(true);
    painter.setFont(font);
    painter.drawText(this->width()-120,35,wifi->connectedname);

    ui->widgetlist->move(this->width()-350,40);
    
    ui->pushButton->move(this->width()-240,10);
    ui->pushButton_1->move(this->width()-350,10);
    ui->pushButton_2->move(this->width()-120,10);
    ui->pushButton_3->move(this->width()-70,10);
    ui->pushButton_4->move(this->width()-200,this->height()-50);
    ui->pushButton_5->move(this->width()-100,this->height()-50);


}
Esempio n. 15
0
void ImagingWindow::paintEvent(QPaintEvent *)
{
   QPainter painter(this);
   painter.drawPixmap(0, 0, plot);
}
Esempio n. 16
0
void ScribbleArea::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QRect dirtyRect = event->rect();
    painter.drawImage(dirtyRect, image, dirtyRect);
}
Esempio n. 17
0
void QgsBench::render()
{
  QgsDebugMsg( "entered" );

  QgsDebugMsg( "extent: " +  mMapRenderer->extent().toString() );

  QMap<QString, QgsMapLayer*> layersMap = QgsMapLayerRegistry::instance()->mapLayers();

  QStringList layers( layersMap.keys() );

  mMapRenderer->setLayerSet( layers );

  if ( mSetExtent )
  {
    mMapRenderer->setExtent( mExtent );
  }

  // Maybe in future
  //outputCRS = QgsCRSCache::instance()->crsByAuthId( crsId );
  //mMapRenderer->setMapUnits( outputCRS.mapUnits() );
  //mMapRenderer->setDestinationCrs( outputCRS );

  // TODO: this should be probably set according to project
  mMapRenderer->setProjectionsEnabled( true );

  // Necessary?
  //mMapRenderer->setLabelingEngine( new QgsPalLabeling() );

  mImage = new QImage( mWidth, mHeight, QImage::Format_ARGB32_Premultiplied );
  mImage->fill( 0 );

  mMapRenderer->setOutputSize( QSize( mWidth, mHeight ), mImage->logicalDpiX() );

  QPainter painter( mImage );

  painter.setRenderHints( mRendererHints );

  for ( int i = 0; i < mIterations; i++ )
  {
    start();
    mMapRenderer->render( &painter );
    elapsed();
  }

  mLogMap.insert( "iterations", mTimes.size() );
  mLogMap.insert( "revision", QGSVERSION );

  // Calc stats: user, sys, total
  double min[4], max[4];
  double stdev[4] = {0.};
  double maxdev[4] = {0.};
  double avg[4] = {0.};

  for ( int t = 0; t < 4; t++ )
  {
    for ( int i = 0; i < mTimes.size(); i++ )
    {
      avg[t] += mTimes[i][t];

      if ( i == 0 || mTimes[i][t] < min[t] ) min[t] = mTimes[i][t];
      if ( i == 0 || mTimes[i][t] > max[t] ) max[t] = mTimes[i][t];
    }
    avg[t] /= mTimes.size();
  }

  QMap<QString, QVariant> timesMap;
  for ( int t = 0; t < 4; t++ )
  {
    if ( mIterations > 1 )
    {
      for ( int i = 0; i < mTimes.size(); i++ )
      {
        double d = fabs( avg[t] - mTimes[i][t] );
        stdev[t] += pow( d, 2 );
        if ( i == 0 || d > maxdev[t] ) maxdev[t] = d;
      }

      stdev[t] = sqrt( stdev[t] / mTimes.size() );
    }

    const char *pre[] = { "user", "sys", "total", "wall" };

    QMap<QString, QVariant> map;

    map.insert( "min", min[t] );
    map.insert( "max", max[t] );
    map.insert( "avg", avg[t] );
    map.insert( "stdev", stdev[t] );
    map.insert( "maxdev", maxdev[t] );

    timesMap.insert( pre[t], map );
  }
  mLogMap.insert( "times", timesMap );
}
Esempio n. 18
0
void LayerItem::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawPixmap(0, 0, _pixmap);
}
Esempio n. 19
0
void AboutWindow::Logo::paintEvent(QPaintEvent*) {
  QPainter painter(this);
  QPixmap pixmap(":/logo.png");
  painter.drawPixmap(0, 0, pixmap);
}
Esempio n. 20
0
void QwtPicker::PickerWidget::updateMask()
{
    QRegion mask;

    if ( d_type == RubberBand )
    {
        QBitmap bm( width(), height() );
        bm.fill( Qt::color0 );

        QPainter painter( &bm );
        QPen pen = d_picker->rubberBandPen();
        pen.setColor( Qt::color1 );
        painter.setPen( pen );

        d_picker->drawRubberBand( &painter );

        mask = QRegion( bm );
    }
    if ( d_type == Text )
    {
        d_hasTextMask = parentWidget()->testAttribute( Qt::WA_PaintOnScreen );

        if ( d_hasTextMask )
        {
            const QwtText label = d_picker->trackerText(
                d_picker->trackerPosition() );

            if ( label.testPaintAttribute( QwtText::PaintBackground )
                && label.backgroundBrush().style() != Qt::NoBrush )
            {
                if ( label.backgroundBrush().color().alpha() > 0 )
                {
                    // We don't need a text mask, when we have a background
                    d_hasTextMask = false;
                }
            }
        }

        if ( d_hasTextMask )
        {
            QBitmap bm( width(), height() );
            bm.fill( Qt::color0 );

            QPainter painter( &bm );
            painter.setFont( font() );

            QPen pen = d_picker->trackerPen();
            pen.setColor( Qt::color1 );
            painter.setPen( pen );

            d_picker->drawTracker( &painter );

            mask = QRegion( bm );
        }
        else
        {
            mask = d_picker->trackerRect( font() );
        }
    }

    QWidget *w = parentWidget();
    if ( w && !w->testAttribute( Qt::WA_PaintOnScreen ) )
    {
        // The parent widget gets an update for its complete rectangle
        // when the mask is changed in visible state.
        // With this hide/show we only get an update for the
        // previous mask.

        hide();
    }
    setMask( mask );
    setVisible( !mask.isEmpty() );
}
Esempio n. 21
0
    void MapControl::paintEvent(QPaintEvent* evnt)
    {
        QWidget::paintEvent(evnt);
        QPainter painter(this);
        double line;


        // painter.translate(150,190);
        // painter.scale(0.5,0.5);

        // painter.setClipRect(0,0, size.width(), size.height());

        // painter.setViewport(10000000000,0,size.width(),size.height());

        /*
        // rotating
            rotation = 45;
            painter.translate(256,256);
            painter.rotate(rotation);
            painter.translate(-256,-256);
        */

        layermanager->drawImage(&painter);
        layermanager->drawGeoms(&painter);

        // added by wolf
        // draw scale
        if (scaleVisible)
        {
            if (currentZoom() >= 0 && distanceList.size() > currentZoom())
            {
                line = distanceList.at( currentZoom() ) / pow(2, 18-currentZoom() ) / 0.597164;

                // draw the scale
                painter.setPen(Qt::black);
                QPoint p1(10,size.height()-20);
                QPoint p2((int)line,size.height()-20);
                painter.drawLine(p1,p2);

                painter.drawLine(10,size.height()-15, 10,size.height()-25);
                painter.drawLine((int)line,size.height()-15, (int)line,size.height()-25);

                QString distance;
                if (distanceList.at(currentZoom()) >= 1000)
                {
                    distance = QVariant( distanceList.at(currentZoom())/1000 )  .toString()+ " km";
                }
                else
                {
                    distance = QVariant( distanceList.at(currentZoom()) ).toString() + " m";
                }

                painter.drawText(QPoint((int)line+10,size.height()-15), distance);
            }
        }

        painter.drawLine(screen_middle.x(), screen_middle.y()-10,
                         screen_middle.x(), screen_middle.y()+10); // |
        painter.drawLine(screen_middle.x()-10, screen_middle.y(),
                         screen_middle.x()+10, screen_middle.y()); // -

        // int cross_x = int(layermanager->getMapmiddle_px().x())%256;
        // int cross_y = int(layermanager->getMapmiddle_px().y())%256;
        // painter.drawLine(screen_middle.x()-cross_x+cross_x, screen_middle.y()-cross_y+0,
        //   screen_middle.x()-cross_x+cross_x, screen_middle.y()-cross_y+256); // |
        // painter.drawLine(screen_middle.x()-cross_x+0, screen_middle.y()-cross_y+cross_y,
        //   screen_middle.x()-cross_x+256, screen_middle.y()-cross_y+cross_y); // -

        painter.drawRect(0,0, size.width(), size.height());
        /*
        // rotating
          painter.setMatrix(painter.matrix().inverted());
        //qt = painter.transform();
           qm = painter.combinedMatrix();
        */
        if (mousepressed && mymousemode == Dragging)
        {
            QRect rect = QRect(pre_click_px, current_mouse_pos);
            painter.drawRect(rect);
        }


        // Draw the Lat and Lon if needed
        if (cursorPosVisible) {
          line = distanceList.at( currentZoom() ) / pow(2, 18-currentZoom() ) / 0.597164;

          QString str;
          str = QString(tr(" Lat: %1")).arg(currentWorldCoordinate.y());
          painter.drawText(QPoint((int)line+70,size.height()-15), str);

          str = QString(tr(" Lon: %1")).arg(currentWorldCoordinate.x());
          painter.drawText(QPoint((int)line+160,size.height()-15), str);
        }

        emit viewChanged(currentCoordinate(), currentZoom());
    }
    QImage *createArrowBackground(const QMatrix &matrix) const
    {
        QRect scaledRect;
        scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height()));

        QImage *image = new QImage(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied);
        image->fill(QColor(0, 0, 0, 0).rgba());
        QPainter painter(image);
        painter.setRenderHint(QPainter::SmoothPixmapTransform);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setPen(Qt::NoPen);

        if (Colors::useEightBitPalette){
            painter.setPen(QColor(120, 120, 120));
            if (this->pressed)
                painter.setBrush(QColor(60, 60, 60));
            else if (this->highlighted)
                painter.setBrush(QColor(100, 100, 100));
            else
                painter.setBrush(QColor(80, 80, 80));
        }
        else {
            QLinearGradient outlinebrush(0, 0, 0, scaledRect.height());
            QLinearGradient brush(0, 0, 0, scaledRect.height());

            brush.setSpread(QLinearGradient::PadSpread);
            QColor highlight(255, 255, 255, 70);
            QColor shadow(0, 0, 0, 70);
            QColor sunken(220, 220, 220, 30);
            QColor normal1 = QColor(200, 170, 160, 50);
            QColor normal2 = QColor(50, 10, 0, 50);

           if (pressed) {
               outlinebrush.setColorAt(0.0f, shadow);
               outlinebrush.setColorAt(1.0f, highlight);
               brush.setColorAt(0.0f, sunken);
               painter.setPen(Qt::NoPen);
           } else {
               outlinebrush.setColorAt(1.0f, shadow);
               outlinebrush.setColorAt(0.0f, highlight);
               brush.setColorAt(0.0f, normal1);
               if (!this->highlighted)
                   brush.setColorAt(1.0f, normal2);
               painter.setPen(QPen(outlinebrush, 1));
           }
           painter.setBrush(brush);
        }

        painter.drawRect(0, 0, scaledRect.width(), scaledRect.height());

        float xOff = scaledRect.width() / 2;
        float yOff = scaledRect.height() / 2;
        float sizex = 3.0f * matrix.m11();
        float sizey = 1.5f * matrix.m22();
        if (this->type == TextButton::UP)
            sizey *= -1;
        QPainterPath path;
        path.moveTo(xOff, yOff + (5 * sizey));
        path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey));
        path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey));
        path.lineTo(xOff, yOff + (5 * sizey));
        painter.drawPath(path);

        return image;
    }
      int validPix = width-x;
      if(validPix<8) { // set out-of-bounds pixels to zero
        imageByte >>= 8-validPix;
        imageByte <<= 8-validPix;
      }
      grfImage.append(QString().sprintf("%02X",imageByte));
    }
  }

  int bytesPerLine = (width+7)/8;
  m_printBuffer += QString("~DGR:IMG.GRF,%1,%2,").arg(bytesPerLine*nbOfLines).arg(bytesPerLine);
  m_printBuffer += compressedHexa(grfImage);

  m_printBuffer += "\n";

  QTransform transform = painter()->worldTransform();

  int xInDots = (int)(rectangle.top() + transform.dx());
  int yInDots = (int)(rectangle.left() + transform.dy());

  m_printBuffer += QString(m_CmdPrefix + "FO%1,%2" + m_CmdPrefix + "XGR:IMG.GRF,1,1" + m_CmdPrefix + "FS\n").arg(xInDots).arg(yInDots);
}


void 	ZebraPaintEngine::drawLines ( const QLineF * lines, int lineCount )
{
  for (int i=0; i< lineCount; i++) {

    QTransform transform = painter()->worldTransform();

    int xInDots = (int)(lines[i].x1() + transform.dx());
int ImageWindowItem::displayModeDisplay() const
{
    if (!m_dataProvider || !m_imgBuffer || !m_image)
        return ERR_NOT_SET_DATAPTR;
    if (!m_convertor)       //表明转换过后才显示
        return ERR_NOT_SET_CONVERTOR;
    const FeaturesOfDataItem* features = m_dataProvider->constDataFeatures();
    if (!features)
        return ERR_INTERNAL_ERROR;

    //fetch pixel around cursor, convert to rgba format
    QRect rtWnd = geometry();//显示区左上角坐标及显示区的长宽
	//m_range显示图像的大小
    QRect rtRange(
                m_cursorPostion.x()-m_range.width()/2,
                m_cursorPostion.y()-m_range.height()/2,
                m_range.width(),
                m_range.height()
                );
    QRect rtData(0,0,features->payloadDataWidth, features->linesPerFrame);
    //qDebug()<<rtWnd<<rtRange<<"->";
    if (!rtData.contains(rtRange))//数据区不包含图像显示区
    {
        //adjust target rectangle
        if (!rtData.contains(0, rtRange.top()))
            rtRange.setTop(0);
        if (!rtData.contains(rtRange.left(), 0))
            rtRange.setLeft(0);
        if (!rtData.contains(rtRange.right(), 0))
        {
            rtRange.setRight(rtData.right());
            int left = rtData.right()-m_range.width();
            rtRange.setLeft(left < 0 ? 0 : left);
        }
        if (!rtData.contains(rtRange.right(), rtRange.bottom()))
        {
            rtRange.setBottom(rtData.bottom());
            int top = rtData.bottom()-m_range.height();
            rtRange.setTop(top < 0 ? 0 : top);
        }

        rtRange.setWidth(m_range.width());
        rtRange.setHeight(m_range.height());
    }
    //qDebug()<<rtRange<<"<-\n";
    unsigned char *pixel = m_imgBuffer.get();
	//put sth useful information
	QString str;
	str.sprintf("COMS %d (%d,%d)", cmosNumber,m_mousePostion.x(),m_mousePostion.y());  //图像上标记通道和当前坐标(相对于图像1280*1024)
	
	//	 str.sprintf("[%d,%d, %d*%d] H:%.2f, V:%.2f", rtRange.left()*features->colSampleLevel, rtRange.top()*features->rowSampleLevel, rtRange.width(), rtRange.height(),
	//	 static_cast<float>(pic.width())/rtRange.width(), static_cast<float>(pic.height())/rtRange.height());
	
    if (!m_dataProvider->copyArea(rtRange.left(), rtRange.top(), rtRange.width(), rtRange.height(), pixel))
        return ERR_INVALID_PARAM; 
    m_convertor->convert(m_image->bits(), pixel, rtRange.width(), rtRange.height());

	//scale and paint
    QPainter painter(const_cast<ImageWindowItem*>(this));
    QPixmap pic = QPixmap::fromImage(*m_image).scaled(rtWnd.width(), rtWnd.height(), Qt::KeepAspectRatio);
    QRect rtDst((rtWnd.width()-pic.width())/2,(rtWnd.height()-pic.height())/2,pic.width(), pic.height());
    painter.drawPixmap(rtDst, pic);//显示图像

	painter.setPen(m_fontColor);
	painter.drawText(rtDst, str);
    return EXEC_SUCCESS;
}
Esempio n. 25
0
void ItemViewImageDelegate::prepareRatingPixmaps(bool composeOverBackground)
{
    /// Please call this method after prepareBackground() and when d->ratingPixmap is set

    Q_D(ItemViewImageDelegate);

    if (!d->ratingRect.isValid())
    {
        return;
    }

    // We use antialiasing and want to pre-render the pixmaps.
    // So we need the background at the time of painting,
    // and the background may be a gradient, and will be different for selected items.
    // This makes 5*2 (small) pixmaps.

    for (int sel=0; sel<2; ++sel)
    {
        QPixmap basePix;

        if (composeOverBackground)
        {
            // do this once for regular, once for selected backgrounds
            if (sel)
            {
                basePix = d->selPixmap.copy(d->ratingRect);
            }
            else
            {
                basePix = d->regPixmap.copy(d->ratingRect);
            }
        }
        else
        {
            basePix = QPixmap(d->ratingRect.size());
            basePix.fill(Qt::transparent);
        }

        for (int rating=1; rating<=5; ++rating)
        {
            // we store first the 5 regular, then the 5 selected pixmaps, for simplicity
            int index = (sel * 5 + rating) - 1;

            // copy background
            d->ratingPixmaps[index] = basePix;
            // open a painter
            QPainter painter(&d->ratingPixmaps[index]);

            // use antialiasing
            painter.setRenderHint(QPainter::Antialiasing, true);
            painter.setBrush(qApp->palette().color(QPalette::Link));
            QPen pen(qApp->palette().color(QPalette::Text));
            // set a pen which joins the lines at a filled angle
            pen.setJoinStyle(Qt::MiterJoin);
            painter.setPen(pen);

            // move painter while drawing polygons
            painter.translate( lround((d->ratingRect.width() - d->margin - rating*(d->starPolygonSize.width()+1))/2.0) + 2, 0);

            for (int s=0; s<rating; ++s)
            {
                painter.drawPolygon(d->starPolygon, Qt::WindingFill);
                painter.translate(d->starPolygonSize.width() + 1, 0);
            }
        }
    }
}
Esempio n. 26
0
void Z3DCanvasRenderer::renderInportToImage(const QString &filename, Z3DEye eye)
{
  if (eye == CenterEye) {
    //if (m_inport.isReady()) {
    // get color buffer content
    glm::detail::tvec4<uint8_t,glm::highp>* colorBuffer = readBGRAColorBuffer<uint8_t>(eye);
    //if (colorBuffer) {
    glm::ivec2 size = m_inport.getSize();
    QImage upsideDownImage((const uchar*)colorBuffer, size.x, size.y,
                           QImage::Format_ARGB32_Premultiplied);
    QImage image = upsideDownImage.mirrored(false, true);
    QImageWriter writer(filename);
    writer.setCompression(1);
    if (!writer.write(image)) {
      writer.setCompression(0);
      if (!writer.write(image)) {
        if (ZFileType::fileType(filename.toStdString()) == ZFileType::TIFF_FILE) {
          Stack *stack = C_Stack::make(COLOR, image.width(), image.height(), 1);
          color_t *arrayc = (color_t*) stack->array;
          size_t index = 0;
          for (int y = 0; y < image.height(); ++y) {
            for (int x = 0; x < image.width(); ++x) {
              QRgb color = image.pixel(x, y);
              arrayc[index][0] = qRed(color);
              arrayc[index][1] = qGreen(color);
              arrayc[index][2] = qBlue(color);

              index++;
            }
          }
          C_Stack::write(filename.toStdString(), stack);
          C_Stack::kill(stack);
        } else {
          //LERROR() << writer.errorString();
          delete[] colorBuffer;
          throw Exception(writer.errorString().toStdString());
        }
      }
    }
    delete[] colorBuffer;
    //}
    //}
  } else if (eye == RightEye) {
    glm::detail::tvec4<uint8_t,glm::highp>* colorBuffer = readBGRAColorBuffer<uint8_t>(LeftEye);
    glm::ivec2 size = m_rightEyeInport.getSize();
    QImage sideBySideImage(size.x * 2, size.y, QImage::Format_ARGB32_Premultiplied);
    QPainter painter(&sideBySideImage);
    painter.scale(1, -1);
    painter.translate(0, -size.y);
    QImage upsideDownImageLeft((const uchar*)colorBuffer, size.x, size.y,
                               QImage::Format_ARGB32_Premultiplied);
    painter.drawImage(0, 0, upsideDownImageLeft);
    delete[] colorBuffer;
    colorBuffer = readBGRAColorBuffer<uint8_t>(RightEye);
    QImage upsideDownImageRight((const uchar*)colorBuffer, size.x, size.y,
                                QImage::Format_ARGB32_Premultiplied);
    painter.drawImage(size.x, 0, upsideDownImageRight);
    delete[] colorBuffer;

    if (m_renderToImageType == HalfSideBySideStereoView) {
      QImage halfSideBySideImage = sideBySideImage.scaled(
            size.x, size.y, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
      QImageWriter writer(filename);
      writer.setCompression(1);
      if(!writer.write(halfSideBySideImage)) {
        //LERROR() << writer.errorString();
        throw Exception(writer.errorString().toStdString());
      }
    } else {
      QImageWriter writer(filename);
      writer.setCompression(1);
      if(!writer.write(sideBySideImage)) {
        //LERROR() << writer.errorString();
        throw Exception(writer.errorString().toStdString());
      }
    }
  }
}
Esempio n. 27
0
/*!
  protected functions
*/
void PYHistogramTip::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing);
    draw(&painter);
}
Esempio n. 28
0
void QAlphaPaintEngine::flushAndInit(bool init)
{
    Q_D(QAlphaPaintEngine);
    Q_ASSERT(d->m_pass == 0);

    if (d->m_pic) {
        d->m_picpainter->end();

        // set clip region
        d->m_alphargn = d->m_alphargn.intersected(QRect(0, 0, d->m_pdev->width(), d->m_pdev->height()));

        // just use the bounding rect if it's a complex region..
        QVector<QRect> rects = d->m_alphargn.rects();
        if (rects.size() > 10) {
            QRect br = d->m_alphargn.boundingRect();
            d->m_alphargn = QRegion(br);
            rects.clear();
            rects.append(br);
        }

        d->m_cliprgn = d->m_alphargn;

        // now replay the QPicture
        ++d->m_pass; // we are now doing pass #2

        // reset states
        gccaps = d->m_savedcaps;

        painter()->save();
        d->resetState(painter());

        // make sure the output from QPicture is unscaled
        QTransform mtx;
        mtx.scale(1.0f / (qreal(d->m_pdev->logicalDpiX()) / qreal(qt_defaultDpiX())),
                  1.0f / (qreal(d->m_pdev->logicalDpiY()) / qreal(qt_defaultDpiY())));
        painter()->setTransform(mtx);
        painter()->drawPicture(0, 0, *d->m_pic);

        d->m_cliprgn = QRegion();
        d->resetState(painter());

        // fill in the alpha images
        for (int i=0; i<rects.size(); ++i)
            d->drawAlphaImage(rects.at(i));

        d->m_alphargn = QRegion();

        painter()->restore();

        --d->m_pass; // pass #2 finished

        cleanUp();
    }

    if (init) {
        gccaps = PaintEngineFeatures(AllFeatures & ~QPaintEngine::ObjectBoundingModeGradients);

        d->m_pic = new QPicture();
        d->m_pic->d_ptr->in_memory_only = true;
        d->m_picpainter = new QPainter(d->m_pic);
        d->m_picengine = d->m_picpainter->paintEngine();

        // When newPage() is called and the m_picpainter is recreated
        // we have to copy the current state of the original printer
        // painter back to the m_picpainter
        d->m_picpainter->setPen(painter()->pen());
        d->m_picpainter->setBrush(painter()->brush());
        d->m_picpainter->setBrushOrigin(painter()->brushOrigin());
        d->m_picpainter->setFont(painter()->font());
        d->m_picpainter->setOpacity(painter()->opacity());
        d->m_picpainter->setTransform(painter()->combinedTransform());
        d->m_picengine->syncState();
    }
}
Esempio n. 29
0
void IconWidget::paintEvent(QPaintEvent *)
{
	QPainter painter(this);
	icon->paint(&painter, rect(), align, mode, state);
}
Esempio n. 30
0
void Graph::
paintEvent(QPaintEvent */*event*/)
{
    QPainter painter(this);

    QBrush brush;brush.setColor(QColor(250,50,50));
    painter.fillRect(0,0,width(),height(),brush);
    
    QPen pen;
    pen.setWidth(1);
    pen.setColor(QColor(210,210,255));
    painter.setPen(pen);

    float powerx=(int)floor(log(xmax-xmin)/log(logBase));
    float powery=(int)floor(log(ymax-ymin)/log(logBase));

    int powerOffsetSmall=4;
    int powerOffsetBig=1;
    drawX(painter,powerx-powerOffsetSmall);
    drawY(painter,powery-powerOffsetSmall);
    
    pen.setWidth(2);
    pen.setColor(QColor(200,200,255));
    painter.setPen(pen);

    drawX(painter,powerx-powerOffsetBig,false);
    drawY(painter,powery-powerOffsetBig,false);

    pen.setColor(Qt::black);
    painter.setPen(pen);
    drawX(painter,powerx-powerOffsetBig,true);
    drawY(painter,powery-powerOffsetBig,true);


    pen.setWidth(2);
    pen.setColor(QColor(50,100,200));
    painter.setPen(pen);
    float x1,y1,x2,y2;
    xform(0,ymin,x1,y1);
    xform(0,ymax,x2,y2);
    painter.drawLine(x1,y1,x2,y2);
    xform(xmin,0,x1,y1);
    xform(xmax,0,x2,y2);
    painter.drawLine(x1,y1,x2,y2);

   



    painter.setRenderHints(QPainter::Antialiasing);
    //for(int i=0;i<funcs.rowCount(QModelIndex());i++){
    //    plot(painter,i);
    //}

    for(unsigned int i=0;i<exprs.size();i++){
        plotNew(painter,i);
    }

    if(rootShow || minShow){
        pen.setColor(Qt::black);
        painter.setPen(pen);
        //std::cerr<<"drawing"<<std::endl;
        float dx,dy;
        xform(rootX,rootY,dx,dy);
        painter.drawEllipse(QPoint(dx,dy),3,3);
        QString text=QString("(%1,%2)").arg(rootX).arg(rootY);
        painter.drawText(QPoint(dx,dy),text);
    }


    if(minShow || operationCode==FIND_MIN || operationCode==FIND_MAX){
        QBrush brush(Qt::yellow);
        painter.setBrush(brush);
        //std::cerr<<"draw boundstart "<<boundStart<<" "<<boundEnd<<std::endl;
        xform(boundStart,ymin,x1,y1);
        xform(boundStart,ymax,x1,y2);
        xform(boundEnd,ymin,x2,y1);
        xform(boundEnd,ymax,x2,y2);
        //painter.drawLine(x1,y1,x1,y2);
        //painter.drawLine(x2,y1,x2,y2);
        painter.setOpacity(.2);
        painter.drawRect(x1,y1,x2-x1,y2-y1);
        painter.setOpacity(1);
    }

}