Difference between revisions of "Images (for developers)"

From Trinity Desktop Project Wiki
Jump to navigation Jump to search
(Started writing)
 
(Added basic instructions for loading and displaying images)
Line 12: Line 12:
 
* {{TQt class|TQIconSet}} is a helper class for icons.
 
* {{TQt class|TQIconSet}} is a helper class for icons.
 
: Compared to the basic image classes, this class does not represent a single image, but a ''set'' of images which correspond to an icon. A folder icon can come in different sizes (a different image file corresponds to each size), but it is still considered to be the same icon.
 
: Compared to the basic image classes, this class does not represent a single image, but a ''set'' of images which correspond to an icon. A folder icon can come in different sizes (a different image file corresponds to each size), but it is still considered to be the same icon.
  +
  +
Usually you won't need more advanced classes.
  +
  +
== Loading an image ==
  +
The simplest way to load an image is to use the constructor of the {{TQt class|TQPixmap}} class with the path of the file you want to load. If the file is located in one of your application paths (e.g. the <tt>share</tt> folder) use the [http://trinitydesktop.org/docs/trinity/tdelibs/tdecore/html/classTDEStandardDirs.html TDEStandardDirs] class.
  +
  +
If you want to load an icon, the simplest (and by far the most preferred) way to do so is via the [http://trinitydesktop.org/docs/trinity/tdelibs/tdecore/html/classTDEIconLoader.html TDEIconLoader] class. For TDE applications you don't even have to explicitly initialize this object. You can access a TDEIconLoader instance from the [http://trinitydesktop.org/docs/trinity/tdelibs/tdecore/html/classTDEApplication.html TDEApplication] class. The TDEIconLoader class makes sure that recommended settings are used for the kind of icon you are loading, so you usually need to provide a `group` parameter of type [http://trinitydesktop.org/docs/trinity/tdelibs/tdecore/html/classTDEIcon.html#a8d521faaf8f00ecbe33314a08d386f91 TDEIcon::Group] which defines the type of icon that you are loading and will decide its size and whether any effects will be applied to it. For example, to load a folder icon with the default settings for a toolbar icon:
  +
  +
<syntaxhighlight lang="c++">
  +
TQPixmap icon = kapp->iconLoader()->loadIcon("folder", TDEIcon::Toolbar);
  +
</syntaxhighlight>
  +
  +
== Displaying an image ==
  +
Images can be used in quite a few widgets, including labels, text views and buttons. These widgets offer constructors and/or functions where you can pass an image as an argument (usually as a {{TQt class|TQPixmap}} or a {{TQt class|TQIconSet}}.
  +
  +
The following example creates a push button with a folder icon from the icon theme:
  +
  +
<syntaxhighlight lang="c++">
  +
TQIconSet icon = kapp->iconLoader()->loadIconSet("folder", TDEIcon::Toolbar);
  +
TQPushButton *button = new TQPushButton(icon, i18n("Open folder..."), this);
  +
</syntaxhighlight>
  +
  +
If you want to display an image as standalone, you first need a widget where you will display it. Usually, a {{TQt class|TQLabel}} should be enough.
   
 
[[Category: Developers]]
 
[[Category: Developers]]

Revision as of 20:48, 25 November 2023

Messagebox warning.png
Work in progress
This page has been marked as undergoing heavy editing by user Blu256. Please be patient.

Working with images is an important part of a graphical application, whether it's a simple application or a complex graphical suite. In TQt/TDE, this can be as simple as learning to use a few classes. This guide aims to be a good guide for developers who want to work with TQt/TDE.

Image classes

  • TQPixmap API is one of the two basic image classes provided by TQt.
It is, essentially, a paint device, so it is optimized for drawing. You'll see this class used a lot (more than TQImage) because of this quality.
  • TQImage API is the other basic image class.
According to the API docs, it is "a hardware-independent pixmap representation" and it is optimized for I/O operations and direct pixel access and manipulation.
  • TQIconSet API is a helper class for icons.
Compared to the basic image classes, this class does not represent a single image, but a set of images which correspond to an icon. A folder icon can come in different sizes (a different image file corresponds to each size), but it is still considered to be the same icon.

Usually you won't need more advanced classes.

Loading an image

The simplest way to load an image is to use the constructor of the TQPixmap API class with the path of the file you want to load. If the file is located in one of your application paths (e.g. the share folder) use the TDEStandardDirs class.

If you want to load an icon, the simplest (and by far the most preferred) way to do so is via the TDEIconLoader class. For TDE applications you don't even have to explicitly initialize this object. You can access a TDEIconLoader instance from the TDEApplication class. The TDEIconLoader class makes sure that recommended settings are used for the kind of icon you are loading, so you usually need to provide a `group` parameter of type TDEIcon::Group which defines the type of icon that you are loading and will decide its size and whether any effects will be applied to it. For example, to load a folder icon with the default settings for a toolbar icon:

TQPixmap icon = kapp->iconLoader()->loadIcon("folder", TDEIcon::Toolbar);

Displaying an image

Images can be used in quite a few widgets, including labels, text views and buttons. These widgets offer constructors and/or functions where you can pass an image as an argument (usually as a TQPixmap API or a TQIconSet API.

The following example creates a push button with a folder icon from the icon theme:

TQIconSet icon = kapp->iconLoader()->loadIconSet("folder", TDEIcon::Toolbar);
TQPushButton *button = new TQPushButton(icon, i18n("Open folder..."), this);

If you want to display an image as standalone, you first need a widget where you will display it. Usually, a TQLabel API should be enough.