m (Proofreading) |
m (improve markup) |
||
| (One intermediate revision by one user not shown) | |||
| Line 64: | Line 64: | ||
= The icon naming scheme = | = The icon naming scheme = | ||
Example for icon names: | Example for icon names: | ||
| − | * hisc-apps-bla.svgz will be installed e.g. to /usr/local/share/icons/hicolor/scalable/apps/bla.svgz. | + | * hisc-apps-bla.svgz will be installed e.g. to /usr/local/share/icons/hicolor/scalable/apps/bla.svgz. <tt>hi</tt> stands for "hicolor", <tt>sc</tt> for "scalable", <tt>apps</tt> for "applications", <tt>bla</tt> for the application's name and <tt>.svgz</tt> is the suffix for gzipped scalable vector graphic files. |
| − | * hi128-app-ktimetracker.png will be installed e.g. to /usr/share/icons/hicolor/128x128/apps/ktimetracker.png. | + | * hi128-app-ktimetracker.png will be installed e.g. to /usr/share/icons/hicolor/128x128/apps/ktimetracker.png. <tt>hi</tt> stands for "hicolor", <tt>128</tt> for a resolution of 128x128 pixels, <tt>app</tt> for "applications", <tt>ktimetracker</tt> for the application's name and <tt>.png</tt> is the suffix for portable network graphic files. |
= example application = | = example application = | ||
| Line 80: | Line 80: | ||
: just taken from the [[Development/Tutorials/Using_KActions|KAction example]] | : just taken from the [[Development/Tutorials/Using_KActions|KAction example]] | ||
* [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/mainwindow.cpp mainwindow.cpp] | * [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/mainwindow.cpp mainwindow.cpp] | ||
| − | : Note the command < | + | : Note the command <syntaxhighlight lang="bash">clearAction->setIcon(KIcon("tutorial-kicon"));</syntaxhighlight> that sets the icon |
* [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/mainwindow.h mainwindow.h] | * [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/mainwindow.h mainwindow.h] | ||
: just taken from the [[Development/Tutorials/Using_KActions|KAction example]] | : just taken from the [[Development/Tutorials/Using_KActions|KAction example]] | ||
| Line 88: | Line 88: | ||
: just taken from the [[Development/Tutorials/Using_KActions|KAction example]] | : just taken from the [[Development/Tutorials/Using_KActions|KAction example]] | ||
* [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/hisc-apps-tutorial-kicon.svgz hisc-apps-tutorial-kicon.svgz] | * [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/hisc-apps-tutorial-kicon.svgz hisc-apps-tutorial-kicon.svgz] | ||
| − | : sorry for the name, but there are [[#The_icon_naming_scheme|naming conventions]]. Create this file with the ''convert'' command from the ''ImageMagick'' package | + | : sorry for the name, but there are [[#The_icon_naming_scheme|naming conventions]]. Create this file with the ''convert'' command from the ''ImageMagick'' package <syntaxhighlight lang="bash">convert world.svg hisc-apps-tutorial-kicon.svgz</syntaxhighlight> |
| − | <syntaxhighlight lang="bash"> | + | |
| − | convert world.svg hisc-apps-tutorial-kicon.svgz | + | |
| − | </syntaxhighlight> | + | |
* [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/CMakeLists.txt CMakeLists.txt] | * [http://quickgit.kde.org/?p=kdeexamples.git&a=blob&f=kicons/CMakeLists.txt CMakeLists.txt] | ||
| − | : Note the commands | + | : Note the commands <syntaxhighlight lang="bash">kde4_install_icons(${ICON_INSTALL_DIR})</syntaxhighlight> and <syntaxhighlight lang="bash">kde4_update_iconcache()</syntaxhighlight> which integrate the icons. |
| − | <syntaxhighlight lang="bash"> | + | |
| − | kde4_install_icons(${ICON_INSTALL_DIR}) | + | |
| − | </syntaxhighlight> | + | |
| − | and | + | |
| − | <syntaxhighlight lang="bash"> | + | |
| − | kde4_update_iconcache() | + | |
| − | </syntaxhighlight> | + | |
| − | which integrate the icons. | + | |
== build it == | == build it == | ||
Contents |
When you create your own KDE application you will probably want icons in it like this:
These icons are called KIcons. This article shows you how to do this using the software krep as an example. In case of a CMake-based project you will need to
How to use icons in QMake-based projects is discussed elsewhere.
If you have a KDE project and want to use icons within it, and want these icons installed seamlessly, you will have to name the icons after the project. In the following we look at a project named krep. The important lines in CMakeLists.txt are the ones printed bold below:
PROJECT( krep ) FIND_PACKAGE( KDE4 REQUIRED ) INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . ) SET( krepSources main.cpp krep.cpp krep.h ) qt4_add_dbus_adaptor( krepSources org.kde.krep.xml krep.h krep mainadaptor MainAdaptor ) kde4_add_ui_files( krepSources krepui.ui ) kde4_add_app_icon]]( krepSources "hi*-app-krep.png" ) KDE4_ADD_EXECUTABLE( krep ${krepSources} ) TARGET_LINK_LIBRARIES( krep ${KDE4_KPARTS_LIBS} ) install( TARGETS krep ${INSTALL_TARGETS_DEFAULT_ARGS} ) '''kde4_install_icons( ${ICON_INSTALL_DIR]]} )
Weitere Informationen:
rm /usr/local/share/icons/hicolor/22x22/apps/krep.png
| Note |
|---|
| We are assuming your icon path is /usr/local/share/icons.
Find it out with the command kde4-config --path icon |
rm -rf /var/tmp/kdecache-''user''/icon-cache.kcache
According to Development/CMake/Addons_for_KDE#Macros you need to provide a 128x128 pixels icon.
Example for icon names:
In this chapter we will build - on top of the KAction example - an example application kicons that looks like this:
You can obtain its source code as part of kdeexamples by calling
git clone git://anongit.kde.org/kdeexamples
The example application consists of
clearAction->setIcon(KIcon("tutorial-kicon"));
convert world.svg hisc-apps-tutorial-kicon.svgz
kde4_install_icons(${ICON_INSTALL_DIR})
kde4_update_iconcache()
To compile, link and install the example application, do a
cmake . && make && make install
To run it, call
tutorial-kicon
Maybe you have already searched for yourself how a KDE application finds its icons. You will not be successful like this:
# [http://www.linuxintro.org/wiki/Strace#Search_for_a_syscall strace -e open] ktimetracker 2>&1 | grep icon open("/usr/lib64/libkemoticons.so.4", O_RDONLY) = 3 #
You see, a KDE application (in this case ktimetracker) does not open icon files or even look for them. However, it spawns a process to look for these icons:
linux-qgla:~/repos/kdepim/ktimetracker # strace -ffe open ktimetracker 2>&1 | grep icon open("/usr/lib64/libkemoticons.so.4", O_RDONLY) = 3 [pid 3457] open("/root/.icons/DMZ/cursors/left_ptr", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 3457] open("/root/.icons/DMZ/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 3457] open("/usr/share/icons/DMZ/cursors/left_ptr", O_RDONLY) = 10 [pid 3457] open("/var/tmp/kdecache-root/icon-cache.kcache", O_RDWR|O_CREAT|O_CLOEXEC, 0666) = 10 [pid 3457] open("/var/tmp/kdecache-root/kpc/kde-icon-cache.data", O_RDONLY|O_CLOEXEC) = 10 [pid 3457] open("/var/tmp/kdecache-root/kpc/kde-icon-cache.index", O_RDONLY|O_CLOEXEC) = 10 [...]
Now you can move on to how to place your application in the K-Menu using .desktop files.