QRectF CartesianChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const { QSizeF left; QSizeF right; QSizeF bottom; QSizeF top; foreach (ChartAxisElement *axis, axes) { QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); if (!axis->isVisible()) continue; switch (axis->axis()->alignment()) { case Qt::AlignLeft: left.setWidth(left.width() + size.width()); left.setHeight(qMax(left.height(), size.height())); break; case Qt::AlignRight: right.setWidth(right.width() + size.width()); right.setHeight(qMax(right.height(), size.height())); break; case Qt::AlignTop: top.setWidth(qMax(top.width(), size.width())); top.setHeight(top.height() + size.height()); break; case Qt::AlignBottom: bottom.setWidth(qMax(bottom.width(), size.width())); bottom.setHeight(bottom.height() + size.height()); break; } }
QSizeF CanvasSize::size(SizeUnits unit) const { QSizeF result; result.setWidth( toPixels(m_size.width(), m_resolution.width(), m_size_unit, m_resolution_unit) ); result.setHeight( toPixels(m_size.height(), m_resolution.height(), m_size_unit, m_resolution_unit) ); if (unit != Pixels) { result.setWidth( fromPixels(result.width(), m_resolution.width(), unit, m_resolution_unit) ); result.setHeight( fromPixels(result.height(), m_resolution.height(), unit, m_resolution_unit) ); } return result; }
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; }
QSizeF targetSize() const { QSizeF size = imageData->imageSize(); if (targetImageSizePercent.width() > 0.0) size.setWidth(0.01 * targetImageSizePercent.width() * size.width()); else if (targetImageSize.width() > 0.0) size.setWidth(targetImageSize.width()); if (targetImageSizePercent.height() > 0.0) size.setHeight(0.01 * targetImageSizePercent.height() * size.height()); else if (targetImageSize.height() > 0.0) size.setHeight(targetImageSize.height()); return size; }
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; }
QSizeF UIGraphicsScrollArea::minimumSizeHint() const { /* Minimum size-hint of scroll-bar by default: */ QSizeF msh = m_pScrollBar->minimumSizeHint(); if (m_pViewport) { switch (m_enmOrientation) { case Qt::Horizontal: { /* Expand it with viewport height: */ const int iWidgetHeight = m_pViewport->size().height(); if (msh.height() < iWidgetHeight) msh.setHeight(iWidgetHeight); break; } case Qt::Vertical: { /* Expand it with viewport width: */ const int iWidgetWidth = m_pViewport->size().width(); if (msh.width() < iWidgetWidth) msh.setWidth(iWidgetWidth); break; } } } return msh; }
void KPathShapePrivate::applyViewboxTransformation(const KXmlElement &element) { Q_Q(KPathShape); // apply viewbox transformation QRectF viewBox = q->loadOdfViewbox(element); if (! viewBox.isEmpty()) { // load the desired size QSizeF size; size.setWidth(KUnit::parseValue(element.attributeNS(KOdfXmlNS::svg, "width", QString()))); size.setHeight(KUnit::parseValue(element.attributeNS(KOdfXmlNS::svg, "height", QString()))); // load the desired position QPointF pos; pos.setX(KUnit::parseValue(element.attributeNS(KOdfXmlNS::svg, "x", QString()))); pos.setY(KUnit::parseValue(element.attributeNS(KOdfXmlNS::svg, "y", QString()))); // create matrix to transform original path data into desired size and position QTransform viewMatrix; viewMatrix.translate(-viewBox.left(), -viewBox.top()); viewMatrix.scale(size.width() / viewBox.width(), size.height() / viewBox.height()); viewMatrix.translate(pos.x(), pos.y()); // transform the path data map(viewMatrix); } }
/** * @brief cwRegionLoadTask::loadSizeF * @param protoSize * @return */ QSizeF cwRegionLoadTask::loadSizeF(const QtProto::QSizeF &protoSize) { QSizeF size; size.setWidth(protoSize.width()); size.setHeight(protoSize.height()); return size; }
/** * Reimplemented from UMLWidget::updateGeometry to calculate * minimum size for signal widget based on the current signal type. */ void SignalWidget::updateGeometry() { QSizeF minSize = textItemGroupAt(GroupIndex)->minimumSize(); if (minSize.width() < SignalWidget::MinimumSize.width()) { minSize.setWidth(SignalWidget::MinimumSize.width()); } if (m_signalType == SignalWidget::Accept) { // We need 1/3rd part for the '>' shape.(hollow or convex) minSize.rwidth() += minSize.width() / 3 + margin(); } else if (m_signalType == SignalWidget::Send) { // Add one third for the '>' shape. minSize.rwidth() += minSize.width() / 3 + margin(); } else if (m_signalType == SignalWidget::Time) { // In case of SignalWidget::Time add minimum height to // calculated as the text appears below drawing. minSize.rheight() += SignalWidget::MinimumSize.height(); } setMinimumSize(minSize); UMLWidget::updateGeometry(); }
void RightClickStrategy::createNewFolder() { FolderShape *fs = new FolderShape(); // TODO show dialog to name the folder fs->setName("New folder"); if (m_canvas->itemStore()->folders().count() == 1 && m_canvas->itemStore()->folders()[0]->border() == 0) { // the first new folder, lets be kinds and resize the folders to make it managable for the user. FolderShape *oldFolder = m_canvas->itemStore()->folders()[0]; oldFolder->update(); oldFolder->setBorder(new FolderBorder()); KInsets insets = oldFolder->insets(); oldFolder->setPosition(QPointF(insets.left, insets.top)); QSizeF size = oldFolder->size(); // we can assume size is the size of the whole widget. So we just make each use half of that. size.setWidth(size.width() / 2.); oldFolder->setSize(size); if (oldFolder->model()->count()) { // Make sure we don't resize the folder to small for its contents. QPointF bottom = oldFolder->model()->shapes().last()->absolutePosition(KFlake::BottomRightCorner); if (bottom.y() > size.height()) oldFolder->setSize(QSizeF(size.width(), bottom.y())); } oldFolder->update(); fs->setPosition(QPointF(size.width(), insets.top)); fs->setSize(size); } else { fs->setAbsolutePosition(m_lastPosition); fs->setSize(QSizeF(150, 100)); } m_canvas->itemStore()->addFolder(fs); }
qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const { qreal left, top, right, bottom; getContentsMargins(&left, &top, &right, &bottom); const qreal maxw = geom.width() - left - right; qreal x = 0; qreal y = 0; qreal maxRowHeight = 0; QSizeF pref; for (int i = 0; i < m_items.count(); ++i) { QGraphicsLayoutItem *item = m_items.at(i); pref = item->effectiveSizeHint(Qt::PreferredSize); maxRowHeight = qMax(maxRowHeight, pref.height()); qreal next_x; next_x = x + pref.width(); if (next_x > maxw) { if (x == 0) { pref.setWidth(maxw); } else { x = 0; next_x = pref.width(); } y += maxRowHeight + spacing(Qt::Vertical); maxRowHeight = 0; } if (applyNewGeometry) item->setGeometry(QRectF(QPointF(left + x, top + y), pref)); x = next_x + spacing(Qt::Horizontal); } maxRowHeight = qMax(maxRowHeight, pref.height()); return top + y + maxRowHeight + bottom; }
static void expandSize(QSizeF &result, const QSizeF &size) { if (size.width() >= 0 && size.width() > result.width()) result.setWidth(size.width()); if (size.height() >= 0 && size.height() > result.height()) result.setHeight(size.height()); }
// -------------------------------------------------------------------------------------------------------------------------------------- QVariant CSizeGrip::itemChange(GraphicsItemChange change, const QVariant &value) { switch(change) { case QGraphicsItem::ItemPositionChange: { QPointF nextPos = value.toPointF(); QPointF targetPos = pos() - nextPos; QSizeF resultSize = gWindow()->size() - QSizeF(targetPos.x(), targetPos.y()); if(resultSize.width() < gWindow()->minSize().width()) { resultSize.setWidth(gWindow()->minSize().width()); nextPos.setX(pos().x()); } if(resultSize.height() < gWindow()->minSize().height()) { resultSize.setHeight(gWindow()->minSize().height()); nextPos.setY(pos().y()); } gWindow()->setSize(resultSize); return nextPos; } break; default: return QGraphicsItem::itemChange(change, value); } return QGraphicsItem::itemChange(change, value); }
static void combineSize(QSizeF &result, const QSizeF &size) { if (result.width() < 0) result.setWidth(size.width()); if (result.height() < 0) result.setHeight(size.height()); }
QSizeF readSize(QDomElement e) { QSizeF p; p.setWidth(e.attribute("w", "0.0").toDouble()); p.setHeight(e.attribute("h", "0.0").toDouble()); return p; }
void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) { Q_Q(QDeclarativeLoader); if (!item || updatingSize) return; updatingSize = true; if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(item)) { if (!itemWidthValid) q->setImplicitWidth(qmlItem->implicitWidth()); else q->setImplicitWidth(qmlItem->width()); if (loaderGeometryChanged && q->widthValid()) qmlItem->setWidth(q->width()); if (!itemHeightValid) q->setImplicitHeight(qmlItem->implicitHeight()); else q->setImplicitHeight(qmlItem->height()); if (loaderGeometryChanged && q->heightValid()) qmlItem->setHeight(q->height()); } else if (item && item->isWidget()) { QGraphicsWidget *widget = static_cast<QGraphicsWidget*>(item); QSizeF widgetSize = widget->size(); q->setImplicitWidth(widgetSize.width()); if (loaderGeometryChanged && q->widthValid()) widgetSize.setWidth(q->width()); q->setImplicitHeight(widgetSize.height()); if (loaderGeometryChanged && q->heightValid()) widgetSize.setHeight(q->height()); if (widget->size() != widgetSize) widget->resize(widgetSize); } updatingSize = false; }
void BSplineVisDialog::on_printButton_clicked() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save PDF File"), "/tmpfs", tr("PDF File (*.pdf)")); if (fileName.isNull()) { return; } QGraphicsScene printerScene; renderScene(printerScene, true); QPrinter printer(QPrinter::HighResolution); QSizeF paperSize; paperSize.setWidth(printerScene.sceneRect().width()); paperSize.setHeight(printerScene.sceneRect().height()); printer.setPaperSize(paperSize, QPrinter::Millimeter); printer.setPageMargins(5, 5, 5, 5, QPrinter::Millimeter); printer.setOrientation(QPrinter::Portrait); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); QPainter painter(&printer); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform | QPainter::NonCosmeticDefaultPen); printerScene.render(&painter); painter.end(); }
QVariant XmlQSizeFSerializator::loadValue() { QSizeF size; size.setWidth(node()->attribute("width").toDouble()); size.setHeight(node()->attribute("height").toDouble()); return size; }
bool AbstractScrollArea::event(QEvent *e) { if (e->type() == QEvent::ApplicationLayoutDirectionChange || e->type() == QEvent::LayoutDirectionChange) { } else if (e->type() == QEvent::GraphicsSceneResize) { QGraphicsSceneResizeEvent *event = static_cast<QGraphicsSceneResizeEvent*>(e); QSizeF newSize = event->newSize(); QRectF hrect = m_horizontalScrollBar->boundingRect(); QRectF vrect = m_verticalScrollBar->boundingRect(); QSizeF vpSize = newSize; if (m_horizontalScrollBarPolicy != Qt::ScrollBarAlwaysOff) vpSize.setHeight(newSize.height() - hrect.height()); if (m_verticalScrollBarPolicy != Qt::ScrollBarAlwaysOff) vpSize.setWidth(newSize.width() - vrect.width()); m_viewport->resize(vpSize); adjustScrollBars(); } return QGraphicsWidget::event(e); }
QString LayoutTabSI::doCommand(QString x) { if(x.startsWith("getLayout")) { x.remove(0,9); QSizeF f; if(x.contains("Margin")) { f=vi->layoutMargins(); } else if(x.contains("Spacing")) { f=vi->layoutSpacing(); } else { return ""; } if(x.contains("Horizontal")) { return QString::number(f.width()); } else if(x.contains("Vertical")) { return QString::number(f.height()); } } else if(x.startsWith("setLayout")) { x.remove(0,9); QSizeF f; if(x.contains("Margin")) { f=vi->layoutMargins(); } else if(x.contains("Spacing")) { f=vi->layoutSpacing(); } else { return ""; } if(x.contains("Horizontal")) { x.remove(0,x.indexOf("(")); x.remove(x.indexOf(")"),99999); f.setWidth(x.toInt()); } else if(x.contains("Vertical")) { x.remove(0,x.indexOf("(")); x.remove(x.indexOf(")"),99999); f.setWidth(x.toInt()); } else { return ""; } if(x.contains("Margin")) { vi->setLayoutMargins(f); } else if(x.contains("Spacing")) { vi->setLayoutSpacing(f); } return "Done"; } return ""; }
QSizeF CaretInterface::textSize(const QString& text) { QFontMetrics metrics(m_font); QSizeF s = metrics.size(Qt::TextSingleLine, text); s.setWidth( s.width() + 4 ); s.setHeight( s.height() + 2 ); return s; }
void PlotExporter::guessPlotDimensions(const QwtPlot *plot, const double currentWidth, QSizeF &dimensions) { const QRect &plotDims = plot->geometry(); const qreal plotRatio = static_cast<qreal>(plotDims.width()) / static_cast<qreal>(plotDims.height()); dimensions.setWidth(currentWidth); dimensions.setHeight(currentWidth / plotRatio); }
NS_IMETHODIMP nsPrintSettingsQt::SetPaperWidth(double aPaperWidth) { QSizeF papersize = mQPrinter->paperSize(GetQtUnit(mPaperSizeUnit)); papersize.setWidth(aPaperWidth); mQPrinter->setPaperSize(papersize, GetQtUnit(mPaperSizeUnit)); return NS_OK; }
void PrintLayout::printTable() const { QTextDocument doc; QSizeF pageSize; pageSize.setWidth(pageRect.width()); pageSize.setHeight(pageRect.height()); doc.setPageSize(pageSize); QString styleSheet( "<style type='text/css'>" \ "table {" \ " border-width: 1px;" \ " border-style: solid;" \ " border-color: #999999;" \ "}" \ "th {" \ " background-color: #eeeeee;" \ " font-size: small;" \ " padding: 3px 5px 3px 5px;" \ "}" \ "td {" \ " font-size: small;" \ " padding: 3px 5px 3px 5px;" \ "}" \ "</style>" ); // setDefaultStyleSheet() doesn't work here? QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>"; QString htmlTextPrev; int pageCountNew = 1, pageCount; bool insertHeading = true; int i; struct dive *dive; for_each_dive(i, dive) { if (!dive->selected && printOptions->print_selected) continue; if (insertHeading) { htmlText += insertTableHeadingRow(); insertHeading = false; } htmlTextPrev = htmlText; htmlText += insertTableDataRow(dive); doc.setHtml(htmlText); pageCount = pageCountNew; pageCountNew = doc.pageCount(); /* if the page count increases after adding this row we 'revert' * and add a heading instead. */ if (pageCountNew > pageCount) { htmlText = htmlTextPrev; insertHeading = true; i--; } } htmlText += "</table>"; doc.setHtml(htmlText); doc.print(printer); }
QSizeF RecycledListItem::effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint) const { QSizeF s = m_item->effectiveSizeHint(which,constraint); if (m_item2) s.setWidth(s.width()*2); if (s.height()<MinItemHeight) s.setHeight(MinItemHeight); return s; }
QSizeF XmlReader::readSize() { Q_ASSERT(tokenType() == QXmlStreamReader::StartElement); QSizeF p; p.setWidth(doubleAttribute("w", 0.0)); p.setHeight(doubleAttribute("h", 0.0)); skipCurrentElement(); return p; }
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 ); }
QSizeF GraphicsNodeSocket:: getMinimalSize() const { QSizeF size; QFont font; QFontMetrics fm(font); int text_width = fm.width(_text); const qreal text_height = static_cast<qreal>(fm.height()); size.setWidth(std::max(_min_width, _circle_radius*2 + _text_offset + text_width + _pen_width)); size.setHeight(std::max(_min_height, text_height + _pen_width)); return size; }
/** * Reimplemented from UMLWidget::updateGeometry to calculate * minimum size for this widget based on the current state of this * widget. */ void ClassifierWidget::updateGeometry() { // Min size including classifier and template box. QSizeF totalMinSize; UMLWidget::SizeHintOption sizeHintOption = UMLWidget::AddMargin; // Min size for classifier items and header (doesn't include template) QSizeF headerSize = textItemGroupAt(HeaderGroupIndex)->minimumSize(); QSizeF attribOpSize = textItemGroupAt(AttribOpGroupIndex)->minimumSize(); QSizeF classifierMinSize; // combined size classifierMinSize.setWidth(qMax(headerSize.width(), attribOpSize.width())); classifierMinSize.setHeight(headerSize.height() + attribOpSize.height()); if (shouldDrawAsCircle()) { qreal minDiameter = 2 * ClassifierWidget::CircleMinimumRadius; // only header items are drawn, so total min size should include only that. totalMinSize.setWidth(qMax(headerSize.width(), minDiameter)); totalMinSize.setHeight(headerSize.height() + minDiameter); } else { // Draw the bounding rectangle QSizeF templateBoxSize = textItemGroupAt(TemplateGroupIndex)->minimumSize(); if (textItemGroupAt(TemplateGroupIndex)->textItemCount() == 0) { // If we don't have template params use entire size for header, params and operations. totalMinSize = classifierMinSize; } else { // minus margin() below because to overlap a bit. totalMinSize.setHeight(classifierMinSize.height() + templateBoxSize.height() - margin()); totalMinSize.setWidth(classifierMinSize.width() + .5 * templateBoxSize.width()); // Dont add margin as we have already added manually sizeHintOption = UMLWidget::DontAddMargin; } } setMinimumSize(totalMinSize, sizeHintOption); setSize(totalMinSize); UMLWidget::updateGeometry(); }
QSizeF QGLE::qtSizeToGLE(QSizeF qt, double dpi) { // DO NOT RELY ON THIS FOR ACCURACY! double gleX, gleY; qt.setWidth(qt.width() - 2*GS_OFFSET*dpi); qt.setHeight(qt.height() - 2*GS_OFFSET*dpi); QPointF rel = relQtToGLE(qt.width(), qt.height(), dpi); gleX = rel.x(); gleY = rel.y(); return(QSizeF(gleX,gleY)); }