Move packages to trunk root
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
Fourth tutorial
|
||||
-----------------
|
||||
|
||||
The fourth tutorial shows how to create a more complex application
|
||||
using the Qt class QMainWindow. With this class you can create a
|
||||
MDI(Multiple document interface) application.
|
||||
|
||||
For drawing, the tutorial use the same layer as for the previous one
|
||||
but this time we use another class QMainWindow, as the main frame of
|
||||
the application. Further down is described how the flow is:
|
||||
|
||||
The entry point is the same:
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
My_window W(600,600);
|
||||
app.setMainWidget( &W );
|
||||
W.show();
|
||||
W.setCaption("Using QMainWindow QT class");
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
This time you see that W is no longer an instance of Qt_widget but is
|
||||
an instance of QMainWindow. QMainWindow is also a widget but provides
|
||||
functionalities like you can use a toolbar, a status bar ... in other
|
||||
words you can create a complex MDI application. To use an instance of
|
||||
Qt_widget you have to say in the constructor:
|
||||
|
||||
setCentralWidget(widget);
|
||||
|
||||
where widget is an instance of Qt_widget. As you see it is also declared
|
||||
in My_window.
|
||||
|
||||
There is one more thing, at the constructor you see:
|
||||
|
||||
widget = new My_Widget(this);
|
||||
|
||||
Also the constructor of My_widget is adapted:
|
||||
|
||||
My_widget(QMainWindow* c) : CGAL::Qt_widget(c) {};
|
||||
|
||||
This lines tells the application that My_window is a parent for
|
||||
My_widget. Try to comment this lines to see what happens. Two
|
||||
windows will appear, one for My_window and one for My_widget.
|
||||
|
||||
In the constructor it is widget->attach(&v); This way, the layer is
|
||||
attached by My_widget. The rest of the code does the same thing as the
|
||||
previous tutorials: insert a new point in a Delaunay triangulation and
|
||||
draw the triangulation every time you click on the window.
|
||||
@@ -0,0 +1,48 @@
|
||||
# Created by the script create_makefile
|
||||
# This is the makefile for compiling a CGAL application.
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# include platform specific settings
|
||||
#---------------------------------------------------------------------#
|
||||
# Choose the right include file from the <cgalroot>/make directory.
|
||||
|
||||
# CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE
|
||||
include $(CGAL_MAKEFILE)
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# compiler flags
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
CXXFLAGS = -I../../../../include/ \
|
||||
$(CGAL_CXXFLAGS) \
|
||||
$(LONG_NAME_PROBLEM_CXXFLAGS) \
|
||||
$(DEBUG_OPT)
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# linker flags
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
LIBPATH = \
|
||||
$(CGAL_LIB_DIR)
|
||||
|
||||
LDFLAGS = \
|
||||
$(LONG_NAME_PROBLEM_LDFLAGS) \
|
||||
$(CGAL_QT_LDFLAGS)
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# target entries
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
all: tutorial4$(EXE_EXT)
|
||||
|
||||
tutorial4$(EXE_EXT): tutorial4$(OBJ_EXT)
|
||||
$(CGAL_CXX) $(EXE_OPT)tutorial4 tutorial4$(OBJ_EXT) $(LDFLAGS)
|
||||
|
||||
clean: tutorial4.clean
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# suffix rules
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
.C$(OBJ_EXT):
|
||||
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<
|
||||
@@ -0,0 +1,67 @@
|
||||
//demo/Qt_widget/basic/tutorial4.C
|
||||
#ifndef CGAL_USE_QT
|
||||
#include <iostream>
|
||||
int main(int, char*){
|
||||
std::cout << "Sorry, this demo needs QT..." << std::endl; return 0;}
|
||||
#else
|
||||
#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>
|
||||
|
||||
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 << 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);
|
||||
widget->attach(&v);
|
||||
}
|
||||
private:
|
||||
My_widget *widget;
|
||||
My_layer v;
|
||||
};
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
My_window W(400,400);
|
||||
app.setMainWidget( &W );
|
||||
W.show();
|
||||
W.setCaption("Using QMainWindow QT class");
|
||||
return app.exec();
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user