llpreview.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**
  2. * @file llpreview.h
  3. * @brief LLPreview class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLPREVIEW_H
  33. #define LL_LLPREVIEW_H
  34. #include <map> // For multimap
  35. #include "llfloater.h"
  36. #include "llresizehandle.h"
  37. #include "lltabcontainer.h"
  38. #include "llinventorymodel.h"
  39. #include "llviewerinventory.h"
  40. class LLLineEditor;
  41. class LLRadioGroup;
  42. class LLPreview;
  43. class LLMultiPreview : public LLMultiFloater
  44. {
  45. public:
  46. LLMultiPreview(const LLRect& rect);
  47. void open() override;
  48. void tabOpen(LLFloater* opened_floater, bool from_click) override;
  49. void userSetShape(const LLRect& new_rect) override;
  50. static LLMultiPreview* getAutoOpenInstance(const LLUUID& id);
  51. static void setAutoOpenInstance(LLMultiPreview* previewp,
  52. const LLUUID& id);
  53. protected:
  54. typedef fast_hmap<LLUUID, LLHandle<LLFloater> > handle_map_t;
  55. static handle_map_t sAutoOpenPreviewHandles;
  56. };
  57. class LLPreview : public LLFloater, LLInventoryObserver
  58. {
  59. protected:
  60. LOG_CLASS(LLPreview);
  61. public:
  62. typedef enum e_asset_status
  63. {
  64. PREVIEW_ASSET_ERROR,
  65. PREVIEW_ASSET_UNLOADED,
  66. PREVIEW_ASSET_LOADING,
  67. PREVIEW_ASSET_LOADED
  68. } EAssetStatus;
  69. // Used for XML-based construction.
  70. LLPreview(const std::string& name);
  71. LLPreview(const std::string& name, const LLRect& rect,
  72. const std::string& title, const LLUUID& item_uuid,
  73. const LLUUID& object_uuid, bool allow_resize = false,
  74. S32 min_width = 0, S32 min_height = 0,
  75. LLPointer<LLViewerInventoryItem> inv_item = NULL);
  76. ~LLPreview() override;
  77. LL_INLINE virtual void setObjectID(const LLUUID& object_id)
  78. {
  79. mObjectUUID = object_id;
  80. }
  81. virtual void setItemID(const LLUUID& item_id);
  82. void setAssetId(const LLUUID& asset_id);
  83. // Searches if not constructed with it
  84. const LLViewerInventoryItem* getItem() const;
  85. static LLPreview* find(const LLUUID& item_uuid);
  86. static LLPreview* show(const LLUUID& item_uuid, bool take_focus = true);
  87. static void hide(const LLUUID& item_uuid, bool no_saving = false);
  88. static void rename(const LLUUID& item_uuid, const std::string& new_name);
  89. static bool save(const LLUUID& item_uuid,
  90. LLPointer<LLInventoryItem>* itemptr);
  91. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  92. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  93. bool handleHover(S32 x, S32 y, MASK mask) override;
  94. void open() override;
  95. virtual bool saveItem(LLPointer<LLInventoryItem>* itemptr);
  96. virtual void setAuxItem(const LLInventoryItem* itemp);
  97. static void onBtnCopyToInv(void* userdata);
  98. void addKeepDiscardButtons();
  99. static void onKeepBtn(void* data);
  100. static void onDiscardBtn(void* data);
  101. void userSetShape(const LLRect& new_rect) override;
  102. void userResized() { mUserResized = true; };
  103. virtual void loadAsset() { mAssetStatus = PREVIEW_ASSET_LOADED; }
  104. virtual EAssetStatus getAssetStatus() { return mAssetStatus;}
  105. void setNotecardInfo(const LLUUID& notecard_inv_id,
  106. const LLUUID& object_id);
  107. void draw() override;
  108. virtual void refreshFromItem();
  109. // We cannot modify item or description in preview if either in-world object
  110. // or item itself is unmodifiable.
  111. static bool canModify(const LLUUID& task_id, const LLInventoryItem* itemp);
  112. protected:
  113. void onCommit() override;
  114. void addDescriptionUI();
  115. static void onText(LLUICtrl*, void* userdata);
  116. static void onRadio(LLUICtrl*, void* userdata);
  117. // LLInventoryObserver override
  118. void changed(U32 mask) override;
  119. virtual const char* getTitleName() const { return "Preview"; }
  120. protected:
  121. LLUUID mItemUUID;
  122. // mObjectID will have a value if it is associated with a rezzed object
  123. // (task), and will be LLUUID::null if it is in the agent inventory.
  124. LLUUID mObjectUUID;
  125. LLRect mClientRect;
  126. LLPointer<LLInventoryItem> mAuxItem; // HACK!
  127. LLButton* mCopyToInvBtn;
  128. // Close without saving changes
  129. bool mForceClose;
  130. bool mDirty;
  131. bool mUserResized;
  132. // When closing springs a "Want to save ?" dialog, we want to keep the
  133. // preview open until the save completes.
  134. bool mCloseAfterSave;
  135. // True if the save changes confirmation dialog was already shown
  136. bool mSaveDialogShown;
  137. EAssetStatus mAssetStatus;
  138. typedef fast_hmap<LLUUID, LLPreview*> preview_map_t;
  139. static preview_map_t sInstances;
  140. LLUUID mNotecardInventoryID;
  141. LLUUID mObjectID;
  142. LLPointer<LLViewerInventoryItem> mItem;
  143. };
  144. constexpr S32 PREVIEW_BORDER = 4;
  145. constexpr S32 PREVIEW_PAD = 5;
  146. constexpr S32 PREVIEW_BUTTON_WIDTH = 100;
  147. constexpr S32 PREVIEW_LINE_HEIGHT = 19;
  148. constexpr S32 PREVIEW_CLOSE_BOX_SIZE = 16;
  149. constexpr S32 PREVIEW_BORDER_WIDTH = 2;
  150. constexpr S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) +
  151. PREVIEW_BORDER_WIDTH;
  152. constexpr S32 PREVIEW_VPAD = 2;
  153. constexpr S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
  154. constexpr S32 PREVIEW_HEADER_SIZE = 2 * PREVIEW_LINE_HEIGHT + 2 * PREVIEW_VPAD;
  155. #endif // LL_LLPREVIEW_H