-// Copyright (C) 2005 OPEN CASCADE
+// Copyright (C) 2007-2024 CEA, EDF, 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.
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// 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, or (at your option) any later version.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// Author : OPEN CASCADE
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+// Author : OPEN CASCADE
// File: GLViewer_Viewer.cxx
// Created: November, 2004
-
//#include <GLViewerAfx.h>
+//
#include "GLViewer_Viewer.h"
#include "GLViewer_Selector.h"
#include "GLViewer_ViewPort.h"
#include "GLViewer_ViewFrame.h"
-#include "SUIT_Desktop.h"
+//#include "SUIT_Desktop.h"
#include "SUIT_ViewWindow.h"
+#include "SUIT_ViewManager.h"
-#include <qapplication.h>
-#include <qpainter.h>
-#include <qpopupmenu.h>
-#include <qcolordialog.h>
+#include <QApplication>
+#include <QMenu>
+#include <QColorDialog>
+#include <QMouseEvent>
+#include <QWheelEvent>
+#include <QRect>
+#include <QRubberBand>
/* used for sketching */
static QEvent* l_mbPressEvent = 0;
/*!
Constructor
*/
-GLViewer_Viewer::GLViewer_Viewer( const QString& title )
+GLViewer_Viewer::GLViewer_Viewer( const QString& /*title*/ )
: SUIT_ViewModel(),
mySelector( 0 ),
+mySelMode( NoSelection ),
mySketcher( 0 ),
-myTransformer( 0 ),
-mySelMode( NoSelection )
+myTransformer( 0 )
{
}
/*!
Builds popup for GL viewer
*/
-void GLViewer_Viewer::contextMenuPopup( QPopupMenu* thePopup )
+void GLViewer_Viewer::contextMenuPopup( QMenu* thePopup )
{
- if( thePopup->count() > 0 )
- thePopup->insertSeparator();
+ if( thePopup->actions().count() > 0 )
+ thePopup->addSeparator();
- thePopup->insertItem( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
+ thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
}
/*!
/*!
Called when smth is selected in this viewer. [ virtual protected slot ]
*/
-void GLViewer_Viewer::onSelectionDone( bool bAdded, SelectionChangeStatus status )
+void GLViewer_Viewer::onSelectionDone( bool /*bAdded*/, SelectionChangeStatus status )
{
emit selectionChanged( status );
}
void GLViewer_Viewer::onSelectionModeChanged()
{
bool enable = ( mySelMode == Multiple );
- QPtrVector<SUIT_ViewWindow> views = getViewManager()->getViews();
+ QVector<SUIT_ViewWindow*> views = getViewManager()->getViews();
for ( int i = 0, n = views.count(); i < n; i++ )
{
GLViewer_ViewPort* vp = ((GLViewer_ViewFrame*)views[i])->getViewPort();
*/
void GLViewer_Viewer::update( int flags )
{
- QPtrVector<SUIT_ViewWindow> views = getViewManager()->getViews();
+ QVector<SUIT_ViewWindow*> views = getViewManager()->getViews();
for ( int i = 0, n = views.count(); i < n; i++ )
((GLViewer_ViewFrame*)views[i])->onUpdate( flags );
}
void GLViewer_Viewer::handleMousePress( QMouseEvent* e )
{
/* test accel for transforms */
- if ( e->state() & GLViewer_ViewTransformer::accelKey() )
+ if ( e->modifiers() & GLViewer_ViewTransformer::accelKey() )
{
- ButtonState bs = e->button();
- if ( bs == GLViewer_ViewTransformer::zoomButton() )
+ Qt::MouseButton bs = e->button();
+ if ( (int)bs == GLViewer_ViewTransformer::zoomButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint
activateTransform( Zoom );
- else if ( bs == GLViewer_ViewTransformer::panButton() )
+ else if ( (int)bs == GLViewer_ViewTransformer::panButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint
activateTransform( Pan );
}
else
void GLViewer_Viewer::handleMouseMove( QMouseEvent* e )
{
/* Highlight for selection */
- bool dragged = ( e->state() & ( LeftButton | MidButton | RightButton ) );
+ bool dragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
if ( !dragged )
{
if ( getSelector() )
}
/* Try to activate default sketching
*/
- else if ( e->state() == GLViewer_ViewSketcher::sketchButton() )
+ else if ( (int)e->button() == GLViewer_ViewSketcher::sketchButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint
{
activateSketching( Rect );
if ( mySketcher )
{
/* selection */
/* tmp - in handleMousePress*/
- if( e->button() == LeftButton && !(getActiveView()->getViewPort()->currentBlock() & BS_Selection) )
+ if( e->button() == Qt::LeftButton && !(getActiveView()->getViewPort()->currentBlock() & BS_Selection) )
{
if ( getSelector() )
{
- bool append = bool ( e->state() & GLViewer_Selector::appendKey() );
+ bool append = bool ( e->modifiers() & GLViewer_Selector::appendKey() );
getSelector()->select( append );
}
}
int GLViewer_ViewTransformer::zoomBtn = Qt::LeftButton;
int GLViewer_ViewTransformer::fitRectBtn = Qt::LeftButton;
int GLViewer_ViewTransformer::panGlobalBtn = Qt::LeftButton;
-int GLViewer_ViewTransformer::acccelKey = Qt::ControlButton;
+int GLViewer_ViewTransformer::acccelKey = Qt::ControlModifier;
/*!
Constructor
: QObject( 0 ),
myViewer( v ),
myType( type ),
-myMajorBtn( NoButton ),
-myButtonState( 0 )
+myButtonState( 0 ),
+myMajorBtn( Qt::NoButton ),
+myRectBand( 0 )
{
if ( myType == GLViewer_Viewer::Pan ||
myType == GLViewer_Viewer::Zoom ||
}
//QAD_Application::getDesktop()->clearInfo();
+
+ endDrawRect();
}
/*!
TransformState state = EnTrain;
QMouseEvent* me = ( QMouseEvent* )e;
- myButtonState = me->state();
+ myButtonState = me->buttons();
if ( e->type() == QEvent::MouseButtonPress )
myButtonState |= me->button(); /* add pressed button */
- int mouseOnlyState = ( myButtonState & ( LeftButton | MidButton | RightButton ) );
+ if ( e->type() == QEvent::MouseButtonRelease )
+ myButtonState |= me->button(); /* add release button */
+
+ int mouseOnlyState = ( myButtonState & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
if ( myStart.isNull() )
{
state = Debut;
myMajorBtn = mouseOnlyState;
}
- if ( e->type() == QEvent::MouseButtonRelease && mouseOnlyState == myMajorBtn )
+ if ( e->type() == QEvent::MouseButtonRelease )
{
state = Fin;
}
{
if ( doTrsf )
{
- QRect rect( QMIN( myStart.x(), myCurr.x() ), QMIN( myStart.y(), myCurr.y() ),
- QABS( myStart.x() - myCurr.x() ), QABS( myStart.y() - myCurr.y() ) );
+ QRect rect( qMin( myStart.x(), myCurr.x() ), qMin( myStart.y(), myCurr.y() ),
+ qAbs( myStart.x() - myCurr.x() ), qAbs( myStart.y() - myCurr.y() ) );
if ( !rect.isEmpty() )
{
switch ( state )
break;
default:
{
- QPainter p( avp->getPaintDevice() ); // for QAD_GLWidget
- p.setPen( Qt::white );
- p.setRasterOp( Qt::XorROP );
- if ( !myDrawRect.isEmpty() )
- p.drawRect( myDrawRect ); /* erase */
- p.drawRect( rect );
- myDrawRect = rect;
+ drawRect( rect );
break;
}
}
myViewer->activateTransform( GLViewer_Viewer::NoTransform );
}
+/*!
+ Draws rectangle by starting and current points
+*/
+void GLViewer_ViewTransformer::drawRect(const QRect& theRect)
+{
+ if ( !myRectBand ) {
+ myRectBand = new QRubberBand( QRubberBand::Rectangle, myViewer->getActiveView()->getViewPort() );
+ QPalette palette;
+ palette.setColor(myRectBand->foregroundRole(), Qt::white);
+ myRectBand->setPalette(palette);
+ }
+ myRectBand->hide();
+
+ myRectBand->setGeometry( theRect );
+ myRectBand->setVisible( theRect.isValid() );
+}
+
+/*!
+ \brief Delete rubber band on the end on the dragging operation.
+*/
+void GLViewer_ViewTransformer::endDrawRect()
+{
+ if ( myRectBand ) myRectBand->hide();
+
+ delete myRectBand;
+ myRectBand = 0;
+}
+
/*!
Returns the type of the transformer. [ public ]
*/
}
-int GLViewer_ViewSketcher::sketchBtn = LeftButton;
+int GLViewer_ViewSketcher::sketchBtn = Qt::LeftButton;
/*!
Constructor
GLViewer_ViewSketcher::GLViewer_ViewSketcher( GLViewer_Viewer* viewer, int type )
: QObject( 0 ),
myViewer( viewer ),
+myType( type ),
myData( 0 ),
-myType( type )
+myRectBand( 0 )
{
if( !myViewer )
return;
if ( myType == GLViewer_Viewer::Rect )
delete ( QRect* ) myData;
+
+ endDrawRect();
}
/*!
SketchState state = EnTrain;
QMouseEvent* me = (QMouseEvent*)e;
- myButtonState = me->state();
+ myButtonState = me->buttons();
if ( e->type() == QEvent::MouseButtonPress )
myButtonState |= me->button(); /* add pressed button */
myStart = me->pos();
}
- int mouseOnlyState = ( myButtonState & ( LeftButton | MidButton | RightButton ) );
+ int mouseOnlyState = ( myButtonState & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
if ( e->type() == QEvent::MouseButtonRelease && mouseOnlyState == sketchButton() )
{
state = Fin;
QRect* sketchRect = ( QRect* )data();
if ( myButtonState & sketchButton() )
{
- QRect rect( QMIN( myStart.x(), myCurr.x() ), QMIN( myStart.y(), myCurr.y() ),
- QABS( myStart.x() - myCurr.x() ), QABS( myStart.y() - myCurr.y() ) );
+ QRect rect( qMin( myStart.x(), myCurr.x() ), qMin( myStart.y(), myCurr.y() ),
+ qAbs( myStart.x() - myCurr.x() ), qAbs( myStart.y() - myCurr.y() ) );
if ( !rect.isEmpty() )
{
- QPainter p( avp );
- p.setPen( Qt::white );
- p.setRasterOp( Qt::XorROP );
- if ( !sketchRect->isEmpty() )
- p.drawRect( *sketchRect ); /* erase */
+ if ( !sketchRect->isEmpty() && myRectBand )
+ myRectBand->hide(); /* erase */
*sketchRect = rect;
if ( state != Fin )
- p.drawRect( *sketchRect );
+ drawRect( *sketchRect );
}
}
}
if ( state == Fin )
{
- QApplication::syncX(); /* force rectangle redrawing */
myViewer->activateSketching( GLViewer_Viewer::NoSketching );
}
}
+
+/*!
+ Draws rectangle by starting and current points
+*/
+void GLViewer_ViewSketcher::drawRect(const QRect& theRect)
+{
+ if ( !myRectBand ) {
+ myRectBand = new QRubberBand( QRubberBand::Rectangle, myViewer->getActiveView()->getViewPort() );
+ QPalette palette;
+ palette.setColor(myRectBand->foregroundRole(), Qt::white);
+ myRectBand->setPalette(palette);
+ }
+ myRectBand->hide();
+
+ myRectBand->setGeometry( theRect );
+ myRectBand->setVisible( theRect.isValid() );
+}
+
+/*!
+ \brief Delete rubber band on the end on the dragging operation.
+*/
+void GLViewer_ViewSketcher::endDrawRect()
+{
+ if ( myRectBand ) myRectBand->hide();
+
+ delete myRectBand;
+ myRectBand = 0;
+}