X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FQtx%2FQtxRubberBand.cxx;h=3c92e0dbe1b13313585887f8ae35e4e0dc41f65b;hb=7d93c764f1cd3fbbe7db561b2e4b0bafa10bc0d4;hp=82b267f876c16e2d0ddcaea9202be3c1683950e0;hpb=bb8609caf7881d966fbb88dec0a7822736da93f5;p=modules%2Fgui.git diff --git a/src/Qtx/QtxRubberBand.cxx b/src/Qtx/QtxRubberBand.cxx old mode 100755 new mode 100644 index 82b267f87..3c92e0dbe --- a/src/Qtx/QtxRubberBand.cxx +++ b/src/Qtx/QtxRubberBand.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -30,6 +30,8 @@ #include #include +#include + /*! \class QtxAbstractRubberBand \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection. @@ -95,7 +97,7 @@ void QtxAbstractRubberBand::paintEvent( QPaintEvent* theEvent ) QPainter aPainter( this ); aPainter.setRenderHint( QPainter::Antialiasing ); QRect r = myPoints.boundingRect(); - aPainter.setClipRegion( r.normalized().adjusted( -1, -1, 2, 2 ) ); + //aPainter.setClipRegion( r.normalized().adjusted( -1, -1, 2, 2 ) ); aPainter.drawTiledPixmap( 0, 0, width(), height(), tiledPixmap); aPainter.end(); @@ -205,8 +207,8 @@ void QtxAbstractRubberBand::updateMask() if ( isClosed() ) r += createRegion( myPoints.last(), myPoints.first() ); - setMask( r ); - + if ( !r.isEmpty() ) + setMask( r ); } @@ -311,3 +313,95 @@ void QtxPolyRubberBand::setClosed( bool theFlag ) updateMask(); } } + +QtxCircleRubberBand::QtxCircleRubberBand(QWidget* parent) + :QtxAbstractRubberBand(parent), myHasCenter(false) +{ + myPoints.resize(2); + myIsClosed = true; +} + +QtxCircleRubberBand::~QtxCircleRubberBand() +{ +} + +void QtxCircleRubberBand::initGeometry(const QPoint& thePoint) +{ + myIsClosed = false; + myHasCenter = true; + myPoints.clear(); + myPoints << thePoint; + updateMask(); +} + +void QtxCircleRubberBand::setRadius(const QPoint& thePoint) +{ + if (myPoints.size() == 1) + myPoints << thePoint; + else + myPoints.setPoint(1, thePoint); + myIsClosed = true; + updateMask(); +} + +void QtxCircleRubberBand::updateMask() +{ + int aLen = radius(); + if (aLen > MIN_RADIUS) { + QRegion aReg1(myPoints[0].x() - aLen, + myPoints[0].y() - aLen, aLen * 2, aLen * 2, QRegion::Ellipse); + QRegion aReg2(myPoints[0].x() - aLen + 2, + myPoints[0].y() - aLen + 2, aLen * 2 - 4, aLen * 2 - 4, QRegion::Ellipse); + setMask(aReg1 - aReg2); + } +} + +bool QtxCircleRubberBand::isCenterDefined() const +{ + return myHasCenter; +} + +void QtxCircleRubberBand::clearGeometry() +{ + QtxAbstractRubberBand::clearGeometry(); + myHasCenter = false; + myIsClosed = false; +} + +QPoint rotatePoint(const QPoint& theStart, const QPoint& theCenter, double theAngle) +{ + double cosTheta = cos(theAngle); + double sinTheta = sin(theAngle); + int aX = (int)(cosTheta * (theStart.x() - theCenter.x()) - + sinTheta * (theStart.y() - theCenter.y()) + theCenter.x()); + int aY = (int)(sinTheta * (theStart.x() - theCenter.x()) + + cosTheta * (theStart.y() - theCenter.y()) + theCenter.y()); + return QPoint(aX, aY); +} + +static double m_pi = 4 * atan(1); +static double angle_deg = 360. / CIRCLE_NB_POINTS; +static double angle_rad = angle_deg * (m_pi / 180.); + + +void QtxCircleRubberBand::getPoligon(QPolygon* thePoints) const +{ + int aLen = radius(); + if (aLen > MIN_RADIUS) { + thePoints->clear(); + QPoint aCenter = myPoints[0]; + QPoint aStart = myPoints[1]; + for (int i = 0; i < CIRCLE_NB_POINTS; i++) { + thePoints->append(aStart); + aStart = rotatePoint(aStart, aCenter, angle_rad); + } + } +} + +int QtxCircleRubberBand::radius() const +{ + if (myPoints.size() < 2) + return -1; + QPoint aDist = myPoints[1] - myPoints[0]; + return (int)std::sqrt(std::pow(aDist.x(), 2) + std::pow(aDist.y(), 2)); +} \ No newline at end of file