Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 1 and Inria Bordeaux - Sud Ouest
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 
22 #ifndef ITEMSDIALOGLIST_H
23 #define ITEMSDIALOGLIST_H
24 
25 #ifndef DOXYGEN_NOTFOR_DEVEL
26 
27 #include <tulip/tulipconf.h>
28 
29 #include <QtGui/QListWidget>
30 #include <QtGui/QMouseEvent>
31 #include <QtGui/QDragEnterEvent>
32 #include <QtGui/QDropEvent>
33 #include <QtGui/QMouseEvent>
34 #include <QtCore/QObject>
35 #include <QtCore/QHash>
36 
37 
38 namespace tlp {
39 
40 struct itemInfo {
41  QString attribut;
42  bool choice;
43 };
44 
45 // A Custom List Widget which supports drag and drop
46 class TLP_QT_SCOPE ItemsListWidget : public QListWidget {
47 
48  Q_OBJECT
49 
50 public:
51 
52  ItemsListWidget(QWidget *parent = NULL, const unsigned int maxListSize = 0);
53 
54  // Method which adds an item in the list
55  // return true if the item has been added, false if the maximum size of the list is already reached
56  bool addItemList(QString item);
57 
58  void deleteItemList(QListWidgetItem *item);
59 
60  // Method which sets the maximum size of the list
61  // if 0, there is no size restriction
62  void setMaxListSize(const unsigned int maxListSize) {
63  this->maxListSize = maxListSize;
64  }
65  unsigned int getMaxListSize() const {
66  return maxListSize;
67  }
68 
69 protected:
70 
71  void mousePressEvent(QMouseEvent *event);
72  void mouseMoveEvent(QMouseEvent *event);
73  void dragEnterEvent(QDragEnterEvent *event);
74  void dragMoveEvent(QDragMoveEvent *event);
75  void dropEvent(QDropEvent *event);
76 
77 private:
78 
79  void startDrag(QListWidgetItem *item);
80  void changeStatus(QListWidgetItem *item);
81  void dragMoveOrEnterEvent(QDragMoveEvent *event);
82  QPoint startPos;
83  QHash<QString,itemInfo> hashDataBase;
84  unsigned int maxListSize;
85 };
86 
87 }
88 
89 #endif // DOXYGEN_NOTFOR_DEVEL
90 
91 #endif
92 
93 
94 ///@endcond