File indexing completed on 2024-05-12 05:09:50

0001 /***************************************************************************
0002     Copyright (C) 2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #include "imageinfo.h"
0026 #include "image.h"
0027 #include "imagefactory.h"
0028 
0029 using namespace Tellico;
0030 using Tellico::Data::ImageInfo;
0031 
0032 ImageInfo::ImageInfo(const Data::Image& img_)
0033     : id(img_.id())
0034     , format(img_.format())
0035     , linkOnly(img_.linkOnly())
0036     , m_width(img_.width())
0037     , m_height(img_.height()) {
0038 }
0039 
0040 ImageInfo::ImageInfo(const QString& id_, const QByteArray& format_, int w_, int h_, bool l_)
0041     : id(id_)
0042     , format(format_)
0043     , linkOnly(l_)
0044     , m_width(w_)
0045     , m_height(h_) {
0046 }
0047 
0048 int ImageInfo::width(bool loadIfNecessary) const {
0049   if(m_width < 1 && loadIfNecessary) {
0050     const Image& img = ImageFactory::imageById(id);
0051     if(!img.isNull()) {
0052       m_width = img.width();
0053       m_height = img.height();
0054     }
0055   }
0056   return m_width;
0057 }
0058 
0059 int ImageInfo::height(bool loadIfNecessary) const {
0060   if(m_height < 1 && loadIfNecessary) {
0061     const Image& img = ImageFactory::imageById(id);
0062     if(!img.isNull()) {
0063       m_width = img.width();
0064       m_height = img.height();
0065     }
0066   }
0067   return m_height;
0068 }