Tulip  5.7.4
Large graphs analysis and drawing
WorkspaceExposeWidget.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 WORKSPACEEXPOSEWIDGET_H
22 #define WORKSPACEEXPOSEWIDGET_H
23 
24 #include <QGraphicsObject>
25 #include <QGraphicsView>
26 
27 #include <tulip/tulipconf.h>
28 #include <tulip/WorkspacePanel.h>
29 
30 class QAbstractAnimation;
31 
32 namespace tlp {
33 
34 class PreviewItem : public QGraphicsObject {
35  Q_OBJECT
36 
37  static QPixmap *_closeButtonPixmap;
38  static QRect _closePixmapRect;
39 
40  QPixmap _pixmap;
41  WorkspacePanel *_panel;
42  bool _hovered;
43  bool _closeButtonHovered;
44 
45  int textHeight() const;
46 
47 public:
48  explicit PreviewItem(const QPixmap &pixmap, WorkspacePanel *panel,
49  QGraphicsItem *parent = nullptr);
50  QRectF boundingRect() const override;
51  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
52  WorkspacePanel *panel() const;
53  bool shouldClose(const QPointF &);
54 
55 protected:
56  void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
57  void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
58  void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
59  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override;
60 signals:
61  void opened();
62 };
63 
64 class TLP_QT_SCOPE WorkspaceExposeWidget : public QGraphicsView {
65  Q_OBJECT
66 
67  QAbstractAnimation *_positionAnimation;
68  std::vector<PreviewItem *> _items;
69  PreviewItem *_selectedItem;
70  QGraphicsRectItem *_placeholderItem;
71  bool _switchToSingleMode;
72 
73  int _currentPanelIndex;
74 
75  void updatePositions(bool resetScenePos = true);
76  static const int MARGIN;
77 
78  void finish();
79 
80 public:
81  static QSize previewSize();
82 
83  explicit WorkspaceExposeWidget(QWidget *parent = nullptr);
84  ~WorkspaceExposeWidget() override;
85  unsigned int currentPanelIndex() const;
86  std::vector<WorkspacePanel *> panels() const;
87 
88  bool isSwitchToSingleMode() const;
89 
90 public slots:
91  void setData(const std::vector<WorkspacePanel *> &panels, unsigned int currentPanelIndex);
92 
93 signals:
94  void exposeFinished();
95 
96 protected:
97  void resizeEvent(QResizeEvent *event) override;
98  bool eventFilter(QObject *, QEvent *) override;
99  bool event(QEvent *) override;
100 
101 protected slots:
102  void updatePositionsAnimationFinished();
103  void resetSceneRect();
104  void itemOpened();
105 };
106 } // namespace tlp
107 
108 #endif // WORKSPACEEXPOSEWIDGET_H
109 
110 ///@endcond