Tulip  4.6.0
Better Visualization Through Research
library/tulip-gui/include/tulip/ViewWidget.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 #ifndef VIEWWIDGET_H
00021 #define VIEWWIDGET_H
00022 
00023 #include <tulip/tulipconf.h>
00024 #include <tulip/View.h>
00025 
00026 class QGraphicsItem;
00027 
00028 namespace tlp {
00029 
00030 /**
00031   @ingroup Plugins
00032 
00033   @brief ViewWidget provides convenience functions to allow the user to build a view plugin that displays a QWidget as its main element.
00034 
00035   The ViewWidget class will build a QGraphicsView that sets a widget as the background of the whole panel.
00036   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.
00037   You can use the addToScene() and removeFromScene() methods to edit the QGraphicsItems that will drawn over the widget.
00038 
00039   By default, when an interactor gets active on a ViewWidget, it gets installed on the centralWidget (see Interactor::install)
00040 
00041   @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.
00042   */
00043 class TLP_QT_SCOPE ViewWidget : public tlp::View {
00044   Q_OBJECT
00045 
00046   QSet<QGraphicsItem *> _items;
00047   QGraphicsView* _graphicsView;
00048   QWidget* _centralWidget;
00049   QGraphicsItem* _centralWidgetItem;
00050 
00051   void refreshItemsParenthood();
00052 
00053 public:
00054   ViewWidget();
00055   virtual ~ViewWidget();
00056 
00057   /**
00058     @see View::graphicsView()
00059     @note This method should not be reimplemented as a subclass of ViewWidget
00060     */
00061   virtual QGraphicsView* graphicsView() const;
00062 
00063 public slots:
00064   /**
00065     @see View::setupUi
00066     @note This method should not be reimplemented as a subclass of ViewWidget
00067     */
00068   virtual void setupUi();
00069 
00070   /**
00071     @brief Reimplemented from View::draw()
00072     By default, this method does nothing. We assume the widget is automatically repainted by Qt's windowing manager
00073     */
00074   virtual void draw() { }
00075 
00076 protected slots:
00077   /**
00078     By default, the current interactor gets installed over the central widget.
00079 
00080     @see View::currentInteractorChanged()
00081     */
00082   virtual void currentInteractorChanged(tlp::Interactor*);
00083 
00084   virtual void graphDeleted(Graph *parentGraph);
00085 
00086 protected:
00087   /**
00088     @brief Sets up the central widget.
00089     This is similar to View::setupUi in the sense that the purpose of setupWidget is to construct the GUI element.
00090     @warning This method MUST call the setCentralWidget to provide the ViewWidget with a valid widget.
00091     */
00092   virtual void setupWidget()=0;
00093 
00094   /**
00095     @brief Adds an item to the graphicsView that will be drawn on top of the widget
00096     This is a convenience function for the user to avoid taking care of item parenthood.
00097     */
00098   void addToScene(QGraphicsItem* item);
00099 
00100   /**
00101     @brief Removes a graphics item from the view.
00102     This is a convenience function for the user to avoid taking care of item parenthood.
00103     */
00104   void removeFromScene(QGraphicsItem* item);
00105 
00106   /**
00107     @brief Sets the widget to be drawn as the view's background.
00108     This method may be called several times. Parenthood between the widget and items added using addToScene will be automatically updated.
00109     @note The ViewWidget takes ownership of the central widget. The previous central widget gets deleted in the process.
00110     */
00111   void setCentralWidget(QWidget*, bool deleteOldCentralWidget=true);
00112 
00113   /**
00114     @return The graphics item associated to the central widget
00115     @see setCentralWidget
00116     */
00117   virtual QGraphicsItem* centralItem() const;
00118 
00119   QPixmap snapshot(const QSize &outputSize=QSize()) const;
00120 };
00121 
00122 }
00123 
00124 #endif // VIEWWIDGET_H
 All Classes Files Functions Variables Enumerations Enumerator Properties