1 #ifndef WINDOW_DECKEDITOR_H
2 #define WINDOW_DECKEDITOR_H
3 
4 #include "carddatabase.h"
5 #include "customlineedit.h"
6 #include "keysignals.h"
7 #include "tab.h"
8 
9 #include <QAbstractItemModel>
10 #include <QDir>
11 
12 class CardDatabaseModel;
13 class CardDatabaseDisplayModel;
14 class DeckListModel;
15 class QTreeView;
16 
17 class CardFrame;
18 class QTextEdit;
19 class QLabel;
20 class DeckLoader;
21 class Response;
22 class FilterTreeModel;
23 class FilterBuilder;
24 class QGroupBox;
25 class QHBoxLayout;
26 class QVBoxLayout;
27 class QPushButton;
28 class QDockWidget;
29 
30 class SearchLineEdit : public LineEditUnfocusable
31 {
32 private:
33     QTreeView *treeView;
34 
35 protected:
36     void keyPressEvent(QKeyEvent *event) override;
37 
38 public:
SearchLineEdit()39     SearchLineEdit() : LineEditUnfocusable(), treeView(nullptr)
40     {
41     }
setTreeView(QTreeView * _treeView)42     void setTreeView(QTreeView *_treeView)
43     {
44         treeView = _treeView;
45     }
46 };
47 
48 class TabDeckEditor : public Tab
49 {
50     Q_OBJECT
51 private slots:
52     void updateName(const QString &name);
53     void updateComments();
54     void updateHash();
55     void updateCardInfoLeft(const QModelIndex &current, const QModelIndex &previous);
56     void updateCardInfoRight(const QModelIndex &current, const QModelIndex &previous);
57     void updateSearch(const QString &search);
58     void databaseCustomMenu(QPoint point);
59 
60     void actNewDeck();
61     void actLoadDeck();
62     bool actSaveDeck();
63     bool actSaveDeckAs();
64     void actLoadDeckFromClipboard();
65     void actSaveDeckToClipboard();
66     void actSaveDeckToClipboardRaw();
67     void actPrintDeck();
68     void actExportDeckDecklist();
69     void actAnalyzeDeckDeckstats();
70     void actAnalyzeDeckTappedout();
71 
72     void actClearFilterAll();
73     void actClearFilterOne();
74 
75     void actSwapCard();
76     void actAddCard();
77     void actAddCardToSideboard();
78     void actRemoveCard();
79     void actIncrement();
80     void actDecrement();
81     void actDecrementCard();
82     void actDecrementCardFromSideboard();
83 
84     void saveDeckRemoteFinished(const Response &r);
85     void filterViewCustomContextMenu(const QPoint &point);
86     void filterRemove(QAction *action);
87 
88     void loadLayout();
89     void restartLayout();
90     void freeDocksSize();
91     void refreshShortcuts();
92 
93     bool eventFilter(QObject *o, QEvent *e) override;
94     void dockVisibleTriggered();
95     void dockFloatingTriggered();
96     void dockTopLevelChanged(bool topLevel);
97     void saveDbHeaderState();
98     void setSaveStatus(bool newStatus);
99     void showSearchSyntaxHelp();
100 
101 private:
102     CardInfoPtr currentCardInfo() const;
103     void addCardHelper(QString zoneName);
104     void offsetCountAtIndex(const QModelIndex &idx, int offset);
105     void decrementCardHelper(QString zoneName);
106     void recursiveExpand(const QModelIndex &index);
107 
108     CardDatabaseModel *databaseModel;
109     CardDatabaseDisplayModel *databaseDisplayModel;
110     DeckListModel *deckModel;
111     QTreeView *databaseView;
112 
113     QTreeView *deckView;
114     KeySignals deckViewKeySignals;
115     CardFrame *cardInfo;
116     SearchLineEdit *searchEdit;
117     KeySignals searchKeySignals;
118 
119     QLabel *nameLabel;
120     LineEditUnfocusable *nameEdit;
121     QLabel *commentsLabel;
122     QTextEdit *commentsEdit;
123     QLabel *hashLabel1;
124     LineEditUnfocusable *hashLabel;
125     FilterTreeModel *filterModel;
126     QTreeView *filterView;
127     KeySignals filterViewKeySignals;
128     QWidget *filterBox;
129 
130     QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *analyzeDeckMenu,
131         *saveDeckToClipboardMenu;
132     QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard,
133         *aSaveDeckToClipboardRaw, *aPrintDeck, *aExportDeckDecklist, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout,
134         *aClose;
135     QAction *aClearFilterAll, *aClearFilterOne;
136     QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
137     QAction *aResetLayout;
138     QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aDeckDockVisible, *aDeckDockFloating, *aFilterDockVisible,
139         *aFilterDockFloating;
140 
141     bool modified;
142     QVBoxLayout *centralFrame;
143     QHBoxLayout *searchLayout;
144     QDockWidget *cardInfoDock;
145     QDockWidget *deckDock;
146     QDockWidget *filterDock;
147     QWidget *centralWidget;
148 
149 public:
150     explicit TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr);
151     ~TabDeckEditor() override;
152     void retranslateUi() override;
153     QString getTabText() const override;
154     void setDeck(DeckLoader *_deckLoader);
155     void setModified(bool _windowModified);
156     bool confirmClose();
157     void createDeckDock();
158     void createCardInfoDock();
159     void createFiltersDock();
160     void createMenus();
161     void createCentralFrame();
162 
163 public slots:
164     void closeRequest() override;
165 signals:
166     void deckEditorClosing(TabDeckEditor *tab);
167 };
168 
169 #endif
170