Exemplo n.º 1
0
void MarbleWidget::paintEvent( QPaintEvent *evt )
{
    QTime t;
    t.start();

    QPaintDevice *paintDevice = this;
    QImage image;
    if (!isEnabled())
    {
        // If the globe covers fully the screen then we can use the faster
        // RGB32 as there are no translucent areas involved.
        QImage::Format imageFormat = ( d->map()->viewport()->mapCoversViewport() )
                                     ? QImage::Format_RGB32
                                     : QImage::Format_ARGB32_Premultiplied;
        // Paint to an intermediate image
        image = QImage( rect().size(), imageFormat );
        image.fill( Qt::transparent );
        paintDevice = ℑ
    }

    {
        // FIXME: Better way to get the GeoPainter
        // Create a painter that will do the painting.
        GeoPainter geoPainter( paintDevice, d->map()->viewport(), d->map()->mapQuality() );

        d->map()->paint( geoPainter, evt->rect() );
    }

    if ( !isEnabled() )
    {
        // Draw a grayscale version of the intermediate image
        QRgb* pixel = reinterpret_cast<QRgb*>( image.scanLine( 0 ));
        for (int i=0; i<image.width()*image.height(); ++i, ++pixel) {
            int gray = qGray( *pixel );
            *pixel = qRgb( gray, gray, gray );
        }

        QPainter widgetPainter( this );
        widgetPainter.drawImage( rect(), image );
    }

    if ( d->m_showFrameRate )
    {
        QPainter painter( this );
        FpsLayer fpsPainter( &t );
        fpsPainter.paint( &painter );

        const qreal fps = 1000.0 / (qreal)( t.elapsed() + 1 );
        emit framesPerSecond( fps );
    }
}
Exemplo n.º 2
0
    void paintEvent(QPaintEvent *)
    {
        QSize layoutSize(75, 75);

        QPainter widgetPainter(this);
        widgetPainter.fillRect(QRect(QPoint(0, 0), this->size()), Qt::gray);

        {
            const qreal devicePixelRatio = this->windowHandle()->devicePixelRatio();
            QPixmap cache(layoutSize * devicePixelRatio);
            cache.setDevicePixelRatio(devicePixelRatio);

            QPainter cachedPainter(&cache);
            cachedPainter.fillRect(QRect(0,0, 75, 75), Qt::blue);
            cachedPainter.fillRect(QRect(10,10, 55, 55), Qt::red);
            cachedPainter.drawEllipse(QRect(10,10, 55, 55));

            QPainter widgetPainter(this);
            widgetPainter.drawPixmap(QPoint(10, 10), cache);
        }

        {
            const qreal devicePixelRatio = this->windowHandle()->devicePixelRatio();
            QImage cache = QImage(layoutSize * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
            cache.setDevicePixelRatio(devicePixelRatio);

            QPainter cachedPainter(&cache);
            cachedPainter.fillRect(QRect(0,0, 75, 75), Qt::blue);
            cachedPainter.fillRect(QRect(10,10, 55, 55), Qt::red);
            cachedPainter.drawEllipse(QRect(10,10, 55, 55));

            QPainter widgetPainter(this);
            widgetPainter.drawImage(QPoint(95, 10), cache);
        }

    }
Exemplo n.º 3
0
void TextureDisplay::paintEvent(QPaintEvent *event) {
    QPainter widgetPainter(this);
    QPen pen;
    pen.setWidth(1);
    pen.setColor(QColor(0, 255, 0));
    widgetPainter.setPen(pen);

    image = image.scaledToWidth(WIDTH);
    widgetPainter.drawImage(image_x, image_y, image);
    widgetPainter.drawLine(params.center_of_rotation*WIDTH, 0,params.center_of_rotation*WIDTH, HEIGHT);
    pen.setColor(QColor(0,0,255));
    widgetPainter.setPen(pen);
    widgetPainter.drawLine(0, params.top_crop*HEIGHT,WIDTH, params.top_crop*HEIGHT);
    widgetPainter.drawLine(0, HEIGHT-(params.bottom_crop*HEIGHT)-1,WIDTH,HEIGHT-(params.bottom_crop*HEIGHT)-1);
    widgetPainter.end();
    return;
}
Exemplo n.º 4
0
void RatingWidget::paintEvent(QPaintEvent *event)
{
	QPainter imagePainter(&image);
	QPainter widgetPainter(this);

	for (int i = 0; i < 5; i++) {
		if (i < rating) {
			QRect target((i +1) * 20 +2, 2, 16, 16);
			QRect source(0, 0, 16, 16);
			imagePainter.drawImage(target, starOn, source);
		} else {
			QRect target((i +1) * 20 +2, 2, 16, 16);
			QRect source(0, 0, 16, 16);
			imagePainter.drawImage(target, starOff, source);
		}
	}

	QRect dirtyRect = event->rect();
	widgetPainter.drawImage(dirtyRect, image, dirtyRect);
}
Exemplo n.º 5
0
void Tab::paintEvent(QPaintEvent *event)
{
	QImage image(QSize(150,20), QImage::Format_ARGB32_Premultiplied);
	QPainter painter(&image);
	painter.setRenderHint(QPainter::Antialiasing, true);
	painter.setPen(QPen(Qt::black,1, Qt::SolidLine, Qt::RoundCap));
	QLinearGradient gradient(0,0,0,20);
	if(index == currentTab) //means that the tab is selected
	{
		gradient.setColorAt(0.0, Qt::white);
		gradient.setColorAt(0.3, Qt::white);
		gradient.setColorAt(1.0, QColor("#FF925F"));
	}
	else
	{
		gradient.setColorAt(0.0, Qt::white);
		gradient.setColorAt(1.0, QColor("#AAAAAA"));
	}
	painter.setBrush(gradient);
	painter.drawRoundedRect(0,0,150,20,5,5);

	QLinearGradient loadGradient(0,0,0,20);

	if(loading)
	{
		loadGradient.setColorAt(0.0, QColor("#EEFFEE"));
		loadGradient.setColorAt(1.0, QColor("#44EE44"));
		painter.setBrush(loadGradient);
		painter.setPen(QPen(Qt::black,0.5, Qt::SolidLine, Qt::RoundCap));
		painter.drawRoundedRect(0,0,(150*LoadProgress/100),20,5,5);
	}

//	painter.setPen(QPen(Qt::black,1, Qt::SolidLine, Qt::RoundCap));
	if(!mouseOverIcon)
	{
		if(iconSet)
		{
			painter.drawPixmap(2,2,icon);
		}
		else
		{
			painter.drawPixmap(2,2,QPixmap(":/icons/arrow-down.png").scaled(16,16));
		}
	}
	else
	{
		painter.drawPixmap(2,2,QPixmap(":/icons/arrow-down.png").scaled(16,16));
	}

	if(textSet)
	{
		painter.drawText(24,1,120,20, Qt::AlignLeft, text);
	}
	else
	{
		painter.drawText(24,1,120,20, Qt::AlignLeft, tr("Untitled")); //24,2,120,20
	}
	painter.end();
	QPainter widgetPainter(this);
	widgetPainter.drawImage(0,0,image);
}