Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces 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
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  int currentPanelIndex() const;
84  QVector<WorkspacePanel*> panels() const;
85 
86  bool isSwitchToSingleMode() const;
87 
88 public slots:
89  void setData(const QVector<WorkspacePanel*>& panels, int currentPanelIndex);
90 
91 signals:
92  void exposeFinished();
93 
94 protected:
95  void resizeEvent(QResizeEvent *event);
96  bool eventFilter(QObject *, QEvent *);
97  bool event(QEvent*);
98 
99 protected slots:
100  void updatePositionsAnimationFinished();
101  void resetSceneRect();
102  void itemOpened();
103 };
104 
105 }
106 
107 #endif // WORKSPACEEXPOSEWIDGET_H
108 
109 ///@endcond