Tulip  5.0.0
Large graphs analysis and drawing
ItemsListWidget.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef ITEMSDIALOGLIST_H
22 #define ITEMSDIALOGLIST_H
23 
24 #ifndef DOXYGEN_NOTFOR_DEVEL
25 
26 #include <tulip/tulipconf.h>
27 
28 #include <QListWidget>
29 
30 namespace tlp {
31 
32 struct itemInfo {
33  QString attribut;
34  bool choice;
35 };
36 
37 // A Custom List Widget which supports drag and drop
38 class TLP_QT_SCOPE ItemsListWidget : public QListWidget {
39 
40  Q_OBJECT
41 
42 public:
43 
44  ItemsListWidget(QWidget *parent = NULL, const unsigned int maxListSize = 0);
45 
46  // Method which adds an item in the list
47  // return true if the item has been added, false if the maximum size of the list is already reached
48  bool addItemList(QString item);
49 
50  void deleteItemList(QListWidgetItem *item);
51 
52  // Method which sets the maximum size of the list
53  // if 0, there is no size restriction
54  void setMaxListSize(const unsigned int maxListSize) {
55  this->maxListSize = maxListSize;
56  }
57  unsigned int getMaxListSize() const {
58  return maxListSize;
59  }
60 
61 protected:
62 
63  void mousePressEvent(QMouseEvent *event);
64  void mouseMoveEvent(QMouseEvent *event);
65  void dragEnterEvent(QDragEnterEvent *event);
66  void dragMoveEvent(QDragMoveEvent *event);
67  void dropEvent(QDropEvent *event);
68 
69 private:
70 
71  void beginDrag(QListWidgetItem *item);
72  void changeStatus(QListWidgetItem *item);
73  void dragMoveOrEnterEvent(QDragMoveEvent *event);
74  QPoint startPos;
75  QHash<QString,itemInfo> hashDataBase;
76  unsigned int maxListSize;
77 };
78 
79 }
80 
81 #endif // DOXYGEN_NOTFOR_DEVEL
82 
83 #endif
84 
85 
86 ///@endcond