Commit e523cedb authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Make the open url in tab feature a bit more discoverable

Introduce a context menu item that invites to open the button under the menu in a tab.
It used to just work with the middle button, now it works with control+click as well, much like in web browsers.

BUG: 402073

Reviewers: #dolphin, ngraham, #frameworks, elvisangelaccio

Reviewed By: #dolphin, ngraham, elvisangelaccio

Subscribers: elvisangelaccio, kde-frameworks-devel

Tags: #frameworks

Differential Revision:
parent 16c98669
......@@ -105,9 +105,9 @@ public:
* of the navigator if the left mouse button has been used. If the middle
* mouse button has been used, the signal tabRequested() will be emitted.
void slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button);
void slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers);
void openContextMenu();
void openContextMenu(const QPoint &p);
void slotPathBoxChanged(const QString &text);
......@@ -280,7 +280,7 @@ KUrlNavigator::Private::Private(KUrlNavigator *q, KFilePlacesModel *placesModel)
connect(q, SIGNAL(customContextMenuRequested(QPoint)),
q, SLOT(openContextMenu()));
q, SLOT(openContextMenu(QPoint)));
void KUrlNavigator::Private::initialize(const QUrl &url)
......@@ -448,16 +448,16 @@ void KUrlNavigator::Private::dropUrls(const QUrl &destination, QDropEvent *event
void KUrlNavigator::Private::slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button)
void KUrlNavigator::Private::slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
if (button & Qt::LeftButton) {
} else if (button & Qt::MidButton) {
if (button & Qt::MidButton || (button & Qt::LeftButton && modifiers & Qt::ControlModifier)) {
emit q->tabRequested(url);
} else if (button & Qt::LeftButton) {
void KUrlNavigator::Private::openContextMenu()
void KUrlNavigator::Private::openContextMenu(const QPoint &p)
......@@ -475,6 +475,18 @@ void KUrlNavigator::Private::openContextMenu()
//We are checking for receivers because it's odd to have a tab entry even if it's not supported, like in the case of the open dialog
if (q->receivers(SIGNAL(tabRequested(QUrl))) > 0) {
for (auto button : qAsConst(m_navButtons)) {
if (button->geometry().contains(p)) {
const auto url = button->url();
QAction* openInTab = popup->addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18n("Open %1 in tab", button->text()));
q->connect(openInTab, &QAction::triggered, q, [this, url](){ Q_EMIT q->tabRequested(url); });
// provide radiobuttons for toggling between the edit and the navigation mode
QAction *editAction = popup->addAction(i18n("Edit"));
......@@ -602,8 +614,8 @@ void KUrlNavigator::Private::updateButtons(int startIndex)
connect(button, SIGNAL(urlsDropped(QUrl,QDropEvent*)),
q, SLOT(dropUrls(QUrl,QDropEvent*)));
connect(button, SIGNAL(clicked(QUrl,Qt::MouseButton)),
q, SLOT(slotNavigatorButtonClicked(QUrl,Qt::MouseButton)));
connect(button, SIGNAL(clicked(QUrl,Qt::MouseButton,Qt::KeyboardModifiers)),
q, SLOT(slotNavigatorButtonClicked(QUrl,Qt::MouseButton,Qt::KeyboardModifiers)));
connect(button, SIGNAL(finishedTextResolving()),
q, SLOT(updateButtonVisibility()));
......@@ -481,8 +481,8 @@ private:
Q_PRIVATE_SLOT(d, void slotProtocolChanged(const QString &protocol))
Q_PRIVATE_SLOT(d, void slotToggleEditableButtonPressed())
Q_PRIVATE_SLOT(d, void dropUrls(const QUrl &destination, QDropEvent *))
Q_PRIVATE_SLOT(d, void slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button))
Q_PRIVATE_SLOT(d, void openContextMenu())
Q_PRIVATE_SLOT(d, void slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers))
Q_PRIVATE_SLOT(d, void openContextMenu(QPoint))
Q_PRIVATE_SLOT(d, void openPathSelectorMenu())
Q_PRIVATE_SLOT(d, void updateButtonVisibility())
Q_PRIVATE_SLOT(d, void switchToBreadcrumbMode())
......@@ -283,7 +283,7 @@ void KUrlNavigatorButton::keyPressEvent(QKeyEvent *event)
switch (event->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
emit clicked(m_url, Qt::LeftButton);
emit clicked(m_url, Qt::LeftButton, event->modifiers());
case Qt::Key_Down:
case Qt::Key_Space:
......@@ -366,7 +366,7 @@ void KUrlNavigatorButton::mouseReleaseEvent(QMouseEvent *event)
if (!isAboveArrow(event->x()) || (event->button() != Qt::LeftButton)) {
// the mouse has been released above the text area and not
// above the [>] button
emit clicked(m_url, event->button());
emit clicked(m_url, event->button(), event->modifiers());
......@@ -453,7 +453,7 @@ void KUrlNavigatorButton::slotMenuActionClicked(QAction *action, Qt::MouseButton
const int result = action->data().toInt();
QUrl url(m_url);
emit clicked(url, button);
emit clicked(url, button, Qt::NoModifier);
void KUrlNavigatorButton::statFinished(KJob *job)
......@@ -573,7 +573,7 @@ void KUrlNavigatorButton::replaceButton(KJob *job)
QUrl url(KIO::upUrl(m_url));
url.setPath(concatPaths(url.path(), m_subDirs[targetIndex].first));
emit clicked(url, Qt::LeftButton);
emit clicked(url, Qt::LeftButton, Qt::NoModifier);
......@@ -90,7 +90,7 @@ Q_SIGNALS:
void urlsDropped(const QUrl &destination, QDropEvent *event);
void clicked(const QUrl &url, Qt::MouseButton button);
void clicked(const QUrl &url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers);
* Is emitted, if KUrlNavigatorButton::setUrl() cannot resolve
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment