Wt::WImage Class Reference

A widget that displays an image. More...

#include <Wt/WImage>

Inheritance diagram for Wt::WImage:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 WImage (WContainerWidget *parent=0)
 Create an empty image widget.
 WImage (const std::string &imageRef, WContainerWidget *parent=0)
 Create an image widget with given image URL.
 WImage (const std::string &imageRef, const WString &altText, WContainerWidget *parent=0)
 Create an image widget with given image URL and alternate text.
 WImage (WResource *resource, const WString &altText, WContainerWidget *parent=0)
 Create an image widget with given image resource and alternate text.
void setAlternateText (const WString &text)
 Set an alternate text.
const WStringalternateText () const
 Returns the alternate text.
void setImageRef (const std::string &url)
 Set the image URL.
const std::string imageRef () const
 Returns the image URL.
void setResource (WResource *resource)
 Set the image resource.
WResourceresource () const
 Returns the image resource.
void addArea (WAbstractArea *area)
 Add an interactive area.
void insertArea (int index, WAbstractArea *area)
 Insert an interactive area.
void removeArea (WAbstractArea *area)
 Removes an interactive area.
WAbstractAreaarea (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< void > & imageLoaded ()
 Event emitted when the image was loaded.


Detailed Description

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/jhonny_cash.png", this);
 img->setAlternateText("Jhonny Cash sings a song");

WImage is an inline widget.

The widget corresponds to the HTML <img> tag.

See also:
WResource, WPaintedWidget

Constructor & Destructor Documentation

Wt::WImage::WImage ( WResource resource,
const WString altText,
WContainerWidget parent = 0 
)

Create an image widget with given image resource and alternate text.

Use this constructor if you want to present a dynamically generated image.


Member Function Documentation

void Wt::WImage::setAlternateText ( const WString text  ) 

Set 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 ("").

See also:
alternateText()

const WString& Wt::WImage::alternateText (  )  const [inline]

Returns the alternate text.

See also:
setAlternateText()

void Wt::WImage::setImageRef ( const std::string &  url  ) 

Set the image URL.

This should not be used when the image is specified as a resource.

See also:
setResource()

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::setResource ( WResource resource  ) 

Set 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.

See also:
setImageRef()

WResource* Wt::WImage::resource (  )  const [inline]

Returns the image resource.

Returns 0 if no image resource was set.

void Wt::WImage::addArea ( WAbstractArea area  ) 

Add 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.

See also:
insertArea(int, WAbstractArea *)

void Wt::WImage::insertArea ( int  index,
WAbstractArea area 
)

Insert 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.

See also:
addArea(WAbstractArea *)

void Wt::WImage::removeArea ( WAbstractArea area  ) 

Removes an interactive area.

Removes the area from this widget, and also returns the ownership.

See also:
addArea(WAbstractArea *)

WAbstractArea * Wt::WImage::area ( int  index  )  const

Returns the interactive area at the given index.

Returns 0 if index was invalid.

See also:
insertArea(int, WAbstractArea *)

const std::vector< WAbstractArea * > Wt::WImage::areas (  )  const

Returns the interactive areas set for this widget.

See also:
addArea()


Generated on Mon Mar 9 08:27:51 2009 for Wt by doxygen 1.5.6