PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLINVENTORYLISTITEM_H
  30. #define LL_LLINVENTORYLISTITEM_H
  31. // llcommon
  32. #include "llassettype.h"
  33. // llui
  34. #include "llpanel.h"
  35. #include "llstyle.h"
  36. #include "lliconctrl.h"
  37. #include "lltextbox.h"
  38. // newview
  39. #include "llwearabletype.h"
  40. class LLViewerInventoryItem;
  41. /**
  42. * @class LLPanelInventoryListItemBase
  43. *
  44. * Base class for Inventory flat list item. Panel consists of inventory icon
  45. * and inventory item name.
  46. * This class is able to display widgets(buttons) on left(before icon) and right(after text-box) sides
  47. * of panel.
  48. *
  49. * How to use (see LLPanelClothingListItem for example):
  50. * - implement init() to build panel from xml
  51. * - create new xml file, fill it with widgets you want to dynamically show/hide/reshape on left/right sides
  52. * - redefine postBuild()(call base implementation) and add needed widgets to needed sides,
  53. *
  54. */
  55. class LLPanelInventoryListItemBase : public LLPanel
  56. {
  57. public:
  58. struct Params : public LLInitParam::Block<Params, LLPanel::Params>
  59. {
  60. Optional<LLStyle::Params> default_style,
  61. worn_style;
  62. Optional<LLUIImage*> hover_image,
  63. selected_image,
  64. separator_image;
  65. Optional<LLIconCtrl::Params> item_icon;
  66. Optional<LLTextBox::Params> item_name;
  67. Params();
  68. };
  69. typedef enum e_item_state {
  70. IS_DEFAULT,
  71. IS_WORN,
  72. } EItemState;
  73. static LLPanelInventoryListItemBase* create(LLViewerInventoryItem* item);
  74. virtual void draw();
  75. /**
  76. * Let item know it need to be refreshed in next draw()
  77. */
  78. void setNeedsRefresh(bool needs_refresh){ mNeedsRefresh = needs_refresh; }
  79. bool getNeedsRefresh(){ return mNeedsRefresh; }
  80. /**
  81. * Add widget to left side
  82. */
  83. void addWidgetToLeftSide(const std::string& name, bool show_widget = true);
  84. void addWidgetToLeftSide(LLUICtrl* ctrl, bool show_widget = true);
  85. /**
  86. * Add widget to right side, widget is supposed to be child of calling panel
  87. */
  88. void addWidgetToRightSide(const std::string& name, bool show_widget = true);
  89. void addWidgetToRightSide(LLUICtrl* ctrl, bool show_widget = true);
  90. /**
  91. * Mark widgets as visible. Only visible widgets take part in reshaping children
  92. */
  93. void setShowWidget(const std::string& name, bool show);
  94. void setShowWidget(LLUICtrl* ctrl, bool show);
  95. /**
  96. * Set spacing between widgets during reshape
  97. */
  98. void setWidgetSpacing(S32 spacing) { mWidgetSpacing = spacing; }
  99. S32 getWidgetSpacing() { return mWidgetSpacing; }
  100. /**
  101. * Inheritors need to call base implementation of postBuild()
  102. */
  103. /*virtual*/ BOOL postBuild();
  104. /**
  105. * Handles item selection
  106. */
  107. /*virtual*/ void setValue(const LLSD& value);
  108. /**
  109. * Handles filter request
  110. */
  111. /*virtual*/ S32 notify(const LLSD& info);
  112. /* Highlights item */
  113. /*virtual*/ void onMouseEnter(S32 x, S32 y, MASK mask);
  114. /* Removes item highlight */
  115. /*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask);
  116. /** Get the name of a corresponding inventory item */
  117. const std::string& getItemName() const;
  118. /** Get the asset type of a corresponding inventory item */
  119. LLAssetType::EType getType() const;
  120. /** Get the wearable type of a corresponding inventory item */
  121. LLWearableType::EType getWearableType() const;
  122. /** Get the description of a corresponding inventory item */
  123. const std::string& getDescription() const;
  124. /** Get the creation date of a corresponding inventory item */
  125. time_t getCreationDate() const;
  126. /** Get the associated inventory item */
  127. LLViewerInventoryItem* getItem() const;
  128. void setSeparatorVisible(bool visible) { mSeparatorVisible = visible; }
  129. virtual ~LLPanelInventoryListItemBase(){}
  130. protected:
  131. LLPanelInventoryListItemBase(LLViewerInventoryItem* item, const Params& params);
  132. typedef std::vector<LLUICtrl*> widget_array_t;
  133. /**
  134. * Called after inventory item was updated, update panel widgets to reflect inventory changes.
  135. */
  136. virtual void updateItem(const std::string& name,
  137. EItemState item_state = IS_DEFAULT);
  138. void setLeftWidgetsWidth(S32 width) { mLeftWidgetsWidth = width; }
  139. void setRightWidgetsWidth(S32 width) { mRightWidgetsWidth = width; }
  140. /**
  141. * Set all widgets from both side visible/invisible. Only enabled widgets
  142. * (see setShowWidget()) can become visible
  143. */
  144. virtual void setWidgetsVisible(bool visible);
  145. /**
  146. * Reshape all child widgets - icon, text-box and side widgets
  147. */
  148. virtual void reshapeWidgets();
  149. /** set wearable type icon image */
  150. void setIconImage(const LLUIImagePtr& image);
  151. /** Set item title - inventory item name usually */
  152. void setTitle(const std::string& title,
  153. const std::string& highlit_text,
  154. EItemState item_state = IS_DEFAULT);
  155. /**
  156. * Show tool tip if item name text size > panel size
  157. */
  158. virtual BOOL handleToolTip( S32 x, S32 y, MASK mask);
  159. const LLUUID mInventoryItemUUID;
  160. private:
  161. /** reshape left side widgets
  162. * Deprecated for now. Disabled reshape left for now to reserve space for 'delete'
  163. * button in LLPanelClothingListItem according to Neal's comment (https://codereview.productengine.com/secondlife/r/325/)
  164. */
  165. void reshapeLeftWidgets();
  166. /** reshape right side widgets */
  167. void reshapeRightWidgets();
  168. /** reshape remaining widgets */
  169. void reshapeMiddleWidgets();
  170. LLIconCtrl* mIconCtrl;
  171. LLTextBox* mTitleCtrl;
  172. LLUIImagePtr mIconImage;
  173. LLUIImagePtr mHoverImage;
  174. LLUIImagePtr mSelectedImage;
  175. LLUIImagePtr mSeparatorImage;
  176. bool mHovered;
  177. bool mSelected;
  178. bool mSeparatorVisible;
  179. std::string mHighlightedText;
  180. widget_array_t mLeftSideWidgets;
  181. widget_array_t mRightSideWidgets;
  182. S32 mWidgetSpacing;
  183. S32 mLeftWidgetsWidth;
  184. S32 mRightWidgetsWidth;
  185. bool mNeedsRefresh;
  186. };
  187. #endif //LL_LLINVENTORYLISTITEM_H