043bfdebbd9c617d5a6ce5fe2d50498b2b2e9bdb
[platform/core/uifw/dali-demo.git] / examples / contact-cards / contact-card.h
1 #ifndef CONTACT_CARD_H
2 #define CONTACT_CARD_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/events/tap-gesture-detector.h>
25 #include <dali/public-api/object/ref-object.h>
26 #include <dali-toolkit/public-api/controls/control.h>
27
28 class ContactCardLayoutInfo;
29
30 /**
31  * @brief Creates and sets up animations for a contact card
32  *
33  * Each contact card has two states, folded and unfolded.
34  * In this context, "unfolded" means when all the details, including the name, address and image are shown.
35  * In this scenario, the control takes up most of the screen.
36  *
37  * When the contact card is "folded", this means when only brief information is shown to the user, i.e. the image and name.
38  * In this scenario, the control is small and there should be several of these contact cards visible on the screen.
39  *
40  * The contact card creates several controls that it requires to appropriately display itself in both of these states.
41  */
42 class ContactCard : public Dali::RefObject
43 {
44 public:
45
46   /**
47    * @brief Constructor.
48    *
49    * This will create all the controls and add them to the stage so should only be called after the init-signal from the Application has been received.
50    *
51    * @param[in]  contactCardLayoutInfo  Reference to the common data used by all contact cards.
52    * @param[in]  contactName            The name of the contact to display.
53    * @param[in]  contactAddress         The address of the contact to display.
54    * @param[in]  imagePath              The path to the image to display.
55    * @param[in]  position               The unique folded position of this particular contact-card.
56    */
57   ContactCard( const ContactCardLayoutInfo& contactCardLayoutInfo, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath, const Dali::Vector2& position );
58
59 private:
60
61   /**
62    * @brief Private Destructor. Will only be deleted when ref-count goes to 0.
63    *
64    * Unparent the created contact card (i.e. remove from stage).
65    */
66   ~ContactCard();
67
68   /**
69    * @brief Called when this contact card is tapped.
70    * @param[in] actor The tapped actor.
71    * @param[in] gesture The tap gesture.
72    */
73   void OnTap( Dali::Actor actor, const Dali::TapGesture& gesture );
74
75   /**
76    * @brief Called when the animation finishes.
77    * @param[in] animation The animation which has just finished.
78    */
79   void OnAnimationFinished( Dali::Animation& animation );
80
81   Dali::TapGestureDetector mTapDetector; ///< Used for tap detection.
82   Dali::Toolkit::Control mContactCard; ///< Used for the background and to clip the contents.
83   Dali::Toolkit::Control mHeader; ///< Header shown when unfolded.
84   Dali::Toolkit::Control mClippedImage; ///< The image representing the contact (whose clipping can be animated).
85   Dali::Toolkit::Control mNameText; ///< The text shown when folded.
86   Dali::Toolkit::Control mDetailText; ///< The text shown when unfolded.
87
88   Dali::SlotDelegate< ContactCard > mSlotDelegate; ///< Used to automatically disconnect our member functions from signals that this class connects to upon destruction. Can be used instead of inheriting from ConnectionTracker.
89
90   const ContactCardLayoutInfo& mContactCardLayoutInfo; ///< Reference to the common data used by all contact cards.
91   const Dali::Vector2 foldedPosition; ///< The unique position of this card when it is folded.
92   Dali::Property::Index mClippedImagePropertyIndex; ///< Index used to animate the clipping of mClippedImage.
93   bool mFolded; ///< Whether the contact card is folded or not.
94 };
95
96 #endif // CONTACT_CARD_H