The dropping itself has not been implemented yet.
Q_UNUSED(transform);
m_view->setAutoScroll(false);
+ m_view->hideDropIndicator();
KItemListWidget* widget = hoveredWidget();
if (widget) {
const int index = newHoveredWidget->index();
if (m_model->supportsDropping(index)) {
newHoveredWidget->setHovered(true);
+ } else if (m_model->sortRole().isEmpty()) {
+ // The model supports the inserting of items on
+ // the given index as no sort-role has been
+ // specified. Assure that a drag-indicator
+ // is shown by the view.
+ const int dropIndex = m_view->showDropIndicator(pos);
+ Q_UNUSED(dropIndex); // TODO
}
emit itemHovered(index);
m_autoScrollIncrement(0),
m_autoScrollTimer(0),
m_header(0),
- m_headerWidget(0)
+ m_headerWidget(0),
+ m_dropIndicator()
{
setAcceptHoverEvents(true);
opt.rect = rubberBandRect.toRect();
style()->drawControl(QStyle::CE_RubberBand, &opt, painter);
}
+
+ if (!m_dropIndicator.isEmpty()) {
+ const QRectF r = m_dropIndicator.toRect();
+
+ QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
+ painter->setPen(color);
+
+ // TODO: The following implementation works only for a vertical scroll-orientation
+ // and assumes a height of the m_draggingInsertIndicator of 1.
+ Q_ASSERT(r.height() == 1);
+ painter->drawLine(r.left() + 1, r.top(), r.right() - 1, r.top());
+
+ color.setAlpha(128);
+ painter->setPen(color);
+ painter->drawRect(r.left(), r.top() - 1, r.width() - 1, 2);
+ }
}
void KItemListView::setItemSize(const QSizeF& size)
: maxOffset > size.width();
}
+int KItemListView::showDropIndicator(const QPointF& pos)
+{
+ QHashIterator<int, KItemListWidget*> it(m_visibleItems);
+ while (it.hasNext()) {
+ it.next();
+ const KItemListWidget* widget = it.value();
+
+ const QPointF mappedPos = widget->mapFromItem(this, pos);
+ const QRectF rect = itemRect(widget->index());
+ if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
+ const qreal y = (mappedPos.y () < rect.height() / 2) ?
+ rect.top() : rect.bottom();
+
+ const QRectF draggingInsertIndicator(rect.left(), y, rect.width(), 1);
+ if (m_dropIndicator != draggingInsertIndicator) {
+ m_dropIndicator = draggingInsertIndicator;
+ update();
+ }
+ return widget->index();
+ }
+ }
+
+ return -1;
+}
+
+void KItemListView::hideDropIndicator()
+{
+ if (!m_dropIndicator.isNull()) {
+ m_dropIndicator = QRectF();
+ update();
+ }
+}
+
void KItemListView::updateGroupHeaderHeight()
{
qreal groupHeaderHeight = m_styleOption.fontMetrics.height();
void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase* groupHeaderCreator);
KItemListGroupHeaderCreatorBase* groupHeaderCreator() const;
+ /**
+ * @return The basic size of all items. The size of an item may be larger than
+ * the basic size (see KItemListView::itemSizeHint() and KItemListView::itemRect()).
+ */
QSizeF itemSize() const;
const KItemListStyleOption& styleOption() const;
*/
bool scrollBarRequired(const QSizeF& size) const;
+ /**
+ * Shows a drop-indicator between items dependent on the given
+ * cursor position. The cursor position is relative the the upper left
+ * edge of the view.
+ * @return Index of the item where the dropping is done.
+ */
+ int showDropIndicator(const QPointF& pos);
+ void hideDropIndicator();
+
/**
* Applies the height of the group header to the layouter. The height
* depends on the used scroll orientation.
KItemListHeader* m_header;
KItemListHeaderWidget* m_headerWidget;
+ // When dragging items into the view where the sort-role of the model
+ // is empty, a visual indicator should be shown during dragging where
+ // the dropping will happen. This indicator is specified by an index
+ // of the item. -1 means that no indicator will be shown at all.
+ // The m_dropIndicator is set by the KItemListController
+ // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
+ QRectF m_dropIndicator;
+
friend class KItemListContainer; // Accesses scrollBarRequired()
friend class KItemListHeader; // Accesses m_headerWidget
friend class KItemListController;
{
QList<QPair<int, QVariant> > groups;
- const QByteArray role = sortRole();
+ const QByteArray role = sortRole().isEmpty() ? "group" : sortRole();
bool isFirstGroupValue = true;
QString groupValue;
const int maxIndex = count() - 1;
return mimeData;
}
-bool PlacesItemModel::supportsDropping(int index) const
-{
- Q_UNUSED(index);
- return true;
-}
-
KUrl PlacesItemModel::convertedUrl(const KUrl& url)
{
KUrl newUrl = url;
/** @reimp */
virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
- /** @reimp */
- virtual bool supportsDropping(int index) const;
-
/**
* @return Converts the URL, which contains "virtual" URLs for system-items like
* "search:/documents" into a Nepomuk-Query-URL that will be handled by
// used at all and stays invisible.
m_model = new PlacesItemModel(this);
m_model->setGroupedSorting(true);
- m_model->setSortRole("group");
connect(m_model, SIGNAL(errorMessage(QString)),
this, SIGNAL(errorMessage(QString)));