tahoma2d/toonz/sources/toonzqt/schematicviewer.cpp

1193 lines
38 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "toonzqt/schematicviewer.h"
// TnzQt includes
#include "toonzqt/fxtypes.h"
2016-03-19 06:57:51 +13:00
#include "toonzqt/schematicnode.h"
#include "toonzqt/fxschematicnode.h"
#include "toonzqt/schematicgroupeditor.h"
#include "toonzqt/stageschematicscene.h"
#include "toonzqt/fxschematicscene.h"
#include "toonzqt/menubarcommand.h"
#include "toonzqt/tselectionhandle.h"
#include "toonzqt/gutil.h"
#include "toonzqt/imageutils.h"
#include "toonzqt/dvscrollwidget.h"
// TnzLib includes
#include "toonz/txsheethandle.h"
#include "toonz/tcolumnhandle.h"
#include "toonz/tobjecthandle.h"
#include "toonz/tfxhandle.h"
#include "toonz/txsheet.h"
#include "toonz/txshlevelcolumn.h"
#include "toonz/tcolumnfx.h"
#include "toonz/txshzeraryfxcolumn.h"
#include "toonz/preferences.h"
#include "toonz/fxdag.h"
#include "toonz/tapplication.h"
#include "toonz/tscenehandle.h"
#include "toonz/txshleveltypes.h"
2016-03-19 06:57:51 +13:00
2018-07-20 22:15:22 +12:00
#include "../toonz/menubarcommandids.h"
#include "tools/cursormanager.h"
#include "tools/cursors.h"
2016-03-19 06:57:51 +13:00
// Qt includes
#include <QGraphicsSceneMouseEvent>
#include <QMouseEvent>
2016-03-27 13:30:32 +13:00
#include <QGraphicsItem>
2016-03-19 06:57:51 +13:00
#include <QToolBar>
#include <QToolButton>
#include <QMenu>
#include <QIcon>
#include <QAction>
#include <QMainWindow>
#include <QVBoxLayout>
2018-07-20 22:15:22 +12:00
#include <QGestureEvent>
2016-03-19 06:57:51 +13:00
#include <QDebug>
2016-03-19 06:57:51 +13:00
// STD includes
#include "assert.h"
#include "math.h"
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
class SchematicZoomer final : public ImageUtils::ShortcutZoomer {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
SchematicZoomer(QWidget *parent) : ShortcutZoomer(parent) {}
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool zoom(bool zoomin, bool resetZoom) override {
2016-06-15 18:43:10 +12:00
static_cast<SchematicSceneViewer *>(getWidget())->zoomQt(zoomin, resetZoom);
return true;
}
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//==================================================================
//
// SchematicScene
//
//==================================================================
2016-06-15 18:43:10 +12:00
SchematicScene::SchematicScene(QWidget *parent) : QGraphicsScene(parent) {
setSceneRect(0, 0, 50000, 50000);
setItemIndexMethod(NoIndex);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
SchematicScene::~SchematicScene() { clearAllItems(); }
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicScene::showEvent(QShowEvent *se) {
TSelectionHandle *selHandle = TSelectionHandle::getCurrent();
connect(selHandle, SIGNAL(selectionSwitched(TSelection *, TSelection *)),
this, SLOT(onSelectionSwitched(TSelection *, TSelection *)));
clearSelection();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicScene::hideEvent(QHideEvent *se) {
TSelectionHandle *selHandle = TSelectionHandle::getCurrent();
disconnect(selHandle, SIGNAL(selectionSwitched(TSelection *, TSelection *)),
this, SLOT(onSelectionSwitched(TSelection *, TSelection *)));
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
/*! Removes and then deletes all item in the scene.
*/
2016-06-15 18:43:10 +12:00
void SchematicScene::clearAllItems() {
clearSelection();
m_highlightedLinks.clear();
QList<SchematicWindowEditor *> editors;
QList<SchematicNode *> nodes;
QList<SchematicLink *> links;
int i;
QList<QGraphicsItem *> sceneItems = items();
int size = sceneItems.size();
// create nodes and links list
for (i = 0; i < size; i++) {
QGraphicsItem *item = sceneItems.at(i);
SchematicWindowEditor *editor = dynamic_cast<SchematicWindowEditor *>(item);
SchematicNode *node = dynamic_cast<SchematicNode *>(item);
SchematicLink *link = dynamic_cast<SchematicLink *>(item);
if (editor) editors.append(editor);
if (node) nodes.append(node);
if (link) links.append(link);
}
while (links.size() > 0) {
SchematicLink *link = links.back();
removeItem(link);
links.removeLast();
SchematicPort *startPort = link->getStartPort();
SchematicPort *endPort = link->getEndPort();
if (startPort) startPort->removeLink(link);
if (endPort) endPort->removeLink(link);
delete link;
}
while (editors.size() > 0) {
SchematicWindowEditor *editor = editors.back();
removeItem(editor);
editors.removeLast();
delete editor;
}
while (nodes.size() > 0) {
SchematicNode *node = nodes.back();
removeItem(node);
nodes.removeLast();
delete node;
}
assert(items().size() == 0);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
/*! check if any item exists in the rect
*/
2016-06-15 18:43:10 +12:00
bool SchematicScene::isAnEmptyZone(const QRectF &rect) {
QList<QGraphicsItem *> allItems = items();
for (auto const level : allItems) {
SchematicNode *node = dynamic_cast<SchematicNode *>(level);
if (!node) continue;
FxSchematicNode *fxNode = dynamic_cast<FxSchematicNode *>(node);
if (fxNode && fxNode->isA(eXSheetFx)) continue;
if (node->boundingRect().translated(node->scenePos()).intersects(rect))
return false;
}
return true;
}
//------------------------------------------------------------------
QVector<SchematicNode *> SchematicScene::getPlacedNode(SchematicNode *node) {
QRectF rect = node->boundingRect().translated(node->scenePos());
QList<QGraphicsItem *> allItems = items();
QVector<SchematicNode *> nodes;
for (auto const item : allItems) {
SchematicNode *placedNode = dynamic_cast<SchematicNode *>(item);
if (!placedNode || placedNode == node) continue;
QRectF nodeRect =
placedNode->boundingRect().translated(placedNode->scenePos());
QRectF enlargedRect = rect.adjusted(-10, -10, 10, 10);
if (enlargedRect.contains(nodeRect)) nodes.push_back(placedNode);
}
return nodes;
2016-03-19 06:57:51 +13:00
}
//==================================================================
//
// SchematicSceneViewer
//
//==================================================================
SchematicSceneViewer::SchematicSceneViewer(QWidget *parent)
2016-06-15 18:43:10 +12:00
: QGraphicsView(parent)
, m_buttonState(Qt::NoButton)
, m_oldWinPos()
, m_oldScenePos()
, m_firstShowing(true) {
setObjectName("SchematicSceneViewer");
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setDragMode(QGraphicsView::NoDrag);
setTransformationAnchor(QGraphicsView::NoAnchor);
setRenderHint(QPainter::SmoothPixmapTransform);
setRenderHint(QPainter::TextAntialiasing);
setRenderHint(QPainter::Antialiasing);
setInteractive(true);
setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
show();
2018-07-20 22:15:22 +12:00
setAttribute(Qt::WA_AcceptTouchEvents);
grabGesture(Qt::SwipeGesture);
grabGesture(Qt::PanGesture);
grabGesture(Qt::PinchGesture);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
SchematicSceneViewer::~SchematicSceneViewer() {}
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
/*! Reimplemets the QGraphicsView::mousePressEvent()
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::mousePressEvent(QMouseEvent *me) {
if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen &&
!m_stylusUsed) {
2018-07-20 22:15:22 +12:00
return;
}
2016-06-15 18:43:10 +12:00
m_buttonState = me->button();
2018-07-31 01:43:18 +12:00
m_oldWinPos = me->pos();
m_oldScenePos = mapToScene(m_oldWinPos);
2018-07-20 22:15:22 +12:00
if (m_buttonState == Qt::LeftButton) {
if (m_cursorMode == CursorMode::Zoom) {
2018-07-31 01:43:18 +12:00
m_zoomPoint = me->pos();
m_zooming = true;
2018-07-20 22:15:22 +12:00
return;
} else if (m_cursorMode == CursorMode::Hand) {
2018-07-31 01:43:18 +12:00
m_firstPanPoint = mapToScene(me->pos());
m_panning = true;
2018-07-20 22:15:22 +12:00
return;
}
2018-07-31 01:43:18 +12:00
} else if (m_buttonState == Qt::MidButton) {
m_firstPanPoint = mapToScene(me->pos());
2018-07-20 22:15:22 +12:00
}
2016-06-15 18:43:10 +12:00
bool drawRect = true;
QList<QGraphicsItem *> pointedItems = items(me->pos());
int i;
for (i = 0; i < pointedItems.size(); i++) {
SchematicWindowEditor *editor =
dynamic_cast<SchematicWindowEditor *>(pointedItems[i]);
if (!editor) {
drawRect = false;
break;
}
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (m_buttonState == Qt::LeftButton && drawRect)
setDragMode(QGraphicsView::RubberBandDrag);
QGraphicsView::mousePressEvent(me);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
/*! Reimplemets the QGraphicsView::mouseMoveEvent()
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::mouseMoveEvent(QMouseEvent *me) {
if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen &&
!m_stylusUsed) {
2018-07-20 22:15:22 +12:00
return;
}
2016-06-15 18:43:10 +12:00
QPoint currWinPos = me->pos();
QPointF currScenePos = mapToScene(currWinPos);
2018-07-20 22:15:22 +12:00
if ((m_cursorMode == CursorMode::Hand && m_panning) ||
m_buttonState == Qt::MidButton) {
2018-07-31 01:43:18 +12:00
QPointF deltaPoint = ((mapToScene(me->pos()) * getDevPixRatio()) -
(m_firstPanPoint * getDevPixRatio()));
panQt(deltaPoint);
2018-07-20 22:15:22 +12:00
} else {
2018-07-31 01:43:18 +12:00
if (m_cursorMode == CursorMode::Zoom && m_zooming) {
// int deltaY = (m_prevWinPos.y() - me->pos().y()) * 10;
int deltaY = (m_oldWinPos.y() - me->pos().y()) * 10;
double factorY = exp(deltaY * 0.001);
changeScale(m_zoomPoint, factorY);
}
2018-07-20 22:15:22 +12:00
m_oldWinPos = currWinPos;
m_oldScenePos = currScenePos;
2016-06-15 18:43:10 +12:00
}
QGraphicsView::mouseMoveEvent(me);
}
//------------------------------------------------------------------
/*! Reimplemets the QGraphicsView::mouseReleaseEvent()
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::mouseReleaseEvent(QMouseEvent *me) {
2018-07-20 22:15:22 +12:00
// for touchscreens but not touchpads...
if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen &&
!m_stylusUsed) {
2018-07-20 22:15:22 +12:00
m_gestureActive = false;
m_zooming = false;
m_panning = false;
m_stylusUsed = false;
2018-07-20 22:15:22 +12:00
m_scaleFactor = 0.0;
return;
}
m_zooming = false;
m_panning = false;
m_stylusUsed = false;
2018-07-20 22:15:22 +12:00
2016-06-15 18:43:10 +12:00
m_buttonState = Qt::NoButton;
QGraphicsView::mouseReleaseEvent(me);
setDragMode(QGraphicsView::NoDrag);
// update();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2018-07-20 22:15:22 +12:00
void SchematicSceneViewer::mouseDoubleClickEvent(QMouseEvent *event) {
if (m_gestureActive && !m_stylusUsed) {
2018-07-20 22:15:22 +12:00
fitScene();
m_gestureActive = false;
return;
}
2018-07-20 22:15:22 +12:00
QGraphicsView::mouseDoubleClickEvent(event);
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::keyPressEvent(QKeyEvent *ke) {
ke->ignore();
QGraphicsView::keyPressEvent(ke);
if (!ke->isAccepted()) SchematicZoomer(this).exec(ke);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
/*! Reimplemets the QGraphicsView::wheelEvent()
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::wheelEvent(QWheelEvent *me) {
if ((m_gestureActive == true && m_touchDevice == QTouchDevice::TouchScreen) ||
m_gestureActive == false) {
me->accept();
double factor = exp(me->delta() * 0.001);
changeScale(me->pos(), factor);
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::zoomQt(bool zoomin, bool resetZoom) {
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
double scale2 = matrix().determinant();
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
double scale2 = matrix().det();
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
// if the zoom scale is changed over 100% in FxSchematic, call updateScene
bool beforeIsLarge = (scale2 >= 1.0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (resetZoom ||
((scale2 < 100000 || !zoomin) && (scale2 > 0.001 * 0.05 || zoomin))) {
double oldZoomScale = sqrt(scale2);
double zoomScale = resetZoom ? 1 : ImageUtils::getQuantizedZoomFactor(
oldZoomScale, zoomin);
QMatrix scale =
QMatrix().scale(zoomScale / oldZoomScale, zoomScale / oldZoomScale);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// See QGraphicsView::mapToScene()'s doc for details
QRect rect(0, 0, width(), height());
QRectF sceneCenterRect(
mapToScene(QRect(rect.center(), QSize(2, 2))).boundingRect());
setMatrix(scale, true);
centerOn(sceneCenterRect.center());
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().determinant() >= 1.0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().det() >= 1.0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
if (beforeIsLarge != afterIsLarge) {
FxSchematicScene *fxScene = qobject_cast<FxSchematicScene *>(scene());
if (fxScene) fxScene->updateScene();
}
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
/*! The view is scaled around the point \b winPos by \b scaleFactor;
*/
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::changeScale(const QPoint &winPos,
qreal scaleFactor) {
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
bool beforeIsLarge = (matrix().determinant() >= 1.0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
bool beforeIsLarge = (matrix().det() >= 1.0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
QPointF startScenePos = mapToScene(winPos);
QMatrix scale = QMatrix().scale(scaleFactor, scaleFactor);
setMatrix(scale, true);
QPointF endScenePos = mapToScene(winPos);
QPointF delta = endScenePos - startScenePos;
translate(delta.x(), delta.y());
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().determinant() >= 1.0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().det() >= 1.0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
if (beforeIsLarge != afterIsLarge) {
FxSchematicScene *fxScene = qobject_cast<FxSchematicScene *>(scene());
if (fxScene) fxScene->updateScene();
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::fitScene() {
if (scene()) {
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
bool beforeIsLarge = (matrix().determinant() >= 1.0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
bool beforeIsLarge = (matrix().det() >= 1.0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
QRectF rect = scene()->itemsBoundingRect();
fitInView(rect, Qt::KeepAspectRatio);
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().determinant() >= 1.0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().det() >= 1.0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
if (beforeIsLarge != afterIsLarge) {
FxSchematicScene *fxScene = qobject_cast<FxSchematicScene *>(scene());
if (fxScene) fxScene->updateScene();
}
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::centerOnCurrent() {
SchematicScene *schematicScene = dynamic_cast<SchematicScene *>(scene());
QGraphicsItem *node = schematicScene->getCurrentNode();
if (node) centerOn(node);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::reorderScene() {
SchematicScene *schematicScene = dynamic_cast<SchematicScene *>(scene());
schematicScene->reorderScene();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::normalizeScene() {
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
bool beforeIsLarge = (matrix().determinant() >= 1.0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
bool beforeIsLarge = (matrix().det() >= 1.0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
// See QGraphicsView::mapToScene()'s doc for details
QRect rect(0, 0, width(), height());
QRectF sceneCenterRect(
mapToScene(QRect(rect.center(), QSize(2, 2))).boundingRect());
resetMatrix();
2016-03-19 06:57:51 +13:00
#if defined(MACOSX)
2016-06-15 18:43:10 +12:00
scale(1.32, 1.32);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
centerOn(sceneCenterRect.center());
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050000
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().determinant() >= 1.0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
bool afterIsLarge = (matrix().det() >= 1.0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
if (beforeIsLarge != afterIsLarge) {
FxSchematicScene *fxScene = qobject_cast<FxSchematicScene *>(scene());
if (fxScene) fxScene->updateScene();
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2018-07-31 01:43:18 +12:00
void SchematicSceneViewer::panQt(const QPointF &delta) {
2018-07-20 22:15:22 +12:00
setInteractive(false);
// I need to disable QGraphicsView event handling to avoid the generation of
// 'virtual' mouseMoveEvent
2018-07-31 01:43:18 +12:00
translate(delta.x(), delta.y());
2018-07-20 22:15:22 +12:00
// translate has changed the matrix affecting the mapToScene() method. I
// have to recompute currScenePos
setInteractive(true);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void SchematicSceneViewer::showEvent(QShowEvent *se) {
QGraphicsView::showEvent(se);
if (m_firstShowing) {
m_firstShowing = false;
QRectF rect = scene()->itemsBoundingRect();
resetMatrix();
centerOn(rect.center());
}
2016-03-19 06:57:51 +13:00
}
2018-07-20 22:15:22 +12:00
//------------------------------------------------------------------
void SchematicSceneViewer::enterEvent(QEvent *e) {
switch (m_cursorMode) {
case CursorMode::Hand:
setToolCursor(this, ToolCursor::PanCursor);
break;
case CursorMode::Zoom:
setToolCursor(this, ToolCursor::ZoomCursor);
break;
default:
setToolCursor(this, ToolCursor::StrokeSelectCursor);
break;
}
}
//------------------------------------------------------------------
void SchematicSceneViewer::leaveEvent(QEvent *e) { setCursor(Qt::ArrowCursor); }
//------------------------------------------------------------------
void SchematicSceneViewer::tabletEvent(QTabletEvent *e) {
if (e->type() == QTabletEvent::TabletPress) {
m_stylusUsed = e->pointerType() ? true : false;
} else if (e->type() == QTabletEvent::TabletRelease) {
m_stylusUsed = false;
}
e->accept();
}
//------------------------------------------------------------------
2018-07-20 22:15:22 +12:00
void SchematicSceneViewer::gestureEvent(QGestureEvent *e) {
m_gestureActive = false;
if (QGesture *swipe = e->gesture(Qt::SwipeGesture)) {
m_gestureActive = true;
} else if (QGesture *pan = e->gesture(Qt::PanGesture)) {
m_gestureActive = true;
}
if (QGesture *pinch = e->gesture(Qt::PinchGesture)) {
QPinchGesture *gesture = static_cast<QPinchGesture *>(pinch);
QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
2018-07-31 01:43:18 +12:00
QPoint firstCenter = gesture->centerPoint().toPoint();
2018-07-20 22:15:22 +12:00
if (gesture->state() == Qt::GestureStarted) {
2018-07-31 01:43:18 +12:00
m_gestureActive = true;
2018-07-20 22:15:22 +12:00
} else if (gesture->state() == Qt::GestureFinished) {
2018-07-31 01:43:18 +12:00
m_gestureActive = false;
m_zooming = false;
m_scaleFactor = 0.0;
2018-07-20 22:15:22 +12:00
} else {
if (changeFlags & QPinchGesture::ScaleFactorChanged) {
double scaleFactor = gesture->scaleFactor();
// the scale factor makes for too sensitive scaling
// divide the change in half
if (scaleFactor > 1) {
double decimalValue = scaleFactor - 1;
decimalValue /= 1.5;
scaleFactor = 1 + decimalValue;
} else if (scaleFactor < 1) {
double decimalValue = 1 - scaleFactor;
decimalValue /= 1.5;
scaleFactor = 1 - decimalValue;
}
if (!m_zooming) {
double delta = scaleFactor - 1;
m_scaleFactor += delta;
if (m_scaleFactor > .2 || m_scaleFactor < -.2) {
m_zooming = true;
}
}
if (m_zooming) {
2018-07-31 01:43:18 +12:00
changeScale(firstCenter * getDevPixRatio(), scaleFactor);
2018-07-20 22:15:22 +12:00
}
m_gestureActive = true;
}
if (changeFlags & QPinchGesture::CenterPointChanged) {
2018-07-31 01:43:18 +12:00
QPointF centerDelta = (gesture->centerPoint() * getDevPixRatio()) -
(gesture->lastCenterPoint() * getDevPixRatio());
if (centerDelta.manhattanLength() > 1) {
// panQt(centerDelta.toPoint());
2018-07-20 22:15:22 +12:00
}
m_gestureActive = true;
}
}
}
e->accept();
}
2018-07-31 01:43:18 +12:00
void SchematicSceneViewer::touchEvent(QTouchEvent *e, int type) {
if (type == QEvent::TouchBegin) {
m_touchActive = true;
m_firstPanPoint = e->touchPoints().at(0).pos();
// obtain device type
m_touchDevice = e->device()->type();
} else if (m_touchActive) {
// touchpads must have 2 finger panning for tools and navigation to be
// functional on other devices, 1 finger panning is preferred
if ((e->touchPoints().count() == 2 &&
m_touchDevice == QTouchDevice::TouchPad) ||
(e->touchPoints().count() == 1 &&
m_touchDevice == QTouchDevice::TouchScreen)) {
QTouchEvent::TouchPoint panPoint = e->touchPoints().at(0);
if (!m_panning) {
QPointF deltaPoint = panPoint.pos() - m_firstPanPoint;
// minimize accidental and jerky zooming/rotating during 2 finger
// panning
if ((deltaPoint.manhattanLength() > 100) && !m_zooming) {
m_panning = true;
}
}
if (m_panning) {
QPointF centerDelta = (panPoint.pos() * getDevPixRatio()) -
(panPoint.lastPos() * getDevPixRatio());
panQt(centerDelta.toPoint());
}
}
}
if (type == QEvent::TouchEnd || type == QEvent::TouchCancel) {
m_touchActive = false;
m_panning = false;
}
e->accept();
}
2018-07-20 22:15:22 +12:00
bool SchematicSceneViewer::event(QEvent *e) {
/*
switch (e->type()) {
case QEvent::TabletPress:
QTabletEvent *te = static_cast<QTabletEvent *>(e);
qDebug() << "[event] TabletPress: pointerType(" << te->pointerType()
<< ") device(" << te->device() << ")";
break;
case QEvent::TabletRelease:
qDebug() << "[event] TabletRelease";
break;
case QEvent::TouchBegin:
qDebug() << "[event] TouchBegin";
break;
case QEvent::TouchEnd:
qDebug() << "[event] TouchEnd";
break;
case QEvent::TouchCancel:
qDebug() << "[event] TouchCancel";
break;
case QEvent::MouseButtonPress:
qDebug() << "[event] MouseButtonPress";
break;
case QEvent::MouseButtonDblClick:
qDebug() << "[event] MouseButtonDblClick";
break;
case QEvent::MouseButtonRelease:
qDebug() << "[event] MouseButtonRelease";
break;
case QEvent::Gesture:
qDebug() << "[event] Gesture";
break;
default:
break;
}
*/
2018-07-20 22:15:22 +12:00
if (CommandManager::instance()
->getAction(MI_TouchGestureControl)
->isChecked()) {
if (e->type() == QEvent::Gesture) {
gestureEvent(static_cast<QGestureEvent *>(e));
return true;
}
if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchEnd ||
e->type() == QEvent::TouchCancel || e->type() == QEvent::TouchUpdate) {
touchEvent(static_cast<QTouchEvent *>(e), e->type());
m_gestureActive = true;
return true;
}
}
return QGraphicsView::event(e);
}
//------------------------------------------------------------------
void SchematicSceneViewer::setCursorMode(CursorMode cursorMode) {
m_cursorMode = cursorMode;
}
2016-03-19 06:57:51 +13:00
//==================================================================
//
// SchematicViewer
//
//==================================================================
SchematicViewer::SchematicViewer(QWidget *parent)
2016-06-15 18:43:10 +12:00
: QWidget(parent)
, m_fullSchematic(true)
, m_maximizedNode(false)
2018-07-20 22:15:22 +12:00
, m_sceneHandle(0)
, m_cursorMode(CursorMode::Select) {
2016-06-15 18:43:10 +12:00
m_viewer = new SchematicSceneViewer(this);
m_stageScene = new StageSchematicScene(this);
m_fxScene = new FxSchematicScene(this);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_commonToolbar = new QToolBar(m_viewer);
m_stageToolbar = new QToolBar(m_viewer);
m_fxToolbar = new QToolBar(m_viewer);
m_swapToolbar = new QToolBar(m_viewer);
2016-03-19 06:57:51 +13:00
2017-06-26 14:43:02 +12:00
m_commonToolbar->setObjectName("MediumPaddingToolBar");
m_stageToolbar->setObjectName("MediumPaddingToolBar");
m_fxToolbar->setObjectName("MediumPaddingToolBar");
m_swapToolbar->setObjectName("MediumPaddingToolBar");
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
createToolbars();
createActions();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// layout
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->setMargin(0);
2016-06-15 18:43:10 +12:00
mainLayout->setSpacing(0);
{
mainLayout->addWidget(m_viewer, 1);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QFrame *bottomFrame = new QFrame(this);
bottomFrame->setObjectName("SchematicBottomFrame");
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->setMargin(0);
horizontalLayout->setSpacing(0);
{
horizontalLayout->addWidget(m_commonToolbar);
horizontalLayout->addStretch();
horizontalLayout->addWidget(m_fxToolbar);
horizontalLayout->addWidget(m_stageToolbar);
horizontalLayout->addWidget(m_swapToolbar);
}
bottomFrame->setLayout(horizontalLayout);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
mainLayout->addWidget(bottomFrame, 0);
}
setLayout(mainLayout);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
connect(m_fxScene, SIGNAL(showPreview(TFxP)), this,
SIGNAL(showPreview(TFxP)));
connect(m_fxScene, SIGNAL(doCollapse(const QList<TFxP> &)), this,
SIGNAL(doCollapse(const QList<TFxP> &)));
connect(m_stageScene, SIGNAL(doCollapse(QList<TStageObjectId>)), this,
SIGNAL(doCollapse(QList<TStageObjectId>)));
connect(m_fxScene, SIGNAL(doExplodeChild(const QList<TFxP> &)), this,
SIGNAL(doExplodeChild(const QList<TFxP> &)));
connect(m_stageScene, SIGNAL(doExplodeChild(QList<TStageObjectId>)), this,
SIGNAL(doExplodeChild(QList<TStageObjectId>)));
connect(m_stageScene, SIGNAL(editObject()), this, SIGNAL(editObject()));
connect(m_fxScene, SIGNAL(editObject()), this, SIGNAL(editObject()));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_viewer->setScene(m_stageScene);
m_fxToolbar->hide();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
setFocusProxy(m_viewer);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
SchematicViewer::~SchematicViewer() {}
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------
void SchematicViewer::getNodeColor(int ltype, QColor &nodeColor) {
switch (ltype) {
case TZI_XSHLEVEL:
case OVL_XSHLEVEL:
nodeColor = getFullcolorColumnColor();
break;
case PLI_XSHLEVEL:
nodeColor = getVectorColumnColor();
break;
case TZP_XSHLEVEL:
nodeColor = getLevelColumnColor();
break;
case ZERARYFX_XSHLEVEL:
nodeColor = getFxColumnColor();
break;
case CHILD_XSHLEVEL:
nodeColor = getChildColumnColor();
break;
case MESH_XSHLEVEL:
nodeColor = getMeshColumnColor();
break;
case PLT_XSHLEVEL:
nodeColor = getPaletteColumnColor();
break;
case eNormalFx:
nodeColor = getNormalFxColor();
break;
case eZeraryFx:
nodeColor = getFxColumnColor();
break;
case eMacroFx:
nodeColor = getMacroFxColor();
break;
case eGroupedFx:
nodeColor = getGroupColor();
break;
case eNormalImageAdjustFx:
nodeColor = getImageAdjustFxColor();
break;
case eNormalLayerBlendingFx:
nodeColor = getLayerBlendingFxColor();
break;
case eNormalMatteFx:
nodeColor = getMatteFxColor();
break;
default:
nodeColor = grey210;
break;
}
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::setApplication(TApplication *app) {
m_stageScene->setXsheetHandle(app->getCurrentXsheet());
m_stageScene->setObjectHandle(app->getCurrentObject());
m_stageScene->setFxHandle(app->getCurrentFx());
m_stageScene->setColumnHandle(app->getCurrentColumn());
m_stageScene->setSceneHandle(app->getCurrentScene());
m_stageScene->setFrameHandle(app->getCurrentFrame());
m_fxScene->setApplication(app);
}
//------------------------------------------------------------------
void SchematicViewer::updateSchematic() {
m_stageScene->updateScene();
m_fxScene->updateScene();
}
//------------------------------------------------------------------
void SchematicViewer::setSchematicScene(SchematicScene *scene) {
if (scene) {
m_viewer->setScene(scene);
m_viewer->centerOn(scene->sceneRect().center());
}
}
//------------------------------------------------------------------
void SchematicViewer::createToolbars() {
// Initialize them
m_stageToolbar->setMovable(false);
2017-06-26 14:43:02 +12:00
m_stageToolbar->setIconSize(QSize(17, 17));
2016-06-15 18:43:10 +12:00
m_stageToolbar->setLayoutDirection(Qt::RightToLeft);
m_stageToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_commonToolbar->setMovable(false);
2017-06-26 14:43:02 +12:00
m_commonToolbar->setIconSize(QSize(17, 17));
2016-06-15 18:43:10 +12:00
m_commonToolbar->setLayoutDirection(Qt::RightToLeft);
m_commonToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_fxToolbar->setMovable(false);
2017-06-26 14:43:02 +12:00
m_fxToolbar->setIconSize(QSize(17, 17));
2016-06-15 18:43:10 +12:00
m_fxToolbar->setLayoutDirection(Qt::RightToLeft);
m_fxToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_swapToolbar->setMovable(false);
2017-06-26 14:43:02 +12:00
m_swapToolbar->setIconSize(QSize(17, 17));
2016-06-15 18:43:10 +12:00
m_swapToolbar->setLayoutDirection(Qt::RightToLeft);
m_swapToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}
//------------------------------------------------------------------
void SchematicViewer::createActions() {
// Create all actions
QAction *addPegbar = 0, *addSpline = 0, *addCamera = 0, *insertFx = 0,
*addOutputFx = 0, *switchPort = 0, *iconifyNodes = 0;
2016-06-15 18:43:10 +12:00
{
// Fit schematic
2017-06-26 14:43:02 +12:00
QIcon fitSchematicIcon = createQIconOnOff("fit", false);
2016-06-15 18:43:10 +12:00
m_fitSchematic =
new QAction(fitSchematicIcon, tr("&Fit to Window"), m_commonToolbar);
connect(m_fitSchematic, SIGNAL(triggered()), m_viewer, SLOT(fitScene()));
// Center On
2017-06-26 14:43:02 +12:00
QIcon centerOnIcon = createQIconOnOff("centerselection", false);
2016-06-15 18:43:10 +12:00
m_centerOn =
new QAction(centerOnIcon, tr("&Focus on Current"), m_commonToolbar);
connect(m_centerOn, SIGNAL(triggered()), m_viewer, SLOT(centerOnCurrent()));
// Reorder schematic
2017-06-26 14:43:02 +12:00
QIcon reorderIcon = createQIconOnOff("reorder", false);
2016-06-15 18:43:10 +12:00
m_reorder = new QAction(reorderIcon, tr("&Reorder Nodes"), m_commonToolbar);
connect(m_reorder, SIGNAL(triggered()), m_viewer, SLOT(reorderScene()));
// Normalize schematic schematic
2017-06-26 14:43:02 +12:00
QIcon normalizeIcon = createQIconOnOff("resetsize", false);
2016-06-15 18:43:10 +12:00
m_normalize =
new QAction(normalizeIcon, tr("&Reset Size"), m_commonToolbar);
connect(m_normalize, SIGNAL(triggered()), m_viewer, SLOT(normalizeScene()));
2016-03-19 06:57:51 +13:00
2017-06-26 14:43:02 +12:00
QIcon nodeSizeIcon = createQIconOnOff(
2016-06-15 18:43:10 +12:00
m_maximizedNode ? "minimizenodes" : "maximizenodes", false);
m_nodeSize =
new QAction(nodeSizeIcon, m_maximizedNode ? tr("&Minimize Nodes")
: tr("&Maximize Nodes"),
m_commonToolbar);
connect(m_nodeSize, SIGNAL(triggered()), this, SLOT(changeNodeSize()));
2016-03-19 06:57:51 +13:00
2018-07-20 22:15:22 +12:00
QIcon selectModeIcon = createQIconOnOff("schematic_selection_mode", false);
m_selectMode =
new QAction(selectModeIcon, tr("&Selection Mode"), m_commonToolbar);
m_selectMode->setCheckable(true);
connect(m_selectMode, SIGNAL(triggered()), this, SLOT(selectModeEnabled()));
QIcon zoomModeIcon = createQIconOnOff("schematic_zoom_mode", false);
m_zoomMode = new QAction(zoomModeIcon, tr("&Zoom Mode"), m_commonToolbar);
m_zoomMode->setCheckable(true);
connect(m_zoomMode, SIGNAL(triggered()), this, SLOT(zoomModeEnabled()));
QIcon handModeIcon = createQIconOnOff("schematic_hand_mode", false);
m_handMode = new QAction(handModeIcon, tr("&Hand Mode"), m_commonToolbar);
m_handMode->setCheckable(true);
connect(m_handMode, SIGNAL(triggered()), this, SLOT(handModeEnabled()));
setCursorMode(m_cursorMode);
2016-06-15 18:43:10 +12:00
if (m_fullSchematic) {
// AddPegbar
addPegbar = new QAction(tr("&New Pegbar"), m_stageToolbar);
2017-06-26 14:43:02 +12:00
QIcon addPegbarIcon = createQIconOnOff("pegbar", false);
2016-06-15 18:43:10 +12:00
addPegbar->setIcon(addPegbarIcon);
connect(addPegbar, SIGNAL(triggered()), m_stageScene,
SLOT(onPegbarAdded()));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// AddCamera
addCamera = new QAction(tr("&New Camera"), m_stageToolbar);
2017-06-26 14:43:02 +12:00
QIcon addCameraIcon = createQIconOnOff("camera", false);
2016-06-15 18:43:10 +12:00
addCamera->setIcon(addCameraIcon);
connect(addCamera, SIGNAL(triggered()), m_stageScene,
SLOT(onCameraAdded()));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// AddSpline
addSpline = new QAction(tr("&New Motion Path"), m_stageToolbar);
2017-06-26 14:43:02 +12:00
QIcon addSplineIcon = createQIconOnOff("motionpath", false);
2016-06-15 18:43:10 +12:00
addSpline->setIcon(addSplineIcon);
connect(addSpline, SIGNAL(triggered()), m_stageScene,
SLOT(onSplineAdded()));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Switch display of stage schematic's output port
switchPort =
new QAction(tr("&Swtich output port display mode"), m_stageToolbar);
switchPort->setCheckable(true);
switchPort->setChecked(m_stageScene->isShowLetterOnPortFlagEnabled());
2017-06-26 14:43:02 +12:00
QIcon switchPortIcon = createQIconOnOff("switchport");
2016-06-15 18:43:10 +12:00
switchPort->setIcon(switchPortIcon);
connect(switchPort, SIGNAL(toggled(bool)), m_stageScene,
SLOT(onSwitchPortModeToggled(bool)));
// InsertFx
insertFx = CommandManager::instance()->getAction("MI_InsertFx");
if (insertFx) {
2017-06-26 14:43:02 +12:00
QIcon insertFxIcon = createQIconOnOff("fx", false);
2016-06-15 18:43:10 +12:00
insertFx->setIcon(insertFxIcon);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// AddOutputFx
addOutputFx = CommandManager::instance()->getAction("MI_NewOutputFx");
// Iconify Fx nodes
iconifyNodes = new QAction(tr("&Toggle node icons"), m_fxToolbar);
iconifyNodes->setCheckable(true);
iconifyNodes->setChecked(!m_fxScene->isNormalIconView());
QIcon iconifyNodesIcon = createQIconOnOff("iconifynodes");
iconifyNodes->setIcon(iconifyNodesIcon);
connect(iconifyNodes, SIGNAL(toggled(bool)), m_fxScene,
SLOT(onIconifyNodesToggled(bool)));
2016-06-15 18:43:10 +12:00
// Swap fx/stage schematic
2017-06-26 14:43:02 +12:00
QIcon changeSchematicIcon = createQIconOnOff("swap", false);
2016-06-15 18:43:10 +12:00
m_changeScene =
CommandManager::instance()->getAction("A_FxSchematicToggle", true);
if (m_changeScene) {
m_changeScene->setIcon(changeSchematicIcon);
connect(m_changeScene, SIGNAL(triggered()), this,
SLOT(onSceneChanged()));
} else
m_changeScene = 0;
}
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Add actions to toolbars (in reverse)
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_commonToolbar->addSeparator();
m_commonToolbar->addAction(m_nodeSize);
m_commonToolbar->addAction(m_normalize);
m_commonToolbar->addAction(m_reorder);
m_commonToolbar->addAction(m_centerOn);
m_commonToolbar->addAction(m_fitSchematic);
2018-07-20 22:15:22 +12:00
m_commonToolbar->addSeparator();
m_commonToolbar->addAction(m_handMode);
m_commonToolbar->addAction(m_zoomMode);
m_commonToolbar->addAction(m_selectMode);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (m_fullSchematic) {
m_stageToolbar->addSeparator();
m_stageToolbar->addAction(switchPort);
m_stageToolbar->addSeparator();
m_stageToolbar->addAction(addSpline);
m_stageToolbar->addAction(addCamera);
m_stageToolbar->addAction(addPegbar);
2016-03-19 06:57:51 +13:00
m_fxToolbar->addSeparator();
m_fxToolbar->addAction(iconifyNodes);
2016-06-15 18:43:10 +12:00
m_fxToolbar->addSeparator();
m_fxToolbar->addAction(addOutputFx);
m_fxToolbar->addAction(insertFx);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (m_changeScene) m_swapToolbar->addAction(m_changeScene);
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::setStageSchematic() {
if (m_viewer->scene() != m_stageScene) {
m_viewer->setScene(m_stageScene);
QRectF rect = m_stageScene->itemsBoundingRect();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_viewer->resetMatrix();
m_viewer->centerOn(rect.center());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_fxToolbar->hide();
m_stageToolbar->show();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_viewer->update();
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
parentWidget()->setWindowTitle(QObject::tr("Stage Schematic"));
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::setFxSchematic() {
if (m_viewer->scene() != m_fxScene) {
m_viewer->setScene(m_fxScene);
QRectF rect = m_fxScene->itemsBoundingRect();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_viewer->resetMatrix();
m_viewer->centerOn(rect.center());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_stageToolbar->hide();
m_fxToolbar->show();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// check if the fx scene was small scaled (icon view mode)
if (!m_fxScene->isNormalIconView()) m_fxScene->updateScene();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_viewer->update();
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
parentWidget()->setWindowTitle(QObject::tr("FX Schematic"));
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::onSceneChanged() {
if (!hasFocus()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QGraphicsScene *scene = m_viewer->scene();
if (scene == m_fxScene)
setStageSchematic();
else if (scene == m_stageScene)
setFxSchematic();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::onSceneSwitched() {
m_maximizedNode = m_fxScene->getXsheetHandle()
->getXsheet()
->getFxDag()
->getDagGridDimension() == 0;
2017-06-26 14:43:02 +12:00
QIcon nodeSizeIcon = createQIconOnOff(
2016-06-15 18:43:10 +12:00
m_maximizedNode ? "minimizenodes" : "maximizenodes", false);
m_nodeSize->setIcon(nodeSizeIcon);
QString label(m_maximizedNode ? tr("&Minimize Nodes")
: tr("&Maximize Nodes"));
m_nodeSize->setText(label);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// reset schematic
m_viewer->resetMatrix();
m_viewer->centerOn(m_viewer->scene()->itemsBoundingRect().center());
if (m_viewer->scene() == m_fxScene && !m_fxScene->isNormalIconView())
2016-06-15 18:43:10 +12:00
m_fxScene->updateScene();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool SchematicViewer::isStageSchematicViewed() {
QGraphicsScene *scene = m_viewer->scene();
return scene == m_stageScene;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::setStageSchematicViewed(bool isStageSchematic) {
if (!m_fullSchematic) isStageSchematic = true;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (isStageSchematic == isStageSchematicViewed()) return;
if (isStageSchematic)
setStageSchematic();
else
setFxSchematic();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::updateScenes() {
TStageObjectId id = m_stageScene->getCurrentObject();
if (id.isColumn()) {
m_stageScene->update();
TXsheet *xsh = m_stageScene->getXsheetHandle()->getXsheet();
if (!xsh) return;
TXshColumn *column = xsh->getColumn(id.getIndex());
if (!column) {
m_fxScene->getFxHandle()->setFx(0, false);
return;
}
TFx *fx = column->getFx();
m_fxScene->getFxHandle()->setFx(fx, false);
m_fxScene->update();
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void SchematicViewer::changeNodeSize() {
m_maximizedNode = !m_maximizedNode;
// aggiono l'icona del pulsante;
m_fxScene->resizeNodes(m_maximizedNode);
m_stageScene->resizeNodes(m_maximizedNode);
2017-06-26 14:43:02 +12:00
QIcon nodeSizeIcon = createQIconOnOff(
2016-06-15 18:43:10 +12:00
m_maximizedNode ? "minimizenodes" : "maximizenodes", false);
m_nodeSize->setIcon(nodeSizeIcon);
QString label(m_maximizedNode ? tr("&Minimize Nodes")
: tr("&Maximize Nodes"));
m_nodeSize->setText(label);
2016-03-19 06:57:51 +13:00
}
2018-07-20 22:15:22 +12:00
//------------------------------------------------------------------
QColor SchematicViewer::getSelectedNodeTextColor() {
// get colors
TPixel currentColumnPixel;
Preferences::instance()->getCurrentColumnData(currentColumnPixel);
QColor currentColumnColor((int)currentColumnPixel.r,
(int)currentColumnPixel.g,
(int)currentColumnPixel.b, 255);
return currentColumnColor;
}
//------------------------------------------------------------------
2018-07-20 22:15:22 +12:00
void SchematicViewer::setCursorMode(CursorMode cursorMode) {
m_cursorMode = cursorMode;
m_viewer->setCursorMode(m_cursorMode);
m_selectMode->setChecked((m_cursorMode == CursorMode::Select));
m_zoomMode->setChecked((m_cursorMode == CursorMode::Zoom));
m_handMode->setChecked((m_cursorMode == CursorMode::Hand));
}
//------------------------------------------------------------------
void SchematicViewer::selectModeEnabled() { setCursorMode(CursorMode::Select); }
2018-07-20 22:15:22 +12:00
//------------------------------------------------------------------
void SchematicViewer::zoomModeEnabled() { setCursorMode(CursorMode::Zoom); }
2018-07-20 22:15:22 +12:00
//------------------------------------------------------------------
void SchematicViewer::handModeEnabled() { setCursorMode(CursorMode::Hand); }