// Copyright (c) 2008 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL: https://github.com/CGAL/cgal/blob/v5.1/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h $ // $Id: GraphicsViewPolylineInput.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // // Author(s) : Andreas Fabri // Laurent Rineau #ifndef CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H #define CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H #include #include #include #include #include #include #include #include #include class QGraphicsScene; class QGraphicsSceneMouseEvent; class QGraphicsItem; class QGraphicsPathItem; class QGraphicsLineItem; class QKeyEvent; class QEvent; class QObject; namespace CGAL { namespace Qt { class CGAL_QT_EXPORT GraphicsViewPolylineInput_non_templated_base : public GraphicsViewInput { public: void setNumberOfVertices(int n) { n_ = n; } bool eventFilter(QObject *obj, QEvent *event); protected: // protected constructor GraphicsViewPolylineInput_non_templated_base(QObject* parent, QGraphicsScene* s, int n = 0, bool closed = true); // mousePressEvent returns true iff the event is consummed bool mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); // keyPressEvent returns true iff the event is consummed bool keyPressEvent(QKeyEvent *event); void rubberbands(const QPointF& p); virtual void generate_polygon() = 0; protected: QPolygonF polygon; bool closed_; private: QGraphicsPathItem *path_item; QGraphicsLineItem *b, *e; int n_; QPointF sp; QGraphicsScene *scene_; }; // end class GraphicsViewPolylineInput_non_templated_base template class GraphicsViewPolylineInput : public GraphicsViewPolylineInput_non_templated_base { public: GraphicsViewPolylineInput(QObject* parent, QGraphicsScene* s, int n = 0, bool closed = true) : GraphicsViewPolylineInput_non_templated_base(parent, s, n, closed) { } protected: void generate_polygon() { std::list points; Converter convert; convert(points, this->polygon); if(closed_ && points.size()>2){ points.push_back(points.front()); } Q_EMIT( generate(CGAL::make_object(points))); } }; // end class GraphicsViewPolylineInput } // namespace Qt } // namespace CGAL #ifdef CGAL_HEADER_ONLY #include #endif // CGAL_HEADER_ONLY #endif // CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H