summaryrefslogtreecommitdiff
path: root/indra/newview/llinventorygallery.h
blob: 02e706eecd8b979e23982d9fe5b53df06919ce6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/**
 * @file llinventorygallery.h
 * @brief LLInventoryGallery class definition
 *
 * $LicenseInfo:firstyear=2023&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2023, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#ifndef LL_LLINVENTORYGALLERY_H
#define LL_LLINVENTORYGALLERY_H

#include "lllistcontextmenu.h"
#include "llpanel.h"
#include "llinventoryfilter.h"
#include "llinventorymodel.h"

class LLInventoryCategoriesObserver;
class LLInventoryGalleryItem;
class LLScrollContainer;
class LLTextBox;

class LLInventoryGalleryContextMenu;

class LLInventoryGallery : public LLPanel
{
public:

    typedef boost::signals2::signal<void(const LLUUID&)> selection_change_signal_t;
    typedef boost::function<void(const LLUUID&)> selection_change_callback_t;

    struct Params
        : public LLInitParam::Block<Params, LLPanel::Params>
    {
        Optional<S32>   row_panel_height;
        Optional<S32>   row_panel_width_factor;
        Optional<S32>   gallery_width_factor;
        Optional<S32>   vertical_gap;
        Optional<S32>   horizontal_gap;
        Optional<S32>   item_width;
        Optional<S32>   item_height;
        Optional<S32>   item_horizontal_gap;
        Optional<S32>   items_in_row;

        Params();
    };

    static const LLInventoryGallery::Params& getDefaultParams();

    LLInventoryGallery(const LLInventoryGallery::Params& params = getDefaultParams());
    ~LLInventoryGallery();

    BOOL postBuild();
    void initGallery();
    void draw();
    BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type,
                           void* cargo_data, EAcceptance* accept, std::string& tooltip_msg);

    void setFilterSubString(const std::string& string);
    std::string getFilterSubString() { return mFilterSubString; }

    void getCurrentCategories(uuid_vec_t& vcur);
    void updateAddedItem(LLUUID item_id);
    void updateRemovedItem(LLUUID item_id);
    void updateChangedItemName(LLUUID item_id, std::string name);
    void updateItemThumbnail(LLUUID item_id);

    void updateMessageVisibility();

    void setRootFolder(const LLUUID cat_id);
    void updateRootFolder();
    LLUUID getRootFolder() { return mFolderID; }
    typedef boost::function<void()> root_changed_callback_t;
    boost::signals2::connection setRootChangedCallback(root_changed_callback_t cb);
    void onForwardFolder();
    void onBackwardFolder();
    void clearNavigationHistory();
    bool isBackwardAvailable();
    bool isForwardAvailable();

    void setNavBackwardList(std::list<LLUUID> backward_list) { mBackwardFolders = backward_list; }
    void setNavForwardList(std::list<LLUUID> forward_list) { mForwardFolders = forward_list; }
    std::list<LLUUID> getNavBackwardList() { return mBackwardFolders; }
    std::list<LLUUID> getNavForwardList() { return mForwardFolders; }

    LLUUID getOutfitImageID(LLUUID outfit_id);

    void refreshList(const LLUUID& category_id);
    void computeDifference(const LLInventoryModel::cat_array_t vcats, const LLInventoryModel::item_array_t vitems, uuid_vec_t& vadded, uuid_vec_t& vremoved);

    void deselectItem(const LLUUID& category_id);
    void signalSelectionItemID(const LLUUID& category_id);
    boost::signals2::connection setSelectionChangeCallback(selection_change_callback_t cb);

    void setSearchType(LLInventoryFilter::ESearchType type);
    LLInventoryFilter::ESearchType getSearchType() { return mSearchType; }
    void toggleSearchLinks();
    bool getSearchLinks(){ return mSearchLinks; }

protected:

    void onChangeItemSelection(const LLUUID& category_id);
    void showContextMenu(LLUICtrl* ctrl, S32 x, S32 y, const LLUUID& item_id);

    void applyFilter(LLInventoryGalleryItem* item, const std::string& filter_substring);

    LLInventoryCategoriesObserver*     mCategoriesObserver;
    LLUUID                             mSelectedItemID;
    bool                               mIsInitialized;

    selection_change_signal_t        mSelectionChangeSignal;
    boost::signals2::signal<void()>  mRootChangedSignal;
    LLUUID mFolderID;
    std::list<LLUUID> mBackwardFolders;
    std::list<LLUUID> mForwardFolders;

private:
    void addToGallery(LLInventoryGalleryItem* item);
    void removeFromGalleryLast(LLInventoryGalleryItem* item);
    void removeFromGalleryMiddle(LLInventoryGalleryItem* item);
    LLPanel* addLastRow();
    void removeLastRow();
    void moveRowUp(int row);
    void moveRowDown(int row);
    void moveRow(int row, int pos);
    LLPanel* addToRow(LLPanel* row_stack, LLInventoryGalleryItem* item, int pos, int hgap);
    void removeFromLastRow(LLInventoryGalleryItem* item);
    void reArrangeRows(S32 row_diff = 0);
    void updateRowsIfNeeded();
    void updateGalleryWidth();

    LLInventoryGalleryItem* buildGalleryItem(std::string name, LLUUID item_id, LLAssetType::EType type, LLUUID thumbnail_id, LLInventoryType::EType inventory_type, U32 flags, bool is_link);

    void buildGalleryPanel(int row_count);
    void reshapeGalleryPanel(int row_count);
    LLPanel* buildItemPanel(int left);
    LLPanel* buildRowPanel(int left, int bottom);
    void moveRowPanel(LLPanel* stack, int left, int bottom);

    std::vector<LLPanel*> mRowPanels;
    std::vector<LLPanel*> mItemPanels;
    std::vector<LLPanel*> mUnusedRowPanels;
    std::vector<LLPanel*> mUnusedItemPanels;
    std::vector<LLInventoryGalleryItem*> mItems;
    std::vector<LLInventoryGalleryItem*> mHiddenItems;
    LLScrollContainer* mScrollPanel;
    LLPanel* mGalleryPanel;
    LLPanel* mLastRowPanel;
    LLTextBox* mMessageTextBox;
    int mRowCount;
    int mItemsAddedCount;
    bool mGalleryCreated;

    /* Params */
    int mRowPanelHeight;
    int mVerticalGap;
    int mHorizontalGap;
    int mItemWidth;
    int mItemHeight;
    int mItemHorizontalGap;
    int mItemsInRow;
    int mRowPanelWidth;
    int mGalleryWidth;
    int mRowPanWidthFactor;
    int mGalleryWidthFactor;

    LLInventoryGalleryContextMenu* mInventoryGalleryMenu;
    std::string mFilterSubString;

    typedef std::map<LLUUID, LLInventoryGalleryItem*> gallery_item_map_t;
    gallery_item_map_t mItemMap;
    std::map<LLInventoryGalleryItem*, S32> mItemIndexMap;

    LLInventoryFilter::ESearchType mSearchType;
    bool mSearchLinks;
};

class LLInventoryGalleryItem : public LLPanel
{
public:
    struct Params : public LLInitParam::Block<Params, LLPanel::Params>
    {};

    enum EInventorySortGroup
    {
        SG_SYSTEM_FOLDER,
        SG_TRASH_FOLDER,
        SG_NORMAL_FOLDER,
        SG_ITEM
    };

    LLInventoryGalleryItem(const Params& p);
    virtual ~LLInventoryGalleryItem();

    BOOL postBuild();
    void draw();
    BOOL handleMouseDown(S32 x, S32 y, MASK mask);
    BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
    BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
    BOOL handleMouseUp(S32 x, S32 y, MASK mask);
    BOOL handleHover(S32 x, S32 y, MASK mask);
    BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
                                   EDragAndDropType cargo_type,
                                   void* cargo_data,
                                   EAcceptance* accept,
                                   std::string& tooltip_msg);

    void setName(std::string name);
    void setSelected(bool value);
    void setUUID(LLUUID id) {mUUID = id;}
    LLUUID getUUID() { return mUUID;}

    void setAssetIDStr(std::string asset_id) {mAssetIDStr = asset_id;}
    std::string getAssetIDStr() { return mAssetIDStr;}
    void setDescription(std::string desc) {mDesc = desc;}
    std::string getDescription() { return mDesc;}
    void setCreatorName(std::string name) {mCreatorName = name;}
    std::string getCreatorName() { return mCreatorName;}

    std::string getItemName() {return mName;}
    bool isDefaultImage() {return mDefaultImage;}
    
    bool isHidden() {return mHidden;}
    void setHidden(bool hidden) {mHidden = hidden;}

    void setType(LLAssetType::EType type, LLInventoryType::EType inventory_type, U32 flags, bool is_link);
    void setThumbnail(LLUUID id);
    void setGallery(LLInventoryGallery* gallery) { mGallery = gallery; }
    bool isFolder() { return mIsFolder; }
    bool isLink() { return mIsLink; }
    EInventorySortGroup getSortGroup() { return mSortGroup; }
    
private:
    LLUUID mUUID;
    LLTextBox* mNameText;
    LLPanel* mTextBgPanel;
    bool     mSelected;
    bool     mDefaultImage;
    bool     mHidden;
    bool     mIsFolder;
    bool     mIsLink;

    std::string mAssetIDStr;
    std::string mDesc;
    std::string mCreatorName;

    EInventorySortGroup mSortGroup;
    LLAssetType::EType mType;
    std::string mName;
    LLInventoryGallery* mGallery;
};

#endif