Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

util_icon.cpp

Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           util.cpp  -  description
00009                              -------------------
00010     begin                : Fri Sep 14 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include <QFile>
00025 #include <QPixmap>
00026 #include <QRgb>
00027 
00028 #include "util_icon.h"
00029 
00030 #include "prefsmanager.h"
00031 #include "scpaths.h"
00032 #include "scpixmapcache.h"
00033 
00034 
00035 QPixmap loadIcon(const QString nam, bool forceUseColor)
00036 {
00037     static ScPixmapCache<QString> pxCache;
00038     if (pxCache.contains(nam))
00039         return *pxCache[nam];
00040 
00041     QString iconFilePath(QString("%1%2").arg(ScPaths::instance().iconDir()).arg(nam));
00042     QPixmap *pm = new QPixmap();
00043     
00044     if (!QFile::exists(iconFilePath))
00045         qWarning("Unable to load icon %s: File not found", iconFilePath.toAscii().constData());
00046     else
00047     {
00048         pm->load(iconFilePath);
00049         if (pm->isNull())
00050             qWarning("Unable to load icon %s: Got null pixmap", iconFilePath.toAscii().constData());
00051         if (PrefsManager::instance()->appPrefs.grayscaleIcons && !forceUseColor)
00052         {
00053             QImage qi(pm->toImage());
00054             int h=qi.height();
00055             int w=qi.width();
00056             QRgb c_rgb;
00057             for (int i=0;i<w;++i)
00058             {
00059                 for (int j=0;j<h;++j)
00060                 {
00061                     c_rgb=qi.pixel(i,j);
00062                     int k = qMin(qRound(0.3 * qRed(c_rgb) + 0.59 * qGreen(c_rgb) + 0.11 * qBlue(c_rgb)), 255);
00063                     qi.setPixel(i, j, qRgba(k, k, k, qAlpha(c_rgb)));
00064                 }
00065             }
00066             *pm=QPixmap::fromImage(qi);
00067         }
00068     }
00069     pxCache.insert(nam, pm);
00070     return *pm;
00071 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.