From f5249f67db11f9e4b398fc8c040753605a359744 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Thu, 12 Dec 2024 22:31:00 +0100 Subject: [PATCH] Show history & bookmark url in menu on mouse hover BUG: 448238 Signed-off-by: Juraj Oravec --- src/lib/bookmarks/bookmarksmenu.cpp | 7 ++++++ src/lib/bookmarks/bookmarksmenu.h | 1 + src/lib/bookmarks/bookmarkstools.cpp | 12 +++++++++- src/lib/history/historymenu.cpp | 28 ++++++++++++++++++++--- src/lib/history/historymenu.h | 2 ++ src/lib/navigation/navigationbar.cpp | 15 +++++++++++-- src/lib/sidebar/bookmarkssidebar.cpp | 33 ++++++++++++++++++++++++++++ src/lib/sidebar/bookmarkssidebar.h | 3 +++ src/lib/sidebar/historysidebar.cpp | 19 ++++++++++++++++ src/lib/sidebar/historysidebar.h | 3 +++ 10 files changed, 117 insertions(+), 6 deletions(-) diff --git a/src/lib/bookmarks/bookmarksmenu.cpp b/src/lib/bookmarks/bookmarksmenu.cpp index 370badbac..acaf98c29 100644 --- a/src/lib/bookmarks/bookmarksmenu.cpp +++ b/src/lib/bookmarks/bookmarksmenu.cpp @@ -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(menu->menuAction()->data().value()); @@ -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() diff --git a/src/lib/bookmarks/bookmarksmenu.h b/src/lib/bookmarks/bookmarksmenu.h index c38699ecc..458d41704 100644 --- a/src/lib/bookmarks/bookmarksmenu.h +++ b/src/lib/bookmarks/bookmarksmenu.h @@ -43,6 +43,7 @@ private Q_SLOTS: void bookmarksChanged(); void aboutToShow(); void menuAboutToShow(); + void menuAboutToHide(); void menuMiddleClicked(Menu* menu); void bookmarkActivated(); diff --git a/src/lib/bookmarks/bookmarkstools.cpp b/src/lib/bookmarks/bookmarkstools.cpp index e8ac1a3ed..2d1fa8818 100644 --- a/src/lib/bookmarks/bookmarkstools.cpp +++ b/src/lib/bookmarks/bookmarkstools.cpp @@ -25,6 +25,7 @@ #include "qzsettings.h" #include "browserwindow.h" #include "sqldatabase.h" +#include "statusbar.h" #include #include @@ -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(static_cast(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) diff --git a/src/lib/history/historymenu.cpp b/src/lib/history/historymenu.cpp index 2b683eaf1..b3752876c 100644 --- a/src/lib/history/historymenu.cpp +++ b/src/lib/history/historymenu.cpp @@ -27,6 +27,7 @@ #include "qzsettings.h" #include "sqldatabase.h" #include "closedwindowsmanager.h" +#include "statusbar.h" #include #include @@ -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); } diff --git a/src/lib/history/historymenu.h b/src/lib/history/historymenu.h index 23bef2916..ad78515d6 100644 --- a/src/lib/history/historymenu.h +++ b/src/lib/history/historymenu.h @@ -55,6 +55,8 @@ private Q_SLOTS: void openUrlInNewTab(const QUrl &url); void openUrlInNewWindow(const QUrl &url); + void clearStatusbar(); + private: void init(); diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index 9e0c6ecd3..f07d10821 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -31,6 +31,7 @@ #include "abstractbuttoninterface.h" #include "navigationbartoolbutton.h" #include "navigationbarconfigdialog.h" +#include "statusbar.h" #include #include @@ -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() diff --git a/src/lib/sidebar/bookmarkssidebar.cpp b/src/lib/sidebar/bookmarkssidebar.cpp index f399b48ff..504ce9be8 100644 --- a/src/lib/sidebar/bookmarkssidebar.cpp +++ b/src/lib/sidebar/bookmarkssidebar.cpp @@ -22,6 +22,9 @@ #include "bookmarks.h" #include "mainapplication.h" #include "iconprovider.h" +#include "statusbar.h" + +#include "bookmarksmodel.h" #include @@ -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 &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(); + } + } +} \ No newline at end of file diff --git a/src/lib/sidebar/bookmarkssidebar.h b/src/lib/sidebar/bookmarkssidebar.h index fc01c10d6..ecf5a7346 100644 --- a/src/lib/sidebar/bookmarkssidebar.h +++ b/src/lib/sidebar/bookmarkssidebar.h @@ -52,6 +52,9 @@ private Q_SLOTS: void deleteBookmarks(); void createContextMenu(const QPoint &pos); + void onCurrentChanged(const QList &items); + void onEntered(const QModelIndex& index); + private: void showEvent(QShowEvent *event) override; diff --git a/src/lib/sidebar/historysidebar.cpp b/src/lib/sidebar/historysidebar.cpp index c6e0a0b0b..47aa50726 100644 --- a/src/lib/sidebar/historysidebar.cpp +++ b/src/lib/sidebar/historysidebar.cpp @@ -23,6 +23,10 @@ #include "mainapplication.h" #include "qzsettings.h" #include "iconprovider.h" +#include "historymodel.h" +#include "statusbar.h" + +#include 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; diff --git a/src/lib/sidebar/historysidebar.h b/src/lib/sidebar/historysidebar.h index 74ab5cec5..c8aa499f5 100644 --- a/src/lib/sidebar/historysidebar.h +++ b/src/lib/sidebar/historysidebar.h @@ -50,6 +50,9 @@ private Q_SLOTS: void createContextMenu(const QPoint &pos); + void onCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous); + void showSidebarHint(const QModelIndex& index); + private: void showEvent(QShowEvent *event) override;