File indexing completed on 2024-05-05 17:09:08

0001 /*
0002  * This file is part of the KDE project
0003  *
0004  * Copyright (C) 2013 Shantanu Tushar <shantanu@kde.org>
0005  * Copyright (C) 2013 Sujith Haridasan <sujith.h@gmail.com>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  *
0022  */
0023 
0024 #include "CQImageProvider.h"
0025 
0026 
0027 const char CQImageProvider::identificationString[] = "cqimage";
0028 CQImageProvider *CQImageProvider::s_imageProvider = 0;
0029 
0030 CQImageProvider::CQImageProvider()
0031     : QDeclarativeImageProvider(Image)
0032 {
0033 }
0034 
0035 CQImageProvider::~CQImageProvider()
0036 {
0037 
0038 }
0039 
0040 QImage CQImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
0041 {
0042     if (m_images.contains(id)) {
0043         QImage image = m_images.value(id);
0044         *size = image.size();
0045         return requestedSize.isValid() ? image.scaled(requestedSize, Qt::KeepAspectRatioByExpanding) : image;
0046     }
0047     *size = QSize();
0048     return QImage();
0049 }
0050 
0051 void CQImageProvider::addImage(const QString& id, const QImage& image)
0052 {
0053     m_images.insert(id, image);
0054 }
0055 
0056 bool CQImageProvider::containsId(const QString& id)
0057 {
0058     return m_images.contains(id);
0059 }
0060 
0061 void CQImageProvider::clearCache()
0062 {
0063     m_images.clear();
0064 }