Fix alpha setting in Designer's "Edit Palette" window
[qt-netbsd.git] / demos / sub-attaq / custompropertyanimation.h
blob0c97bf0c64aec1931e735af36893aadd41b8fe28
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #ifndef CUSTOMPROPERTYANIMATION_H
43 #define CUSTOMPROPERTYANIMATION_H
45 #include <QtCore/qvariantanimation.h>
47 QT_BEGIN_NAMESPACE
48 class QGraphicsItem;
49 QT_END_NAMESPACE
51 struct AbstractProperty
53 virtual QVariant read() const = 0;
54 virtual void write(const QVariant &value) = 0;
58 class CustomPropertyAnimation : public QVariantAnimation
60 Q_OBJECT
62 template <typename Target, typename T, typename T2 = T>
63 class MemberFunctionProperty : public AbstractProperty
65 public:
66 typedef T (Target::*Getter)(void) const;
67 typedef void (Target::*Setter)(T2);
69 MemberFunctionProperty(Target* target, Getter getter, Setter setter)
70 : m_target(target), m_getter(getter), m_setter(setter) {}
72 virtual void write(const QVariant &value)
74 if (m_setter) (m_target->*m_setter)(qVariantValue<T>(value));
77 virtual QVariant read() const
79 if (m_getter) return qVariantFromValue<T>((m_target->*m_getter)());
80 return QVariant();
83 private:
84 Target *m_target;
85 Getter m_getter;
86 Setter m_setter;
89 public:
90 CustomPropertyAnimation(QObject *parent = 0);
91 ~CustomPropertyAnimation();
93 template<class Target, typename T>
94 void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(const T& ))
96 setProperty(new MemberFunctionProperty<Target, T, const T&>(target, getter, setter));
99 template<class Target, typename T>
100 void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(T))
102 setProperty(new MemberFunctionProperty<Target, T>(target, getter, setter));
105 void updateCurrentValue(const QVariant &value);
106 void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
107 void setProperty(AbstractProperty *animProp);
109 private:
110 Q_DISABLE_COPY(CustomPropertyAnimation);
111 AbstractProperty *animProp;
114 #endif // CUSTOMPROPERTYANIMATION_H