Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/anidata.cpp
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | |||||
67 | , startTime(AnimationEffect::clock() + delay) | 67 | , startTime(AnimationEffect::clock() + delay) | ||
68 | , windowType((NET::WindowTypeMask)0) | 68 | , windowType((NET::WindowTypeMask)0) | ||
69 | , fullScreenEffectLock(fullScreenEffectLock_) | 69 | , fullScreenEffectLock(fullScreenEffectLock_) | ||
70 | , waitAtSource(waitAtSource_) | 70 | , waitAtSource(waitAtSource_) | ||
71 | , keepAtTarget(keepAtTarget_) | 71 | , keepAtTarget(keepAtTarget_) | ||
72 | { | 72 | { | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | static FPx2 fpx2(const QString &s, AnimationEffect::Attribute a) | | |||
76 | { | | |||
77 | bool ok; float f1, f2; | | |||
78 | const QVector<QStringRef> floats = s.splitRef(u','); | | |||
79 | f1 = floats.at(0).toFloat(&ok); | | |||
80 | if (!ok || (f1 < 0.0 && !( a == AnimationEffect::Position || | | |||
81 | a == AnimationEffect::Translation || | | |||
82 | a == AnimationEffect::Size || | | |||
83 | a == AnimationEffect::Rotation)) ) { | | |||
84 | if (ok) | | |||
85 | qCDebug(LIBKWINEFFECTS) << "Invalid value (must not be negative)" << s; | | |||
86 | return FPx2(); | | |||
87 | } | | |||
88 | | ||||
89 | bool forced_align = (floats.count() < 2); | | |||
90 | if (forced_align) | | |||
91 | f2 = f1; | | |||
92 | else { | | |||
93 | f2 = floats.at(1).toFloat(&ok); | | |||
94 | if ( (forced_align = !ok || (f2 < 0.0 && !( a == AnimationEffect::Position || | | |||
95 | a == AnimationEffect::Translation || | | |||
96 | a == AnimationEffect::Size || | | |||
97 | a == AnimationEffect::Rotation))) ) | | |||
98 | f2 = f1; | | |||
99 | } | | |||
100 | if ( forced_align && a >= AnimationEffect::NonFloatBase ) | | |||
101 | qCDebug(LIBKWINEFFECTS) << "Generic Animations, WARNING: had to align second dimension of non-onedimensional attribute" << a; | | |||
102 | return FPx2(f1, f2); | | |||
103 | } | | |||
104 | | ||||
105 | AniData::AniData(const QString &str) // format: WindowMask:Attribute:Meta:Duration:To:Shape:Delay:From | | |||
106 | : customCurve(0) // Linear | | |||
107 | , time(0) | | |||
108 | , duration(1) // invalidate | | |||
109 | { | | |||
110 | const QVector<QStringRef> animation = str.splitRef(u':'); | | |||
111 | if (animation.count() < 5) | | |||
112 | return; // at least window type, attribute, metadata, time and target is required | | |||
113 | | ||||
114 | windowType = (NET::WindowTypeMask)animation.at(0).toUInt(); | | |||
115 | | ||||
116 | if (animation.at(1) == QLatin1String("Opacity")) attribute = AnimationEffect::Opacity; | | |||
117 | else if (animation.at(1) == QLatin1String("Brightness")) attribute = AnimationEffect::Brightness; | | |||
118 | else if (animation.at(1) == QLatin1String("Saturation")) attribute = AnimationEffect::Saturation; | | |||
119 | else if (animation.at(1) == QLatin1String("Scale")) attribute = AnimationEffect::Scale; | | |||
120 | else if (animation.at(1) == QLatin1String("Translation")) attribute = AnimationEffect::Translation; | | |||
121 | else if (animation.at(1) == QLatin1String("Rotation")) attribute = AnimationEffect::Rotation; | | |||
122 | else if (animation.at(1) == QLatin1String("Position")) attribute = AnimationEffect::Position; | | |||
123 | else if (animation.at(1) == QLatin1String("Size")) attribute = AnimationEffect::Size; | | |||
124 | else if (animation.at(1) == QLatin1String("Clip")) attribute = AnimationEffect::Clip; | | |||
125 | else { | | |||
126 | qCDebug(LIBKWINEFFECTS) << "Invalid attribute" << animation.at(1); | | |||
127 | return; | | |||
128 | } | | |||
129 | | ||||
130 | meta = animation.at(2).toUInt(); | | |||
131 | | ||||
132 | bool ok; | | |||
133 | duration = animation.at(3).toInt(&ok); | | |||
134 | if (!ok || duration < 0) { | | |||
135 | qCDebug(LIBKWINEFFECTS) << "Invalid duration" << animation.at(3); | | |||
136 | duration = 0; | | |||
137 | return; | | |||
138 | } | | |||
139 | | ||||
140 | to = fpx2(animation.at(4).toString(), attribute); | | |||
141 | | ||||
142 | if (animation.count() > 5) { | | |||
143 | customCurve = animation.at(5).toInt(); | | |||
144 | if (customCurve < QEasingCurve::Custom) | | |||
145 | curve.setType((QEasingCurve::Type)customCurve); | | |||
146 | else if (customCurve == Gaussian) | | |||
147 | curve.setCustomType(AnimationEffect::qecGaussian); | | |||
148 | else | | |||
149 | qCDebug(LIBKWINEFFECTS) << "Unknown curve type" << customCurve; // remains default, ie. linear | | |||
150 | | ||||
151 | if (animation.count() > 6) { | | |||
152 | int t = animation.at(6).toInt(); | | |||
153 | if (t < 0) | | |||
154 | qCDebug(LIBKWINEFFECTS) << "Delay can not be negative" << animation.at(6); | | |||
155 | else | | |||
156 | time = t; | | |||
157 | | ||||
158 | if (animation.count() > 7) | | |||
159 | from = fpx2(animation.at(7).toString(), attribute); | | |||
160 | } | | |||
161 | } | | |||
162 | if (!(from.isValid() || to.isValid())) { | | |||
163 | duration = -1; // invalidate | | |||
164 | return; | | |||
165 | } | | |||
166 | } | | |||
167 | | ||||
168 | static QString attributeString(KWin::AnimationEffect::Attribute attribute) | 75 | static QString attributeString(KWin::AnimationEffect::Attribute attribute) | ||
169 | { | 76 | { | ||
170 | switch (attribute) { | 77 | switch (attribute) { | ||
171 | case KWin::AnimationEffect::Opacity: return QStringLiteral("Opacity"); | 78 | case KWin::AnimationEffect::Opacity: return QStringLiteral("Opacity"); | ||
172 | case KWin::AnimationEffect::Brightness: return QStringLiteral("Brightness"); | 79 | case KWin::AnimationEffect::Brightness: return QStringLiteral("Brightness"); | ||
173 | case KWin::AnimationEffect::Saturation: return QStringLiteral("Saturation"); | 80 | case KWin::AnimationEffect::Saturation: return QStringLiteral("Saturation"); | ||
174 | case KWin::AnimationEffect::Scale: return QStringLiteral("Scale"); | 81 | case KWin::AnimationEffect::Scale: return QStringLiteral("Scale"); | ||
175 | case KWin::AnimationEffect::Translation: return QStringLiteral("Translation"); | 82 | case KWin::AnimationEffect::Translation: return QStringLiteral("Translation"); | ||
176 | case KWin::AnimationEffect::Rotation: return QStringLiteral("Rotation"); | 83 | case KWin::AnimationEffect::Rotation: return QStringLiteral("Rotation"); | ||
177 | case KWin::AnimationEffect::Position: return QStringLiteral("Position"); | 84 | case KWin::AnimationEffect::Position: return QStringLiteral("Position"); | ||
178 | case KWin::AnimationEffect::Size: return QStringLiteral("Size"); | 85 | case KWin::AnimationEffect::Size: return QStringLiteral("Size"); | ||
179 | case KWin::AnimationEffect::Clip: return QStringLiteral("Clip"); | 86 | case KWin::AnimationEffect::Clip: return QStringLiteral("Clip"); | ||
180 | default: return QStringLiteral(" "); | 87 | default: return QStringLiteral(" "); | ||
181 | } | 88 | } | ||
182 | } | 89 | } | ||
183 | 90 | | |||
184 | QList<AniData> AniData::list(const QString &str) | | |||
185 | { | | |||
186 | QList<AniData> newList; | | |||
187 | foreach (const QString &astr, str.split(u';', QString::SkipEmptyParts)) { | | |||
188 | newList << AniData(astr); | | |||
189 | if (newList.last().duration < 0) | | |||
190 | newList.removeLast(); | | |||
191 | } | | |||
192 | return newList; | | |||
193 | } | | |||
194 | | ||||
195 | QString AniData::toString() const | | |||
196 | { | | |||
197 | QString ret = QString::number((uint)windowType) + QLatin1Char(':') + attributeString(attribute) + QLatin1Char(':') + | | |||
198 | QString::number(meta) + QLatin1Char(':') + QString::number(duration) + QLatin1Char(':') + | | |||
199 | to.toString() + QLatin1Char(':') + QString::number(customCurve) + QLatin1Char(':') + | | |||
200 | QString::number(time) + QLatin1Char(':') + from.toString(); | | |||
201 | return ret; | | |||
202 | } | | |||
203 | | ||||
204 | QString AniData::debugInfo() const | 91 | QString AniData::debugInfo() const | ||
205 | { | 92 | { | ||
206 | return QLatin1String("Animation: ") + attributeString(attribute) + | 93 | return QLatin1String("Animation: ") + attributeString(attribute) + | ||
207 | QLatin1String("\n From: ") + from.toString() + | 94 | QLatin1String("\n From: ") + from.toString() + | ||
208 | QLatin1String("\n To: ") + to.toString() + | 95 | QLatin1String("\n To: ") + to.toString() + | ||
209 | QLatin1String("\n Started: ") + QString::number(AnimationEffect::clock() - startTime) + QLatin1String("ms ago\n") + | 96 | QLatin1String("\n Started: ") + QString::number(AnimationEffect::clock() - startTime) + QLatin1String("ms ago\n") + | ||
210 | QLatin1String( " Duration: ") + QString::number(duration) + QLatin1String("ms\n") + | 97 | QLatin1String( " Duration: ") + QString::number(duration) + QLatin1String("ms\n") + | ||
211 | QLatin1String( " Passed: ") + QString::number(time) + QLatin1String("ms\n") + | 98 | QLatin1String( " Passed: ") + QString::number(time) + QLatin1String("ms\n") + | ||
212 | QLatin1String( " Applying: ") + QString::number(windowType) + QLatin1Char('\n'); | 99 | QLatin1String( " Applying: ") + QString::number(windowType) + QLatin1Char('\n'); | ||
213 | } | 100 | } |