File indexing completed on 2024-05-05 16:39:00

0001 /* This file is part of the KDE project
0002    Copyright (C) 1998-2009 Carsten Pfeiffer <pfeiffer@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, version 2.
0007 
0008    This program is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011     General Public License for more details.
0012 
0013    You should have received a copy of the GNU General Public License
0014    along with this program; see the file COPYING.  If not, write to
0015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016    Boston, MA 02110-1301, USA.
0017  */
0018 
0019 #include "imagemods.h"
0020 
0021 
0022 QCache<QUrl, ImageMods>* ImageMods::s_modifications = 0L;
0023 
0024 QCache<QUrl, ImageMods>* ImageMods::getInstance() {
0025     if ( !s_modifications) {
0026         s_modifications = new QCache<QUrl, ImageMods>(kdata->modificationCacheSize);
0027     }
0028     return s_modifications;
0029 }
0030 
0031 
0032 void ImageMods::rememberFor(KuickImage *kuim)
0033 {
0034     QCache<QUrl, ImageMods>* instance = getInstance();
0035 
0036     ImageMods *mods = instance->object(kuim->url());
0037     if ( !mods )
0038     {
0039         mods = new ImageMods();
0040         instance->insert(kuim->url(), mods);
0041     }
0042 
0043     mods->width = kuim->width();
0044     mods->height = kuim->height();
0045     mods->rotation = kuim->absRotation();
0046     mods->flipMode = kuim->flipMode();
0047 }
0048 
0049 bool ImageMods::restoreFor(KuickImage *kuim, ImData *idata)
0050 {
0051     ImageMods *mods = getInstance()->object(kuim->url());
0052     if ( mods )
0053     {
0054         kuim->rotateAbs( mods->rotation );
0055         kuim->flipAbs( mods->flipMode );
0056         kuim->resize( mods->width, mods->height, idata->smoothScale ? KuickImage::SMOOTH : KuickImage::FAST );
0057         return true;
0058     }
0059 
0060     return false;
0061 }