krita/ui

kis_bookmarked_filter_configurations_model.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_bookmarked_filter_configurations_model.h"
00020 #include <QPixmap>
00021 
00022 #include <filter/kis_filter.h>
00023 #include <filter/kis_filter_configuration.h>
00024 #include <kis_paint_device.h>
00025 
00026 struct KisBookmarkedFilterConfigurationsModel::Private {
00027     KisPaintDeviceSP thumb;
00028     KisFilterSP filter;
00029     QHash<int, QImage> previewCache;
00030 };
00031 
00032 KisBookmarkedFilterConfigurationsModel::KisBookmarkedFilterConfigurationsModel(KisPaintDeviceSP thumb, KisFilterSP filter)
00033         : KisBookmarkedConfigurationsModel(filter->bookmarkManager()), d(new Private)
00034 {
00035     d->thumb = thumb;
00036     d->filter = filter;
00037 }
00038 
00039 KisBookmarkedFilterConfigurationsModel::~KisBookmarkedFilterConfigurationsModel()
00040 {
00041     delete d;
00042 }
00043 
00044 QVariant KisBookmarkedFilterConfigurationsModel::data(const QModelIndex &index, int role) const
00045 {
00046     if (!index.isValid()) {
00047         return QVariant();
00048     }
00049     if (role == Qt::DecorationRole) {
00050         if (!d->previewCache.contains(index.row())) {
00051             KisPaintDeviceSP target = new KisPaintDevice(*d->thumb);
00052             d->filter->process(target, QRect(0, 0, 100, 100), configuration(index));
00053             d->previewCache[index.row()] = target->convertToQImage(0);
00054         }
00055         return d->previewCache[index.row()];
00056     } else {
00057         return KisBookmarkedConfigurationsModel::data(index, role);
00058     }
00059 }
00060 
00061 KisFilterConfiguration* KisBookmarkedFilterConfigurationsModel::configuration(const QModelIndex &index) const
00062 {
00063     KisFilterConfiguration* config = dynamic_cast<KisFilterConfiguration*>(KisBookmarkedConfigurationsModel::configuration(index));
00064     if (config) return config;
00065     return d->filter->defaultConfiguration(d->thumb);
00066 }