#include "kitemlistview.h"
-#include <KDebug>
+#include "dolphindebug.h"
#include "kitemlistcontainer.h"
#include "kitemlistcontroller.h"
#include "kitemlistheader.h"
#include "kitemlistselectionmanager.h"
-#include "kitemlistwidget.h"
+#include "kstandarditemlistwidget.h"
#include "private/kitemlistheaderwidget.h"
#include "private/kitemlistrubberband.h"
#include "private/kitemlistviewlayouter.h"
#include "private/kitemlistviewanimation.h"
-#include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QPainter>
-#include <QPropertyAnimation>
#include <QStyle>
#include <QStyleOptionRubberBand>
#include <QTimer>
+#include <QElapsedTimer>
#include <algorithm>
-#if 0
#include "kitemlistviewaccessible.h"
-#else
-#define QT_NO_ACCESSIBILITY 1
-#pragma message("TODO: port accessibility to Qt5")
-#endif
namespace {
// Time in ms until reaching the autoscroll margin triggers
}
#ifndef QT_NO_ACCESSIBILITY
-QAccessibleInterface* accessibleInterfaceFactory(const QString &key, QObject *object)
+QAccessibleInterface* accessibleInterfaceFactory(const QString& key, QObject* object)
{
Q_UNUSED(key)
void KItemListView::setWidgetCreator(KItemListWidgetCreatorBase* widgetCreator)
{
- if (m_widgetCreator) {
- delete m_widgetCreator;
- }
+ delete m_widgetCreator;
m_widgetCreator = widgetCreator;
}
void KItemListView::setGroupHeaderCreator(KItemListGroupHeaderCreatorBase* groupHeaderCreator)
{
- if (m_groupHeaderCreator) {
- delete m_groupHeaderCreator;
- }
+ delete m_groupHeaderCreator;
m_groupHeaderCreator = groupHeaderCreator;
}
return m_itemSize;
}
+QSizeF KItemListView::itemSizeHint() const
+{
+ return m_sizeHintResolver->maxSizeHint();
+}
+
const KItemListStyleOption& KItemListView::styleOption() const
{
return m_styleOption;
return false;
}
+bool KItemListView::isAboveText(int index, const QPointF &pos) const
+{
+ const KItemListWidget* widget = m_visibleItems.value(index);
+ if (widget) {
+ const QRectF &textRect = widget->textRect();
+ if (!textRect.isEmpty()) {
+ const QPointF mappedPos = widget->mapFromItem(this, pos);
+ return textRect.contains(mappedPos);
+ }
+ }
+ return false;
+}
+
int KItemListView::firstVisibleIndex() const
{
return m_layouter->firstVisibleIndex();
return m_layouter->lastVisibleIndex();
}
-void KItemListView::calculateItemSizeHints(QVector<QSizeF>& sizeHints) const
+void KItemListView::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint) const
{
- widgetCreator()->calculateItemSizeHints(sizeHints, this);
+ widgetCreator()->calculateItemSizeHints(logicalHeightHints, logicalWidthHint, this);
}
void KItemListView::setSupportsItemExpanding(bool supportsExpanding)
--m_activeTransactions;
if (m_activeTransactions < 0) {
m_activeTransactions = 0;
- kWarning() << "Mismatch between beginTransaction()/endTransaction()";
+ qCWarning(DolphinDebug) << "Mismatch between beginTransaction()/endTransaction()";
}
if (m_activeTransactions == 0) {
void KItemListView::editRole(int index, const QByteArray& role)
{
- KItemListWidget* widget = m_visibleItems.value(index);
+ KStandardItemListWidget* widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index));
if (!widget || m_editingRole) {
return;
}
this, &KItemListView::slotRoleEditingCanceled);
connect(widget, &KItemListWidget::roleEditingFinished,
this, &KItemListView::slotRoleEditingFinished);
+
+ connect(this, &KItemListView::scrollOffsetChanged,
+ widget, &KStandardItemListWidget::finishRoleEditing);
}
void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
setAutoScroll(true);
}
-void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
+void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent* event)
{
QGraphicsWidget::dragMoveEvent(event);
}
}
-void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent* event)
{
QGraphicsWidget::dragLeaveEvent(event);
setAutoScroll(false);
const int index = range.index + previouslyInsertedCount;
const int count = range.count;
if (index < 0 || count <= 0) {
- kWarning() << "Invalid item range (index:" << index << ", count:" << count << ")";
+ qCWarning(DolphinDebug) << "Invalid item range (index:" << index << ", count:" << count << ")";
continue;
}
previouslyInsertedCount += count;
const int index = range.index;
const int count = range.count;
if (index < 0 || count <= 0) {
- kWarning() << "Invalid item range (index:" << index << ", count:" << count << ")";
+ qCWarning(DolphinDebug) << "Invalid item range (index:" << index << ", count:" << count << ")";
continue;
}
const int firstRemovedIndex = index;
const int lastRemovedIndex = index + count - 1;
- // Remeber which items have to be moved because they are behind the removed range.
+ // Remember which items have to be moved because they are behind the removed range.
QVector<int> itemsToMove;
// Remove all KItemListWidget instances that got deleted
updateVisibleGroupHeaders();
doLayout(NoAnimation);
}
+
+ QAccessibleTableModelChangeEvent ev(this, QAccessibleTableModelChangeEvent::DataChanged);
+ ev.setFirstRow(itemRange.index);
+ ev.setLastRow(itemRange.index + itemRange.count);
+ QAccessible::updateAccessibility(&ev);
}
-#pragma message("TODO: port accessibility otherwise the following line asserts")
- //QAccessible::updateAccessibility(this, 0, QAccessible::TableModelChanged);
}
void KItemListView::slotGroupsChanged()
{
Q_UNUSED(previous);
- KItemListWidget* previousWidget = m_visibleItems.value(previous, 0);
- if (previousWidget) {
- previousWidget->setCurrent(false);
- }
+ // In SingleSelection mode (e.g., in the Places Panel), the current item is
+ // always the selected item. It is not necessary to highlight the current item then.
+ if (m_controller->selectionBehavior() != KItemListController::SingleSelection) {
+ KItemListWidget* previousWidget = m_visibleItems.value(previous, 0);
+ if (previousWidget) {
+ previousWidget->setCurrent(false);
+ }
- KItemListWidget* currentWidget = m_visibleItems.value(current, 0);
- if (currentWidget) {
- currentWidget->setCurrent(true);
+ KItemListWidget* currentWidget = m_visibleItems.value(current, 0);
+ if (currentWidget) {
+ currentWidget->setCurrent(true);
+ }
}
-#pragma message("TODO: port accessibility otherwise the following line asserts")
- //QAccessible::updateAccessibility(this, current+1, QAccessible::Focus);
+
+ QAccessibleEvent ev(this, QAccessible::Focus);
+ ev.setChild(current);
+ QAccessible::updateAccessibility(&ev);
}
void KItemListView::slotSelectionChanged(const KItemSet& current, const KItemSet& previous)
widget->setStyleOption(m_styleOption);
const KItemListSelectionManager* selectionManager = m_controller->selectionManager();
- widget->setCurrent(index == selectionManager->currentItem());
+
+ // In SingleSelection mode (e.g., in the Places Panel), the current item is
+ // always the selected item. It is not necessary to highlight the current item then.
+ if (m_controller->selectionBehavior() != KItemListController::SingleSelection) {
+ widget->setCurrent(index == selectionManager->currentItem());
+ }
widget->setSelected(selectionManager->isSelected(index));
widget->setHovered(false);
widget->setEnabledSelectionToggle(enabledSelectionToggles());
if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
if (m_model->supportsDropping(widget->index())) {
// Keep 30% of the rectangle as the gap instead of always having a fixed gap
- const int gap = qMax(4.0, 0.3 * rect.height());
+ const int gap = qMax(qreal(4.0), qreal(0.3) * rect.height());
if (mappedPos.y() >= gap && mappedPos.y() <= rect.height() - gap) {
return -1;
}
void KItemListView::disconnectRoleEditingSignals(int index)
{
- KItemListWidget* widget = m_visibleItems.value(index);
+ KStandardItemListWidget* widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index));
if (!widget) {
return;
}
disconnect(widget, &KItemListWidget::roleEditingCanceled, this, nullptr);
disconnect(widget, &KItemListWidget::roleEditingFinished, this, nullptr);
+ disconnect(this, &KItemListView::scrollOffsetChanged, widget, nullptr);
}
int KItemListView::calculateAutoScrollingIncrement(int pos, int range, int oldInc)
pushRecycleableWidget(header);
}
-#include "kitemlistview.moc"