mirror of https://github.com/CGAL/cgal
parent
0ed9eba912
commit
c3da7d5a3e
|
|
@ -0,0 +1,34 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// 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 : demo/Qt_widget/Max_k-gon/Qt_widget_move_point.C
|
||||
// package : QT_window
|
||||
// author(s) : Radu Ursu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifdef CGAL_USE_QT
|
||||
|
||||
#include "Qt_widget_move_list_point.h"
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
void Qt_widget_movepoint_helper::delete_point() { delete_pointi(); };
|
||||
void Qt_widget_movepoint_helper::move_point() { move_pointi(); };
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#include "Qt_widget_move_list_point.moc"
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
// ============================================================================
|
||||
//
|
||||
// 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 : demo/Qt_widget/Max_k-gon/Qt_widget_move_list_point.h
|
||||
// package : Qt_widget
|
||||
// author(s) : Radu Ursu
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
#ifndef CGAL_QT_WIDGET_MOVE_LIST_POINT_H
|
||||
#define CGAL_QT_WIDGET_MOVE_LIST_POINT_H
|
||||
|
||||
#include <CGAL/IO/Qt_widget.h>
|
||||
#include <CGAL/IO/Qt_widget_tool.h>
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qpopupmenu.h>
|
||||
#include <qmessagebox.h>
|
||||
|
||||
#include <CGAL/squared_distance_2.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();
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class R>
|
||||
class Qt_widget_move_list_point : public Qt_widget_movepoint_helper
|
||||
{
|
||||
public:
|
||||
typedef typename R::Point_2 Point;
|
||||
typedef typename R::FT FT;
|
||||
bool on_first, //if the user choosed something from the popup
|
||||
wasrepainted;//true when the widget was repainted
|
||||
Point old_point, //the last point stored in the list
|
||||
current_v; //the current point
|
||||
QPopupMenu *popup1;
|
||||
QCursor cursor;
|
||||
std::list<Point>* l_of_p;
|
||||
|
||||
//constructor
|
||||
Qt_widget_move_list_point(std::list<Point>* l, const QCursor c=QCursor(Qt::crossCursor)) :
|
||||
cursor(c), l_of_p(l), on_first(FALSE)
|
||||
{
|
||||
popup1 = new QPopupMenu( widget, 0);
|
||||
popup1->insertItem("Delete Point", this, SLOT(delete_point()));
|
||||
popup1->insertItem("Move Point", this, SLOT(move_point()));
|
||||
};
|
||||
|
||||
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(l_of_p->empty())
|
||||
QMessageBox::warning( widget, "There are no points in the list!", "Generate some points first or add it with the input tool before using this tool!");
|
||||
else{
|
||||
FT
|
||||
x=static_cast<FT>(widget->x_real(e->x())),
|
||||
y=static_cast<FT>(widget->y_real(e->y()));
|
||||
Point p(x, y);
|
||||
Point closest_p; //this point is the closest one to the mouse coordinates
|
||||
FT min_dist;
|
||||
std::list<Point>::const_iterator it = l_of_p->begin();
|
||||
min_dist = squared_distance(p, (*it));
|
||||
while(it!=l_of_p->end())
|
||||
{
|
||||
if (min_dist > squared_distance(p, (*it)))
|
||||
{
|
||||
min_dist = squared_distance(p, (*it));
|
||||
closest_p = (*it);
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
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 << closest_p;
|
||||
widget->unlock();
|
||||
widget->setRasterOp(old);
|
||||
popup1->popup(widget->mapToGlobal(e->pos()));
|
||||
old_point = closest_p;
|
||||
current_v = closest_p;
|
||||
wasrepainted = FALSE;
|
||||
on_first = FALSE;
|
||||
}
|
||||
}
|
||||
};
|
||||
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);
|
||||
l_of_p->remove(old_point);
|
||||
l_of_p->push_back(Point(x, y));
|
||||
widget->redraw(); //redraw the scenes
|
||||
old_point = Point(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
void attaching()
|
||||
{
|
||||
oldcursor = widget->cursor();
|
||||
widget->setCursor(cursor);
|
||||
};
|
||||
|
||||
void detaching()
|
||||
{
|
||||
widget->setCursor(oldcursor);
|
||||
};
|
||||
|
||||
void delete_pointi(){
|
||||
l_of_p->remove(current_v);
|
||||
widget->redraw(); //redraw the scenes
|
||||
};
|
||||
void move_pointi(){
|
||||
on_first = TRUE;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WIDGET_MOVE_LIST_POINT_H
|
||||
|
|
@ -8,8 +8,8 @@
|
|||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : src/Qt_Window_toolbar.C
|
||||
// package : QT_window
|
||||
// file : demo/Qt_widget/Max_k-gon/Qt_widget_toolbar.C
|
||||
// package : Qt_widget
|
||||
// author(s) : Radu Ursu
|
||||
// release :
|
||||
// release_date :
|
||||
|
|
@ -30,9 +30,10 @@
|
|||
|
||||
|
||||
namespace CGAL {
|
||||
Tools_toolbar::Tools_toolbar(Qt_widget *w, QMainWindow *mw, std::list<Point> &l1) :
|
||||
my_toolbar_list(l1)
|
||||
Tools_toolbar::Tools_toolbar(Qt_widget *w, QMainWindow *mw, std::list<Point> *l1)
|
||||
{
|
||||
|
||||
move_deletebut = new CGAL::Qt_widget_move_list_point<Rp>(l1);
|
||||
//when it is created, the toolbar has 0 buttons
|
||||
nr_of_buttons = 0;
|
||||
//set the widget
|
||||
|
|
@ -65,10 +66,19 @@ namespace CGAL {
|
|||
maintoolbar,
|
||||
"Point Tool");
|
||||
|
||||
|
||||
but[1]->setToggleButton(TRUE);
|
||||
but[2] = new QToolButton(QPixmap( (const char**)movepoint_xpm ),
|
||||
"Move/Delete Point Tool",
|
||||
0,
|
||||
this,
|
||||
SLOT(move_deletetool()),
|
||||
maintoolbar,
|
||||
"Move/Delete Point Tool");
|
||||
|
||||
nr_of_buttons = 2;
|
||||
|
||||
but[1]->setToggleButton(TRUE);
|
||||
but[2]->setToggleButton(TRUE);
|
||||
|
||||
nr_of_buttons = 3;
|
||||
|
||||
connect(w, SIGNAL(detached_tool()), this, SLOT(toggle_button()));
|
||||
};
|
||||
|
|
@ -97,6 +107,21 @@ namespace CGAL {
|
|||
widget->detach_current_tool();
|
||||
}
|
||||
}
|
||||
|
||||
void Tools_toolbar::move_deletetool()
|
||||
{
|
||||
if (but[2]->isOn())
|
||||
{
|
||||
widget->attach(*move_deletebut);
|
||||
activebutton = 2;
|
||||
is_active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_active = false;
|
||||
widget->detach_current_tool();
|
||||
}
|
||||
}
|
||||
|
||||
void Tools_toolbar::notool()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// file : include/CGAL/IO/Qt_Window_toolbar.h
|
||||
// package : QT_window
|
||||
// file : demo/Qt_widget/Max_k-gon/Qt_widget_toolbar.h
|
||||
// package : Qt_widget
|
||||
// author(s) : Ursu Radu
|
||||
// release :
|
||||
// release_date :
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
// 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_get_point.h>
|
||||
#include "Qt_widget_move_list_point.h"
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qtoolbutton.h>
|
||||
|
|
@ -44,7 +45,7 @@ class Tools_toolbar : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Tools_toolbar(Qt_widget *w, QMainWindow *mw, std::list<Point> &l1);
|
||||
Tools_toolbar(Qt_widget *w, QMainWindow *mw, std::list<Point> *l1);
|
||||
~Tools_toolbar()
|
||||
{
|
||||
delete maintoolbar;
|
||||
|
|
@ -59,6 +60,7 @@ private slots:
|
|||
void get_new_object(CGAL::Object obj) { emit(new_object(obj)); }
|
||||
|
||||
void pointtool();
|
||||
void move_deletetool();
|
||||
void notool();
|
||||
|
||||
void toggle_button();
|
||||
|
|
@ -72,9 +74,9 @@ private:
|
|||
void setActiveButton(int i);
|
||||
int nr_of_buttons;
|
||||
|
||||
std::list<Point> my_toolbar_list;
|
||||
|
||||
CGAL::Qt_widget_get_point<Rp> pointbut;
|
||||
CGAL::Qt_widget_get_point<Rp> pointbut;
|
||||
CGAL::Qt_widget_move_list_point<Rp> *move_deletebut;
|
||||
};//end class
|
||||
|
||||
};//end namespace
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ public:
|
|||
|
||||
//the new tools toolbar
|
||||
setUsesBigPixmaps(TRUE);
|
||||
newtoolbar = new CGAL::Tools_toolbar(&win, this, list_of_points);
|
||||
newtoolbar = new CGAL::Tools_toolbar(&win, this, &list_of_points);
|
||||
//the standard toolbar
|
||||
stoolbar = new CGAL::Standard_toolbar (&win, this);
|
||||
this->addToolBar(stoolbar->toolbar(), Top, FALSE);
|
||||
|
|
|
|||
Loading…
Reference in New Issue