diff options
| author | Peter Penz <[email protected]> | 2011-11-29 22:01:16 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-11-29 22:03:26 +0100 |
| commit | 3719ce7d2a7f4ee6a0585763139eea8f7786630c (patch) | |
| tree | a93f357f440ac5866020ba69dc5815d927c3c3f7 /src/kitemviews | |
| parent | 4cd8ebff82cd215cc5a7c5b004207b0b0eda6734 (diff) | |
Reactivate the "Open folders during drag operations" feature
The feature got temporary lost due to the port to the new view
engine.
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.cpp | 68 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.h | 33 |
2 files changed, 97 insertions, 4 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 60bfef518..746df4d1d 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -32,6 +32,7 @@ #include <QEvent> #include <QGraphicsSceneEvent> #include <QMimeData> +#include <QTimer> #include <KGlobalSettings> #include <KDebug> @@ -46,10 +47,16 @@ KItemListController::KItemListController(QObject* parent) : m_keyboardManager(new KItemListKeyboardSearchManager(this)), m_pressedIndex(-1), m_pressedMousePos(), + m_autoActivationTimer(0), m_oldSelection() { connect(m_keyboardManager, SIGNAL(changeCurrentItem(QString,bool)), this, SLOT(slotChangeCurrentItem(QString,bool))); + + m_autoActivationTimer = new QTimer(this); + m_autoActivationTimer->setSingleShot(true); + m_autoActivationTimer->setInterval(-1); + connect(m_autoActivationTimer, SIGNAL(timeout()), this, SLOT(slotAutoActivationTimeout())); } KItemListController::~KItemListController() @@ -121,6 +128,16 @@ KItemListController::SelectionBehavior KItemListController::selectionBehavior() return m_selectionBehavior; } +void KItemListController::setAutoActivationDelay(int delay) +{ + m_autoActivationTimer->setInterval(delay); +} + +int KItemListController::autoActivationDelay() const +{ + return m_autoActivationTimer->interval(); +} + bool KItemListController::showEvent(QShowEvent* event) { Q_UNUSED(event); @@ -217,9 +234,17 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) break; case Qt::Key_Enter: - case Qt::Key_Return: - emit itemActivated(index); + case Qt::Key_Return: { + const QSet<int> selectedItems = m_selectionManager->selectedItems(); + if (selectedItems.count() >= 2) { + emit itemsActivated(selectedItems); + } else if (selectedItems.count() == 1) { + emit itemActivated(selectedItems.toList().first()); + } else { + emit itemActivated(index); + } break; + } case Qt::Key_Space: if (controlPressed) { @@ -276,6 +301,27 @@ void KItemListController::slotChangeCurrentItem(const QString& text, bool search } } +void KItemListController::slotAutoActivationTimeout() +{ + if (!m_model || !m_view) { + return; + } + + const int index = m_autoActivationTimer->property("index").toInt(); + if (index < 0 || index >= m_model->count()) { + return; + } + + if (m_model->supportsDropping(index)) { + if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) { + const bool expanded = m_model->isExpanded(index); + m_model->setExpanded(index, !expanded); + } else { + emit itemActivated(index); + } + } +} + bool KItemListController::inputMethodEvent(QInputMethodEvent* event) { Q_UNUSED(event); @@ -542,8 +588,13 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons } KItemListWidget* oldHoveredWidget = hoveredWidget(); - KItemListWidget* newHoveredWidget = widgetForPos(event->pos()); + + const QPointF pos = transform.map(event->pos()); + KItemListWidget* newHoveredWidget = widgetForPos(pos); + if (oldHoveredWidget != newHoveredWidget) { + m_autoActivationTimer->stop(); + if (oldHoveredWidget) { oldHoveredWidget->setHovered(false); emit itemUnhovered(oldHoveredWidget->index()); @@ -555,6 +606,11 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons newHoveredWidget->setHovered(true); } emit itemHovered(index); + + if (m_autoActivationTimer->interval() >= 0) { + m_autoActivationTimer->setProperty("index", index); + m_autoActivationTimer->start(); + } } } @@ -568,6 +624,8 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT return false; } + m_autoActivationTimer->stop(); + const QPointF pos = transform.map(event->pos()); const int index = m_view->itemAt(pos); emit itemDropEvent(index, event); @@ -590,7 +648,9 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const } KItemListWidget* oldHoveredWidget = hoveredWidget(); - KItemListWidget* newHoveredWidget = widgetForPos(event->pos()); + const QPointF pos = transform.map(event->pos()); + KItemListWidget* newHoveredWidget = widgetForPos(pos); + if (oldHoveredWidget != newHoveredWidget) { if (oldHoveredWidget) { oldHoveredWidget->setHovered(false); diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h index aa2fe2176..29ab6be63 100644 --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -86,6 +86,24 @@ 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; + virtual bool showEvent(QShowEvent* event); virtual bool hideEvent(QHideEvent* event); virtual bool keyPressEvent(QKeyEvent* event); @@ -106,7 +124,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); /** @@ -160,6 +189,8 @@ private slots: void slotChangeCurrentItem(const QString& text, bool searchFromNextItem); + void slotAutoActivationTimeout(); + private: /** * Creates a QDrag object and initiates a drag-operation. @@ -188,6 +219,8 @@ 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 |
