Пример #1
0
Q_GUI_EXPORT QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
{
    // If the margins have the same units, or are all 0, then don't need to convert
    if (fromUnits == toUnits || margins.isNull())
        return margins;

    // If converting to points then convert and round to 0 decimal places
    if (toUnits == QPageLayout::Point) {
        const qreal multiplier = qt_pointMultiplier(fromUnits);
        return QMarginsF(qRound(margins.left() * multiplier),
                         qRound(margins.top() * multiplier),
                         qRound(margins.right() * multiplier),
                         qRound(margins.bottom() * multiplier));
    }

    // If converting to other units, need to convert to unrounded points first
    QMarginsF pointMargins = fromUnits == QPageLayout::Point ? margins : margins * qt_pointMultiplier(fromUnits);

    // Then convert from points to required units rounded to 2 decimal places
    const qreal multiplier = qt_pointMultiplier(toUnits);
    return QMarginsF(qRound(pointMargins.left() * 100 / multiplier) / 100.0,
                     qRound(pointMargins.top() * 100 / multiplier) / 100.0,
                     qRound(pointMargins.right() * 100 / multiplier) / 100.0,
                     qRound(pointMargins.bottom() * 100 / multiplier) / 100.0);
}
Пример #2
0
QMarginsF PageMetrics::pxPageMargins() const
{
	return QMarginsF(m_pxPageMargins.left(),
					 m_pxPageMargins.top(),
					 m_pxPageMargins.right(),
					 m_pxPageMargins.bottom());
}
Пример #3
0
void QPpdPrintDevice::loadPageSizes() const
{
    m_pageSizes.clear();
    m_printableMargins.clear();

    ppd_option_t *pageSizes = ppdFindOption(m_ppd, "PageSize");
    if (pageSizes) {
        for (int i = 0; i < pageSizes->num_choices; ++i) {
            const ppd_size_t *ppdSize = ppdPageSize(m_ppd, pageSizes->choices[i].choice);
            if (ppdSize) {
                // Returned size is in points
                QString key = QString::fromUtf8(ppdSize->name);
                QSize size = QSize(qRound(ppdSize->width), qRound(ppdSize->length));
                QString name = QString::fromUtf8(pageSizes->choices[i].text);
                if (!size.isEmpty()) {
                    QPageSize ps = createPageSize(key, size, name);
                    if (ps.isValid()) {
                        m_pageSizes.append(ps);
                        m_printableMargins.insert(key, QMarginsF(ppdSize->left, ppdSize->length - ppdSize->top,
                                                                 ppdSize->width - ppdSize->right, ppdSize->bottom));
                    }
                }
            }
        }
        m_havePageSizes = true;
    }
}
Пример #4
0
void QPageLayoutPrivate::clampMargins(const QMarginsF &margins)
{
    m_margins = QMarginsF(qBound(m_minMargins.left(),   margins.left(),   m_maxMargins.left()),
                          qBound(m_minMargins.top(),    margins.top(),    m_maxMargins.top()),
                          qBound(m_minMargins.right(),  margins.right(),  m_maxMargins.right()),
                          qBound(m_minMargins.bottom(), margins.bottom(), m_maxMargins.bottom()));
}
Пример #5
0
QRectF PipelineFlowChart::totalAreaRect()
{
  QRectF rect = this->rect();

  qreal m = 6 + BoxBorderWidth;

  return rect.marginsRemoved(QMarginsF(m, m, m, m));
}
Пример #6
0
void QPageLayoutPrivate::setDefaultMargins(const QMarginsF &minMargins)
{
    m_minMargins = minMargins;
    m_maxMargins = QMarginsF(m_fullSize.width() - m_minMargins.right(),
                             m_fullSize.height() - m_minMargins.bottom(),
                             m_fullSize.width() - m_minMargins.left(),
                             m_fullSize.height() - m_minMargins.top());
    if (m_mode == QPageLayout::StandardMode)
        clampMargins(m_margins);
}
Пример #7
0
void ArcStyle::paint(QPainter *painter)
{
    static const qreal m = 1.5;
    painter->setPen(Qt::NoPen);
    painter->setBrush(m_color);
    painter->drawPie(boundingRect().marginsRemoved(QMarginsF(m,m,m,m)), -m_startAngle, -m_spanAngle);
    qreal w = (width()/3.0)-1.0;
    painter->setBrush(Qt::white);
    painter->drawEllipse(boundingRect().center(),w,w);
}
Пример #8
0
void Stack::initPrinter()
{
	if (m_printer) {
		return;
	}

	m_printer = new QPrinter(QPrinter::HighResolution);
	m_printer->setPageSize(QPageSize(QPageSize::Letter));
	m_printer->setPageOrientation(QPageLayout::Portrait);
	m_printer->setPageMargins(QMarginsF(1.0, 1.0, 1.0, 1.0), QPageLayout::Inch);
}
Пример #9
0
void Board::paintPoint(Point point, int index) {
    QRectF rect = Locator<Grid>()->getGridRect(point);
    qreal margin = Locator<Grid>()->getGridSize() * (1 - common::predefinedSize::CircleSizeOverGridSize);
    auto margins = QMarginsF(margin, margin, margin, margin);
    QRectF rectShrinked = rect.marginsRemoved(margins);
    auto circle = new QGraphicsEllipseItem(rectShrinked);
    auto itemID = common::VisibleItemID::Circle;
    QColor color = common::getColor(itemID, index);
    circle->setZValue(itemID);
    circle->setPen(Qt::NoPen);
    circle->setBrush(QBrush(color));
    itemList->addItem(circle);
}
Пример #10
0
void Checkbox::paintEvent(QPaintEvent *e) {
	Painter p(this);

	float64 over = a_over.current(), checked = a_checked.current();
	bool cnone = (over == 0. && checked == 0.), cover = (over == 1. && checked == 0.), cchecked = (checked == 1.);
	bool cbad = !cnone && !cover && !cchecked;
	QColor color;
	if (cbad) {
		float64 onone = (1. - over) * (1. - checked), oover = over * (1. - checked), ochecked = checked;
		color.setRedF(_st.checkFg->c.redF() * onone + _st.checkFgOver->c.redF() * oover + _st.checkFgActive->c.redF() * ochecked);
		color.setGreenF(_st.checkFg->c.greenF() * onone + _st.checkFgOver->c.greenF() * oover + _st.checkFgActive->c.greenF() * ochecked);
		color.setBlueF(_st.checkFg->c.blueF() * onone + _st.checkFgOver->c.blueF() * oover + _st.checkFgActive->c.blueF() * ochecked);
	}

	QRect r(e->rect());
	p.setClipRect(r);
	p.fillRect(r, _st.textBg->b);
	if (_checkRect.intersects(r)) {
		p.setRenderHint(QPainter::HighQualityAntialiasing);

		QPen pen;
		if (cbad) {
			pen = QPen(color);
		} else {
			pen = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->p;
			color = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->c;
		}
		pen.setWidth(_st.thickness);
		p.setPen(pen);
		if (checked > 0) {
			color.setRedF(color.redF() * checked + st::white->c.redF() * (1. - checked));
			color.setGreenF(color.greenF() * checked + st::white->c.greenF() * (1. - checked));
			color.setBlueF(color.blueF() * checked + st::white->c.blueF() * (1. - checked));
			p.setBrush(color);
		} else {
			p.setBrush(st::white);
		}
		p.drawRoundedRect(QRectF(_checkRect).marginsRemoved(QMarginsF(_st.thickness / 2, _st.thickness / 2, _st.thickness / 2, _st.thickness / 2)), st::msgRadius, st::msgRadius);
		p.setRenderHint(QPainter::HighQualityAntialiasing, false);

		if (checked > 0) {
			p.drawSpriteCenter(_checkRect, _st.checkIcon);
		}
	}
	if (_checkRect.contains(r)) return;

	p.setPen(_st.textFg);
	p.setFont(_st.font);
	p.drawTextLeft(_st.textPosition.x(), _st.textPosition.y(), width(), _text, _textWidth);
}
Пример #11
0
void Stack::initPrinter()
{
	if (m_printer) {
		return;
	}

	m_printer = new QPrinter(QPrinter::HighResolution);
#if (QT_VERSION >= QT_VERSION_CHECK(5,3,0))
	m_printer->setPageSize(QPageSize(QPageSize::Letter));
	m_printer->setPageOrientation(QPageLayout::Portrait);
	m_printer->setPageMargins(QMarginsF(1.0, 1.0, 1.0, 1.0), QPageLayout::Inch);
#else
	m_printer->setPageSize(QPrinter::Letter);
	m_printer->setOrientation(QPrinter::Portrait);
	m_printer->setPageMargins(1.0, 1.0, 1.0, 1.0, QPrinter::Inch);
#endif
}
Пример #12
0
void Document::exportPDF(QString fileName)
{
  //    QPdfWriter pdfWriter("/Users/tom/Desktop/qpdfwriter.pdf");
  //    QPdfWriter pdfWriter(fileName);

  QPrinter pdfWriter(QPrinter::HighResolution);
  pdfWriter.setOutputFormat(QPrinter::PdfFormat);
  pdfWriter.setOutputFileName(fileName);
  //    pdfWriter.setMargins();

  pdfWriter.setPageSize(QPageSize(QSizeF(pages[0].width(), pages[0].height()), QPageSize::Point));
  pdfWriter.setPageMargins(QMarginsF(0, 0, 0, 0));
  qreal zoomW = ((qreal)pdfWriter.pageRect().width()) / ((qreal)pdfWriter.paperRect().width());
  qreal zoomH = ((qreal)pdfWriter.pageRect().height()) / ((qreal)pdfWriter.paperRect().height());
  qreal zoom = zoomW;
  if (zoomH < zoomW)
    zoom = zoomH;
  pdfWriter.setResolution(72);
  pdfWriter.pageLayout().setUnits(QPageLayout::Point);
  QPainter painter;

  //    std::cout << "PDF " << pdfWriter.colorCount() << std::endl;

  painter.begin(&pdfWriter);
  painter.setRenderHint(QPainter::Antialiasing, true);
  for (int pageNum = 0; pageNum < pages.size(); ++pageNum)
  {
    if (pages[pageNum].backgroundColor() != QColor("white"))
    {
      QRectF pageRect = pdfWriter.pageRect(QPrinter::Point);
      pageRect.translate(-pageRect.topLeft());
      painter.fillRect(pageRect, pages[pageNum].backgroundColor());
    }
    pages[pageNum].paint(painter, zoom, QRect(0, 0, 0, 0));

    if (pageNum + 1 < pages.size())
    {
      pdfWriter.setPageSize(QPageSize(QSize(pages[pageNum + 1].width(), pages[pageNum + 1].height())));
      pdfWriter.newPage();
    }
  }
  painter.end();
}
Пример #13
0
void PageMetrics::update(QPageSize::PageSizeId _pageFormat, QMarginsF _mmPageMargins)
{
	m_pageFormat = _pageFormat;

	m_mmPageSize = QPageSize(m_pageFormat).rect(QPageSize::Millimeter).size();
	m_mmPageMargins = _mmPageMargins;

	//
	// Рассчитываем значения в пикселах
	//
	const bool x = true, y = false;
	m_pxPageSize =
			QSizeF(mmToPx(m_mmPageSize.width(), x),
				   mmToPx(m_mmPageSize.height(), y));
	m_pxPageMargins =
			QMarginsF(mmToPx(m_mmPageMargins.left(), x),
					  mmToPx(m_mmPageMargins.top(), y),
					  mmToPx(m_mmPageMargins.right(), x),
					  mmToPx(m_mmPageMargins.bottom(), y)
					  );
}
Пример #14
0
void NodeLabel::updateStyle()
{
    prepareGeometryChange();
    // update the text position
    m_text.prepare(QTransform(), s_font);
    QSizeF textSize = m_text.size();
    m_textPos = QPointF(textSize.width() / -2., textSize.height() / -2.);
    // update the label
    QSizeF labelSize =
        QSizeF(qMax(textSize.width(), Node::getCoreRadius() * 2.),
               textSize.height());
    m_outlineRect =
        QRectF((labelSize.width() / -2.) - s_horizontalMargin,
               m_textPos.y() - s_verticalMargin,
               labelSize.width() + (s_horizontalMargin * 2.),
               textSize.height() + (s_verticalMargin * 2.));
    // update bounding rectangle
    qreal halfLine = s_outlineWidth * 0.5;
    m_boundingRect =
        m_outlineRect.
        marginsAdded(QMarginsF(halfLine, halfLine, halfLine, halfLine));
    update();
}
Пример #15
0
QPpdPrintDevice::QPpdPrintDevice(const QString &id)
    : QPlatformPrintDevice(id),
      m_cupsDest(0),
      m_ppd(0)
{
    if (!id.isEmpty()) {

        // TODO For now each dest is an individual device
        QStringList parts = id.split(QLatin1Char('/'));
        m_cupsName = parts.at(0).toUtf8();
        if (parts.size() > 1)
            m_cupsInstance = parts.at(1).toUtf8();
        loadPrinter();

        if (m_cupsDest && m_ppd) {
            m_name = printerOption("printer-info");
            m_location = printerOption("printer-location");
            m_makeAndModel = printerOption("printer-make-and-model");
            cups_ptype_e type = printerTypeFlags();
            m_isRemote = type & CUPS_PRINTER_REMOTE;
            // Note this is if the hardware does multiple copies, not if Cups can
            m_supportsMultipleCopies = type & CUPS_PRINTER_COPIES;
            // Note this is if the hardware does collation, not if Cups can
            m_supportsCollateCopies = type & CUPS_PRINTER_COLLATE;

            // Custom Page Size support
            // Cups cups_ptype_e CUPS_PRINTER_VARIABLE
            // Cups ppd_file_t variable_sizes custom_min custom_max
            // PPD MaxMediaWidth MaxMediaHeight
            m_supportsCustomPageSizes = type & CUPS_PRINTER_VARIABLE;
            m_minimumPhysicalPageSize = QSize(m_ppd->custom_min[0], m_ppd->custom_min[1]);
            m_maximumPhysicalPageSize = QSize(m_ppd->custom_max[0], m_ppd->custom_max[1]);
            m_customMargins = QMarginsF(m_ppd->custom_margins[0], m_ppd->custom_margins[3],
                                        m_ppd->custom_margins[2], m_ppd->custom_margins[1]);
        }
    }
}
Пример #16
0
void tst_QPdfWriter::basics()
{
    QTemporaryFile file;
    if (!file.open())
        QSKIP("Couldn't open temp file!");
    QPdfWriter writer(file.fileName());

    QCOMPARE(writer.title(), QString());
    writer.setTitle(QString("Test Title"));
    QCOMPARE(writer.title(), QString("Test Title"));

    QCOMPARE(writer.creator(), QString());
    writer.setCreator(QString("Test Creator"));
    QCOMPARE(writer.creator(), QString("Test Creator"));

    QCOMPARE(writer.resolution(), 1200);
    writer.setResolution(600);
    QCOMPARE(writer.resolution(), 600);

    QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
    QCOMPARE(writer.pageSize(), QPdfWriter::A4);
    QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));

    writer.setPageSize(QPageSize(QPageSize::A5));
    QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A5);
    QCOMPARE(writer.pageSize(), QPdfWriter::A5);
    QCOMPARE(writer.pageSizeMM(), QSizeF(148, 210));

    writer.setPageSize(QPdfWriter::A3);
    QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3);
    QCOMPARE(writer.pageSize(), QPdfWriter::A3);
    QCOMPARE(writer.pageSizeMM(), QSizeF(297, 420));

    writer.setPageSizeMM(QSize(210, 297));
    QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
    QCOMPARE(writer.pageSize(), QPdfWriter::A4);
    QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));

    QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait);
    writer.setPageOrientation(QPageLayout::Landscape);
    QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape);
    QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));

    QCOMPARE(writer.pageLayout().margins(), QMarginsF(10, 10, 10, 10));
    QCOMPARE(writer.pageLayout().units(), QPageLayout::Point);
    QCOMPARE(writer.margins().left, 3.53);  // mm
    QCOMPARE(writer.margins().right, 3.53);
    QCOMPARE(writer.margins().top, 3.53);
    QCOMPARE(writer.margins().bottom, 3.53);
    writer.setPageMargins(QMarginsF(20, 20, 20, 20), QPageLayout::Millimeter);
    QCOMPARE(writer.pageLayout().margins(), QMarginsF(20, 20, 20, 20));
    QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter);
    QCOMPARE(writer.margins().left, 20.0);
    QCOMPARE(writer.margins().right, 20.0);
    QCOMPARE(writer.margins().top, 20.0);
    QCOMPARE(writer.margins().bottom, 20.0);
    QPdfWriter::Margins margins = {50, 50, 50, 50};
    writer.setMargins(margins);
    QCOMPARE(writer.pageLayout().margins(), QMarginsF(50, 50, 50, 50));
    QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter);
    QCOMPARE(writer.margins().left, 50.0);
    QCOMPARE(writer.margins().right, 50.0);
    QCOMPARE(writer.margins().top, 50.0);
    QCOMPARE(writer.margins().bottom, 50.0);

    QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
    QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(50, 50, 197, 110));
}
Пример #17
0
void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
{
    Q_D(QPdfPrintEngine);

    switch (int(key)) {

    // The following keys are properties or derived values and so cannot be set
    case PPK_PageRect:
        break;
    case PPK_PaperRect:
        break;
    case PPK_PaperSources:
        break;
    case PPK_SupportsMultipleCopies:
        break;
    case PPK_SupportedResolutions:
        break;

    // The following keys are settings that are unsupported by the PDF PrintEngine
    case PPK_CustomBase:
        break;

    // The following keys are properties and settings that are supported by the PDF PrintEngine
    case PPK_CollateCopies:
        d->collate = value.toBool();
        break;
    case PPK_ColorMode:
        d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale);
        break;
    case PPK_Creator:
        d->creator = value.toString();
        break;
    case PPK_DocumentName:
        d->title = value.toString();
        break;
    case PPK_FullPage:
        if (value.toBool())
            d->m_pageLayout.setMode(QPageLayout::FullPageMode);
        else
            d->m_pageLayout.setMode(QPageLayout::StandardMode);
        break;
    case PPK_CopyCount: // fallthrough
    case PPK_NumberOfCopies:
        d->copies = value.toInt();
        break;
    case PPK_Orientation:
        d->m_pageLayout.setOrientation(QPageLayout::Orientation(value.toInt()));
        break;
    case PPK_OutputFileName:
        d->outputFileName = value.toString();
        break;
    case PPK_PageOrder:
        d->pageOrder = QPrinter::PageOrder(value.toInt());
        break;
    case PPK_PageSize: {
        QPageSize pageSize = QPageSize(QPageSize::PageSizeId(value.toInt()));
        if (pageSize.isValid())
            d->m_pageLayout.setPageSize(pageSize);
        break;
    }
    case PPK_PaperName: {
        QString name = value.toString();
        for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
            QPageSize pageSize = QPageSize(QPageSize::PageSizeId(i));
            if (name == pageSize.name()) {
                d->m_pageLayout.setPageSize(pageSize);
                break;
            }
        }
        break;
    }
    case PPK_WindowsPageSize:
        d->m_pageLayout.setPageSize(QPageSize(QPageSize::id(value.toInt())));
        break;
    case PPK_PaperSource:
        d->paperSource = QPrinter::PaperSource(value.toInt());
        break;
    case PPK_PrinterName:
        d->printerName = value.toString();
        break;
    case PPK_PrinterProgram:
        d->printProgram = value.toString();
        break;
    case PPK_Resolution:
        d->resolution = value.toInt();
        break;
    case PPK_SelectionOption:
        d->selectionOption = value.toString();
        break;
    case PPK_FontEmbedding:
        d->embedFonts = value.toBool();
        break;
    case PPK_Duplex:
        d->duplex = static_cast<QPrint::DuplexMode>(value.toInt());
        break;
    case PPK_CustomPaperSize:
        d->m_pageLayout.setPageSize(QPageSize(value.toSizeF(), QPageSize::Point));
        break;
    case PPK_PageMargins: {
        QList<QVariant> margins(value.toList());
        Q_ASSERT(margins.size() == 4);
        d->m_pageLayout.setUnits(QPageLayout::Point);
        d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
                                             margins.at(2).toReal(), margins.at(3).toReal()));
        break;
    }
    case PPK_QPageSize: {
        QPageSize pageSize = value.value<QPageSize>();
        if (pageSize.isValid())
            d->m_pageLayout.setPageSize(pageSize);
        break;
    }
    case PPK_QPageMargins: {
        QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
        d->m_pageLayout.setUnits(pair.second);
        d->m_pageLayout.setMargins(pair.first);
        break;
    }
    case PPK_QPageLayout: {
        QPageLayout pageLayout = value.value<QPageLayout>();
        if (pageLayout.isValid())
            d->m_pageLayout = pageLayout;
        break;
    }
    // No default so that compiler will complain if new keys added and not handled in this engine
    }
}
Пример #18
0
QRectF GraphicsBoard::boundingRect() const
{
	const auto margins = QMarginsF(m_coordSize, m_coordSize,
				       m_coordSize, m_coordSize);
	return m_rect.marginsAdded(margins);
}
Пример #19
0
QMarginsF QPrintDevice::printableMargins(const QPageSize &pageSize,
                                         QPageLayout::Orientation orientation,
                                         int resolution) const
{
    return isValid() ? d->printableMargins(pageSize, orientation, resolution) : QMarginsF();
}
/*!
  Sets the margins to be used to \a margins.

  Margins are specified in millimeters.

  The margins are purely a hint to the drawing method. They don't affect the
  coordinate system or clipping.

  \sa margins()
  */
void QPagedPaintDevice::setMargins(const Margins &margins)
{
    d->m_pageLayout.setUnits(QPageLayout::Millimeter);
    d->m_pageLayout.setMargins(QMarginsF(margins.left, margins.top, margins.right, margins.bottom));
}
Пример #21
0
void Radiobutton::paintEvent(QPaintEvent *e) {
	Painter p(this);

	float64 over = a_over.current(), checked = a_checked.current();
	bool cnone = (over == 0. && checked == 0.), cover = (over == 1. && checked == 0.), cchecked = (checked == 1.);
	bool cbad = !cnone && !cover && !cchecked;
	QColor color;
	if (cbad) {
		float64 onone = (1. - over) * (1. - checked), oover = over * (1. - checked), ochecked = checked;
		color.setRedF(_st.checkFg->c.redF() * onone + _st.checkFgOver->c.redF() * oover + _st.checkFgActive->c.redF() * ochecked);
		color.setGreenF(_st.checkFg->c.greenF() * onone + _st.checkFgOver->c.greenF() * oover + _st.checkFgActive->c.greenF() * ochecked);
		color.setBlueF(_st.checkFg->c.blueF() * onone + _st.checkFgOver->c.blueF() * oover + _st.checkFgActive->c.blueF() * ochecked);
	}

	QRect r(e->rect());
	p.setClipRect(r);
	p.fillRect(r, _st.textBg->b);
	if (_checkRect.intersects(r)) {
		p.setRenderHint(QPainter::HighQualityAntialiasing);

		QPen pen;
		if (cbad) {
			pen = QPen(color);
		} else {
			pen = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->p;
		}
		pen.setWidth(_st.thickness);
		p.setPen(pen);
		p.setBrush(Qt::NoBrush);
		//int32 skip = qCeil(_st.thickness / 2);
		//p.drawEllipse(_checkRect.marginsRemoved(QMargins(skip, skip, skip, skip)));
		p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(_st.thickness / 2, _st.thickness / 2, _st.thickness / 2, _st.thickness / 2)));

		if (checked > 0) {
			p.setPen(Qt::NoPen);
			if (cbad) {
				p.setBrush(color);
			} else {
				p.setBrush(cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive));
			}
			float64 skip0 = _checkRect.width() / 2., skip1 = _st.checkSkip / 10., checkSkip = skip0 * (1. - checked) + skip1 * checked;
			p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)));
			//int32 fskip = qFloor(checkSkip), cskip = qCeil(checkSkip);
			//if (2 * fskip < _checkRect.width()) {
			//	if (fskip != cskip) {
			//		p.setOpacity(float64(cskip) - checkSkip);
			//		p.drawEllipse(_checkRect.marginsRemoved(QMargins(fskip, fskip, fskip, fskip)));
			//		p.setOpacity(1.);
			//	}
			//	if (2 * cskip < _checkRect.width()) {
			//		p.drawEllipse(_checkRect.marginsRemoved(QMargins(cskip, cskip, cskip, cskip)));
			//	}
			//}
		}

		p.setRenderHint(QPainter::HighQualityAntialiasing, false);
	}
	if (_checkRect.contains(r)) return;

	p.setPen(_st.textFg);
	p.setFont(_st.font);
	p.drawTextLeft(_st.textPosition.x(), _st.textPosition.y(), width(), _text, _textWidth);
}
Пример #22
0
QMarginsF uniformMargins(qreal m)
{
  return QMarginsF(m, m, m, m);
}
Пример #23
0
void TimelineBar::paintEvent(QPaintEvent *e)
{
  QPainter p(viewport());

  p.setFont(font());
  p.setRenderHint(QPainter::TextAntialiasing);

  // draw boundaries and background
  {
    QRectF r = viewport()->rect();

    p.fillRect(r, palette().brush(QPalette::Window));

    r = r.marginsRemoved(QMargins(borderWidth + margin, borderWidth + margin, borderWidth + margin,
                                  borderWidth + margin));

    p.fillRect(r, palette().brush(QPalette::Base));
    p.drawRect(r);
  }

  QTextOption to;

  to.setWrapMode(QTextOption::NoWrap);
  to.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);

  QFontMetrics fm = p.fontMetrics();

  {
    QRectF titleRect = m_eidAxisRect;
    titleRect.setLeft(titleRect.left() - m_titleWidth);
    titleRect.setWidth(m_titleWidth);

    p.setPen(QPen(palette().brush(QPalette::Text), 1.0));

    // add an extra margin for the text
    p.drawText(titleRect.marginsRemoved(QMarginsF(margin, 0, 0, 0)), eidAxisTitle, to);

    titleRect.setLeft(titleRect.left() - margin);
    titleRect.setTop(titleRect.top() - margin);
    p.drawLine(titleRect.bottomLeft(), titleRect.bottomRight());
    p.drawLine(titleRect.topRight(), titleRect.bottomRight());
  }

  QRectF eidAxisRect = m_eidAxisRect;

  p.drawLine(eidAxisRect.bottomLeft(), eidAxisRect.bottomRight() + QPointF(margin, 0));

  p.drawLine(m_highlightingRect.topLeft(), m_highlightingRect.topRight());

  if(m_Draws.isEmpty())
    return;

  eidAxisRect.setLeft(m_eidAxisRect.left() + m_pan);

  uint32_t maxEID = m_Draws.isEmpty() ? 0 : m_Draws.back();

  to.setAlignment(Qt::AlignCenter | Qt::AlignVCenter);

  p.setFont(Formatter::PreferredFont());

  QRectF hoverRect = eidAxisRect;

  // clip labels to the visible section
  p.setClipRect(m_eidAxisRect.marginsAdded(QMargins(0, margin, margin, 0)));

  // draw where we're hovering
  {
    QPoint pos = viewport()->mapFromGlobal(QCursor::pos());

    if(m_dataArea.contains(pos))
    {
      uint32_t hoverEID = eventAt(pos.x());

      hoverRect.setLeft(offsetOf(hoverEID));
      hoverRect.setWidth(m_eidAxisLabelWidth);

      // recentre
      hoverRect.moveLeft(hoverRect.left() - m_eidAxisLabelWidth / 2 + m_eidWidth / 2);

      QColor backCol = palette().color(QPalette::Base);

      if(getLuminance(backCol) < 0.2f)
        backCol = backCol.lighter(120);
      else
        backCol = backCol.darker(120);

      QRectF backRect = hoverRect.marginsAdded(QMargins(0, margin - borderWidth, 0, 0));

      backRect.setLeft(qMax(backRect.left(), m_eidAxisRect.left() + 1));

      p.fillRect(backRect, backCol);

      p.drawText(hoverRect, QString::number(hoverEID), to);

      // re-add the top margin so the lines match up with the border around the EID axis
      hoverRect = hoverRect.marginsAdded(QMargins(0, margin, 0, 0));

      if(hoverRect.left() >= m_eidAxisRect.left())
        p.drawLine(hoverRect.topLeft(), hoverRect.bottomLeft());
      p.drawLine(hoverRect.topRight(), hoverRect.bottomRight());

      // shrink the rect a bit for clipping against labels below
      hoverRect.setX(qRound(hoverRect.x() + 0.5));
      hoverRect.setWidth(int(hoverRect.width()));
    }
    else
    {
      hoverRect = QRectF();
    }
  }

  QRectF labelRect = eidAxisRect;
  labelRect.setWidth(m_eidAxisLabelWidth);

  // iterate through the EIDs from 0, starting from possible a negative offset if the user has
  // panned to the right.
  for(uint32_t i = 0; i <= maxEID; i += m_eidAxisLabelStep)
  {
    labelRect.moveLeft(offsetOf(i) - labelRect.width() / 2 + m_eidWidth / 2);

    // check if this label is visible at all, but don't draw labels that intersect with the hovered
    // number
    if(labelRect.right() >= 0 && !labelRect.intersects(hoverRect))
      p.drawText(labelRect, QString::number(i), to);

    // check if labelRect is off the edge of the screen
    if(labelRect.left() >= m_eidAxisRect.right())
      break;
  }

  // stop clipping
  p.setClipRect(viewport()->rect());

  // clip the markers
  p.setClipRect(m_markerRect);

  {
    QPen pen = p.pen();
    paintMarkers(p, m_RootMarkers, m_RootDraws, m_markerRect);
    p.setPen(pen);
  }

  // stop clipping
  p.setClipRect(viewport()->rect());

  QRectF currentRect = eidAxisRect;

  // draw the current label and line
  {
    uint32_t curEID = m_Ctx.CurEvent();

    currentRect.setLeft(offsetOf(curEID));
    currentRect.setWidth(
        qMax(m_eidAxisLabelWidth, m_eidAxisLabelTextWidth + dataBarHeight + margin * 2));

    // recentre
    currentRect.moveLeft(currentRect.left() - currentRect.width() / 2 + m_eidWidth / 2);

    // remember where the middle would have been, without clamping
    qreal realMiddle = currentRect.center().x();

    // clamp the position from the left or right side
    if(currentRect.left() < eidAxisRect.left())
      currentRect.moveLeft(eidAxisRect.left());
    else if(currentRect.right() > eidAxisRect.right())
      currentRect.moveRight(eidAxisRect.right());

    // re-add the top margin so the lines match up with the border around the EID axis
    QRectF currentBackRect = currentRect.marginsAdded(QMargins(0, margin, 0, 0));

    p.fillRect(currentBackRect, palette().brush(QPalette::Base));
    p.drawRect(currentBackRect);

    // draw the 'current marker' pixmap
    const QPixmap &px = Pixmaps::flag_green(devicePixelRatio());
    p.drawPixmap(currentRect.topLeft() + QPointF(margin, 1), px, px.rect());

    // move to where the text should be and draw it
    currentRect.setLeft(currentRect.left() + margin * 2 + dataBarHeight);
    p.drawText(currentRect, QString::number(curEID), to);

    // draw a line from the bottom of the shadow downwards
    QPointF currentTop = currentRect.center();
    currentTop.setX(int(qBound(eidAxisRect.left(), realMiddle, eidAxisRect.right() - 2.0)) + 0.5);
    currentTop.setY(currentRect.bottom());

    QPointF currentBottom = currentTop;
    currentBottom.setY(m_markerRect.bottom());

    p.drawLine(currentTop, currentBottom);
  }

  to.setAlignment(Qt::AlignLeft | Qt::AlignTop);

  if(!m_UsageTarget.isEmpty() || !m_HistoryTarget.isEmpty())
  {
    p.setRenderHint(QPainter::Antialiasing);

    QRectF highlightLabel = m_highlightingRect.marginsRemoved(uniformMargins(margin));

    highlightLabel.setX(highlightLabel.x() + margin);

    QString text;

    if(!m_HistoryTarget.isEmpty())
      text = tr("Pixel history for %1").arg(m_HistoryTarget);
    else
      text = tr("Usage for %1:").arg(m_UsageTarget);

    p.drawText(highlightLabel, text, to);

    const int triRadius = fm.averageCharWidth();
    const int triHeight = fm.ascent();

    QPainterPath triangle;
    triangle.addPolygon(
        QPolygonF({QPoint(0, triHeight), QPoint(triRadius * 2, triHeight), QPoint(triRadius, 0)}));
    triangle.closeSubpath();

    enum
    {
      ReadUsage,
      WriteUsage,
      ReadWriteUsage,
      ClearUsage,
      BarrierUsage,

      HistoryPassed,
      HistoryFailed,

      UsageCount,
    };

    const QColor colors[UsageCount] = {
        // read
        QColor(Qt::red),
        // write
        QColor(Qt::green),
        // read/write
        QColor(Qt::yellow),
        // clear
        QColor(Qt::blue),
        // barrier
        QColor(Qt::magenta),

        // pass
        QColor(Qt::green),
        // fail
        QColor(Qt::red),
    };

    // draw the key
    if(m_HistoryTarget.isEmpty())
    {
      // advance past the first text to draw the key
      highlightLabel.setLeft(highlightLabel.left() + fm.width(text));

      text = lit(" Reads ( ");
      p.drawText(highlightLabel, text, to);
      highlightLabel.setLeft(highlightLabel.left() + fm.width(text));

      QPainterPath path = triangle.translated(aliasAlign(highlightLabel.topLeft()));
      p.fillPath(path, colors[ReadUsage]);
      p.drawPath(path);
      highlightLabel.setLeft(highlightLabel.left() + triRadius * 2);

      text = lit(" ), Writes ( ");
      p.drawText(highlightLabel, text, to);
      highlightLabel.setLeft(highlightLabel.left() + fm.width(text));

      path = triangle.translated(aliasAlign(highlightLabel.topLeft()));
      p.fillPath(path, colors[WriteUsage]);
      p.drawPath(path);
      highlightLabel.setLeft(highlightLabel.left() + triRadius * 2);

      text = lit(" ), Read/Write ( ");
      p.drawText(highlightLabel, text, to);
      highlightLabel.setLeft(highlightLabel.left() + fm.width(text));

      path = triangle.translated(aliasAlign(highlightLabel.topLeft()));
      p.fillPath(path, colors[ReadWriteUsage]);
      p.drawPath(path);
      highlightLabel.setLeft(highlightLabel.left() + triRadius * 2);

      if(m_Ctx.CurPipelineState().SupportsBarriers())
      {
        text = lit(" ) Barriers ( ");
        p.drawText(highlightLabel, text, to);
        highlightLabel.setLeft(highlightLabel.left() + fm.width(text));

        path = triangle.translated(aliasAlign(highlightLabel.topLeft()));
        p.fillPath(path, colors[BarrierUsage]);
        p.drawPath(path);
        highlightLabel.setLeft(highlightLabel.left() + triRadius * 2);
      }

      text = lit(" ), and Clears ( ");
      p.drawText(highlightLabel, text, to);
      highlightLabel.setLeft(highlightLabel.left() + fm.width(text));

      path = triangle.translated(aliasAlign(highlightLabel.topLeft()));
      p.fillPath(path, colors[ClearUsage]);
      p.drawPath(path);
      highlightLabel.setLeft(highlightLabel.left() + triRadius * 2);

      text = lit(" )");
      p.drawText(highlightLabel, text, to);
    }

    PipRanges pipranges[UsageCount];

    QRectF pipsRect = m_highlightingRect.marginsRemoved(uniformMargins(margin));

    pipsRect.setX(pipsRect.x() + margin + m_titleWidth);
    pipsRect.setHeight(triHeight + margin);
    pipsRect.moveBottom(m_highlightingRect.bottom());

    p.setClipRect(pipsRect);

    qreal leftClip = -triRadius * 2.0;
    qreal rightClip = pipsRect.width() + triRadius * 10.0;

    if(!m_HistoryEvents.isEmpty())
    {
      for(const PixelModification &mod : m_HistoryEvents)
      {
        qreal pos = offsetOf(mod.eventId) + m_eidWidth / 2 - triRadius;

        if(pos < leftClip || pos > rightClip)
          continue;

        if(mod.Passed())
          pipranges[HistoryPassed].push(pos, triRadius);
        else
          pipranges[HistoryFailed].push(pos, triRadius);
      }
    }
    else
    {
      for(const EventUsage &use : m_UsageEvents)
      {
        qreal pos = offsetOf(use.eventId) + m_eidWidth / 2 - triRadius;

        if(pos < leftClip || pos > rightClip)
          continue;

        if(((int)use.usage >= (int)ResourceUsage::VS_RWResource &&
            (int)use.usage <= (int)ResourceUsage::All_RWResource) ||
           use.usage == ResourceUsage::GenMips || use.usage == ResourceUsage::Copy ||
           use.usage == ResourceUsage::Resolve)
        {
          pipranges[ReadWriteUsage].push(pos, triRadius);
        }
        else if(use.usage == ResourceUsage::StreamOut || use.usage == ResourceUsage::ResolveDst ||
                use.usage == ResourceUsage::ColorTarget ||
                use.usage == ResourceUsage::DepthStencilTarget || use.usage == ResourceUsage::CopyDst)
        {
          pipranges[WriteUsage].push(pos, triRadius);
        }
        else if(use.usage == ResourceUsage::Clear)
        {
          pipranges[ClearUsage].push(pos, triRadius);
        }
        else if(use.usage == ResourceUsage::Barrier)
        {
          pipranges[BarrierUsage].push(pos, triRadius);
        }
        else
        {
          pipranges[ReadUsage].push(pos, triRadius);
        }
      }
    }

    for(int i = 0; i < UsageCount; i++)
    {
      QPainterPath path = pipranges[i].makePath(triRadius, triHeight, pipsRect.y());

      if(!path.isEmpty())
      {
        p.drawPath(path);
        p.fillPath(path, colors[i]);
      }
    }
  }
  else
  {
    QRectF highlightLabel = m_highlightingRect;
    highlightLabel = highlightLabel.marginsRemoved(uniformMargins(margin));

    highlightLabel.setX(highlightLabel.x() + margin);

    p.drawText(highlightLabel, tr("No resource selected for highlighting."), to);
  }
}
Пример #24
0
void RangeHistogram::paintEvent(QPaintEvent *e)
{
  QPainter p(this);

  p.setRenderHint(QPainter::Antialiasing);

  const QBrush blackBrush(QColor(0, 0, 0));
  const QBrush redBrush(QColor(60, 0, 0));
  const QBrush greenBrush(QColor(0, 128, 0));
  const QBrush whiteBrush(QColor(255, 255, 255));

  QRectF r = rect();

  p.eraseRect(r);

  r = r.marginsRemoved(QMarginsF(m_Margin, m_Margin, m_Margin, m_Margin));

  p.fillRect(r, palette().brush(QPalette::Shadow));

  QMarginsF border(m_Border, m_Border, m_Border, m_Border);
  border /= devicePixelRatioF();

  r = r.marginsRemoved(border);

  p.fillRect(r, ValidRange() ? palette().brush(QPalette::Inactive, QPalette::Highlight) : redBrush);

  int whiteX = (int)(whiteDelta() * r.width());
  int blackX = (int)(blackDelta() * r.width() + 0.5);

  QRectF blackPoint(r.topLeft(), QSize(blackX, r.height()));
  QRectF whitePoint(r.left() + whiteX, r.top(), r.width() - whiteX, r.height());

  if(ValidRange())
  {
    p.setPen(QPen(palette().color(QPalette::Dark)));
    p.drawLine(blackPoint.topRight(), blackPoint.bottomRight());
    p.drawLine(whitePoint.topLeft(), whitePoint.bottomLeft());
  }

  p.fillRect(whitePoint, whiteBrush);
  p.fillRect(blackPoint, blackBrush);

  if(!ValidRange())
    return;

  if(!m_HistogramData.isEmpty())
  {
    float minx = delta(m_HistogramMin);
    float maxx = delta(m_HistogramMax);

    uint32_t maxval = 0;
    for(int i = 0; i < m_HistogramData.count(); i++)
    {
      float x = (float)i / (float)m_HistogramData.count();

      float xdelta = minx + x * (maxx - minx);

      if(xdelta >= 0.0f && xdelta <= 1.0f)
      {
        maxval = qMax(maxval, m_HistogramData[i]);
      }
    }

    if(maxval == 0)
      maxval = 1;

    for(int i = 0; i < m_HistogramData.count(); i++)
    {
      float x = (float)i / (float)m_HistogramData.count();
      float y = (float)m_HistogramData[i] / (float)maxval;

      float xdelta = minx + x * (maxx - minx);

      if(xdelta >= 0.0f && xdelta <= 1.0f)
      {
        float segwidth = qMax(r.width() * (maxx - minx) / (float)m_HistogramData.count(), 1.0);

        QRectF barRect(QPointF(r.left() + r.width() * (minx + x * (maxx - minx)),
                               r.bottom() - r.height() * y + 1),
                       QSizeF(segwidth, r.height() * y));

        p.fillRect(barRect, greenBrush);
      }
    }
  }

  QVector<QPointF> blackTriangle = {QPoint(blackPoint.right(), m_MarkerSize * 2),
                                    QPoint(blackPoint.right() + m_MarkerSize, 0),
                                    QPoint(blackPoint.right() - m_MarkerSize, 0)};

  QPainterPath blackPath;
  blackPath.addPolygon(QPolygonF(blackTriangle));
  p.fillPath(blackPath, palette().brush(QPalette::Dark));

  QVector<QPointF> whiteTriangle = {
      QPoint(whitePoint.left(), whitePoint.bottom() - m_MarkerSize * 2 + m_Margin),
      QPoint(whitePoint.left() + m_MarkerSize, whitePoint.bottom() + m_Margin),
      QPoint(whitePoint.left() - m_MarkerSize, whitePoint.bottom() + m_Margin)};

  QPainterPath whitePath;
  whitePath.addPolygon(QPolygonF(whiteTriangle));
  p.fillPath(whitePath, palette().brush(QPalette::Dark));

  blackTriangle[0] -= QPointF(0.0, 2.0) / devicePixelRatioF();
  blackTriangle[1] += QPointF(-2.0, 1.0) / devicePixelRatioF();
  blackTriangle[2] += QPointF(2.0, 1.0) / devicePixelRatioF();

  blackPath = QPainterPath();
  blackPath.addPolygon(QPolygonF(blackTriangle));

  whiteTriangle[0] += QPointF(0.0, 2.0) / devicePixelRatioF();
  whiteTriangle[1] -= QPointF(2.0, 1.0) / devicePixelRatioF();
  whiteTriangle[2] += QPointF(2.0, -1.0) / devicePixelRatioF();

  whitePath = QPainterPath();
  whitePath.addPolygon(QPolygonF(whiteTriangle));

  p.fillPath(blackPath, blackBrush);
  p.fillPath(whitePath, whiteBrush);
}
Пример #25
0
#include "graphicsitemresizer.h"

#include "resizehandleitem.h"

#include <QPainter>


static QSizeF handleSize = QSizeF(6, 6);
static QMarginsF handleBounds = QMarginsF(handleSize.width(), handleSize.height(), handleSize.width(), handleSize.height());

GraphicsItemResizer::GraphicsItemResizer(QGraphicsItem *parent)
    : QGraphicsItem(parent)
    , mTargetSize(0, 0)
    , mMinSize(0, 0)
{
    static QRectF handleRect(QPointF(), handleSize);

    setFlag(ItemHasNoContents);

    // sides
    mHandleItems.append(new HandleItem(HandleItem::Left, handleRect, this));
    mHandleItems.append(new HandleItem(HandleItem::Top, handleRect, this));
    mHandleItems.append(new HandleItem(HandleItem::Right, handleRect, this));
    mHandleItems.append(new HandleItem(HandleItem::Bottom, handleRect, this));
    // corners
    mHandleItems.append(new HandleItem(HandleItem::Top | HandleItem::Left, handleRect, this));
    mHandleItems.append(new HandleItem(HandleItem::Top | HandleItem::Right, handleRect, this));
    mHandleItems.append(new HandleItem(HandleItem::Bottom | HandleItem::Right, handleRect, this));
    mHandleItems.append(new HandleItem(HandleItem::Bottom | HandleItem::Left, handleRect, this));
}