PageRenderTime 31ms CodeModel.GetById 1ms app.highlight 24ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llavatarlistitem.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 232 lines | 114 code | 37 blank | 81 comment | 0 complexity | e810baad14463918ee3b2b0413c2837f MD5 | raw file
  1/** 
  2 * @file llavatarlistitem.h
  3 * @brief avatar list item header file
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLAVATARLISTITEM_H
 28#define LL_LLAVATARLISTITEM_H
 29
 30#include "llpanel.h"
 31#include "lloutputmonitorctrl.h"
 32#include "llbutton.h"
 33#include "lltextbox.h"
 34#include "llstyle.h"
 35
 36#include "llcallingcard.h" // for LLFriendObserver
 37
 38class LLAvatarIconCtrl;
 39class LLAvatarName;
 40class LLIconCtrl;
 41
 42class LLAvatarListItem : public LLPanel, public LLFriendObserver
 43{
 44public:
 45	struct Params : public LLInitParam::Block<Params, LLPanel::Params>
 46	{
 47		Optional<LLStyle::Params>	default_style,
 48									voice_call_invited_style,
 49									voice_call_joined_style,
 50									voice_call_left_style,
 51									online_style,
 52									offline_style;
 53
 54		Optional<S32>				name_right_pad;
 55
 56		Params();
 57	};
 58
 59	typedef enum e_item_state_type {
 60		IS_DEFAULT,
 61		IS_VOICE_INVITED,
 62		IS_VOICE_JOINED,
 63		IS_VOICE_LEFT,
 64		IS_ONLINE,
 65		IS_OFFLINE,
 66	} EItemState;
 67
 68	/**
 69	 * Creates an instance of LLAvatarListItem.
 70	 *
 71	 * It is not registered with LLDefaultChildRegistry. It is built via LLUICtrlFactory::buildPanel
 72	 * or via registered LLCallbackMap depend on passed parameter.
 73	 * 
 74	 * @param not_from_ui_factory if true instance will be build with LLUICtrlFactory::buildPanel 
 75	 * otherwise it should be registered via LLCallbackMap before creating.
 76	 */
 77	LLAvatarListItem(bool not_from_ui_factory = true);
 78	virtual ~LLAvatarListItem();
 79
 80	virtual BOOL postBuild();
 81
 82	/**
 83	 * Processes notification from speaker indicator to update children when indicator's visibility is changed.
 84	 */
 85	virtual S32	notifyParent(const LLSD& info);
 86	virtual void onMouseLeave(S32 x, S32 y, MASK mask);
 87	virtual void onMouseEnter(S32 x, S32 y, MASK mask);
 88	virtual void setValue(const LLSD& value);
 89	virtual void changed(U32 mask); // from LLFriendObserver
 90
 91	void setOnline(bool online);
 92	void updateAvatarName(); // re-query the name cache
 93	void setAvatarName(const std::string& name);
 94	void setAvatarToolTip(const std::string& tooltip);
 95	void setHighlight(const std::string& highlight);
 96	void setState(EItemState item_style);
 97	void setAvatarId(const LLUUID& id, const LLUUID& session_id, bool ignore_status_changes = false, bool is_resident = true);
 98	void setLastInteractionTime(U32 secs_since);
 99	//Show/hide profile/info btn, translating speaker indicator and avatar name coordinates accordingly
100	void setShowProfileBtn(bool show);
101	void setShowInfoBtn(bool show);
102	void showSpeakingIndicator(bool show);
103	void setShowPermissions(bool show) { mShowPermissions = show; };
104	void showLastInteractionTime(bool show);
105	void setAvatarIconVisible(bool visible);
106	
107	const LLUUID& getAvatarId() const;
108	std::string getAvatarName() const;
109	std::string getAvatarToolTip() const;
110
111	void onInfoBtnClick();
112	void onProfileBtnClick();
113
114	/*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
115
116protected:
117	/**
118	 * Contains indicator to show voice activity. 
119	 */
120	LLOutputMonitorCtrl* mSpeakingIndicator;
121
122	LLAvatarIconCtrl* mAvatarIcon;
123
124	/// Indicator for permission to see me online.
125	LLIconCtrl* mIconPermissionOnline;
126	/// Indicator for permission to see my position on the map.
127	LLIconCtrl* mIconPermissionMap;
128	/// Indicator for permission to edit my objects.
129	LLIconCtrl* mIconPermissionEditMine;
130	/// Indicator for permission to edit their objects.
131	LLIconCtrl* mIconPermissionEditTheirs;
132
133private:
134
135	typedef enum e_online_status {
136		E_OFFLINE,
137		E_ONLINE,
138		E_UNKNOWN,
139	} EOnlineStatus;
140
141	/**
142	 * Enumeration of item elements in order from right to left.
143	 * 
144	 * updateChildren() assumes that indexes are in the such order to process avatar icon easier.
145	 *
146	 * @see updateChildren()
147	 */
148	typedef enum e_avatar_item_child {
149		ALIC_SPEAKER_INDICATOR,
150		ALIC_PROFILE_BUTTON,
151		ALIC_INFO_BUTTON,
152		ALIC_PERMISSION_ONLINE,
153		ALIC_PERMISSION_MAP,
154		ALIC_PERMISSION_EDIT_MINE,
155		ALIC_PERMISSION_EDIT_THEIRS,
156		ALIC_INTERACTION_TIME,
157		ALIC_NAME,
158		ALIC_ICON,
159		ALIC_COUNT,
160	} EAvatarListItemChildIndex;
161
162	void setNameInternal(const std::string& name, const std::string& highlight);
163	void onAvatarNameCache(const LLAvatarName& av_name);
164
165	std::string formatSeconds(U32 secs);
166
167	typedef std::map<EItemState, LLColor4> icon_color_map_t;
168	static icon_color_map_t& getItemIconColorMap();
169
170	/**
171	 * Initializes widths of all children to use them while changing visibility of any of them.
172	 *
173	 * @see updateChildren()
174	 */
175	static void initChildrenWidths(LLAvatarListItem* self);
176
177	/**
178	 * Updates position and rectangle of visible children to fit all available item's width.
179	 */
180	void updateChildren();
181
182	/**
183	 * Update visibility of active permissions icons.
184	 *
185	 * Need to call updateChildren() afterwards to sort out their layout.
186	 */
187	bool showPermissions(bool visible);
188
189	/**
190	 * Gets child view specified by index.
191	 *
192	 * This method implemented via switch by all EAvatarListItemChildIndex values.
193	 * It is used to not store children in array or vector to avoid of increasing memory usage.
194	 */
195	LLView* getItemChildView(EAvatarListItemChildIndex child_index);
196
197	LLTextBox* mAvatarName;
198	LLTextBox* mLastInteractionTime;
199	LLStyle::Params mAvatarNameStyle;
200	
201	LLButton* mInfoBtn;
202	LLButton* mProfileBtn;
203
204	LLUUID mAvatarId;
205	std::string mHighlihtSubstring; // substring to highlight
206	EOnlineStatus mOnlineStatus;
207	//Flag indicating that info/profile button shouldn't be shown at all.
208	//Speaker indicator and avatar name coords are translated accordingly
209	bool mShowInfoBtn;
210	bool mShowProfileBtn;
211
212	/// indicates whether to show icons representing permissions granted
213	bool mShowPermissions;
214
215	/// true when the mouse pointer is hovering over this item
216	bool mHovered;
217
218	static bool	sStaticInitialized; // this variable is introduced to improve code readability
219	static S32  sLeftPadding; // padding to first left visible child (icon or name)
220	static S32  sNameRightPadding; // right padding from name to next visible child
221
222	/**
223	 * Contains widths of each child specified by EAvatarListItemChildIndex
224	 * including padding to the next right one.
225	 *
226	 * @see initChildrenWidths()
227	 */
228	static S32 sChildrenWidths[ALIC_COUNT];
229
230};
231
232#endif //LL_LLAVATARLISTITEM_H