An object of type Qt_widget is a two-dimensional window for graphical IO. It is a class that is designed to help CGAL users to visualize easily CGAL objects and for advanced users to interact with them. This widget is designed for 2D CGAL objects only.
#include <CGAL/IO/Qt_widget.h>
The widget class also defines the following enum type to specify which kind of point representation do you want to use:
|
| |
Constructs a widget which is a child of parent, with the name
name. The default visible area is between ranges xmin = -1, xmax
= 1, ymin = -1, ymax = 1. By default the X and Y scale factors are equal.
|
Qt_widget provides scaling support. You can use a scaling factor for your objects as well as you can draw the objects with one scale and look at the objects with different scales. Also there is a possibility to tell the widget that you want that the visible area should be mapped to a certain interval, and the widget adjust the scaling factor according to that.
advanced |
advanced |
|
| |||
Multiply the X and Y scaling factors by ratio, then calls redraw. The center of the visible area remains the same. | ||||
|
| |||
Multiply the X and Y scaling factors by ratio, then calls redraw. The center of the visible area becomes (xc, yc). | ||||
|
| |||
Move the center of the widget with distx on the X axis and disty on the Y axis. | ||||
|
| |||
Set the center of the widget to (x, y). | ||||
|
| |||
Deprecated: This function adds the current viewport and transformations to history. You should use save() public slot from Qt_widget_history object. | ||||
|
| |||
Deprecated: Clears the history. This means that there are no elements in the history list. Call this method when you want to reinitialize the history list. You should use clear_history() method from Qt_widget_standard_toolbar or the clear() public slot from Qt_widget_history object. |
|
|
|
|
| Deprecated: This slots permit to walk into history. Return true if succeded. These slots are deprecated. You should use the backward() and forward() methods of Qt_widget_history object, or the back() and forward() public slots from Qt_widget_standard_toolbar object. |
|
| Clear the screen. The properties of the widget remain the same after calling this member function. You can see a list of the properties that you can set at the properties description. |
|
| Locks the widget, keeping the widget from being refreshed. If you lock the widget you should verify that you unlock it somewhere. The number of lock() calls should be the same with the number of unlock() calls. Lock and unlock calls can be nested. |
|
| Unlocks the widget, and calls do_paint(). The widget is only unlocked if the number of unlock calls is equal to the number of lock calls. |
|
| Refresh the widget calling paintEvent(QPaintEvent *e) for the Qt_widget only if the widget is unlocked. This mean that redraw() is called if and only if the widget is unlocked. |
|
| If you derive from Qt_widget you have to overload this function and put your code for drawing here if you don't use layers. The best way is to attach layers to the widget and call this method. This method redraws the layers attached and active. Before drawing the layers, redraw clear the screen and emit redraw_on_back(). Emit redraw_on_front() at the end. |
|
| Redraws all the attached and active layers into a Postscript device. It could be a file or a printer. This method also use signals as redraw_on_back() or redraw_on_front(). |
You can set the properties of the functions through this functions as well as with the help of manipulators described later. The function naming convention has changed for this member functions, to Qt convention.
|
| |
Set the current pen color of the widget to be c. | ||
|
| |
Set the current background color to be c. | ||
|
| |
Set the current fill color of the widget to be c. | ||
|
| |
Set the status of the widget to true or false concerning filling the objects: polygons, circles, rectangles ... | ||
|
| |
Set the current line width of the widget. | ||
|
| |
Set the current point size of the widget. | ||
|
| |
Set the current point style of the widget to s. PointStyle is a enumeration declared in Qt_widget. | ||
|
| |
Set the current raster operation. |
|
| |
Add the layer s in the list of layers.The last added will be on top of the screen. Also the events are forwarded to layers in the order they have been attached. | ||
|
| |
Remove the layer s from the list. s it's a pointer to an existing layer. |
|
| |
This function should be called by the tools that create CGAL objects. It then emits the signal new_cgal_object(CGAL::Object). Slots of other components can be connected to this signal. |
Note that we use also types from Qt here.
|
| Returns the current pen color. The color returned is a Qt class. |
|
| |
Returns the current widget background color. The color returned is a Qt class. | ||
|
| Returns the current color used for filling the objects. The color returned is a Qt class. |
|
| Returns the current point style. PointStyle is a enumeration declared in Qt_widget. |
|
| Returns the current point size. |
|
| Returns the current line width. |
|
| Return the current raster operation. |
|
| Returns the left x coordinate of the widget. |
|
| Returns the lower y coordinate of the widget. |
|
| Returns the right x coordinate of the widget. |
|
| Returns the upper y coordinate of the widget. |
advanced |
|
| |
|
| |
| ||
|
| |
Returns the x real world coordinate of the Qt_widget. | ||
| ||
|
| |
Returns the y real world coordinate of the Qt_widget. | ||
|
| |
|
|
advanced |
|
| |
This method is the opposite of x_real method. Converts the world coordinates in screen coordinates. If you want to get an integer between 0 and width, you should pass an x between xmin and xmax. | ||
|
| |
This method is the opposite of y_real method. Converts the world coordinates in screen coordinates. If you want to get an integer between 0 and height, you should pass an y between ymin and ymax. |
advanced |
In order that layers can draw on the drawing area of a widget, they have to access the underlying pixmap and painter.
Qt_widget use as a backbuffer for drawing a pixmap defined inside the class, i.e. an object of type QPixmap. The QPixmap class is an off-screen pixel-based paint device. One common use of the QPixmap class is to enable smooth updating of widgets. The QPainter class paints on paint devices. There is an object of type QPainter defined in Qt_widget that uses as a paint device the QPixmap object.
|
| Returns the current pixmap. |
|
| Returns the current painter. |
advanced |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
The Qt_widget receives the events through virtual functions. This is the mechanism that Qt offers for dispaching events. This signals are called every time an event is dispatched to a virtual function. For example if Qt_widget receives mousePressEvent(QMouseEvent *e) emits s_mousePressEvent(e). This is very useful when you have only a pointer to Qt_widget. It is enough to connect this slot to your function to receive the event. | ||
|
| |
Triggered when a new object from a tool is received. The user should catch this signal if it's working with tools that provide CGAL objects as input. | ||
|
| |
Deprecated: Emitted in the redraw() function after the layers are drawn. | ||
|
| |
Emmitted in redraw() method before calling layer's redraw. | ||
|
| |
Emmitted in redraw() method after calling layer's redraw. | ||
|
| |
Emmitted each time (xmin, xmax) and (ymin, ymax) ranges are changed. |
The output operator is defined for all geometric classes in the CGAL kernel.
| ||
|
| |
| ||
|
| |
| ||
|
| |
| ||
|
| |
| ||
|
| |
| ||
|
| |
| ||
|
|
To use the other operators described you have to include the right header.
#include <CGAL/IO/Qt_widget_Polygon_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Min_ellipse_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Optimisation_ellipse_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Optimisation_circle_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Conic_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Triangulation_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Alpha_shape_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Delaunay_triangulation_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Constrained_triangulation_2.h>
| ||
|
|
#include <CGAL/IO/Qt_widget_Regular_triangulation_2.h>
| ||
|
|
A manipulator is an object which can be inserted in the Qt_widget , via the operator <<, to change the context for further drawing.
Here, we simply document the use of these operators which is all the user needs to know to modify the state of a stream.
|
| |
Sets the color used for background color. | ||
|
| |
Sets the color used for filling the objects. | ||
|
| |
Sets the width of the line for drawing objects. | ||
|
| |
Sets the size of the points. | ||
|
| Sets the state of Qt_widget concerning filling the objects to be false. |
|
| Sets the color used as the Qt_widget fillColor. |
|
| |
Sets the point style for Qt_widget. |
In the given example, that is found in tutorial/Qt_widget/tutorial1/tutorial1.C, we create an object of type Qt_widget and then we use the operators for output and the manipulators to show some of the widget's functionality.
#include <CGAL/Cartesian.h> #include <CGAL/Bbox_2.h> #include <list> #include <CGAL/Polygon_2.h> #include <CGAL/IO/Qt_widget_Polygon_2.h> #include <qapplication.h> #include <CGAL/IO/Qt_widget.h> typedef CGAL::Cartesian<int> Rep; typedef CGAL::Point_2<Rep> Point; typedef CGAL::Circle_2<Rep> Circle; typedef CGAL::Segment_2<Rep> Segment; typedef CGAL::Line_2<Rep> Line; typedef CGAL::Ray_2<Rep> Ray; typedef CGAL::Triangle_2<Rep> Triangle; typedef CGAL::Iso_rectangle_2<Rep> Cgal_Rectangle; typedef CGAL::Bbox_2 BBox; typedef std::list<Point> Container; typedef CGAL::Polygon_2<Rep,Container> Cgal_Polygon; int main( int argc, char **argv ) { QApplication app( argc, argv ); using namespace CGAL; CGAL::Qt_widget * W = new CGAL::Qt_widget(); app.setMainWidget( W ); W->resize(600, 600); W->set_window(0, 600, 0, 600); W->show(); //painting something on the screen W->lock(); *W << BackgroundColor(ORANGE) << RED << LineWidth(3) << PointSize(3) << PointStyle(DISC); *W << Segment(Point(10,20),Point(300,400)); *W << LineWidth(5) << GREEN << FillColor(BLACK) << Circle(Point(400,400),50*50); *W << LineWidth(1) << noFill << Circle(Point(300,300),300*300); *W << BLUE << LineWidth(2); *W << Segment(Point(200,200),Point(400,400)); *W << Segment(Point(200,400),Point(400,200)); W->setFilled(TRUE); *W << RED << Triangle(Point(150,300), Point(150,350), Point(100,325)); *W << FillColor(RED) << Cgal_Rectangle(Point(320,220), Point(350,240)); *W << DEEPBLUE << BBox(100,80,260,140); Cgal_Polygon p; p.push_back(Point(300,30)); p.push_back(Point(400,30)); p.push_back(Point(500,130)); p.push_back(Point(400,180)); p.push_back(Point(300,130)); *W << p; *W << Ray(Point(200,400), Point(180,430)) << Ray(Point(200,400), Point(180,370)); W->unlock(); return app.exec(); }