/** * 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(); }
QSizeF ContentWindowController::getMaxSize() const { QSizeF maxSize = getMaxContentSize(); maxSize.rwidth() *= _contentWindow->getZoomRect().size().width(); maxSize.rheight() *= _contentWindow->getZoomRect().size().height(); return maxSize; }
QImage GLImageDrawable::applyBorder(const QImage& sourceImg) { if(renderBorder() && m_borderWidth > 0.001) { QSizeF originalSizeWithBorder = sourceImg.size(); double x = m_borderWidth * 2; originalSizeWithBorder.rwidth() += x; originalSizeWithBorder.rheight() += x; QImage cache(originalSizeWithBorder.toSize(),QImage::Format_ARGB32_Premultiplied); memset(cache.scanLine(0),0,cache.byteCount()); QPainter p(&cache); int bw = (int)(m_borderWidth / 2); p.drawImage(bw,bw,sourceImg); //drawImage(bw,bw,sourceImg); p.setPen(QPen(m_borderColor,m_borderWidth)); p.drawRect(sourceImg.rect().adjusted(bw,bw,bw,bw)); //QRectF(sourceImg.rect()).adjusted(-bw,-bw,bw,bw)); m_imageWithBorder = cache; return cache; } if(!m_imageWithBorder.isNull()) m_imageWithBorder = QImage(); return sourceImg; }
void KStandardItemListWidget::updateTextsCache() { QTextOption textOption; switch (m_layout) { case IconsLayout: textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); textOption.setAlignment(Qt::AlignHCenter); break; case CompactLayout: case DetailsLayout: textOption.setAlignment(Qt::AlignLeft); textOption.setWrapMode(QTextOption::NoWrap); break; default: Q_ASSERT(false); break; } qDeleteAll(m_textInfo); m_textInfo.clear(); for (int i = 0; i < m_sortedVisibleRoles.count(); ++i) { TextInfo* textInfo = new TextInfo(); textInfo->staticText.setTextFormat(Qt::PlainText); textInfo->staticText.setPerformanceHint(QStaticText::AggressiveCaching); textInfo->staticText.setTextOption(textOption); m_textInfo.insert(m_sortedVisibleRoles[i], textInfo); } switch (m_layout) { case IconsLayout: updateIconsLayoutTextCache(); break; case CompactLayout: updateCompactLayoutTextCache(); break; case DetailsLayout: updateDetailsLayoutTextCache(); break; default: Q_ASSERT(false); break; } const TextInfo* ratingTextInfo = m_textInfo.value("rating"); if (ratingTextInfo) { // The text of the rating-role has been set to empty to get // replaced by a rating-image showing the rating as stars. const KItemListStyleOption& option = styleOption(); QSizeF ratingSize = preferredRatingSize(option); const qreal availableWidth = (m_layout == DetailsLayout) ? columnWidth("rating") - columnPadding(option) : size().width(); if (ratingSize.width() > availableWidth) { ratingSize.rwidth() = availableWidth; } m_rating = QPixmap(ratingSize.toSize()); m_rating.fill(Qt::transparent); QPainter painter(&m_rating); const QRect rect(0, 0, m_rating.width(), m_rating.height()); const int rating = data().value("rating").toInt(); KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating); } else if (!m_rating.isNull()) { m_rating = QPixmap(); } }
void ResolutionCalculator::on_acceptButton_clicked() { if ((hRes>0) && (vRes>0)) { QSizeF s = image->data()->getTransformedSizeData(ImageDataStore::PixelSize); s.rwidth() *= hRes; s.rheight() *= vRes; image->data()->setTransformedSizeData(ImageDataStore::PhysicalSize, s); } rulers.clear(); }
void QgsDiagramRendererV2::convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const { if ( !size.isValid() ) { return; } double pixelToMap = context.scaleFactor() * context.mapToPixel().mapUnitsPerPixel(); size.rwidth() *= pixelToMap; size.rheight() *= pixelToMap; }
QRect QtopiaPrintEngine::paperRect() const { QSizeF s = qt_paperSizeToQSizeF(d_func()->paperSize); s.rwidth() = MM(s.width()); s.rheight() = MM(s.height()); int w = qRound(s.width()*d_func()->resolution/72.); int h = qRound(s.height()*d_func()->resolution/72.); if (d_func()->orientation == QPrinter::Portrait) return QRect(0, 0, w, h); else return QRect(0, 0, h, w); }
void AbstractDiagram::paintMarker( QPainter* painter, const DataValueAttributes& a, const QModelIndex& index, const QPointF& pos ) { if ( !checkInvariants() || !a.isVisible() ) return; const MarkerAttributes ma = a.markerAttributes(); if ( !ma.isVisible() ) return; const PainterSaver painterSaver( painter ); QSizeF maSize = ma.markerSize(); const qreal diagramWidth = d->diagramSize.width(); const qreal diagramHeight = d->diagramSize.height(); switch( ma.markerSizeMode() ) { case MarkerAttributes::AbsoluteSize: // Unscaled, i.e. without the painter's "zoom" maSize.rwidth() /= painter->matrix().m11(); maSize.rheight() /= painter->matrix().m22(); break; case MarkerAttributes::AbsoluteSizeScaled: // Keep maSize as is. It is specified directly in pixels and desired // to be effected by the painter's "zoom". break; case MarkerAttributes::RelativeToDiagramWidth: maSize *= diagramWidth; break; case MarkerAttributes::RelativeToDiagramHeight: maSize *= diagramHeight; break; case MarkerAttributes::RelativeToDiagramWidthHeightMin: maSize *= qMin( diagramWidth, diagramHeight ); break; } QBrush indexBrush( brush( index ) ); QPen indexPen( ma.pen() ); if ( ma.markerColor().isValid() ) indexBrush.setColor( ma.markerColor() ); paintMarker( painter, ma, indexBrush, indexPen, pos, maSize ); // workaround: BC cannot be changed, otherwise we would pass the // index down to next-lower paintMarker function. So far, we // basically save a circle of radius maSize at pos in the // reverseMapper. This means that ^^^ this version of paintMarker // needs to be called to reverse-map the marker. d->reverseMapper.addCircle( index.row(), index.column(), pos, 2 * maSize ); }
void QgsDiagramRendererV2::convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const { if ( !size.isValid() ) { return; } int dpi = dpiPaintDevice( context.constPainter() ); if ( dpi < 0 ) { return; } double pixelToMap = dpi / 25.4 * context.mapToPixel().mapUnitsPerPixel(); size.rwidth() *= pixelToMap; size.rheight() *= pixelToMap; }
QSizeF QuickGridDefinition::cellSize(QRectF rect, int row, int column, int rowSpan, int columnSpan) { QSizeF size; for(int end = qMin(row + rowSpan, rowCount()); row < end; row++) { size.rheight() += rowWeight(row) * rect.height(); } for(int end = qMin(column + columnSpan, columnCount()); column < end; column++) { size.rwidth() += columnWeight(column) * rect.width(); } return size; }
void KItemListViewLayouter::doLayout() { if (m_dirty) { #ifdef KITEMLISTVIEWLAYOUTER_DEBUG QElapsedTimer timer; timer.start(); #endif m_visibleIndexesDirty = true; QSizeF itemSize = m_itemSize; QSizeF itemMargin = m_itemMargin; QSizeF size = m_size; const bool grouped = createGroupHeaders(); const bool horizontalScrolling = (m_scrollOrientation == Qt::Horizontal); if (horizontalScrolling) { // Flip everything so that the layout logically can work like having // a vertical scrolling itemSize.transpose(); itemMargin.transpose(); size.transpose(); if (grouped) { // In the horizontal scrolling case all groups are aligned // at the top, which decreases the available height. For the // flipped data this means that the width must be decreased. size.rwidth() -= m_groupHeaderHeight; } } m_columnWidth = itemSize.width() + itemMargin.width(); const qreal widthForColumns = size.width() - itemMargin.width(); m_columnCount = qMax(1, int(widthForColumns / m_columnWidth)); m_xPosInc = itemMargin.width(); const int itemCount = m_model->count(); if (itemCount > m_columnCount && m_columnWidth >= 32) { // Apply the unused width equally to each column const qreal unusedWidth = widthForColumns - m_columnCount * m_columnWidth; if (unusedWidth > 0) { const qreal columnInc = unusedWidth / (m_columnCount + 1); m_columnWidth += columnInc; m_xPosInc += columnInc; } } int rowCount = itemCount / m_columnCount; if (itemCount % m_columnCount != 0) { ++rowCount; } m_itemInfos.resize(itemCount); qreal y = m_headerHeight + itemMargin.height(); int row = 0; int index = 0; while (index < itemCount) { qreal x = m_xPosInc; qreal maxItemHeight = itemSize.height(); if (grouped) { if (horizontalScrolling) { // All group headers will always be aligned on the top and not // flipped like the other properties x += m_groupHeaderHeight; } if (m_groupItemIndexes.contains(index)) { // The item is the first item of a group. // Increase the y-position to provide space // for the group header. if (index > 0) { // Only add a margin if there has been added another // group already before y += m_groupHeaderMargin; } else if (!horizontalScrolling) { // The first group header should be aligned on top y -= itemMargin.height(); } if (!horizontalScrolling) { y += m_groupHeaderHeight; } } } int column = 0; while (index < itemCount && column < m_columnCount) { qreal requiredItemHeight = itemSize.height(); if (m_sizeHintResolver) { const QSizeF sizeHint = m_sizeHintResolver->sizeHint(index); const qreal sizeHintHeight = horizontalScrolling ? sizeHint.width() : sizeHint.height(); if (sizeHintHeight > requiredItemHeight) { requiredItemHeight = sizeHintHeight; } } ItemInfo& itemInfo = m_itemInfos[index]; itemInfo.rect = QRectF(x, y, itemSize.width(), requiredItemHeight); itemInfo.column = column; itemInfo.row = row; if (grouped && horizontalScrolling) { // When grouping is enabled in the horizontal mode, the header alignment // looks like this: // Header-1 Header-2 Header-3 // Item 1 Item 4 Item 7 // Item 2 Item 5 Item 8 // Item 3 Item 6 Item 9 // In this case 'requiredItemHeight' represents the column-width. We don't // check the content of the header in the layouter to determine the required // width, hence assure that at least a minimal width of 15 characters is given // (in average a character requires the halve width of the font height). // // TODO: Let the group headers provide a minimum width and respect this width here const qreal headerWidth = minimumGroupHeaderWidth(); if (requiredItemHeight < headerWidth) { requiredItemHeight = headerWidth; } } maxItemHeight = qMax(maxItemHeight, requiredItemHeight); x += m_columnWidth; ++index; ++column; if (grouped && m_groupItemIndexes.contains(index)) { // The item represents the first index of a group // and must aligned in the first column break; } } y += maxItemHeight + itemMargin.height(); ++row; } if (itemCount > 0) { // Calculate the maximum y-range of the last row for m_maximumScrollOffset m_maximumScrollOffset = m_itemInfos.last().rect.bottom(); const qreal rowY = m_itemInfos.last().rect.y(); int index = m_itemInfos.count() - 2; while (index >= 0 && m_itemInfos[index].rect.bottom() >= rowY) { m_maximumScrollOffset = qMax(m_maximumScrollOffset, m_itemInfos[index].rect.bottom()); --index; } m_maximumScrollOffset += itemMargin.height(); m_maximumItemOffset = m_columnCount * m_columnWidth; } else { m_maximumScrollOffset = 0; m_maximumItemOffset = 0; } #ifdef KITEMLISTVIEWLAYOUTER_DEBUG kDebug() << "[TIME] doLayout() for " << m_model->count() << "items:" << timer.elapsed(); #endif m_dirty = false; } updateVisibleIndexes(); }
static inline void combineSize(QSizeF &result, const QSizeF &fallbackSize) { combineHints(result.rwidth(), fallbackSize.width()); combineHints(result.rheight(), fallbackSize.height()); }