File indexing completed on 2024-04-28 03:59:15

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org>
0004     SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
0005     SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org>
0006     SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
0007     SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org>
0008     SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org>
0009     SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org>
0010     SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org>
0011     SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
0012 
0013     SPDX-License-Identifier: LGPL-2.0-only
0014 */
0015 
0016 #ifndef KTOGGLEFULLSCREENACTION_H
0017 #define KTOGGLEFULLSCREENACTION_H
0018 
0019 #include <ktoggleaction.h>
0020 
0021 class QWidget;
0022 
0023 class KToggleFullScreenActionPrivate;
0024 
0025 /**
0026  * @class KToggleFullScreenAction ktogglefullscreenaction.h KToggleFullScreenAction
0027  *
0028  * An action for switching between to/from full screen mode. Note that
0029  * QWidget::isFullScreen() may reflect the new or the old state
0030  * depending on how the action was triggered (by the application or
0031  * from the window manager). Also don't try to track the window state
0032  * yourself. Rely on this action's state (isChecked()) instead.
0033  *
0034  * Important: If you need to set/change the fullscreen state manually,
0035  * use KToggleFullScreenAction::setFullScreen() or a similar function,
0036  * do not call directly the slot connected to the toggled() signal. The slot
0037  * still needs to explicitly set the window state though.
0038  *
0039  * @note Do NOT use QWidget::showFullScreen() or QWidget::showNormal().
0040  * They have several side-effects besides just switching the fullscreen
0041  * state (for example, showNormal() resets all window states, not just
0042  * fullscreen). Use the KToggleFullScreenAction::setFullScreen() helper function.
0043  */
0044 class KWIDGETSADDONS_EXPORT KToggleFullScreenAction : public KToggleAction
0045 {
0046     Q_OBJECT
0047 
0048 public:
0049     /**
0050      * Create a KToggleFullScreenAction. Call setWindow() to associate this
0051      * action with a window.
0052      *
0053      *  @param parent This action's parent object.
0054      */
0055     explicit KToggleFullScreenAction(QObject *parent);
0056 
0057     /**
0058      * Create a KToggleFullScreenAction
0059      *  @param window the window that will switch to/from full screen mode
0060      *  @param parent This action's parent object.
0061      */
0062     KToggleFullScreenAction(QWidget *window, QObject *parent);
0063 
0064     /**
0065      * Destroys the toggle fullscreen action.
0066      */
0067     ~KToggleFullScreenAction() override;
0068 
0069     /**
0070      * Sets the window that will be related to this action.
0071      */
0072     void setWindow(QWidget *window);
0073 
0074     /**
0075      * Helper function to set or reset the fullscreen state of a window.
0076      * Use this function rather than showFullScreen()/showNormal() QWidget functions.
0077      * @since 4.0.3
0078      */
0079     static void setFullScreen(QWidget *window, bool set);
0080 
0081 protected:
0082     bool eventFilter(QObject *object, QEvent *event) override;
0083 
0084     // KF6 TODO: remove
0085 protected Q_SLOTS:
0086     void slotToggled(bool checked) override;
0087 
0088 private:
0089     Q_DECLARE_PRIVATE(KToggleFullScreenAction)
0090 };
0091 
0092 #endif