void QgsComposerPicture::setSceneRect( const QRectF& rectangle ) { QSizeF currentPictureSize = pictureSize(); if ( mResizeMode == QgsComposerPicture::Clip ) { QgsComposerItem::setSceneRect( rectangle ); mPictureWidth = rectangle.width(); mPictureHeight = rectangle.height(); return; } QRectF newRect = rectangle; if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) ) { //if width has changed less than height, then fix width and set height correspondingly //else, do the opposite if ( qAbs( rect().width() - rectangle.width() ) < qAbs( rect().height() - rectangle.height() ) ) { newRect.setHeight( currentPictureSize.height() * newRect.width() / currentPictureSize.width() ); } else { newRect.setWidth( currentPictureSize.width() * newRect.height() / currentPictureSize.height() ); } } else if ( mResizeMode == FrameToImageSize ) { if ( !( currentPictureSize.isEmpty() ) ) { newRect.setWidth( currentPictureSize.width() * 25.4 / mComposition->printResolution() ); newRect.setHeight( currentPictureSize.height() * 25.4 / mComposition->printResolution() ); } } //find largest scaling of picture with this rotation which fits in item if ( mResizeMode == Zoom ) { QRectF rotatedImageRect = largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), newRect, mPictureRotation ); mPictureWidth = rotatedImageRect.width(); mPictureHeight = rotatedImageRect.height(); } else { mPictureWidth = newRect.width(); mPictureHeight = newRect.height(); } QgsComposerItem::setSceneRect( newRect ); emit itemChanged(); }
void CanvasAppliance::setExactSizeProject(bool usePrevious) { ui.projectCombo->setCurrentIndex(1); m_extCanvas->clearMarkers(); if (!usePrevious || !m_extCanvas->modeInfo()->fixedSize()) { ExactSizeDialog sizeDialog; QSizeF prevSizeInches = m_extCanvas->modeInfo()->fixedSizeInches(); if (!prevSizeInches.isEmpty()) { bool cm = !sizeDialog.ui.unityComboBox->currentIndex(); sizeDialog.ui.widthSpinBox->setValue(cm?prevSizeInches.width()*2.54:prevSizeInches.width()); sizeDialog.ui.heightSpinBox->setValue(cm?prevSizeInches.height()*2.54:prevSizeInches.height()); } QPointF screenDpi = m_extCanvas->modeInfo()->screenDpi(); if (screenDpi.x() == screenDpi.y()) sizeDialog.ui.screenDpi->setValue((int)screenDpi.x()); else sizeDialog.ui.screenDpi->setSpecialValueText(QString("%1, %2").arg(screenDpi.x()).arg(screenDpi.y())); if (sizeDialog.exec() != QDialog::Accepted) return; float w = sizeDialog.ui.widthSpinBox->value(); float h = sizeDialog.ui.heightSpinBox->value(); int printDpi = sizeDialog.ui.printDpi->value(); bool landscape = sizeDialog.ui.landscapeCheckBox->isChecked(); bool cm = !sizeDialog.ui.unityComboBox->currentIndex(); m_extCanvas->modeInfo()->setPrintLandscape(landscape); m_extCanvas->modeInfo()->setPrintDpi(printDpi); m_extCanvas->modeInfo()->setFixedSizeInches(QSizeF(cm?(double)w/2.54:w, cm?(double)h/2.54:h)); } m_extCanvas->modeInfo()->setProjectMode(CanvasModeInfo::ModeExactSize); m_extCanvas->adjustSceneSize(); configurePrint(true); }
void QGraphicsVideoItemPrivate::updateRects() { q_ptr->prepareGeometryChange(); if (nativeSize.isEmpty()) { //this is necessary for item to receive the //first paint event and configure video surface. boundingRect = rect; } else if (aspectRatioMode == Qt::IgnoreAspectRatio) { boundingRect = rect; sourceRect = QRectF(0, 0, 1, 1); } else if (aspectRatioMode == Qt::KeepAspectRatio) { QSizeF size = nativeSize; size.scale(rect.size(), Qt::KeepAspectRatio); boundingRect = QRectF(0, 0, size.width(), size.height()); boundingRect.moveCenter(rect.center()); sourceRect = QRectF(0, 0, 1, 1); } else if (aspectRatioMode == Qt::KeepAspectRatioByExpanding) { boundingRect = rect; QSizeF size = rect.size(); size.scale(nativeSize, Qt::KeepAspectRatio); sourceRect = QRectF( 0, 0, size.width() / nativeSize.width(), size.height() / nativeSize.height()); sourceRect.moveCenter(QPointF(0.5, 0.5)); } }
void QQuickWebPage::setContentsSize(const QSizeF& size) { if (size.isEmpty() || d->contentsSize == size) return; d->contentsSize = size; d->updateSize(); emit d->viewportItem->experimental()->test()->contentsSizeChanged(); }
void QQuickWebPage::setContentsSize(const QSizeF& size) { if (size.isEmpty() || d->contentsSize == size) return; d->contentsSize = size; d->updateSize(); d->setDrawingAreaSize(d->contentsSize.toSize()); }
QFont Font::stretch(const QFont& baseFont, int rows, int cols, const QSizeF& size) { Q_ASSERT(rows > 0); Q_ASSERT(cols > 0); Q_ASSERT(!size.isEmpty()); int height = size.height() / rows; // Create the font QFont font(baseFont); // Set the size font.setPixelSize(height); // Get the actual metrics of the font QFontMetrics metrics(font); // Is the font height greater than requested? if (metrics.height() > height) { // Recreate the font int diff = metrics.height() - height; font.setPixelSize(height - diff); metrics = QFontMetrics(font); while (metrics.height() * rows > size.height()) { font.setPixelSize(font.pixelSize() - 1); metrics = QFontMetrics(font); } } metrics = QFontMetrics(font); Q_ASSERT(metrics.height() * rows <= size.height()); // Is the font too wide? int fontWidth = metrics.averageCharWidth(); // Ideal width int width = size.width() / cols; if (width > 0) { int newWidth = (width * 100) / fontWidth; font.setStretch(newWidth); // Anything left over? metrics = QFontMetrics(font); if (metrics.averageCharWidth() * cols < size.width()) { qreal diff = size.width() - (metrics.averageCharWidth() * cols); diff /= cols; font.setLetterSpacing(QFont::AbsoluteSpacing, diff); } } return font; }
QDpi QEGLDeviceIntegration::logicalDpi() const { const QSizeF ps = physicalScreenSize(); const QSize s = screenSize(); if (!ps.isEmpty() && !s.isEmpty()) return QDpi(25.4 * s.width() / ps.width(), 25.4 * s.height() / ps.height()); else return QDpi(100, 100); }
void QtCamRoi::setRegionOfInterest(const QRectF& roi) { if (!d_ptr->dev || !d_ptr->dev->viewfinder()) { return; } QSizeF vf = d_ptr->dev->viewfinder()->videoResolution(); if (vf.isEmpty()) { return; } int frameWidth = vf.width(); int frameHeight = vf.height(); int x = roi.x() * frameWidth; int y = roi.y() * frameHeight; int width = roi.width() * frameWidth; int height = roi.height() * frameHeight; // if we have an empty roi then we reset: int priority = roi.isEmpty() ? 0 : 1; GstStructure *region = gst_structure_new("region0", "region-x", G_TYPE_UINT, x, "region-y", G_TYPE_UINT, y, "region-w", G_TYPE_UINT, width, "region-h", G_TYPE_UINT, height, "region-priority", G_TYPE_UINT, priority, "region-id", G_TYPE_UINT, 0, NULL); GValue regionValue = G_VALUE_INIT; GValue regionList = G_VALUE_INIT; g_value_init(®ionValue, GST_TYPE_STRUCTURE); g_value_init(®ionList, GST_TYPE_LIST); gst_value_set_structure(®ionValue, region); gst_value_list_append_value(®ionList, ®ionValue); GstStructure *s = gst_structure_new("regions-of-interest", "frame-width", G_TYPE_UINT, frameWidth, "frame-height", G_TYPE_UINT, frameHeight, NULL); gst_structure_set_value(s, "regions", ®ionList); GstEvent *event = gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM, s); gst_structure_free(region); g_value_unset(®ionValue); g_value_unset(®ionList); if (!d_ptr->sendEventToSource(event)) { qWarning() << "Failed to send ROI event"; } }
QSizeF EglUtils::physicalScreenSizeFromFb(int framebufferDevice, const QSize &screenSize) { #ifndef Q_OS_LINUX Q_UNUSED(framebufferDevice) #endif const int defaultPhysicalDpi = 100; static QSizeF size; if (size.isEmpty()) { // Note: in millimeters int width = qEnvironmentVariableIntValue("GREENISLAND_QPA_PHYSICAL_WIDTH"); int height = qEnvironmentVariableIntValue("GREENISLAND_QPA_PHYSICAL_HEIGHT"); if (width && height) { size.setWidth(width); size.setHeight(height); return size; } int w = -1; int h = -1; QSize screenResolution; #ifdef Q_OS_LINUX struct fb_var_screeninfo vinfo; if (framebufferDevice != -1) { if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) { qCWarning(lcEglConvenience, "Could not query screen info"); } else { w = vinfo.width; h = vinfo.height; screenResolution = QSize(vinfo.xres, vinfo.yres); } } else #endif { // Use the provided screen size, when available, since some platforms may have their own // specific way to query it. Otherwise try querying it from the framebuffer. screenResolution = screenSize.isEmpty() ? screenSizeFromFb(framebufferDevice) : screenSize; } size.setWidth(w <= 0 ? screenResolution.width() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(w)); size.setHeight(h <= 0 ? screenResolution.height() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(h)); if (w <= 0 || h <= 0) qCWarning(lcEglConvenience, "Unable to query physical screen size, defaulting to %d dpi.\n" "To override, set GREENISLAND_QPA_PHYSICAL_WIDTH " "and GREENISLAND_QPA_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi); } return size; }
/*! \return Icon for the legend In case of Tube style() the icon is a plain rectangle filled with the brush(). If a symbol is assigned it is scaled to size. \param index Index of the legend entry ( ignored as there is only one ) \param size Icon size \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() */ QwtGraphic QwtPlotIntervalCurve::legendIcon( int index, const QSizeF &size ) const { Q_UNUSED( index ); if ( size.isEmpty() ) return QwtGraphic(); QwtGraphic icon; icon.setDefaultSize( size ); icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); QPainter painter( &icon ); painter.setRenderHint( QPainter::Antialiasing, testRenderHint( QwtPlotItem::RenderAntialiased ) ); if ( d_data->style == Tube ) { QRectF r( 0, 0, size.width(), size.height() ); painter.fillRect( r, d_data->brush ); } if ( d_data->symbol && ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) { QPen pen = d_data->symbol->pen(); pen.setWidthF( pen.widthF() ); pen.setCapStyle( Qt::FlatCap ); painter.setPen( pen ); painter.setBrush( d_data->symbol->brush() ); if ( orientation() == Qt::Vertical ) { const double x = 0.5 * size.width(); d_data->symbol->draw( &painter, orientation(), QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) ); } else { const double y = 0.5 * size.height(); d_data->symbol->draw( &painter, orientation(), QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) ); } } return icon; }
QSizeF QEglFSHooks::physicalScreenSize() const { static QSizeF size; if (size.isEmpty()) { // Note: in millimeters int width = qgetenv("QT_QPA_EGLFS_PHYSICAL_WIDTH").toInt(); int height = qgetenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT").toInt(); if (width && height) { // no need to read fb0 size.setWidth(width); size.setHeight(height); return size; } struct fb_var_screeninfo vinfo; int w = -1; int h = -1; if (framebuffer != -1) { if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) { qWarning("EGLFS: Could not query variable screen info."); } else { w = vinfo.width; h = vinfo.height; } } const int defaultPhysicalDpi = 100; size.setWidth(w <= 0 ? vinfo.xres * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(w)); size.setHeight(h <= 0 ? vinfo.yres * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(h)); if (w <= 0 || h <= 0) { qWarning("EGLFS: Unable to query physical screen size, defaulting to %d dpi.\n" "EGLFS: To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi); } // override fb0 from environment var setting if (width) size.setWidth(width); if (height) size.setWidth(height); } return size; }
/*! \return Icon representing the marker on the legend \param index Index of the legend entry ( usually there is only one ) \param size Icon size \sa setLegendIconSize(), legendData() */ QwtGraphic QwtPlotMarker::legendIcon( int index, const QSizeF &size ) const { Q_UNUSED( index ); if ( size.isEmpty() ) return QwtGraphic(); QwtGraphic icon; icon.setDefaultSize( size ); icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); QPainter painter( &icon ); painter.setRenderHint( QPainter::Antialiasing, testRenderHint( QwtPlotItem::RenderAntialiased ) ); if ( d_data->style != QwtPlotMarker::NoLine ) { painter.setPen( d_data->pen ); if ( d_data->style == QwtPlotMarker::HLine || d_data->style == QwtPlotMarker::Cross ) { const double y = 0.5 * size.height(); QwtPainter::drawLine( &painter, 0.0, y, size.width(), y ); } if ( d_data->style == QwtPlotMarker::VLine || d_data->style == QwtPlotMarker::Cross ) { const double x = 0.5 * size.width(); QwtPainter::drawLine( &painter, x, 0.0, x, size.height() ); } } if ( d_data->symbol ) { const QRect r( 0.0, 0.0, size.width(), size.height() ); d_data->symbol->drawSymbol( &painter, r ); } return icon; }
void QGraphicsVideoItemPrivate::updateRects() { q_ptr->prepareGeometryChange(); QSizeF videoSize; if (nativeSize.isEmpty()) { videoSize = rect.size(); } else if (aspectRatioMode == Qt::IgnoreAspectRatio) { videoSize = rect.size(); } else { // KeepAspectRatio or KeepAspectRatioByExpanding videoSize = nativeSize; videoSize.scale(rect.size(), aspectRatioMode); } displayRect = QRectF(QPointF(0, 0), videoSize); displayRect.moveCenter(rect.center()); boundingRect = displayRect.intersected(rect); }
QSizeF PushButton::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const { QSizeF hint = QGraphicsProxyWidget::sizeHint(which, constraint); if (hint.isEmpty()) { return hint; } //replace the native margin with the Svg one QStyleOption option; option.initFrom(nativeWidget()); int nativeMargin = nativeWidget()->style()->pixelMetric(QStyle::PM_ButtonMargin, &option, nativeWidget()); qreal left, top, right, bottom; d->background->getMargins(left, top, right, bottom); hint = hint - QSize(nativeMargin, nativeMargin) + QSize(left+right, top+bottom); return hint; }
void LabelGraphicsItem::setContentSize( const QSizeF &contentSize ) { QSizeF updatedSize = contentSize; if ( updatedSize.isEmpty() ) { updatedSize.setHeight( 0 ); updatedSize.setWidth( 0 ); } else { if ( d->m_minimumSize.width() > updatedSize.width() ) { updatedSize.setWidth( d->m_minimumSize.width() ); } if ( d->m_minimumSize.height() > updatedSize.height() ) { updatedSize.setHeight( d->m_minimumSize.height() ); } } FrameGraphicsItem::setContentSize( updatedSize ); }
static inline QRectF qwtScaledBoundingRect( const QwtGraphic &graphic, const QSizeF size ) { QSizeF scaledSize = size; if ( scaledSize.isEmpty() ) scaledSize = graphic.defaultSize(); const QSizeF sz = graphic.controlPointRect().size(); double sx = 1.0; if ( sz.width() > 0.0 ) sx = scaledSize.width() / sz.width(); double sy = 1.0; if ( sz.height() > 0.0 ) sy = scaledSize.height() / sz.height(); return graphic.scaledBoundingRect( sx, sy ); }
QwtGraphic Plot2DProfile::legendIcon( int /*index*/, const QSizeF& iconSize ) const { if ( iconSize.isEmpty() ){ return QwtGraphic(); } QwtGraphic icon; icon.setDefaultSize( iconSize ); icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); QPainter painter( &icon ); QPen pen( m_defaultColor ); pen.setStyle( m_penStyle ); pen.setWidth( 3 ); const double y = 0.5 * iconSize.height(); QPainterPath path; path.moveTo( 0.0, y ); path.lineTo( iconSize.width(), y ); painter.strokePath( path, pen ); return icon; }
/*! \return A rectangle filled with the color of the brush ( or the pen ) \param index Index of the legend entry ( usually there is only one ) \param size Icon size \sa setLegendIconSize(), legendData() */ QwtGraphic QwtPlotShapeItem::legendIcon( int index, const QSizeF &size ) const { Q_UNUSED( index ); QwtGraphic icon; icon.setDefaultSize( size ); if ( size.isEmpty() ) return icon; if ( d_data->legendMode == QwtPlotShapeItem::LegendShape ) { const QRectF &br = d_data->boundingRect; QPainter painter( &icon ); painter.setRenderHint( QPainter::Antialiasing, testRenderHint( QwtPlotItem::RenderAntialiased ) ); painter.translate( -br.topLeft() ); painter.setPen( d_data->pen ); painter.setBrush( d_data->brush ); painter.drawPath( d_data->shape ); } else { QColor iconColor; if ( d_data->brush.style() != Qt::NoBrush ) iconColor = d_data->brush.color(); else iconColor = d_data->pen.color(); icon = defaultIcon( iconColor, size ); } return icon; }
//------------------------------------------------------------------------ // // ThumbnailContext // //------------------------------------------------------------------------ bool ThumbnailContext::load(const QString &pixPath, int pixelSize) { mImage = QImage(); mNeedCaching = true; Orientation orientation = NORMAL; QImageReader reader(pixPath); if (!reader.canRead()) { reader.setDecideFormatFromContent(true); // Set filename again, otherwise QImageReader won't restart from scratch reader.setFileName(pixPath); } // If it's a Jpeg, try to load an embedded thumbnail, if available. // If applyExifOrientation is not set, don't use the // embedded thumbnail since it might be rotated differently // than the actual image if (reader.format() == "jpeg" && GwenviewConfig::applyExifOrientation()) { JpegContent content; content.load(pixPath); QImage thumbnail = content.thumbnail(); orientation = content.orientation(); if (qMax(thumbnail.width(), thumbnail.height()) >= pixelSize) { mImage = thumbnail; if (orientation != NORMAL && orientation != NOT_AVAILABLE) { QMatrix matrix = ImageUtils::transformMatrix(orientation); mImage = mImage.transformed(matrix); } mOriginalWidth = content.size().width(); mOriginalHeight = content.size().height(); return true; } } // Generate thumbnail from full image QSize originalSize = reader.size(); if (originalSize.isValid() && reader.supportsOption(QImageIOHandler::ScaledSize)) { QSizeF scaledSize = originalSize; scaledSize.scale(pixelSize, pixelSize, Qt::KeepAspectRatio); if (!scaledSize.isEmpty()) { reader.setScaledSize(scaledSize.toSize()); } } QImage originalImage; // format() is empty after QImageReader::read() is called QByteArray format = reader.format(); if (!reader.read(&originalImage)) { return false; } if (!originalSize.isValid()) { originalSize = originalImage.size(); } mOriginalWidth = originalSize.width(); mOriginalHeight = originalSize.height(); if (qMax(mOriginalWidth, mOriginalHeight) <= pixelSize) { mImage = originalImage; mNeedCaching = format != "png"; } else { mImage = originalImage.scaled(pixelSize, pixelSize, Qt::KeepAspectRatio); } // Rotate if necessary if (orientation != NORMAL && orientation != NOT_AVAILABLE && GwenviewConfig::applyExifOrientation()) { QMatrix matrix = ImageUtils::transformMatrix(orientation); mImage = mImage.transformed(matrix); switch (orientation) { case TRANSPOSE: case ROT_90: case TRANSVERSE: case ROT_270: qSwap(mOriginalWidth, mOriginalHeight); break; default: break; } } return true; }
/*! \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; }
/*! \brief Draw the symbol into a rectangle The symbol is painted centered and scaled into the target rectangle. It is always painted uncached and the pin point is ignored. This method is primarily intended for drawing a symbol to the legend. \param painter Painter \param rect Target rectangle for the symbol */ void QwtSymbol::drawSymbol( QPainter *painter, const QRectF &rect ) const { if ( d_data->style == QwtSymbol::NoSymbol ) return; if ( d_data->style == QwtSymbol::Graphic ) { d_data->graphic.graphic.render( painter, rect, Qt::KeepAspectRatio ); } else if ( d_data->style == QwtSymbol::Path ) { if ( d_data->path.graphic.isNull() ) { d_data->path.graphic = qwtPathGraphic( d_data->path.path, d_data->pen, d_data->brush ); } d_data->path.graphic.render( painter, rect, Qt::KeepAspectRatio ); return; } else if ( d_data->style == QwtSymbol::SvgDocument ) { #ifndef QWT_NO_SVG if ( d_data->svg.renderer ) { QRectF scaledRect; QSizeF sz = d_data->svg.renderer->viewBoxF().size(); if ( !sz.isEmpty() ) { sz.scale( rect.size(), Qt::KeepAspectRatio ); scaledRect.setSize( sz ); scaledRect.moveCenter( rect.center() ); } else { scaledRect = rect; } d_data->svg.renderer->render( painter, scaledRect ); } #endif } else { const QRect br = boundingRect(); // scale the symbol size to fit into rect. const double ratio = qMin( rect.width() / br.width(), rect.height() / br.height() ); painter->save(); painter->translate( rect.center() ); painter->scale( ratio, ratio ); const bool isPinPointEnabled = d_data->isPinPointEnabled; d_data->isPinPointEnabled = false; const QPointF pos; renderSymbols( painter, &pos, 1 ); d_data->isPinPointEnabled = isPinPointEnabled; painter->restore(); } }
QSizeF QgsLayoutItemPicture::applyItemSizeConstraint( const QSizeF &targetSize ) { QSizeF currentPictureSize = pictureSize(); QSizeF newSize = targetSize; if ( mResizeMode == QgsLayoutItemPicture::Clip ) { mPictureWidth = targetSize.width(); mPictureHeight = targetSize.height(); } else { if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) ) { QSizeF targetImageSize; if ( qgsDoubleNear( mPictureRotation, 0.0 ) ) { targetImageSize = currentPictureSize; } else { //calculate aspect ratio of bounds of rotated image QTransform tr; tr.rotate( mPictureRotation ); QRectF rotatedBounds = tr.mapRect( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ) ); targetImageSize = QSizeF( rotatedBounds.width(), rotatedBounds.height() ); } //if height has changed more than width, then fix width and set height correspondingly //else, do the opposite if ( std::fabs( rect().width() - targetSize.width() ) < std::fabs( rect().height() - targetSize.height() ) ) { newSize.setHeight( targetImageSize.height() * newSize.width() / targetImageSize.width() ); } else { newSize.setWidth( targetImageSize.width() * newSize.height() / targetImageSize.height() ); } } else if ( mResizeMode == FrameToImageSize ) { if ( !( currentPictureSize.isEmpty() ) ) { QgsLayoutSize sizeMM = mLayout->convertFromLayoutUnits( currentPictureSize, QgsUnitTypes::LayoutMillimeters ); newSize.setWidth( sizeMM.width() * 25.4 / mLayout->context().dpi() ); newSize.setHeight( sizeMM.height() * 25.4 / mLayout->context().dpi() ); } } //find largest scaling of picture with this rotation which fits in item if ( mResizeMode == Zoom || mResizeMode == ZoomResizeFrame ) { QRectF rotatedImageRect = QgsLayoutUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), QRectF( 0, 0, newSize.width(), newSize.height() ), mPictureRotation ); mPictureWidth = rotatedImageRect.width(); mPictureHeight = rotatedImageRect.height(); } else { mPictureWidth = newSize.width(); mPictureHeight = newSize.height(); } if ( newSize != targetSize ) { emit changed(); } } return newSize; }
void QgsComposerPicture::setSceneRect( const QRectF& rectangle ) { QSizeF currentPictureSize = pictureSize(); if ( mResizeMode == QgsComposerPicture::Clip ) { QgsComposerItem::setSceneRect( rectangle ); mPictureWidth = rectangle.width(); mPictureHeight = rectangle.height(); } else { QRectF newRect = rectangle; if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) ) { QSizeF targetImageSize; if ( qgsDoubleNear( mPictureRotation, 0.0 ) ) { targetImageSize = currentPictureSize; } else { //calculate aspect ratio of bounds of rotated image QTransform tr; tr.rotate( mPictureRotation ); QRectF rotatedBounds = tr.mapRect( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ) ); targetImageSize = QSizeF( rotatedBounds.width(), rotatedBounds.height() ); } //if height has changed more than width, then fix width and set height correspondingly //else, do the opposite if ( qAbs( rect().width() - rectangle.width() ) < qAbs( rect().height() - rectangle.height() ) ) { newRect.setHeight( targetImageSize.height() * newRect.width() / targetImageSize.width() ); } else { newRect.setWidth( targetImageSize.width() * newRect.height() / targetImageSize.height() ); } } else if ( mResizeMode == FrameToImageSize ) { if ( !( currentPictureSize.isEmpty() ) ) { newRect.setWidth( currentPictureSize.width() * 25.4 / mComposition->printResolution() ); newRect.setHeight( currentPictureSize.height() * 25.4 / mComposition->printResolution() ); } } //find largest scaling of picture with this rotation which fits in item if ( mResizeMode == Zoom || mResizeMode == ZoomResizeFrame ) { QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), newRect, mPictureRotation ); mPictureWidth = rotatedImageRect.width(); mPictureHeight = rotatedImageRect.height(); } else { mPictureWidth = newRect.width(); mPictureHeight = newRect.height(); } QgsComposerItem::setSceneRect( newRect ); emit itemChanged(); } if ( mMode == SVG && !mLoadingSvg ) { mLoadingSvg = true; refreshPicture(); mLoadingSvg = false; } }
void qDrawRoundedCorners(QPainter *p, qreal x1, qreal y1, qreal x2, qreal y2, const QSizeF& r1, const QSizeF& r2, Edge edge, BorderStyle s, QBrush c) { const qreal pw = (edge == TopEdge || edge == BottomEdge) ? y2-y1 : x2-x1; if (s == BorderStyle_Double) { qreal wby3 = pw/3; switch (edge) { case TopEdge: case BottomEdge: qDrawRoundedCorners(p, x1, y1, x2, y1+wby3, r1, r2, edge, BorderStyle_Solid, c); qDrawRoundedCorners(p, x1, y2-wby3, x2, y2, r1, r2, edge, BorderStyle_Solid, c); break; case LeftEdge: qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, LeftEdge, BorderStyle_Solid, c); qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, LeftEdge, BorderStyle_Solid, c); break; case RightEdge: qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, RightEdge, BorderStyle_Solid, c); qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, RightEdge, BorderStyle_Solid, c); break; default: break; } return; } else if (s == BorderStyle_Ridge || s == BorderStyle_Groove) { BorderStyle s1, s2; if (s == BorderStyle_Groove) { s1 = BorderStyle_Inset; s2 = BorderStyle_Outset; } else { s1 = BorderStyle_Outset; s2 = BorderStyle_Inset; } int pwby2 = qRound(pw/2); switch (edge) { case TopEdge: qDrawRoundedCorners(p, x1, y1, x2, y1 + pwby2, r1, r2, TopEdge, s1, c); qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, TopEdge, s2, c); break; case BottomEdge: qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, BottomEdge, s1, c); qDrawRoundedCorners(p, x1, y1, x2, y2-pwby2, r1, r2, BottomEdge, s2, c); break; case LeftEdge: qDrawRoundedCorners(p, x1, y1, x1 + pwby2, y2, r1, r2, LeftEdge, s1, c); qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, LeftEdge, s2, c); break; case RightEdge: qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, RightEdge, s1, c); qDrawRoundedCorners(p, x1, y1, x2 - pwby2, y2, r1, r2, RightEdge, s2, c); break; default: break; } } else if ((s == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge)) || (s == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge))) c = c.color().lighter(); p->save(); qreal pwby2 = pw/2; p->setBrush(Qt::NoBrush); QPen pen = qPenFromStyle(c, pw, s); pen.setCapStyle(Qt::SquareCap); // this eliminates the offby1 errors that we might hit below p->setPen(pen); switch (edge) { case TopEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x1 - r1.width() + pwby2, y1 + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, -45*16); if (!r2.isEmpty()) p->drawArc(QRectF(x2 - r2.width() + pwby2, y1 + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 45*16, 45*16); break; case BottomEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x1 - r1.width() + pwby2, y2 - 2*r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), -90 * 16, -45 * 16); if (!r2.isEmpty()) p->drawArc(QRectF(x2 - r2.width() + pwby2, y2 - 2*r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), -90 * 16, 45 * 16); break; case LeftEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x1 + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, 45*16); if (!r2.isEmpty()) p->drawArc(QRectF(x1 + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 180*16, 45*16); break; case RightEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x2 - 2*r1.width() + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 45*16, -45*16); if (!r2.isEmpty()) p->drawArc(QRectF(x2 - 2*r2.width() + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 315*16, 45*16); break; default: break; } p->restore(); }
/*! Render a plot to a file Supported formats are: - pdf\n - ps\n - svg\n - all image formats supported by Qt, see QImageWriter::supportedImageFormats() \param plot Plot widget \param fileName Path of the file, where the document will be stored \param format Format for the document \param sizeMM Size for the document in millimeters. \param resolution Resolution in dots per Inch (dpi) \sa renderTo(), render(), QwtPainter::setRoundingAlignment() */ void QwtPolarRenderer::renderDocument( QwtPolarPlot *plot, const QString &fileName, const QString &format, const QSizeF &sizeMM, int resolution ) { if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 ) return; QString title = plot->title().text(); if ( title.isEmpty() ) title = "Plot Document"; const double mmToInch = 1.0 / 25.4; const QSizeF size = sizeMM * mmToInch * resolution; const QRectF documentRect( 0.0, 0.0, size.width(), size.height() ); const QString fmt = format.toLower(); if ( format == "pdf" || format == "ps" ) { QPrinter printer; printer.setFullPage( true ); printer.setPaperSize( sizeMM, QPrinter::Millimeter ); printer.setDocName( title ); printer.setOutputFileName( fileName ); printer.setOutputFormat( ( format == "pdf" ) ? QPrinter::PdfFormat : QPrinter::PostScriptFormat ); printer.setResolution( resolution ); QPainter painter( &printer ); render( plot, &painter, documentRect ); } #ifndef QWT_NO_POLAR_SVG #ifdef QT_SVG_LIB #if QT_VERSION >= 0x040500 else if ( format == "svg" ) { QSvgGenerator generator; generator.setTitle( title ); generator.setFileName( fileName ); generator.setResolution( resolution ); generator.setViewBox( documentRect ); QPainter painter( &generator ); render( plot, &painter, documentRect ); } #endif #endif #endif else { if ( QImageWriter::supportedImageFormats().indexOf( format.toLatin1() ) >= 0 ) { const QRect imageRect = documentRect.toRect(); const int dotsPerMeter = qRound( resolution * mmToInch * 1000.0 ); QImage image( imageRect.size(), QImage::Format_ARGB32 ); image.setDotsPerMeterX( dotsPerMeter ); image.setDotsPerMeterY( dotsPerMeter ); image.fill( QColor( Qt::white ).rgb() ); QPainter painter( &image ); render( plot, &painter, imageRect ); painter.end(); image.save( fileName, format.toLatin1() ); } } }