| 1 | /* |
|---|---|
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org> |
| 4 | SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> |
| 5 | SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org> |
| 6 | SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> |
| 7 | SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org> |
| 8 | SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org> |
| 9 | SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org> |
| 10 | SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org> |
| 11 | SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org> |
| 12 | SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> |
| 13 | |
| 14 | SPDX-License-Identifier: LGPL-2.0-only |
| 15 | */ |
| 16 | |
| 17 | #include "ktogglefullscreenaction.h" |
| 18 | |
| 19 | #include "ktoggleaction_p.h" |
| 20 | |
| 21 | #include <QEvent> |
| 22 | #include <QWidget> |
| 23 | |
| 24 | class KToggleFullScreenActionPrivate : public KToggleActionPrivate |
| 25 | { |
| 26 | Q_DECLARE_PUBLIC(KToggleFullScreenAction) |
| 27 | |
| 28 | public: |
| 29 | KToggleFullScreenActionPrivate(KToggleFullScreenAction *qq) |
| 30 | : KToggleActionPrivate(qq) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | void updateTextsAndIcon() |
| 35 | { |
| 36 | Q_Q(KToggleFullScreenAction); |
| 37 | |
| 38 | q->setText(KToggleFullScreenAction::tr(s: "F&ull Screen Mode", c: "@action:inmenu")); |
| 39 | q->setIconText(KToggleFullScreenAction::tr(s: "Full Screen", c: "@action:intoolbar")); |
| 40 | q->setToolTip(KToggleFullScreenAction::tr(s: "Display the window in full screen", c: "@info:tooltip")); |
| 41 | q->setIcon(QIcon::fromTheme(QStringLiteral("view-fullscreen"))); |
| 42 | } |
| 43 | |
| 44 | QWidget *window = nullptr; |
| 45 | }; |
| 46 | |
| 47 | KToggleFullScreenAction::KToggleFullScreenAction(QObject *parent) |
| 48 | : KToggleAction(*new KToggleFullScreenActionPrivate(this), parent) |
| 49 | { |
| 50 | Q_D(KToggleFullScreenAction); |
| 51 | setAutoRepeat(false); |
| 52 | d->updateTextsAndIcon(); |
| 53 | } |
| 54 | |
| 55 | KToggleFullScreenAction::KToggleFullScreenAction(QWidget *window, QObject *parent) |
| 56 | : KToggleFullScreenAction(parent) |
| 57 | { |
| 58 | setWindow(window); |
| 59 | } |
| 60 | |
| 61 | KToggleFullScreenAction::~KToggleFullScreenAction() = default; |
| 62 | |
| 63 | void KToggleFullScreenAction::setWindow(QWidget *window) |
| 64 | { |
| 65 | Q_D(KToggleFullScreenAction); |
| 66 | |
| 67 | if (d->window) { |
| 68 | d->window->removeEventFilter(obj: this); |
| 69 | } |
| 70 | |
| 71 | d->window = window; |
| 72 | |
| 73 | if (d->window) { |
| 74 | d->window->installEventFilter(filterObj: this); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void KToggleFullScreenAction::slotToggled(bool checked) |
| 79 | { |
| 80 | KToggleAction::slotToggled(checked); |
| 81 | } |
| 82 | |
| 83 | bool KToggleFullScreenAction::eventFilter(QObject *object, QEvent *event) |
| 84 | { |
| 85 | Q_D(KToggleFullScreenAction); |
| 86 | |
| 87 | if (object == d->window) { |
| 88 | if (event->type() == QEvent::WindowStateChange) { |
| 89 | if (d->window->isFullScreen() != isChecked()) { |
| 90 | activate(event: QAction::Trigger); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | void KToggleFullScreenAction::setFullScreen(QWidget *window, bool set) |
| 99 | { |
| 100 | if (set) { |
| 101 | window->setWindowState(window->windowState() | Qt::WindowFullScreen); |
| 102 | } else { |
| 103 | window->setWindowState(window->windowState() & ~Qt::WindowFullScreen); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | #include "moc_ktogglefullscreenaction.cpp" |
| 108 |
