A widget that displays an image. More...
#include <Wt/WImage>
Public Member Functions | |
WImage (WContainerWidget *parent=0) | |
Creates an empty image widget. | |
WImage (const std::string &imageRef, WContainerWidget *parent=0) | |
Creates an image widget with given image URL. | |
WImage (const std::string &imageRef, const WString &altText, WContainerWidget *parent=0) | |
Creates an image widget with given image URL and alternate text. | |
WImage (WResource *resource, const WString &altText, WContainerWidget *parent=0) | |
Creates an image widget with given image resource and alternate text. | |
void | setAlternateText (const WString &text) |
Sets an alternate text. | |
const WString & | alternateText () const |
Returns the alternate text. | |
void | setImageRef (const std::string &url) |
Sets the image URL. | |
const std::string | imageRef () const |
Returns the image URL. | |
void | setResource (WResource *resource) |
Sets the image resource. | |
WResource * | resource () const |
Returns the image resource. | |
void | addArea (WAbstractArea *area) |
Adds an interactive area. | |
void | insertArea (int index, WAbstractArea *area) |
Inserts an interactive area. | |
void | removeArea (WAbstractArea *area) |
Removes an interactive area. | |
WAbstractArea * | area (int index) const |
Returns the interactive area at the given index. | |
const std::vector < WAbstractArea * > | areas () const |
Returns the interactive areas set for this widget. | |
EventSignal & | imageLoaded () |
Event emitted when the image was loaded. |
A widget that displays an image.
The image may be specified either as a URL, or may be dynamically generated by a WResource.
You may listen to events by attaching event listeners to signals such as clicked(). Since mouse events pass the coordinates through a WMouseEvent object, it is possible to react to clicks in specific parts of the image. An alternative is to define interactive areas on the image using addArea(), which in addition allows to have customized tool tips for certain image areas (using WAbstractArea::setToolTip()).
Usage example:
Wt::WImage *img = new Wt::WImage("images/johnny_cash.png", this); img->setAlternateText("Johnny Cash sings a song");
WImage is an inline widget.
The widget corresponds to the HTML <img>
tag and does not provide styling. It can be styled using inline or external CSS as appropriate.
Wt::WImage::WImage | ( | WResource * | resource, |
const WString & | altText, | ||
WContainerWidget * | parent = 0 |
||
) |
Creates an image widget with given image resource and alternate text.
Use this constructor if you want to present a dynamically generated image.
void Wt::WImage::addArea | ( | WAbstractArea * | area ) |
Adds an interactive area.
Adds the area
which listens to events in a specific region of the image. Areas are organized in an indexed list, to which the given area
is appended. When areas overlap, the area with the lowest index receives the event.
Ownership of the area
is transferred to the image.
const WString& Wt::WImage::alternateText | ( | ) | const [inline] |
Returns the alternate text.
WAbstractArea * Wt::WImage::area | ( | int | index ) | const |
Returns the interactive area at the given index.
Returns 0
if index
was invalid.
const std::vector< WAbstractArea * > Wt::WImage::areas | ( | ) | const |
Returns the interactive areas set for this widget.
const std::string Wt::WImage::imageRef | ( | ) | const |
Returns the image URL.
When the image is specified as a resource, this returns the current resource URL.
void Wt::WImage::insertArea | ( | int | index, |
WAbstractArea * | area | ||
) |
Inserts an interactive area.
Inserts the area
which listens to events in the coresponding area of the image. Areas are organized in a list, and the area is inserted at index index
. When areas overlap, the area with the lowest index receives the event.
Ownership of the Area
is transferred to the image.
void Wt::WImage::removeArea | ( | WAbstractArea * | area ) |
Removes an interactive area.
Removes the area
from this widget, and also returns the ownership.
WResource* Wt::WImage::resource | ( | ) | const [inline] |
Returns the image resource.
Returns 0
if no image resource was set.
void Wt::WImage::setAlternateText | ( | const WString & | text ) |
Sets an alternate text.
The alternate text should provide a fallback for browsers that do not display an image. If no sensible fallback text can be provided, an empty text is preferred over nonsense.
This should not be confused with toolTip() text, which provides additional information that is displayed when the mouse hovers over the image.
The default alternate text is an empty text ("").
void Wt::WImage::setImageRef | ( | const std::string & | url ) |
Sets the image URL.
This should not be used when the image is specified as a resource.
void Wt::WImage::setResource | ( | WResource * | resource ) |
Sets the image resource.
A resource specifies application-dependent content, which may be used to generate an image on demand.
This sets resource
as the contents for the image, as an alternative to setImageRef(). The resource may be cleared by passing resource
= 0
.
The image does not assume ownership of the resource.