If a spacebar is used as a keyboard shortcut to activate the Selection Mode, then allow this shortcut to be triggered only if the view has a keyboard focus.
BUG: 465489
});
}
+bool DolphinMainWindow::event(QEvent *event)
+{
+ if (event->type() == QEvent::ShortcutOverride) {
+ const QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Space && m_activeViewContainer->view()->handleSpaceAsNormalKey()) {
+ event->accept();
+ return true;
+ }
+ }
+
+ return KXmlGuiWindow::event(event);
+}
+
void DolphinMainWindow::showEvent(QShowEvent *event)
{
KXmlGuiWindow::showEvent(event);
"</para>"));
toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
toggleSelectionModeAction->setCheckable(true);
+ actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space );
connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
// A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
void settingsChanged();
protected:
+ /** @see QObject::event() */
+ bool event(QEvent *event) override;
+
/** @see QWidget::showEvent() */
void showEvent(QShowEvent *event) override;
return m_selectionMode;
}
+bool KItemListController::isSearchAsYouTypeActive() const
+{
+ return m_keyboardManager->isSearchAsYouTypeActive();
+}
+
bool KItemListController::keyPressEvent(QKeyEvent *event)
{
int index = m_selectionManager->currentItem();
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.
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:
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()) {
m_keyboardInputTime.start();
}
-bool KItemListKeyboardSearchManager::addKeyBeginsNewSearch() const
-{
- return m_keyboardInputTime.hasExpired(m_timeout) || m_searchedString.isEmpty();
-}
-
void KItemListKeyboardSearchManager::setTimeout(qint64 milliseconds)
{
m_timeout = milliseconds;
* 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.
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);
private:
bool shouldClearSearchIfInputTimeReached();
-private:
QString m_searchedString;
bool m_isSearchRestarted;
/** Measures the time since the last key press. */
}
}
+bool DolphinView::handleSpaceAsNormalKey() const
+{
+ return !m_container->hasFocus() || m_container->controller()->isSearchAsYouTypeActive();
+}
+
void DolphinView::slotTwoClicksRenamingTimerTimeout()
{
const KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager();
*/
void hideToolTip(const ToolTipManager::HideBehavior behavior = ToolTipManager::HideBehavior::Later);
+ /**
+ * Check if the space key should be handled as a normal key, even if it's
+ * used as a keyboard shortcut.
+ *
+ * See BUG 465489
+ */
+ bool handleSpaceAsNormalKey() const;
+
+ /** Activates the view if the item list container gets focus. */
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
public Q_SLOTS:
/**
* Changes the directory to \a url. If the current directory is equal to
*/
void updateViewState();
- /** Activates the view if the item list container gets focus. */
- bool eventFilter(QObject *watched, QEvent *event) override;
-
Q_SIGNALS:
/**
* Is emitted if the view has been activated by e. g. a mouse click.