tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / slideshow / source / engine / animationnodes / setactivity.hxx
blob3e8107fb56c95515d2a57b53167236187b47d5fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_ANIMATIONNODES_SETACTIVITY_HXX
20 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_ANIMATIONNODES_SETACTIVITY_HXX
22 #include <comphelper/diagnose_ex.hxx>
24 #include <animationactivity.hxx>
25 #include <animatableshape.hxx>
26 #include <shapeattributelayer.hxx>
27 #include <activitiesfactory.hxx>
28 #include <utility>
30 namespace slideshow::internal {
32 /** Templated setter for animation values
34 This template class implements the AnimationActivity
35 interface, but only the perform() and
36 setAttributeLayer() methods are functional. To be used for set animations.
38 @see AnimationSetNode.
40 template <class AnimationT>
41 class SetActivity : public AnimationActivity
43 public:
44 typedef ::std::shared_ptr< AnimationT > AnimationSharedPtrT;
45 typedef typename AnimationT::ValueType ValueT;
47 SetActivity( const ActivitiesFactory::CommonParameters& rParms,
48 AnimationSharedPtrT xAnimation,
49 ValueT aToValue )
50 : mpAnimation(std::move( xAnimation )),
51 mpShape(),
52 mpAttributeLayer(),
53 mpEndEvent( rParms.mpEndEvent ),
54 mrEventQueue( rParms.mrEventQueue ),
55 maToValue(std::move( aToValue )),
56 mbIsActive(true)
58 ENSURE_OR_THROW( mpAnimation, "Invalid animation" );
61 virtual void dispose() override
63 mbIsActive = false;
64 mpAnimation.reset();
65 mpShape.reset();
66 mpAttributeLayer.reset();
67 // discharge end event:
68 if (mpEndEvent && mpEndEvent->isCharged())
69 mpEndEvent->dispose();
70 mpEndEvent.reset();
73 virtual double calcTimeLag() const override
75 return 0.0;
78 virtual bool perform() override
80 if (! isActive())
81 return false;
82 // we're going inactive immediately:
83 mbIsActive = false;
85 if (mpAnimation && mpAttributeLayer && mpShape) {
86 mpAnimation->start( mpShape, mpAttributeLayer );
87 (*mpAnimation)(maToValue);
88 mpAnimation->end();
90 // fire end event, if any
91 if (mpEndEvent)
92 mrEventQueue.addEvent( mpEndEvent );
94 return false; // don't reinsert
97 virtual bool isActive() const override
99 return mbIsActive;
102 virtual void dequeued() override
106 virtual void end() override
108 perform();
111 virtual void setTargets( const AnimatableShapeSharedPtr& rShape,
112 const ShapeAttributeLayerSharedPtr& rAttrLayer ) override
114 ENSURE_OR_THROW( rShape, "Invalid shape" );
115 ENSURE_OR_THROW( rAttrLayer, "Invalid attribute layer" );
117 mpShape = rShape;
118 mpAttributeLayer = rAttrLayer;
121 private:
122 AnimationSharedPtrT mpAnimation;
123 AnimatableShapeSharedPtr mpShape;
124 ShapeAttributeLayerSharedPtr mpAttributeLayer;
125 EventSharedPtr mpEndEvent;
126 EventQueue& mrEventQueue;
127 ValueT maToValue;
128 bool mbIsActive;
131 template <class AnimationT> AnimationActivitySharedPtr makeSetActivity(
132 const ActivitiesFactory::CommonParameters& rParms,
133 const ::std::shared_ptr< AnimationT >& rAnimation,
134 const typename AnimationT::ValueType& rToValue )
136 return std::make_shared<SetActivity<AnimationT>>(rParms,rAnimation,rToValue);
139 } // namespace presentation::internal
141 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_ANIMATIONNODES_SETACTIVITY_HXX
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */