diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,7 @@ ktitlewidget.cpp ktoggleaction.cpp ktogglefullscreenaction.cpp + ktoggleshowmenubaraction.cpp kviewstateserializer.cpp kviewstatemaintainerbase.cpp keditlistwidget.cpp @@ -149,6 +150,7 @@ KSqueezedTextLabel KToggleAction KToggleFullScreenAction + KToggleShowMenuBarAction KViewStateSerializer KViewStateMaintainerBase KEditListWidget @@ -232,6 +234,7 @@ ksqueezedtextlabel.h ktoggleaction.h ktogglefullscreenaction.h + ktoggleshowmenubaraction.h kviewstateserializer.h kviewstatemaintainerbase.h keditlistwidget.h diff --git a/src/ktoggleshowmenubaraction.h b/src/ktoggleshowmenubaraction.h new file mode 100644 --- /dev/null +++ b/src/ktoggleshowmenubaraction.h @@ -0,0 +1,88 @@ +/* This file is part of the KDE libraries + Copyright (C) 2018 Luca Sartorelli + + 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 KTOGGLESHOWMENUBARACTION_H +#define KTOGGLESHOWMENUBARACTION_H + +#include + +/** + * @class KToggleShowMenuBarAction KToggleShowMenuBarAction.h KToggleShowMenuBarAction + * + * An action to hide or show the menubar of a window. + * The action by default remind the user how to show + * the menu bar using the keyboard shortcut. + * + * @author Luca Sartorelli + */ +class KWIDGETSADDONS_EXPORT KToggleShowMenuBarAction : public KToggleAction +{ + Q_OBJECT + +public: + /** + * Create a KToggleShowMenuBarAction. Call setWindow() to associate this + * action with a parent window for the message box. + * + * @param parent This action's parent object. + */ + explicit KToggleShowMenuBarAction(QObject *parent); + + /** + * Create a KToggleShowMenuBarAction + * @param window the parent window to be associated to the message box. + * @param parent This action's parent object. + */ + KToggleShowMenuBarAction(QWidget *window, QObject *parent); + + /** + * Destroys the toggle show menubar action. + */ + ~KToggleShowMenuBarAction() override; + + /** + * Sets the parent window for message box with the user reminder. + * @param window the window that will be parent for the message box + * @since 5.54 + */ + void setWindow(QWidget *window); + + /** + * If set to true, this action will remind the user through a message box + * on how to show the menu bar again, using the keyboard shortcut. + * Default: false + * @param show the window that will switch to/from full screen mode + * @since 5.54 + */ + void setShowMessage(bool show); + + /** + * @returns true if the user reminder needs to be shown. + * @since 5.54 + */ + bool showMessage(); + +protected Q_SLOTS: + void slotToggled(bool checked) override; + +private: + class Private; + Private *const d; +}; + +#endif diff --git a/src/ktoggleshowmenubaraction.cpp b/src/ktoggleshowmenubaraction.cpp new file mode 100644 --- /dev/null +++ b/src/ktoggleshowmenubaraction.cpp @@ -0,0 +1,86 @@ +/* This file is part of the KDE libraries + Copyright (C) 2018 Luca Sartorelli + + 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 "ktoggleshowmenubaraction.h" + +#include + +#include + +class Q_DECL_HIDDEN KToggleShowMenuBarAction::Private +{ +public: + Private(KToggleShowMenuBarAction *action) + : q(action) + , window(nullptr) + , showMessage(false) + { + } + + KToggleShowMenuBarAction *q; + QWidget *window; + bool showMessage; +}; + +KToggleShowMenuBarAction::KToggleShowMenuBarAction(QObject *parent) + : KToggleAction(parent), + d(new Private(this)) +{ +} + +KToggleShowMenuBarAction::KToggleShowMenuBarAction(QWidget *window, QObject *parent) + : KToggleAction(parent), + d(new Private(this)) +{ + setWindow(window); +} + +KToggleShowMenuBarAction::~KToggleShowMenuBarAction() +{ + delete d; +} + +void KToggleShowMenuBarAction::setWindow(QWidget *window) +{ + d->window = window; +} + +void KToggleShowMenuBarAction::setShowMessage(bool show) +{ + d->showMessage = show; +} + +bool KToggleShowMenuBarAction::showMessage() +{ + return d->showMessage; +} + +void KToggleShowMenuBarAction::slotToggled(bool checked) +{ + if (!checked && d->showMessage) + { + QKeySequence keySeq = d->q->shortcut(); + if (!keySeq.isEmpty()) + KMessageBox::information(d->window, tr("This will hide the menu bar completely." + " You can show it again by pressing %1.").arg(keySeq.toString(QKeySequence::NativeText)), + tr("Hide menu bar"), + QStringLiteral("HideMenuBarWarning")); + } + + KToggleAction::slotToggled(checked); +}