Warning, file /office/calligra/libs/pageapp/KoPAPageThumbnailModel.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) 2008 Fredy Yanardi <fyanardi@gmail.com> 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 "KoPAPageThumbnailModel.h" 0021 0022 #include <QIcon> 0023 0024 #include <klocalizedstring.h> 0025 0026 #include "KoPAPageBase.h" 0027 0028 KoPAPageThumbnailModel::KoPAPageThumbnailModel(const QList<KoPAPageBase *> &pages, QObject *parent) 0029 : QAbstractListModel(parent), 0030 m_pages(pages), 0031 m_iconSize(512, 512) 0032 { 0033 } 0034 0035 KoPAPageThumbnailModel::~KoPAPageThumbnailModel() 0036 { 0037 } 0038 0039 int KoPAPageThumbnailModel::rowCount(const QModelIndex &parent) const 0040 { 0041 if (!parent.isValid()) 0042 return m_pages.size(); 0043 0044 return 0; 0045 } 0046 0047 QModelIndex KoPAPageThumbnailModel::index(int row, int column, const QModelIndex &parent) const 0048 { 0049 if (!parent.isValid()) { 0050 if (row >= 0 && row < m_pages.size()) 0051 return createIndex(row, column, m_pages.at(row)); 0052 } 0053 0054 return QModelIndex(); 0055 } 0056 0057 QVariant KoPAPageThumbnailModel::data(const QModelIndex &index, int role) const 0058 { 0059 if (!index.isValid()) { 0060 return QVariant(); 0061 } 0062 0063 if (role == Qt::DisplayRole) { 0064 QString name = m_pages.at( index.row() )->name(); 0065 if ( name.isEmpty() ) { 0066 if(m_pages.at(index.row() )->pageType() == KoPageApp::Slide ) { 0067 name = i18n( "Slide %1", index.row() + 1 ); 0068 } else { 0069 name = i18n( "Page %1", index.row() + 1 ); 0070 } 0071 } 0072 return name; 0073 } 0074 else if (role == Qt::DecorationRole) { 0075 return QIcon( m_pages.at(index.row())->thumbnail( m_iconSize ) ); 0076 } 0077 0078 return QVariant(); 0079 } 0080 0081 void KoPAPageThumbnailModel::setIconSize(const QSize &size) 0082 { 0083 m_iconSize = size; 0084 }