Development/Architecture/KDE3/Icon Loader

Jump to: navigation, search
Other languages:English 100% • ‎Galician 100% • ‎Brazilian Portuguese 100%

Carregando e instalando ícones no KDE

Os ícones são um importante elemento de interface do usuário em qualquer ambiente de trabalho. Devido a diferentes preferências do usuário e de hardware de vídeo, um ícone pode vir em diferentes tamanhos e profundidades de exibição. Para que isso seja gerenciável, uma forma padrão de armazenamento e acesso a ícones foi desenvolvido.

Contents

Loading icons

Acessando o iconloader

Ícones são carregados usando a classe KIconLoader. Todo appliation do KDE tem um objeto iconloader global. Você pode acessar esse objeto com:

#include <kglobal.h>
#include <kiconloader.h>
 
KIconLoader *loader = KGlobal::iconLoader();

Carregando ícones com loadIcon

O iconloader carrega ícones, faz o cache deles e aplica efeitos. Para carregar um ícone, use o método loadIcon(), que é definido assim:

QPixmap loadIcon( QString name, int group, int size=0,
                  int state=KIcon::DefaultState, 
                  QString *path_store=0L, bool canReturnNull=false);

Como você vê, existem muitos parâmetros. Os dois primeiros são os mais importantes:

  1. name - O nome do ícone a ser carregado. Você deve passar o nome do ícone aqui, sem extensão.
  2. group - O grupo do ícone. Isto é explicado abaixo.

Grupos de ícone

A ideia de um grupo de ícone é um conceito importante no esquema de ícone do KDE. O grupo de ícone indica onde na tela o ícone vai ser usado. Isso é relevante, pois o usuário pode vincular os tamanhos dos ícones e efeitos visuais do KDE para cada grupo. Ao passar o grupo de ícone para o carregador de ícone, você está na verdade dizendo-lhe que encarnação do ícone deve carregar. E, exigindo o argumento do grupo, o iconloader fornece os meios para ter um consistente e configurável exame de ícone sobre toda a área de trabalho do KDE.

Por exemplo: o usuário pode configurar que ele deseja ícones de 32 pixels com 0.2 de dessaturação para as barras de ferramentas principais.

Os grupos de ícones disponíveis são apresentados abaixo. Todos estão definidos na classe KIcon, assim prefixe-os com KIcon::.

  • Desktop - Icons for use on the desktop, in the filemanager and similar places.
  • Toolbar - Icon for in normal toolbars.
  • MainToolbar - Icons for in the main toolbar. An application can have multiple toolbars, of which one is allways the main toolbar. This typically has entries like "Save" and "Open" and contains larger icons than the other toolbars.
  • Small - Various small icons, like the ones in popup menus, listviews and treelists.
  • User - Special group for loading application specific icons. This is explained in section 3: Installing icons.

So, to load the icon "kfind" for use in the Desktop group, you'd use:

QPixmap icon;
icon = loader->loadIcon("kfind", KIcon::Desktop);

loadIcon continued

Now lets discuss the other parameters of loadIcon.

  1. size - Override the globally configured size for the specified icon group. Effects bound to the group are still applied.
  2. state - The icon state. The icon state is one of KIcon::DefaultState, KIcon::ActiveState or KIcon::DisabledState. The icon state denotes in which state the icon is. Toolbar buttons, for example, are in state active if the mouse pointer is above them, in state disabled when they are not available, and default otherwise. Each icon state can have different effects assigned to it to give the user visual feedback.
  3. path_store - If you want to know where the icon you just loaded is in the filesystem, you can pass a pointer to a QString here and the icon path is stored there.
  4. canReturnNull - If the requested icon is not found, the result of loadIcon depends on this parameter. If canReturnNull is true, a null pixmap will be returned, if not, the "unknown" icon is returned.

Installing icons

Icons may come in different sizes and display depths. I shall refer to these icons as themed icons. Icons that come in just one form are referred to as unthemed icons.

Default icon sizes

Themed icons come in different sizes and display depths. The standard sizes are:

40 Colors
16x16 pixels
22x22 pixels
32x32 pixels
Truecolor
22x22 pixels
32x32 pixels
48x48 pixels

Please refer to the KDE icon factory for information on which icon sizes are mandatory and more. Remember that each of these sizes can be bound to an icon group.

Icon context

Themed icons are stored in a directory hierarchy according to their 1. depth, 2. size and 3. context. The term context is new concept introduced by the KDE icon scheme. The context of an icon is what the icon means. The standard contexts are given below:

  • action - The icon represents an action in a toolbar, for example "Open" or "Save".
  • application - The icon represents an application, for example "kfind".
  • device - The icon represents something related to a device, for example "floppy" or "mount".
  • filesystem - The icon represents something in the filesystem, for example "directory", "socket" or "trashcan".
  • mimetype - The icon represents an mimetype, for example "text/html".

Contexts are important in one case: selecting an icon. When an application wants the user to select an icon for, say, a toolbar, it would be very user unfriendly to show every single icon installed in KDE. Instead, it is much better to let the user select an icon from the "action" icons only. These all represent some action and therefore are suitable for in toolbars.

Directory hierarchy

The directory hierarchy in which themed icons are stored follows. The directory names are self explanatory.

hicolor/
    22x22/
        actions/
        apps/
        devices/
        filesystems/
        mimetypes/
    32x32/
        ...
    48x48/
        ...

locolor/
    16x16/
        ...
    22x22/
        ...
    32x32/
        ...

Directory roots

Themed icons can be installed either globally with respect to KDE, or in application specific place. In the global case, the icon theme hierarchy resides under $KDEDIR/share/icons while in the application specific case, it is under $KDEDIR/share/apps/$APPNAME/icons.

Installing themed icons

The KDE source configuration system (specifically, am_edit) has support for installing themed icons. First, you have to name your icons in a way that it is clear where it must be installed. The naming convention is explained in the table below:

depth size - context - name .png
hi 16 action
lo 22 app
32 device
48 filesys
mime

Examples:

lo22-action-open.png
hi48-app-kfind.png

To install these icons globally, add this line to your Makefile.am.

KDE_ICON = open kfind

and to install them in an application specific directory, use this:

icondir = $(kde_datadir)/myapp/icons
icon_ICON = open kfind

Loading themed icons

Themed icons are loaded with the iconloader, using the standard icon groups. For example:

QPixmap pm;
pm = loader->loadIcon("kfind", KIcon::Desktop);

This will load the "kfind" icon, of depth and size specified for the Desktop group.

Unthemed icons

Unthemed icons are installed in $KDEDIR/share/apps/$APPNAME/pics. To install them, use this in you Makefile.am.

icondir = $(kde_datadir)/myapp/pics
icon_DATA = open kfind

You must not give the icons special names. Also, no further processing is done on them: no effects and size,depth selection is done.

Unthemed icons can be loaded with the iconloader using the User group. This will load a user icon:

QPixmap pm;
pm = loader->loadIcon("myicon", KIcon::User);

Conclusion

There are 3 ways to install icons: global themed, application specific themed and unthemed. All types of icons can be loaded with the iconloader. You should choose a specific installation depending on your needs.


Initial Author: Geert Jansen <jansen@kde.org>


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal