-#include "XGUI_RubberBand.h"
-
-#include <QBitmap>
-#include <QImage>
-#include <QPaintEvent>
-#include <QPainter>
-#include <QPalette>
-#include <QShowEvent>
-#include <QVectorIterator>
-
-/*!
- \class QtxAbstractRubberBand
- \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection.
-
- Currently this class does not support Style functionality in full.
-*/
-
-/*!
- \brief Constructor
- \param theParent parent widget
- */
-
-XGUI_AbstractRubberBand::XGUI_AbstractRubberBand( QWidget* theParent)
- : QWidget( theParent ),
- myPoints(),
- myIsClosed( false )
-{
- setAttribute(Qt::WA_TransparentForMouseEvents);
-#ifndef WIN32
- setAttribute(Qt::WA_NoSystemBackground);
-#endif //WIN32
- setAttribute(Qt::WA_WState_ExplicitShowHide);
- setVisible(false);
- theParent->installEventFilter(this);
- setGeometry( QRect(QPoint(0,0), theParent->size() ) );
-}
-
-/*!
- \brief Destructor
- */
-XGUI_AbstractRubberBand::~XGUI_AbstractRubberBand()
-{
-}
-
-void XGUI_AbstractRubberBand::clearGeometry()
-{
- myPoints.clear();
-}
-
-bool XGUI_AbstractRubberBand::isClosed()
-{
- return myIsClosed;
-}
-
-void XGUI_AbstractRubberBand::paintEvent( QPaintEvent* theEvent )
-{
- if ( !myPoints.empty() ) {
- QPixmap tiledPixmap(16, 16);
-
- QPainter pixmapPainter(&tiledPixmap);
- pixmapPainter.setPen(Qt::NoPen);
- pixmapPainter.setBrush(QBrush( Qt::black, Qt::Dense4Pattern ));
- pixmapPainter.setBackground(QBrush( Qt::white ));
- pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
- pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
- pixmapPainter.end();
- // ### workaround for borked XRENDER
- tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
-
- QPainter aPainter( this );
- aPainter.setRenderHint( QPainter::Antialiasing );
- QRect r = myPoints.boundingRect();
- aPainter.setClipRegion( r.normalized().adjusted( -1, -1, 2, 2 ) );
- aPainter.drawTiledPixmap( 0, 0, width(), height(), tiledPixmap);
-
- aPainter.end();
- }
-}
-
-void XGUI_AbstractRubberBand::showEvent( QShowEvent* theEvent )
-{
- raise();
- theEvent->ignore();
-}
-
-void XGUI_AbstractRubberBand::moveEvent( QMoveEvent* )
-{
-}
-
-void XGUI_AbstractRubberBand::resizeEvent( QResizeEvent* )
-{
-}
-
-bool XGUI_AbstractRubberBand::eventFilter( QObject* obj, QEvent* e )
-{
- if ( obj && obj == parent() && e->type() == QEvent::Resize ) {
- QWidget* p = (QWidget*)parent();
- setGeometry( QRect(QPoint(0,0), p->size() ) );
- }
- return QWidget::eventFilter( obj, e );
-}
-
-QRegion createRegion( const QPointF& p1, const QPointF& p2 )
-{
- if ( p1 == p2 )
- return QRegion();
-
- QLineF n = QLineF( p1, p2 ).normalVector();//.unitVector();
- n.setLength( 1 );
- n.translate( p1 * -1 );
- QPointF nPoint = n.p2();
-
- QPolygonF p;
- p << p1 + nPoint << p2 + nPoint << p2 - nPoint << p1 - nPoint << p1 + nPoint;
-
- return QRegion( p.toPolygon() );
-}
-
-void XGUI_AbstractRubberBand::updateMask()
-{
- QRegion r;
-
- QVectorIterator<QPoint> it(myPoints);
- while( it.hasNext() ) {
- QPoint p = it.next();
- if( !it.hasNext() )
- break;
-
- QPoint np = it.peekNext();
-
- if ( p == np ) continue;
-
- r += createRegion( p, np );
- }
-
- if ( isClosed() )
- r += createRegion( myPoints.last(), myPoints.first() );
-
- setMask( r );
-}
-
-
-//**********************************************************
-XGUI_RectRubberBand::XGUI_RectRubberBand(QWidget* parent)
- :XGUI_AbstractRubberBand( parent )
-{
- myPoints.resize( 4 );
- myIsClosed = true;
-}
-
-XGUI_RectRubberBand::~XGUI_RectRubberBand()
-{
-}
-
-void XGUI_RectRubberBand::initGeometry( const QRect& theRect )
-{
- myPoints.clear();
- myPoints << theRect.topLeft() << theRect.topRight() << theRect.bottomRight() << theRect.bottomLeft();
- //setMask( QRegion( myPoints ) );
- updateMask();
-}
-
-void XGUI_RectRubberBand::setStartPoint( const QPoint& thePoint )
-{
- myPoints[0] = thePoint;
- myPoints[1].setY( thePoint.y() );
- myPoints[3].setX( thePoint.x() );
- updateMask();
-}
-
-void XGUI_RectRubberBand::setEndPoint( const QPoint& thePoint)
-{
- myPoints[2] = thePoint;
- myPoints[1].setX( thePoint.x() );
- myPoints[3].setY( thePoint.y() );
- updateMask();
-}
-
-void XGUI_RectRubberBand::clearGeometry()
-{
- QMutableVectorIterator<QPoint> i(myPoints);
- while (i.hasNext()) {
- i.next();
- i.setValue( QPoint( -1, -1 ) );
- }
-}
-
-//**********************************************************
-XGUI_PolyRubberBand::XGUI_PolyRubberBand(QWidget* parent)
- :XGUI_AbstractRubberBand( parent )
-{
-}
-
-XGUI_PolyRubberBand::~XGUI_PolyRubberBand()
-{
-}
-
-void XGUI_PolyRubberBand::initGeometry( const QPolygon& thePoints )
-{
- myPoints = thePoints;
- updateMask();
-}
-
-void XGUI_PolyRubberBand::initGeometry( const QPoint& thePoint )
-{
- myPoints.clear();
- myPoints << thePoint;
- updateMask();
-}
-
-void XGUI_PolyRubberBand::addNode( const QPoint& thePoint )
-{
- myPoints << thePoint;
- updateMask();
-}
-
-void XGUI_PolyRubberBand::replaceLastNode( const QPoint& thePoint )
-{
- if ( !myPoints.empty() ) {
- myPoints.pop_back();
- myPoints << thePoint;
- updateMask();
- }
-}
-
-void XGUI_PolyRubberBand::removeLastNode()
-{
- if ( !myPoints.empty() ) {
- myPoints.pop_back();
- updateMask();
- }
-}
-
-void XGUI_PolyRubberBand::setClosed( bool theFlag )
-{
- if (myIsClosed != theFlag ) {
- myIsClosed = theFlag;
- updateMask();
- }
-}
+#include "XGUI_RubberBand.h"\r
+\r
+#include <QBitmap>\r
+#include <QImage>\r
+#include <QPaintEvent>\r
+#include <QPainter>\r
+#include <QPalette>\r
+#include <QShowEvent>\r
+#include <QVectorIterator>\r
+\r
+/*!\r
+ \class QtxAbstractRubberBand\r
+ \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection.\r
+ \r
+ Currently this class does not support Style functionality in full.\r
+ */\r
+\r
+/*!\r
+ \brief Constructor\r
+ \param theParent parent widget\r
+ */\r
+\r
+XGUI_AbstractRubberBand::XGUI_AbstractRubberBand(QWidget* theParent)\r
+ : QWidget(theParent), myPoints(), myIsClosed(false)\r
+{\r
+ setAttribute(Qt::WA_TransparentForMouseEvents);\r
+#ifndef WIN32\r
+ setAttribute(Qt::WA_NoSystemBackground);\r
+#endif //WIN32\r setAttribute(Qt::WA_WState_ExplicitShowHide);\r setVisible(false);\r theParent->installEventFilter(this);\r
+ setGeometry(QRect(QPoint(0, 0), theParent->size()));\r
+}\r
+\r
+/*!\r
+ \brief Destructor\r
+ */\r
+XGUI_AbstractRubberBand::~XGUI_AbstractRubberBand()\r
+{\r
+}\r
+\r
+void XGUI_AbstractRubberBand::clearGeometry()\r
+{\r
+ myPoints.clear();\r
+}\r
+\r
+bool XGUI_AbstractRubberBand::isClosed()\r
+{\r
+ return myIsClosed;\r
+}\r
+\r
+void XGUI_AbstractRubberBand::paintEvent(QPaintEvent* theEvent)\r
+{\r
+ if (!myPoints.empty()) {\r
+ QPixmap tiledPixmap(16, 16);\r
+\r
+ QPainter pixmapPainter(&tiledPixmap);\r
+ pixmapPainter.setPen(Qt::NoPen);\r
+ pixmapPainter.setBrush(QBrush(Qt::black, Qt::Dense4Pattern));\r
+ pixmapPainter.setBackground(QBrush(Qt::white));\r
+ pixmapPainter.setBackgroundMode(Qt::OpaqueMode);\r
+ pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());\r
+ pixmapPainter.end();\r
+ // ### workaround for borked XRENDER\r
+ tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());\r
+\r
+ QPainter aPainter(this);\r
+ aPainter.setRenderHint(QPainter::Antialiasing);\r
+ QRect r = myPoints.boundingRect();\r
+ aPainter.setClipRegion(r.normalized().adjusted(-1, -1, 2, 2));\r
+ aPainter.drawTiledPixmap(0, 0, width(), height(), tiledPixmap);\r
+\r
+ aPainter.end();\r
+ }\r
+}\r
+\r
+void XGUI_AbstractRubberBand::showEvent(QShowEvent* theEvent)\r
+{\r
+ raise();\r
+ theEvent->ignore();\r
+}\r
+\r
+void XGUI_AbstractRubberBand::moveEvent(QMoveEvent*)\r
+{\r
+}\r
+\r
+void XGUI_AbstractRubberBand::resizeEvent(QResizeEvent*)\r
+{\r
+}\r
+\r
+bool XGUI_AbstractRubberBand::eventFilter(QObject* obj, QEvent* e)\r
+{\r
+ if (obj && obj == parent() && e->type() == QEvent::Resize) {\r
+ QWidget* p = (QWidget*) parent();\r
+ setGeometry(QRect(QPoint(0, 0), p->size()));\r
+ }\r
+ return QWidget::eventFilter(obj, e);\r
+}\r
+\r
+QRegion createRegion(const QPointF& p1, const QPointF& p2)\r
+{\r
+ if (p1 == p2)\r
+ return QRegion();\r
+\r
+ QLineF n = QLineF(p1, p2).normalVector(); //.unitVector();\r
+ n.setLength(1);\r
+ n.translate(p1 * -1);\r
+ QPointF nPoint = n.p2();\r
+\r
+ QPolygonF p;\r
+ p << p1 + nPoint << p2 + nPoint << p2 - nPoint << p1 - nPoint << p1 + nPoint;\r
+\r
+ return QRegion(p.toPolygon());\r
+}\r
+\r
+void XGUI_AbstractRubberBand::updateMask()\r
+{\r
+ QRegion r;\r
+\r
+ QVectorIterator<QPoint> it(myPoints);\r
+ while(it.hasNext()) {\r
+ QPoint p = it.next();\r
+ if (!it.hasNext())\r
+ break;\r
+\r
+ QPoint np = it.peekNext();\r
+\r
+ if (p == np)\r
+ continue;\r
+\r
+ r += createRegion(p, np);\r
+ }\r
+\r
+ if (isClosed())\r
+ r += createRegion(myPoints.last(), myPoints.first());\r
+\r
+ setMask(r);\r
+}\r
+\r
+//**********************************************************\r
+XGUI_RectRubberBand::XGUI_RectRubberBand(QWidget* parent)\r
+ : XGUI_AbstractRubberBand(parent)\r
+{\r
+ myPoints.resize(4);\r
+ myIsClosed = true;\r
+}\r
+\r
+XGUI_RectRubberBand::~XGUI_RectRubberBand()\r
+{\r
+}\r
+\r
+void XGUI_RectRubberBand::initGeometry(const QRect& theRect)\r
+{\r
+ myPoints.clear();\r
+ myPoints << theRect.topLeft() << theRect.topRight() << theRect.bottomRight()\r
+ << theRect.bottomLeft();\r
+ //setMask( QRegion( myPoints ) );\r
+ updateMask();\r
+}\r
+\r
+void XGUI_RectRubberBand::setStartPoint(const QPoint& thePoint)\r
+{\r
+ myPoints[0] = thePoint;\r
+ myPoints[1].setY(thePoint.y());\r
+ myPoints[3].setX(thePoint.x());\r
+ updateMask();\r
+}\r
+\r
+void XGUI_RectRubberBand::setEndPoint(const QPoint& thePoint)\r
+{\r
+ myPoints[2] = thePoint;\r
+ myPoints[1].setX(thePoint.x());\r
+ myPoints[3].setY(thePoint.y());\r
+ updateMask();\r
+}\r
+\r
+void XGUI_RectRubberBand::clearGeometry()\r
+{\r
+ QMutableVectorIterator<QPoint> i(myPoints);\r
+ while(i.hasNext()) {\r
+ i.next();\r
+ i.setValue(QPoint(-1, -1));\r
+ }\r
+}\r
+\r
+//**********************************************************\r
+XGUI_PolyRubberBand::XGUI_PolyRubberBand(QWidget* parent)\r
+ : XGUI_AbstractRubberBand(parent)\r
+{\r
+}\r
+\r
+XGUI_PolyRubberBand::~XGUI_PolyRubberBand()\r
+{\r
+}\r
+\r
+void XGUI_PolyRubberBand::initGeometry(const QPolygon& thePoints)\r
+{\r
+ myPoints = thePoints;\r
+ updateMask();\r
+}\r
+\r
+void XGUI_PolyRubberBand::initGeometry(const QPoint& thePoint)\r
+{\r
+ myPoints.clear();\r
+ myPoints << thePoint;\r
+ updateMask();\r
+}\r
+\r
+void XGUI_PolyRubberBand::addNode(const QPoint& thePoint)\r
+{\r
+ myPoints << thePoint;\r
+ updateMask();\r
+}\r
+\r
+void XGUI_PolyRubberBand::replaceLastNode(const QPoint& thePoint)\r
+{\r
+ if (!myPoints.empty()) {\r
+ myPoints.pop_back();\r
+ myPoints << thePoint;\r
+ updateMask();\r
+ }\r
+}\r
+\r
+void XGUI_PolyRubberBand::removeLastNode()\r
+{\r
+ if (!myPoints.empty()) {\r
+ myPoints.pop_back();\r
+ updateMask();\r
+ }\r
+}\r
+\r
+void XGUI_PolyRubberBand::setClosed(bool theFlag)\r
+{\r
+ if (myIsClosed != theFlag) {\r
+ myIsClosed = theFlag;\r
+ updateMask();\r
+ }\r
+}\r