1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 18:26:34 +01:00

Show history & bookmark url in menu on mouse hover

BUG: 448238

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-12-12 22:31:00 +01:00
parent a779a018e1
commit f5249f67db
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
10 changed files with 117 additions and 6 deletions

View File

@ -25,6 +25,7 @@
#include "qzsettings.h"
#include "tabwidget.h"
#include "iconprovider.h"
#include "statusbar.h"
BookmarksMenu::BookmarksMenu(QWidget* parent)
: Menu(parent)
@ -93,6 +94,11 @@ void BookmarksMenu::menuAboutToShow()
}
}
void BookmarksMenu::menuAboutToHide()
{
mApp->getWindow()->statusBar()->clearMessage();
}
void BookmarksMenu::menuMiddleClicked(Menu* menu)
{
BookmarkItem* item = static_cast<BookmarkItem*>(menu->menuAction()->data().value<void*>());
@ -173,6 +179,7 @@ void BookmarksMenu::init()
connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
connect(this, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
connect(this, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(menuMiddleClicked(Menu*)));
connect(this, &QMenu::aboutToHide, this, &BookmarksMenu::menuAboutToHide);
}
void BookmarksMenu::refresh()

View File

@ -43,6 +43,7 @@ private Q_SLOTS:
void bookmarksChanged();
void aboutToShow();
void menuAboutToShow();
void menuAboutToHide();
void menuMiddleClicked(Menu* menu);
void bookmarkActivated();

View File

@ -25,6 +25,7 @@
#include "qzsettings.h"
#include "browserwindow.h"
#include "sqldatabase.h"
#include "statusbar.h"
#include <iostream>
#include <QDialogButtonBox>
@ -390,11 +391,15 @@ void BookmarksTools::addFolderToMenu(QObject* receiver, Menu* menu, BookmarkItem
m->setTitle(title);
m->setIcon(folder->icon());
QObject::connect(m, &QMenu::aboutToHide, mApp->getWindow()->statusBar(), &StatusBar::clearMessage);
addFolderContentsToMenu(receiver, m, folder);
QAction* act = menu->addMenu(m);
act->setData(QVariant::fromValue<void*>(static_cast<void*>(folder)));
act->setIconVisibleInMenu(true);
QObject::connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), &StatusBar::clearMessage);
}
void BookmarksTools::addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* bookmark)
@ -413,6 +418,10 @@ void BookmarksTools::addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* b
QObject::connect(act, SIGNAL(ctrlTriggered()), receiver, SLOT(bookmarkCtrlActivated()));
QObject::connect(act, SIGNAL(shiftTriggered()), receiver, SLOT(bookmarkShiftActivated()));
QObject::connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), [=]() {
mApp->getWindow()->statusBar()->showMessage(bookmark->url().toString());
});
menu->addAction(act);
}
@ -423,7 +432,8 @@ void BookmarksTools::addSeparatorToMenu(Menu* menu, BookmarkItem* separator)
Q_ASSERT(menu);
Q_ASSERT(separator->isSeparator());
menu->addSeparator();
auto* act = menu->addSeparator();
QObject::connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), &StatusBar::clearMessage);
}
void BookmarksTools::addFolderContentsToMenu(QObject *receiver, Menu *menu, BookmarkItem *folder)

View File

@ -27,6 +27,7 @@
#include "qzsettings.h"
#include "sqldatabase.h"
#include "closedwindowsmanager.h"
#include "statusbar.h"
#include <QApplication>
#include <QWebEngineHistory>
@ -104,12 +105,18 @@ void HistoryMenu::aboutToShow()
connect(act, &QAction::triggered, this, &HistoryMenu::historyEntryActivated);
connect(act, &Action::ctrlTriggered, this, &HistoryMenu::historyEntryCtrlActivated);
connect(act, &Action::shiftTriggered, this, &HistoryMenu::historyEntryShiftActivated);
connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), [=]() {
mApp->getWindow()->statusBar()->showMessage(url.toString());
});
addAction(act);
}
}
void HistoryMenu::aboutToHide()
{
clearStatusbar();
// Enable Back/Forward actions to ensure shortcuts are working
actions().at(0)->setEnabled(true);
actions().at(1)->setEnabled(true);
@ -128,6 +135,10 @@ void HistoryMenu::aboutToShowMostVisited()
connect(act, &QAction::triggered, this, &HistoryMenu::historyEntryActivated);
connect(act, &Action::ctrlTriggered, this, &HistoryMenu::historyEntryCtrlActivated);
connect(act, &Action::shiftTriggered, this, &HistoryMenu::historyEntryShiftActivated);
connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), [=]() {
mApp->getWindow()->statusBar()->showMessage(entry.url.toString());
});
m_menuMostVisited->addAction(act);
}
@ -231,6 +242,11 @@ void HistoryMenu::openUrlInNewWindow(const QUrl &url)
mApp->createWindow(Qz::BW_NewWindow, url);
}
void HistoryMenu::clearStatusbar()
{
mApp->getWindow()->statusBar()->clearMessage();
}
void HistoryMenu::init()
{
setTitle(tr("Hi&story"));
@ -254,6 +270,7 @@ void HistoryMenu::init()
m_menuMostVisited = new Menu(tr("Most Visited"), this);
connect(m_menuMostVisited, &QMenu::aboutToShow, this, &HistoryMenu::aboutToShowMostVisited);
connect(m_menuMostVisited, &QMenu::aboutToHide, this, &HistoryMenu::clearStatusbar);
m_menuClosedTabs = new Menu(tr("Closed Tabs"));
connect(m_menuClosedTabs, &QMenu::aboutToShow, this, &HistoryMenu::aboutToShowClosedTabs);
@ -261,7 +278,12 @@ void HistoryMenu::init()
m_menuClosedWindows = new Menu(tr("Closed Windows"));
connect(m_menuClosedWindows, &QMenu::aboutToShow, this, &HistoryMenu::aboutToShowClosedWindows);
addMenu(m_menuMostVisited);
addMenu(m_menuClosedTabs);
addMenu(m_menuClosedWindows);
act = addMenu(m_menuMostVisited);
connect(act, &QAction::hovered, this, &HistoryMenu::clearStatusbar);
act = addMenu(m_menuClosedTabs);
connect(act, &QAction::hovered, this, &HistoryMenu::clearStatusbar);
act = addMenu(m_menuClosedWindows);
connect(act, &QAction::hovered, this, &HistoryMenu::clearStatusbar);
}

View File

@ -55,6 +55,8 @@ private Q_SLOTS:
void openUrlInNewTab(const QUrl &url);
void openUrlInNewWindow(const QUrl &url);
void clearStatusbar();
private:
void init();

View File

@ -31,6 +31,7 @@
#include "abstractbuttoninterface.h"
#include "navigationbartoolbutton.h"
#include "navigationbarconfigdialog.h"
#include "statusbar.h"
#include <QTimer>
#include <QSplitter>
@ -382,6 +383,9 @@ void NavigationBar::aboutToShowHistoryBackMenu()
act->setData(i);
connect(act, &QAction::triggered, this, &NavigationBar::loadHistoryIndex);
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab()));
connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), [=]() {
mApp->getWindow()->statusBar()->showMessage(item.url().toString());
});
m_menuBack->addAction(act);
}
@ -392,7 +396,9 @@ void NavigationBar::aboutToShowHistoryBackMenu()
}
m_menuBack->addSeparator();
m_menuBack->addAction(QIcon::fromTheme(QSL("edit-clear")), tr("Clear history"), this, &NavigationBar::clearHistory);
auto *act = m_menuBack->addAction(QIcon::fromTheme(QSL("edit-clear")), tr("Clear history"), this, &NavigationBar::clearHistory);
connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), &StatusBar::clearMessage);
connect(m_menuBack, &QMenu::aboutToHide, mApp->getWindow()->statusBar(), &StatusBar::clearMessage);
}
void NavigationBar::aboutToShowHistoryNextMenu()
@ -416,6 +422,9 @@ void NavigationBar::aboutToShowHistoryNextMenu()
act->setData(i);
connect(act, &QAction::triggered, this, &NavigationBar::loadHistoryIndex);
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab()));
connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), [=]() {
mApp->getWindow()->statusBar()->showMessage(item.url().toString());
});
m_menuForward->addAction(act);
}
@ -426,7 +435,9 @@ void NavigationBar::aboutToShowHistoryNextMenu()
}
m_menuForward->addSeparator();
m_menuForward->addAction(QIcon::fromTheme(QSL("edit-clear")), tr("Clear history"), this, &NavigationBar::clearHistory);
auto *act = m_menuForward->addAction(QIcon::fromTheme(QSL("edit-clear")), tr("Clear history"), this, &NavigationBar::clearHistory);
connect(act, &QAction::hovered, mApp->getWindow()->statusBar(), &StatusBar::clearMessage);
connect(m_menuForward, &QMenu::aboutToHide, mApp->getWindow()->statusBar(), &StatusBar::clearMessage);
}
void NavigationBar::aboutToShowToolsMenu()

View File

@ -22,6 +22,9 @@
#include "bookmarks.h"
#include "mainapplication.h"
#include "iconprovider.h"
#include "statusbar.h"
#include "bookmarksmodel.h"
#include <QMenu>
@ -39,6 +42,9 @@ BookmarksSidebar::BookmarksSidebar(BrowserWindow* window, QWidget* parent)
connect(ui->tree, &BookmarksTreeView::bookmarkShiftActivated, this, &BookmarksSidebar::bookmarkShiftActivated);
connect(ui->tree, &BookmarksTreeView::contextMenuRequested, this, &BookmarksSidebar::createContextMenu);
connect(ui->tree, &BookmarksTreeView::bookmarksSelected, this, &BookmarksSidebar::onCurrentChanged);
connect(ui->tree, &QTreeView::entered, this, &BookmarksSidebar::onEntered);
connect(ui->search, &QLineEdit::textChanged, ui->tree, &BookmarksTreeView::search);
}
@ -140,3 +146,30 @@ void BookmarksSidebar::showEvent(QShowEvent *event)
QWidget::showEvent(event);
ui->search->setFocus();
}
void BookmarksSidebar::onCurrentChanged(const QList<BookmarkItem*> &items)
{
if (items.count() > 0) {
auto item = items.first();
if (item->isUrl()) {
mApp->getWindow()->statusBar()->showMessage(item->url().toString());
}
else {
mApp->getWindow()->statusBar()->clearMessage();
}
}
}
void BookmarksSidebar::onEntered(const QModelIndex& index)
{
if (index.isValid()) {
if (index.data(BookmarksModel::TypeRole).toInt() == BookmarkItem::Url) {
auto url = index.data(BookmarksModel::UrlStringRole).toString();
mApp->getWindow()->statusBar()->showMessage(url);
}
else {
mApp->getWindow()->statusBar()->clearMessage();
}
}
}

View File

@ -52,6 +52,9 @@ private Q_SLOTS:
void deleteBookmarks();
void createContextMenu(const QPoint &pos);
void onCurrentChanged(const QList<BookmarkItem*> &items);
void onEntered(const QModelIndex& index);
private:
void showEvent(QShowEvent *event) override;

View File

@ -23,6 +23,10 @@
#include "mainapplication.h"
#include "qzsettings.h"
#include "iconprovider.h"
#include "historymodel.h"
#include "statusbar.h"
#include <QItemSelectionModel>
HistorySideBar::HistorySideBar(BrowserWindow* window, QWidget* parent)
: QWidget(parent)
@ -37,6 +41,9 @@ HistorySideBar::HistorySideBar(BrowserWindow* window, QWidget* parent)
connect(ui->historyTree, &HistoryTreeView::urlShiftActivated, this, &HistorySideBar::urlShiftActivated);
connect(ui->historyTree, &HistoryTreeView::contextMenuRequested, this, &HistorySideBar::createContextMenu);
connect(ui->historyTree, &QTreeView::entered, this, &HistorySideBar::showSidebarHint);
connect(ui->historyTree->selectionModel(), &QItemSelectionModel::currentChanged, this, &HistorySideBar::onCurrentChanged);
connect(ui->search, &QLineEdit::textEdited, ui->historyTree, &HistoryTreeView::search);
}
@ -109,6 +116,18 @@ void HistorySideBar::showEvent(QShowEvent *event)
ui->search->setFocus();
}
void HistorySideBar::onCurrentChanged(const QModelIndex& current, const QModelIndex& previous)
{
Q_UNUSED(previous)
showSidebarHint(current);
}
void HistorySideBar::showSidebarHint(const QModelIndex& index)
{
const QUrl url = index.data(HistoryModel::UrlRole).toUrl();
mApp->getWindow()->statusBar()->showMessage(url.toString());
}
HistorySideBar::~HistorySideBar()
{
delete ui;

View File

@ -50,6 +50,9 @@ private Q_SLOTS:
void createContextMenu(const QPoint &pos);
void onCurrentChanged(const QModelIndex &current, const QModelIndex &previous);
void showSidebarHint(const QModelIndex& index);
private:
void showEvent(QShowEvent *event) override;