Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQIconViewItem Class Reference
[iconview module]

The TQIconViewItem class provides a single item in a TQIconView. More...

#include <ntqiconview.h>

Inherits TQt.

List of all member functions.

Public Members

Protected Members


Detailed Description

The TQIconViewItem class provides a single item in a TQIconView.

A TQIconViewItem contains an icon, a string and optionally a sort key, and can display itself in a TQIconView. The class is designed to be very similar to TQListView and TQListBox in use, both via instantiation and subclassing.

The simplest way to create a TQIconViewItem and insert it into a TQIconView is to construct the item passing the constructor a pointer to the icon view, a string and an icon:

    (void) new TQIconViewItem(
                    iconView,   // A pointer to a TQIconView
                    "This is the text of the item",
                    aPixmap );
    

By default the text of an icon view item may not be edited by the user but calling setRenameEnabled(TRUE) will allow the user to perform in-place editing of the item's text.

When the icon view is deleted all items in it are deleted automatically.

The TQIconView::firstItem() and TQIconViewItem::nextItem() functions provide a means of iterating over all the items in a TQIconView:

    TQIconViewItem *item;
    for ( item = iconView->firstItem(); item; item = item->nextItem() )
        do_something_with( item );
    

The item's icon view is available from iconView(), and its position in the icon view from index().

The item's selection status is available from isSelected() and is set and controlled by setSelected() and isSelectable().

The text and icon can be set with setText() and setPixmap() and retrieved with text() and pixmap(). The item's sort key defaults to text() but may be set with setKey() and retrieved with key(). The comparison function, compare() uses key().

Items may be repositioned with move() and moveBy(). An item's geometry is available from rect(), x(), y(), width(), height(), size(), pos(), textRect() and pixmapRect(). You can also test against the position of a point with contains() and intersects().

To remove an item from an icon view, just delete the item. The TQIconViewItem destructor removes it cleanly from its icon view.

Because the icon view is designed to use drag-and-drop, the icon view item also has functions for drag-and-drop which may be reimplemented.

Note: Pixmaps with individual dimensions larger than 300 pixels may not be displayed properly, depending on the arrangement in use. For example, pixmaps wider than 300 pixels will not be arranged correctly if the icon view uses a TQIconView::TopToBottom arrangement, and pixmaps taller than 300 pixels will not be arranged correctly if the icon view uses a TQIconView::LeftToRight arrangement.

See also Advanced Widgets.


Member Function Documentation

TQIconViewItem::TQIconViewItem ( TQIconView * parent )

Constructs a TQIconViewItem and inserts it into icon view parent with no text and a default icon.

TQIconViewItem::TQIconViewItem ( TQIconView * parent, TQIconViewItem * after )

Constructs a TQIconViewItem and inserts it into the icon view parent with no text and a default icon, after the icon view item after.

TQIconViewItem::TQIconViewItem ( TQIconView * parent, const TQString & text )

Constructs an icon view item and inserts it into the icon view parent using text as the text and a default icon.

TQIconViewItem::TQIconViewItem ( TQIconView * parent, TQIconViewItem * after, const TQString & text )

Constructs an icon view item and inserts it into the icon view parent using text as the text and a default icon, after the icon view item after.

TQIconViewItem::TQIconViewItem ( TQIconView * parent, const TQString & text, const TQPixmap & icon )

Constructs an icon view item and inserts it into the icon view parent using text as the text and icon as the icon.

TQIconViewItem::TQIconViewItem ( TQIconView * parent, TQIconViewItem * after, const TQString & text, const TQPixmap & icon )

Constructs an icon view item and inserts it into the icon view parent using text as the text and icon as the icon, after the icon view item after.

See also setPixmap().

TQIconViewItem::TQIconViewItem ( TQIconView * parent, const TQString & text, const TQPicture & picture )

Constructs an icon view item and inserts it into the icon view parent using text as the text and picture as the icon.

TQIconViewItem::TQIconViewItem ( TQIconView * parent, TQIconViewItem * after, const TQString & text, const TQPicture & picture )

Constructs an icon view item and inserts it into the icon view parent using text as the text and picture as the icon, after the icon view item after.

TQIconViewItem::~TQIconViewItem () [virtual]

Destroys the icon view item and tells the parent icon view that the item has been destroyed.

bool TQIconViewItem::acceptDrop ( const TQMimeSource * mime ) const [virtual]

Returns TRUE if you can drop things with a TQMimeSource of mime onto this item; otherwise returns FALSE.

The default implementation always returns FALSE. You must subclass TQIconViewItem and reimplement acceptDrop() to accept drops.

Examples: fileiconview/qfileiconview.cpp and iconview/simple_dd/main.cpp.

void TQIconViewItem::calcRect ( const TQString & text_ = TQString::null ) [virtual protected]

This virtual function is responsible for calculating the rectangles returned by rect(), textRect() and pixmapRect(). setRect(), setTextRect() and setPixmapRect() are provided mainly for reimplementations of this function.

text_ is an internal parameter which defaults to TQString::null.

int TQIconViewItem::compare ( TQIconViewItem * i ) const [virtual]

Compares this icon view item to i. Returns -1 if this item is less than i, 0 if they are equal, and 1 if this icon view item is greater than i.

The default implementation compares the item keys (key()) using TQString::localeAwareCompare(). A reimplementation may use different values and a different comparison function. Here is a reimplementation that uses plain Unicode comparison:

        int MyIconViewItem::compare( TQIconViewItem *i ) const
        {
            return key().compare( i->key() );
        }
    

See also key(), TQString::localeAwareCompare(), and TQString::compare().

bool TQIconViewItem::contains ( const TQPoint & pnt ) const

Returns TRUE if the item contains the point pnt (in contents coordinates); otherwise returns FALSE.

bool TQIconViewItem::dragEnabled () const

Returns TRUE if the user is allowed to drag the icon view item; otherwise returns FALSE.

See also setDragEnabled().

void TQIconViewItem::dragEntered () [virtual protected]

This function is called when a drag enters the item's bounding rectangle.

The default implementation does nothing; subclasses may reimplement this function.

Example: fileiconview/qfileiconview.cpp.

void TQIconViewItem::dragLeft () [virtual protected]

This function is called when a drag leaves the item's bounding rectangle.

The default implementation does nothing; subclasses may reimplement this function.

Example: fileiconview/qfileiconview.cpp.

bool TQIconViewItem::dropEnabled () const

Returns TRUE if the user is allowed to drop something onto the item; otherwise returns FALSE.

See also setDropEnabled().

void TQIconViewItem::dropped ( TQDropEvent * e, const TQValueList<TQIconDragItem> & lst ) [virtual protected]

This function is called when something is dropped on the item. e provides all the information about the drop. If the drag object of the drop was a TQIconDrag, lst contains the list of the dropped items. You can get the data by calling TQIconDragItem::data() on each item. If the lst is empty, i.e. the drag was not a TQIconDrag, you must decode the data in e and work with that.

The default implementation does nothing; subclasses may reimplement this function.

Examples: fileiconview/qfileiconview.cpp and iconview/simple_dd/main.cpp.

int TQIconViewItem::height () const

Returns the height of the item.

TQIconView * TQIconViewItem::iconView () const

Returns a pointer to this item's icon view parent.

int TQIconViewItem::index () const

Returns the index of this item in the icon view, or -1 if an error occurred.

bool TQIconViewItem::intersects ( const TQRect & r ) const

Returns TRUE if the item intersects the rectangle r (in contents coordinates); otherwise returns FALSE.

bool TQIconViewItem::isSelectable () const

Returns TRUE if the item is selectable; otherwise returns FALSE.

See also setSelectable().

bool TQIconViewItem::isSelected () const

Returns TRUE if the item is selected; otherwise returns FALSE.

See also setSelected().

Example: fileiconview/qfileiconview.cpp.

TQString TQIconViewItem::key () const [virtual]

Returns the key of the icon view item or text() if no key has been explicitly set.

See also setKey() and compare().

bool TQIconViewItem::move ( int x, int y ) [virtual]

Moves the item to position (x, y) in the icon view (these are contents coordinates).

bool TQIconViewItem::move ( const TQPoint & pnt ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Moves the item to the point pnt.

void TQIconViewItem::moveBy ( int dx, int dy ) [virtual]

Moves the item dx pixels in the x-direction and dy pixels in the y-direction.

void TQIconViewItem::moveBy ( const TQPoint & pnt ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Moves the item by the x, y values in point pnt.

TQIconViewItem * TQIconViewItem::nextItem () const

Returns a pointer to the next item, or 0 if this is the last item in the icon view.

To find the first item use TQIconView::firstItem().

Example:

    TQIconViewItem *item;
    for ( item = iconView->firstItem(); item; item = item->nextItem() )
        do_something_with( item );
    

See also prevItem().

Example: fileiconview/qfileiconview.cpp.

void TQIconViewItem::paintFocus ( TQPainter * p, const TQColorGroup & cg ) [virtual protected]

Paints the focus rectangle of the item using the painter p and the color group cg.

void TQIconViewItem::paintItem ( TQPainter * p, const TQColorGroup & cg ) [virtual protected]

Paints the item using the painter p and the color group cg. If you want the item to be drawn with a different font or color, reimplement this function, change the values of the color group or the painter's font, and then call the TQIconViewItem::paintItem() with the changed values.

Example: fileiconview/qfileiconview.cpp.

TQPicture * TQIconViewItem::picture () const [virtual]

Returns the icon of the icon view item if it is a picture, or 0 if it is a pixmap. In the latter case use pixmap() instead. Normally you set the picture of the item with setPicture(), but sometimes it's inconvenient to call setPicture() for every item. So you can subclass TQIconViewItem, reimplement this function and return a pointer to the item's picture. If you do this, you must call calcRect() manually each time the size of this picture changes.

See also setPicture().

TQPixmap * TQIconViewItem::pixmap () const [virtual]

Returns the icon of the icon view item if it is a pixmap, or 0 if it is a picture. In the latter case use picture() instead. Normally you set the pixmap of the item with setPixmap(), but sometimes it's inconvenient to call setPixmap() for every item. So you can subclass TQIconViewItem, reimplement this function and return a pointer to the item's pixmap. If you do this, you must call calcRect() manually each time the size of this pixmap changes.

See also setPixmap().

Example: fileiconview/qfileiconview.cpp.

TQRect TQIconViewItem::pixmapRect ( bool relative = TRUE ) const

Returns the bounding rectangle of the item's icon.

If relative is TRUE, (the default), the rectangle is relative to the origin of the item's rectangle. If relative is FALSE, the returned rectangle is relative to the origin of the icon view's contents coordinate system.

Example: fileiconview/qfileiconview.cpp.

TQPoint TQIconViewItem::pos () const

Returns the position of the item (in contents coordinates).

TQIconViewItem * TQIconViewItem::prevItem () const

Returns a pointer to the previous item, or 0 if this is the first item in the icon view.

See also nextItem() and TQIconView::firstItem().

TQRect TQIconViewItem::rect () const

Returns the bounding rectangle of the item (in contents coordinates).

void TQIconViewItem::removeRenameBox () [virtual protected]

Removes the editbox that is used for in-place renaming.

void TQIconViewItem::rename ()

Starts in-place renaming of an icon, if allowed.

This function sets up the icon view so that the user can edit the item text, and then returns. When the user is done, setText() will be called and TQIconView::itemRenamed() will be emitted (unless the user canceled, e.g. by pressing the Escape key).

See also setRenameEnabled().

Example: fileiconview/qfileiconview.cpp.

bool TQIconViewItem::renameEnabled () const

Returns TRUE if the item can be renamed by the user with in-place renaming; otherwise returns FALSE.

See also setRenameEnabled().

Example: fileiconview/qfileiconview.cpp.

void TQIconViewItem::repaint () [virtual]

Repaints the item.

int TQIconViewItem::rtti () const [virtual]

Returns 0.

Make your derived classes return their own values for rtti(), so that you can distinguish between icon view item types. You should use values greater than 1000, preferably a large random number, to allow for extensions to this class.

void TQIconViewItem::setDragEnabled ( bool allow ) [virtual]

If allow is TRUE, the icon view permits the user to drag the icon view item either to another position within the icon view or to somewhere outside of it. If allow is FALSE, the item cannot be dragged.

void TQIconViewItem::setDropEnabled ( bool allow ) [virtual]

If allow is TRUE, the icon view lets the user drop something on this icon view item.

void TQIconViewItem::setItemRect ( const TQRect & r ) [protected]

Sets the bounding rectangle of the whole item to r. This function is provided for subclasses which reimplement calcRect(), so that they can set the calculated rectangle. Any other use is discouraged.

See also calcRect(), textRect(), setTextRect(), pixmapRect(), and setPixmapRect().

void TQIconViewItem::setKey ( const TQString & k ) [virtual]

Sets k as the sort key of the icon view item. By default text() is used for sorting.

See also compare().

Example: fileiconview/qfileiconview.cpp.

void TQIconViewItem::setPicture ( const TQPicture & icon ) [virtual]

Sets icon as the item's icon in the icon view. This function might be a no-op if you reimplement picture().

See also picture().

void TQIconViewItem::setPixmap ( const TQPixmap & icon ) [virtual]

Sets icon as the item's icon in the icon view. This function might be a no-op if you reimplement pixmap().

Note: Pixmaps with individual dimensions larger than 300 pixels may not be displayed properly, depending on the arrangement in use. See the main class documentation for details.

See also pixmap().

void TQIconViewItem::setPixmap ( const TQPixmap & icon, bool recalc, bool redraw = TRUE ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets icon as the item's icon in the icon view. If recalc is TRUE, the icon view's layout is recalculated. If redraw is TRUE (the default), the icon view is repainted.

Note: Pixmaps with individual dimensions larger than 300 pixels may not be displayed properly, depending on the arrangement in use. See the main class documentation for details.

See also pixmap().

void TQIconViewItem::setPixmapRect ( const TQRect & r ) [protected]

Sets the bounding rectangle of the item's icon to r. This function is provided for subclasses which reimplement calcRect(), so that they can set the calculated rectangle. Any other use is discouraged.

See also calcRect(), pixmapRect(), setItemRect(), and setTextRect().

void TQIconViewItem::setRenameEnabled ( bool allow ) [virtual]

If allow is TRUE, the user can rename the icon view item by clicking on the text (or pressing F2) while the item is selected (in-place renaming). If allow is FALSE, in-place renaming is not possible.

Examples: fileiconview/qfileiconview.cpp, iconview/main.cpp, and iconview/simple_dd/main.cpp.

void TQIconViewItem::setSelectable ( bool enable ) [virtual]

Sets this item to be selectable if enable is TRUE (the default) or unselectable if enable is FALSE.

The user is unable to select a non-selectable item using either the keyboard or the mouse. (The application programmer can select an item in code regardless of this setting.)

See also isSelectable().

void TQIconViewItem::setSelected ( bool s, bool cb ) [virtual]

Selects or unselects the item, depending on s; it may also unselect other items, depending on TQIconView::selectionMode() and cb.

If s is FALSE, the item is unselected.

If s is TRUE and TQIconView::selectionMode() is Single, the item is selected and the item previously selected is unselected.

If s is TRUE and TQIconView::selectionMode() is Extended, the item is selected. If cb is TRUE, the selection state of the other items is left unchanged. If cb is FALSE (the default) all other items are unselected.

If s is TRUE and TQIconView::selectionMode() is Multi, the item is selected.

Note that cb is used only if TQIconView::selectionMode() is Extended; cb defaults to FALSE.

All items whose selection status changes repaint themselves.

Example: fileiconview/qfileiconview.cpp.

void TQIconViewItem::setSelected ( bool s ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This variant is equivalent to calling the other variant with cb set to FALSE.

void TQIconViewItem::setText ( const TQString & text ) [virtual]

Sets text as the text of the icon view item. This function might be a no-op if you reimplement text().

See also text().

Example: fileiconview/qfileiconview.cpp.

void TQIconViewItem::setText ( const TQString & text, bool recalc, bool redraw = TRUE ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets text as the text of the icon view item. If recalc is TRUE, the icon view's layout is recalculated. If redraw is TRUE (the default), the icon view is repainted.

See also text().

void TQIconViewItem::setTextRect ( const TQRect & r ) [protected]

Sets the bounding rectangle of the item's text to r. This function is provided for subclasses which reimplement calcRect(), so that they can set the calculated rectangle. Any other use is discouraged.

See also calcRect(), textRect(), setItemRect(), and setPixmapRect().

TQSize TQIconViewItem::size () const

Returns the size of the item.

TQString TQIconViewItem::text () const [virtual]

Returns the text of the icon view item. Normally you set the text of the item with setText(), but sometimes it's inconvenient to call setText() for every item; so you can subclass TQIconViewItem, reimplement this function, and return the text of the item. If you do this, you must call calcRect() manually each time the text (and therefore its size) changes.

See also setText().

Example: fileiconview/qfileiconview.cpp.

TQRect TQIconViewItem::textRect ( bool relative = TRUE ) const

Returns the bounding rectangle of the item's text.

If relative is TRUE, (the default), the returned rectangle is relative to the origin of the item's rectangle. If relative is FALSE, the returned rectangle is relative to the origin of the icon view's contents coordinate system.

Example: fileiconview/qfileiconview.cpp.

int TQIconViewItem::width () const

Returns the width of the item.

int TQIconViewItem::x () const

Returns the x-coordinate of the item (in contents coordinates).

int TQIconViewItem::y () const

Returns the y-coordinate of the item (in contents coordinates).

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8