diff options
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 9 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodelrolesupdater.cpp | 9 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.cpp | 50 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.h | 5 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistwidget.cpp | 1 | ||||
| -rw-r--r-- | src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp | 10 | ||||
| -rw-r--r-- | src/kitemviews/private/kitemlistkeyboardsearchmanager.h | 11 |
7 files changed, 61 insertions, 34 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index c7b3af76b..ebcd4b912 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -324,8 +324,13 @@ int KFileItemModel::indexForKeyboardSearch(const QString &text, int startFromInd bool KFileItemModel::supportsDropping(int index) const { - const KFileItem item = fileItem(index); - return !item.isNull() && (item.isDir() || item.isDesktopFile()); + KFileItem item; + if (index == -1) { + item = rootItem(); + } else { + item = fileItem(index); + } + return !item.isNull() && ((item.isDir() && item.isWritable()) || item.isDesktopFile()); } QString KFileItemModel::roleDescription(const QByteArray &role) const diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 4ff730652..8d5656daf 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -1214,8 +1214,9 @@ void KFileItemModelRolesUpdater::applySortRole(int index) } data.insert("type", item.mimeComment()); - } else if (m_model->sortRole() == "size" && item.isLocalFile() && !item.isSlow() && item.isDir()) { + } else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) { startDirectorySizeCounting(item, index); + return; } else { // Probably the sort role is a baloo role - just determine all roles. data = rolesData(item, index); @@ -1277,6 +1278,10 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint) void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &item, int index) { + if (item.isSlow()) { + return; + } + // Tell m_directoryContentsCounter that we want to count the items // inside the directory. The result will be received in slotDirectoryContentsCountReceived. if (m_scanDirectories && item.isLocalFile()) { @@ -1294,7 +1299,7 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte const bool getSizeRole = m_roles.contains("size"); const bool getIsExpandableRole = m_roles.contains("isExpandable"); - if ((getSizeRole || getIsExpandableRole) && !item.isSlow() && item.isDir()) { + if ((getSizeRole || getIsExpandableRole) && item.isDir()) { startDirectorySizeCounting(item, index); } diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 54a856fb8..2e7d2f057 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -228,6 +228,11 @@ bool KItemListController::selectionMode() const return m_selectionMode; } +bool KItemListController::isSearchAsYouTypeActive() const +{ + return m_keyboardManager->isSearchAsYouTypeActive(); +} + bool KItemListController::keyPressEvent(QKeyEvent *event) { int index = m_selectionManager->currentItem(); @@ -439,10 +444,13 @@ bool KItemListController::keyPressEvent(QKeyEvent *event) m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle); m_selectionManager->beginAnchoredSelection(index); break; - } else if (m_keyboardManager->addKeyBeginsNewSearch()) { // File names shouldn't start with a space, - // so we can use this press as a keyboard shortcut instead. - Q_EMIT selectionModeChangeRequested(!m_selectionMode); - break; + } else { + // Select the current item if it is not selected yet. + const int current = m_selectionManager->currentItem(); + if (!m_selectionManager->isSelected(current)) { + m_selectionManager->setSelected(current); + break; + } } } Q_FALLTHROUGH(); // fall through to the default case and add the Space to the current search string. @@ -534,7 +542,7 @@ void KItemListController::slotAutoActivationTimeout() * * See Bug 293200 and 305783 */ - if (m_model->supportsDropping(index) && m_view->isUnderMouse()) { + if (m_view->isUnderMouse()) { if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) { const bool expanded = m_model->isExpanded(index); m_model->setExpanded(index, !expanded); @@ -738,6 +746,7 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons const QPointF pos = transform.map(event->pos()); KItemListWidget *newHoveredWidget = widgetForDropPos(pos); + int index = -1; if (oldHoveredWidget != newHoveredWidget) { m_autoActivationTimer->stop(); @@ -755,25 +764,23 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0); } - const int index = newHoveredWidget->index(); + index = newHoveredWidget->index(); if (m_model->isDir(index)) { hoveredDir = m_model->url(index); } if (!droppingBetweenItems) { - if (m_model->supportsDropping(index)) { - // Something has been dragged on an item. - m_view->hideDropIndicator(); - if (!newHoveredWidget->isHovered()) { - newHoveredWidget->setHovered(true); - Q_EMIT itemHovered(index); - } + // Something has been dragged on an item. + m_view->hideDropIndicator(); + if (!newHoveredWidget->isHovered()) { + newHoveredWidget->setHovered(true); + Q_EMIT itemHovered(index); + } - if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) { - m_autoActivationTimer->setProperty("index", index); - m_autoActivationTimer->start(); - } + if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) { + m_autoActivationTimer->setProperty("index", index); + m_autoActivationTimer->start(); } } else { m_autoActivationTimer->stop(); @@ -790,8 +797,13 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons event->setDropAction(Qt::IgnoreAction); event->ignore(); } else { - event->setDropAction(event->proposedAction()); - event->accept(); + if (m_model->supportsDropping(index)) { + event->setDropAction(event->proposedAction()); + event->accept(); + } else { + event->setDropAction(Qt::IgnoreAction); + event->ignore(); + } } return false; } diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h index d75a8a22d..0969ed21a 100644 --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -123,6 +123,11 @@ public: void setSelectionModeEnabled(bool enabled); bool selectionMode() const; + /** + * @return \c true if search as you type is active, or \c false otherwise. + */ + bool isSearchAsYouTypeActive() const; + bool processEvent(QEvent *event, const QTransform &transform); Q_SIGNALS: diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index 25a347517..1d6b9641a 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -49,6 +49,7 @@ KItemListWidget::KItemListWidget(KItemListWidgetInformant *informant, QGraphicsI , m_selectionToggle(nullptr) , m_editedRole() , m_iconSize(-1) + , m_sidePadding(0) { connect(&m_hoverSequenceTimer, &QTimer::timeout, this, &KItemListWidget::slotHoverSequenceTimerTimeout); } diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp index b7318b344..c74ef1638 100644 --- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp +++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp @@ -27,6 +27,11 @@ bool KItemListKeyboardSearchManager::shouldClearSearchIfInputTimeReached() return (keyboardInputTimeElapsed > m_timeout) || !keyboardTimeWasValid; } +bool KItemListKeyboardSearchManager::isSearchAsYouTypeActive() const +{ + return !m_searchedString.isEmpty() && !m_keyboardInputTime.hasExpired(m_timeout); +} + void KItemListKeyboardSearchManager::addKeys(const QString &keys) { if (shouldClearSearchIfInputTimeReached()) { @@ -63,11 +68,6 @@ void KItemListKeyboardSearchManager::addKeys(const QString &keys) m_keyboardInputTime.start(); } -bool KItemListKeyboardSearchManager::addKeyBeginsNewSearch() const -{ - return m_keyboardInputTime.hasExpired(m_timeout) || m_searchedString.isEmpty(); -} - void KItemListKeyboardSearchManager::setTimeout(qint64 milliseconds) { m_timeout = milliseconds; diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h index d370bc9ba..981d98cd3 100644 --- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h +++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h @@ -34,11 +34,6 @@ public: * Add \a keys to the text buffer used for searching. */ void addKeys(const QString &keys); - /** - * @returns true if the next call to addKeys() will trigger a new search. - * Returns false if the next added key char will be added to the search string that was used previously. - */ - bool addKeyBeginsNewSearch() const; /** * Sets the delay after which the search is cancelled to \a milliseconds. @@ -51,6 +46,11 @@ public: void cancelSearch(); + /** + * @return \c true if search as you type is active, or \c false otherwise. + */ + bool isSearchAsYouTypeActive() const; + public Q_SLOTS: void slotCurrentChanged(int current, int previous); @@ -71,7 +71,6 @@ Q_SIGNALS: private: bool shouldClearSearchIfInputTimeReached(); -private: QString m_searchedString; bool m_isSearchRestarted; /** Measures the time since the last key press. */ |
