mirror of https://github.com/CGAL/cgal
Laurent Rineau 2001/12/20:
~~~~~~~~~~~~~~~~~~~~~~~~~ Change of set_window stuff. init, initialized, isInitialized have been removed. set_window now has a fifth optionnal argument that decides if the ranges are const. By default they are not and the *scales* are const.
This commit is contained in:
parent
b4b6d932a7
commit
8bdf64d015
|
|
@ -129,12 +129,15 @@ class MyWindow : public QMainWindow
|
|||
public:
|
||||
MyWindow(int x, int y): win(this) {
|
||||
setCentralWidget(&win);
|
||||
win.set_window(-1.1, 1.1, -1.1, 1.1, true);
|
||||
point_factory = new CGAL::Qt_widget_get_point<Rep>();
|
||||
connect(&win, SIGNAL(new_cgal_object(CGAL::Object)), this,
|
||||
SLOT(new_point(CGAL::Object)));
|
||||
win << point_factory;
|
||||
connect(&win, SIGNAL(mousePressed(QMouseEvent*)), this,
|
||||
SLOT(mousePressedOnWin(QMouseEvent*)));
|
||||
|
||||
// TODO: change this connect when Qt_scenes_widget come back.
|
||||
connect(&win, SIGNAL(redrawed()), this, SLOT(redrawWin()));
|
||||
statusBar();
|
||||
|
||||
|
|
@ -156,8 +159,6 @@ public:
|
|||
void init_paint()
|
||||
{
|
||||
win.lock();
|
||||
win.set_window(-1.1, 1.1, -1.1, 1.1); // we need to put it there because Qt
|
||||
// send resizeEvent only on show.
|
||||
load_file("data/fish");
|
||||
win.unlock();
|
||||
statusBar()->message("Enter points with the left button");
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ public:
|
|||
~Qt_widget() {};
|
||||
|
||||
// initialization of coordinates system
|
||||
void set_window(double x_min, double x_max, double y_min, double y_max);
|
||||
bool isInitialized() const; // tell if init has been called
|
||||
void set_window(double x_min, double x_max, double y_min, double y_max,
|
||||
bool const_ranges = false);
|
||||
void zoom_in(double ratio);
|
||||
void zoom_out(double ratio);
|
||||
void zoom_in(double ratio, double xc, double yc);
|
||||
|
|
@ -70,7 +70,6 @@ public:
|
|||
set_scale_center(xcentre, ycentre);
|
||||
};
|
||||
|
||||
|
||||
// painting system
|
||||
inline QPainter& painter() { return paint; };
|
||||
inline QPixmap& get_pixmap() { return pixmap; };
|
||||
|
|
@ -199,8 +198,6 @@ public slots:
|
|||
void remove_scene(Qt_scene* s);
|
||||
|
||||
private:
|
||||
void initialize(); // initialize initiale dimensions
|
||||
bool initialized;
|
||||
void set_scales(); // set xscal and yscal
|
||||
void set_scale_center(double xc, double yc);
|
||||
double xcentre, ycentre; //the center of the axex
|
||||
|
|
@ -222,6 +219,7 @@ private:
|
|||
|
||||
double xmin, xmax, ymin, ymax; // real dimensions
|
||||
double xscal, yscal; // scalings int/double
|
||||
bool constranges; // tell if the ranges should be const
|
||||
|
||||
// current tool
|
||||
bool _has_tool;
|
||||
|
|
@ -231,12 +229,6 @@ private:
|
|||
std::list<Qt_scene*> qt_scenes;
|
||||
};//end Qt_widget class
|
||||
|
||||
inline
|
||||
bool Qt_widget:: isInitialized() const
|
||||
{
|
||||
return initialized;
|
||||
}
|
||||
|
||||
// manipulators
|
||||
// ~~~~~~~~~~~~
|
||||
// single manipulators
|
||||
|
|
|
|||
|
|
@ -28,40 +28,50 @@
|
|||
namespace CGAL {
|
||||
|
||||
Qt_widget::Qt_widget(QWidget *parent, const char *name) :
|
||||
QWidget(parent, name), initialized(false), Locked(0), _pointSize(4),
|
||||
QWidget(parent, name), Locked(0), _pointSize(4),
|
||||
_pointStyle(DISC), _has_tool(false), current_tool(0)
|
||||
{
|
||||
setCaption("CGAL::Qt_widget");
|
||||
initialize();
|
||||
paint.begin(&pixmap);
|
||||
setBackgroundColor(Qt::white);
|
||||
paint.setPen(QPen(Qt::black,2));
|
||||
clear();
|
||||
}
|
||||
|
||||
void Qt_widget::initialize()
|
||||
{
|
||||
// initialize ranges and scales
|
||||
xmin=0;
|
||||
xmax=width()-1;
|
||||
ymin=0;
|
||||
ymax=height()-1;
|
||||
xcentre = xmin + (xmax - xmin)/2;
|
||||
ycentre = ymin + (ymax - ymin)/2;
|
||||
constranges=false;
|
||||
set_scales();
|
||||
|
||||
// initialize the pixmap and the painter
|
||||
pixmap.resize(size());
|
||||
initialized=true;
|
||||
paint.begin(&pixmap);
|
||||
|
||||
// set properties
|
||||
setBackgroundColor(Qt::white);
|
||||
paint.setPen(QPen(Qt::black,2));
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
void Qt_widget::set_scales()
|
||||
{
|
||||
double
|
||||
tempmin = min(width(), height()),
|
||||
tempmax = max(xmax-xmin, ymax-ymin);
|
||||
|
||||
xscal=(tempmin - 1)/(tempmax);
|
||||
yscal=(tempmin - 1)/(tempmax);
|
||||
set_scale_center(xcentre, ycentre);
|
||||
if(!constranges)
|
||||
{
|
||||
double
|
||||
tempmin = min(width(), height()),
|
||||
tempmax = max(xmax-xmin, ymax-ymin);
|
||||
|
||||
xscal=yscal=(tempmin - 1)/(tempmax);
|
||||
set_scale_center(xcentre, ycentre);
|
||||
}
|
||||
else
|
||||
{
|
||||
xscal=width()/(xmax-xmin);
|
||||
yscal=height()/(ymax-ymin);
|
||||
}
|
||||
}
|
||||
|
||||
void Qt_widget::set_scale_center(double xc, double yc)
|
||||
{
|
||||
xmin = xc - (width()/xscal)/2;
|
||||
|
|
@ -81,19 +91,7 @@ void Qt_widget::resizeEvent(QResizeEvent *e)
|
|||
|
||||
paint.end(); // end painting on pixmap
|
||||
|
||||
/*
|
||||
the only difference between an initialized Qt_widget and a
|
||||
non-initialized one is here:
|
||||
if the widget has been initialized, a resizeEvent modifies the
|
||||
scalings where as it modifies z_min(), z_max() dimensions if not.
|
||||
*/
|
||||
if (!isInitialized())
|
||||
initialize();
|
||||
else
|
||||
{
|
||||
pixmap.resize(size());
|
||||
//set_scales();
|
||||
}
|
||||
pixmap.resize(size());
|
||||
paint.begin(&pixmap); // begin again painting on pixmap
|
||||
|
||||
// restore paint state
|
||||
|
|
@ -104,7 +102,10 @@ void Qt_widget::resizeEvent(QResizeEvent *e)
|
|||
|
||||
clear();
|
||||
|
||||
set_scale_center(xcentre, ycentre);
|
||||
if (constranges)
|
||||
set_scales();
|
||||
else
|
||||
set_scale_center(xcentre, ycentre);
|
||||
emit(resized());
|
||||
redraw();
|
||||
}
|
||||
|
|
@ -223,16 +224,18 @@ void Qt_widget::leaveEvent(QEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
void Qt_widget::set_window(double x_min, double x_max, double y_min, double y_max)
|
||||
void Qt_widget::set_window(double x_min, double x_max,
|
||||
double y_min, double y_max,
|
||||
bool const_ranges)
|
||||
{
|
||||
xmin = x_min;
|
||||
xmax = x_max;
|
||||
ymin = y_min;
|
||||
ymax = y_max;
|
||||
constranges = const_ranges;
|
||||
xcentre = xmin + (xmax - xmin)/2;
|
||||
ycentre = ymin + (ymax - ymin)/2;
|
||||
set_scales();
|
||||
initialized=true;
|
||||
}
|
||||
|
||||
void Qt_widget::zoom_in(double ratio, double xc, double yc)
|
||||
|
|
|
|||
Loading…
Reference in New Issue