1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <test_GraphicsView.h>
20 #include <GraphicsView_ViewManager.h>
21 #include <GraphicsView_Viewer.h>
22 #include <GraphicsView_ViewFrame.h>
23 #include <GraphicsView_ViewPort.h>
24 #include <GraphicsView_Object.h>
25 #include <GraphicsView_Scene.h>
27 #include <QGraphicsPixmapItem>
28 #include <QGraphicsSceneWheelEvent>
29 #include <TestViewer.h>
31 extern QString REF_DATA_PATH;
33 class TestObject : public GraphicsView_Object
37 virtual ~TestObject();
39 virtual void compute();
40 virtual QRectF getRect() const;
41 virtual QRectF boundingRect() const;
44 QGraphicsPixmapItem* myItem;
48 TestObject::TestObject()
54 TestObject::~TestObject()
58 void TestObject::compute()
60 QPixmap image( REF_DATA_PATH + "/garonne.png" );
61 myItem = new QGraphicsPixmapItem( image );
65 QRectF TestObject::getRect() const
67 return QRectF( 0, 0, 400, 300 );
70 QRectF TestObject::boundingRect() const
73 return myItem->boundingRect();
80 #define CPPUNIT_ASSERT_VIEW( theCase ) \
82 qApp->processEvents(); \
83 QImage im = aViewPort->dumpView(); \
84 const bool SWAP_RGB_ORDER = true; \
85 if( SWAP_RGB_ORDER ) \
87 /* A temporary patch for bug in SALOME/OCC dump; \
88 the result image contains swapped RGB colors */ \
89 im = im.rgbSwapped(); \
91 CPPUNIT_ASSERT_IMAGES2( &im, theCase ); \
94 void test_GraphicsView::test_wheel_zoom()
96 GraphicsView_ViewManager* aViewManager = new GraphicsView_ViewManager( 0, 0 );
97 GraphicsView_Viewer* aViewer = new GraphicsView_Viewer( "test", 0 );
99 aViewManager->setViewModel( aViewer );
100 GraphicsView_ViewFrame* aWindow = dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->createViewWindow() );
101 aWindow->setGeometry( 100, 100, 600, 450 );
104 qApp->processEvents();
106 // 1. Initialize presentation
107 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
108 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
109 // This is necessary to activate wheeling zoom
111 TestObject* obj = new TestObject();
112 aViewPort->addItem( obj );
114 CPPUNIT_ASSERT_VIEW( "gv_fitall" );
116 // 2. Mouse wheel zoom
117 QWheelEvent we1( QPoint( 10, 10 ), 120*10, Qt::NoButton, Qt::NoModifier );
118 qApp->sendEvent( aViewPort->viewport(), &we1 );
119 CPPUNIT_ASSERT_VIEW( "gv_zoomed_1" );
121 //QTest::qWait( 50000 );
123 QWheelEvent we2( QPoint( 650, 500 ), 120*10, Qt::NoButton, Qt::NoModifier );
124 qApp->sendEvent( aViewPort->viewport(), &we2 );
125 CPPUNIT_ASSERT_VIEW( "gv_zoomed_2" );
127 //QTest::qWait( 50000 );