Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
ViewWidget.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 
20 #ifndef VIEWWIDGET_H
21 #define VIEWWIDGET_H
22 
23 #include <tulip/tulipconf.h>
24 #include <tulip/View.h>
25 
26 class QGraphicsItem;
27 
28 namespace tlp {
29 
30 /**
31  @ingroup Plugins
32 
33  @brief ViewWidget provides convenience functions to allow the user to build a view plugin that displays a QWidget as its main element.
34 
35  The ViewWidget class will build a QGraphicsView that sets a widget as the background of the whole panel.
36  Sublassing ViewWidget means that you'll have to provide a centralWidget (see ViewWidget::setCentralWidget) that will take up the whole panel and be drawn in the background.
37  You can use the addToScene() and removeFromScene() methods to edit the QGraphicsItems that will drawn over the widget.
38 
39  By default, when an interactor gets active on a ViewWidget, it gets installed on the centralWidget (see Interactor::install)
40 
41  @note When creating a ViewWidget, you should overload setupWidget instead of setupUi. If you still want to implement setupUi, you must call the ViewWidget::setupUi() method first.
42  */
43 class TLP_QT_SCOPE ViewWidget : public tlp::View {
44  Q_OBJECT
45 
46  QSet<QGraphicsItem *> _items;
47  QGraphicsView* _graphicsView;
48  QWidget* _centralWidget;
49  QGraphicsItem* _centralWidgetItem;
50 
51  void refreshItemsParenthood();
52 
53 public:
54  ViewWidget();
55  virtual ~ViewWidget();
56 
57  /**
58  @see View::graphicsView()
59  @note This method should not be reimplemented as a subclass of ViewWidget
60  */
61  virtual QGraphicsView* graphicsView() const;
62 
63 public slots:
64  /**
65  @see View::setupUi
66  @note This method should not be reimplemented as a subclass of ViewWidget
67  */
68  virtual void setupUi();
69 
70  /**
71  @brief Reimplemented from View::draw()
72  By default, this method does nothing. We assume the widget is automatically repainted by Qt's windowing manager
73  */
74  virtual void draw() { }
75 
76 protected slots:
77  /**
78  By default, the current interactor gets installed over the central widget.
79 
80  @see View::currentInteractorChanged()
81  */
82  virtual void currentInteractorChanged(tlp::Interactor*);
83 
84  virtual void graphDeleted(Graph *parentGraph);
85 
86 protected:
87  /**
88  @brief Sets up the central widget.
89  This is similar to View::setupUi in the sense that the purpose of setupWidget is to construct the GUI element.
90  @warning This method MUST call the setCentralWidget to provide the ViewWidget with a valid widget.
91  */
92  virtual void setupWidget()=0;
93 
94  /**
95  @brief Adds an item to the graphicsView that will be drawn on top of the widget
96  This is a convenience function for the user to avoid taking care of item parenthood.
97  */
98  void addToScene(QGraphicsItem* item);
99 
100  /**
101  @brief Removes a graphics item from the view.
102  This is a convenience function for the user to avoid taking care of item parenthood.
103  */
104  void removeFromScene(QGraphicsItem* item);
105 
106  /**
107  @brief Sets the widget to be drawn as the view's background.
108  This method may be called several times. Parenthood between the widget and items added using addToScene will be automatically updated.
109  @note The ViewWidget takes ownership of the central widget. The previous central widget gets deleted in the process.
110  */
111  void setCentralWidget(QWidget*, bool deleteOldCentralWidget=true);
112 
113  /**
114  @return The graphics item associated to the central widget
115  @see setCentralWidget
116  */
117  virtual QGraphicsItem* centralItem() const;
118 
119  QPixmap snapshot(const QSize &outputSize=QSize()) const;
120 };
121 
122 }
123 
124 #endif // VIEWWIDGET_H
Interactor provides a way to handle user inputs over a view. Basically, The interactor class is an ov...
Definition: Interactor.h:53
ViewWidget provides convenience functions to allow the user to build a view plugin that displays a QW...
Definition: ViewWidget.h:43
View plugins provide a way to dynamically add to a Tulip plateform various ways to visualize a graph...
Definition: View.h:73
virtual void draw()
Reimplemented from View::draw() By default, this method does nothing. We assume the widget is automat...
Definition: ViewWidget.h:74