KWin
Loading...
Searching...
No Matches
tileseditoreffect.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 Marco Martin <mart@kde.org>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "tileseditoreffect.h"
8
9#include <QAction>
10#include <QQuickItem>
11#include <QTimer>
12
13#include <KGlobalAccel>
14#include <KLocalizedString>
15
16namespace KWin
17{
18
20 : m_shutdownTimer(std::make_unique<QTimer>())
21{
22 m_shutdownTimer->setSingleShot(true);
23 connect(m_shutdownTimer.get(), &QTimer::timeout, this, &TilesEditorEffect::realDeactivate);
24 connect(effects, &EffectsHandler::screenAboutToLock, this, &TilesEditorEffect::realDeactivate);
25
26 const QKeySequence defaultToggleShortcut = Qt::META | Qt::Key_T;
27 m_toggleAction = std::make_unique<QAction>();
28 connect(m_toggleAction.get(), &QAction::triggered, this, &TilesEditorEffect::toggle);
29 m_toggleAction->setObjectName(QStringLiteral("Edit Tiles"));
30 m_toggleAction->setText(i18n("Toggle Tiles Editor"));
31 KGlobalAccel::self()->setDefaultShortcut(m_toggleAction.get(), {defaultToggleShortcut});
32 KGlobalAccel::self()->setShortcut(m_toggleAction.get(), {defaultToggleShortcut});
33 m_toggleShortcut = KGlobalAccel::self()->shortcut(m_toggleAction.get());
34
35 setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/effects/tileseditor/qml/main.qml"))));
36}
37
41
43{
44 return QVariantMap{
45 {QStringLiteral("effect"), QVariant::fromValue(this)},
46 {QStringLiteral("targetScreen"), QVariant::fromValue(screen)},
47 };
48}
49
50void TilesEditorEffect::reconfigure(ReconfigureFlags)
51{
53}
54
56{
57 if (!isRunning()) {
58 activate();
59 } else {
60 deactivate(0);
61 }
62}
63
65{
66 setRunning(true);
67}
68
70{
71 const auto screens = effects->screens();
72 for (const auto screen : screens) {
73 if (QuickSceneView *view = viewForScreen(screen)) {
74 QMetaObject::invokeMethod(view->rootItem(), "stop");
75 }
76 }
77
78 m_shutdownTimer->start(timeout);
79}
80
81void TilesEditorEffect::realDeactivate()
82{
83 setRunning(false);
84}
85
87{
88 return m_animationDuration;
89}
90
92{
93 if (m_animationDuration != duration) {
94 m_animationDuration = duration;
96 }
97}
98
100{
101 return 70;
102}
103
105{
106 if (m_toggleShortcut.contains(keyEvent->key() | keyEvent->modifiers())) {
107 if (keyEvent->type() == QEvent::KeyPress) {
108 toggle();
109 }
110 return;
111 }
113}
114
115} // namespace KWin
116
117#include "moc_tileseditoreffect.cpp"
QList< Output * > screens() const
void grabbedKeyboardEvent(QKeyEvent *keyEvent) override
Q_INVOKABLE QuickSceneView * viewForScreen(Output *screen) const
void setSource(const QUrl &url)
void setRunning(bool running)
void grabbedKeyboardEvent(QKeyEvent *keyEvent) override
void reconfigure(ReconfigureFlags) override
QVariantMap initialProperties(Output *screen) override
int requestedEffectChainPosition() const override
void setAnimationDuration(int duration)
static double animationTime(const KConfigGroup &cfg, const QString &key, int defaultTime)
Definition effect.cpp:483
EffectsHandler * effects