1 /***************************************************************************
2                           gamelist.h  -  Game List window
3                              -------------------
4     begin                : Sun 23 Jul 2006
5     copyright            : (C) 2006 Michal Rudolf <mrudolf@kdewebdev.org>
6  ***************************************************************************/
7 
8 /***************************************************************************
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  ***************************************************************************/
16 
17 #ifndef GAMELIST_H_INCLUDED
18 #define GAMELIST_H_INCLUDED
19 
20 #include "tableview.h"
21 #include "gamex.h"
22 
23 #include <QPointer>
24 #include <QSortFilterProxyModel>
25 #include "filteroperator.h"
26 
27 class FilterX;
28 class FilterModel;
29 class GameListSortModel;
30 class Search;
31 
32 /** @ingroup GUI
33 The GameList class displays list of the games in current filter. It allows
34 user to click on list header and perform simple tag searches. */
35 
36 class GameList : public TableView
37 {
38     Q_OBJECT
39 public:
40     GameList(FilterX* filter, QWidget* parent = nullptr);
41     ~GameList();
42 
43     void keyPressEvent(QKeyEvent* event);
44     void removeSelection();
45     /** Set current database */
46     QList<GameId> selectedGames();
47 
48     void startUpdate(); // TODO Remove this hack
49     void endUpdate(); // TODO Remove this hack
50 
51 public slots:
52     /** Change current filter/database */
53     void setFilter(FilterX* filter);
54     /** Update filter (called after changing filter outside) */
55     void updateFilter(GameId index, int value);
56     /** Perform simple search */
57     void simpleSearch(int tag);
58     void executeSearch(Search* search, FilterOperator searchOperator=FilterOperator::NullOperator);
59     void endSearch();
60     /** Select and show current game in the list */
61     void selectGame(GameId index);
62     /** Select and show current game in the list */
63     void slotFilterListByPlayer(QString ns);
64     /** Select and show current event in the list */
65     void slotFilterListByEvent(QString ns);
66     /** Select and show current ECO in the list */
67     void slotFilterListByEco(QString ns);
68     /** Select and show current event and player in the list */
69     void slotFilterListByEventPlayer(QString player, QString event);
70     /** Select and show current player and ECO in the list */
71     void slotFilterListByEcoPlayer(QString tag, QString eco, QString player, QString result);
72     /** Select the next visible game from the list */
73     bool selectNextGame();
74     /** Select a random but visible game from the list */
75     void selectRandomGame();
76     /** Select the previous visible game from the list */
77     void selectPreviousGame();
78     /** Show the context menu */
79     virtual void ShowContextMenu(const QPoint& pos);
80     void slotReconfigure();
81 
82 public slots:
83     /** Request a filter operation to invert the visibility of all items */
84     void filterInvert();
85     /** Request a filter operation to show all items*/
86     void filterSetAll(int value=1);
87 
88 private slots:
89     /** Re-emit the request to the receivers to perform some action */
90     void itemSelected(const QModelIndex& index);
91     /** Request a context menu for the list members */
92     void slotContextMenu(const QPoint& pos);
93     /** Request to merge all games from the database into the current game */
94     void slotMergeAllGames();
95     /** Request to merge the complete filter into the current game */
96     void slotMergeFilter();
97     /** Request to merge a game into the current game */
98     void slotMergeSelectedGames();
99     /** Request a copy dialog for the games selected */
100     void slotCopyGame();
101     /** Request finding duplicates for the games selected */
102     void slotFindDuplicate();
103     /** Delete or undelete a game */
104     void slotDeleteGame();
105     /** Remove a game from a filter */
106     void slotHideGame();
107     /** Remove deleted games from a filter */
108     void slotHideDeletedGames();
109     /** React to a change in selected item */
110     void slotItemSelected(const QModelIndex&);
111     bool triggerGameSelection(int sortRow);
112 signals:
113     void gameSelected(GameId);
114     void raiseRequest();
115     void requestMergeGame(QList<GameId>);
116     void requestMergeAllGames();
117     void requestMergeFilter();
118     void requestCopyGame(QList<GameId>);
119     void requestFindDuplicates(QList<GameId>);
120     void requestDeleteGame(QList<GameId>);
121     void requestGameData(GameX&);
122     void signalFirstGameLoaded(bool);
123     void signalLastGameLoaded(bool);
124     void signalFilterSize(quint64);
125     void signalDropEvent(QDropEvent*);
126     void searchProgress(int);
127     void searchFinished();
128     void requestAppendGames(QString path, QList<GameId> indexes, QString source);
129 
130 protected: //Drag'n'Drop Support
131     void startDrag(Qt::DropActions supportedActions);
132     QModelIndex GetSourceIndex(const QModelIndex& index) const;
133     QModelIndex NewSortIndex(int row) const;
134     QModelIndex GetSortModelIndex(const QModelIndex& index) const;
135 
136     void dragEnterEvent(QDragEnterEvent *event);
137     void dragMoveEvent(QDragMoveEvent *event);
138     void dragLeaveEvent(QDragLeaveEvent *event);
139     void dropEvent(QDropEvent *event);
140 
141 private:
142     FilterModel* m_model;
143     QPointer<GameListSortModel> sortModel;
144 };
145 
146 #endif
147