Beispiel #1
0
int QGLPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
{
    if (w == 0)
        return 0;

    switch (metric) {
    case QPaintDevice::PdmWidth:
        return w;
    case QPaintDevice::PdmHeight:
        return h;
    case QPaintDevice::PdmNumColors:
        return 0;
    case QPaintDevice::PdmDepth:
        return d;
    case QPaintDevice::PdmWidthMM:
        return qRound(w * 25.4 / qt_defaultDpiX());
    case QPaintDevice::PdmHeightMM:
        return qRound(h * 25.4 / qt_defaultDpiY());
    case QPaintDevice::PdmDpiX:
    case QPaintDevice::PdmPhysicalDpiX:
        return qt_defaultDpiX();
    case QPaintDevice::PdmDpiY:
    case QPaintDevice::PdmPhysicalDpiY:
        return qt_defaultDpiY();
    default:
        qWarning("QGLPixmapData::metric(): Invalid metric");
        return 0;
    }
}
Beispiel #2
0
int QBlittablePixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
{
    switch (metric) {
    case QPaintDevice::PdmWidth:
        return w;
    case QPaintDevice::PdmHeight:
        return h;
    case QPaintDevice::PdmWidthMM:
        return qRound(w * 25.4 / qt_defaultDpiX());
    case QPaintDevice::PdmHeightMM:
        return qRound(h * 25.4 / qt_defaultDpiY());
    case QPaintDevice::PdmDepth:
        return 32;
    case QPaintDevice::PdmDpiX: // fall-through
    case QPaintDevice::PdmPhysicalDpiX:
        return qt_defaultDpiX();
    case QPaintDevice::PdmDpiY: // fall-through
    case QPaintDevice::PdmPhysicalDpiY:
        return qt_defaultDpiY();
    default:
        qWarning("QRasterPixmapData::metric(): Unhandled metric type %d", metric);
        break;
    }

    return 0;
}
Beispiel #3
0
QgsMapSettings::QgsMapSettings()
    : mDpi( qt_defaultDpiX() ) // DPI that will be used by default for QImage instances
    , mSize( QSize( 0, 0 ) )
    , mExtent()
    , mRotation( 0.0 )
    , mMagnificationFactor( 1.0 )
    , mProjectionsEnabled( false )
    , mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId )  // WGS 84
    , mDatumTransformStore( mDestCRS )
    , mBackgroundColor( Qt::white )
    , mSelectionColor( Qt::yellow )
    , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
    , mImageFormat( QImage::Format_ARGB32_Premultiplied )
    , mSegmentationTolerance( M_PI_2 / 90 )
    , mSegmentationToleranceType( QgsAbstractGeometryV2::MaximumAngle )
    , mValid( false )
    , mVisibleExtent()
    , mMapUnitsPerPixel( 1 )
    , mScale( 1 )
{
  updateDerived();

  // set default map units - we use WGS 84 thus use degrees
  setMapUnits( QGis::Degrees );
}
qreal QQuickControlSettings::dpiScaleFactor() const
{
#ifndef Q_OS_MAC
    return (qreal(qt_defaultDpiX()) / 96.0);
#endif
    return 1.0;
}
Beispiel #5
0
int QDirectFBPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
{
    if (!serialNumber())
        return 0;

    switch (metric) {
    case QPaintDevice::PdmWidth: {
        int w, h;
        surface->GetSize(surface, &w, &h);
        return w;
    }
    case QPaintDevice::PdmHeight: {
        int w, h;
        surface->GetSize(surface, &w, &h);
        return h;
    }
    case QPaintDevice::PdmWidthMM: {
        int w, h;
        surface->GetSize(surface, &w, &h);
        return qRound(w * qreal(25.4) / qt_defaultDpiX());
    }
    case QPaintDevice::PdmHeightMM: {
        int w, h;
        surface->GetSize(surface, &w, &h);
        return qRound(h * qreal(25.4) / qt_defaultDpiY());
    }
    case QPaintDevice::PdmNumColors: {
        return (1 << depth()); // hw: make inline
    }
    case QPaintDevice::PdmDepth: {
        DFBSurfacePixelFormat format;
        surface->GetPixelFormat(surface, &format);
        return QDirectFBScreen::depth(format);
    }
    case QPaintDevice::PdmPhysicalDpiX:
    case QPaintDevice::PdmDpiX: {
        return qt_defaultDpiX();
    }
    case QPaintDevice::PdmPhysicalDpiY:
    case QPaintDevice::PdmDpiY: {
        return qt_defaultDpiY();
    }
    default:
        qCritical("QDirectFBScreen::metric(): Unhandled metric!");
        return 0;
    }
}
static void _fixQPictureDPI( QPainter* p )
{
  // QPicture makes an assumption that we drawing to it with system DPI.
  // Then when being drawn, it scales the painter. The following call
  // negates the effect. There is no way of setting QPicture's DPI.
  // See QTBUG-20361
  p->scale(( double )qt_defaultDpiX() / p->device()->logicalDpiX(),
           ( double )qt_defaultDpiY() / p->device()->logicalDpiY() );
}
Beispiel #7
0
void QgsPaintEffect::fixQPictureDpi( QPainter *painter ) const
{
  // QPicture makes an assumption that we drawing to it with system DPI.
  // Then when being drawn, it scales the painter. The following call
  // negates the effect. There is no way of setting QPicture's DPI.
  // See QTBUG-20361
  painter->scale( static_cast< double >( qt_defaultDpiX() ) / painter->device()->logicalDpiX(),
                  static_cast< double >( qt_defaultDpiY() ) / painter->device()->logicalDpiY() );
}
Beispiel #8
0
QgsMapSettings::QgsMapSettings()
  : mDpi( qt_defaultDpiX() ) // DPI that will be used by default for QImage instances
  , mSize( QSize( 0, 0 ) )
  , mBackgroundColor( Qt::white )
  , mSelectionColor( Qt::yellow )
  , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
  , mSegmentationTolerance( M_PI_2 / 90 )
{
  mScaleCalculator.setMapUnits( QgsUnitTypes::DistanceUnknownUnit );

  updateDerived();
}
Beispiel #9
0
int QRasterPlatformPixmap::metric(QPaintDevice::PaintDeviceMetric metric) const
{
    QImageData *d = image.d;
    if (!d)
        return 0;

    // override the image dpi with the screen dpi when rendering to a pixmap
    switch (metric) {
    case QPaintDevice::PdmWidth:
        return w;
    case QPaintDevice::PdmHeight:
        return h;
    case QPaintDevice::PdmWidthMM:
        return qRound(d->width * 25.4 / qt_defaultDpiX());
    case QPaintDevice::PdmHeightMM:
        return qRound(d->height * 25.4 / qt_defaultDpiY());
    case QPaintDevice::PdmNumColors:
        return d->colortable.size();
    case QPaintDevice::PdmDepth:
        return this->d;
    case QPaintDevice::PdmDpiX:
        return qt_defaultDpiX();
    case QPaintDevice::PdmPhysicalDpiX:
        return qt_defaultDpiX();
    case QPaintDevice::PdmDpiY:
        return qt_defaultDpiX();
    case QPaintDevice::PdmPhysicalDpiY:
        return qt_defaultDpiY();
    case QPaintDevice::PdmDevicePixelRatio:
        return image.devicePixelRatio();
    case QPaintDevice::PdmDevicePixelRatioScaled:
        return image.devicePixelRatio() * QPaintDevice::devicePixelRatioFScale();

    default:
        qWarning("QRasterPlatformPixmap::metric(): Unhandled metric type %d", metric);
        break;
    }

    return 0;
}
Beispiel #10
0
/*! \reimp */
int QGLPixelBuffer::metric(PaintDeviceMetric metric) const
{
    Q_D(const QGLPixelBuffer);

    float dpmx = qt_defaultDpiX()*100./2.54;
    float dpmy = qt_defaultDpiY()*100./2.54;
    int w = d->req_size.width();
    int h = d->req_size.height();
    switch (metric) {
    case PdmWidth:
        return w;

    case PdmHeight:
        return h;

    case PdmWidthMM:
        return qRound(w * 1000 / dpmx);

    case PdmHeightMM:
        return qRound(h * 1000 / dpmy);

    case PdmNumColors:
        return 0;

    case PdmDepth:
        return 32;//d->depth;

    case PdmDpiX:
        return qRound(dpmx * 0.0254);

    case PdmDpiY:
        return qRound(dpmy * 0.0254);

    case PdmPhysicalDpiX:
        return qRound(dpmx * 0.0254);

    case PdmPhysicalDpiY:
        return qRound(dpmy * 0.0254);

    case QPaintDevice::PdmDevicePixelRatio:
        return 1;

    default:
        qWarning("QGLPixelBuffer::metric(), Unhandled metric type: %d\n", metric);
        break;
    }
    return 0;
}
Beispiel #11
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();
        QPainterState &state = *d->m_picpainter->d_func()->state;
        QPainter *oldPainter = state.painter;
        state = *painter()->d_func()->state;
        state.painter = oldPainter;
    }
}
Beispiel #12
0
bool QtPrinterTableView::print()
{
    Q_D(QtPrinterTableView);
    if (! d->printer->isValid()) {
        qWarning() << "QtPrinterTableView::print: printer not valid, please setup the printer before calling print";
        return false;
    }

    // next use a view just for the filling of the options...
    QGraphicsScene scene;
    QtGraphicsTableView view;
    scene.addItem(&view);
    view.setModel(d->model);


    class QTableHeaderDataProvider2 : public QtGraphicsHeaderDataProvider
    {
    public:
        QTableHeaderDataProvider2(QtTableModelInterface *model_) : model(model_) {}
        QHash<int,QVariant> data(int logicalIndex, const QList<int> &roles) const
        {
            // ### call the model - temporary implementation
            QHash<int,QVariant> hash;
            for (int i = 0; i < roles.count(); ++i)
                if (roles.at(i) == Qt::DisplayRole)
                    hash.insert(Qt::DisplayRole, logicalIndex + 1);
            return hash;
        }
        QtTableModelInterface *model;
    };

    if (d->horizontalHeader) {
        QtGraphicsHeader *header = new QtGraphicsHeader(Qt::Horizontal, &view);
        header->setDataProvider(new QTableHeaderDataProvider2(d->model));
        header->copySections(*d->horizontalHeader);
        view.setHorizontalHeader(header);
    }
    if (d->verticalHeader) {
        QtGraphicsHeader *header = new QtGraphicsHeader(Qt::Vertical, &view);
        header->setDataProvider(new QTableHeaderDataProvider2(d->model));
        header->copySections(*d->verticalHeader);
        view.setVerticalHeader(header);
    }

    QPainter painter;
    if (!painter.begin(d->printer)) {
        qWarning() << "QtPrinterTableView::print: printer fails to begin(), sorry can't print";
        return false;
    }

    // re-layout the header footer to the current page size.
    if (d->header) {
        d->header->documentLayout()->setPaintDevice(d->printer);
        d->header->setPageSize(d->printer->pageRect().size());
    }
    if (d->footer) {
        d->footer->documentLayout()->setPaintDevice(d->printer);
        d->footer->setPageSize(d->printer->pageRect().size());
    }

    const qreal headerSize = d->printHeader(painter);
    const qreal footerSize = d->printFooter(painter);
    const bool vertical = d->orientation == Qt::Vertical;
    const qreal scaleX = d->printer->logicalDpiX() / (qreal) qt_defaultDpiX();
    const qreal scaleY = d->printer->logicalDpiY() / (qreal) qt_defaultDpiY();
    painter.scale(scaleX, scaleY);

    const QRect rect = d->printer->pageRect();
    QSizeF visibleSize(rect.width() / scaleX, rect.height() / scaleY);
    if (vertical)
        visibleSize = QSizeF(visibleSize.width(), visibleSize.height() - headerSize - footerSize);
    else // then rotate it.
        visibleSize = QSizeF(visibleSize.height() - headerSize - footerSize, visibleSize.width());

    view.setGeometry(0, 0, visibleSize.width(), visibleSize.height());
    view.setHorizontalOffset(0);

    int row = 0;
    int column;
    bool first = true;
    qreal offsetInColumn = 0; // for those columns too wide and thus split over more than one page
    while (row < d->model->rowCount()) {
        column = 0;
        view.setFirstRow(row);
        qreal height = visibleSize.height();
        while (true) {
            const qreal rowHeight = view.rowHeight(row);
            if (height - rowHeight < 0)
                break;
            if (row >= d->model->rowCount())
                break;
            ++row;
            height -= rowHeight;
        }
        while (column < d->model->columnCount()) {
            if (!first) {
                d->printer->newPage();
                d->printHeader(painter);
                d->printFooter(painter);
            }
            first = false;
            view.setFirstColumn(column);
            view.setHorizontalOffset(offsetInColumn);

            qreal width = visibleSize.width();
            while (true) {
                const qreal columnWidth = view.columnWidth(column);
                if (width == visibleSize.width() && columnWidth - offsetInColumn > visibleSize.width()) {
                    // the column doesn't fit on a page. Lets split it.
                    offsetInColumn += visibleSize.width();
                    width = 0;
                    break;
                } else if (offsetInColumn > 0) { // we still have a part of a split column to print!
                    width -= columnWidth - offsetInColumn;
                    offsetInColumn = 0;
                    ++column;
                    continue;
                }

                if (width - columnWidth + offsetInColumn < 0)
                    break;
                if (column >= d->model->columnCount())
                    break;
                ++column;
                width -= columnWidth;
            }
            view.doLayout();

            painter.save(); // for each page
            painter.translate(0, headerSize);
            if (!vertical) {
                painter.translate(0, visibleSize.width());
                painter.rotate(-90);
            }
#ifdef DEBUG_TABLES
            painter.setPen(QPen(QColor(Qt::green)));
            painter.drawRect(QRectF(0, 0, visibleSize.width() - width, visibleSize.height() - height));
#endif
            painter.setClipRect(QRectF(0, 0, visibleSize.width() - width, visibleSize.height() - height));
            // find and paint children which are the cells
            QList<QGraphicsItem*> items = scene.items(view.rect());
            QList<QGraphicsItem*>::Iterator iter = items.begin();
            for (;iter != items.end(); ++iter) {
                QGraphicsItem *parent = *iter;
                while (parent != &view && parent != 0) // only draw children of our view
                    parent = parent->parentItem();
                if (parent == 0)
                    continue;
                if (!(*iter)->isVisible())
                    continue;
                painter.save();
                painter.translate((*iter)->mapToItem(&view, QPointF()));
#ifdef DEBUG_TABLES
                QGraphicsWidget *w = dynamic_cast<QGraphicsWidget*>(*iter);
                if (w) {
                    painter.save();
                    painter.setPen(QPen(QColor(Qt::red)));
                    painter.drawRect(QRectF(QPointF(), w->size()));
                    painter.restore();
                }
#endif
                (*iter)->paint(&painter, 0);
                painter.restore();
            }
            painter.restore(); // for each page
        }
    }
    return true;
}
void KoStyleThumbnailer::layoutThumbnail(QSize size, QImage *im, KoStyleThumbnailerFlags flags)
{
    QPainter p(im);
    d->documentLayout->removeRootArea();
    KoTextLayoutRootArea rootArea(d->documentLayout);
    rootArea.setReferenceRect(0, size.width() * 72.0 / qt_defaultDpiX(), 0, 1E6);
    rootArea.setNoWrap(1E6);

    FrameIterator frameCursor(d->thumbnailHelperDocument->rootFrame());
    rootArea.layoutRoot(&frameCursor);

    QSizeF documentSize = rootArea.boundingRect().size();
    documentSize.setWidth(documentSize.width() * qt_defaultDpiX() / 72.0);
    documentSize.setHeight(documentSize.height() * qt_defaultDpiY() / 72.0);
    if (documentSize.width() > size.width() || documentSize.height() > size.height()) {
        //calculate the space needed for the font size indicator (should the preview be too big with the style's font size
        QTextCursor cursor(d->thumbnailHelperDocument);
        cursor.select(QTextCursor::Document);
        QString sizeHint = "\t" + QString::number(cursor.charFormat().fontPointSize()) + "pt";
        p.save();
        QFont sizeHintFont = p.font();
        sizeHintFont.setPointSize(8);
        p.setFont(sizeHintFont);
        QRectF sizeHintRect(p.boundingRect(0, 0, 1, 1, Qt::AlignCenter, sizeHint));
        p.restore();
        qreal width = qMax<qreal>(0., size.width()-sizeHintRect.width());

        QTextCharFormat fmt = cursor.charFormat();
        if (flags & ScaleThumbnailFont) {
            //calculate the font reduction factor so that the text + the sizeHint fits
            qreal reductionFactor = qMin(width/documentSize.width(), size.height()/documentSize.height());

            fmt.setFontPointSize((int)(fmt.fontPointSize()*reductionFactor));
        }

        cursor.mergeCharFormat(fmt);

        frameCursor = FrameIterator(d->thumbnailHelperDocument->rootFrame());
        rootArea.setReferenceRect(0, width * 72.0 / qt_defaultDpiX(), 0, 1E6);
        rootArea.setNoWrap(1E6);
        rootArea.layoutRoot(&frameCursor);
        documentSize = rootArea.boundingRect().size();
        documentSize.setWidth(documentSize.width() * qt_defaultDpiX() / 72.0);
        documentSize.setHeight(documentSize.height() * qt_defaultDpiY() / 72.0);
        //center the preview in the pixmap
        qreal yOffset = (size.height()-documentSize.height())/2;
        p.save();
        if ((flags & CenterAlignThumbnail) && yOffset) {
            p.translate(0, yOffset);
        }

        p.scale(qt_defaultDpiX() / 72.0, qt_defaultDpiY() / 72.0);

        KoTextDocumentLayout::PaintContext pc;
        rootArea.paint(&p, pc);

        p.restore();

        p.setFont(sizeHintFont);
        p.drawText(QRectF(size.width()-sizeHintRect.width(), 0, sizeHintRect.width(),
                          size.height() /*because we want to be vertically centered in the pixmap, like the style name*/),Qt::AlignCenter, sizeHint);
    }
    else {
        //center the preview in the pixmap
        qreal yOffset = (size.height()-documentSize.height())/2;
        if ((flags & CenterAlignThumbnail) && yOffset) {
            p.translate(0, yOffset);
        }

        p.scale(qt_defaultDpiX() / 72.0, qt_defaultDpiY() / 72.0);

        KoTextDocumentLayout::PaintContext pc;
        rootArea.paint(&p, pc);
    }
}