Tulip  4.0.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
WorkspaceExposeWidget.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 WORKSPACEEXPOSEWIDGET_H
23 #define WORKSPACEEXPOSEWIDGET_H
24 
25 #include <QtGui/QGraphicsObject>
26 #include <QtGui/QGraphicsView>
27 #include <QtCore/QMap>
28 #include <QtGui/QPixmap>
29 #include <tulip/tulipconf.h>
30 
31 class QAbstractAnimation;
32 
33 namespace tlp {
34 class WorkspacePanel;
35 
36 class PreviewItem: public QGraphicsObject {
37  Q_OBJECT
38 
39  static QPixmap* _closeButtonPixmap;
40  static QRect _closePixmapRect;
41 
42  QPixmap _pixmap;
43  tlp::WorkspacePanel* _panel;
44  bool _hovered;
45  bool _closeButtonHovered;
46 
47  int textHeight() const;
48 public:
49  explicit PreviewItem(const QPixmap& pixmap, tlp::WorkspacePanel* panel, QGraphicsItem* parent = NULL);
50  QRectF boundingRect() const;
51  void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
52  tlp::WorkspacePanel* panel() const;
53  bool shouldClose(const QPointF&);
54 protected:
55  void hoverEnterEvent(QGraphicsSceneHoverEvent*);
56  void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
57  void hoverMoveEvent(QGraphicsSceneHoverEvent*);
58  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
59 signals:
60  void opened();
61 };
62 
63 
64 class TLP_QT_SCOPE WorkspaceExposeWidget : public QGraphicsView {
65  Q_OBJECT
66 
67  QAbstractAnimation* _positionAnimation;
68  QList<PreviewItem*> _items;
69  PreviewItem* _selectedItem;
70  QGraphicsRectItem* _placeholderItem;
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  int currentPanelIndex() const;
84  QVector<WorkspacePanel*> panels() const;
85 
86 public slots:
87  void setData(const QVector<WorkspacePanel*>& panels, int currentPanelIndex);
88 
89 signals:
90  void exposeFinished();
91 
92 protected:
93  void resizeEvent(QResizeEvent *event);
94  bool eventFilter(QObject *, QEvent *);
95  bool event(QEvent*);
96 
97 protected slots:
98  void updatePositionsAnimationFinished();
99  void resetSceneRect();
100  void itemOpened();
101 };
102 
103 }
104 
105 #endif // WORKSPACEEXPOSEWIDGET_H
106 
107 ///@endcond