File indexing completed on 2024-05-12 13:04:47
0001 /* 0002 * This file is part of the KDE project 0003 * SPDX-FileCopyrightText: 2013 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "CQThumbnailItem.h" 0009 0010 #include <QPainter> 0011 0012 class CQThumbnailItem::Private 0013 { 0014 public: 0015 Private() : contentWidth(-1), contentHeight(-1) { } 0016 0017 QPixmap content; 0018 QString source; 0019 int contentWidth; 0020 int contentHeight; 0021 }; 0022 0023 CQThumbnailItem::CQThumbnailItem(QDeclarativeItem* parent) 0024 : QDeclarativeItem(parent), d(new Private) 0025 { 0026 setFlag(QGraphicsItem::ItemHasNoContents, false); 0027 } 0028 0029 CQThumbnailItem::~CQThumbnailItem() 0030 { 0031 delete d; 0032 } 0033 0034 void CQThumbnailItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* ) 0035 { 0036 if (!d->content.isNull()) { 0037 QPixmap pixmap = d->content.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 0038 int xpos = (width() - pixmap.width()) / 2; 0039 int ypos = (height() - pixmap.height()) / 2; 0040 painter->drawPixmap(xpos, ypos, pixmap); 0041 } 0042 } 0043 0044 QPixmap CQThumbnailItem::content() const 0045 { 0046 return d->content; 0047 } 0048 0049 void CQThumbnailItem::setContent(const QPixmap& content) 0050 { 0051 d->content = content; 0052 emit contentChanged(); 0053 update(); 0054 }