// Copyright (c) 2008 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). // You can redistribute it and/or modify it under the terms of the GNU // General Public License as published by the Free Software Foundation, // either version 3 of the License, or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // // // Author(s) : Andreas Fabri // Laurent Rineau #ifndef CGAL_QT_GRAPHICS_VIEW_ISO_RECTANGLE_INPUT_H #define CGAL_QT_GRAPHICS_VIEW_ISO_RECTANGLE_INPUT_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace CGAL { namespace Qt { template class GraphicsViewIsoRectangleInput : public GraphicsViewInput { public: GraphicsViewIsoRectangleInput(QObject *parent, QGraphicsScene* s); ~GraphicsViewIsoRectangleInput(); protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void keyPressEvent(QKeyEvent *event); bool eventFilter(QObject *obj, QEvent *event); private: typedef typename K::Point_2 Point_2; QPointF qp, qq, qr; Point_2 p, q, r; QGraphicsRectItem *rectItem; QPointF rect_first_point; QGraphicsScene *scene_; Converter convert; }; template GraphicsViewIsoRectangleInput::GraphicsViewIsoRectangleInput(QObject *parent, QGraphicsScene* s) : GraphicsViewInput(parent), rectItem(new QGraphicsRectItem), scene_(s) { rectItem->setBrush(QBrush()); scene_->addItem(rectItem); rectItem->hide(); rectItem->setZValue(10000); } template GraphicsViewIsoRectangleInput::~GraphicsViewIsoRectangleInput() { delete rectItem; } template void GraphicsViewIsoRectangleInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { if(event->modifiers() & ::Qt::ShiftModifier){ return; } if(event->button() == ::Qt::LeftButton) { if(rectItem->isVisible()) { // we have clicked twice Q_EMIT generate(CGAL::make_object(convert(rectItem->rect()))); rectItem->hide(); } else { // we enter a first point rect_first_point = event->scenePos(); rectItem->setRect(QRectF(rect_first_point, rect_first_point)); rectItem->show(); } } } template void GraphicsViewIsoRectangleInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { // todo: only do this if no modifiers are pressed at the same time if(rectItem->isVisible()) { rectItem->setRect(QRectF(rect_first_point, event->scenePos())); } } template void GraphicsViewIsoRectangleInput::keyPressEvent ( QKeyEvent * event ) { } template bool GraphicsViewIsoRectangleInput::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::GraphicsSceneMousePress) { QGraphicsSceneMouseEvent *mouseEvent = static_cast(event); mousePressEvent(mouseEvent); return true; } else if (event->type() == QEvent::GraphicsSceneMouseMove) { QGraphicsSceneMouseEvent *mouseEvent = static_cast(event); mouseMoveEvent(mouseEvent); return true; } else if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); keyPressEvent(keyEvent); return true; } else{ // standard event processing return QObject::eventFilter(obj, event); } } } // namespace Qt } // namespace CGAL #endif // CGAL_QT_GRAPHICS_VIEW_ISO_RECTANGLE_INPUT_H