CGAL::Qt_widget_standard_toolbar

Definition

The standard toolbar includes the basic tools used for zooming and translating in a Qt_widget.

#include <CGAL/IO/Qt_widget_standard_toolbar.h>

Inherits From

QToolBar

Creation

Qt_widget_standard_toolbar stoolbar ( Qt_widget *w, QMainWindow *mw, QWidget* parent, bool newline = true, const char* name = 0);
This constructor creates a new toolbar, called name, in your application, containing all the standard tools. The first parameter w is a non-null pointer to the Qt_widget object on which the toolbar functionalities act. The second parameter mw is a pointer to the QMainWindow that manages the toolbar. The later is added to the top area of the QMainWindow, unless mw=0. mw, parent, newline, name are passed to the QMainWindow constructor (with first parameter label=''Qt_widget standard toolbar'').


Qt_widget_standard_toolbar stoolbar ( Qt_widget *w, QMainWindow *parent = 0, const char* name = 0);
Simplified version of the previous one. The parent is the QMainWindow that manages the toolbar.

const QToolBar* stoolbar.toolbar () Deprecated: (in CGAL-2.4 the standard toolbar was not derived from QToolBar) Returns a pointer to the QToolBar this itself.

public slots:

void stoolbar.back () Goes back in the history list of the standard toolbar.

void stoolbar.forward () Goes forward in the history list of the standard toolbar.

void stoolbar.clear_history () Clears the history list of the standard toolbar.

Example

#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/IO/Qt_widget_Delaunay_triangulation_2.h>

#include <qapplication.h>
#include <qmainwindow.h>

#include <CGAL/IO/Qt_widget.h>
#include <CGAL/IO/Qt_widget_layer.h>
#include <CGAL/IO/Qt_widget_standard_toolbar.h>

typedef CGAL::Cartesian<double>             Rep;
typedef CGAL::Point_2<Rep>                  Point;
typedef CGAL::Delaunay_triangulation_2<Rep> Delaunay;

Delaunay dt;

class My_layer : public CGAL::Qt_widget_layer{
  void draw(){
    *widget << CGAL::BLACK;
    *widget << dt;
  }
};

class My_widget : public CGAL::Qt_widget {
public:
  My_widget(QMainWindow* c) : CGAL::Qt_widget(c) {};
private:
  //this event is called only when the user presses the mouse
  void mousePressEvent(QMouseEvent *e)
  {
    Qt_widget::mousePressEvent(e);
    dt.insert(Point(x_real(e->x()), y_real(e->y())));
    redraw();
  }
};

class My_window : public QMainWindow{
public:
  My_window(int x, int y)
  {
    widget = new My_widget(this);
    setCentralWidget(widget);
    resize(x,y);
    widget->set_window(0, x, 0, y);
    
    //How to attach the standard toolbar
    stoolbar = new CGAL::Qt_widget_standard_toolbar(widget, this,
                                                    "Standard toolbar");
    widget->attach(&v);
  }
private:
  My_widget *widget;
  My_layer  v;
  CGAL::Qt_widget_standard_toolbar *stoolbar;
};

int main( int argc, char **argv )
{
    QApplication app( argc, argv );
    My_window W(400,400);
    app.setMainWidget( &W );
    W.show();
    W.setCaption("Using the Standard Toolbar");
    return app.exec();
}

This example is implemented in the fifth tutorial. You can look over the code to see how the code works.