Warning, file /office/calligra/libs/main/KoTemplate.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2000 Werner Trobin <trobin@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoTemplate.h" 0021 0022 #include <QImage> 0023 #include <QPixmap> 0024 0025 #include <MainDebug.h> 0026 0027 #include <kiconloader.h> 0028 0029 0030 KoTemplate::KoTemplate(const QString &name, const QString &description, const QString &file, 0031 const QString &picture, const QString &fileName, const QString &_measureSystem, 0032 const QString &color, const QString &swatch, const QString &variantName, bool wide, 0033 bool hidden, bool touched) : 0034 m_name(name), m_descr(description), m_file(file), m_picture(picture), m_fileName(fileName), 0035 m_color(color), m_swatch(swatch), m_variantName(variantName), m_wide(wide), 0036 m_hidden(hidden), m_touched(touched), m_cached(false), m_measureSystem(_measureSystem) 0037 { 0038 } 0039 0040 const QPixmap &KoTemplate::loadPicture() 0041 { 0042 if (m_cached) 0043 return m_pixmap; 0044 m_cached = true; 0045 if (m_picture[ 0 ] == '/') { 0046 QImage img(m_picture); 0047 if (img.isNull()) { 0048 qWarning() << "Couldn't find icon " << m_picture; 0049 m_pixmap = QPixmap(); 0050 return m_pixmap; 0051 } 0052 const int maxHeightWidth = 128; // ### TODO: some people would surely like to have 128x128 0053 if (img.width() > maxHeightWidth || img.height() > maxHeightWidth) { 0054 img = img.scaled(maxHeightWidth, maxHeightWidth, Qt::KeepAspectRatio, Qt::SmoothTransformation); 0055 } 0056 m_pixmap = QPixmap::fromImage(img); 0057 return m_pixmap; 0058 } else { // relative path 0059 m_pixmap = KIconLoader::global()->loadIcon(m_picture, KIconLoader::Desktop, 128); 0060 return m_pixmap; 0061 } 0062 } 0063