Commit e833b3ce authored by Albert Astals Cid's avatar Albert Astals Cid

Fix menu titles not showing up

QMenu title/section are optional to draw from the style side but we have crucial information in them
so reuse old KMenu code to create a fake action that behaves as title

I'll see if KF5 wants to accept this as contribution later

BUGS: 374079
parent 4290dffb
......@@ -264,6 +264,7 @@ set(okularpart_SRCS
ui/ktreeviewsearchline.cpp
ui/latexrenderer.cpp
ui/minibar.cpp
ui/okmenutitle.cpp
ui/pageitemdelegate.cpp
ui/pagepainter.cpp
ui/pagesizelabel.cpp
......
......@@ -94,6 +94,7 @@
#include "ui/fileprinterpreview.h"
#include "ui/guiutils.h"
#include "ui/layers.h"
#include "ui/okmenutitle.h"
#include "conf/preferencesdialog.h"
#include "settings.h"
#include "core/action.h"
......@@ -2518,7 +2519,7 @@ void Part::slotShowMenu(const Okular::Page *page, const QPoint &point)
QAction *fitPageWidth = 0;
if (page)
{
popup->setTitle( i18n( "Page %1", page->number() + 1 ) );
popup->addAction( new OKMenuTitle( popup, i18n( "Page %1", page->number() + 1 ) ) );
if ( ( !currentPage && m_document->bookmarkManager()->isBookmarked( page->number() ) ) ||
( currentPage && m_document->bookmarkManager()->isBookmarked( m_document->viewport() ) ) )
removeBookmark = popup->addAction( QIcon::fromTheme(QStringLiteral("edit-delete-bookmark")), i18n("Remove Bookmark") );
......@@ -2533,7 +2534,7 @@ void Part::slotShowMenu(const Okular::Page *page, const QPoint &point)
if ((m_showMenuBarAction && !m_showMenuBarAction->isChecked()) || (m_showFullScreenAction && m_showFullScreenAction->isChecked()))
{
popup->setTitle( i18n( "Tools" ) );
popup->addAction( new OKMenuTitle( popup, i18n( "Tools" ) ) );
if (m_showMenuBarAction && !m_showMenuBarAction->isChecked()) popup->addAction(m_showMenuBarAction);
if (m_showFullScreenAction && m_showFullScreenAction->isChecked()) popup->addAction(m_showFullScreenAction);
reallyShow = true;
......
......@@ -18,6 +18,7 @@
#include "core/annotations.h"
#include "core/document.h"
#include "guiutils.h"
#include "okmenutitle.h"
Q_DECLARE_METATYPE( AnnotationPopup::AnnotPagePair )
......@@ -84,7 +85,7 @@ void AnnotationPopup::exec( const QPoint &point )
const AnnotPagePair &pair = mAnnotations.at(0);
menu.setTitle( i18np( "Annotation", "%1 Annotations", mAnnotations.count() ) );
menu.addAction( new OKMenuTitle( &menu, i18np( "Annotation", "%1 Annotations", mAnnotations.count() ) ) );
action = menu.addAction( QIcon::fromTheme( QStringLiteral("comment") ), i18n( "&Open Pop-up Note" ) );
action->setData( QVariant::fromValue( pair ) );
......@@ -124,7 +125,7 @@ void AnnotationPopup::exec( const QPoint &point )
{
foreach ( const AnnotPagePair& pair, mAnnotations )
{
menu.setTitle( GuiUtils::captionForAnnotation( pair.annotation ) );
menu.addAction( new OKMenuTitle( &menu, GuiUtils::captionForAnnotation( pair.annotation ) ) );
action = menu.addAction( QIcon::fromTheme( QStringLiteral("comment") ), i18n( "&Open Pop-up Note" ) );
action->setData( QVariant::fromValue( pair ) );
......
/* 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 false;
} 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;
}
/* 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.
*/
#ifndef OKMENUTITLE_H
#define OKMENUTITLE_H
#include <QWidgetAction>
class OKMenuTitle : public QWidgetAction
{
public:
OKMenuTitle(QMenu *menu, const QString &text, const QIcon &icon = QIcon());
bool eventFilter(QObject *object, QEvent *event) override;
};
#endif
......@@ -70,6 +70,7 @@
#include "pageviewannotator.h"
#include "priorities.h"
#include "toolaction.h"
#include "okmenutitle.h"
#ifdef HAVE_SPEECH
#include "tts.h"
#endif
......@@ -2774,7 +2775,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
QAction *imageToFile = 0;
if ( d->document->supportsSearching() && !selectedText.isEmpty() )
{
menu.setTitle( i18np( "Text (1 character)", "Text (%1 characters)", selectedText.length() ) );
menu.addAction( new OKMenuTitle( &menu, i18np( "Text (1 character)", "Text (%1 characters)", selectedText.length() ) ) );
textToClipboard = menu.addAction( QIcon::fromTheme(QStringLiteral("edit-copy")), i18n( "Copy to Clipboard" ) );
bool copyAllowed = d->document->isAllowed( Okular::AllowCopy );
if ( !copyAllowed )
......@@ -2791,7 +2792,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
addWebShortcutsMenu( &menu, selectedText );
}
}
menu.setTitle( i18n( "Image (%1 by %2 pixels)", selectionRect.width(), selectionRect.height() ) );
menu.addAction( new OKMenuTitle( &menu, i18n( "Image (%1 by %2 pixels)", selectionRect.width(), selectionRect.height() ) ) );
imageToClipboard = menu.addAction( QIcon::fromTheme(QStringLiteral("image-x-generic")), i18n( "Copy to Clipboard" ) );
imageToFile = menu.addAction( QIcon::fromTheme(QStringLiteral("document-save")), i18n( "Save to File..." ) );
QAction *choice = menu.exec( e->globalPos() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment