Introduce a templated animationTime overload for the KConfigXT case

This method can be used to get the animationTime in case a configuration
class generated through KConfigXT is used. In general the configuration
stores the magic value 0 for a property "duration". This magic value
indicates that a hard-coded default value should be used.

So the common logic to test the stored value for 0 and then either pass
the stored value or the default value to animationTime is encapsulated
in this method in a generic way.

A MyEffect can use it in the following way:
animationTime<MyEffectConfig>(200);

BUG: 310646
FIXED-IN: 4.10
REVIEW: 107460
icc-effect-5.14.5
Martin Gräßlin 2012-11-25 18:46:13 +01:00
parent 40400167b9
commit 18cccad806
10 changed files with 23 additions and 6 deletions

View File

@ -91,7 +91,7 @@ bool CoverSwitchEffect::supported()
void CoverSwitchEffect::reconfigure(ReconfigureFlags)
{
CoverSwitchConfig::self()->readConfig();
animationDuration = animationTime(CoverSwitchConfig::duration());
animationDuration = animationTime<CoverSwitchConfig>(200);
animateSwitch = CoverSwitchConfig::animateSwitch();
animateStart = CoverSwitchConfig::animateStart();
animateStop = CoverSwitchConfig::animateStop();

View File

@ -159,6 +159,7 @@ void CubeEffect::reconfigure(ReconfigureFlags)
opacityDesktopOnly = CubeConfig::opacityDesktopOnly();
displayDesktopName = CubeConfig::displayDesktopName();
reflection = CubeConfig::reflection();
// TODO: rename rotationDuration to duration
rotationDuration = animationTime(CubeConfig::rotationDuration() != 0 ? CubeConfig::rotationDuration() : 500);
backgroundColor = CubeConfig::backgroundColor();
capColor = CubeConfig::capColor();

View File

@ -57,6 +57,7 @@ bool CubeSlideEffect::supported()
void CubeSlideEffect::reconfigure(ReconfigureFlags)
{
CubeSlideConfig::self()->readConfig();
// TODO: rename rotationDuration to duration
rotationDuration = animationTime(CubeSlideConfig::rotationDuration() != 0 ? CubeSlideConfig::rotationDuration() : 500);
timeLine.setCurveShape(QTimeLine::EaseInOutCurve);
timeLine.setDuration(rotationDuration);

View File

@ -71,10 +71,9 @@ void DashboardEffect::reconfigure(ReconfigureFlags)
{
brightness = DashboardConfig::brightness()/ 100.0;
saturation = DashboardConfig::saturation()/ 100.0;
duration = DashboardConfig::duration() != 0 ? DashboardConfig::duration() : 500;
blur = DashboardConfig::blur();
timeline.setDuration(animationTime(duration));
timeline.setDuration(animationTime<DashboardConfig>(500));
}
void DashboardEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)

View File

@ -73,7 +73,6 @@ private:
long atom;
qreal brightness;
qreal saturation;
int duration;
EffectWindow* window;
};

View File

@ -112,6 +112,7 @@ void DesktopGridEffect::reconfigure(ReconfigureFlags)
effects->reserveElectricBorder(ElectricBorder(i));
}
// TODO: rename zoomDuration to duration
zoomDuration = animationTime(DesktopGridConfig::zoomDuration() != 0 ? DesktopGridConfig::zoomDuration() : 300);
timeline.setCurveShape(QTimeLine::EaseInOutCurve);
timeline.setDuration(zoomDuration);

View File

@ -114,7 +114,7 @@ void FlipSwitchEffect::reconfigure(ReconfigureFlags)
}
m_tabbox = FlipSwitchConfig::tabBox();
m_tabboxAlternative = FlipSwitchConfig::tabBoxAlternative();
const int duration = animationTime(FlipSwitchConfig::duration() != 0 ? FlipSwitchConfig::duration() : 200);
const int duration = animationTime<FlipSwitchConfig>(200);
m_timeLine.setDuration(duration);
m_startStopTimeLine.setDuration(duration);

View File

@ -61,7 +61,7 @@ void GlideEffect::reconfigure(ReconfigureFlags)
{
// Fetch config with KConfigXT
GlideConfig::self()->readConfig();
duration = animationTime(GlideConfig::duration() != 0 ? GlideConfig::duration() : 350);
duration = animationTime<GlideConfig>(350);
effect = (EffectStyle) GlideConfig::glideEffect();
angle = GlideConfig::glideAngle();
}

View File

@ -52,6 +52,7 @@ bool MagicLampEffect::supported()
void MagicLampEffect::reconfigure(ReconfigureFlags)
{
MagicLampConfig::self()->readConfig();
// TODO: rename animationDuration to duration
mAnimationDuration = animationTime(MagicLampConfig::animationDuration() != 0 ? MagicLampConfig::animationDuration() : 250);
KConfigGroup conf = effects->effectConfig("MagicLamp");

View File

@ -477,6 +477,12 @@ public:
* in the effect itself.
*/
static double animationTime(int defaultTime);
/**
* @overload Use this variant if animation time is provided through a KConfigXT generated class
* having a property called "duration".
**/
template <typename T>
int animationTime(int defaultDuration);
/**
* Linearly interpolates between @p x and @p y.
*
@ -2713,6 +2719,15 @@ void Motion<T>::finish()
m_velocity = T();
}
/***************************************************************
Effect
***************************************************************/
template <typename T>
int Effect::animationTime(int defaultDuration)
{
return animationTime(T::duration() != 0 ? T::duration() : defaultDuration);
}
} // namespace
Q_DECLARE_METATYPE(KWin::EffectWindow*)
Q_DECLARE_METATYPE(QList<KWin::EffectWindow*>)