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