Fixed DGEUF-1841.
[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) 2020 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/adaptor-framework/window.h>
25 #include <dali/public-api/animation/animation.h>
26 #include <dali/public-api/events/tap-gesture-detector.h>
27 #include <dali/public-api/object/ref-object.h>
28 #include <dali-toolkit/public-api/controls/control.h>
29
30 struct ContactCardLayoutInfo;
31
32 /**
33  * @brief Creates and sets up animations for a contact card
34  *
35  * Each contact card has two states, folded and unfolded.
36  * In this context, "unfolded" means when all the details, including the name, address and image are shown.
37  * In this scenario, the control takes up most of the screen.
38  *
39  * When the contact card is "folded", this means when only brief information is shown to the user, i.e. the image and name.
40  * In this scenario, the control is small and there should be several of these contact cards visible on the screen.
41  *
42  * The contact card creates several controls that it requires to appropriately display itself in both of these states.
43  */
44 class ContactCard : public Dali::RefObject
45 {
46 public:
47
48   /**
49    * @brief Constructor.
50    *
51    * This will create all the controls and add them to the window so should only be called after the init-signal from the Application has been received.
52    *
53    * @param[in]  window                 The window to add the contact card to.
54    * @param[in]  contactCardLayoutInfo  Reference to the common data used by all contact cards.
55    * @param[in]  contactName            The name of the contact to display.
56    * @param[in]  contactAddress         The address of the contact to display.
57    * @param[in]  imagePath              The path to the image to display.
58    * @param[in]  position               The unique folded position of this particular contact-card.
59    */
60   ContactCard( Dali::Window window, const ContactCardLayoutInfo& contactCardLayoutInfo, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath, const Dali::Vector2& position );
61
62 private:
63
64   /**
65    * @brief Private Destructor. Will only be deleted when ref-count goes to 0.
66    *
67    * Unparent the created contact card (i.e. remove from window).
68    */
69   ~ContactCard();
70
71   /**
72    * @brief Called when this contact card is tapped.
73    * @param[in]  actor    The tapped actor.
74    * @param[in]  gesture  The tap gesture.
75    */
76   void OnTap( Dali::Actor actor, const Dali::TapGesture& gesture );
77
78   /**
79    * @brief Animates the fold/unfold animation as required.
80    */
81   void Animate();
82
83   /**
84    * @brief Called when the animation finishes.
85    * @param[in]  animation  The animation which has just finished.
86    */
87   void OnAnimationFinished( Dali::Animation& animation );
88
89   /**
90    * @brief Called when any key event is received
91    *
92    * Will use this to fold a contact card if it is unfolded.
93    * @param[in]  event  The key event information
94    */
95   void OnKeyEvent( const Dali::KeyEvent& event );
96
97   Dali::TapGestureDetector mTapDetector; ///< Used for tap detection.
98   Dali::Toolkit::Control mContactCard; ///< Used for the background and to clip the contents.
99   Dali::Toolkit::Control mHeader; ///< Header shown when unfolded.
100   Dali::Toolkit::Control mClippedImage; ///< The image representing the contact (whose clipping can be animated).
101   Dali::Toolkit::Control mMaskedImage; ///< The image with a mask (better quality around the edges than the clipped image when folded).
102   Dali::Toolkit::Control mNameText; ///< The text shown when folded.
103   Dali::Toolkit::Control mDetailText; ///< The text shown when unfolded.
104
105   Dali::Animation mAnimation; ///< The fold/unfold animation.
106
107   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.
108
109   const ContactCardLayoutInfo& mContactCardLayoutInfo; ///< Reference to the common data used by all contact cards.
110   const Dali::Vector2 foldedPosition; ///< The unique position of this card when it is folded.
111   Dali::Property::Index mClippedImagePropertyIndex; ///< Index used to animate the clipping of mClippedImage.
112   bool mFolded; ///< Whether the contact card is folded or not.
113 };
114
115 #endif // CONTACT_CARD_H