Index: kiconloader.h =================================================================== --- kiconloader.h (revisión: 719351) +++ kiconloader.h (copia de trabajo) @@ -23,10 +23,11 @@ #define KICONLOADER_H #include +#include #include #include -#include +#include class QIcon; class QMovie; @@ -35,9 +36,10 @@ class QPixmap; struct KIconGroup; class KIconThemeNode; class KComponentData; -struct KIconLoaderPrivate; +class KIconLoaderPrivate; class KStandardDirs; class KIconEffect; +class KIconTheme; /** @@ -56,12 +58,12 @@ class KIconEffect; * * The standard groups are defined below. * - * @li K3Icon::Desktop: Icons in the iconview of konqueror, kdesktop and similar apps. - * @li K3Icon::Toolbar: Icons in toolbars. - * @li K3Icon::MainToolbar: Icons in the main toolbars. - * @li K3Icon::Small: Various small (typical 16x16) places: titlebars, listviews + * @li KIconLoader::Desktop: Icons in the iconview of konqueror, kdesktop and similar apps. + * @li KIconLoader::Toolbar: Icons in toolbars. + * @li KIconLoader::MainToolbar: Icons in the main toolbars. + * @li KIconLoader::Small: Various small (typical 16x16) places: titlebars, listviews * and menu entries. - * @li K3Icon::Panel: Icons in kicker's panel + * @li KIconLoader::Panel: Icons in kicker's panel * * The icons are stored on disk in an icon theme or in a standalone * directory. The icon theme directories contain multiple sizes and/or @@ -81,6 +83,96 @@ class KDEUI_EXPORT KIconLoader : public public: /** + * Defines the context of the icon. + */ + enum Context { + Any, ///< Some icon with unknown purpose. + Action, ///< An action icon (e.g. 'save', 'print'). + Application, ///< An icon that represents an application. + Device, ///< An icon that represents a device. + FileSystem, ///< An icon that represents a file system. + MimeType, ///< An icon that represents a mime type (or file type). + Animation, ///< An icon that is animated. + Category, ///< An icon that represents a category. + Emblem, ///< An icon that adds information to an existing icon. + Emote, ///< An icon that expresses an emotion. + International, ///< An icon that represents a country's flag. + Place, ///< An icon that represents a location (e.g. 'home', 'trash'). + StatusIcon ///< An icon that represents an event. + }; + + /** + * The type of the icon. + */ + enum Type { + Fixed, ///< Fixed-size icon. + Scalable, ///< Scalable-size icon. + Threshold ///< A threshold icon. + }; + + /** + * The type of a match. + */ + enum MatchType { + MatchExact, ///< Only try to find an exact match. + MatchBest ///< Take the best match if there is no exact match. + }; + + /** + * The group of the icon. + */ + enum Group { + /// No group + NoGroup=-1, + /// Desktop icons + Desktop=0, + /// First group + FirstGroup=0, + /// Toolbar icons + Toolbar, + /// Main toolbar icons + MainToolbar, + /// Small icons, e.g. for buttons + Small, + /// Panel (Kicker) icons + Panel, + /// Icons for use in dialog titles, page lists, etc + Dialog, + /// Last group + LastGroup, + /// User icons + User + }; + + /** + * These are the standard sizes for icons. + */ + enum StdSizes { + /// small icons for menu entries + SizeSmall=16, + /// slightly larger small icons for toolbars, panels, etc + SizeSmallMedium=22, + /// medium sized icons for the desktop + SizeMedium=32, + /// large sized icons for the panel + SizeLarge=48, + /// huge sized icons for iconviews + SizeHuge=64, + /// enormous sized icons for iconviews + SizeEnormous=128 + }; + + /** + * Defines the possible states of an icon. + */ + enum States { + DefaultState, ///< The default state. + ActiveState, ///< Icon is active. + DisabledState, ///< Icon is disabled. + LastState ///< Last state (last constant) + }; + + /** * Constructs an iconloader. * @param appname Add the data directories of this application to the * icon search path for the "User" group. The default argument adds the @@ -134,7 +226,7 @@ public: * @param group The icon group. This will specify the size of and effects to * be applied to the icon. * @param size If nonzero, this overrides the size specified by @p group. - * See K3Icon::StdSizes. + * See KIconLoader::StdSizes. * @param state The icon state: @p DefaultState, @p ActiveState or * @p DisabledState. Depending on the user's preferences, the iconloader * may apply a visual effect to hint about its state. @@ -147,8 +239,8 @@ public: * @return the QPixmap. Can be null when not found, depending on * @p canReturnNull. */ - QPixmap loadIcon(const QString& name, K3Icon::Group group, int size=0, - int state=K3Icon::DefaultState, const QStringList &overlays = QStringList(), + QPixmap loadIcon(const QString& name, KIconLoader::Group group, int size=0, + int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList(), QString *path_store=0L, bool canReturnNull=false) const; @@ -160,7 +252,7 @@ public: * @param group The icon group. This will specify the size of and effects to * be applied to the icon. * @param size If nonzero, this overrides the size specified by @p group. - * See K3Icon::StdSizes. + * See KIconLoader::StdSizes. * @param state The icon state: @p DefaultState, @p ActiveState or * @p DisabledState. Depending on the user's preferences, the iconloader * may apply a visual effect to hint about its state. @@ -171,8 +263,8 @@ public: * @return the QPixmap. Can not be null, the * "unknown" pixmap is returned when no appropriate icon has been found. */ - QPixmap loadMimeTypeIcon( const QString& iconName, K3Icon::Group group, int size=0, - int state=K3Icon::DefaultState, const QStringList &overlays = QStringList(), + QPixmap loadMimeTypeIcon( const QString& iconName, KIconLoader::Group group, int size=0, + int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList(), QString *path_store=0 ) const; /** @@ -183,7 +275,7 @@ public: * @param group The icon group. This will specify the size of and effects to * be applied to the icon. * @param size If nonzero, this overrides the size specified by @p group. - * See K3Icon::StdSizes. + * See KIconLoader::StdSizes. * @param canReturnNull Can return a null iconset? If false, iconset * containing the "unknown" pixmap is returned when no appropriate icon has * been found. @@ -192,7 +284,7 @@ public: * * @deprecated use KIcon instead, which uses the iconloader internally */ - KDE_DEPRECATED QIcon loadIconSet(const QString& name, K3Icon::Group group, int size = 0, + KDE_DEPRECATED QIcon loadIconSet(const QString& name, KIconLoader::Group group, int size = 0, bool canReturnNull = false); /** @@ -203,7 +295,7 @@ public: * @param group_or_size If positive, search icons whose size is * specified by the icon group @p group_or_size. If negative, search * icons whose size is - @p group_or_size. - * See K3Icon::Group and K3Icon::StdSizes + * See KIconLoader::Group and KIconLoader::StdSizes * @param canReturnNull Can return a null string? If not, a path to the * "unknown" icon will be returned. * @return the path of an icon, can be null or the "unknown" icon when @@ -217,23 +309,23 @@ public: * @param name The name of the icon. * @param group The icon group. See loadIcon(). * @param size Override the default size for @p group. - * See K3Icon::StdSizes. + * See KIconLoader::StdSizes. * @param parent The parent object of the returned QMovie. * @return A QMovie object. Can be null if not found or not valid. * Ownership is passed to the caller. */ - QMovie *loadMovie(const QString& name, K3Icon::Group group, int size=0, QObject *parent=0) const; + QMovie *loadMovie(const QString& name, KIconLoader::Group group, int size=0, QObject *parent=0) const; /** * Returns the path to an animated icon. * @param name The name of the icon. * @param group The icon group. See loadIcon(). * @param size Override the default size for @p group. - * See K3Icon::StdSizes. + * See KIconLoader::StdSizes. * @return the full path to the movie, ready to be passed to QMovie's constructor. * Empty string if not found. */ - QString moviePath(const QString& name, K3Icon::Group group, int size=0) const; + QString moviePath(const QString& name, KIconLoader::Group group, int size=0) const; /** * Loads an animated icon as a series of still frames. If you want to load @@ -241,11 +333,11 @@ public: * @param name The name of the icon. * @param group The icon group. See loadIcon(). * @param size Override the default size for @p group. - * See K3Icon::StdSizes. + * See KIconLoader::StdSizes. * @return A QStringList containing the absolute path of all the frames * making up the animation. */ - QStringList loadAnimated(const QString& name, K3Icon::Group group, int size=0) const; + QStringList loadAnimated(const QString& name, KIconLoader::Group group, int size=0) const; /** * Queries all available icons for a specific group, having a specific @@ -253,30 +345,30 @@ public: * @param group_or_size If positive, search icons whose size is * specified by the icon group @p group_or_size. If negative, search * icons whose size is - @p group_or_size. - * See K3Icon::Group and K3Icon::StdSizes + * See KIconLoader::Group and KIconLoader::StdSizes * @param context The icon context. * @return a list of all icons */ - QStringList queryIcons(int group_or_size, K3Icon::Context context=K3Icon::Any) const; + QStringList queryIcons(int group_or_size, KIconLoader::Context context=KIconLoader::Any) const; /** * Queries all available icons for a specific context. * @param group_or_size The icon preferred group or size. If available * at this group or size, those icons will be returned, in other case, * icons of undefined size will be returned. Positive numbers are groups, - * negative numbers are negated sizes. See K3Icon::Group and - * K3Icon::StdSizes + * negative numbers are negated sizes. See KIconLoader::Group and + * KIconLoader::StdSizes * @param context The icon context. * @return A QStringList containing the icon names * available for that context */ QStringList queryIconsByContext(int group_or_size, - K3Icon::Context context=K3Icon::Any) const; + KIconLoader::Context context=KIconLoader::Any) const; /** * @internal */ - bool hasContext( K3Icon::Context context ) const; + bool hasContext( KIconLoader::Context context ) const; /** * Returns a list of all icons (*.png or *.xpm extension) in the @@ -291,7 +383,7 @@ public: * @param group the group to check. * @return the current size for an icon group. */ - int currentSize(K3Icon::Group group) const; + int currentSize(KIconLoader::Group group) const; /** * Returns a pointer to the current theme. Can be used to query @@ -328,7 +420,7 @@ public: * @return true if alpha blending is desired * @obsolete */ - bool alphaBlending( K3Icon::Group group ) const; + bool alphaBlending( KIconLoader::Group group ) const; /** * Adds all the default themes from other desktops at the end of @@ -349,48 +441,6 @@ public: void newIconLoader(); private: - /** - * @internal - */ - void init( const QString& _appname, KStandardDirs *_dirs ); - - /** - * @internal - */ - bool initIconThemes(); - - /** - * @internal - * tries to find an icon with the name. It tries some extension and - * match strategies - */ - K3Icon findMatchingIcon(const QString& name, int size) const; - - /** - * @internal - * Adds themes installed in the application's directory. - **/ - void addAppThemes(const QString& appname); - - /** - * Adds all themes that are part of this node and the themes - * below (the fallbacks of the theme) in the tree. - * @internal - */ - void addBaseThemes(KIconThemeNode *node, const QString &appname); - - /** - * @internal - * return the path for the unknown icon in that size - */ - QString unknownIconPath( int size ) const; - - /** - * Checks if name ends in one of the supported icon formats (i.e. .png) - * and returns the name without the extension if it does. - */ - QString removeIconExtension(const QString &name) const; - // @internal the data object KIconLoaderPrivate *d; }; @@ -400,7 +450,7 @@ public: * Load a desktop icon. */ KDEUI_EXPORT QPixmap DesktopIcon(const QString& name, int size=0, - int state=K3Icon::DefaultState, const QStringList& overlays = QStringList()); + int state=KIconLoader::DefaultState, const QStringList& overlays = QStringList()); /** * \relates KIconLoader @@ -413,7 +463,7 @@ KDEUI_EXPORT_DEPRECATED QIcon DesktopIco * \relates KIconLoader * Load a toolbar icon. */ -KDEUI_EXPORT QPixmap BarIcon(const QString& name, int size=0, int state=K3Icon::DefaultState, +KDEUI_EXPORT QPixmap BarIcon(const QString& name, int size=0, int state=KIconLoader::DefaultState, const QStringList& overlays = QStringList()); /** @@ -428,7 +478,7 @@ KDEUI_EXPORT_DEPRECATED QIcon BarIconSet * Load a small icon. */ KDEUI_EXPORT QPixmap SmallIcon(const QString& name, int size=0, - int state=K3Icon::DefaultState, const QStringList &overlays = QStringList()); + int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList()); /** * \relates KIconLoader @@ -442,7 +492,7 @@ KDEUI_EXPORT_DEPRECATED QIcon SmallIconS * Load a main toolbar icon. */ KDEUI_EXPORT QPixmap MainBarIcon(const QString& name, int size=0, - int state=K3Icon::DefaultState, const QStringList &overlays = QStringList()); + int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList()); /** * \relates KIconLoader @@ -455,7 +505,7 @@ KDEUI_EXPORT_DEPRECATED QIcon MainBarIco * \relates KIconLoader * Load a user icon. User icons are searched in $appdir/pics. */ -KDEUI_EXPORT QPixmap UserIcon(const QString& name, int state=K3Icon::DefaultState, const QStringList &overlays = QStringList()); +KDEUI_EXPORT QPixmap UserIcon(const QString& name, int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList()); /** * \relates KIconLoader @@ -468,6 +518,9 @@ KDEUI_EXPORT_DEPRECATED QIcon UserIconSe * \relates KIconLoader * Returns the current icon size for a specific group. */ -KDEUI_EXPORT int IconSize(K3Icon::Group group); +KDEUI_EXPORT int IconSize(KIconLoader::Group group); + +inline KIconLoader::Group& operator++(KIconLoader::Group& group) { group = static_cast(group+1); return group; } +inline KIconLoader::Group operator++(KIconLoader::Group& group,int) { KIconLoader::Group ret = group; ++group; return ret; } #endif // KICONLOADER_H Index: kiconengine_p.h =================================================================== --- kiconengine_p.h (revisión: 719351) +++ kiconengine_p.h (copia de trabajo) @@ -42,7 +42,7 @@ class KIconEngine : public QIconEngineV2 * * @param iconName the name of the icon to load * @param iconLoader The KDE icon loader that this engine is to use. - * @param overlays Add one or more overlays to the icon. See K3Icon::Overlays. + * @param overlays Add one or more overlays to the icon. See KIconLoader::Overlays. * * @sa KIconLoader */ Index: kiconloader_p.h =================================================================== --- kiconloader_p.h (revisión: 0) +++ kiconloader_p.h (revisión: 0) @@ -0,0 +1,76 @@ +/** + * This file is part of the KDE project, module kdecore. + * Copyright (C) 2000 Geert Jansen + * Antonio Larrosa + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef KICONLOADER_P_H +#define KICONLOADER_P_H + +#include "kiconloader.h" + +/** + * @internal + * One icon as found by KIconTheme. Also serves as a namespace containing + * icon related constants. + * @see KIconEffect + * @see KIconTheme + * @see KIconLoader + */ +class K3Icon +{ +public: + K3Icon(); + ~K3Icon(); + + /** + * Return true if this icon is valid, false otherwise. + */ + bool isValid() const; + + /** + * The size in pixels of the icon. + */ + int size; + + /** + * The context of the icon. + */ + KIconLoader::Context context; + + /** + * The type of the icon: Fixed, Scalable or Threshold. + **/ + KIconLoader::Type type; + + /** + * The threshold in case type == Threshold + */ + int threshold; + + /** + * The full path of the icon. + */ + QString path; + +private: + class KIconPrivate; + KIconPrivate * d; +}; + +#endif // KICONLOADER_P_H Index: kiconeffect.cpp =================================================================== --- kiconeffect.cpp (revisión: 719351) +++ kiconeffect.cpp (copia de trabajo) @@ -153,7 +153,7 @@ bool KIconEffect::hasEffect(int group, i QString KIconEffect::fingerprint(int group, int state) const { - if ( group >= K3Icon::LastGroup ) return ""; + if ( group >= KIconLoader::LastGroup ) return ""; QString cached = d->key[group][state]; if (cached.isEmpty()) { @@ -183,12 +183,12 @@ QString KIconEffect::fingerprint(int gro QImage KIconEffect::apply(const QImage &image, int group, int state) const { - if (state >= K3Icon::LastState) + if (state >= KIconLoader::LastState) { kDebug(265) << "Illegal icon state: " << state << "\n"; return image; } - if (group >= K3Icon::LastGroup) + if (group >= KIconLoader::LastGroup) { kDebug(265) << "Illegal icon group: " << group << "\n"; return image; @@ -244,12 +244,12 @@ QImage KIconEffect::apply(const QImage & QPixmap KIconEffect::apply(const QPixmap &pixmap, int group, int state) const { - if (state >= K3Icon::LastState) + if (state >= KIconLoader::LastState) { kDebug(265) << "Illegal icon state: " << state << "\n"; return pixmap; } - if (group >= K3Icon::LastGroup) + if (group >= KIconLoader::LastGroup) { kDebug(265) << "Illegal icon group: " << group << "\n"; return pixmap; Index: kiconeffect.h =================================================================== --- kiconeffect.h (revisión: 719351) +++ kiconeffect.h (copia de trabajo) @@ -75,12 +75,12 @@ public: /** * Tests whether an effect has been configured for the given icon group. - * @param group the group to check, see K3Icon::Group - * @param state the state to check, see K3Icon::States + * @param group the group to check, see KIconLoader::Group + * @param state the state to check, see KIconLoader::States * @returns true if an effect is configured for the given @p group * in @p state, otherwise false. - * @see K3Icon::Group - * K3Icon::States + * @see KIconLoader::Group + * KIconLoader::States */ bool hasEffect(int group, int state) const; @@ -88,8 +88,8 @@ public: * Returns a fingerprint for the effect by encoding * the given @p group and @p state into a QString. This * is useful for caching. - * @param group the group, see K3Icon::Group - * @param state the state, see K3Icon::States + * @param group the group, see KIconLoader::Group + * @param state the state, see KIconLoader::States * @return the fingerprint of the given @p group+@p state */ QString fingerprint(int group, int state) const; @@ -98,8 +98,8 @@ public: * Applies an effect to an image. The effect to apply depends on the * @p group and @p state parameters, and is configured by the user. * @param src The image. - * @param group The group for the icon, see K3Icon::Group - * @param state The icon's state, see K3Icon::States + * @param group The group for the icon, see KIconLoader::Group + * @param state The icon's state, see KIconLoader::States * @return An image with the effect applied. */ QImage apply(const QImage &src, int group, int state) const; @@ -119,8 +119,8 @@ public: /** * Applies an effect to a pixmap. * @param src The pixmap. - * @param group The group for the icon, see K3Icon::Group - * @param state The icon's state, see K3Icon::States + * @param group The group for the icon, see KIconLoader::Group + * @param state The icon's state, see KIconLoader::States * @return A pixmap with the effect applied. */ QPixmap apply(const QPixmap &src, int group, int state) const; Index: kicontheme.cpp =================================================================== --- kicontheme.cpp (revisión: 719351) +++ kicontheme.cpp (copia de trabajo) @@ -22,6 +22,7 @@ */ #include "kicontheme.h" +#include "kiconloader_p.h" #include #include @@ -79,8 +80,8 @@ public: QStringList iconList() const; QString dir() const { return mDir; } - K3Icon::Context context() const { return mContext; } - K3Icon::Type type() const { return mType; } + KIconLoader::Context context() const { return mContext; } + KIconLoader::Type type() const { return mType; } int size() const { return mSize; } int minSize() const { return mMinSize; } int maxSize() const { return mMaxSize; } @@ -88,8 +89,8 @@ public: private: bool mbValid; - K3Icon::Type mType; - K3Icon::Context mContext; + KIconLoader::Type mType; + KIconLoader::Context mContext; int mSize, mMinSize, mMaxSize; int mThreshold; @@ -222,7 +223,7 @@ KIconTheme::KIconTheme(const QString& na foreach(KIconThemeDir *dir, d->mDirs) { if(!dir) break; - if ((dir->type() == K3Icon::Scalable) && !scIcons.contains(dir->size())) + if ((dir->type() == KIconLoader::Scalable) && !scIcons.contains(dir->size())) { QList lst; for (i=dir->minSize(); i<=dir->maxSize(); i++) @@ -313,9 +314,9 @@ int KIconTheme::depth() const return d->mDepth; } -int KIconTheme::defaultSize(K3Icon::Group group) const +int KIconTheme::defaultSize(KIconLoader::Group group) const { - if ((group < 0) || (group >= K3Icon::LastGroup)) + if ((group < 0) || (group >= KIconLoader::LastGroup)) { kDebug(264) << "Illegal icon group: " << group << "\n"; return -1; @@ -323,10 +324,10 @@ int KIconTheme::defaultSize(K3Icon::Grou return d->mDefSize[group]; } -QList KIconTheme::querySizes(K3Icon::Group group) const +QList KIconTheme::querySizes(KIconLoader::Group group) const { QList empty; - if ((group < 0) || (group >= K3Icon::LastGroup)) + if ((group < 0) || (group >= KIconLoader::LastGroup)) { kDebug(264) << "Illegal icon group: " << group << "\n"; return empty; @@ -334,7 +335,7 @@ QList KIconTheme::querySizes(K3Icon return d->mSizes[group]; } -QStringList KIconTheme::queryIcons(int size, K3Icon::Context context) const +QStringList KIconTheme::queryIcons(int size, KIconLoader::Context context) const { int delta = 1000, dw; @@ -345,20 +346,20 @@ QStringList KIconTheme::queryIcons(int s for(int i=0; imDirs.size(); ++i) { dir = d->mDirs.at(i); - if ((context != K3Icon::Any) && (context != dir->context())) + if ((context != KIconLoader::Any) && (context != dir->context())) continue; - if ((dir->type() == K3Icon::Fixed) && (dir->size() == size)) + if ((dir->type() == KIconLoader::Fixed) && (dir->size() == size)) { result += dir->iconList(); continue; } - if ((dir->type() == K3Icon::Scalable) && + if ((dir->type() == KIconLoader::Scalable) && (size >= dir->minSize()) && (size <= dir->maxSize())) { result += dir->iconList(); continue; } - if ((dir->type() == K3Icon::Threshold) && + if ((dir->type() == KIconLoader::Threshold) && (abs(size-dir->size())threshold())) result+=dir->iconList(); } @@ -370,7 +371,7 @@ QStringList KIconTheme::queryIcons(int s for(int i=0; imDirs.size(); ++i) { dir = d->mDirs.at(i); - if ((context != K3Icon::Any) && (context != dir->context())) + if ((context != KIconLoader::Any) && (context != dir->context())) continue; dw = dir->size() - size; if ((dw > 6) || (abs(dw) >= abs(delta))) @@ -384,7 +385,7 @@ QStringList KIconTheme::queryIcons(int s return best->iconList(); } -QStringList KIconTheme::queryIconsByContext(int size, K3Icon::Context context) const +QStringList KIconTheme::queryIconsByContext(int size, KIconLoader::Context context) const { int dw; KIconThemeDir *dir; @@ -400,7 +401,7 @@ QStringList KIconTheme::queryIconsByCont for(int i=0;imDirs.size();++i) { dir = d->mDirs.at(i); - if ((context != K3Icon::Any) && (context != dir->context())) + if ((context != KIconLoader::Any) && (context != dir->context())) continue; dw = abs(dir->size() - size); iconlist[(dw<127)?dw:127]+=dir->iconList(); @@ -412,15 +413,15 @@ QStringList KIconTheme::queryIconsByCont return iconlistResult; } -bool KIconTheme::hasContext(K3Icon::Context context) const +bool KIconTheme::hasContext(KIconLoader::Context context) const { foreach(KIconThemeDir *dir, d->mDirs) - if ((context == K3Icon::Any) || (context == dir->context())) + if ((context == KIconLoader::Any) || (context == dir->context())) return true; return false; } -K3Icon KIconTheme::iconPath(const QString& name, int size, K3Icon::MatchType match) const +K3Icon KIconTheme::iconPath(const QString& name, int size, KIconLoader::MatchType match) const { K3Icon icon; QString path; @@ -433,23 +434,23 @@ K3Icon KIconTheme::iconPath(const QStrin { dir = d->mDirs.at(i); - if (match == K3Icon::MatchExact) + if (match == KIconLoader::MatchExact) { - if ((dir->type() == K3Icon::Fixed) && (dir->size() != size)) + if ((dir->type() == KIconLoader::Fixed) && (dir->size() != size)) continue; - if ((dir->type() == K3Icon::Scalable) && + if ((dir->type() == KIconLoader::Scalable) && ((size < dir->minSize()) || (size > dir->maxSize()))) continue; - if ((dir->type() == K3Icon::Threshold) && + if ((dir->type() == KIconLoader::Threshold) && (abs(dir->size()-size) > dir->threshold())) continue; } else { // dw < 0 means need to scale up to get an icon of the requested size - if (dir->type() == K3Icon::Fixed) + if (dir->type() == KIconLoader::Fixed) { dw = dir->size() - size; - } else if (dir->type() == K3Icon::Scalable) + } else if (dir->type() == KIconLoader::Scalable) { if (size < dir->minSize()) dw = dir->minSize() - size; @@ -457,7 +458,7 @@ K3Icon KIconTheme::iconPath(const QStrin dw = dir->maxSize() - size; else dw = 0; - } else if (dir->type() == K3Icon::Threshold) + } else if (dir->type() == KIconLoader::Threshold) { if (size < dir->size() - dir->threshold()) dw = dir->size() - dir->threshold() - size; @@ -485,7 +486,7 @@ K3Icon KIconTheme::iconPath(const QStrin icon.context = dir->context(); // if we got in MatchExact that far, we find no better - if (match == K3Icon::MatchExact) + if (match == KIconLoader::MatchExact) return icon; else { @@ -605,56 +606,56 @@ KIconThemeDir::KIconThemeDir(const QStri mSize = config.readEntry("Size", 0); mMinSize = 1; // just set the variables to something mMaxSize = 50; // meaningful in case someone calls minSize or maxSize - mType = K3Icon::Fixed; + mType = KIconLoader::Fixed; if (mSize == 0) return; QString tmp = config.readEntry("Context"); if (tmp == "Devices") - mContext = K3Icon::Device; + mContext = KIconLoader::Device; else if (tmp == "MimeTypes") - mContext = K3Icon::MimeType; + mContext = KIconLoader::MimeType; else if (tmp == "FileSystems") - mContext = K3Icon::FileSystem; + mContext = KIconLoader::FileSystem; else if (tmp == "Applications") - mContext = K3Icon::Application; + mContext = KIconLoader::Application; else if (tmp == "Actions") - mContext = K3Icon::Action; + mContext = KIconLoader::Action; else if (tmp == "Animations") - mContext = K3Icon::Animation; + mContext = KIconLoader::Animation; else if (tmp == "Categories") - mContext = K3Icon::Category; + mContext = KIconLoader::Category; else if (tmp == "Emblems") - mContext = K3Icon::Emblem; + mContext = KIconLoader::Emblem; else if (tmp == "Emotes") - mContext = K3Icon::Emote; + mContext = KIconLoader::Emote; else if (tmp == "International") - mContext = K3Icon::International; + mContext = KIconLoader::International; else if (tmp == "Places") - mContext = K3Icon::Place; + mContext = KIconLoader::Place; else if (tmp == "Status") - mContext = K3Icon::StatusIcon; + mContext = KIconLoader::StatusIcon; else { kDebug(264) << "Invalid Context= line for icon theme: " << mDir << "\n"; return; } tmp = config.readEntry("Type"); if (tmp == "Fixed") - mType = K3Icon::Fixed; + mType = KIconLoader::Fixed; else if (tmp == "Scalable") - mType = K3Icon::Scalable; + mType = KIconLoader::Scalable; else if (tmp == "Threshold") - mType = K3Icon::Threshold; + mType = KIconLoader::Threshold; else { kDebug(264) << "Invalid Type= line for icon theme: " << mDir << "\n"; return; } - if (mType == K3Icon::Scalable) + if (mType == KIconLoader::Scalable) { mMinSize = config.readEntry("MinSize", mSize); mMaxSize = config.readEntry("MaxSize", mSize); - } else if (mType == K3Icon::Threshold) + } else if (mType == KIconLoader::Threshold) mThreshold = config.readEntry("Threshold", 2); mbValid = true; } Index: kiconcache.cpp =================================================================== --- kiconcache.cpp (revisión: 719351) +++ kiconcache.cpp (copia de trabajo) @@ -224,9 +224,9 @@ unsigned int KIconCache::mostRecentMTime return timestamp; } -int KIconCache::defaultIconSize(K3Icon::Group group) const +int KIconCache::defaultIconSize(KIconLoader::Group group) const { - if ((group < 0) || (group >= K3Icon::LastGroup)) + if ((group < 0) || (group >= KIconLoader::LastGroup)) { kDebug(264) << "Illegal icon group:" << group; return -1; @@ -239,7 +239,7 @@ void KIconCache::setThemeInfo(const QLis if (themes.isEmpty()) return; // This as to be done always, even if the cache itself is disabled - for (K3Icon::Group i = K3Icon::FirstGroup; i < K3Icon::LastGroup; i++) { + for (KIconLoader::Group i = KIconLoader::FirstGroup; i < KIconLoader::LastGroup; i++) { d->mDefaultIconSize[i] = themes.first()->defaultSize(i); } Index: kiconengine.cpp =================================================================== --- kiconengine.cpp (revisión: 719351) +++ kiconengine.cpp (copia de trabajo) @@ -59,13 +59,13 @@ static int qIconModeToKIconState( QIcon: switch (mode) { default: case QIcon::Normal: - kstate = K3Icon::DefaultState; + kstate = KIconLoader::DefaultState; break; case QIcon::Active: - kstate = K3Icon::ActiveState; + kstate = KIconLoader::ActiveState; break; case QIcon::Disabled: - kstate = K3Icon::DisabledState; + kstate = KIconLoader::DisabledState; break; } return kstate; @@ -78,7 +78,7 @@ QSize KIconEngine::actualSize( const QSi const int kstate = qIconModeToKIconState(mode); // We ignore overlays here - QPixmap pix = iconLoader()->loadIcon(d->iconName, K3Icon::Desktop, qMin(size.width(), size.height()), kstate); + QPixmap pix = iconLoader()->loadIcon(d->iconName, KIconLoader::Desktop, qMin(size.width(), size.height()), kstate); return pix.size(); } @@ -87,13 +87,13 @@ void KIconEngine::paint( QPainter * pain Q_UNUSED(state) const int kstate = qIconModeToKIconState(mode); - K3Icon::Group group = K3Icon::Desktop; + KIconLoader::Group group = KIconLoader::Desktop; if (QWidget* targetWidget = dynamic_cast(painter->device())) { if (qobject_cast(targetWidget)) - group = K3Icon::Small; + group = KIconLoader::Small; else if (qobject_cast(targetWidget->parent())) - group = K3Icon::Toolbar; + group = KIconLoader::Toolbar; } const int iconSize = qMin(rect.width(), rect.height()); @@ -123,7 +123,7 @@ QPixmap KIconEngine::pixmap( const QSize const int kstate = qIconModeToKIconState(mode); const int iconSize = qMin(size.width(), size.height()); - painter.drawPixmap(QPoint(), iconLoader()->loadIcon(d->iconName, K3Icon::Desktop, + painter.drawPixmap(QPoint(), iconLoader()->loadIcon(d->iconName, KIconLoader::Desktop, iconSize, kstate, d->overlays)); return pix; Index: kiconloader.cpp =================================================================== --- kiconloader.cpp (revisión: 719351) +++ kiconloader.cpp (copia de trabajo) @@ -22,6 +22,7 @@ */ #include "kiconloader.h" +#include "kiconloader_p.h" #include "kicontheme.h" #include "kiconeffect.h" #include "kiconcache.h" @@ -68,9 +69,9 @@ public: KIconThemeNode(KIconTheme *_theme); ~KIconThemeNode(); - void queryIcons(QStringList *lst, int size, K3Icon::Context context) const; - void queryIconsByContext(QStringList *lst, int size, K3Icon::Context context) const; - K3Icon findIcon(const QString& name, int size, K3Icon::MatchType match) const; + void queryIcons(QStringList *lst, int size, KIconLoader::Context context) const; + void queryIconsByContext(QStringList *lst, int size, KIconLoader::Context context) const; + K3Icon findIcon(const QString& name, int size, KIconLoader::MatchType match) const; void printTree(QString& dbgString) const; KIconTheme *theme; @@ -96,21 +97,21 @@ void KIconThemeNode::printTree(QString& } void KIconThemeNode::queryIcons(QStringList *result, - int size, K3Icon::Context context) const + int size, KIconLoader::Context context) const { // add the icons of this theme to it *result += theme->queryIcons(size, context); } void KIconThemeNode::queryIconsByContext(QStringList *result, - int size, K3Icon::Context context) const + int size, KIconLoader::Context context) const { // add the icons of this theme to it *result += theme->queryIconsByContext(size, context); } K3Icon KIconThemeNode::findIcon(const QString& name, int size, - K3Icon::MatchType match) const + KIconLoader::MatchType match) const { return theme->iconPath(name, size, match); } @@ -128,8 +129,60 @@ struct KIconGroup static const int MAX_SVG_RENDERERS = 100; /*** d pointer for KIconLoader. ***/ -struct KIconLoaderPrivate +class KIconLoaderPrivate { +public: + KIconLoaderPrivate(KIconLoader *q) + : q(q) + { + } + + ~KIconLoaderPrivate() + { + } + + /** + * @internal + */ + void init( const QString& _appname, KStandardDirs *_dirs ); + + /** + * @internal + */ + bool initIconThemes(); + + /** + * @internal + * tries to find an icon with the name. It tries some extension and + * match strategies + */ + K3Icon findMatchingIcon(const QString& name, int size) const; + + /** + * @internal + * Adds themes installed in the application's directory. + **/ + void addAppThemes(const QString& appname); + + /** + * Adds all themes that are part of this node and the themes + * below (the fallbacks of the theme) in the tree. + * @internal + */ + void addBaseThemes(KIconThemeNode *node, const QString &appname); + + /** + * @internal + * return the path for the unknown icon in that size + */ + QString unknownIconPath( int size ) const; + + /** + * Checks if name ends in one of the supported icon formats (i.e. .png) + * and returns the name without the extension if it does. + */ + QString removeIconExtension(const QString &name) const; + QStringList mThemesInTree; KIconGroup *mpGroups; KIconThemeNode *mpThemeRoot; @@ -138,8 +191,8 @@ struct KIconLoaderPrivate QHash imgDict; QImage lastImage; // last loaded image without effect applied QString lastImageKey; // key for icon without effect - int lastIconType; // see K3Icon::type - int lastIconThreshold; // see K3Icon::threshold + int lastIconType; // see KIconLoader::type + int lastIconThreshold; // see KIconLoader::threshold QList links; bool extraDesktopIconsLoaded :1; QHash svgRenderers; @@ -147,10 +200,12 @@ struct KIconLoaderPrivate bool mIconThemeInited; QString appname; - void drawOverlays(const KIconLoader *loader, K3Icon::Group group, int state, QPixmap& pix, const QStringList& overlays); + KIconLoader *q; + + void drawOverlays(const KIconLoader *loader, KIconLoader::Group group, int state, QPixmap& pix, const QStringList& overlays); }; -void KIconLoaderPrivate::drawOverlays(const KIconLoader *iconLoader, K3Icon::Group group, int state, QPixmap& pix, const QStringList& overlays) +void KIconLoaderPrivate::drawOverlays(const KIconLoader *iconLoader, KIconLoader::Group group, int state, QPixmap& pix, const QStringList& overlays) { if (overlays.isEmpty()) { return; @@ -248,57 +303,61 @@ static void registerIconLoader( KIconLoa KIconLoader::KIconLoader(const QString& _appname, KStandardDirs *_dirs, QObject* parent) : QObject(parent) { + setObjectName(_appname); + d = new KIconLoaderPrivate(this); + connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), this, SLOT(newIconLoader())); #ifdef KICONLOADER_CHECKS registerIconLoader(this, _appname); #endif - init( _appname, _dirs ); + d->init( _appname, _dirs ); } KIconLoader::KIconLoader(const KComponentData &componentData, QObject* parent) : QObject(parent) { + setObjectName(componentData.componentName()); + d = new KIconLoaderPrivate(this); + connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), this, SLOT(newIconLoader())); #ifdef KICONLOADER_CHECKS registerIconLoader(this, componentData.componentName()); #endif - init(componentData.componentName(), componentData.dirs()); + d->init(componentData.componentName(), componentData.dirs()); } void KIconLoader::reconfigure( const QString& _appname, KStandardDirs *_dirs ) { delete d; - init( _appname, _dirs ); + d->init( _appname, _dirs ); } -void KIconLoader::init( const QString& _appname, KStandardDirs *_dirs ) +void KIconLoaderPrivate::init( const QString& _appname, KStandardDirs *_dirs ) { - setObjectName(_appname); - d = new KIconLoaderPrivate; - d->extraDesktopIconsLoaded=false; - d->mIconThemeInited = false; - d->mpThemeRoot = 0; + extraDesktopIconsLoaded=false; + mIconThemeInited = false; + mpThemeRoot = 0; if (_dirs) - d->mpDirs = _dirs; + mpDirs = _dirs; else - d->mpDirs = KGlobal::dirs(); + mpDirs = KGlobal::dirs(); - d->appname = _appname; - if (d->appname.isEmpty()) - d->appname = KGlobal::mainComponent().componentName(); + appname = _appname; + if (appname.isEmpty()) + appname = KGlobal::mainComponent().componentName(); // Initialize icon cache - d->mIconCache = new KIconCache; - if (!d->mIconCache->isValid()) { + mIconCache = new KIconCache; + if (!mIconCache->isValid()) { initIconThemes(); QList allThemes; - foreach (KIconThemeNode* node, d->links) { + foreach (KIconThemeNode* node, links) { allThemes.append(node->theme); } - d->mIconCache->setThemeInfo(allThemes); + mIconCache->setThemeInfo(allThemes); } // These have to match the order in kicontheme.h @@ -306,22 +365,22 @@ void KIconLoader::init( const QString& _ KSharedConfig::Ptr config = KGlobal::config(); // loading config and default sizes - d->mpGroups = new KIconGroup[(int) K3Icon::LastGroup]; - for (K3Icon::Group i=K3Icon::FirstGroup; impGroups[i].size = cg.readEntry("Size", 0); - d->mpGroups[i].dblPixels = cg.readEntry("DoublePixels", false); + mpGroups[i].size = cg.readEntry("Size", 0); + mpGroups[i].dblPixels = cg.readEntry("DoublePixels", false); if (QPixmap::defaultDepth()>8) - d->mpGroups[i].alphaBlending = cg.readEntry("AlphaBlending", true); + mpGroups[i].alphaBlending = cg.readEntry("AlphaBlending", true); else - d->mpGroups[i].alphaBlending = false; + mpGroups[i].alphaBlending = false; - if (!d->mpGroups[i].size) - d->mpGroups[i].size = d->mIconCache->defaultIconSize(i); + if (!mpGroups[i].size) + mpGroups[i].size = mIconCache->defaultIconSize(i); } #ifdef NO_LAZYLOAD_ICONTHEME @@ -329,23 +388,23 @@ void KIconLoader::init( const QString& _ #endif } -bool KIconLoader::initIconThemes() +bool KIconLoaderPrivate::initIconThemes() { - if (d->mIconThemeInited) { - // If d->mpThemeRoot isn't 0 then initing has succeeded - return (d->mpThemeRoot != 0); + if (mIconThemeInited) { + // If mpThemeRoot isn't 0 then initing has succeeded + return (mpThemeRoot != 0); } kDebug(264) ; - d->mIconThemeInited = true; + mIconThemeInited = true; // Add the default theme and its base themes to the theme tree - KIconTheme *def = new KIconTheme(KIconTheme::current(), d->appname); + KIconTheme *def = new KIconTheme(KIconTheme::current(), appname); if (!def->isValid()) { delete def; // warn, as this is actually a small penalty hit kDebug(264) << "Couldn't find current icon theme, falling back to default."; - def = new KIconTheme(KIconTheme::defaultThemeName(), d->appname); + def = new KIconTheme(KIconTheme::defaultThemeName(), appname); if (!def->isValid()) { kError(264) << "Error: standard icon theme" << KIconTheme::defaultThemeName() << "not found!" << endl; @@ -353,30 +412,30 @@ bool KIconLoader::initIconThemes() return false; } } - d->mpThemeRoot = new KIconThemeNode(def); - d->links.append(d->mpThemeRoot); - d->mThemesInTree += KIconTheme::current(); - addBaseThemes(d->mpThemeRoot, d->appname); + mpThemeRoot = new KIconThemeNode(def); + links.append(mpThemeRoot); + mThemesInTree += KIconTheme::current(); + addBaseThemes(mpThemeRoot, appname); // Insert application specific themes at the top. - d->mpDirs->addResourceType("appicon", "data", d->appname + "/pics/"); + mpDirs->addResourceType("appicon", "data", appname + "/pics/"); // ################## KDE4: consider removing the toolbar directory - d->mpDirs->addResourceType("appicon", "data", d->appname + "/toolbar/"); + mpDirs->addResourceType("appicon", "data", appname + "/toolbar/"); // Add legacy icon dirs. QStringList dirs; - dirs += d->mpDirs->resourceDirs("icon"); - dirs += d->mpDirs->resourceDirs("pixmap"); - dirs += d->mpDirs->resourceDirs("xdgdata-icon"); + dirs += mpDirs->resourceDirs("icon"); + dirs += mpDirs->resourceDirs("pixmap"); + dirs += mpDirs->resourceDirs("xdgdata-icon"); dirs += "/usr/share/pixmaps"; // These are not in the icon spec, but e.g. GNOME puts some icons there anyway. - dirs += d->mpDirs->resourceDirs("xdgdata-pixmap"); + dirs += mpDirs->resourceDirs("xdgdata-pixmap"); for (QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) - d->mpDirs->addResourceDir("appicon", *it); + mpDirs->addResourceDir("appicon", *it); #ifndef NDEBUG QString dbgString = "Theme tree: "; - d->mpThemeRoot->printTree(dbgString); + mpThemeRoot->printTree(dbgString); kDebug(264) << dbgString; #endif @@ -411,17 +470,17 @@ KIconLoader::~KIconLoader() void KIconLoader::addAppDir(const QString& appname) { - const_cast(this)->initIconThemes(); + const_cast(this)->d->initIconThemes(); d->mpDirs->addResourceType("appicon", "data", appname + "/pics/"); // ################## KDE4: consider removing the toolbar directory d->mpDirs->addResourceType("appicon", "data", appname + "/toolbar/"); - addAppThemes(appname); + d->addAppThemes(appname); } -void KIconLoader::addAppThemes(const QString& appname) +void KIconLoaderPrivate::addAppThemes(const QString& appname) { - const_cast(this)->initIconThemes(); + initIconThemes(); if ( KIconTheme::current() != KIconTheme::defaultThemeName() ) { @@ -429,7 +488,7 @@ void KIconLoader::addAppThemes(const QSt if (def->isValid()) { KIconThemeNode* node = new KIconThemeNode(def); - d->links.append(node); + links.append(node); addBaseThemes(node, appname); } else @@ -438,18 +497,18 @@ void KIconLoader::addAppThemes(const QSt KIconTheme *def = new KIconTheme(KIconTheme::defaultThemeName(), appname); KIconThemeNode* node = new KIconThemeNode(def); - d->links.append(node); + links.append(node); addBaseThemes(node, appname); } -void KIconLoader::addBaseThemes(KIconThemeNode *node, const QString &appname) +void KIconLoaderPrivate::addBaseThemes(KIconThemeNode *node, const QString &appname) { QStringList lst = node->theme->inherits(); QStringList::ConstIterator it; for (it=lst.begin(); it!=lst.end(); ++it) { - if( d->mThemesInTree.contains(*it) && (*it) != "hicolor") + if( mThemesInTree.contains(*it) && (*it) != "hicolor") continue; KIconTheme *theme = new KIconTheme(*it,appname); if (!theme->isValid()) { @@ -457,9 +516,9 @@ void KIconLoader::addBaseThemes(KIconThe continue; } KIconThemeNode *n = new KIconThemeNode(theme); - d->mThemesInTree.append(*it); + mThemesInTree.append(*it); addBaseThemes(n, appname); - d->links.append(n); + links.append(n); } } @@ -467,7 +526,7 @@ void KIconLoader::addExtraDesktopThemes( { if ( d->extraDesktopIconsLoaded ) return; - const_cast(this)->initIconThemes(); + const_cast(this)->d->initIconThemes(); QStringList list; QStringList icnlibs = KGlobal::dirs()->resourceDirs("icon"); @@ -509,7 +568,7 @@ void KIconLoader::addExtraDesktopThemes( KIconThemeNode* node = new KIconThemeNode(def); d->mThemesInTree.append(*it); d->links.append(node); - addBaseThemes(node, "" ); + d->addBaseThemes(node, "" ); } d->extraDesktopIconsLoaded=true; @@ -521,7 +580,7 @@ bool KIconLoader::extraDesktopThemesAdde return d->extraDesktopIconsLoaded; } -QString KIconLoader::removeIconExtension(const QString &name) const +QString KIconLoaderPrivate::removeIconExtension(const QString &name) const { int extensionLength=0; @@ -551,9 +610,9 @@ QString KIconLoader::removeIconExtension } -K3Icon KIconLoader::findMatchingIcon(const QString& name, int size) const +K3Icon KIconLoaderPrivate::findMatchingIcon(const QString& name, int size) const { - const_cast(this)->initIconThemes(); + const_cast(this)->initIconThemes(); K3Icon icon; const char * const ext[4] = { ".png", ".svgz", ".svg", ".xpm" }; @@ -570,18 +629,18 @@ K3Icon KIconLoader::findMatchingIcon(con and so on */ - foreach(KIconThemeNode *themeNode, d->links) + foreach(KIconThemeNode *themeNode, links) { for (int i = 0 ; i < 4 ; i++) { - icon = themeNode->theme->iconPath(name + ext[i], size, K3Icon::MatchExact); + icon = themeNode->theme->iconPath(name + ext[i], size, KIconLoader::MatchExact); if (icon.isValid()) return icon; } for (int i = 0 ; i < 4 ; i++) { - icon = themeNode->theme->iconPath(name + ext[i], size, K3Icon::MatchBest); + icon = themeNode->theme->iconPath(name + ext[i], size, KIconLoader::MatchBest); if (icon.isValid()) return icon; } @@ -591,7 +650,7 @@ K3Icon KIconLoader::findMatchingIcon(con return icon; } -inline QString KIconLoader::unknownIconPath( int size ) const +inline QString KIconLoaderPrivate::unknownIconPath( int size ) const { static const QString &str_unknown = KGlobal::staticQString("unknown"); @@ -610,17 +669,17 @@ inline QString KIconLoader::unknownIconP QString KIconLoader::iconPath(const QString& _name, int group_or_size, bool canReturnNull) const { - if (!const_cast(this)->initIconThemes()) { + if (!const_cast(this)->d->initIconThemes()) { return QString(); } if (!QDir::isRelativePath(_name)) return _name; - QString name = removeIconExtension( _name ); + QString name = d->removeIconExtension( _name ); QString path; - if (group_or_size == K3Icon::User) + if (group_or_size == KIconLoader::User) { static const QString &png_ext = KGlobal::staticQString(".png"); static const QString &xpm_ext = KGlobal::staticQString(".xpm"); @@ -637,7 +696,7 @@ QString KIconLoader::iconPath(const QStr return path; } - if (group_or_size >= K3Icon::LastGroup) + if (group_or_size >= KIconLoader::LastGroup) { kDebug(264) << "Illegal icon group: " << group_or_size; return path; @@ -653,24 +712,24 @@ QString KIconLoader::iconPath(const QStr if (canReturnNull) return QString(); else - return unknownIconPath(size); + return d->unknownIconPath(size); } - K3Icon icon = findMatchingIcon(name, size); + K3Icon icon = d->findMatchingIcon(name, size); if (!icon.isValid()) { // Try "User" group too. - path = iconPath(name, K3Icon::User, true); + path = iconPath(name, KIconLoader::User, true); if (!path.isEmpty() || canReturnNull) return path; - return unknownIconPath(size); + return d->unknownIconPath(size); } return icon.path; } -QPixmap KIconLoader::loadMimeTypeIcon( const QString& iconName, K3Icon::Group group, int size, +QPixmap KIconLoader::loadMimeTypeIcon( const QString& iconName, KIconLoader::Group group, int size, int state, const QStringList& overlays, QString *path_store ) const { if ( !d->extraDesktopIconsLoaded ) @@ -682,7 +741,7 @@ QPixmap KIconLoader::loadMimeTypeIcon( c return loadIcon( iconName, group, size, state, overlays, path_store, false ); } -QPixmap KIconLoader::loadIcon(const QString& _name, K3Icon::Group group, int size, +QPixmap KIconLoader::loadIcon(const QString& _name, KIconLoader::Group group, int size, int state, const QStringList& overlays, QString *path_store, bool canReturnNull) const { @@ -703,7 +762,7 @@ QPixmap KIconLoader::loadIcon(const QStr static const QString &str_unknown = KGlobal::staticQString("unknown"); // Special case for "User" icons. - if (group == K3Icon::User) + if (group == KIconLoader::User) { key = "$kicou_"; key += QString::number(size); key += '_'; @@ -711,18 +770,18 @@ QPixmap KIconLoader::loadIcon(const QStr if (d->mIconCache->find(key, pix, path_store)) { //kDebug(264) << "KIL: " << "found the icon from KIC"; return pix; - } else if (!const_cast(this)->initIconThemes()) { + } else if (!const_cast(this)->d->initIconThemes()) { return pix; // null pixmap } path = (absolutePath) ? name : - iconPath(name, K3Icon::User, canReturnNull); + iconPath(name, KIconLoader::User, canReturnNull); if (path.isEmpty()) { if (canReturnNull) return pix; // We don't know the desired size: use small - path = iconPath(str_unknown, K3Icon::Small, true); + path = iconPath(str_unknown, KIconLoader::Small, true); if (path.isEmpty()) { kDebug(264) << "Warning: Cannot find \"unknown\" icon."; @@ -745,22 +804,22 @@ QPixmap KIconLoader::loadIcon(const QStr // Regular case: Check parameters - if ((group < -1) || (group >= K3Icon::LastGroup)) + if ((group < -1) || (group >= KIconLoader::LastGroup)) { kDebug(264) << "Illegal icon group: " << group; - group = K3Icon::Desktop; + group = KIconLoader::Desktop; } - if ((state < 0) || (state >= K3Icon::LastState)) + if ((state < 0) || (state >= KIconLoader::LastState)) { kDebug(264) << "Illegal icon state: " << state; - state = K3Icon::DefaultState; + state = KIconLoader::DefaultState; } if (size == 0 && group < 0) { kDebug(264) << "Neither size nor group specified!"; - group = K3Icon::Desktop; + group = KIconLoader::Desktop; } if (!absolutePath) @@ -768,7 +827,7 @@ QPixmap KIconLoader::loadIcon(const QStr if (!canReturnNull && name.isEmpty()) name = str_unknown; else - name = removeIconExtension(name); + name = d->removeIconExtension(name); } // If size == 0, use default size for the specified group. @@ -800,7 +859,7 @@ QPixmap KIconLoader::loadIcon(const QStr if (d->mIconCache->find(key, pix, path_store)) { //kDebug() << "KIL: " << "found icon from KIC"; return pix; - } else if (!const_cast(this)->initIconThemes()) { + } else if (!const_cast(this)->d->initIconThemes()) { return pix; // null pixmap } @@ -815,25 +874,25 @@ QPixmap KIconLoader::loadIcon(const QStr K3Icon icon; if (absolutePath && !favIconOverlay) { - icon.context=K3Icon::Any; - icon.type=K3Icon::Scalable; + icon.context=KIconLoader::Any; + icon.type=KIconLoader::Scalable; icon.path=name; } else { if (!name.isEmpty()) - icon = findMatchingIcon(favIconOverlay ? QString("www") : name, size); + icon = d->findMatchingIcon(favIconOverlay ? QString("www") : name, size); if (!icon.isValid()) { // Try "User" icon too. Some apps expect this. if (!name.isEmpty()) { - pix = loadIcon(name, K3Icon::User, size, state, overlays, path_store, true); + pix = loadIcon(name, KIconLoader::User, size, state, overlays, path_store, true); } if (!pix.isNull() || canReturnNull) return pix; - icon = findMatchingIcon(str_unknown, size); + icon = d->findMatchingIcon(str_unknown, size); if (!icon.isValid()) { kDebug(264) @@ -905,11 +964,11 @@ QPixmap KIconLoader::loadIcon(const QStr } // Scale the icon and apply effects if necessary - if (iconType == K3Icon::Scalable && size != img->width()) + if (iconType == KIconLoader::Scalable && size != img->width()) { *img = img->scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } - if (iconType == K3Icon::Threshold && size != img->width()) + if (iconType == KIconLoader::Threshold && size != img->width()) { if ( abs(size-img->width())>iconThreshold ) *img = img->scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); @@ -956,7 +1015,7 @@ QPixmap KIconLoader::loadIcon(const QStr return pix; } -QMovie *KIconLoader::loadMovie(const QString& name, K3Icon::Group group, int size, QObject *parent) const +QMovie *KIconLoader::loadMovie(const QString& name, KIconLoader::Group group, int size, QObject *parent) const { QString file = moviePath( name, group, size ); if (file.isEmpty()) @@ -974,25 +1033,25 @@ QMovie *KIconLoader::loadMovie(const QSt return movie; } -QString KIconLoader::moviePath(const QString& name, K3Icon::Group group, int size) const +QString KIconLoader::moviePath(const QString& name, KIconLoader::Group group, int size) const { if (!d->mpGroups) return QString(); - const_cast(this)->initIconThemes(); + const_cast(this)->d->initIconThemes(); - if ( (group < -1 || group >= K3Icon::LastGroup) && group != K3Icon::User ) + if ( (group < -1 || group >= KIconLoader::LastGroup) && group != KIconLoader::User ) { kDebug(264) << "Illegal icon group: " << group; - group = K3Icon::Desktop; + group = KIconLoader::Desktop; } if (size == 0 && group < 0) { kDebug(264) << "Neither size nor group specified!"; - group = K3Icon::Desktop; + group = KIconLoader::Desktop; } QString file = name + ".mng"; - if (group == K3Icon::User) + if (group == KIconLoader::User) { file = d->mpDirs->findResource("appicon", file); } @@ -1005,7 +1064,7 @@ QString KIconLoader::moviePath(const QSt foreach(KIconThemeNode *themeNode, d->links) { - icon = themeNode->theme->iconPath(file, size, K3Icon::MatchExact); + icon = themeNode->theme->iconPath(file, size, KIconLoader::MatchExact); if (icon.isValid()) break; } @@ -1014,7 +1073,7 @@ QString KIconLoader::moviePath(const QSt { foreach(KIconThemeNode *themeNode, d->links) { - icon = themeNode->theme->iconPath(file, size, K3Icon::MatchBest); + icon = themeNode->theme->iconPath(file, size, KIconLoader::MatchBest); if (icon.isValid()) break; } @@ -1026,34 +1085,34 @@ QString KIconLoader::moviePath(const QSt } -QStringList KIconLoader::loadAnimated(const QString& name, K3Icon::Group group, int size) const +QStringList KIconLoader::loadAnimated(const QString& name, KIconLoader::Group group, int size) const { QStringList lst; if (!d->mpGroups) return lst; - const_cast(this)->initIconThemes(); + const_cast(this)->d->initIconThemes(); - if ((group < -1) || (group >= K3Icon::LastGroup)) + if ((group < -1) || (group >= KIconLoader::LastGroup)) { kDebug(264) << "Illegal icon group: " << group; - group = K3Icon::Desktop; + group = KIconLoader::Desktop; } if ((size == 0) && (group < 0)) { kDebug(264) << "Neither size nor group specified!"; - group = K3Icon::Desktop; + group = KIconLoader::Desktop; } QString file = name + "/0001"; - if (group == K3Icon::User) + if (group == KIconLoader::User) { file = d->mpDirs->findResource("appicon", file + ".png"); } else { if (size == 0) size = d->mpGroups[group].size; - K3Icon icon = findMatchingIcon(file, size); + K3Icon icon = d->findMatchingIcon(file, size); file = icon.isValid() ? icon.path : QString(); } @@ -1085,11 +1144,11 @@ KIconTheme *KIconLoader::theme() const return 0L; } -int KIconLoader::currentSize(K3Icon::Group group) const +int KIconLoader::currentSize(KIconLoader::Group group) const { if (!d->mpGroups) return -1; - if (group < 0 || group >= K3Icon::LastGroup) + if (group < 0 || group >= KIconLoader::LastGroup) { kDebug(264) << "Illegal icon group: " << group; return -1; @@ -1111,10 +1170,10 @@ QStringList KIconLoader::queryIconsByDir } QStringList KIconLoader::queryIconsByContext(int group_or_size, - K3Icon::Context context) const + KIconLoader::Context context) const { QStringList result; - if (group_or_size >= K3Icon::LastGroup) + if (group_or_size >= KIconLoader::LastGroup) { kDebug(264) << "Illegal icon group: " << group_or_size; return result; @@ -1139,7 +1198,7 @@ QStringList KIconLoader::queryIconsByCon name = *it; else name = (*it).mid(n+1); - name = removeIconExtension(name); + name = d->removeIconExtension(name); if (!entries.contains(name)) { entries += name; @@ -1150,10 +1209,10 @@ QStringList KIconLoader::queryIconsByCon } -QStringList KIconLoader::queryIcons(int group_or_size, K3Icon::Context context) const +QStringList KIconLoader::queryIcons(int group_or_size, KIconLoader::Context context) const { QStringList result; - if (group_or_size >= K3Icon::LastGroup) + if (group_or_size >= KIconLoader::LastGroup) { kDebug(264) << "Illegal icon group: " << group_or_size; return result; @@ -1178,7 +1237,7 @@ QStringList KIconLoader::queryIcons(int name = *it; else name = (*it).mid(n+1); - name = removeIconExtension(name); + name = d->removeIconExtension(name); if (!entries.contains(name)) { entries += name; @@ -1189,7 +1248,7 @@ QStringList KIconLoader::queryIcons(int } // used by KIconDialog to find out which contexts to offer in a combobox -bool KIconLoader::hasContext(K3Icon::Context context) const +bool KIconLoader::hasContext(KIconLoader::Context context) const { foreach(KIconThemeNode *themeNode, d->links) if( themeNode->theme->hasContext( context )) @@ -1202,11 +1261,11 @@ KIconEffect * KIconLoader::iconEffect() return &d->mpEffect; } -bool KIconLoader::alphaBlending(K3Icon::Group group) const +bool KIconLoader::alphaBlending(KIconLoader::Group group) const { if (!d->mpGroups) return false; - if (group < 0 || group >= K3Icon::LastGroup) + if (group < 0 || group >= KIconLoader::LastGroup) { kDebug(264) << "Illegal icon group: " << group; return false; @@ -1215,16 +1274,16 @@ bool KIconLoader::alphaBlending(K3Icon:: } // deprecated -QIcon KIconLoader::loadIconSet( const QString& name, K3Icon::Group g, int s, +QIcon KIconLoader::loadIconSet( const QString& name, KIconLoader::Group g, int s, bool canReturnNull ) { QIcon iconset; - QPixmap tmp = loadIcon(name, g, s, K3Icon::ActiveState, QStringList(), NULL, canReturnNull); + QPixmap tmp = loadIcon(name, g, s, KIconLoader::ActiveState, QStringList(), NULL, canReturnNull); iconset.addPixmap( tmp, QIcon::Active, QIcon::On ); // we don't use QIconSet's resizing anyway - tmp = loadIcon(name, g, s, K3Icon::DisabledState, QStringList(), NULL, canReturnNull); + tmp = loadIcon(name, g, s, KIconLoader::DisabledState, QStringList(), NULL, canReturnNull); iconset.addPixmap( tmp, QIcon::Disabled, QIcon::On ); - tmp = loadIcon(name, g, s, K3Icon::DefaultState, QStringList(), NULL, canReturnNull); + tmp = loadIcon(name, g, s, KIconLoader::DefaultState, QStringList(), NULL, canReturnNull); iconset.addPixmap( tmp, QIcon::Normal, QIcon::On ); return iconset; } @@ -1234,69 +1293,69 @@ QIcon KIconLoader::loadIconSet( const QS QPixmap DesktopIcon(const QString& name, int force_size, int state, const QStringList &overlays) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIcon(name, K3Icon::Desktop, force_size, state, overlays); + return loader->loadIcon(name, KIconLoader::Desktop, force_size, state, overlays); } // deprecated QIcon DesktopIconSet(const QString& name, int force_size) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIconSet(name, K3Icon::Desktop, force_size); + return loader->loadIconSet(name, KIconLoader::Desktop, force_size); } QPixmap BarIcon(const QString& name, int force_size, int state, const QStringList &overlays) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIcon(name, K3Icon::Toolbar, force_size, state, overlays); + return loader->loadIcon(name, KIconLoader::Toolbar, force_size, state, overlays); } // deprecated QIcon BarIconSet(const QString& name, int force_size) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIconSet( name, K3Icon::Toolbar, force_size ); + return loader->loadIconSet( name, KIconLoader::Toolbar, force_size ); } QPixmap SmallIcon(const QString& name, int force_size, int state, const QStringList &overlays) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIcon(name, K3Icon::Small, force_size, state, overlays); + return loader->loadIcon(name, KIconLoader::Small, force_size, state, overlays); } // deprecated QIcon SmallIconSet(const QString& name, int force_size) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIconSet( name, K3Icon::Small, force_size ); + return loader->loadIconSet( name, KIconLoader::Small, force_size ); } QPixmap MainBarIcon(const QString& name, int force_size, int state, const QStringList &overlays) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIcon(name, K3Icon::MainToolbar, force_size, state, overlays); + return loader->loadIcon(name, KIconLoader::MainToolbar, force_size, state, overlays); } // deprecated QIcon MainBarIconSet(const QString& name, int force_size) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIconSet( name, K3Icon::MainToolbar, force_size ); + return loader->loadIconSet( name, KIconLoader::MainToolbar, force_size ); } QPixmap UserIcon(const QString& name, int state, const QStringList &overlays) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIcon(name, K3Icon::User, 0, state, overlays); + return loader->loadIcon(name, KIconLoader::User, 0, state, overlays); } // deprecated QIcon UserIconSet(const QString& name) { KIconLoader *loader = KIconLoader::global(); - return loader->loadIconSet( name, K3Icon::User ); + return loader->loadIconSet( name, KIconLoader::User ); } -int IconSize(K3Icon::Group group) +int IconSize(KIconLoader::Group group) { KIconLoader *loader = KIconLoader::global(); return loader->currentSize(group); @@ -1308,7 +1367,7 @@ QPixmap KIconLoader::unknown() if ( QPixmapCache::find("unknown", pix) ) return pix; - QString path = global()->iconPath("unknown", K3Icon::Small, true); + QString path = global()->iconPath("unknown", KIconLoader::Small, true); if (path.isEmpty()) { kDebug(264) << "Warning: Cannot find \"unknown\" icon."; Index: kicontheme.h =================================================================== --- kicontheme.h (revisión: 719351) +++ kicontheme.h (copia de trabajo) @@ -29,153 +29,14 @@ #include #include +#include "kiconloader.h" + class QAction; class KIconThemeDir; +class K3Icon; /** - * One icon as found by KIconTheme. Also serves as a namespace containing - * icon related constants. - * @see KIconEffect - * @see KIconTheme - * @see KIconLoader - */ -class KDEUI_EXPORT K3Icon -{ -public: - K3Icon(); - ~K3Icon(); - - /** - * Return true if this icon is valid, false otherwise. - */ - bool isValid() const; - - /** - * Defines the context of the icon. - */ - enum Context { - Any, ///< Some icon with unknown purpose. - Action, ///< An action icon (e.g. 'save', 'print'). - Application, ///< An icon that represents an application. - Device, ///< An icon that represents a device. - FileSystem, ///< An icon that represents a file system. - MimeType, ///< An icon that represents a mime type (or file type). - Animation, ///< An icon that is animated. - Category, ///< An icon that represents a category. - Emblem, ///< An icon that adds information to an existing icon. - Emote, ///< An icon that expresses an emotion. - International, ///< An icon that represents a country's flag. - Place, ///< An icon that represents a location (e.g. 'home', 'trash'). - StatusIcon ///< An icon that represents an event. - }; - - /** - * The type of the icon. - */ - enum Type { - Fixed, ///< Fixed-size icon. - Scalable, ///< Scalable-size icon. - Threshold ///< A threshold icon. - }; - - /** - * The type of a match. - */ - enum MatchType { - MatchExact, ///< Only try to find an exact match. - MatchBest ///< Take the best match if there is no exact match. - - }; - - // if you add a group here, make sure to change the config reading in - // KIconLoader too - /** - * The group of the icon. - */ - enum Group { - /// No group - NoGroup=-1, - /// Desktop icons - Desktop=0, - /// First group - FirstGroup=0, - /// Toolbar icons - Toolbar, - /// Main toolbar icons - MainToolbar, - /// Small icons, e.g. for buttons - Small, - /// Panel (Kicker) icons - Panel, - /// Icons for use in dialog titles, page lists, etc - Dialog, - /// Last group - LastGroup, - /// User icons - User - }; - - /** - * These are the standard sizes for icons. - */ - enum StdSizes { - /// small icons for menu entries - SizeSmall=16, - /// slightly larger small icons for toolbars, panels, etc - SizeSmallMedium=22, - /// medium sized icons for the desktop - SizeMedium=32, - /// large sized icons for the panel - SizeLarge=48, - /// huge sized icons for iconviews - SizeHuge=64, - /// enormous sized icons for iconviews - SizeEnormous=128 - }; - - /** - * Defines the possible states of an icon. - */ - enum States { DefaultState, ///< The default state. - ActiveState, ///< Icon is active. - DisabledState, ///< Icon is disabled. - LastState ///< Last state (last constant) - }; - - /** - * The size in pixels of the icon. - */ - int size; - - /** - * The context of the icon. - */ - Context context; - - /** - * The type of the icon: Fixed, Scalable or Threshold. - **/ - Type type; - - /** - * The threshold in case type == Threshold - */ - int threshold; - - /** - * The full path of the icon. - */ - QString path; - -private: - class KIconPrivate; - KIconPrivate * d; -}; - -inline K3Icon::Group& operator++(K3Icon::Group& group) { group = static_cast(group+1); return group; } -inline K3Icon::Group operator++(K3Icon::Group& group,int) { K3Icon::Group ret = group; ++group; return ret; } - -/** + * @internal * Class to use/access icon themes in KDE. This class is used by the * iconloader but can be used by others too. * @see KIconLoader @@ -258,17 +119,17 @@ public: /** * The default size of this theme for a certain icon group. - * @param group The icon group. See K3Icon::Group. + * @param group The icon group. See KIconLoader::Group. * @return The default size in pixels for the given icon group. */ - int defaultSize(K3Icon::Group group) const; + int defaultSize(KIconLoader::Group group) const; /** * Query available sizes for a group. - * @param group The icon group. See K3Icon::Group. + * @param group The icon group. See KIconLoader::Group. * @return a list of available sized for the given group */ - QList querySizes(K3Icon::Group group) const; + QList querySizes(KIconLoader::Group group) const; /** * Query available icons for a size and context. @@ -276,7 +137,7 @@ public: * @param context the context of the icons * @return the list of icon names */ - QStringList queryIcons(int size, K3Icon::Context context = K3Icon::Any) const; + QStringList queryIcons(int size, KIconLoader::Context context = KIconLoader::Any) const; /** * Query available icons for a context and preferred size. @@ -284,25 +145,25 @@ public: * @param context the context of the icons * @return the list of icon names */ - QStringList queryIconsByContext(int size, K3Icon::Context context = K3Icon::Any) const; - + QStringList queryIconsByContext(int size, KIconLoader::Context context = KIconLoader::Any) const; /** * Lookup an icon in the theme. * @param name The name of the icon, without extension. * @param size The desired size of the icon. - * @param match The matching mode. K3Icon::MatchExact returns an icon - * only if matches exactly. K3Icon::MatchBest returns the best matching + * @param match The matching mode. KIconLoader::MatchExact returns an icon + * only if matches exactly. KIconLoader::MatchBest returns the best matching * icon. - * @return A K3Icon class that describes the icon. If an icon is found, - * @see K3Icon::isValid will return true, and false otherwise. + * @return A K3Icon class that describes the icon. If an icon is found, an invalid + * K3Icon object otherwise. + * @see KIconLoader::isValid will return true, and false otherwise. */ - K3Icon iconPath(const QString& name, int size, K3Icon::MatchType match) const; + K3Icon iconPath(const QString& name, int size, KIconLoader::MatchType match) const; /** * Returns true if the theme has any icons for the given context. */ - bool hasContext( K3Icon::Context context ) const; + bool hasContext( KIconLoader::Context context ) const; /** * List all icon themes installed on the system, global and local. Index: kiconcache.h =================================================================== --- kiconcache.h (revisión: 719351) +++ kiconcache.h (copia de trabajo) @@ -64,10 +64,10 @@ public: /** * The default size of current theme for a certain icon group. - * @param group The icon group. See K3Icon::Group. + * @param group The icon group. See KIconLoader::Group. * @return The default size in pixels for the given icon group. */ - int defaultIconSize(K3Icon::Group group) const; + int defaultIconSize(KIconLoader::Group group) const; void setThemeInfo(const QList& themes);