2011-12-13 21:15:07 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-12-13 21:15:07 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-12-14 22:30:05 +01:00
|
|
|
#include "enhancedmenu.h"
|
2011-12-11 17:51:03 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMouseEvent>
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
Menu::Menu(QWidget* parent)
|
2011-12-11 17:51:03 +01:00
|
|
|
: QMenu(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu::Menu(const QString &title, QWidget* parent)
|
|
|
|
: QMenu(title, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
void Menu::mouseReleaseEvent(QMouseEvent* e)
|
2011-12-11 17:51:03 +01:00
|
|
|
{
|
2011-12-20 18:58:42 +01:00
|
|
|
QAction* qact = actionAt(e->pos());
|
|
|
|
Action* act = qobject_cast<Action*> (qact);
|
|
|
|
|
|
|
|
if (qact && qact->menu()) {
|
|
|
|
Menu* m = qobject_cast<Menu*> (qact->menu());
|
|
|
|
if (!m) {
|
|
|
|
QMenu::mouseReleaseEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
|
|
|
|
closeAllMenus();
|
|
|
|
emit menuMiddleClicked(m);
|
|
|
|
}
|
|
|
|
}
|
2011-12-11 17:51:03 +01:00
|
|
|
|
|
|
|
if (!act) {
|
|
|
|
QMenu::mouseReleaseEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e->button() == Qt::LeftButton && e->modifiers() == Qt::NoModifier) {
|
2011-12-13 19:18:05 +01:00
|
|
|
closeAllMenus();
|
2011-12-14 22:30:05 +01:00
|
|
|
act->trigger();
|
2011-12-11 17:51:03 +01:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
else if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
|
2011-12-13 19:18:05 +01:00
|
|
|
closeAllMenus();
|
2011-12-14 22:30:05 +01:00
|
|
|
act->triggerMiddleClick();
|
2011-12-11 17:51:03 +01:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 19:18:05 +01:00
|
|
|
void Menu::closeAllMenus()
|
|
|
|
{
|
|
|
|
QMenu* parentMenu = this;
|
|
|
|
|
|
|
|
while (parentMenu) {
|
|
|
|
parentMenu->close();
|
|
|
|
parentMenu = qobject_cast<QMenu*>(parentMenu->parentWidget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-11 17:51:03 +01:00
|
|
|
Action::Action(QObject* parent)
|
|
|
|
: QAction(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
Action::Action(const QString &text, QObject* parent)
|
2011-12-11 17:51:03 +01:00
|
|
|
: QAction(text, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
Action::Action(const QIcon &icon, const QString &text, QObject* parent)
|
2011-12-11 17:51:03 +01:00
|
|
|
: QAction(icon, text, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Action::triggerMiddleClick()
|
|
|
|
{
|
|
|
|
emit middleClicked();
|
|
|
|
}
|