delete m_file; m_file = 0;
}
-void QuillItem::componentComplete() {
- QDeclarativeItem::componentComplete();
-}
-
void QuillItem::initialize(const QUrl& url, const QString& mimeType) {
if (m_error) {
m_error = false;
void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
Q_UNUSED(widget);
+ Q_UNUSED(option);
QRectF rect = boundingRect();
painter->fillRect(rect, Qt::black);
return;
}
- if (m_image.isNull()) {
- return;
- }
+ QImage image = m_file->image(0);
- QPoint pos((rect.width() - m_image.width()) / 2, (rect.height() - m_image.height()) / 2);
- if (!m_image.isNull()) {
- painter->drawImage(pos, m_image);
+ if (image.isNull()) {
+ return;
}
-}
-void QuillItem::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
- // TODO: rotation animation looks weird
- QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
+ QSizeF imageSize = QSizeF(image.size());
+ QSizeF widgetSize = rect.size();
+ imageSize.scale(widgetSize, Qt::KeepAspectRatio);
- m_image = QImage();
+ QPointF pos = QPointF(widgetSize.width() - imageSize.width(),
+ widgetSize.height() - imageSize.height()) / 2;
- updateImage();
+ painter->drawImage(QRectF(pos, imageSize), image, QRect(0, 0, image.width(), image.height()));
}
void QuillItem::fileLoaded() {
- updateImage();
update();
}
return false;
}
-
-void QuillItem::updateImage() {
- if (!m_file) {
- return;
- }
-
- QImage image = m_file->image(0);
-
- if (image.isNull()) {
- return;
- }
-
- m_image = image.scaled(boundingRect().size().toSize(),
- Qt::KeepAspectRatio, Qt::SmoothTransformation);
-}