mirror of https://github.com/CGAL/cgal
rename
This commit is contained in:
parent
64387a24c4
commit
3fbb9adcbb
|
|
@ -0,0 +1,117 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_Get_line.h
|
||||
// package : QT_window
|
||||
// author(s) : Ursu Radu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifndef CGAL_QT_WIDGET_GET_LINE_H
|
||||
#define CGAL_QT_WIDGET_GET_LINE_H
|
||||
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/IO/Qt_Widget_tool.h>
|
||||
|
||||
#ifndef CGAL_QT_WIDGET_GET_POINT_BUTTON
|
||||
#define CGAL_QT_WIDGET_GET_POINT_BUTTON Qt::LeftButton
|
||||
#endif
|
||||
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template <class R>
|
||||
class Qt_widget_get_line : public Qt_widget_tool
|
||||
{
|
||||
public:
|
||||
typedef Point_2<R> Point;
|
||||
typedef Line_2<R> Line;
|
||||
typedef typename R::FT FT;
|
||||
|
||||
Qt_widget_get_line() {};
|
||||
|
||||
private:
|
||||
void mousePressEvent(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()));
|
||||
x1 = x;
|
||||
y1 = y;
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
firstpoint = TRUE;
|
||||
}
|
||||
};
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
|
||||
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 << Line(Point(x1,y1),Point(x2,y2));
|
||||
*widget << Line(Point(x1,y1),Point(x,y));
|
||||
widget->unlock();
|
||||
widget->setRasterOp(old);
|
||||
|
||||
//save the last coordinates to redraw the screen
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
|
||||
//widget->setRasterOp(old); //restore the initial mode
|
||||
}
|
||||
};
|
||||
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(Line(Point(x1,y1),Point(x,y))));
|
||||
firstpoint = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(crossCursor);
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
};
|
||||
|
||||
FT x1, y1;
|
||||
FT x2, y2;
|
||||
bool firstpoint;
|
||||
};//end class
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WINDOW_GET_SEGMENT_H
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_Get_point.h
|
||||
// package : QT_window
|
||||
// author(s) : Laurent Rineau
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifndef CGAL_QT_WIDGET_GET_POINT_H
|
||||
#define CGAL_QT_WIDGET_GET_POINT_H
|
||||
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/IO/Qt_Widget_tool.h>
|
||||
|
||||
#ifndef CGAL_QT_WIDGET_GET_POINT_BUTTON
|
||||
#define CGAL_QT_WIDGET_GET_POINT_BUTTON Qt::LeftButton
|
||||
#endif
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template <class R>
|
||||
class Qt_widget_get_point : public Qt_widget_tool
|
||||
{
|
||||
public:
|
||||
typedef typename R::Point_2 Point;
|
||||
typedef typename R::FT FT;
|
||||
|
||||
Qt_widget_get_point(const QCursor c=QCursor(Qt::crossCursor)) :
|
||||
cursor(c) {};
|
||||
|
||||
private:
|
||||
void mousePressEvent(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()));
|
||||
widget->new_object(make_object(Point(x, y)));
|
||||
}
|
||||
};
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(cursor);
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
};
|
||||
|
||||
QCursor cursor;
|
||||
};
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WINDOW_GET_POINT_H
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_Zoom.h
|
||||
// package : QT_window
|
||||
// author(s) : Radu Ursu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifndef CGAL_QT_WINDOW_HANDTOOL_H
|
||||
#define CGAL_QT_WINDOW_HANDTOOL_H
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <CGAL/IO/pixmaps/hand.xpm>
|
||||
#include <CGAL/IO/pixmaps/holddown.xpm>
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/IO/Qt_Widget_tool.h>
|
||||
#include <qrect.h>
|
||||
|
||||
|
||||
#ifndef CGAL_QT_WINDOW_GET_POINT_BUTTON
|
||||
#define CGAL_QT_WINDOW_GET_POINT_BUTTON Qt::LeftButton
|
||||
#endif
|
||||
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template <class R>
|
||||
class Qt_widget_handtool : public Qt_widget_tool
|
||||
{
|
||||
public:
|
||||
typedef Point_2<R> Point;
|
||||
typedef Segment_2<R> Segment;
|
||||
typedef typename R::FT FT;
|
||||
|
||||
Qt_widget_handtool() : wasrepainted(TRUE), on_first(FALSE){};
|
||||
|
||||
private:
|
||||
void widget_repainted(){
|
||||
wasrepainted = TRUE;
|
||||
};
|
||||
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if(e->button() == CGAL_QT_WINDOW_GET_POINT_BUTTON)
|
||||
{
|
||||
widget->setCursor(QCursor( QPixmap( (const char**)holddown_xpm)));
|
||||
if (!on_first){
|
||||
first_x = e->x();
|
||||
first_y = e->y();
|
||||
on_first = TRUE;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if(e->button() == CGAL_QT_WINDOW_GET_POINT_BUTTON)
|
||||
{
|
||||
widget->setCursor(QCursor( QPixmap( (const char**)hand_xpm)));
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y())),
|
||||
xfirst2 = static_cast<FT>(widget->x_real(first_x)),
|
||||
yfirst2 = static_cast<FT>(widget->y_real(first_y));
|
||||
|
||||
double xmin, xmax, ymin, ymax, distx, disty;
|
||||
if(x < xfirst2) {xmin = x; xmax = xfirst2;}
|
||||
else {xmin = xfirst2; xmax = x;};
|
||||
if(y < yfirst2) {ymin = y; ymax = yfirst2;}
|
||||
else {ymin = yfirst2; ymax = y;};
|
||||
distx = xfirst2 - x;
|
||||
disty = yfirst2 - y;
|
||||
widget->move_center(distx, disty);
|
||||
widget->redraw();
|
||||
emit(redraw());
|
||||
on_first = FALSE;
|
||||
}
|
||||
}
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
char tempc1[100], tempc2[20];
|
||||
if(on_first)
|
||||
{
|
||||
double
|
||||
x = e->x(),
|
||||
y = e->y();
|
||||
|
||||
RasterOp old = widget->rasterOp(); //save the initial raster mode
|
||||
widget->setRasterOp(XorROP);
|
||||
widget->lock();
|
||||
*widget << CGAL::GRAY;
|
||||
if(!wasrepainted) {
|
||||
CGAL_CLIB_STD::sprintf(tempc1, "dx=%f", widget->x_real(x2 - first_x));
|
||||
CGAL_CLIB_STD::sprintf(tempc2, ", dy=%f", widget->x_real(y2 - first_y));
|
||||
strcat(tempc1, tempc2);
|
||||
widget->painter().drawLine(first_x, first_y, x2, y2);
|
||||
*widget << CGAL::GREEN;
|
||||
widget->painter().drawText(x2, y2, tempc1, 25);
|
||||
*widget << CGAL::GRAY;
|
||||
}
|
||||
CGAL_CLIB_STD::sprintf(tempc1, "dx=%f", widget->x_real(x - first_x));
|
||||
CGAL_CLIB_STD::sprintf(tempc2, ", dy=%f", widget->x_real(y - first_y));
|
||||
strcat(tempc1, tempc2);
|
||||
widget->painter().drawLine(first_x, first_y, x, y);
|
||||
*widget << CGAL::GREEN;
|
||||
widget->painter().drawText(x, y, tempc1, 25);
|
||||
widget->unlock();
|
||||
widget->setRasterOp(old);
|
||||
|
||||
//save the last coordinates to redraw the screen
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
wasrepainted = FALSE;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(QCursor( QPixmap( (const char**)hand_xpm)));
|
||||
wasrepainted = TRUE;
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
};
|
||||
|
||||
double first_x, first_y;
|
||||
double x2, y2;
|
||||
bool wasrepainted;
|
||||
bool on_first;
|
||||
};//end class
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WINDOW_GET_SEGMENT_H
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_MovePoint.h
|
||||
// package : QT_window
|
||||
// author(s) : Radu Ursu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifndef CGAL_QT_WIDGET_MOVEPOINT_H
|
||||
#define CGAL_QT_WIDGET_MOVEPOINT_H
|
||||
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/IO/Qt_Widget_tool.h>
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qpopupmenu.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
class Qt_widget_movepoint_helper : public Qt_widget_tool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual void delete_pointi(){};
|
||||
virtual void move_pointi(){};
|
||||
|
||||
public slots:
|
||||
void delete_point();
|
||||
void move_point();
|
||||
virtual void widget_repainted() {};
|
||||
signals:
|
||||
void redraw(); //emited when this tool need to repaint the screen
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class Qt_widget_movepoint : public Qt_widget_movepoint_helper
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename T::Point Point;
|
||||
typedef typename T::Segment Segment;
|
||||
typedef typename T::Face_handle Face_handle;
|
||||
typedef typename T::Vertex_handle Vertex_handle;
|
||||
typedef typename T::Geom_traits::FT FT;
|
||||
|
||||
protected:
|
||||
FT first_x, first_y;
|
||||
FT x2, y2;
|
||||
bool wasrepainted;
|
||||
bool on_first;
|
||||
Vertex_handle current_v; //the vertex that will be process
|
||||
Point old_point;
|
||||
T *dt;
|
||||
QPopupMenu *popup1;
|
||||
|
||||
public:
|
||||
Qt_widget_movepoint() : wasrepainted(TRUE), on_first(FALSE)
|
||||
{
|
||||
popup1 = new QPopupMenu( widget, 0);
|
||||
popup1->insertItem("Delete Point", this, SLOT(delete_point()));
|
||||
popup1->insertItem("Move Point", this, SLOT(move_point()));
|
||||
};
|
||||
|
||||
void set_Delaunay (T *t) {dt = t;}
|
||||
|
||||
private:
|
||||
void widget_repainted(){
|
||||
wasrepainted = TRUE;
|
||||
};
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if(e->button() == Qt::LeftButton && on_first)
|
||||
{
|
||||
on_first = FALSE;
|
||||
}
|
||||
if(e->button() == Qt::RightButton)
|
||||
{
|
||||
if (dt->dimension()<2) return;
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
|
||||
Point p(x, y);
|
||||
Vertex_handle v = dt->nearest_vertex(p);
|
||||
|
||||
RasterOp old = widget->rasterOp(); //save the initial raster mode
|
||||
widget->setRasterOp(XorROP);
|
||||
widget->lock();
|
||||
*widget << CGAL::GREEN << CGAL::PointSize (7) << CGAL::PointStyle (CGAL::DISC);
|
||||
if(!wasrepainted)
|
||||
*widget << old_point;
|
||||
*widget << v->point();
|
||||
widget->unlock();
|
||||
widget->setRasterOp(old);
|
||||
|
||||
popup1->popup(widget->mapToGlobal(e->pos()));
|
||||
|
||||
old_point = v->point();
|
||||
current_v = v;
|
||||
wasrepainted = FALSE;
|
||||
on_first = FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
};
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if(on_first)
|
||||
{
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
|
||||
*widget << CGAL::GREEN << CGAL::PointSize (5) << CGAL::PointStyle (CGAL::DISC);
|
||||
if(!wasrepainted)
|
||||
*widget << old_point;
|
||||
*widget << Point(x, y);
|
||||
dt->remove(current_v);
|
||||
current_v = dt->insert(Point(x, y));
|
||||
widget->redraw(); //redraw the scenes
|
||||
//emit(redraw());
|
||||
old_point = Point(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(crossCursor);
|
||||
wasrepainted = TRUE;
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
};
|
||||
|
||||
void delete_pointi(){
|
||||
dt->remove(current_v);
|
||||
widget->redraw(); //redraw the scenes
|
||||
emit(redraw());
|
||||
};
|
||||
void move_pointi(){
|
||||
on_first = TRUE;
|
||||
};
|
||||
|
||||
};//end class
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WINDOW_GET_SEGMENT_H
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_toolbar.h
|
||||
// package : QT_window
|
||||
// author(s) : Ursu Radu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
|
||||
#ifndef CGAL_QT_WIDGET_STANDARD_TOOLBAR_H
|
||||
#define CGAL_QT_WIDGET_STANDARD_TOOLBAR_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
|
||||
|
||||
// TODO: check if some of those includes shouldn't be in the .C file
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/IO/Qt_Widget_Zoom.h>
|
||||
#include <CGAL/IO/Qt_Widget_Zoomrect.h>
|
||||
#include <CGAL/IO/Qt_Widget_Handtool.h>
|
||||
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qtoolbar.h>
|
||||
#include <qmainwindow.h>
|
||||
|
||||
typedef double Coord_type;
|
||||
typedef CGAL::Cartesian<Coord_type> Rp;
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
class Standard_toolbar : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Standard_toolbar(Qt_widget *w, QMainWindow *mw);
|
||||
~Standard_toolbar()
|
||||
{
|
||||
delete maintoolbar;
|
||||
};
|
||||
QToolBar* toolbar(){return maintoolbar;}
|
||||
|
||||
|
||||
private slots:
|
||||
|
||||
void toggle_button();
|
||||
|
||||
void toolregion();
|
||||
void zoomin();
|
||||
void zoomout();
|
||||
void zoominrect();
|
||||
void notool();
|
||||
void handtool();
|
||||
|
||||
private:
|
||||
QToolBar *maintoolbar;
|
||||
QToolButton *but[10];
|
||||
Qt_widget *widget;
|
||||
int activebutton;
|
||||
bool is_active;
|
||||
void setActiveButton(int i);
|
||||
int nr_of_buttons;
|
||||
|
||||
CGAL::Qt_widget_zoom zoombut;
|
||||
CGAL::Qt_widget_zoomrect zoomrectbut;
|
||||
CGAL::Qt_widget_handtool<Rp> handtoolbut;
|
||||
};//end class
|
||||
|
||||
};//end namespace
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_tool.h
|
||||
// package : QT_window
|
||||
// author(s) : Laurent Rineau
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifndef CGAL_QT_WINDOW_TOOL_H
|
||||
#define CGAL_QT_WINDOW_TOOL_H
|
||||
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/Object.h>
|
||||
#include <qobject.h>
|
||||
#include <qcursor.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
class Qt_widget_tool : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
||||
Qt_widget_tool();
|
||||
|
||||
inline bool is_attached() const
|
||||
{ return (widget==0); };
|
||||
|
||||
// Event handlers
|
||||
virtual void mousePressEvent(QMouseEvent *) {} ;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *) {};
|
||||
virtual void wheelEvent(QMouseEvent *) {};
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *) {};
|
||||
virtual void mouseMoveEvent(QMouseEvent *) {};
|
||||
virtual void keyPressEvent(QKeyEvent *) {};
|
||||
virtual void keyReleaseEvent(QKeyEvent *) {};
|
||||
virtual void enterEvent(QEvent *) {};
|
||||
virtual void leaveEvent(QEvent *) {};
|
||||
|
||||
signals:
|
||||
void redraw(); //this signal is emited when the tool needs to repaint the widget
|
||||
|
||||
public slots:
|
||||
virtual void widget_repainted() {}; //called every time widget been repainted
|
||||
|
||||
protected:
|
||||
virtual void attaching() {};
|
||||
virtual void detaching() {};
|
||||
|
||||
Qt_widget *widget;
|
||||
QCursor oldcursor;
|
||||
private:
|
||||
// attach a Qt_widget to the tool
|
||||
void attach(Qt_widget *w);
|
||||
// detach it
|
||||
void detach();
|
||||
friend class Qt_widget;
|
||||
};
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WINDOW_TOOL_H
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_Zoom.h
|
||||
// package : QT_window
|
||||
// author(s) : Radu Ursu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
// TODO: put almost everything in a .C file
|
||||
|
||||
#ifndef CGAL_QT_WINDOW_ZOOM_H
|
||||
#define CGAL_QT_WINDOW_ZOOM_H
|
||||
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/IO/Qt_Widget_tool.h>
|
||||
#include <qcolor.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
class Qt_widget_zoom : public Qt_widget_tool
|
||||
{
|
||||
private:
|
||||
int x2, y2;
|
||||
bool circle_already_drawn;
|
||||
bool old_mouse_tracking;
|
||||
|
||||
public:
|
||||
Qt_widget_zoom() : circle_already_drawn(false) {};
|
||||
|
||||
void draw_circle(int x,int y)
|
||||
{
|
||||
const int
|
||||
d=100, // diameter
|
||||
r=50; // radius (should be d/2 :-)
|
||||
|
||||
RasterOp oldRasterOp = widget->rasterOp(); //save the initial raster mode
|
||||
widget->setRasterOp(XorROP);
|
||||
QColor oldColor=widget->color(); // save the initial color
|
||||
widget->setColor(Qt::green);
|
||||
widget->painter().drawEllipse(x-r, y-r, d, d);
|
||||
widget->setColor(oldColor);
|
||||
widget->setRasterOp(oldRasterOp);
|
||||
widget->do_paint();
|
||||
};
|
||||
|
||||
void leaveEvent(QEvent*)
|
||||
{
|
||||
if(circle_already_drawn)
|
||||
draw_circle(x2,y2);
|
||||
circle_already_drawn=false;
|
||||
};
|
||||
|
||||
void widget_repainted(){
|
||||
circle_already_drawn=false;
|
||||
};
|
||||
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
const double ratios=2.0;
|
||||
double
|
||||
x=widget->x_real(e->x()),
|
||||
y=widget->y_real(e->y());
|
||||
|
||||
if(e->button() == Qt::LeftButton)
|
||||
widget->zoom_in(ratios, x, y);
|
||||
if(e->button() == Qt::RightButton)
|
||||
widget->zoom_out(ratios, x, y);
|
||||
|
||||
widget->redraw();
|
||||
emit(redraw());
|
||||
};
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
int
|
||||
x = e->x(),
|
||||
y = e->y();
|
||||
|
||||
widget->lock();
|
||||
draw_circle(x,y); // draw the new circle
|
||||
if(circle_already_drawn) // erase the old one if needed
|
||||
draw_circle(x2,y2);
|
||||
widget->unlock();
|
||||
|
||||
//save the last coordinates to redraw the screen
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
circle_already_drawn=true;
|
||||
};
|
||||
|
||||
void attaching()
|
||||
{
|
||||
old_mouse_tracking=widget->hasMouseTracking();
|
||||
widget->setMouseTracking(TRUE);
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(crossCursor);
|
||||
circle_already_drawn=false;
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
if(circle_already_drawn)
|
||||
draw_circle(x2,y2); // erase the circle if needed
|
||||
widget->setCursor(oldcursor);
|
||||
widget->setMouseTracking(old_mouse_tracking);
|
||||
};
|
||||
};//end class
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WINDOW_ZOOM_H
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// Copyright (c) 1997-2000 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_Zoom.h
|
||||
// package : QT_window
|
||||
// author(s) : Radu Ursu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifndef CGAL_QT_WINDOW_ZOOMRECT_H
|
||||
#define CGAL_QT_WINDOW_ZOOMRECT_H
|
||||
|
||||
#include <CGAL/IO/Qt_Widget.h>
|
||||
#include <CGAL/IO/Qt_Widget_tool.h>
|
||||
#include <qrect.h>
|
||||
|
||||
|
||||
|
||||
#ifndef CGAL_QT_WINDOW_ZOOMRECT_BUTTON
|
||||
#define CGAL_QT_WINDOW_ZOOMRECT_BUTTON Qt::LeftButton
|
||||
#endif
|
||||
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
class Qt_widget_zoomrect : public Qt_widget_tool
|
||||
{
|
||||
public:
|
||||
int first_x, first_y, x2, y2;
|
||||
bool widgetrepainted;
|
||||
bool on_first;
|
||||
|
||||
Qt_widget_zoomrect() : widgetrepainted(TRUE), on_first(FALSE) {};
|
||||
|
||||
private:
|
||||
void widget_repainted(){
|
||||
widgetrepainted = TRUE;
|
||||
};
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if(e->button() == CGAL_QT_WINDOW_ZOOMRECT_BUTTON)
|
||||
{
|
||||
if (!on_first)
|
||||
{
|
||||
first_x = e->x();
|
||||
first_y = e->y();
|
||||
on_first = TRUE;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if(e->button() == CGAL_QT_WINDOW_ZOOMRECT_BUTTON)
|
||||
{
|
||||
double
|
||||
x=widget->x_real(e->x()),
|
||||
y=widget->y_real(e->y()),
|
||||
xfirst2 = widget->x_real(first_x),
|
||||
yfirst2 = widget->y_real(first_y);
|
||||
|
||||
double xmin, xmax, ymin, ymax;
|
||||
if(x < xfirst2) {xmin = x; xmax = xfirst2;}
|
||||
else {xmin = xfirst2; xmax = x;};
|
||||
if(y < yfirst2) {ymin = y; ymax = yfirst2;}
|
||||
else {ymin = yfirst2; ymax = y;};
|
||||
|
||||
widget->set_window(xmin, xmax, ymin, ymax);
|
||||
widget->redraw();
|
||||
emit(redraw());
|
||||
on_first = FALSE;
|
||||
}
|
||||
}
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if(on_first)
|
||||
{
|
||||
int
|
||||
x = e->x(),
|
||||
y = e->y();
|
||||
|
||||
RasterOp old = widget->rasterOp(); //save the initial raster mode
|
||||
QColor old_color=widget->color();
|
||||
widget->setRasterOp(XorROP);
|
||||
widget->lock();
|
||||
widget->setColor(Qt::green);
|
||||
if(!widgetrepainted)
|
||||
widget->painter().drawRect(first_x, first_y, x2 - first_x, y2 - first_y);
|
||||
widget->painter().drawRect(first_x, first_y, x - first_x, y - first_y);
|
||||
widget->unlock();
|
||||
widget->setColor(old_color);
|
||||
widget->setRasterOp(old);
|
||||
|
||||
//save the last coordinates to redraw the screen
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
widgetrepainted = FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(crossCursor);
|
||||
widgetrepainted = TRUE;
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
|
||||
RasterOp old = widget->rasterOp(); //save the initial raster mode
|
||||
widget->setRasterOp(XorROP);
|
||||
widget->lock();
|
||||
*widget << CGAL::GREEN;
|
||||
widget->unlock();
|
||||
widget->setRasterOp(old);
|
||||
};
|
||||
};//end class
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WINDOW_GET_SEGMENT_H
|
||||
Loading…
Reference in New Issue