#include <QGraphicsItem>
class SUIT_DataOwner;
-
-class GraphicsView_ViewPort;
-
/*
Class : GraphicsView_Object
Description : Base class for all objects displayed at the scene
#include "GraphicsView_Scene.h"
-//#define VIEWER_DEBUG
-
//=======================================================================
// Name : GraphicsView_Scene
// Purpose : Constructor
#define GRAPHICSVIEW_SCENE_H
#include "GraphicsView.h"
-
#include <QGraphicsScene>
class QGraphicsRectItem;
public:
GraphicsView_Scene( QObject* theParent = 0 );
~GraphicsView_Scene();
-/*
-public:
- void processRectChanged();
-
-protected slots:
- void onSceneRectChanged( const QRectF& theRect ); // for debug
-
-protected:
- virtual void keyPressEvent( QKeyEvent* );
- virtual void keyReleaseEvent( QKeyEvent* );
- virtual void mousePressEvent( QGraphicsSceneMouseEvent* );
- virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* );
- virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* );
- virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* );
- virtual void wheelEvent( QGraphicsSceneWheelEvent* );
- virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* );
-
- virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* );
- virtual void dragLeaveEvent( QGraphicsSceneDragDropEvent* );
- virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* );
- virtual void dropEvent( QGraphicsSceneDragDropEvent* );
-
-
-signals:
- void gsKeyEvent( QKeyEvent* );
- void gsMouseEvent( QGraphicsSceneMouseEvent* );
- void gsWheelEvent( QGraphicsSceneWheelEvent* );
- void gsContextMenuEvent( QGraphicsSceneContextMenuEvent* );
-
- void gsBoundingRectChanged();
-
-private:
- QGraphicsRectItem* mySceneRectItem; // for debug
-*/
};
-
#endif
#include <QColor>
#include <QFrame>
#include <QFileDialog>
-#include <QGraphicsSceneMouseEvent>
-#include <QGraphicsSceneWheelEvent>
+
+#include <QWheelEvent>
#include <QHBoxLayout>
#include <QImage>
#include <QMouseEvent>
myViewPort = new GraphicsView_ViewPort( aFrame );
aLayout->addWidget( myViewPort );
-
- connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ),
- this, SLOT( mouseEvent( QMouseEvent* ) ) );
-/*
+
connect( myViewPort, SIGNAL( vpKeyEvent( QKeyEvent* ) ),
this, SLOT( keyEvent( QKeyEvent* ) ) );
- connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
- this, SLOT( mouseEvent( QGraphicsSceneMouseEvent* ) ) );
- connect( myViewPort, SIGNAL( vpWheelEvent( QGraphicsSceneWheelEvent* ) ),
- this, SLOT( wheelEvent( QGraphicsSceneWheelEvent* ) ) );
- connect( myViewPort, SIGNAL( vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
- this, SLOT( contextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) );
-
- connect( myViewPort, SIGNAL( vpSketchingFinished( QPainterPath ) ),
- this, SIGNAL( sketchingFinished( QPainterPath ) ) );
-*/
+ connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ),
+ this, SLOT( mouseEvent( QMouseEvent* ) ) );
+ connect( myViewPort, SIGNAL( vpWheelEvent( QWheelEvent* ) ),
+ this, SLOT( wheelEvent( QWheelEvent* ) ) );
+ connect( myViewPort, SIGNAL( vpContextMenuEvent( QContextMenuEvent* ) ),
+ this, SLOT( contextMenuEvent( QContextMenuEvent* ) ) );
}
//=======================================================================
//================================================================
QImage GraphicsView_ViewFrame::dumpView()
{
- return QImage();
-// return myViewPort->dumpView();
+ return myViewPort->dumpView();
}
//================================================================
//================================================================
bool GraphicsView_ViewFrame::dumpViewToFormat( const QImage& image, const QString& fileName, const QString& format )
{
-/*
bool isOK = myViewPort->dumpViewToFormat(fileName, format);
if( !isOK )
isOK = SUIT_ViewWindow::dumpViewToFormat( image, fileName, format );
return isOK;
-*/
- return false;
}
//================================================================
QTransform aTransform = myViewPort->transform();
QString aString;
- aString.sprintf( "%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f",
+ aString.asprintf( "%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f",
aTransform.m11(), aTransform.m12(), aTransform.m13(),
aTransform.m21(), aTransform.m22(), aTransform.m23(),
aTransform.m31(), aTransform.m32(), aTransform.m33() );
if( !anIsOk[ i ] )
return;
-// myViewPort->setTransform( aTransform );
-// myViewPort->applyTransform();
+ myViewPort->setTransform(aTransform);
}
//================================================================
void GraphicsView_ViewFrame::onViewPan()
{
myViewer->pan();
-// myViewer->activateTransform( GraphicsView_Viewer::Pan );
}
//================================================================
void GraphicsView_ViewFrame::onViewZoom()
{
myViewer->zoom();
-// myViewer->activateTransform( GraphicsView_Viewer::Zoom );
}
//================================================================
void GraphicsView_ViewFrame::onViewFitAll()
{
myViewer->fitAll();
-// myViewer->activateTransform( GraphicsView_Viewer::FitAll );
}
//================================================================
void GraphicsView_ViewFrame::onViewFitArea()
{
myViewer->fitArea();
-// myViewer->activateTransform( GraphicsView_Viewer::FitRect );
}
//================================================================
void GraphicsView_ViewFrame::onViewFitSelect()
{
myViewer->fitSelect();
-// myViewer->activateTransform( GraphicsView_Viewer::FitSelect );
}
//================================================================
//================================================================
void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e )
{
-/*
switch ( e->type() )
{
case QEvent::KeyPress:
default:
break;
}
-*/
}
//================================================================
// Function : mouseEvent
// Purpose :
//================================================================
-/*
-void GraphicsView_ViewFrame::mouseEvent( QGraphicsSceneMouseEvent* e )
-{
- switch ( e->type() )
- {
- case QEvent::GraphicsSceneMousePress:
- emit mousePressed( e );
- break;
- case QEvent::GraphicsSceneMouseMove:
- emit mouseMoving( e );
- break;
- case QEvent::GraphicsSceneMouseRelease:
- emit mouseReleased( e );
- break;
- case QEvent::GraphicsSceneMouseDoubleClick:
- emit mouseDoubleClicked( e );
- break;
- default:
- break;
- }
-}
-*/
void GraphicsView_ViewFrame::mouseEvent( QMouseEvent* e )
{
switch ( e->type() )
// Function : wheelEvent
// Purpose :
//================================================================
-void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e )
+void GraphicsView_ViewFrame::wheelEvent( QWheelEvent* e )
{
switch ( e->type() )
{
- case QEvent::GraphicsSceneWheel:
+ case QEvent::Wheel:
emit wheeling( e );
break;
default:
// Function : contextMenuEvent
// Purpose :
//================================================================
-void GraphicsView_ViewFrame::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
+void GraphicsView_ViewFrame::contextMenuEvent( QContextMenuEvent* e )
{
- QPoint aPos = myViewPort->mapFromScene( e->scenePos() );
- QContextMenuEvent* anEvent = new QContextMenuEvent( (QContextMenuEvent::Reason)e->reason(),
- aPos, e->screenPos(), e->modifiers() );
- emit contextMenuRequested( anEvent );
- delete anEvent;
+ emit contextMenuRequested(e);
}
/*!
*/
QString GraphicsView_ViewFrame::filter() const
{
- QStringList filters = SUIT_ViewWindow::filter().split( ";;", QString::SkipEmptyParts );
- filters << tr( "POSTSCRIPT_FILES" );
+ QStringList filters = SUIT_ViewWindow::filter().split( ";;", Qt::SkipEmptyParts );
+ filters << tr("POSTSCRIPT_FILES");
return filters.join( ";;" );
}
#include <SUIT_ViewWindow.h>
#include <QPainterPath>
-class QGraphicsSceneContextMenuEvent;
-class QGraphicsSceneMouseEvent;
-class QGraphicsSceneWheelEvent;
+class QContextMenuEvent;
class QAction;
private slots:
void keyEvent( QKeyEvent* );
void mouseEvent( QMouseEvent* );
- void wheelEvent( QGraphicsSceneWheelEvent* );
- void contextMenuEvent( QGraphicsSceneContextMenuEvent* );
+ void wheelEvent( QWheelEvent* );
+ void contextMenuEvent( QContextMenuEvent* );
signals:
void keyPressed( QKeyEvent* );
void mouseMoving( QMouseEvent* );
void mouseReleased( QMouseEvent* );
void mouseDoubleClicked( QMouseEvent* );
- void wheeling( QGraphicsSceneWheelEvent* );
+ void wheeling( QWheelEvent* );
void sketchingFinished( QPainterPath );
#include <QMouseEvent>
#include <QCursor>
#include <QScrollBar>
+#include <QPainter>
+#include <QPrinter>
#include "SUIT_ResourceMgr.h"
#include "SUIT_Session.h"
fitInView( aRect.adjusted(-myFitAllGap, -myFitAllGap, myFitAllGap, myFitAllGap), Qt::KeepAspectRatio);
}
-void GraphicsView_ViewPort::updateSceneRect(const QRectF &rect)
-{
-}
-
void GraphicsView_ViewPort::fitSelect()
{
if (scene()->selectedItems().isEmpty())
fitInView(selectionRect.adjusted(-myFitAllGap, -myFitAllGap, myFitAllGap, myFitAllGap), Qt::KeepAspectRatio);
}
+void GraphicsView_ViewPort::fitRect(const QRectF& theRect)
+{
+ fitInView(theRect, Qt::KeepAspectRatio);
+}
+
QRect GraphicsView_ViewPort::selectionRect()
{
if (myRectBand)
return QRect();
}
-void GraphicsView_ViewPort::fitRect(const QRectF& theRect)
-{
- fitInView(theRect, Qt::KeepAspectRatio);
-}
-
void GraphicsView_ViewPort::startDrawingRect( int x, int y )
{
myRectBandStart = QPoint(x,y);
myRectBand = nullptr;
}
+void GraphicsView_ViewPort::updateSceneRect(const QRectF &rect)
+{
+}
+
void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event)
{
- if (!zooming && !panning && items(event->pos()).count()==0)
+ if (!zooming && !panning && items(event->pos()).count()==0 && (event->buttons() & Qt::LeftButton))
{
startDrawingRect(event->pos().x(), event->pos().y());
}
qreal widthRatio = w/w0;
qreal heightRatio = h/h0;
-
-
-
+
if (widthRatio>0 && heightRatio>0)
{
qreal scaleFactor = w<h ? widthRatio : heightRatio;
aVBar->setValue( aVBar->value() + theDY );
}
}
+
+//================================================================
+// Function : dumpView
+// Purpose :
+//================================================================
+QImage GraphicsView_ViewPort::dumpView( bool theWholeScene,
+ QSizeF theSize )
+{
+ QPixmap screenshot = viewport()->grab();
+ return screenshot.toImage();
+}
+
+bool GraphicsView_ViewPort::dumpViewToFormat(const QString& fileName, const QString& format)
+{
+ if( format!="PS" && format!="EPS" )
+ return false;
+
+ QPrinter printer(QPrinter::ScreenResolution);
+ printer.setOutputFormat(QPrinter::NativeFormat);
+ printer.setOutputFileName(fileName);
+
+ QPainter painter;
+ if (!painter.begin(&printer))
+ return false;
+
+ render(&painter);
+ if (!painter.end())
+ return false;
+
+ return true;
+}
#define GRAPHICSVIEW_VIEWPORT_H
#include "GraphicsView.h"
-
-#include "GraphicsView_Defs.h"
-
#include <QGraphicsView>
-#include <QPainterPath>
-
class QRubberBand;
void activatePanAction();
void pan( double theDX, double theDY );
+
+ QImage dumpView(bool theWholeScene = false, QSizeF theSize = QSizeF());
+ bool dumpViewToFormat(const QString& fileName, const QString& format);
+
+
signals:
void vpMouseEvent(QMouseEvent*);
#include "GraphicsView_Viewer.h"
-#include "GraphicsView_Object.h"
#include "GraphicsView_Selector.h"
#include "GraphicsView_Scene.h"
#include "GraphicsView_ViewFrame.h"
#include <SUIT_ViewManager.h>
-#include <ImageComposer_Image.h>
-
-#include <QApplication>
#include <QColorDialog>
#include <QWheelEvent>
#include <QKeyEvent>
#include <QMenu>
-#include <math.h>
-
//=======================================================================
// Name : GraphicsView_Viewer
if( thePopup->actions().count() > 0 )
thePopup->addSeparator();
-// thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
+ thePopup->addAction(tr("CHANGE_BGCOLOR"), this, SLOT(onChangeBgColor()));
}
//================================================================
// Function : onChangeBgColor
// Purpose :
//================================================================
-/*
+
void GraphicsView_Viewer::onChangeBgColor()
{
if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
{
- QColor aColor = aViewPort->isForegroundEnabled() ?
- aViewPort->foregroundColor() : aViewPort->backgroundColor();
- aColor = QColorDialog::getColor( aColor, aViewPort );
- if ( aColor.isValid() )
- {
- if( aViewPort->isForegroundEnabled() )
- {
- aViewPort->setForegroundColor( aColor );
- aViewPort->updateForeground();
- }
- else
- aViewPort->setBackgroundColor( aColor );
- }
- }
+ QColor aColor = QColorDialog::getColor( aColor, aViewPort );
+
+ if (aColor.isValid())
+ aViewPort->setBackgroundBrush(QBrush(aColor));
+ }
}
-*/
+
//================================================================
// Function : onSelectionDone
// Purpose :
#include "GraphicsView.h"
#include <SUIT_ViewModel.h>
-#include <QPainterPath>
class QKeyEvent;
class QMouseEvent;
Q_OBJECT
public:
- GraphicsView_Viewer( const QString& title, QWidget* widget = nullptr );
+ GraphicsView_Viewer(const QString& title, QWidget* widget = nullptr);
~GraphicsView_Viewer();
public:
- virtual SUIT_ViewWindow* createView( SUIT_Desktop* );
+ virtual SUIT_ViewWindow* createView(SUIT_Desktop*);
- virtual QString getType() const { return Type(); }
- static QString Type() { return "GraphicsView"; }
+ virtual QString getType() const { return Type(); }
+ static QString Type() { return "GraphicsView"; }
- virtual void contextMenuPopup( QMenu* );
+ virtual void contextMenuPopup(QMenu*);
public:
- GraphicsView_Selector* getSelector();
+ GraphicsView_Selector* getSelector();
- GraphicsView_ViewFrame* getActiveView() const;
- GraphicsView_ViewPort* getActiveViewPort() const;
- GraphicsView_Scene* getActiveScene() const;
+ GraphicsView_ViewFrame* getActiveView() const;
+ GraphicsView_ViewPort* getActiveViewPort() const;
+ GraphicsView_Scene* getActiveScene() const;
void fitAll();
void fitSelect();
void pan();
signals:
- void selectionChanged();
+ void selectionChanged();
protected:
- virtual GraphicsView_ViewFrame* createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget );
+ virtual GraphicsView_ViewFrame* createViewFrame(SUIT_Desktop* theDesktop, QWidget* theWidget);
protected slots:
- virtual void onKeyEvent( QKeyEvent* );
- virtual void onMouseEvent( QMouseEvent* );
- virtual void onWheelEvent( QWheelEvent* );
+ virtual void onKeyEvent(QKeyEvent*);
+ virtual void onMouseEvent(QMouseEvent*);
+ virtual void onWheelEvent(QWheelEvent*);
- virtual void onSelectionDone();
+ virtual void onSelectionDone();
+ virtual void onChangeBgColor();
protected:
- virtual void handleKeyPress( QKeyEvent* );
- virtual void handleKeyRelease( QKeyEvent* );
- virtual void handleMouseMove( QMouseEvent* );
- virtual void handleMousePress( QMouseEvent* );
- virtual void handleMouseRelease( QMouseEvent* );
- virtual void handleWheel(QWheelEvent*);
-
- // virtual void onChangeBgColor();
+ virtual void handleKeyPress(QKeyEvent*);
+ virtual void handleKeyRelease(QKeyEvent*);
+ virtual void handleMouseMove(QMouseEvent*);
+ virtual void handleMousePress(QMouseEvent*);
+ virtual void handleMouseRelease(QMouseEvent*);
+ virtual void handleWheel(QWheelEvent*);
protected:
GraphicsView_Selector* mySelector;