KWin
Loading...
Searching...
No Matches
animationsmodel.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include "animationsmodel.h"
11
12#include <KConfigGroup>
13
14namespace KWin
15{
16
18 : EffectsModel(parent)
19{
20 connect(this, &EffectsModel::loaded, this, [this]() {
21 setAnimationEnabled(modelAnimationEnabled());
22 setAnimationIndex(modelAnimationIndex());
23 loadDefaults();
24 });
25 connect(this, &AnimationsModel::animationIndexChanged, this, [this]() {
26 const QModelIndex index_ = index(m_animationIndex, 0);
27 if (!index_.isValid()) {
28 return;
29 }
30 const bool configurable = index_.data(ConfigurableRole).toBool();
31 if (configurable != m_currentConfigurable) {
32 m_currentConfigurable = configurable;
34 }
35 });
36}
37
39{
40 return m_animationEnabled;
41}
42
44{
45 if (m_animationEnabled != enabled) {
46 m_animationEnabled = enabled;
48 }
49}
50
52{
53 return m_animationIndex;
54}
55
57{
58 if (m_animationIndex != index) {
59 m_animationIndex = index;
60 Q_EMIT animationIndexChanged();
61 }
62}
63
65{
66 return m_currentConfigurable;
67}
68
70{
71 return m_defaultAnimationEnabled;
72}
73
75{
76 return m_defaultAnimationIndex;
77}
78
80{
81 return data.untranslatedCategory.contains(
82 QStringLiteral("Virtual Desktop Switching Animation"), Qt::CaseInsensitive);
83}
84
85EffectsModel::Status AnimationsModel::status(int row) const
86{
87 return Status(data(index(row, 0), static_cast<int>(StatusRole)).toInt());
88}
89
90void AnimationsModel::loadDefaults()
91{
92 for (int i = 0; i < rowCount(); ++i) {
93 const QModelIndex rowIndex = index(i, 0);
94 if (rowIndex.data(EnabledByDefaultRole).toBool()) {
95 m_defaultAnimationEnabled = true;
96 m_defaultAnimationIndex = i;
99 break;
100 }
101 }
102}
103
104bool AnimationsModel::modelAnimationEnabled() const
105{
106 for (int i = 0; i < rowCount(); ++i) {
107 if (status(i) != Status::Disabled) {
108 return true;
109 }
110 }
111
112 return false;
113}
114
115int AnimationsModel::modelAnimationIndex() const
116{
117 for (int i = 0; i < rowCount(); ++i) {
118 if (status(i) != Status::Disabled) {
119 return i;
120 }
121 }
122
123 return 0;
124}
125
130
132{
133 for (int i = 0; i < rowCount(); ++i) {
134 const auto status = (m_animationEnabled && i == m_animationIndex)
137 updateEffectStatus(index(i, 0), status);
138 }
139
141}
142
144{
146 setAnimationEnabled(modelAnimationEnabled());
147 setAnimationIndex(modelAnimationIndex());
148}
149
151{
152 // effect at m_animationIndex index may not be the current saved selected effect
153 const bool enabledByDefault = index(m_animationIndex, 0).data(EnabledByDefaultRole).toBool();
154 return enabledByDefault;
155}
156
158{
159 KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), QStringLiteral("Plugins"));
160
161 for (int i = 0; i < rowCount(); ++i) {
162 const QModelIndex index_ = index(i, 0);
163 const bool enabledConfig = kwinConfig.readEntry(
164 index_.data(ServiceNameRole).toString() + QLatin1String("Enabled"),
165 index_.data(EnabledByDefaultRole).toBool());
166 const bool enabled = (m_animationEnabled && i == m_animationIndex);
167
168 if (enabled != enabledConfig) {
169 return true;
170 }
171 }
172
173 return false;
174}
175
176}
177
178#include "moc_animationsmodel.cpp"
void setAnimationEnabled(bool enabled)
bool shouldStore(const EffectData &data) const override
void defaultAnimationEnabledChanged()
void defaultAnimationIndexChanged()
void setAnimationIndex(int index)
void currentConfigurableChanged()
AnimationsModel(QObject *parent=nullptr)
int rowCount(const QModelIndex &parent={}) const override
void updateEffectStatus(const QModelIndex &rowIndex, Status effectState)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QModelIndex index(int row, int column, const QModelIndex &parent={}) const override
void load(LoadOptions options=LoadOptions::None)