• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kiconengine.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "kiconengine_p.h"
00020 
00021 #include <QPainter>
00022 #include <QMenu>
00023 #include <QToolBar>
00024 #include <QApplication>
00025 
00026 #include <kiconloader.h>
00027 
00028 class KIconEngine::Private
00029 {
00030 public:
00031     QString iconName;
00032     QStringList overlays;
00033     KIconLoader* iconLoader;
00034 };
00035 
00036 KIconEngine::KIconEngine(const QString& iconName, KIconLoader* iconLoader, const QStringList &overlays)
00037     : d(new Private)
00038 {
00039     d->iconName = iconName;
00040     d->iconLoader = iconLoader;
00041     d->overlays = overlays;
00042 }
00043 
00044 KIconEngine::KIconEngine(const QString& iconName, KIconLoader* iconLoader)
00045     : d(new Private)
00046 {
00047     d->iconName = iconName;
00048     d->iconLoader = iconLoader;
00049 }
00050 
00051 KIconEngine::~KIconEngine()
00052 {
00053     delete d;
00054 }
00055 
00056 static int qIconModeToKIconState( QIcon::Mode mode )
00057 {
00058     int kstate;
00059     switch (mode) {
00060     default:
00061     case QIcon::Normal:
00062         kstate = KIconLoader::DefaultState;
00063         break;
00064     case QIcon::Active:
00065         kstate = KIconLoader::ActiveState;
00066         break;
00067     case QIcon::Disabled:
00068         kstate = KIconLoader::DisabledState;
00069         break;
00070     }
00071     return kstate;
00072 }
00073 
00074 QSize KIconEngine::actualSize( const QSize & size, QIcon::Mode mode, QIcon::State state )
00075 {
00076     Q_UNUSED(state)
00077     const int kstate = qIconModeToKIconState(mode);
00078     QPixmap pix = iconLoader()->loadIcon(d->iconName, KIconLoader::Desktop,
00079                                          qMin(size.width(), size.height()),
00080                                          kstate, d->overlays);
00081     return pix.size();
00082 }
00083 
00084 void KIconEngine::paint( QPainter * painter, const QRect & rect, QIcon::Mode mode, QIcon::State state )
00085 {
00086     Q_UNUSED(state)
00087 
00088     const int kstate = qIconModeToKIconState(mode);
00089     KIconLoader::Group group = KIconLoader::Desktop;
00090 
00091     if (QWidget* targetWidget = dynamic_cast<QWidget*>(painter->device())) {
00092         if (qobject_cast<QMenu*>(targetWidget))
00093             group = KIconLoader::Small;
00094         else if (qobject_cast<QToolBar*>(targetWidget->parent()))
00095             group = KIconLoader::Toolbar;
00096     }
00097 
00098     const int iconSize = qMin(rect.width(), rect.height());
00099     QPixmap pix = iconLoader()->loadIcon(d->iconName, group, iconSize, kstate, d->overlays);
00100     painter->drawPixmap(rect, pix);
00101 }
00102 
00103 const QString & KIconEngine::iconName( ) const
00104 {
00105     return d->iconName;
00106 }
00107 
00108 KIconLoader * KIconEngine::iconLoader( ) const
00109 {
00110     return d->iconLoader;
00111 }
00112 
00113 QPixmap KIconEngine::pixmap( const QSize & size, QIcon::Mode mode, QIcon::State state )
00114 {
00115     Q_UNUSED(state)
00116 
00117     QPixmap pix(size);
00118     pix.fill(QColor(0,0,0,0));
00119 
00120     QPainter painter(&pix);
00121 
00122     const int kstate = qIconModeToKIconState(mode);
00123     const int iconSize = qMin(size.width(), size.height());
00124 
00125     painter.drawPixmap(QPoint(), iconLoader()->loadIcon(d->iconName, KIconLoader::Desktop,
00126                                                         iconSize, kstate, d->overlays));
00127 
00128     return pix;
00129 }
00130 
00131 QString KIconEngine::key() const
00132 {
00133     return QLatin1String("KIconEngine");
00134 }
00135 
00136 QIconEngineV2 *KIconEngine::clone() const
00137 {
00138     return new KIconEngine(d->iconName, d->iconLoader, d->overlays);
00139 }
00140 
00141 bool KIconEngine::read(QDataStream &in)
00142 {
00143     in >> d->iconName >> d->overlays;
00144     return true;
00145 }
00146 
00147 bool KIconEngine::write(QDataStream &out) const
00148 {
00149     out << d->iconName << d->overlays;
00150     return true;
00151 }
00152 

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal