Tulip  4.1.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  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 = NULL);
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