]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistview.cpp
Fix some EBN issues
[dolphin.git] / src / kitemviews / kitemlistview.cpp
index abde53904f86f55f0e4dcd4c3dce17997bce8fb1..df65399299ba30d48af59678d6b75f8bbb124478 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "kitemlistview.h"
 
-#include <KDebug>
+#include "dolphindebug.h"
 #include "kitemlistcontainer.h"
 #include "kitemlistcontroller.h"
 #include "kitemlistheader.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
@@ -63,7 +57,7 @@ namespace {
 }
 
 #ifndef QT_NO_ACCESSIBILITY
-QAccessibleInterface* accessibleInterfaceFactory(const QString &key, QObject *object)
+QAccessibleInterface* accessibleInterfaceFactory(const QString& key, QObject* object)
 {
     Q_UNUSED(key)
 
@@ -464,9 +458,9 @@ int KItemListView::lastVisibleIndex() const
     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)
@@ -549,7 +543,7 @@ void KItemListView::endTransaction()
     --m_activeTransactions;
     if (m_activeTransactions < 0) {
         m_activeTransactions = 0;
-        kWarning() << "Mismatch between beginTransaction()/endTransaction()";
+        qCWarning(DolphinDebug) << "Mismatch between beginTransaction()/endTransaction()";
     }
 
     if (m_activeTransactions == 0) {
@@ -765,7 +759,8 @@ void KItemListView::setStyleOption(const KItemListStyleOption& option)
         updateGroupHeaderHeight();
     }
 
-    if (animate && previousOption.maxTextSize != option.maxTextSize) {
+    if (animate &&
+        (previousOption.maxTextLines != option.maxTextLines || previousOption.maxTextWidth != option.maxTextWidth)) {
         // Animating a change of the maximum text size just results in expensive
         // temporary eliding and clipping operations and does not look good visually.
         animate = false;
@@ -898,11 +893,23 @@ void KItemListView::onTransactionEnd()
 
 bool KItemListView::event(QEvent* event)
 {
-    // Forward all events to the controller and handle them there
-    if (!m_editingRole && m_controller && m_controller->processEvent(event, transform())) {
-        event->accept();
-        return true;
+    switch (event->type()) {
+    case QEvent::PaletteChange:
+        updatePalette();
+        break;
+
+    case QEvent::FontChange:
+        updateFont();
+        break;
+
+    default:
+        // Forward all other events to the controller and handle them there
+        if (!m_editingRole && m_controller && m_controller->processEvent(event, transform())) {
+            event->accept();
+            return true;
+        }
     }
+
     return QGraphicsWidget::event(event);
 }
 
@@ -928,7 +935,7 @@ void KItemListView::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
     setAutoScroll(true);
 }
 
-void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
+void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEventevent)
 {
     QGraphicsWidget::dragMoveEvent(event);
 
@@ -938,7 +945,7 @@ void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
     }
 }
 
-void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEventevent)
 {
     QGraphicsWidget::dragLeaveEvent(event);
     setAutoScroll(false);
@@ -955,6 +962,27 @@ QList<KItemListWidget*> KItemListView::visibleItemListWidgets() const
     return m_visibleItems.values();
 }
 
+void KItemListView::updateFont()
+{
+    if (scene() && !scene()->views().isEmpty()) {
+        KItemListStyleOption option = styleOption();
+        option.font = scene()->views().first()->font();
+        option.fontMetrics = QFontMetrics(option.font);
+
+        setStyleOption(option);
+    }
+}
+
+void KItemListView::updatePalette()
+{
+    if (scene() && !scene()->views().isEmpty()) {
+        KItemListStyleOption option = styleOption();
+        option.palette = scene()->views().first()->palette();
+
+        setStyleOption(option);
+    }
+}
+
 void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
 {
     if (m_itemSize.isEmpty()) {
@@ -978,7 +1006,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
         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;
@@ -1019,11 +1047,17 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
                                               (!verticalScrollOrientation && maximumScrollOffset() > size().width());
             if (decreaseLayouterSize) {
                 const int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent);
+
+                int scrollbarSpacing = 0;
+                if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) {
+                    scrollbarSpacing = style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing);
+                }
+
                 QSizeF layouterSize = m_layouter->size();
                 if (verticalScrollOrientation) {
-                    layouterSize.rwidth() -= scrollBarExtent;
+                    layouterSize.rwidth() -= scrollBarExtent + scrollbarSpacing;
                 } else {
-                    layouterSize.rheight() -= scrollBarExtent;
+                    layouterSize.rheight() -= scrollBarExtent + scrollbarSpacing;
                 }
                 m_layouter->setSize(layouterSize);
             }
@@ -1080,14 +1114,14 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
         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
@@ -1233,9 +1267,12 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
             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()
@@ -1298,17 +1335,23 @@ void KItemListView::slotCurrentChanged(int current, int previous)
 {
     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)
@@ -1945,7 +1988,12 @@ void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index)
     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());
@@ -2389,7 +2437,7 @@ int KItemListView::showDropIndicator(const QPointF& pos)
         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;
                 }
@@ -2677,4 +2725,3 @@ void KItemListGroupHeaderCreatorBase::recycle(KItemListGroupHeader* header)
     pushRecycleableWidget(header);
 }
 
-#include "kitemlistview.moc"