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 | |
52 | d->updateTextsAndIcon(); |
53 | } |
54 | |
55 | KToggleFullScreenAction::KToggleFullScreenAction(QWidget *window, QObject *parent) |
56 | : KToggleAction(*new KToggleFullScreenActionPrivate(this), parent) |
57 | { |
58 | Q_D(KToggleFullScreenAction); |
59 | |
60 | d->updateTextsAndIcon(); |
61 | setWindow(window); |
62 | } |
63 | |
64 | KToggleFullScreenAction::~KToggleFullScreenAction() = default; |
65 | |
66 | void KToggleFullScreenAction::setWindow(QWidget *window) |
67 | { |
68 | Q_D(KToggleFullScreenAction); |
69 | |
70 | if (d->window) { |
71 | d->window->removeEventFilter(obj: this); |
72 | } |
73 | |
74 | d->window = window; |
75 | |
76 | if (d->window) { |
77 | d->window->installEventFilter(filterObj: this); |
78 | } |
79 | } |
80 | |
81 | void KToggleFullScreenAction::slotToggled(bool checked) |
82 | { |
83 | KToggleAction::slotToggled(checked); |
84 | } |
85 | |
86 | bool KToggleFullScreenAction::eventFilter(QObject *object, QEvent *event) |
87 | { |
88 | Q_D(KToggleFullScreenAction); |
89 | |
90 | if (object == d->window) { |
91 | if (event->type() == QEvent::WindowStateChange) { |
92 | if (d->window->isFullScreen() != isChecked()) { |
93 | activate(event: QAction::Trigger); |
94 | } |
95 | } |
96 | } |
97 | |
98 | return false; |
99 | } |
100 | |
101 | void KToggleFullScreenAction::setFullScreen(QWidget *window, bool set) |
102 | { |
103 | if (set) { |
104 | window->setWindowState(window->windowState() | Qt::WindowFullScreen); |
105 | } else { |
106 | window->setWindowState(window->windowState() & ~Qt::WindowFullScreen); |
107 | } |
108 | } |
109 | |
110 | #include "moc_ktogglefullscreenaction.cpp" |
111 |