okular/part/okmenutitle.cpp
David Hurka 19d5dd8ec7 New part/ directory for okularpart sources from /, ui/, conf/
Source files are no longer separated by UI and non-UI and similar,
but only by their build target.

* ui/ -> part/
* Move all source files from conf/ to part/
* Keep config skeleton definitions in conf/, needed for the mobile target too
* Move editdrawingtooldialogtest.h from conf/autotests/ to autotests/
* ui/data/icons/ -> icons/
* Move /part.cpp, /part.rc and similar files to part/
* Adapt include paths in source files
* Adapt CMakeLists.txt files (in / and in subdirectories)
* Adapt /Messages.sh
2020-11-18 19:32:56 +00:00

64 lines
2.4 KiB
C++

/* This file was part of the KDE libraries (copied partially from kmenu.cpp)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "okmenutitle.h"
#include <QApplication>
#include <QEvent>
#include <QKeyEvent>
#include <QMenu>
#include <QToolButton>
OKMenuTitle::OKMenuTitle(QMenu *menu, const QString &text, const QIcon &icon)
: QWidgetAction(menu)
{
QAction *buttonAction = new QAction(menu);
QFont font = buttonAction->font();
font.setBold(true);
buttonAction->setFont(font);
buttonAction->setText(text);
buttonAction->setIcon(icon);
QToolButton *titleButton = new QToolButton(menu);
titleButton->installEventFilter(this); // prevent clicks on the title of the menu
titleButton->setDefaultAction(buttonAction);
titleButton->setDown(true); // prevent hover style changes in some styles
titleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setDefaultWidget(titleButton);
}
bool OKMenuTitle::eventFilter(QObject *object, QEvent *event)
{
Q_UNUSED(object);
if (event->type() == QEvent::Paint) {
return QWidgetAction::eventFilter(object, event);
} else if (event->type() == QEvent::KeyRelease) {
// If we're receiving the key release event is because we just gained
// focus though a key event, use the same key to move it to the next action
if (static_cast<QMenu *>(parentWidget())->activeAction() == this) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
QKeyEvent newKe(QEvent::KeyPress, ke->key(), ke->modifiers(), ke->text(), ke->isAutoRepeat(), ke->count());
QApplication::sendEvent(parentWidget(), &newKe);
}
// TODO What happens when there's multiple OKMenuTitle or only OKMenuTitle in a menu
}
event->accept();
return true;
}