diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index 83073df60..b2d178f60 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -22,6 +22,7 @@ #include "historymodel.h" #include "toolbutton.h" #include "databasewriter.h" +#include "menu.h" BookmarksToolbar::BookmarksToolbar(QupZilla* mainClass, QWidget* parent) : QWidget(parent) @@ -239,7 +240,7 @@ void BookmarksToolbar::subfolderAdded(const QString &name) b->setIcon(style()->standardIcon(QStyle::SP_DirIcon)); b->setText(name); - QMenu* menu = new QMenu(name); + Menu* menu = new Menu(name); b->setMenu(menu); connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu())); @@ -420,7 +421,7 @@ void BookmarksToolbar::refreshBookmarks() b->setIcon(style()->standardIcon(QStyle::SP_DirIcon)); b->setText(query.value(0).toString()); - QMenu* menu = new QMenu(query.value(0).toString()); + Menu* menu = new Menu(query.value(0).toString()); b->setMenu(menu); connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu())); @@ -434,7 +435,7 @@ void BookmarksToolbar::refreshBookmarks() m_mostVis->setText(tr("Most visited")); m_mostVis->setToolTip(tr("Sites you visited the most")); - m_menuMostVisited = new QMenu(); + m_menuMostVisited = new Menu(); m_mostVis->setMenu(m_menuMostVisited); connect(m_menuMostVisited, SIGNAL(aboutToShow()), this, SLOT(refreshMostVisited())); @@ -466,7 +467,12 @@ void BookmarksToolbar::aboutToShowFolderMenu() title.truncate(40); title += ".."; } - menu->addAction(icon, title, p_QupZilla, SLOT(loadActionUrl()))->setData(url); + + Action* act = new Action(icon, title); + act->setData(url); + connect (act, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl())); + connect (act, SIGNAL(middleClicked()), p_QupZilla, SLOT(loadActionUrlInNewTab())); + menu->addAction(act); } if (menu->isEmpty()) { @@ -484,7 +490,12 @@ void BookmarksToolbar::refreshMostVisited() entry.title.truncate(40); entry.title += ".."; } - m_menuMostVisited->addAction(_iconForUrl(entry.url), entry.title, p_QupZilla, SLOT(loadActionUrl()))->setData(entry.url); + + Action* act = new Action(_iconForUrl(entry.url), entry.title); + act->setData(entry.url); + connect (act, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl())); + connect (act, SIGNAL(middleClicked()), p_QupZilla, SLOT(loadActionUrlInNewTab())); + m_menuMostVisited->addAction(act); } if (m_menuMostVisited->isEmpty()) { diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h index cf52d3c29..538e2b06d 100644 --- a/src/bookmarks/bookmarkstoolbar.h +++ b/src/bookmarks/bookmarkstoolbar.h @@ -28,6 +28,7 @@ class QupZilla; class BookmarksModel; class HistoryModel; class ToolButton; +class Menu; class BookmarksToolbar : public QWidget { Q_OBJECT @@ -68,7 +69,7 @@ private: QupZilla* p_QupZilla; BookmarksModel* m_bookmarksModel; HistoryModel* m_historyModel; - QMenu* m_menuMostVisited; + Menu* m_menuMostVisited; ToolButton* m_mostVis; QHBoxLayout* m_layout; }; diff --git a/src/other/sourceviewer.cpp b/src/other/sourceviewer.cpp index 24675c59a..2f5247499 100644 --- a/src/other/sourceviewer.cpp +++ b/src/other/sourceviewer.cpp @@ -21,6 +21,7 @@ #include "sourceviewersearch.h" #include "globalfunctions.h" #include "iconprovider.h" +#include "menu.h" SourceViewer::SourceViewer(QWebPage* page, const QString &selectedHtml) : QWidget(0) diff --git a/src/src.pro b/src/src.pro index b3eaf686e..aa4979c31 100644 --- a/src/src.pro +++ b/src/src.pro @@ -175,7 +175,8 @@ SOURCES += main.cpp\ tools/pagethumbnailer.cpp \ plugins/speeddial.cpp \ other/databasewriter.cpp \ - bookmarksimport/htmlimporter.cpp + bookmarksimport/htmlimporter.cpp \ + tools/menu.cpp HEADERS += \ 3rdparty/qtwin.h \ @@ -293,7 +294,8 @@ HEADERS += \ tools/pagethumbnailer.h \ plugins/speeddial.h \ other/databasewriter.h \ - bookmarksimport/htmlimporter.h + bookmarksimport/htmlimporter.h \ + tools/menu.h FORMS += \ preferences/autofillmanager.ui \ @@ -390,3 +392,5 @@ equals(d_w7api, "true") { DEFINES += W7API } message(Using following defines) message($$DEFINES) + + diff --git a/src/tools/menu.cpp b/src/tools/menu.cpp new file mode 100644 index 000000000..bb35c0243 --- /dev/null +++ b/src/tools/menu.cpp @@ -0,0 +1,53 @@ +#include "menu.h" + +Menu::Menu(QWidget *parent) + : QMenu(parent) +{ +} + +Menu::Menu(const QString &title, QWidget* parent) + : QMenu(title, parent) +{ +} + +void Menu::mouseReleaseEvent(QMouseEvent *e) +{ + Action* act = qobject_cast (actionAt(e->pos())); + + if (!act) { + QMenu::mouseReleaseEvent(e); + return; + } + + if (e->button() == Qt::LeftButton && e->modifiers() == Qt::NoModifier) { + act->trigger(); + close(); + e->accept(); + } + else if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) { + act->triggerMiddleClick(); + close(); + e->accept(); + } +} + + +Action::Action(QObject* parent) + : QAction(parent) +{ +} + +Action::Action(const QString &text, QObject *parent) + : QAction(text, parent) +{ +} + +Action::Action(const QIcon &icon, const QString &text, QObject *parent) + : QAction(icon, text, parent) +{ +} + +void Action::triggerMiddleClick() +{ + emit middleClicked(); +} diff --git a/src/tools/menu.h b/src/tools/menu.h new file mode 100644 index 000000000..1beeacdaa --- /dev/null +++ b/src/tools/menu.h @@ -0,0 +1,39 @@ +#ifndef MENU_H +#define MENU_H + +#include +#include + +class Menu : public QMenu +{ + Q_OBJECT +public: + explicit Menu(QWidget *parent = 0); + explicit Menu(const QString &title, QWidget *parent = 0); + +signals: + +public slots: + +private: + void mouseReleaseEvent(QMouseEvent *e); + +}; + +class Action : public QAction +{ + Q_OBJECT +public: + explicit Action(QObject *parent = 0); + explicit Action(const QString &text, QObject *parent = 0); + explicit Action(const QIcon &icon, const QString &text, QObject *parent = 0); + +signals: + void middleClicked(); + +public slots: + void triggerMiddleClick(); + +}; + +#endif // MENU_H