208 lines
4.8 KiB
C++
208 lines
4.8 KiB
C++
/*
|
|
* WorkflowGraphicsView.cpp
|
|
*
|
|
* Created on: 2011-9-13
|
|
* Author: dev
|
|
*/
|
|
|
|
#include <QResizeEvent>
|
|
#include <QGraphicsScene>
|
|
#include <QGraphicsItem>
|
|
#include <QDebug>
|
|
#include <QScrollBar>
|
|
#include "WorkflowGraphicsView.h"
|
|
#include "GeneralWorkflowScene.h"
|
|
#include "ModuleGraphicsItem.h"
|
|
#include "PaiGeoObject.h"
|
|
#include "ConsoleGUIService.h"
|
|
#include "ModuleInformation.h"
|
|
#include "ModuleParameterUtil.h"
|
|
|
|
using namespace pai;
|
|
using namespace pai::graphics2d;
|
|
using namespace pai::objectmodel;
|
|
|
|
WorkflowGraphicsView::WorkflowGraphicsView(QGraphicsScene *pScene, QWidget *pParent)
|
|
:QGraphicsView(pScene,pParent), m_pEnsureVisibleItem(NULL)
|
|
{
|
|
// TODO Auto-generated constructor stub
|
|
setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
setDragMode(QGraphicsView::RubberBandDrag);
|
|
setAcceptDrops(true);
|
|
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
|
setResizeAnchor(QGraphicsView::NoAnchor);
|
|
connect(&pai::graphics2d::ModuleGraphicsItem::m_EventAgent,SIGNAL(ModuleCenterOn(QGraphicsItem*)),this,SLOT(slotItemNeedCenterOn(QGraphicsItem*)));
|
|
viewport()->setProperty("UsePaiStyleRubberBand", true);
|
|
m_SceneReadOnly = false;
|
|
|
|
}
|
|
|
|
WorkflowGraphicsView::~WorkflowGraphicsView()
|
|
{
|
|
// TODO Auto-generated destructor stub
|
|
}
|
|
|
|
void WorkflowGraphicsView::SetScenceReadOnly(bool readonly)
|
|
{
|
|
m_SceneReadOnly = readonly;
|
|
QGraphicsScene *pScene = scene();
|
|
if (pScene)
|
|
{
|
|
pai::graphics2d::GeneralWorkflowScene *pWorkflowSceneManager = dynamic_cast<pai::graphics2d::GeneralWorkflowScene *>(pScene);
|
|
if (pWorkflowSceneManager)
|
|
pWorkflowSceneManager->SetScenceReadOnly(m_SceneReadOnly);
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::contextMenuEvent(QContextMenuEvent *event)
|
|
{
|
|
if (!m_SceneReadOnly)
|
|
{
|
|
QGraphicsView::contextMenuEvent(event);
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::dropEvent(QDropEvent *event)
|
|
{
|
|
if (m_SceneReadOnly)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QGraphicsView::dropEvent(event);
|
|
}
|
|
|
|
void WorkflowGraphicsView::dragEnterEvent(QDragEnterEvent *event)
|
|
{
|
|
if (!m_SceneReadOnly)
|
|
{
|
|
QGraphicsView::dragEnterEvent(event);
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::dragLeaveEvent(QDragLeaveEvent *event)
|
|
{
|
|
if (!m_SceneReadOnly)
|
|
{
|
|
QGraphicsView::dragLeaveEvent(event);
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::dragMoveEvent(QDragMoveEvent *event)
|
|
{
|
|
if (!m_SceneReadOnly)
|
|
{
|
|
QGraphicsView::dragMoveEvent(event);
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::keyPressEvent(QKeyEvent *event)
|
|
{
|
|
if (!m_SceneReadOnly)
|
|
{
|
|
QGraphicsView::keyPressEvent(event);
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::keyReleaseEvent(QKeyEvent *event)
|
|
{
|
|
if (!m_SceneReadOnly)
|
|
{
|
|
QGraphicsView::keyReleaseEvent(event);
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::mousePressEvent ( QMouseEvent * event )
|
|
{
|
|
if (event->buttons() != Qt::LeftButton)
|
|
return;
|
|
QGraphicsView::mousePressEvent(event);
|
|
}
|
|
|
|
void WorkflowGraphicsView::mouseReleaseEvent ( QMouseEvent * event )
|
|
{
|
|
QGraphicsView::mouseReleaseEvent(event);
|
|
|
|
if (m_pEnsureVisibleItem)
|
|
{
|
|
ensureVisible(m_pEnsureVisibleItem);
|
|
m_pEnsureVisibleItem = NULL;
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::mouseMoveEvent ( QMouseEvent * event )
|
|
{
|
|
QGraphicsView::mouseMoveEvent(event);
|
|
|
|
if (event->buttons() != Qt::LeftButton)
|
|
return;
|
|
|
|
QScrollBar *scrollBar;
|
|
|
|
int auxX = event->x();
|
|
int auxY = event->y();
|
|
int posMaxX = viewport()->width() -1;
|
|
int posMaxY = viewport()->height() -1;
|
|
|
|
if (auxX <= 0)
|
|
{
|
|
scrollBar = horizontalScrollBar();
|
|
scrollBar->setValue(scrollBar->value() - scrollBar->singleStep());
|
|
}
|
|
else if (auxX >= posMaxX)
|
|
{
|
|
scrollBar = horizontalScrollBar();
|
|
scrollBar->setValue(scrollBar->value() + scrollBar->singleStep());
|
|
}
|
|
|
|
if (auxY <= 0)
|
|
{
|
|
scrollBar = verticalScrollBar();
|
|
scrollBar->setValue(scrollBar->value() - scrollBar->singleStep());
|
|
}
|
|
else if (auxY >= posMaxY)
|
|
{
|
|
scrollBar = verticalScrollBar();
|
|
scrollBar->setValue(scrollBar->value() + scrollBar->singleStep());
|
|
}
|
|
}
|
|
|
|
void WorkflowGraphicsView::focusInEvent(QFocusEvent * focusEvent)
|
|
{
|
|
QGraphicsView::focusInEvent(focusEvent);
|
|
}
|
|
|
|
QRectF WorkflowGraphicsView::CalculateAdaptiveSceneRect()
|
|
{
|
|
QList<QGraphicsItem*> lstItems=items();
|
|
if(lstItems.count()>0)
|
|
{
|
|
QGraphicsItem* pMostRightItem=lstItems.at(0);
|
|
QGraphicsItem* pMostBottomItem=lstItems.at(0);
|
|
foreach(QGraphicsItem* pItem,lstItems)
|
|
{
|
|
if(pItem->pos().x()>pMostRightItem->pos().x())
|
|
{
|
|
pMostRightItem=pItem;
|
|
}
|
|
if(pItem->pos().y()>pMostBottomItem->pos().y())
|
|
{
|
|
pMostBottomItem=pItem;
|
|
}
|
|
}
|
|
return QRectF(0,0,pMostRightItem->pos().x()+pMostRightItem->boundingRect().width(),pMostBottomItem->pos().y()+pMostBottomItem->boundingRect().height());
|
|
}
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
void WorkflowGraphicsView::slotItemNeedCenterOn(QGraphicsItem* pItem)
|
|
{
|
|
// catch the item on current scene only
|
|
if (pItem->scene() == scene())
|
|
{
|
|
m_pEnsureVisibleItem = pItem;
|
|
}
|
|
}
|
|
|