1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-22 10:12:10 +02:00
falkonOfficial/src/tools/menu.cpp

80 lines
2.0 KiB
C++
Raw Normal View History

/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca
*
* 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 "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<Action*> (actionAt(e->pos()));
if (!act) {
QMenu::mouseReleaseEvent(e);
return;
}
if (e->button() == Qt::LeftButton && e->modifiers() == Qt::NoModifier) {
act->trigger();
closeAllMenus();
e->accept();
}
else if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
act->triggerMiddleClick();
closeAllMenus();
e->accept();
}
}
void Menu::closeAllMenus()
{
QMenu* parentMenu = this;
while (parentMenu) {
parentMenu->close();
parentMenu = qobject_cast<QMenu*>(parentMenu->parentWidget());
}
}
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();
}