Item *GfxBlockItem::newImage(QImage img, QUrl src, QPointF pos) { ASSERT(data()->book()); ASSERT(data()->resManager()); double maxW = availableWidth(); double maxH = maxW; double scale = 1; if (scale*img.width()>maxW) scale = maxW/img.width(); if (scale*img.height()>maxH) scale = maxH/img.height(); if (allChildren().isEmpty()) pos = QPointF(0, 0); else pos -= QPointF(img.width(),img.height())*(scale/2); pos = constrainPointToRect(pos, boundingRect()); Resource *res = data()->resManager()->importImage(img, src); QString resName = res->tag(); GfxImageData *gid = new GfxImageData(resName, img, data()); gid->setScale(scale); gid->setPos(pos); GfxImageItem *gii = new GfxImageItem(gid, this); gii->makeWritable(); resetPosition(); sizeToFit(); return gii; }
int KoDocumentSectionDelegate::thumbnailHeight(const QStyleOptionViewItem &option, const QModelIndex &index) const { const QSize size = index.data(Qt::SizeHintRole).toSize(); int width = option.rect.width(); if (!option.rect.isValid()) width = availableWidth(); if (size.width() <= width) return size.height(); else return int(width / (qreal(size.width()) / size.height())); }
QSize KoDocumentSectionDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { switch(d->view->displayMode()) { case View::ThumbnailMode: { const int height = thumbnailHeight(option, index) + textBoxHeight(option) + d->margin * 2; return QSize(availableWidth(), height); } case View::DetailedMode: return QSize(option.rect.width(), textBoxHeight(option) + option.decorationSize.height() + d->margin); case View::MinimalMode: return QSize(option.rect.width(), textBoxHeight(option)); default: return option.rect.size(); } }
QRectF GfxBlockItem::boundingRect() const { /* This returns the bounds of our grid and has nothing to do with children. */ return QRectF(0, data()->yref(), availableWidth(), data()->height()); }