PageRenderTime 50ms CodeModel.GetById 14ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llinventorylistitem.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 238 lines | 89 code | 51 blank | 98 comment | 0 complexity | 0e751a7dc151f83207be1f997f0acada MD5 | raw file
  1/**
  2 * @file llinventorylistitem.h
  3 * @brief Inventory list item panel.
  4 *
  5 * Class LLPanelInventoryListItemBase displays inventory item as an element
  6 * of LLInventoryItemsList.
  7 *
  8 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  9 * Second Life Viewer Source Code
 10 * Copyright (C) 2010, Linden Research, Inc.
 11 * 
 12 * This library is free software; you can redistribute it and/or
 13 * modify it under the terms of the GNU Lesser General Public
 14 * License as published by the Free Software Foundation;
 15 * version 2.1 of the License only.
 16 * 
 17 * This library is distributed in the hope that it will be useful,
 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 20 * Lesser General Public License for more details.
 21 * 
 22 * You should have received a copy of the GNU Lesser General Public
 23 * License along with this library; if not, write to the Free Software
 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 25 * 
 26 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 27 * $/LicenseInfo$
 28 */
 29
 30#ifndef LL_LLINVENTORYLISTITEM_H
 31#define LL_LLINVENTORYLISTITEM_H
 32
 33// llcommon
 34#include "llassettype.h"
 35
 36// llui
 37#include "llpanel.h"
 38#include "llstyle.h"
 39#include "lliconctrl.h"
 40#include "lltextbox.h"
 41
 42// newview
 43#include "llwearabletype.h"
 44
 45class LLViewerInventoryItem;
 46
 47/**
 48 * @class LLPanelInventoryListItemBase
 49 *
 50 * Base class for Inventory flat list item. Panel consists of inventory icon
 51 * and inventory item name.
 52 * This class is able to display widgets(buttons) on left(before icon) and right(after text-box) sides 
 53 * of panel.
 54 *
 55 * How to use (see LLPanelClothingListItem for example):
 56 * - implement init() to build panel from xml
 57 * - create new xml file, fill it with widgets you want to dynamically show/hide/reshape on left/right sides
 58 * - redefine postBuild()(call base implementation) and add needed widgets to needed sides,
 59 *
 60 */
 61class LLPanelInventoryListItemBase : public LLPanel
 62{
 63public:
 64	struct Params : public LLInitParam::Block<Params, LLPanel::Params>
 65	{
 66		Optional<LLStyle::Params>	default_style,
 67									worn_style;
 68		Optional<LLUIImage*>		hover_image,
 69									selected_image,
 70									separator_image;
 71		Optional<LLIconCtrl::Params>	item_icon;
 72		Optional<LLTextBox::Params>		item_name;
 73		Params();
 74	};
 75
 76	typedef enum e_item_state {
 77		IS_DEFAULT,
 78		IS_WORN,
 79	} EItemState;
 80
 81	static LLPanelInventoryListItemBase* create(LLViewerInventoryItem* item);
 82
 83	virtual void draw();
 84
 85	/**
 86	 * Let item know it need to be refreshed in next draw()
 87	 */
 88	void setNeedsRefresh(bool needs_refresh){ mNeedsRefresh = needs_refresh; }
 89
 90	bool getNeedsRefresh(){ return mNeedsRefresh; }
 91
 92	/**
 93	 * Add widget to left side
 94	 */
 95	void addWidgetToLeftSide(const std::string& name, bool show_widget = true);
 96	void addWidgetToLeftSide(LLUICtrl* ctrl, bool show_widget = true);
 97
 98	/**
 99	 * Add widget to right side, widget is supposed to be child of calling panel
100	 */
101	void addWidgetToRightSide(const std::string& name, bool show_widget = true);
102	void addWidgetToRightSide(LLUICtrl* ctrl, bool show_widget = true);
103
104	/**
105	 * Mark widgets as visible. Only visible widgets take part in reshaping children
106	 */
107	void setShowWidget(const std::string& name, bool show);
108	void setShowWidget(LLUICtrl* ctrl, bool show);
109
110	/**
111	 * Set spacing between widgets during reshape
112	 */
113	void setWidgetSpacing(S32 spacing) { mWidgetSpacing = spacing; }
114
115	S32 getWidgetSpacing() { return mWidgetSpacing; }
116
117	/**
118	 * Inheritors need to call base implementation of postBuild()
119	 */
120	/*virtual*/ BOOL postBuild();
121
122	/**
123	 * Handles item selection
124	 */
125	/*virtual*/ void setValue(const LLSD& value);
126
127	/**
128	 * Handles filter request
129	 */
130	/*virtual*/ S32  notify(const LLSD& info);
131
132	 /* Highlights item */
133	/*virtual*/ void onMouseEnter(S32 x, S32 y, MASK mask);
134	/* Removes item highlight */
135	/*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask);
136
137	/** Get the name of a corresponding inventory item */
138	const std::string& getItemName() const;
139
140	/** Get the asset type of a corresponding inventory item */
141	LLAssetType::EType getType() const;
142
143	/** Get the wearable type of a corresponding inventory item */
144	LLWearableType::EType getWearableType() const;
145
146	/** Get the description of a corresponding inventory item */
147	const std::string& getDescription() const;
148
149	/** Get the creation date of a corresponding inventory item */
150	time_t getCreationDate() const;
151
152	/** Get the associated inventory item */
153	LLViewerInventoryItem* getItem() const;
154
155	void setSeparatorVisible(bool visible) { mSeparatorVisible = visible; }
156
157	virtual ~LLPanelInventoryListItemBase(){}
158
159protected:
160
161	LLPanelInventoryListItemBase(LLViewerInventoryItem* item, const Params& params);
162
163	typedef std::vector<LLUICtrl*> widget_array_t;
164
165	/**
166	 * Called after inventory item was updated, update panel widgets to reflect inventory changes.
167	 */
168	virtual void updateItem(const std::string& name,
169							EItemState item_state = IS_DEFAULT);
170
171	void setLeftWidgetsWidth(S32 width) { mLeftWidgetsWidth = width; }
172	void setRightWidgetsWidth(S32 width) { mRightWidgetsWidth = width; }
173
174	/**
175	 * Set all widgets from both side visible/invisible. Only enabled widgets
176	 * (see setShowWidget()) can become visible
177	 */
178	virtual void setWidgetsVisible(bool visible);
179
180	/**
181	 * Reshape all child widgets - icon, text-box and side widgets
182	 */
183	virtual void reshapeWidgets();
184
185	/** set wearable type icon image */
186	void setIconImage(const LLUIImagePtr& image);
187
188	/** Set item title - inventory item name usually */
189	void setTitle(const std::string& title,
190				  const std::string& highlit_text,
191				  EItemState item_state = IS_DEFAULT);
192
193	/**
194	 * Show tool tip if item name text size > panel size
195	 */
196	virtual BOOL handleToolTip( S32 x, S32 y, MASK mask);
197
198	const LLUUID mInventoryItemUUID;
199
200private:
201
202	/** reshape left side widgets
203	 * Deprecated for now. Disabled reshape left for now to reserve space for 'delete' 
204	 * button in LLPanelClothingListItem according to Neal's comment (https://codereview.productengine.com/secondlife/r/325/)
205	 */
206	void reshapeLeftWidgets();
207
208	/** reshape right side widgets */
209	void reshapeRightWidgets();
210
211	/** reshape remaining widgets */
212	void reshapeMiddleWidgets();
213
214
215	LLIconCtrl*		mIconCtrl;
216	LLTextBox*		mTitleCtrl;
217
218	LLUIImagePtr	mIconImage;
219	LLUIImagePtr	mHoverImage;
220	LLUIImagePtr	mSelectedImage;
221	LLUIImagePtr	mSeparatorImage;
222
223	bool			mHovered;
224	bool			mSelected;
225	bool			mSeparatorVisible;
226
227	std::string		mHighlightedText;
228
229	widget_array_t	mLeftSideWidgets;
230	widget_array_t	mRightSideWidgets;
231	S32				mWidgetSpacing;
232
233	S32				mLeftWidgetsWidth;
234	S32				mRightWidgetsWidth;
235	bool			mNeedsRefresh;
236};
237
238#endif //LL_LLINVENTORYLISTITEM_H