]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.h
If an item is clicked to trigger it, clear the rest of the selection
[dolphin.git] / src / kitemviews / kitemlistcontroller.h
index aa2fe2176cacb5fd363e263a8d69d3d9accb316b..d0e5f72ec7882b11905462467159cd32320c1f99 100644 (file)
@@ -86,6 +86,33 @@ public:
     void setSelectionBehavior(SelectionBehavior behavior);
     SelectionBehavior selectionBehavior() const;
 
+    /**
+     * Sets the delay in milliseconds when dragging an object above an item
+     * until the item gets activated automatically. A value of -1 indicates
+     * that no automatic activation will be done at all (= default value).
+     *
+     * The hovered item must support dropping (see KItemModelBase::supportsDropping()),
+     * otherwise the automatic activation is not available.
+     *
+     * After activating the item the signal itemActivated() will be
+     * emitted. If the view supports the expanding of items
+     * (KItemListView::supportsItemExpanding() returns true) and the item
+     * itself is expandable (see KItemModelBase::isExpandable()) then instead
+     * of activating the item it gets expanded instead (see
+     * KItemModelBase::setExpanded()).
+     */
+    void setAutoActivationDelay(int delay);
+    int autoActivationDelay() const;
+
+    /**
+     * If set to true, the signals itemActivated() and itemsActivated() are emitted
+     * after a single-click of the left mouse button. If set to false, a double-click
+     * is required. Per default the setting from KGlobalSettings::singleClick() is
+     * used.
+     */
+    void setSingleClickActivation(bool singleClick);
+    bool singleClickActivation() const;
+
     virtual bool showEvent(QShowEvent* event);
     virtual bool hideEvent(QHideEvent* event);
     virtual bool keyPressEvent(QKeyEvent* event);
@@ -106,7 +133,18 @@ public:
     virtual bool processEvent(QEvent* event, const QTransform& transform);
 
 signals:
+    /**
+     * Is emitted if exactly one item has been activated by e.g. a mouse-click
+     * or by pressing Return/Enter.
+     */
     void itemActivated(int index);
+
+    /**
+     * Is emitted if more than one item has been activated by pressing Return/Enter
+     * when having a selection.
+     */
+    void itemsActivated(const QSet<int>& indexes);
+
     void itemMiddleClicked(int index);
 
     /**
@@ -137,6 +175,17 @@ signals:
      */
     void itemUnhovered(int index);
 
+    /**
+     * Is emitted if a mouse-button has been pressed above an item.
+     */
+    void itemPressed(int index, Qt::MouseButton button);
+
+    /**
+     * Is emitted if a mouse-button has been released above an item.
+     * It is assured that the signal itemPressed() has been emitted before.
+     */
+    void itemReleased(int index, Qt::MouseButton button);
+
     void itemExpansionToggleClicked(int index);
 
     /**
@@ -160,6 +209,8 @@ private slots:
 
     void slotChangeCurrentItem(const QString& text, bool searchFromNextItem);
 
+    void slotAutoActivationTimeout();
+
 private:
     /**
      * Creates a QDrag object and initiates a drag-operation.
@@ -178,8 +229,38 @@ private:
      */
     KItemListWidget* widgetForPos(const QPointF& pos) const;
 
+    /**
+     * Updates m_keyboardAnchorIndex and m_keyboardAnchorPos. If no anchor is
+     * set, it will be adjusted to the current item. If it is set it will be
+     * checked whether it is still valid, otherwise it will be reset to the
+     * current item.
+     */
+    void updateKeyboardAnchor();
+
+    /**
+     * @return Index for the next row based on the current index.
+     *         If there is no next row the current index will be returned.
+     */
+    int nextRowIndex() const;
+
+    /**
+     * @return Index for the previous row based on the current index.
+     *         If there is no previous row the current index will be returned.
+     */
+    int previousRowIndex() const;
+
+    /**
+     * Helper method for updateKeyboardAnchor(), previousRowIndex() and nextRowIndex().
+     * @return The position of the keyboard anchor for the item with the index \a index.
+     *         If a horizontal scrolling is used the y-position of the item will be returned,
+     *         for the vertical scrolling the x-position will be returned.
+     */
+    qreal keyboardAnchorPos(int index) const;
+
 private:
+    bool m_singleClickActivation;
     bool m_selectionTogglePressed;
+    bool m_clearSelectionIfItemsAreNotDragged;
     SelectionBehavior m_selectionBehavior;
     KItemModelBase* m_model;
     KItemListView* m_view;
@@ -188,13 +269,32 @@ private:
     int m_pressedIndex;
     QPointF m_pressedMousePos;
 
+    QTimer* m_autoActivationTimer;
+
     /**
      * When starting a rubberband selection during a Shift- or Control-key has been
      * pressed the current selection should never be deleted. To be able to restore
-     * the current selection it is remembered in m_oldSelection before
+     * the current selection it is remembered in m_oldSelection before the
      * rubberband gets activated.
      */
     QSet<int> m_oldSelection;
+
+    /**
+     * Assuming a view is given with a vertical scroll-orientation, grouped items and
+     * a maximum of 4 columns:
+     *
+     *  1  2  3  4
+     *  5  6  7
+     *  8  9 10 11
+     * 12 13 14
+     *
+     * If the current index is on 4 and key-down is pressed, then item 7 gets the current
+     * item. Now when pressing key-down again item 11 should get the current item and not
+     * item 10. This makes it necessary to keep track of the requested column to have a
+     * similar behavior like in a text editor:
+     */
+    int m_keyboardAnchorIndex;
+    qreal m_keyboardAnchorPos;
 };
 
 #endif