mirror of https://github.com/CGAL/cgal
The segment is constructed by clicking 2 times over the widget.
Not by draging and drop.
This commit is contained in:
parent
f7d22356c9
commit
b22e27ef54
|
|
@ -39,76 +39,92 @@ public:
|
|||
typedef Segment_2<R> Segment;
|
||||
typedef typename R::FT FT;
|
||||
|
||||
Qt_widget_get_segment() {};
|
||||
Qt_widget_get_segment() : firstpoint(false),
|
||||
firsttime(true){};
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if(e->button() == CGAL_QT_WIDGET_GET_POINT_BUTTON)
|
||||
if(e->button() == CGAL_QT_WIDGET_GET_POINT_BUTTON && !firstpoint)
|
||||
{
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
x1 = x;
|
||||
y1 = y;
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
firstpoint = TRUE;
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
x1 = x;
|
||||
y1 = y;
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
firstpoint = TRUE;
|
||||
} else if(e->button() == CGAL_QT_WIDGET_GET_POINT_BUTTON){
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
if(x1!=x || y1!=y) {
|
||||
widget->new_object(make_object(Segment(Point(x1,y1),Point(x,y))));
|
||||
firstpoint = FALSE;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void leaveEvent(QEvent *e)
|
||||
{
|
||||
if(firstpoint)
|
||||
{
|
||||
RasterOp old_raster = widget->rasterOp();//save the initial raster mode
|
||||
QColor old_color = widget->color();
|
||||
widget->lock();
|
||||
widget->setRasterOp(XorROP);
|
||||
*widget << CGAL::GREEN;
|
||||
*widget << Segment(Point(x1,y1),Point(x2,y2));
|
||||
widget->setRasterOp(old_raster);
|
||||
widget->setColor(old_color);
|
||||
widget->unlock();
|
||||
firsttime = true;
|
||||
}
|
||||
}
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if(firstpoint)
|
||||
{
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
RasterOp old_raster = widget->rasterOp();//save the initial raster mode
|
||||
QColor old_color = widget->color();
|
||||
widget->setRasterOp(XorROP);
|
||||
widget->lock();
|
||||
*widget << CGAL::GREEN;
|
||||
if(!firsttime)
|
||||
*widget << Segment(Point(x1,y1),Point(x2,y2));
|
||||
*widget << Segment(Point(x1,y1),Point(x,y));
|
||||
widget->unlock();
|
||||
widget->setRasterOp(old_raster);
|
||||
widget->setColor(old_color);
|
||||
|
||||
if(firstpoint==TRUE)
|
||||
{
|
||||
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
RasterOp old = widget->rasterOp(); //save the initial raster mode
|
||||
|
||||
widget->setRasterOp(XorROP);
|
||||
widget->lock();
|
||||
*widget << CGAL::GREEN;
|
||||
*widget << Segment(Point(x1,y1),Point(x2,y2));
|
||||
*widget << Segment(Point(x1,y1),Point(x,y));
|
||||
widget->unlock();
|
||||
widget->setRasterOp(old);
|
||||
|
||||
//save the last coordinates to redraw the screen
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
//save the last coordinates to redraw the screen
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
firsttime = false;
|
||||
}
|
||||
};
|
||||
void mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if(e->button() == CGAL_QT_WIDGET_GET_POINT_BUTTON)
|
||||
{
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
if(x1!=x || y1!=y)
|
||||
widget->new_object(make_object(Segment(Point(x1,y1),Point(x,y))));
|
||||
firstpoint = FALSE;
|
||||
}
|
||||
}
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(crossCursor);
|
||||
};
|
||||
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(crossCursor);
|
||||
};
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
firstpoint = false;
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
//widget->setMouseTracking(FALSE);
|
||||
};
|
||||
|
||||
FT x1, y1;
|
||||
FT x2, y2;
|
||||
bool firstpoint;
|
||||
FT x1, //the X of the first point
|
||||
y1; //the Y of the first point
|
||||
FT x2, //the old second point's X
|
||||
y2; //the old second point's Y
|
||||
bool firstpoint, //true if the user left clicked once
|
||||
firsttime; //true if the line is not drawn
|
||||
};//end class
|
||||
|
||||
} // namespace CGAL
|
||||
|
|
|
|||
Loading…
Reference in New Issue