Tulip  5.7.4
Large graphs analysis and drawing
CaptionGraphicsSubItems.h
1 /*
2  *
3  * This file is part of Tulip (https://tulip.labri.fr)
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 CAPTIONGRAPHICSSUBITEMS_H
22 #define CAPTIONGRAPHICSSUBITEMS_H
23 
24 #include <QGraphicsPixmapItem>
25 #include <QObject>
26 
27 class QGradient;
28 
29 namespace tlp {
30 
31 class ConfigurationIconItem : public QObject, public QGraphicsPixmapItem {
32 
33  Q_OBJECT
34 
35 public:
36  ConfigurationIconItem() {}
37 
38 signals:
39 
40  void configurationIconPressed();
41 
42 protected:
43  void mousePressEvent(QGraphicsSceneMouseEvent *) override {
44  emit configurationIconPressed();
45  }
46 };
47 
48 class SelectionArrowItem : public QObject, public QGraphicsPathItem {
49 
50  Q_OBJECT
51 
52 public:
53  SelectionArrowItem(float initRangePos, const QPoint &initPos);
54 
55  bool sceneEvent(QEvent *event) override;
56 
57 signals:
58 
59  void circleMoved();
60 
61 protected:
62  int yPos;
63  QPoint initPos;
64 };
65 
66 class SelectionTextItem : public QGraphicsTextItem {
67 
68 public:
69  SelectionTextItem();
70 
71 protected:
72  bool sceneEvent(QEvent *event) override {
73  return static_cast<SelectionArrowItem *>(parentItem())->sceneEvent(event);
74  }
75 };
76 
77 class MovableRectItem : public QObject, public QGraphicsRectItem {
78 
79  Q_OBJECT
80 
81 public:
82  MovableRectItem(const QRectF &rect, const QRectF &size, SelectionArrowItem *topCircle,
83  SelectionArrowItem *bottomCircle);
84 
85  void setInternalRect(const QRectF &rect);
86 
87 signals:
88 
89  // begin and end in 0,1 range
90  void moved(float begin, float end);
91 
92 protected:
93  bool sceneEvent(QEvent *event) override;
94 
95  QRectF _currentRect;
96  QPoint _initPos;
97  SelectionArrowItem *_topCircle;
98  SelectionArrowItem *_bottomCircle;
99 };
100 
101 class MovablePathItem : public QObject, public QGraphicsPathItem {
102 
103  Q_OBJECT
104 
105 public:
106  MovablePathItem(const QRectF &rect, QGraphicsPathItem *topPathItem,
107  QGraphicsPathItem *bottomPathItem, SelectionArrowItem *topCircle,
108  SelectionArrowItem *bottomCircle);
109 
110  void setDataToPath(const std::vector<std::pair<double, float>> &metricToSizeFilteredList,
111  double minMetric, double maxMetric);
112 
113  void setRect(const QRectF &rect);
114 
115 signals:
116 
117  // begin and end in 0,1 range
118  void moved(float begin, float end);
119 
120 protected:
121  void updatePath();
122 
123  bool sceneEvent(QEvent *event) override;
124 
125  std::vector<std::pair<double, float>> _metricToSizeFilteredList;
126  double _minMetric;
127  double _maxMetric;
128 
129  QRectF _currentRect;
130  QGraphicsPathItem *_topPathItem;
131  QGraphicsPathItem *_bottomPathItem;
132  SelectionArrowItem *_topCircle;
133  SelectionArrowItem *_bottomCircle;
134 };
135 
136 class CaptionGraphicsBackgroundItem : public QObject, public QGraphicsRectItem {
137 
138  Q_OBJECT
139 
140 public:
141  CaptionGraphicsBackgroundItem(const QRect &rect);
142 
143  void generateColorCaption(const QGradient &activeGradient, const QGradient &hideGradient,
144  const std::string &propertyName, double minValue, double maxValue);
145 
146  void generateSizeCaption(const std::vector<std::pair<double, float>> &metricToSizeFilteredList,
147  const std::string &propertyName, double minValue, double maxValue);
148 
149 public slots:
150 
151  void updateCaption();
152  // begin and end in 0,1 range
153  void updateCaption(float begin, float end);
154  void configurationIconPressedSlot();
155 
156  void activateInteractions();
157  void removeInteractions();
158 
159 signals:
160 
161  void filterChanged(float begin, float end);
162  void configurationIconPressed();
163 
164  void interactionsActivated();
165  void interactionsRemoved();
166 
167 protected:
168  void activateInteractions(bool);
169 
170  bool sceneEvent(QEvent *event) override;
171  void updateSelectionText(float begin, float end);
172 
173  bool _interactionsActivated;
174  float _beginBackup;
175  float _endBackup;
176  QPoint _captionContentPos;
177 
178  double _minValue;
179  double _maxValue;
180 
181  // Global Items
182  QGraphicsTextItem *_minTextItem;
183  QGraphicsTextItem *_maxTextItem;
184  QGraphicsTextItem *_min2TextItem;
185  QGraphicsTextItem *_max2TextItem;
186  QGraphicsLineItem *_min2LineItem;
187  QGraphicsLineItem *_max2LineItem;
188  QGraphicsRectItem *_captionRectBorder;
189  SelectionArrowItem *_rangeSelector1Item;
190  SelectionArrowItem *_rangeSelector2Item;
191  SelectionTextItem *_rangeSelector1TextItem;
192  SelectionTextItem *_rangeSelector2TextItem;
193 
194  // Color caption Items
195  QGraphicsRectItem *_topCaptionRectItem;
196  MovableRectItem *_middleCaptionRectItem;
197  QGraphicsRectItem *_bottomCaptionRectItem;
198 
199  // Size caption Items
200  // MovableRectItem *_selectionSizeRectItem;
201  MovablePathItem *_sizeCaptionPathItem;
202  QGraphicsPathItem *_topSizeCaptionPathItem;
203  QGraphicsPathItem *_bottomSizeCaptionPathItem;
204 };
205 } // namespace tlp
206 
207 #endif // CAPTIONGRAPHICSSUB_H
208 ///@endcond