CGAL::Qt_widget_layer

Definition

The Qt_widget_layer serves as a base class for layers. Layers are classes that draw on the drawing area of a Qt_widget and receive events from it. You can attach and detach layers on the Qt_widget. All the attached layers will receive the events if they are active. The same for drawing, all the active layers that are attached will be drawn.

#include <CGAL/IO/Qt_widget_layer.h>

Inherits From

QObject

Creation

Qt_widget_layer layer ( QObject *parent = 0, const char* name = 0);
The default constructor. The parameters parent and name are passed to the QObject constructor.

virtual void layer.mousePressEvent ( QMouseEvent *)
virtual void layer.mouseReleaseEvent ( QMouseEvent *)
virtual void layer.wheelEvent ( QMouseEvent *)
virtual void layer.mouseDoubleClickEvent ( QMouseEvent *)
virtual void layer.mouseMoveEvent ( QMouseEvent *)
virtual void layer.keyPressEvent ( QKeyEvent *)
virtual void layer.keyReleaseEvent ( QMouseEvent *)
virtual void layer.enterEvent ( QEvent *)
virtual void layer.leaveEvent ( QEvent *)
virtual bool layer.event ( QEvent *) These virtual functions can be overloaded in the derived class. They are called by the Qt_widget to which the layer is attached.

bool layer.is_active () Returns true if this layer is active.

Public Slots

virtual void layer.draw () This virtual member function must be overloaded. This is where the drawing code goes.

void layer.stateChanged ( int s) This slot is provided to change the layer's state from activated to deactivated and reverse if it is triggered. The layer is activated if s is 2, or it is deactivated if s is 0. These values match with the signal stateChanged(int) in the QButton widget.

void layer.toggle ( bool b) This slot is provided to change the layer's state from activated to deactivated and reverse if it is triggered. The layer is activated if b is true, or it is deactivated if b is false. These values match with the signal toggled(bool) in the QButton widget.

bool layer.activate () Activate and return true if it was not active.

bool layer.deactivate () Deactivate and return true if it was active.

Protected

Qt_widget * widget; The widget a layer is attached to or 0 otherwise.

virtual void layer.activating () You should overload this function if you want to have initializing code for your layer. This function is called every time the layer is activated.

virtual void layer.deactivating () You should overload this function if you want to write clean up code for your layer. This function is called every time the layer is deactivated.

Signals

void layer.activated ( *l) This signal is emitted every time this layer is activated.

void layer.deactivated ( *l) This signal is emitted every time this layer is deactivated.

Example

The following example of a layer draws the points of a triangulation in green.

#include <CGAL/IO/Qt_widget_layer.h>

namespace CGAL {

template <class T>
class Qt_layer_show_points : public Qt_widget_layer {
public:
  typedef typename T::Point           Point;
  typedef typename T::Segment         Segment;
  typedef typename T::Vertex          Vertex;
  typedef typename T::Vertex_iterator   Vertex_iterator;

  Qt_layer_show_points(T &t) : tr(t){};

  void draw()
  {  
    Vertex_iterator it = tr.vertices_begin(), 
                beyond = tr.vertices_end();
    *widget << CGAL::GREEN << CGAL::PointSize (3) 
            << CGAL::PointStyle (CGAL::DISC);    
    while(it != beyond) {      
      *widget << (*it).point();
      ++it;
    }
  };
private:
  T &tr;
  
};//end class 

} // namespace CGAL