📄 q3iconview.cpp
字号:
}/*! Sets the data for the Q3IconDragItem to the data stored in the QByteArray \a d.*/void Q3IconDragItem::setData(const QByteArray &d){ ba = d;}/*! \internal*/bool Q3IconDragItem::operator==(const Q3IconDragItem &i) const{ return ba == i.ba;}/*! \reimp*/bool Q3IconDragDataItem::operator==(const Q3IconDragDataItem &i) const{ return (i.item == item && i.data == data);}/*! \reimp*/bool Q3IconDragData::operator==(const Q3IconDragData &i) const{ return key_ == i.key_;}/*! \class Q3IconDrag qiconview.h \brief The Q3IconDrag class supports drag and drop operations within a Q3IconView. \compat A Q3IconDrag object is used to maintain information about the positions of dragged items and the data associated with them. Q3IconViews are able to use this information to paint the dragged items in the correct positions. Internally, Q3IconDrag stores the data associated with drag items in Q3IconDragItem objects. If you want to use the extended drag and drop functionality of Q3IconView, create a Q3IconDrag object in a reimplementation of Q3IconView::dragObject(). Then create a Q3IconDragItem for each item which should be dragged, set the data it represents with Q3IconDragItem::setData(), and add each Q3IconDragItem to the drag object using append(). The data in Q3IconDragItems is stored in a QByteArray and is mime-typed (see QMimeSource and the \link http://doc.trolltech.com/dnd.html Drag and Drop\endlink overview). If you want to use your own mime-types derive a class from Q3IconDrag and reimplement format(), encodedData() and canDecode(). The fileiconview example program demonstrates the use of the Q3IconDrag class including subclassing and reimplementing dragObject(), format(), encodedData() and canDecode(). \sa QMimeSource::format()*//*! Constructs a drag object called \a name, which is a child of \a dragSource. Note that the drag object will be deleted when \a dragSource is deleted.*/Q3IconDrag::Q3IconDrag(QWidget * dragSource, const char* name) : Q3DragObject(dragSource, name){ d = new Q3IconDragPrivate;}/*! Destructor.*/Q3IconDrag::~Q3IconDrag(){ delete d;}/*! Append the Q3IconDragItem, \a i, to the Q3IconDrag object's list of items. You must also supply the geometry of the pixmap, \a pr, and the textual caption, \a tr. \sa Q3IconDragItem*/void Q3IconDrag::append(const Q3IconDragItem &i, const QRect &pr, const QRect &tr){ d->items.append(Q3IconDragDataItem(i, Q3IconDragData(pr, tr)));}/*! \reimp*/const char* Q3IconDrag::format(int i) const{ if (i == 0) return "application/x-qiconlist"; return 0;}/*! Returns the encoded data of the drag object if \a mime is application/x-qiconlist.*/QByteArray Q3IconDrag::encodedData(const char* mime) const{ if (d->items.size() <= 0 || QString::fromLatin1(mime) != QString::fromLatin1("application/x-qiconlist")) return QByteArray(); QLinkedList<Q3IconDragDataItem>::ConstIterator it = d->items.begin(); QString s; for (; it != d->items.end(); ++it) { QString k(QLatin1String("%1$@@$%2$@@$%3$@@$%4$@@$%5$@@$%6$@@$%7$@@$%8$@@$")); k = k.arg((*it).item.pixmapRect().x()).arg( (*it).item.pixmapRect().y()).arg((*it).item.pixmapRect().width()). arg((*it).item.pixmapRect().height()).arg( (*it).item.textRect().x()).arg((*it).item.textRect().y()). arg((*it).item.textRect().width()).arg( (*it).item.textRect().height()); k += QString(QLatin1String((*it).data.data())) + QLatin1String("$@@$"); s += k; } QByteArray a; a.resize(s.length() + 1); memcpy(a.data(), s.latin1(), a.size()); return a;}/*! Returns true if \a e can be decoded by the Q3IconDrag, otherwise return false.*/bool Q3IconDrag::canDecode(QMimeSource* e){ if (e->provides("application/x-qiconlist")) return true; return false;}/*! Decodes the data which is stored (encoded) in \a e and, if successful, fills the \a list of icon drag items with the decoded data. Returns true if there was some data, false otherwise.*/bool Q3IconDragPrivate::decode(QMimeSource* e, QLinkedList<Q3IconDragDataItem> &lst){ QByteArray ba = e->encodedData("application/x-qiconlist"); if (ba.size()) { lst.clear(); // #### unicode clean???? QString s = QString::fromLatin1(ba); Q3IconDragDataItem item; QRect ir, tr; QStringList l = QStringList::split(QLatin1String("$@@$"), s); int i = 0; QStringList::Iterator it = l.begin(); for (; it != l.end(); ++it) { if (i == 0) { ir.setX((*it).toInt()); } else if (i == 1) { ir.setY((*it).toInt()); } else if (i == 2) { ir.setWidth((*it).toInt()); } else if (i == 3) { ir.setHeight((*it).toInt()); } else if (i == 4) { tr.setX((*it).toInt()); } else if (i == 5) { tr.setY((*it).toInt()); } else if (i == 6) { tr.setWidth((*it).toInt()); } else if (i == 7) { tr.setHeight((*it).toInt()); } else if (i == 8) { QByteArray d; d.resize((*it).length()); memcpy(d.data(), (*it).latin1(), (*it).length()); item.item.setPixmapRect(ir); item.item.setTextRect(tr); item.data.setData(d); lst.append(item); } ++i; if (i > 8) i = 0; } return true; } return false;}Q3IconDragData::Q3IconDragData() : iconRect_(), textRect_(){}Q3IconDragData::Q3IconDragData(const QRect &ir, const QRect &tr) : iconRect_(ir), textRect_(tr){}QRect Q3IconDragData::textRect() const{ return textRect_;}QRect Q3IconDragData::pixmapRect() const{ return iconRect_;}void Q3IconDragData::setPixmapRect(const QRect &r){ iconRect_ = r;}void Q3IconDragData::setTextRect(const QRect &r){ textRect_ = r;}#endif/*! \class Q3IconViewItem qiconview.h \brief The Q3IconViewItem class provides a single item in a Q3IconView. \compat A Q3IconViewItem contains an icon, a string and optionally a sort key, and can display itself in a Q3IconView. The simplest way to create a Q3IconViewItem and insert it into a Q3IconView is to construct the item passing the constructor a pointer to the icon view, a string and an icon: \code (void) new Q3IconViewItem( iconView, // A pointer to a Q3IconView "This is the text of the item", aPixmap); \endcode 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 Q3IconView::firstItem() and Q3IconViewItem::nextItem() functions provide a means of iterating over all the items in a Q3IconView: \code Q3IconViewItem *item; for (item = iconView->firstItem(); item; item = item->nextItem()) do_something_with(item); \endcode 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 Q3IconViewItem 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. The class is designed to be very similar to Q3ListView and Q3ListBox in use, both via instantiation and subclassing.*//*! Constructs a Q3IconViewItem and inserts it into icon view \a parent with no text and a default icon.*/Q3IconViewItem::Q3IconViewItem(Q3IconView *parent) : view(parent), itemText(), itemIcon(unknown_icon){ init();}/*! Constructs a Q3IconViewItem and inserts it into the icon view \a parent with no text and a default icon, after the icon view item \a after.*/Q3IconViewItem::Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after) : view(parent), itemText(), itemIcon(unknown_icon), prev(0), next(0){ init(after);}/*! Constructs an icon view item and inserts it into the icon view \a parent using \a text as the text and a default icon.*/Q3IconViewItem::Q3IconViewItem(Q3IconView *parent, const QString &text) : view(parent), itemText(text), itemIcon(unknown_icon){ init(0);}/*! Constructs an icon view item and inserts it into the icon view \a parent using \a text as the text and a default icon, after the icon view item \a after.*/Q3IconViewItem::Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after, const QString &text) : view(parent), itemText(text), itemIcon(unknown_icon){ init(after);}/*! Constructs an icon view item and inserts it into the icon view \a parent using \a text as the text and \a icon as the icon.*/Q3IconViewItem::Q3IconViewItem(Q3IconView *parent, const QString &text, const QPixmap &icon) : view(parent), itemText(text), itemIcon(new QPixmap(icon)){ init(0);}/*! Constructs an icon view item and inserts it into the icon view \a parent using \a text as the text and \a icon as the icon, after the icon view item \a after.*/Q3IconViewItem::Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after, const QString &text, const QPixmap &icon) : view(parent), itemText(text), itemIcon(new QPixmap(icon)){ init(after);}/*! Constructs an icon view item and inserts it into the icon view \a parent using \a text as the text and \a picture as the icon.*/#ifndef QT_NO_PICTUREQ3IconViewItem::Q3IconViewItem(Q3IconView *parent, const QString &text, const QPicture &picture) : view(parent), itemText(text), itemIcon(0){ init(0, new QPicture(picture));}/*! Constructs an icon view item and inserts it into the icon view \a parent using \a text as the text and \a picture as the icon, after the icon view item \a after.*/Q3IconViewItem::Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after, const QString &text, const QPicture &picture) : view(parent), itemText(text), itemIcon(0){ init(after, new QPicture(picture));}#endif/*! This private function initializes the icon view item and inserts it into the icon view.*/void Q3IconViewItem::init(Q3IconViewItem *after#ifndef QT_NO_PICTURE , QPicture *pic#endif ){ d = new Q3IconViewItemPrivate; d->container1 = 0; d->container2 = 0; prev = next = 0; allow_rename = false; allow_drag = true; allow_drop = true; selected = false; selectable = true;#ifndef QT_NO_TEXTEDIT renameBox = 0;#endif#ifndef QT_NO_PICTURE itemPic = pic;#endif if (view) { itemKey = itemText; dirty = true; wordWrapDirty = true; itemRect = QRect(-1, -1, 0, 0); calcRect(); view->insertItem(this, after); }}/*! Destroys the icon view item and tells the parent icon view that the item has been destroyed.*/Q3IconViewItem::~Q3IconViewItem(){#ifndef QT_NO_TEXTEDIT removeRenameBox();#endif if (view && !view->d->clearing) view->takeItem(this); view = 0; if (itemIcon && itemIcon->serialNumber() != unknown_icon->serialNumber())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -