Exemplo n.º 1
0
void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile)
{
	int x = profilePlaceholder.x() - viewPort.x();
	int y = profilePlaceholder.y() - viewPort.y();
	// use the placeHolder and the viewPort position to calculate the relative position of the dive profile.
	QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
	profile->plotDive(dive, true);

	if (!printOptions->color_selected) {
		QImage image(pos.width(), pos.height(), QImage::Format_ARGB32);
		QPainter imgPainter(&image);
		imgPainter.setRenderHint(QPainter::Antialiasing);
		imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
		profile->render(&imgPainter, QRect(0, 0, pos.width(), pos.height()));
		imgPainter.end();

		// convert QImage to grayscale before rendering
		for (int i = 0; i < image.height(); i++) {
			QRgb *pixel = reinterpret_cast<QRgb *>(image.scanLine(i));
			QRgb *end = pixel + image.width();
			for (; pixel != end; pixel++) {
				int gray_val = qGray(*pixel);
				*pixel = QColor(gray_val, gray_val, gray_val).rgb();
			}
		}

		painter->drawImage(pos, image);
	} else {
		profile->render(painter, pos);
	}
}
Exemplo n.º 2
0
void KisColorSelector::paintEvent(QPaintEvent* /*event*/)
{
    // 0 red    -> (1,0,0)
    // 1 yellow -> (1,1,0)
    // 2 green  -> (0,1,0)
    // 3 cyan   -> (0,1,1)
    // 4 blue   -> (0,0,1)
    // 5 maenta -> (1,0,1)
    // 6 red    -> (1,0,0)
    
    m_renderBuffer.fill(0);
    
    QPainter imgPainter(&m_renderBuffer);
    QPainter wdgPainter(this);
    
    QRect fgRect(0, 0                  , QWidget::width(), QWidget::height()/2);
    QRect bgRect(0, QWidget::height()/2, QWidget::width(), QWidget::height()/2);
    wdgPainter.fillRect(fgRect, m_fgColor.getQColor());
    wdgPainter.fillRect(bgRect, m_bgColor.getQColor());
    
    for(int i=0; i<m_colorRings.size(); ++i)
        drawRing(imgPainter, m_colorRings[i], m_renderArea);
    
    wdgPainter.drawImage(m_renderArea, m_renderBuffer);
    
    drawOutline   (wdgPainter, m_renderArea);
    drawLightStrip(wdgPainter, m_lightStripArea);
}
void PaletteWidget2::paintEvent(QPaintEvent *event)
{
	// hint: use event->rect() to repaint small pieces (when single color is changed) if painting is slow

	QPainter painter(this);
	painter.setPen(Qt::NoPen);

	for(int i = 0; i < PALETTE_COLOR_COUNT; i++)
	{
		QImage img;
		if (i == selectedItem)
		{
			img = ColorWidget::getSelectedMask();
			QPainter imgPainter(&img);
			imgPainter.setCompositionMode(QPainter::CompositionMode_Multiply);
			imgPainter.fillRect(img.rect(), palette.getColor(i));	
		}
		else if (i == hoveredItem)
		{
			img = ColorWidget::getHoverMask();
			QPainter imgPainter(&img);
			imgPainter.setCompositionMode(QPainter::CompositionMode_DestinationAtop);
			imgPainter.fillRect(img.rect(), palette.getColor(i));
		}
		else 
		{
			img = ColorWidget::getNormalMask();
			QPainter imgPainter(&img);
			imgPainter.setCompositionMode(QPainter::CompositionMode_Multiply);
			imgPainter.fillRect(img.rect(), palette.getColor(i));
		}

		painter.drawImage(rects[i], img);
	}

	QImage img(":/MoodBox/Resources/palette_widget.png");
	painter.drawImage(0, 0, img);

	event->accept();

	QWidget::paintEvent(event);
}
Exemplo n.º 4
0
static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen)
{
    const qreal radiusBase = qMax(qreal(1), maxRadius);

    QString key = QLatin1String("WaveUnderline-Bauhaus");

    QPixmap pixmap;
    if (QPixmapCache::find(key, pixmap))
        return pixmap;

    const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio
    const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod);
    const int radius = qFloor(radiusBase);

    QPainterPath path;

    qreal xs = 0;
    qreal ys = radius;

    while (xs < width) {
        xs += halfPeriod;
        ys = -ys;
        path.quadTo(xs - halfPeriod / 2, ys, xs, 0);
    }

    pixmap = QPixmap(width, radius * 2);
    pixmap.fill(Qt::transparent);
    {
        QPen wavePen = pen;
        wavePen.setCapStyle(Qt::SquareCap);

        // This is to protect against making the line too fat, as happens on Mac OS X
        // due to it having a rather thick width for the regular underline.
        const qreal maxPenWidth = .8 * radius;
        if (wavePen.widthF() > maxPenWidth)
            wavePen.setWidth(maxPenWidth);

        QPainter imgPainter(&pixmap);
        imgPainter.setPen(wavePen);
        imgPainter.setRenderHint(QPainter::Antialiasing);
        imgPainter.translate(0, radius);
        imgPainter.drawPath(path);
    }

    QPixmapCache::insert(key, pixmap);

    return pixmap;
}
void QseVerticalAxisWidget::paintEvent(QPaintEvent */*event*/)
{
    if (isUpdateOnce() || m_cache.size() != size()) {
        // resize image, if needed
        if (size() != m_cache.size())
            m_cache = QImage(size(), QImage::Format_RGB32);

        // draw background
        QPainter imgPainter(&m_cache);
        imgPainter.fillRect(rect(), background());

        if (metricProvider())
            leftRightRender(&imgPainter);

        setUpdateOnce(false);
    }

    QPainter painter(this);
    painter.drawImage(rect(), m_cache);
}
Exemplo n.º 6
0
QPixmap AvatarButton::paintRoundBorder(QPixmap &userPicture, bool thumbnailMode, bool mouseIsHovered)
{
	// Paint round border for userpic
	QPixmap avatarMask;
	QIcon avatarBorder;
	QIcon userpic;

	if (thumbnailMode)
	{
		avatarMask.load(AVATAR_TRANSPARENCY_MASK_SMALL);
		if (mouseIsHovered)
			avatarBorder.addFile(AVATAR_HOVER_BORDER_SMALL);
		else
			avatarBorder.addFile(AVATAR_BORDER_SMALL);

		userpic.addPixmap(userPicture.scaled(USERPIC_SMALL_WIDTH - 4, USERPIC_SMALL_HEIGHT - 4, Qt::KeepAspectRatioByExpanding));
	}
	else
	{
		avatarMask.load(AVATAR_TRANSPARENCY_MASK_MAX);
		if (mouseIsHovered)
			avatarBorder.addFile(AVATAR_HOVER_BORDER_MAX);
		else
			avatarBorder.addFile(AVATAR_BORDER_MAX);

		userpic.addPixmap(userPicture.scaled(USERPIC_MAX_WIDTH - 2, USERPIC_MAX_HEIGHT - 2, Qt::KeepAspectRatioByExpanding));
	}
	
	QPainter imgPainter(&avatarMask);
	imgPainter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
	imgPainter.fillRect(avatarMask.rect(), QBrush(Qt::white));

	userpic.paint(&imgPainter, avatarMask.rect(), Qt::AlignCenter, QIcon::Normal);
	
	imgPainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
	avatarBorder.paint(&imgPainter, avatarMask.rect(), Qt::AlignCenter, QIcon::Normal);

	return avatarMask;
}
Exemplo n.º 7
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));
}
Exemplo n.º 8
0
void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
{
	int i, row = 0, col = 0, printed = 0, total = estimateTotalDives();
	int animationOriginal = prefs.animation_speed;

	struct dive *dive;
	if (!total)
		return;

	// disable animations on the profile:
	prefs.animation_speed = 0;

	// setup a painter
	QPainter painter;
	painter.begin(printer);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setRenderHint(QPainter::SmoothPixmapTransform);

	// setup the profile widget
	QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
	const int profileFrameStyle = profile->frameStyle();
	profile->setFrameStyle(QFrame::NoFrame);
	profile->setPrintMode(true, !printOptions->color_selected);
	profile->setFontPrintScale(divesPerRow * divesPerColumn > 3 ? 0.6 : 1.0);
	QSize originalSize = profile->size();
	// swap rows/col for landscape
	if (printer->orientation() == QPrinter::Landscape) {
		int swap = divesPerColumn;
		divesPerColumn = divesPerRow;
		divesPerRow = swap;
	}

	// padding in pixels between two dives. no padding if only one dive per page.
	const int padDef = 20;
	const int padW = (divesPerColumn < 2) ? 0 : padDef;
	const int padH = (divesPerRow < 2) ? 0 : padDef;
	// estimate dimensions for a single dive
	const int scaledW = ESTIMATE_DIVE_DIM(pageW, divesPerColumn, padW);
	const int scaledH = ESTIMATE_DIVE_DIM(pageH, divesPerRow, padH);
	// padding in pixels between profile and table
	const int padPT = 5;
	// create a model and table
	ProfilePrintModel model;
	model.setFontsize(7); // if this is changed we also need to change 'const int sr' in the constructor
	// if there is only one dive per page row we pass fitNotesToHeight to be almost half the page height
	QPointer<QTableView> table(createProfileTable(&model, scaledW, (divesPerRow == 1) ? scaledH * 0.45 : 0.0));
	// profilePrintTableMaxH updates after the table is created
	const int tableH = profilePrintTableMaxH;
	// resize the profile widget
	profile->resize(scaledW, scaledH - tableH - padPT);
	// offset table or profile on top
	int yOffsetProfile = 0, yOffsetTable = 0;
	if (printOptions->notes_up)
		yOffsetProfile = tableH + padPT;
	else
		yOffsetTable = scaledH - tableH;

	// plot the dives at specific rows and columns on the page
	for_each_dive (i, dive) {
		if (!dive->selected && printOptions->print_selected)
			continue;
		if (col == divesPerColumn) {
			col = 0;
			row++;
			if (row == divesPerRow) {
				row = 0;
				printer->newPage();
			}
		}
		// draw a profile
		QTransform origTransform = painter.transform();
		painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetProfile);
		profile->plotDive(dive, true); // make sure the profile is actually redrawn
#ifdef Q_OS_LINUX // on Linux there is a vector line bug (big lines in PDF), which forces us to render to QImage
		QImage image(scaledW, scaledH - tableH - padPT, QImage::Format_ARGB32);
		QPainter imgPainter(&image);
		imgPainter.setRenderHint(QPainter::Antialiasing);
		imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
		profile->render(&imgPainter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
		imgPainter.end();
		painter.drawImage(image.rect(),image);
#else // for other OS we can try rendering the profile as vector
		profile->render(&painter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
#endif
		painter.setTransform(origTransform);

		// draw a table
		QPicture pic;
		QPainter picPainter;
		painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetTable);
		model.setDive(dive);
		picPainter.begin(&pic);
		table->render(&picPainter);
		picPainter.end();
		painter.drawPicture(QPoint(0,0), pic);
		painter.setTransform(origTransform);
		col++;
		printed++;
		emit signalProgress((printed * 100) / total);
	}
	// cleanup
	painter.end();
	profile->setFrameStyle(profileFrameStyle);
	profile->setPrintMode(false);
	profile->resize(originalSize);
	// we need to force a redraw of the profile so it switches back from print mode
	profile->plotDive(0, true);
	// re-enable animations
	prefs.animation_speed = animationOriginal;
}