mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
[Bookmarks] Bookmarks menu is now working
This commit is contained in:
parent
a805f19f13
commit
bb6ead3ad4
|
@ -67,6 +67,7 @@
|
|||
#include "menubar.h"
|
||||
#include "qtwin.h"
|
||||
#include "bookmarkstools.h"
|
||||
#include "bookmarksmenu.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QSplitter>
|
||||
|
@ -567,14 +568,8 @@ void QupZilla::setupMenu()
|
|||
/******************
|
||||
* Bookmarks Menu *
|
||||
******************/
|
||||
m_menuBookmarks = new Menu(tr("&Bookmarks"));
|
||||
m_menuBookmarks->addAction(QIcon::fromTheme("bookmark-new"), tr("Bookmark &This Page"), MENU_RECEIVER, SLOT(bookmarkPage()))->setShortcut(QKeySequence("Ctrl+D"));
|
||||
m_menuBookmarks->addAction(QIcon::fromTheme("bookmark-new-list"), tr("Bookmark &All Tabs"), MENU_RECEIVER, SLOT(bookmarkAllTabs()));
|
||||
m_menuBookmarks->addAction(qIconProvider->fromTheme("bookmarks-organize"), tr("Organize &Bookmarks"), MENU_RECEIVER, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O"));
|
||||
m_menuBookmarks->addSeparator();
|
||||
|
||||
connect(m_menuBookmarks, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowBookmarksMenu()));
|
||||
connect(m_menuBookmarks, SIGNAL(menuMiddleClicked(Menu*)), MENU_RECEIVER, SLOT(loadFolderBookmarks(Menu*)));
|
||||
m_menuBookmarks = new BookmarksMenu();
|
||||
m_menuBookmarks->setMainWindow(this);
|
||||
|
||||
/**************
|
||||
* Tools Menu *
|
||||
|
@ -1010,120 +1005,6 @@ void QupZilla::aboutToHideFileMenu()
|
|||
m_actionCloseWindow->setEnabled(true);
|
||||
}
|
||||
|
||||
void QupZilla::aboutToShowBookmarksMenu()
|
||||
{
|
||||
if (!bookmarksMenuChanged()) {
|
||||
if (menuBookmarksAction()) {
|
||||
menuBookmarksAction()->setVisible(m_bookmarksToolbar->isVisible());
|
||||
}
|
||||
return;
|
||||
}
|
||||
setBookmarksMenuChanged(false);
|
||||
|
||||
while (m_menuBookmarks->actions().count() != 4) {
|
||||
QAction* act = m_menuBookmarks->actions().at(4);
|
||||
if (act->menu()) {
|
||||
act->menu()->clear();
|
||||
}
|
||||
m_menuBookmarks->removeAction(act);
|
||||
delete act;
|
||||
}
|
||||
|
||||
QSqlQuery query;
|
||||
query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='bookmarksMenu'");
|
||||
while (query.next()) {
|
||||
QString title = query.value(0).toString();
|
||||
const QUrl url = query.value(1).toUrl();
|
||||
const QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query.value(2).toByteArray()));
|
||||
if (title.length() > 40) {
|
||||
title.truncate(40);
|
||||
title += "..";
|
||||
}
|
||||
|
||||
Action* act = new Action(icon, title);
|
||||
act->setData(url);
|
||||
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
|
||||
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
|
||||
m_menuBookmarks->addAction(act);
|
||||
}
|
||||
|
||||
Menu* menuBookmarks = new Menu(_bookmarksToolbar, m_menuBookmarks);
|
||||
menuBookmarks->setIcon(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)));
|
||||
|
||||
query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar'");
|
||||
while (query.next()) {
|
||||
QString title = query.value(0).toString();
|
||||
const QUrl url = query.value(1).toUrl();
|
||||
const QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query.value(2).toByteArray()));
|
||||
if (title.length() > 40) {
|
||||
title.truncate(40);
|
||||
title += "..";
|
||||
}
|
||||
|
||||
Action* act = new Action(icon, title);
|
||||
act->setData(url);
|
||||
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
|
||||
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
|
||||
menuBookmarks->addAction(act);
|
||||
}
|
||||
if (menuBookmarks->isEmpty()) {
|
||||
menuBookmarks->addAction(tr("Empty"))->setEnabled(false);
|
||||
}
|
||||
setMenuBookmarksAction(m_menuBookmarks->addMenu(menuBookmarks));
|
||||
|
||||
query.exec("SELECT name FROM folders");
|
||||
while (query.next()) {
|
||||
const QString folderName = query.value(0).toString();
|
||||
Menu* tempFolder = new Menu(folderName, m_menuBookmarks);
|
||||
tempFolder->setIcon(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)));
|
||||
|
||||
QSqlQuery query2;
|
||||
query2.prepare("SELECT title, url, icon FROM bookmarks WHERE folder=?");
|
||||
query2.addBindValue(folderName);
|
||||
query2.exec();
|
||||
while (query2.next()) {
|
||||
QString title = query2.value(0).toString();
|
||||
const QUrl url = query2.value(1).toUrl();
|
||||
const QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query2.value(2).toByteArray()));
|
||||
if (title.length() > 40) {
|
||||
title.truncate(40);
|
||||
title += "..";
|
||||
}
|
||||
|
||||
Action* act = new Action(icon, title);
|
||||
act->setData(url);
|
||||
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
|
||||
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
|
||||
tempFolder->addAction(act);
|
||||
}
|
||||
if (tempFolder->isEmpty()) {
|
||||
tempFolder->addAction(tr("Empty"))->setEnabled(false);
|
||||
}
|
||||
m_menuBookmarks->addMenu(tempFolder);
|
||||
}
|
||||
|
||||
m_menuBookmarks->addSeparator();
|
||||
|
||||
query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='unsorted'");
|
||||
while (query.next()) {
|
||||
QString title = query.value(0).toString();
|
||||
const QUrl url = query.value(1).toUrl();
|
||||
const QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query.value(2).toByteArray()));
|
||||
if (title.length() > 40) {
|
||||
title.truncate(40);
|
||||
title += "..";
|
||||
}
|
||||
|
||||
Action* act = new Action(icon, title);
|
||||
act->setData(url);
|
||||
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
|
||||
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
|
||||
m_menuBookmarks->addAction(act);
|
||||
}
|
||||
|
||||
menuBookmarksAction()->setVisible(m_bookmarksToolbar->isVisible());
|
||||
}
|
||||
|
||||
void QupZilla::aboutToShowHistoryMenu()
|
||||
{
|
||||
TabbedWebView* view = weView();
|
||||
|
@ -1388,11 +1269,6 @@ void QupZilla::addBookmark(const QUrl &url, const QString &title)
|
|||
BookmarksTools::addBookmarkDialog(this, url, title);
|
||||
}
|
||||
|
||||
void QupZilla::bookmarkAllTabs()
|
||||
{
|
||||
BookmarksTools::bookmarkAllTabsDialog(this, m_tabWidget);
|
||||
}
|
||||
|
||||
void QupZilla::newWindow()
|
||||
{
|
||||
mApp->makeNewWindow(Qz::BW_NewWindow);
|
||||
|
@ -1501,18 +1377,6 @@ void QupZilla::loadActionUrlInNewNotSelectedTab(QObject* obj)
|
|||
}
|
||||
}
|
||||
|
||||
void QupZilla::loadFolderBookmarks(Menu* menu)
|
||||
{
|
||||
const QString folder = Bookmarks::fromTranslatedFolder(menu->title());
|
||||
if (folder.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (const Bookmark &b, mApp->bookmarks()->getFolderBookmarks(folder)) {
|
||||
tabWidget()->addView(b.url, b.title, Qz::NT_NotSelectedTab);
|
||||
}
|
||||
}
|
||||
|
||||
void QupZilla::loadAddress(const QUrl &url)
|
||||
{
|
||||
// TOOD: If current tab is pinned, it should open new tab instead
|
||||
|
|
|
@ -36,6 +36,7 @@ class TabWidget;
|
|||
class TabbedWebView;
|
||||
class LineEdit;
|
||||
class SearchToolBar;
|
||||
class BookmarksMenu;
|
||||
class BookmarksToolbar;
|
||||
class AutoFill;
|
||||
class MainApplication;
|
||||
|
@ -129,7 +130,6 @@ public slots:
|
|||
void loadActionUrl(QObject* obj = 0);
|
||||
void loadActionUrlInNewTab(QObject* obj = 0);
|
||||
void loadActionUrlInNewNotSelectedTab(QObject* obj = 0);
|
||||
void loadFolderBookmarks(Menu* menu);
|
||||
|
||||
void bookmarkPage();
|
||||
void loadAddress(const QUrl &url);
|
||||
|
@ -156,7 +156,6 @@ private slots:
|
|||
void aboutToShowHistoryMenu();
|
||||
void aboutToHideHistoryMenu();
|
||||
void aboutToShowClosedTabsMenu();
|
||||
void aboutToShowBookmarksMenu();
|
||||
void aboutToShowViewMenu();
|
||||
void aboutToHideViewMenu();
|
||||
void aboutToShowEditMenu();
|
||||
|
@ -181,7 +180,6 @@ private slots:
|
|||
void showBookmarkImport();
|
||||
|
||||
void refreshHistory();
|
||||
void bookmarkAllTabs();
|
||||
void newWindow();
|
||||
|
||||
void openLocation();
|
||||
|
@ -281,7 +279,7 @@ private:
|
|||
QMenu* m_menuHelp;
|
||||
QMenu* m_menuView;
|
||||
QMenu* m_toolbarsMenu;
|
||||
Menu* m_menuBookmarks;
|
||||
BookmarksMenu* m_menuBookmarks;
|
||||
Menu* m_menuHistory;
|
||||
QMenu* m_menuClosedTabs;
|
||||
Menu* m_menuHistoryRecent;
|
||||
|
|
234
src/lib/bookmarks/bookmarksmenu.cpp
Normal file
234
src/lib/bookmarks/bookmarksmenu.cpp
Normal file
|
@ -0,0 +1,234 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "bookmarksmenu.h"
|
||||
#include "bookmarkstools.h"
|
||||
#include "bookmarkitem.h"
|
||||
#include "bookmarks.h"
|
||||
#include "mainapplication.h"
|
||||
#include "browsinglibrary.h"
|
||||
#include "iconprovider.h"
|
||||
#include "qupzilla.h"
|
||||
#include "qzsettings.h"
|
||||
#include "tabwidget.h"
|
||||
|
||||
BookmarksMenu::BookmarksMenu(QWidget* parent)
|
||||
: Menu(parent)
|
||||
, m_window(0)
|
||||
, m_changed(true)
|
||||
{
|
||||
init();
|
||||
|
||||
connect(mApp->bookmarks(), SIGNAL(bookmarkAdded(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
||||
connect(mApp->bookmarks(), SIGNAL(bookmarkRemoved(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
||||
connect(mApp->bookmarks(), SIGNAL(bookmarkChanged(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
||||
}
|
||||
|
||||
void BookmarksMenu::setMainWindow(QupZilla* window)
|
||||
{
|
||||
m_window = window;
|
||||
}
|
||||
|
||||
void BookmarksMenu::bookmarkPage()
|
||||
{
|
||||
if (m_window) {
|
||||
m_window->bookmarkPage();
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::bookmarkAllTabs()
|
||||
{
|
||||
if (m_window) {
|
||||
BookmarksTools::bookmarkAllTabsDialog(m_window, m_window->tabWidget());
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::showBookmarksManager()
|
||||
{
|
||||
if (m_window) {
|
||||
mApp->browsingLibrary()->showBookmarks(m_window);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::bookmarksChanged()
|
||||
{
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
void BookmarksMenu::aboutToShow()
|
||||
{
|
||||
if (m_changed) {
|
||||
refresh();
|
||||
m_changed = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::loadMenu(Menu* menu)
|
||||
{
|
||||
BookmarkItem* item = static_cast<BookmarkItem*>(menu->menuAction()->data().value<void*>());
|
||||
Q_ASSERT(item);
|
||||
openFolder(item);
|
||||
}
|
||||
|
||||
void BookmarksMenu::bookmarkActivated()
|
||||
{
|
||||
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||
BookmarkItem* item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
||||
Q_ASSERT(item);
|
||||
openBookmark(item);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::bookmarkCtrlActivated()
|
||||
{
|
||||
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||
BookmarkItem* item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
||||
Q_ASSERT(item);
|
||||
openBookmarkInNewTab(item);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::bookmarkShiftActivated()
|
||||
{
|
||||
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||
BookmarkItem* item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
||||
Q_ASSERT(item);
|
||||
openBookmarkInNewWindow(item);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::openFolder(BookmarkItem* item)
|
||||
{
|
||||
Q_ASSERT(item->isFolder());
|
||||
|
||||
foreach (BookmarkItem* child, item->children()) {
|
||||
if (child->isUrl()) {
|
||||
openBookmarkInNewTab(child);
|
||||
}
|
||||
else if (child->isFolder()) {
|
||||
openFolder(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::openBookmark(BookmarkItem* item)
|
||||
{
|
||||
Q_ASSERT(item->isUrl());
|
||||
|
||||
if (m_window) {
|
||||
m_window->loadAddress(item->url());
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::openBookmarkInNewTab(BookmarkItem* item)
|
||||
{
|
||||
Q_ASSERT(item->isUrl());
|
||||
|
||||
if (m_window) {
|
||||
m_window->tabWidget()->addView(item->url(), item->title(), qzSettings->newTabPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::openBookmarkInNewWindow(BookmarkItem* item)
|
||||
{
|
||||
Q_ASSERT(item->isUrl());
|
||||
|
||||
mApp->makeNewWindow(Qz::BW_NewWindow, item->url());
|
||||
}
|
||||
|
||||
void BookmarksMenu::init()
|
||||
{
|
||||
setTitle(tr("&Bookmarks"));
|
||||
|
||||
addAction(QIcon::fromTheme("bookmark-new"), tr("Bookmark &This Page"), this, SLOT(bookmarkPage()))->setShortcut(QKeySequence("Ctrl+D"));
|
||||
addAction(QIcon::fromTheme("bookmark-new-list"), tr("Bookmark &All Tabs"), this, SLOT(bookmarkAllTabs()));
|
||||
addAction(qIconProvider->fromTheme("bookmarks-organize"), tr("Organize &Bookmarks"), this, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O"));
|
||||
addSeparator();
|
||||
|
||||
connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
|
||||
connect(this, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(loadMenu(Menu*)));
|
||||
}
|
||||
|
||||
#define FOLDER_ICON QApplication::style()->standardIcon(QStyle::SP_DirIcon)
|
||||
|
||||
void BookmarksMenu::refresh()
|
||||
{
|
||||
while (actions().count() != 4) {
|
||||
QAction* act = actions().at(4);
|
||||
if (act->menu()) {
|
||||
act->menu()->clear();
|
||||
}
|
||||
removeAction(act);
|
||||
delete act;
|
||||
}
|
||||
|
||||
addItem(this, mApp->bookmarks()->toolbarFolder());
|
||||
addSeparator();
|
||||
|
||||
foreach (BookmarkItem* child, mApp->bookmarks()->menuFolder()->children()) {
|
||||
addItem(this, child);
|
||||
}
|
||||
|
||||
addSeparator();
|
||||
addItem(this, mApp->bookmarks()->unsortedFolder());
|
||||
}
|
||||
|
||||
void BookmarksMenu::addItem(Menu* menu, BookmarkItem* item)
|
||||
{
|
||||
Q_ASSERT(menu);
|
||||
Q_ASSERT(item);
|
||||
|
||||
switch (item->type()) {
|
||||
case BookmarkItem::Url:
|
||||
addBookmark(menu, item);
|
||||
break;
|
||||
case BookmarkItem::Folder:
|
||||
addFolder(menu, item);
|
||||
break;
|
||||
case BookmarkItem::Separator:
|
||||
menu->addSeparator();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::addFolder(Menu* menu, BookmarkItem* folder)
|
||||
{
|
||||
Menu* m = new Menu(folder->title());
|
||||
m->setIcon(FOLDER_ICON);
|
||||
connect(m, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(loadMenu(Menu*)));
|
||||
|
||||
QAction* act = menu->addMenu(m);
|
||||
act->setData(QVariant::fromValue<void*>(static_cast<void*>(folder)));
|
||||
|
||||
foreach (BookmarkItem* child, folder->children()) {
|
||||
addItem(m, child);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::addBookmark(Menu* menu, BookmarkItem* bookmark)
|
||||
{
|
||||
Action* act = new Action(_iconForUrl(bookmark->url()), bookmark->title());
|
||||
act->setData(QVariant::fromValue<void*>(static_cast<void*>(bookmark)));
|
||||
|
||||
connect(act, SIGNAL(triggered()), this, SLOT(bookmarkActivated()));
|
||||
connect(act, SIGNAL(middleClicked()), this, SLOT(bookmarkCtrlActivated()));
|
||||
connect(act, SIGNAL(shiftClicked()), this, SLOT(bookmarkShiftActivated()));
|
||||
|
||||
menu->addAction(act);
|
||||
}
|
68
src/lib/bookmarks/bookmarksmenu.h
Normal file
68
src/lib/bookmarks/bookmarksmenu.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef BOOKMARKSMENU_H
|
||||
#define BOOKMARKSMENU_H
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "enhancedmenu.h"
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class QupZilla;
|
||||
class BookmarkItem;
|
||||
|
||||
class QT_QUPZILLA_EXPORT BookmarksMenu : public Menu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BookmarksMenu(QWidget* parent = 0);
|
||||
|
||||
void setMainWindow(QupZilla* window);
|
||||
|
||||
private slots:
|
||||
void bookmarkPage();
|
||||
void bookmarkAllTabs();
|
||||
void showBookmarksManager();
|
||||
|
||||
void bookmarksChanged();
|
||||
void aboutToShow();
|
||||
void loadMenu(Menu* menu);
|
||||
|
||||
void bookmarkActivated();
|
||||
void bookmarkCtrlActivated();
|
||||
void bookmarkShiftActivated();
|
||||
|
||||
void openFolder(BookmarkItem* item);
|
||||
void openBookmark(BookmarkItem* item);
|
||||
void openBookmarkInNewTab(BookmarkItem* item);
|
||||
void openBookmarkInNewWindow(BookmarkItem* item);
|
||||
|
||||
private:
|
||||
void init();
|
||||
void refresh();
|
||||
|
||||
void addItem(Menu* menu, BookmarkItem* item);
|
||||
void addFolder(Menu* menu, BookmarkItem* folder);
|
||||
void addBookmark(Menu* menu, BookmarkItem* bookmark);
|
||||
|
||||
QPointer<QupZilla> m_window;
|
||||
bool m_changed;
|
||||
};
|
||||
|
||||
#endif // BOOKMARKSMENU_H
|
|
@ -257,7 +257,8 @@ SOURCES += \
|
|||
tools/json.cpp \
|
||||
bookmarks/bookmarksmodel.cpp \
|
||||
bookmarks/bookmarkstreeview.cpp \
|
||||
bookmarks/bookmarkstools.cpp
|
||||
bookmarks/bookmarkstools.cpp \
|
||||
bookmarks/bookmarksmenu.cpp
|
||||
|
||||
|
||||
HEADERS += \
|
||||
|
@ -450,7 +451,8 @@ HEADERS += \
|
|||
tools/json.h \
|
||||
bookmarks/bookmarksmodel.h \
|
||||
bookmarks/bookmarkstreeview.h \
|
||||
bookmarks/bookmarkstools.h
|
||||
bookmarks/bookmarkstools.h \
|
||||
bookmarks/bookmarksmenu.h
|
||||
|
||||
FORMS += \
|
||||
preferences/autofillmanager.ui \
|
||||
|
|
|
@ -32,7 +32,7 @@ Menu::Menu(const QString &title, QWidget* parent)
|
|||
|
||||
void Menu::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
QAction* qact = actionAt(e->pos());
|
||||
QAction* qact = activeAction();
|
||||
Action* act = qobject_cast<Action*> (qact);
|
||||
|
||||
if (qact && qact->menu()) {
|
||||
|
@ -63,6 +63,43 @@ void Menu::mouseReleaseEvent(QMouseEvent* e)
|
|||
act->triggerMiddleClick();
|
||||
e->accept();
|
||||
}
|
||||
else if (e->button() == Qt::LeftButton && e->modifiers() == Qt::ShiftModifier) {
|
||||
closeAllMenus();
|
||||
act->triggerShiftClick();
|
||||
e->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() != Qt::Key_Enter && e->key() != Qt::Key_Return) {
|
||||
QMenu::keyPressEvent(e);
|
||||
return;
|
||||
}
|
||||
|
||||
QAction* qact = activeAction();
|
||||
Action* act = qobject_cast<Action*> (qact);
|
||||
|
||||
if (!act) {
|
||||
QMenu::keyPressEvent(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->modifiers() == Qt::NoModifier) {
|
||||
closeAllMenus();
|
||||
act->trigger();
|
||||
e->accept();
|
||||
}
|
||||
else if (e->modifiers() == Qt::ControlModifier) {
|
||||
closeAllMenus();
|
||||
act->triggerMiddleClick();
|
||||
e->accept();
|
||||
}
|
||||
else if (e->modifiers() == Qt::ShiftModifier) {
|
||||
closeAllMenus();
|
||||
act->triggerShiftClick();
|
||||
e->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::closeAllMenus()
|
||||
|
@ -94,3 +131,8 @@ void Action::triggerMiddleClick()
|
|||
{
|
||||
emit middleClicked();
|
||||
}
|
||||
|
||||
void Action::triggerShiftClick()
|
||||
{
|
||||
emit shiftClicked();
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ public slots:
|
|||
|
||||
private:
|
||||
void mouseReleaseEvent(QMouseEvent* e);
|
||||
void keyPressEvent(QKeyEvent* e);
|
||||
|
||||
void closeAllMenus();
|
||||
};
|
||||
|
||||
|
@ -52,9 +54,11 @@ public:
|
|||
|
||||
signals:
|
||||
void middleClicked();
|
||||
void shiftClicked();
|
||||
|
||||
public slots:
|
||||
void triggerMiddleClick();
|
||||
void triggerShiftClick();
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user