mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-19 16:31:21 +00:00
Places Panel: Show drop indicator
The dropping itself has not been implemented yet.
This commit is contained in:
parent
3b6892b685
commit
894232ebda
|
@ -758,6 +758,7 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con
|
|||
Q_UNUSED(transform);
|
||||
|
||||
m_view->setAutoScroll(false);
|
||||
m_view->hideDropIndicator();
|
||||
|
||||
KItemListWidget* widget = hoveredWidget();
|
||||
if (widget) {
|
||||
|
@ -793,6 +794,13 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
|
|||
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);
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ KItemListView::KItemListView(QGraphicsWidget* parent) :
|
|||
m_autoScrollIncrement(0),
|
||||
m_autoScrollTimer(0),
|
||||
m_header(0),
|
||||
m_headerWidget(0)
|
||||
m_headerWidget(0),
|
||||
m_dropIndicator()
|
||||
{
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
|
@ -622,6 +623,22 @@ void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt
|
|||
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)
|
||||
|
@ -2286,6 +2303,39 @@ bool KItemListView::scrollBarRequired(const QSizeF& size) const
|
|||
: 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();
|
||||
|
|
|
@ -151,6 +151,10 @@ public:
|
|||
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;
|
||||
|
@ -626,6 +630,15 @@ private:
|
|||
*/
|
||||
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.
|
||||
|
@ -716,6 +729,14 @@ private:
|
|||
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;
|
||||
|
|
|
@ -195,7 +195,7 @@ QList<QPair<int, QVariant> > KStandardItemModel::groups() const
|
|||
{
|
||||
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;
|
||||
|
|
|
@ -339,12 +339,6 @@ QMimeData* PlacesItemModel::createMimeData(const QSet<int>& indexes) const
|
|||
return mimeData;
|
||||
}
|
||||
|
||||
bool PlacesItemModel::supportsDropping(int index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
KUrl PlacesItemModel::convertedUrl(const KUrl& url)
|
||||
{
|
||||
KUrl newUrl = url;
|
||||
|
|
|
@ -108,9 +108,6 @@ public:
|
|||
/** @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
|
||||
|
|
|
@ -76,7 +76,6 @@ void PlacesPanel::showEvent(QShowEvent* event)
|
|||
// 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)));
|
||||
|
||||
|
|
Loading…
Reference in a new issue