From f2f4a37738d66399e5a76c2fb77d258dbc808f61 Mon Sep 17 00:00:00 2001 From: Radu Ursu Date: Thu, 28 Feb 2002 11:34:52 +0000 Subject: [PATCH] added the standard tool added standard tool functionality in Qt_widget --- .../demo/Qt_widget/Min_ellipse_2/demo.dsp | 23 ++++++ .../Qt_widget/include/CGAL/IO/Qt_widget.h | 13 +++- .../include/CGAL/IO/Qt_widget_handtool.h | 4 +- .../include/CGAL/IO/Qt_widget_standard_tool.h | 73 +++++++++++++++++++ .../CGAL/IO/Qt_widget_standard_toolbar.h | 3 - .../include/CGAL/IO/Qt_widget_zoom.h | 4 +- .../include/CGAL/IO/Qt_widget_zoomrect.h | 4 +- Packages/Qt_widget/src/CGALQt/Qt_widget.C | 61 +++++++++++++--- .../src/CGALQt/Qt_widget_standard_tool.C | 49 +++++++++++++ .../src/CGALQt/Qt_widget_standard_toolbar.C | 39 +++++----- 10 files changed, 229 insertions(+), 44 deletions(-) create mode 100644 Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_tool.h create mode 100644 Packages/Qt_widget/src/CGALQt/Qt_widget_standard_tool.C diff --git a/Packages/Qt_widget/demo/Qt_widget/Min_ellipse_2/demo.dsp b/Packages/Qt_widget/demo/Qt_widget/Min_ellipse_2/demo.dsp index 451aee1c26c..25c57c441ff 100644 --- a/Packages/Qt_widget/demo/Qt_widget/Min_ellipse_2/demo.dsp +++ b/Packages/Qt_widget/demo/Qt_widget/Min_ellipse_2/demo.dsp @@ -107,6 +107,10 @@ SOURCE=.\Qt_widget_move_list_point.C # End Source File # Begin Source File +SOURCE=..\..\..\src\CGALQt\Qt_widget_standard_tool.C +# End Source File +# Begin Source File + SOURCE=..\..\..\src\CGALQt\Qt_widget_standard_toolbar.C # End Source File # Begin Source File @@ -169,6 +173,25 @@ InputPath=.\Qt_widget_move_list_point.h # End Source File # Begin Source File +SOURCE=..\..\..\include\CGAL\IO\Qt_widget_standard_tool.h + +!IF "$(CFG)" == "demo - Win32 Release" + +!ELSEIF "$(CFG)" == "demo - Win32 Debug" + +# Begin Custom Build +InputPath=..\..\..\include\CGAL\IO\Qt_widget_standard_tool.h + +"../../../src/CGALQt/Qt_Widget_standard_tool.moc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(QTDIR)\bin\moc.exe -o "../../../src/CGALQt/Qt_Widget_standard_tool.moc" "../../../Include/CGAL/IO/Qt_Widget_standard_tool.h" + +# End Custom Build + +!ENDIF + +# End Source File +# Begin Source File + SOURCE=..\..\..\include\CGAL\IO\Qt_Widget_standard_toolbar.h !IF "$(CFG)" == "demo - Win32 Release" diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h index 4e83c0df95c..d3681dfd0ce 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h @@ -36,7 +36,9 @@ namespace CGAL { class Qt_widget_tool; +class Qt_widget_standard_tool; class Qt_widget_layer; + typedef struct togglelayer{ CGAL::Qt_widget_layer *layer; @@ -153,9 +155,12 @@ public: // tool system // ~~~~~~~~~~~ + void attach_standard(Qt_widget_standard_tool* tool); void attach(Qt_widget_tool* tool); inline bool has_tool() const { return _has_tool; }; - void detach_current_tool(); + inline bool has_standard_tool() const { return _has_standard_tool; }; + void detach_current_tool(); + void detach_current_standard_tool(); void new_object(CGAL::Object obj) { emit(new_cgal_object(obj)); }; @@ -221,11 +226,13 @@ private: // current tool bool _has_tool; - Qt_widget_tool *current_tool; + bool _has_standard_tool; + Qt_widget_tool *current_tool; + Qt_widget_standard_tool *current_standard_tool; //for layers std::list qt_layers; - std::list qt_toggle_layers; + std::list qt_toggle_layers; };//end Qt_widget class // manipulators diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h index 303362fe050..b498e71940e 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include @@ -37,7 +37,7 @@ namespace CGAL { -class Qt_widget_handtool : public Qt_widget_tool +class Qt_widget_handtool : public Qt_widget_standard_tool { public: Qt_widget_handtool() : wasrepainted(TRUE), on_first(FALSE){}; diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_tool.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_tool.h new file mode 100644 index 00000000000..c32522d2fe0 --- /dev/null +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_tool.h @@ -0,0 +1,73 @@ +// ============================================================================ +// +// 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_widget_standard_tool.h +// package : Qt_widget +// author(s) : Laurent Rineau & Radu Ursu +// release : +// release_date : +// +// coordinator : Laurent Rineau +// +// ============================================================================ + +#ifndef CGAL_QT_WIDGET_STANDARD_TOOL_H +#define CGAL_QT_WIDGET_STANDARD_TOOL_H + +#include +#include +#include +#include + +namespace CGAL { + +class Qt_widget_standard_tool : public QObject +{ + Q_OBJECT +public: + Qt_widget_standard_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_WIDGET_TOOL_H + diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h index 136e507e24e..532dc703889 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h @@ -49,9 +49,6 @@ public: private slots: - - void toggle_button(); - void toolregion(); void zoomin(); void zoomout(); diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoom.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoom.h index f5b98bb7a05..c55b4e32afd 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoom.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoom.h @@ -22,12 +22,12 @@ #define CGAL_QT_WIDGET_ZOOM_H #include -#include +#include #include namespace CGAL { -class Qt_widget_zoom : public Qt_widget_tool +class Qt_widget_zoom : public Qt_widget_standard_tool { private: int x2, y2; diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h index 2d6e478674a..ff1af1c075e 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h @@ -22,7 +22,7 @@ #define CGAL_QT_WIDGET_ZOOMRECT_H #include -#include +#include #include @@ -34,7 +34,7 @@ namespace CGAL { -class Qt_widget_zoomrect : public Qt_widget_tool +class Qt_widget_zoomrect : public Qt_widget_standard_tool { public: int first_x, first_y, x2, y2; diff --git a/Packages/Qt_widget/src/CGALQt/Qt_widget.C b/Packages/Qt_widget/src/CGALQt/Qt_widget.C index a5ac486f455..7f4684eaa3c 100644 --- a/Packages/Qt_widget/src/CGALQt/Qt_widget.C +++ b/Packages/Qt_widget/src/CGALQt/Qt_widget.C @@ -20,16 +20,19 @@ #ifdef CGAL_USE_QT -#include #include + +#include #include +#include #include namespace CGAL { Qt_widget::Qt_widget(QWidget *parent, const char *name) : QWidget(parent, name), Locked(0), _pointSize(4), - _pointStyle(DISC), _has_tool(false), current_tool(0) + _pointStyle(DISC), _has_tool(false), current_tool(0), + _has_standard_tool(false), current_standard_tool(0) { setCaption("CGAL::Qt_widget"); @@ -134,7 +137,9 @@ void Qt_widget::paintEvent(QPaintEvent *e) void Qt_widget::mousePressEvent(QMouseEvent *e) { emit(mousePressed(e)); - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->mousePressEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->mousePressEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -145,7 +150,9 @@ void Qt_widget::mousePressEvent(QMouseEvent *e) void Qt_widget::mouseReleaseEvent(QMouseEvent *e) { emit(mouseReleased(e)); - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->mouseReleaseEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->mouseReleaseEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -156,7 +163,9 @@ void Qt_widget::mouseReleaseEvent(QMouseEvent *e) void Qt_widget::mouseMoveEvent(QMouseEvent *e) { emit(mouseMoved(e)); - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->mouseMoveEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->mouseMoveEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -166,7 +175,9 @@ void Qt_widget::mouseMoveEvent(QMouseEvent *e) void Qt_widget::wheelEvent(QMouseEvent *e) { - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->wheelEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->wheelEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -176,7 +187,9 @@ void Qt_widget::wheelEvent(QMouseEvent *e) void Qt_widget::mouseDoubleClickEvent(QMouseEvent *e) { - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->mouseDoubleClickEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->mouseDoubleClickEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -186,7 +199,9 @@ void Qt_widget::mouseDoubleClickEvent(QMouseEvent *e) void Qt_widget::keyPressEvent(QKeyEvent *e) { - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->keyPressEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->keyPressEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -196,7 +211,9 @@ void Qt_widget::keyPressEvent(QKeyEvent *e) void Qt_widget::keyReleaseEvent(QKeyEvent *e) { - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->keyReleaseEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->keyReleaseEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -206,7 +223,9 @@ void Qt_widget::keyReleaseEvent(QKeyEvent *e) void Qt_widget::enterEvent(QEvent *e) { - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->enterEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->enterEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -216,7 +235,9 @@ void Qt_widget::enterEvent(QEvent *e) void Qt_widget::leaveEvent(QEvent *e) { - if (has_tool()) + if (has_standard_tool()) + current_standard_tool->leaveEvent(e); + if (has_tool() && !has_standard_tool()) current_tool->leaveEvent(e); std::list::iterator it; for(it = qt_toggle_layers.begin(); it!= qt_toggle_layers.end(); it++) @@ -341,6 +362,16 @@ Qt_widget& operator<<(Qt_widget& w, const Bbox_2& r) *Ursu Radu coding .... * *********************************************/ +void Qt_widget::attach_standard(Qt_widget_standard_tool* tool) { + if (has_standard_tool()) { + current_standard_tool->detach(); + emit(detached_tool()); + } + current_standard_tool=tool; + _has_standard_tool=true; + current_standard_tool->attach(this); +} + void Qt_widget::attach(Qt_widget_tool* tool) { if (has_tool()) { current_tool->detach(); @@ -350,6 +381,12 @@ void Qt_widget::attach(Qt_widget_tool* tool) { _has_tool=true; current_tool->attach(this); } +void Qt_widget::detach_current_standard_tool() +{ + if (has_standard_tool()) + current_standard_tool->detach(); + _has_standard_tool = FALSE; +}; void Qt_widget::detach_current_tool() { if (has_tool()) { @@ -376,6 +413,8 @@ void Qt_widget::redraw() (*it).layer->draw(*this); unlock(); + if (has_standard_tool()) + current_standard_tool->widget_repainted(); if (has_tool()) current_tool->widget_repainted(); } diff --git a/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_tool.C b/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_tool.C new file mode 100644 index 00000000000..162fecd74eb --- /dev/null +++ b/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_tool.C @@ -0,0 +1,49 @@ +// ============================================================================ +// +// 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 : src/Qt_widget_standard_tool.C +// package : Qt_widget +// author(s) : Laurent Rineau & Radu Ursu +// release : +// release_date : +// +// coordinator : Laurent Rineau +// +// ============================================================================ + +#ifdef CGAL_USE_QT + +#include +#include +#include + +namespace CGAL { + +Qt_widget_standard_tool::Qt_widget_standard_tool() : + widget(0) {}; + +void Qt_widget_standard_tool::attach(Qt_widget *w) +{ + widget=w; + attaching(); +} + +void Qt_widget_standard_tool::detach() +{ + detaching(); + widget=0; +} + + +} // namespace CGAL + +#include "Qt_widget_standard_tool.moc" + +#endif diff --git a/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C b/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C index ba08271a8bb..2eb184d08fe 100644 --- a/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C +++ b/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C @@ -102,45 +102,40 @@ namespace CGAL { but[4]->setToggleButton(TRUE); but[5]->setToggleButton(TRUE); - connect(w, SIGNAL(detached_tool()), this, SLOT(toggle_button())); nr_of_buttons = 6; }; - void Standard_toolbar::toggle_button () - { - if(is_active) { - but[activebutton]->toggle(); - is_active = false; - } - } - void Standard_toolbar::toolregion() { if (but[3]->isOn()) { - widget->attach(&zoombut); - activebutton = 3; - is_active = true; + if(is_active) + but[activebutton]->toggle(); + widget->attach_standard(&zoombut); + activebutton = 3; + is_active = true; } else { is_active = false; - widget->detach_current_tool(); + widget->detach_current_standard_tool(); } } void Standard_toolbar::zoominrect() { if (but[4]->isOn()) - { - widget->attach(&zoomrectbut); + { + if(is_active) + but[activebutton]->toggle(); + widget->attach_standard(&zoomrectbut); activebutton = 4; is_active = true; } else { is_active = false; - widget->detach_current_tool(); + widget->detach_current_standard_tool(); } } @@ -157,7 +152,8 @@ namespace CGAL { void Standard_toolbar::notool() { if(is_active) { - widget->detach_current_tool(); + but[activebutton]->toggle(); + widget->detach_current_standard_tool(); is_active = false; } } @@ -166,14 +162,15 @@ namespace CGAL { void Standard_toolbar::handtool() { if (but[5]->isOn()) - { - widget->detach_current_tool(); - widget->attach(&handtoolbut); + { + if(is_active) + but[activebutton]->toggle(); + widget->attach_standard(&handtoolbut); activebutton = 5; is_active = true; } else { is_active = false; - widget->detach_current_tool(); + widget->detach_current_standard_tool(); } }