Difference between revisions of "Images (for developers)"

From Trinity Desktop Project Wiki
Jump to navigation Jump to search
m (Switch to the new TDE class template)
m (Add layout of page)
Line 15: Line 15:
 
Usually you won't need more advanced classes.
 
Usually you won't need more advanced classes.
   
== Loading an image ==
+
== Basic usage ==
  +
=== 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 {{TDE class|tdelibs|tdecore|TDEStandardDirs}} class.
 
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 {{TDE class|tdelibs|tdecore|TDEStandardDirs}} class.
   
Line 24: Line 25:
 
</syntaxhighlight>
 
</syntaxhighlight>
   
== Displaying an image ==
+
=== 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}}.
 
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}}.
   
Line 35: Line 36:
   
 
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.
 
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.
  +
  +
=== Applying effects ===
  +
{{TODO}}
  +
  +
== Advanced usage ==
  +
=== Saving an image ===
  +
{{TODO}}
  +
  +
==== Using KImageIO ====
  +
{{TODO}}
  +
  +
== TDE Developers' usage ==
  +
=== Adding image format support ===
  +
{{TODO}}
   
 
[[Category: Developers]]
 
[[Category: Developers]]

Revision as of 20:58, 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.

Basic usage

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 API class.

If you want to load an icon, the simplest (and by far the most preferred) way to do so is via the TDEIconLoader API class. For TDE applications you don't even have to explicitly initialize this object. You can access an instance of this class through the `kapp` pointer of the TDEApplication API class. The icon loader 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.

Applying effects

Konqi.png
To-do
This section has not been written/completed yet. You can contribute to Trinity by writing or finalizing this section.

Advanced usage

Saving an image

Konqi.png
To-do
This section has not been written/completed yet. You can contribute to Trinity by writing or finalizing this section.

Using KImageIO

Konqi.png
To-do
This section has not been written/completed yet. You can contribute to Trinity by writing or finalizing this section.

TDE Developers' usage

Adding image format support

Konqi.png
To-do
This section has not been written/completed yet. You can contribute to Trinity by writing or finalizing this section.