]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistview.cpp
Adding license header in kitemlistviewaccessible
[dolphin.git] / src / kitemviews / kitemlistview.cpp
index 1586c9d96bd705cc304e5541b5b6df89a3987f87..f2ae37556d9413fd126ff49d6e969b7fb209bcdd 100644 (file)
@@ -23,6 +23,7 @@
 #include "kitemlistview.h"
 
 #include <KDebug>
+#include "kitemlistcontainer.h"
 #include "kitemlistcontroller.h"
 #include "kitemlistheader.h"
 #include "kitemlistselectionmanager.h"
@@ -43,6 +44,8 @@
 #include <QStyleOptionRubberBand>
 #include <QTimer>
 
+#include "kitemlistviewaccessible.h"
+
 namespace {
     // Time in ms until reaching the autoscroll margin triggers
     // an initial autoscrolling
@@ -52,6 +55,21 @@ namespace {
     const int RepeatingAutoScrollDelay = 1000 / 60;
 }
 
+#ifndef QT_NO_ACCESSIBILITY
+QAccessibleInterface* accessibleInterfaceFactory(const QString &key, QObject *object)
+{
+    Q_UNUSED(key)
+
+    if (KItemListContainer* container = qobject_cast<KItemListContainer*>(object)) {
+        return new KItemListContainerAccessible(container);
+    } else if (KItemListView* view = qobject_cast<KItemListView*>(object)) {
+        return new KItemListViewAccessible(view);
+    }
+
+    return 0;
+}
+#endif
+
 KItemListView::KItemListView(QGraphicsWidget* parent) :
     QGraphicsWidget(parent),
     m_enabledSelectionToggles(false),
@@ -110,6 +128,11 @@ KItemListView::KItemListView(QGraphicsWidget* parent) :
     m_headerWidget->setVisible(false);
 
     m_header = new KItemListHeader(this);
+
+#ifndef QT_NO_ACCESSIBILITY
+    QAccessible::installFactory(accessibleInterfaceFactory);
+#endif
+
 }
 
 KItemListView::~KItemListView()
@@ -1189,6 +1212,7 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
             doLayout(NoAnimation);
         }
     }
+    QAccessible::updateAccessibility(this, 0, QAccessible::TableModelChanged);
 }
 
 void KItemListView::slotGroupedSortingChanged(bool current)
@@ -1251,6 +1275,7 @@ void KItemListView::slotCurrentChanged(int current, int previous)
     if (currentWidget) {
         currentWidget->setCurrent(true);
     }
+    QAccessible::updateAccessibility(this, current+1, QAccessible::Focus);
 }
 
 void KItemListView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
@@ -1616,6 +1641,11 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
         }
 
         if (animate) {
+            if (m_animation->isStarted(widget, KItemListViewAnimation::MovingAnimation)) {
+                m_animation->start(widget,  KItemListViewAnimation::MovingAnimation, newPos);
+                applyNewPos = false;
+            }
+
             const bool itemsRemoved = (changedCount < 0);
             const bool itemsInserted = (changedCount > 0);
             if (itemsRemoved && (i >= changedIndex + changedCount + 1)) {
@@ -1748,7 +1778,7 @@ bool KItemListView::moveWidget(KItemListWidget* widget,const QPointF& newPos)
 
     if (m_itemSize.isEmpty()) {
         // The items are not aligned in a grid but either as columns or rows.
-        startMovingAnim = !supportsItemExpanding();
+        startMovingAnim = true;
     } else {
         // When having a grid the moving-animation should only be started, if it is done within
         // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
@@ -2313,19 +2343,32 @@ int KItemListView::showDropIndicator(const QPointF& pos)
         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();
+            if (m_model->supportsDropping(widget->index())) {
+                const int gap = qMax(4, m_styleOption.padding);
+                if (mappedPos.y() >= gap && mappedPos.y() <= rect.height() - gap) {
+                    return -1;
+                }
+            }
+
+            const bool isAboveItem = (mappedPos.y () < rect.height() / 2);
+            const qreal y = isAboveItem ? rect.top() : rect.bottom();
 
             const QRectF draggingInsertIndicator(rect.left(), y, rect.width(), 1);
             if (m_dropIndicator != draggingInsertIndicator) {
                 m_dropIndicator = draggingInsertIndicator;
                 update();
             }
-            return widget->index();
+
+            int index = widget->index();
+            if (!isAboveItem) {
+                ++index;
+            }
+            return index;
         }
     }
 
-    return -1;
+    const QRectF firstItemRect = itemRect(firstVisibleIndex());
+    return (pos.y() <= firstItemRect.top()) ? 0 : -1;
 }
 
 void KItemListView::hideDropIndicator()