Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/schematicviewer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
manongjohn d6e3cc
#include "toonzqt/fxtypes.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/schematicnode.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxschematicnode.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/schematicgroupeditor.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/stageschematicscene.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxschematicscene.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/menubarcommand.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/tselectionhandle.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/imageutils.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvscrollwidget.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tfxhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshzeraryfxcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxdag.h"
Toshihiro Shimizu 890ddd
#include "toonz/tapplication.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
manongjohn d6e3cc
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
manongjohn a99cb6
#include "../toonz/menubarcommandids.h"
manongjohn a99cb6
manongjohn da05a0
#include "tools/cursormanager.h"
manongjohn da05a0
#include "tools/cursors.h"
manongjohn da05a0
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qgraphicsscenemouseevent></qgraphicsscenemouseevent>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Campbell Barton d0e335
#include <qgraphicsitem></qgraphicsitem>
Toshihiro Shimizu 890ddd
#include <qtoolbar></qtoolbar>
Toshihiro Shimizu 890ddd
#include <qtoolbutton></qtoolbutton>
Toshihiro Shimizu 890ddd
#include <qmenu></qmenu>
Toshihiro Shimizu 890ddd
#include <qicon></qicon>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qmainwindow></qmainwindow>
Toshihiro Shimizu 890ddd
#include <qvboxlayout></qvboxlayout>
manongjohn a99cb6
#include <qgestureevent></qgestureevent>
Toshihiro Shimizu 890ddd
manongjohn ebce7c
#include <qdebug></qdebug>
manongjohn ebce7c
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include "assert.h"
Toshihiro Shimizu 890ddd
#include "math.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class SchematicZoomer final : public ImageUtils::ShortcutZoomer {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SchematicZoomer(QWidget *parent) : ShortcutZoomer(parent) {}
Toshihiro Shimizu 890ddd
shun-iwasawa 92d40c
  bool zoom(bool zoomin, bool resetView) override {
shun-iwasawa 92d40c
    static_cast<schematicsceneviewer *="">(getWidget())->zoomQt(zoomin, resetView);</schematicsceneviewer>
shun-iwasawa 92d40c
    return true;
shun-iwasawa 92d40c
  }
shun-iwasawa 92d40c
  bool resetZoom() override {
shun-iwasawa 92d40c
    static_cast<schematicsceneviewer *="">(getWidget())->normalizeScene();</schematicsceneviewer>
shun-iwasawa 92d40c
    return true;
shun-iwasawa 92d40c
  }
shun-iwasawa 92d40c
  bool fit() override {
shun-iwasawa 92d40c
    static_cast<schematicsceneviewer *="">(getWidget())->fitScene();</schematicsceneviewer>
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SchematicScene
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SchematicScene::SchematicScene(QWidget *parent) : QGraphicsScene(parent) {
Shinya Kitaoka 120a6e
  setSceneRect(0, 0, 50000, 50000);
Shinya Kitaoka 120a6e
  setItemIndexMethod(NoIndex);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SchematicScene::~SchematicScene() { clearAllItems(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicScene::showEvent(QShowEvent *se) {
Shinya Kitaoka 120a6e
  TSelectionHandle *selHandle = TSelectionHandle::getCurrent();
Shinya Kitaoka 120a6e
  connect(selHandle, SIGNAL(selectionSwitched(TSelection *, TSelection *)),
Shinya Kitaoka 120a6e
          this, SLOT(onSelectionSwitched(TSelection *, TSelection *)));
Shinya Kitaoka 120a6e
  clearSelection();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicScene::hideEvent(QHideEvent *se) {
Shinya Kitaoka 120a6e
  TSelectionHandle *selHandle = TSelectionHandle::getCurrent();
Shinya Kitaoka 120a6e
  disconnect(selHandle, SIGNAL(selectionSwitched(TSelection *, TSelection *)),
Shinya Kitaoka 120a6e
             this, SLOT(onSelectionSwitched(TSelection *, TSelection *)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*! Removes and then deletes all item in the scene.
shun-iwasawa 92d40c
 */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicScene::clearAllItems() {
Shinya Kitaoka 120a6e
  clearSelection();
Shinya Kitaoka 120a6e
  m_highlightedLinks.clear();
Shinya Kitaoka 120a6e
  QList<schematicwindoweditor *=""> editors;</schematicwindoweditor>
Shinya Kitaoka 120a6e
  QList<schematicnode *=""> nodes;</schematicnode>
Shinya Kitaoka 120a6e
  QList<schematiclink *=""> links;</schematiclink>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> sceneItems = items();</qgraphicsitem>
Shinya Kitaoka 120a6e
  int size                          = sceneItems.size();
Shinya Kitaoka 120a6e
  // create nodes and links list
Shinya Kitaoka 120a6e
  for (i = 0; i < size; i++) {
Shinya Kitaoka 120a6e
    QGraphicsItem *item           = sceneItems.at(i);
Shinya Kitaoka 120a6e
    SchematicWindowEditor *editor = dynamic_cast<schematicwindoweditor *="">(item);</schematicwindoweditor>
Shinya Kitaoka 120a6e
    SchematicNode *node           = dynamic_cast<schematicnode *="">(item);</schematicnode>
Shinya Kitaoka 120a6e
    SchematicLink *link           = dynamic_cast<schematiclink *="">(item);</schematiclink>
Shinya Kitaoka 120a6e
    if (editor) editors.append(editor);
Shinya Kitaoka 120a6e
    if (node) nodes.append(node);
Shinya Kitaoka 120a6e
    if (link) links.append(link);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  while (links.size() > 0) {
Shinya Kitaoka 120a6e
    SchematicLink *link = links.back();
Shinya Kitaoka 120a6e
    removeItem(link);
Shinya Kitaoka 120a6e
    links.removeLast();
Shinya Kitaoka 120a6e
    SchematicPort *startPort = link->getStartPort();
Shinya Kitaoka 120a6e
    SchematicPort *endPort   = link->getEndPort();
Shinya Kitaoka 120a6e
    if (startPort) startPort->removeLink(link);
Shinya Kitaoka 120a6e
    if (endPort) endPort->removeLink(link);
Shinya Kitaoka 120a6e
    delete link;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  while (editors.size() > 0) {
Shinya Kitaoka 120a6e
    SchematicWindowEditor *editor = editors.back();
Shinya Kitaoka 120a6e
    removeItem(editor);
Shinya Kitaoka 120a6e
    editors.removeLast();
Shinya Kitaoka 120a6e
    delete editor;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  while (nodes.size() > 0) {
Shinya Kitaoka 120a6e
    SchematicNode *node = nodes.back();
Shinya Kitaoka 120a6e
    removeItem(node);
Shinya Kitaoka 120a6e
    nodes.removeLast();
Shinya Kitaoka 120a6e
    delete node;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  assert(items().size() == 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! check if any item exists in the rect
shun-iwasawa 92d40c
 */
Shinya Kitaoka 120a6e
bool SchematicScene::isAnEmptyZone(const QRectF &rect) {
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> allItems = items();</qgraphicsitem>
Shinya Kitaoka 120a6e
  for (auto const level : allItems) {
Shinya Kitaoka 120a6e
    SchematicNode *node = dynamic_cast<schematicnode *="">(level);</schematicnode>
Shinya Kitaoka 120a6e
    if (!node) continue;
Shinya Kitaoka 120a6e
    FxSchematicNode *fxNode = dynamic_cast<fxschematicnode *="">(node);</fxschematicnode>
Shinya Kitaoka 120a6e
    if (fxNode && fxNode->isA(eXSheetFx)) continue;
Shinya Kitaoka 120a6e
    if (node->boundingRect().translated(node->scenePos()).intersects(rect))
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return true;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
QVector<schematicnode *=""> SchematicScene::getPlacedNode(SchematicNode *node) {</schematicnode>
Shinya Kitaoka 120a6e
  QRectF rect = node->boundingRect().translated(node->scenePos());
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> allItems = items();</qgraphicsitem>
Shinya Kitaoka 120a6e
  QVector<schematicnode *=""> nodes;</schematicnode>
Shinya Kitaoka 120a6e
  for (auto const item : allItems) {
Shinya Kitaoka 120a6e
    SchematicNode *placedNode = dynamic_cast<schematicnode *="">(item);</schematicnode>
Shinya Kitaoka 120a6e
    if (!placedNode || placedNode == node) continue;
Shinya Kitaoka 120a6e
    QRectF nodeRect =
Shinya Kitaoka 120a6e
        placedNode->boundingRect().translated(placedNode->scenePos());
Shinya Kitaoka 120a6e
    QRectF enlargedRect = rect.adjusted(-10, -10, 10, 10);
Shinya Kitaoka 120a6e
    if (enlargedRect.contains(nodeRect)) nodes.push_back(placedNode);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return nodes;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SchematicSceneViewer
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SchematicSceneViewer::SchematicSceneViewer(QWidget *parent)
Shinya Kitaoka 120a6e
    : QGraphicsView(parent)
Shinya Kitaoka 120a6e
    , m_buttonState(Qt::NoButton)
Shinya Kitaoka 120a6e
    , m_oldWinPos()
Shinya Kitaoka 120a6e
    , m_oldScenePos()
Shinya Kitaoka 120a6e
    , m_firstShowing(true) {
Shinya Kitaoka 120a6e
  setObjectName("SchematicSceneViewer");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Shinya Kitaoka 120a6e
  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Shinya Kitaoka 120a6e
  setDragMode(QGraphicsView::NoDrag);
Shinya Kitaoka 120a6e
  setTransformationAnchor(QGraphicsView::NoAnchor);
Shinya Kitaoka 120a6e
  setRenderHint(QPainter::SmoothPixmapTransform);
Shinya Kitaoka 120a6e
  setRenderHint(QPainter::TextAntialiasing);
Shinya Kitaoka 120a6e
  setRenderHint(QPainter::Antialiasing);
Shinya Kitaoka 120a6e
  setInteractive(true);
Shinya Kitaoka 120a6e
  setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
Shinya Kitaoka 120a6e
  show();
manongjohn a99cb6
manongjohn a99cb6
  setAttribute(Qt::WA_AcceptTouchEvents);
manongjohn a99cb6
  grabGesture(Qt::SwipeGesture);
manongjohn a99cb6
  grabGesture(Qt::PanGesture);
manongjohn a99cb6
  grabGesture(Qt::PinchGesture);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SchematicSceneViewer::~SchematicSceneViewer() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
/*! Reimplemets the QGraphicsView::mousePressEvent()
shun-iwasawa 92d40c
 */
Shinya Kitaoka 120a6e
void SchematicSceneViewer::mousePressEvent(QMouseEvent *me) {
manongjohn 6087a0
  // qDebug() << "[mousePressEvent]";
manongjohn 6af389
  if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen &&
manongjohn 6af389
      !m_stylusUsed) {
manongjohn a99cb6
    return;
manongjohn a99cb6
  }
manongjohn a99cb6
Shinya Kitaoka 120a6e
  m_buttonState = me->button();
manongjohn 6b57d9
  m_oldWinPos   = me->pos();
manongjohn 6b57d9
  m_oldScenePos = mapToScene(m_oldWinPos);
manongjohn a99cb6
manongjohn a99cb6
  if (m_buttonState == Qt::LeftButton) {
manongjohn a99cb6
    if (m_cursorMode == CursorMode::Zoom) {
manongjohn 931ad2
      m_zoomPoint = me->pos();
manongjohn 931ad2
      m_zooming   = true;
manongjohn a99cb6
      return;
manongjohn a99cb6
    } else if (m_cursorMode == CursorMode::Hand) {
manongjohn 0b7d7e
      m_mousePanPoint = m_touchDevice == QTouchDevice::TouchScreen
manongjohn eca762
                            ? mapToScene(me->pos())
manongjohn da00ce
                            : me->pos() * getDevPixRatio();
manongjohn eca762
      m_panning = true;
manongjohn a99cb6
      return;
manongjohn a99cb6
    }
manongjohn 6b57d9
  } else if (m_buttonState == Qt::MidButton) {
manongjohn 0b7d7e
    m_mousePanPoint = m_touchDevice == QTouchDevice::TouchScreen
manongjohn eca762
                          ? mapToScene(me->pos())
manongjohn da00ce
                          : me->pos() * getDevPixRatio();
manongjohn a99cb6
  }
Shinya Kitaoka 120a6e
  bool drawRect                       = true;
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> pointedItems = items(me->pos());</qgraphicsitem>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < pointedItems.size(); i++) {
Shinya Kitaoka 120a6e
    SchematicWindowEditor *editor =
Shinya Kitaoka 120a6e
        dynamic_cast<schematicwindoweditor *="">(pointedItems[i]);</schematicwindoweditor>
Shinya Kitaoka 120a6e
    if (!editor) {
Shinya Kitaoka 120a6e
      drawRect = false;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_buttonState == Qt::LeftButton && drawRect)
Shinya Kitaoka 120a6e
    setDragMode(QGraphicsView::RubberBandDrag);
Shinya Kitaoka 120a6e
  QGraphicsView::mousePressEvent(me);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
/*! Reimplemets the QGraphicsView::mouseMoveEvent()
shun-iwasawa 92d40c
 */
Shinya Kitaoka 120a6e
void SchematicSceneViewer::mouseMoveEvent(QMouseEvent *me) {
manongjohn 6af389
  if (m_gestureActive && m_touchDevice == QTouchDevice::TouchScreen &&
manongjohn 6af389
      !m_stylusUsed) {
manongjohn a99cb6
    return;
manongjohn a99cb6
  }
manongjohn a99cb6
Shinya Kitaoka 120a6e
  QPoint currWinPos    = me->pos();
Shinya Kitaoka 120a6e
  QPointF currScenePos = mapToScene(currWinPos);
manongjohn a99cb6
  if ((m_cursorMode == CursorMode::Hand && m_panning) ||
manongjohn a99cb6
      m_buttonState == Qt::MidButton) {
manongjohn 6e9f12
    QPointF usePos = m_touchDevice == QTouchDevice::TouchScreen
manongjohn 2a5e2e
                         ? mapToScene(me->pos())
manongjohn da00ce
                         : me->pos() * getDevPixRatio();
manongjohn 0b7d7e
    QPointF deltaPoint = usePos - m_mousePanPoint;
manongjohn 6b57d9
    panQt(deltaPoint);
manongjohn 0b7d7e
    m_mousePanPoint = m_touchDevice == QTouchDevice::TouchScreen
manongjohn 7dbf30
                          ? mapToScene(me->pos())
manongjohn da00ce
                          : me->pos() * getDevPixRatio();
manongjohn a99cb6
  } else {
manongjohn 6b57d9
    if (m_cursorMode == CursorMode::Zoom && m_zooming) {
manongjohn 6b57d9
      int deltaY     = (m_oldWinPos.y() - me->pos().y()) * 10;
manongjohn 6b57d9
      double factorY = exp(deltaY * 0.001);
manongjohn 6e9f12
      changeScale(m_zoomPoint, factorY);
manongjohn 0b7d7e
      m_panning = false;
manongjohn 6b57d9
    }
manongjohn a99cb6
    m_oldWinPos   = currWinPos;
manongjohn a99cb6
    m_oldScenePos = currScenePos;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  QGraphicsView::mouseMoveEvent(me);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*! Reimplemets the QGraphicsView::mouseReleaseEvent()
shun-iwasawa 92d40c
 */
Shinya Kitaoka 120a6e
void SchematicSceneViewer::mouseReleaseEvent(QMouseEvent *me) {
manongjohn 6087a0
  // qDebug() << "[mouseReleaseEvent]";
manongjohn 36f776
  m_gestureActive = false;
manongjohn 36f776
  m_zooming       = false;
manongjohn 36f776
  m_panning       = false;
manongjohn 36f776
  m_stylusUsed    = false;
manongjohn 36f776
  m_scaleFactor   = 0.0;
manongjohn a99cb6
Shinya Kitaoka 120a6e
  m_buttonState = Qt::NoButton;
Shinya Kitaoka 120a6e
  QGraphicsView::mouseReleaseEvent(me);
Shinya Kitaoka 120a6e
  setDragMode(QGraphicsView::NoDrag);
Shinya Kitaoka 120a6e
  // update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
manongjohn a99cb6
void SchematicSceneViewer::mouseDoubleClickEvent(QMouseEvent *event) {
manongjohn 6087a0
  // qDebug() << "[mouseDoubleClickEvent]";
manongjohn 6af389
  if (m_gestureActive && !m_stylusUsed) {
manongjohn a99cb6
    m_gestureActive = false;
manongjohn 36f776
    QGraphicsItem *item =
manongjohn 36f776
        scene()->itemAt(mapToScene(event->pos()), QTransform());
manongjohn 36f776
    if (!item) {
manongjohn 36f776
      fitScene();
manongjohn 36f776
      return;
manongjohn 36f776
    }
manongjohn 36f776
manongjohn 36f776
    mousePressEvent(event);
manongjohn a99cb6
  }
manongjohn ebce7c
manongjohn a99cb6
  QGraphicsView::mouseDoubleClickEvent(event);
manongjohn a99cb6
}
manongjohn 36f776
manongjohn a99cb6
//------------------------------------------------------------------
manongjohn a99cb6
Shinya Kitaoka 120a6e
void SchematicSceneViewer::keyPressEvent(QKeyEvent *ke) {
Shinya Kitaoka 120a6e
  ke->ignore();
Shinya Kitaoka 120a6e
  QGraphicsView::keyPressEvent(ke);
Shinya Kitaoka 120a6e
  if (!ke->isAccepted()) SchematicZoomer(this).exec(ke);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
/*! Reimplemets the QGraphicsView::wheelEvent()
shun-iwasawa 92d40c
 */
Shinya Kitaoka 120a6e
void SchematicSceneViewer::wheelEvent(QWheelEvent *me) {
manongjohn 6087a0
  // qDebug() << "[wheelEvent]";
manongjohn 6087a0
manongjohn 6087a0
  int delta = 0;
manongjohn 6087a0
  switch (me->source()) {
manongjohn 6087a0
  case Qt::MouseEventNotSynthesized: {
manongjohn 6087a0
    if (me->modifiers() & Qt::AltModifier)
manongjohn 6087a0
      delta = me->angleDelta().x();
manongjohn 6087a0
    else
manongjohn 6087a0
      delta = me->angleDelta().y();
manongjohn 6087a0
    break;
manongjohn 6087a0
  }
manongjohn 6087a0
manongjohn 6087a0
  case Qt::MouseEventSynthesizedBySystem: {
manongjohn 6087a0
    QPoint numPixels  = me->pixelDelta();
manongjohn 6087a0
    QPoint numDegrees = me->angleDelta() / 8;
manongjohn 6087a0
    if (!numPixels.isNull()) {
manongjohn 6087a0
      delta = me->pixelDelta().y();
manongjohn 6087a0
    } else if (!numDegrees.isNull()) {
manongjohn 6087a0
      QPoint numSteps = numDegrees / 15;
manongjohn 6087a0
      delta           = numSteps.y();
manongjohn 6087a0
    }
manongjohn 6087a0
    break;
manongjohn ebce7c
  }
manongjohn 6087a0
manongjohn 6087a0
  default:  // Qt::MouseEventSynthesizedByQt,
manongjohn 6087a0
            // Qt::MouseEventSynthesizedByApplication
Kite 521c84
    {
Kite 521c84
      std::cout << "not supported event: Qt::MouseEventSynthesizedByQt, "
Kite 521c84
                   "Qt::MouseEventSynthesizedByApplication"
Kite 521c84
                << std::endl;
Kite 521c84
      break;
Kite 521c84
    }
manongjohn 6087a0
manongjohn 6087a0
  }  // end switch
manongjohn 6087a0
manongjohn 6087a0
  if (abs(delta) > 0) {
manongjohn 6087a0
    if ((m_gestureActive == true &&
manongjohn 6087a0
         m_touchDevice == QTouchDevice::TouchScreen) ||
manongjohn 6087a0
        m_gestureActive == false) {
manongjohn 6087a0
      double factor = exp(delta * 0.001);
manongjohn 931ad2
      changeScale(me->pos(), factor);
manongjohn 0b7d7e
      m_panning = false;
manongjohn 6087a0
    }
manongjohn 6087a0
  }
manongjohn 6087a0
  me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 92d40c
void SchematicSceneViewer::zoomQt(bool zoomin, bool resetView) {
shun-iwasawa 92d40c
  if (resetView) {
shun-iwasawa 92d40c
    resetMatrix();
shun-iwasawa 92d40c
    // reseting will set view to the center of items bounding
shun-iwasawa 92d40c
    centerOn(scene()->itemsBoundingRect().center());
shun-iwasawa 92d40c
    return;
shun-iwasawa 92d40c
  }
shun-iwasawa 92d40c
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
  double scale2 = matrix().determinant();
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  double scale2 = matrix().det();
Toshihiro Shimizu 890ddd
#endif
shun-iwasawa 92d40c
  if ((scale2 < 100000 || !zoomin) && (scale2 > 0.001 * 0.05 || zoomin)) {
Shinya Kitaoka 120a6e
    double oldZoomScale = sqrt(scale2);
Kite 521c84
    double zoomScale    = resetView ? 1 : ImageUtils::getQuantizedZoomFactor(
Kite 521c84
                                           oldZoomScale, zoomin);
Shinya Kitaoka 120a6e
    QMatrix scale =
Shinya Kitaoka 120a6e
        QMatrix().scale(zoomScale / oldZoomScale, zoomScale / oldZoomScale);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // See QGraphicsView::mapToScene()'s doc for details
shun-iwasawa 92d40c
    QPointF sceneCenter(mapToScene(rect().center()));
Shinya Kitaoka 120a6e
    setMatrix(scale, true);
shun-iwasawa 92d40c
    centerOn(sceneCenter);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*! The view is scaled around the point \b winPos by \b scaleFactor;
shun-iwasawa 92d40c
 */
Shinya Kitaoka 120a6e
void SchematicSceneViewer::changeScale(const QPoint &winPos,
Shinya Kitaoka 120a6e
                                       qreal scaleFactor) {
manongjohn 0b7d7e
  QPointF startScenePos = mapToScene(winPos);
manongjohn 0b7d7e
  QMatrix scale         = QMatrix().scale(scaleFactor, scaleFactor);
Shinya Kitaoka 120a6e
  setMatrix(scale, true);
manongjohn 0b7d7e
  QPointF endScenePos = mapToScene(winPos);
manongjohn 0b7d7e
  QPointF delta       = endScenePos - startScenePos;
Shinya Kitaoka 120a6e
  translate(delta.x(), delta.y());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicSceneViewer::fitScene() {
Shinya Kitaoka 120a6e
  if (scene()) {
Shinya Kitaoka 120a6e
    QRectF rect = scene()->itemsBoundingRect();
Shinya Kitaoka 120a6e
    fitInView(rect, Qt::KeepAspectRatio);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicSceneViewer::centerOnCurrent() {
Shinya Kitaoka 120a6e
  SchematicScene *schematicScene = dynamic_cast<schematicscene *="">(scene());</schematicscene>
Shinya Kitaoka 120a6e
  QGraphicsItem *node            = schematicScene->getCurrentNode();
Shinya Kitaoka 120a6e
  if (node) centerOn(node);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicSceneViewer::reorderScene() {
Shinya Kitaoka 120a6e
  SchematicScene *schematicScene = dynamic_cast<schematicscene *="">(scene());</schematicscene>
Shinya Kitaoka 120a6e
  schematicScene->reorderScene();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicSceneViewer::normalizeScene() {
Shinya Kitaoka 120a6e
  // See QGraphicsView::mapToScene()'s doc for details
shun-iwasawa 92d40c
  QPointF sceneCenter(mapToScene(rect().center()));
Shinya Kitaoka 120a6e
  resetMatrix();
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Shinya Kitaoka 120a6e
  scale(1.32, 1.32);
Toshihiro Shimizu 890ddd
#endif
shun-iwasawa 92d40c
  centerOn(sceneCenter);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
manongjohn 6b57d9
void SchematicSceneViewer::panQt(const QPointF &delta) {
manongjohn 0b7d7e
  if (delta == QPointF()) return;
manongjohn a99cb6
  setInteractive(false);
manongjohn a99cb6
  // I need to disable QGraphicsView event handling to avoid the generation of
manongjohn a99cb6
  // 'virtual' mouseMoveEvent
manongjohn 6b57d9
  translate(delta.x(), delta.y());
manongjohn a99cb6
  // translate has changed the matrix affecting the mapToScene() method. I
manongjohn a99cb6
  // have to recompute currScenePos
manongjohn a99cb6
  setInteractive(true);
manongjohn a99cb6
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicSceneViewer::showEvent(QShowEvent *se) {
Shinya Kitaoka 120a6e
  QGraphicsView::showEvent(se);
Shinya Kitaoka 120a6e
  if (m_firstShowing) {
Shinya Kitaoka 120a6e
    m_firstShowing = false;
Shinya Kitaoka 120a6e
    QRectF rect    = scene()->itemsBoundingRect();
Shinya Kitaoka 120a6e
    resetMatrix();
Shinya Kitaoka 120a6e
    centerOn(rect.center());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
manongjohn a99cb6
//------------------------------------------------------------------
manongjohn 6af389
manongjohn 3c9f8d
void SchematicSceneViewer::enterEvent(QEvent *e) {
manongjohn 3c9f8d
  switch (m_cursorMode) {
manongjohn 3c9f8d
  case CursorMode::Hand:
manongjohn 3c9f8d
    setToolCursor(this, ToolCursor::PanCursor);
manongjohn 3c9f8d
    break;
manongjohn 3c9f8d
  case CursorMode::Zoom:
manongjohn 3c9f8d
    setToolCursor(this, ToolCursor::ZoomCursor);
manongjohn 3c9f8d
    break;
manongjohn 3c9f8d
  default:
manongjohn 3c9f8d
    setToolCursor(this, ToolCursor::StrokeSelectCursor);
manongjohn 3c9f8d
    break;
manongjohn 3c9f8d
  }
manongjohn 3c9f8d
}
manongjohn 3c9f8d
manongjohn 3c9f8d
//------------------------------------------------------------------
manongjohn 3c9f8d
manongjohn 3c9f8d
void SchematicSceneViewer::leaveEvent(QEvent *e) { setCursor(Qt::ArrowCursor); }
manongjohn 3c9f8d
manongjohn 3c9f8d
//------------------------------------------------------------------
manongjohn 3c9f8d
manongjohn 6af389
void SchematicSceneViewer::tabletEvent(QTabletEvent *e) {
manongjohn 6087a0
  // qDebug() << "[tabletEvent]";
manongjohn 6af389
  if (e->type() == QTabletEvent::TabletPress) {
manongjohn 6af389
    m_stylusUsed = e->pointerType() ? true : false;
manongjohn 6af389
  } else if (e->type() == QTabletEvent::TabletRelease) {
manongjohn 6af389
    m_stylusUsed = false;
manongjohn 6af389
  }
manongjohn 6af389
manongjohn 6af389
  e->accept();
manongjohn 6af389
}
manongjohn 6af389
manongjohn 6af389
//------------------------------------------------------------------
manongjohn ebce7c
manongjohn a99cb6
void SchematicSceneViewer::gestureEvent(QGestureEvent *e) {
manongjohn 6087a0
  // qDebug() << "[gestureEvent]";
manongjohn a99cb6
  m_gestureActive = false;
manongjohn a99cb6
  if (QGesture *swipe = e->gesture(Qt::SwipeGesture)) {
manongjohn a99cb6
    m_gestureActive = true;
manongjohn a99cb6
  } else if (QGesture *pan = e->gesture(Qt::PanGesture)) {
manongjohn a99cb6
    m_gestureActive = true;
manongjohn a99cb6
  }
manongjohn a99cb6
  if (QGesture *pinch = e->gesture(Qt::PinchGesture)) {
manongjohn a99cb6
    QPinchGesture *gesture = static_cast<qpinchgesture *="">(pinch);</qpinchgesture>
manongjohn a99cb6
    QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
manongjohn c2ff21
    QPoint firstCenter                     = gesture->centerPoint().toPoint();
manongjohn c2ff21
    if (m_touchDevice == QTouchDevice::TouchScreen)
manongjohn c2ff21
      firstCenter = mapFromGlobal(firstCenter);
manongjohn a99cb6
manongjohn a99cb6
    if (gesture->state() == Qt::GestureStarted) {
manongjohn 6b57d9
      m_gestureActive = true;
manongjohn a99cb6
    } else if (gesture->state() == Qt::GestureFinished) {
manongjohn 6b57d9
      m_gestureActive = false;
manongjohn 6b57d9
      m_zooming       = false;
manongjohn 6b57d9
      m_scaleFactor   = 0.0;
manongjohn a99cb6
    } else {
manongjohn a99cb6
      if (changeFlags & QPinchGesture::ScaleFactorChanged) {
manongjohn a99cb6
        double scaleFactor = gesture->scaleFactor();
manongjohn a99cb6
        // the scale factor makes for too sensitive scaling
manongjohn a99cb6
        // divide the change in half
manongjohn a99cb6
        if (scaleFactor > 1) {
manongjohn a99cb6
          double decimalValue = scaleFactor - 1;
manongjohn a99cb6
          decimalValue /= 1.5;
manongjohn a99cb6
          scaleFactor = 1 + decimalValue;
manongjohn a99cb6
        } else if (scaleFactor < 1) {
manongjohn a99cb6
          double decimalValue = 1 - scaleFactor;
manongjohn a99cb6
          decimalValue /= 1.5;
manongjohn a99cb6
          scaleFactor = 1 - decimalValue;
manongjohn a99cb6
        }
manongjohn a99cb6
        if (!m_zooming) {
manongjohn a99cb6
          double delta = scaleFactor - 1;
manongjohn a99cb6
          m_scaleFactor += delta;
manongjohn a99cb6
          if (m_scaleFactor > .2 || m_scaleFactor < -.2) {
manongjohn a99cb6
            m_zooming = true;
manongjohn a99cb6
          }
manongjohn a99cb6
        }
manongjohn a99cb6
        if (m_zooming) {
manongjohn 931ad2
          changeScale(firstCenter, scaleFactor);
manongjohn 0b7d7e
          m_panning = false;
manongjohn a99cb6
        }
manongjohn a99cb6
        m_gestureActive = true;
manongjohn a99cb6
      }
manongjohn a99cb6
manongjohn a99cb6
      if (changeFlags & QPinchGesture::CenterPointChanged) {
manongjohn 6b57d9
        QPointF centerDelta = (gesture->centerPoint() * getDevPixRatio()) -
manongjohn 6b57d9
                              (gesture->lastCenterPoint() * getDevPixRatio());
manongjohn 6b57d9
        if (centerDelta.manhattanLength() > 1) {
manongjohn 6b57d9
          // panQt(centerDelta.toPoint());
manongjohn a99cb6
        }
manongjohn a99cb6
        m_gestureActive = true;
manongjohn a99cb6
      }
manongjohn a99cb6
    }
manongjohn a99cb6
  }
manongjohn a99cb6
  e->accept();
manongjohn a99cb6
}
manongjohn a99cb6
manongjohn 6b57d9
void SchematicSceneViewer::touchEvent(QTouchEvent *e, int type) {
manongjohn 6087a0
  // qDebug() << "[touchEvent]";
manongjohn 6b57d9
  if (type == QEvent::TouchBegin) {
manongjohn 6b57d9
    m_touchActive   = true;
manongjohn 6b57d9
    m_firstPanPoint = e->touchPoints().at(0).pos();
manongjohn 6b57d9
    // obtain device type
manongjohn 6b57d9
    m_touchDevice = e->device()->type();
manongjohn 6b57d9
  } else if (m_touchActive) {
manongjohn 6b57d9
    // touchpads must have 2 finger panning for tools and navigation to be
manongjohn 6b57d9
    // functional on other devices, 1 finger panning is preferred
manongjohn 6b57d9
    if ((e->touchPoints().count() == 2 &&
manongjohn 6b57d9
         m_touchDevice == QTouchDevice::TouchPad) ||
manongjohn 6b57d9
        (e->touchPoints().count() == 1 &&
manongjohn 6b57d9
         m_touchDevice == QTouchDevice::TouchScreen)) {
manongjohn 6b57d9
      QTouchEvent::TouchPoint panPoint = e->touchPoints().at(0);
manongjohn 6b57d9
      if (!m_panning) {
manongjohn 6b57d9
        QPointF deltaPoint = panPoint.pos() - m_firstPanPoint;
manongjohn 6b57d9
        // minimize accidental and jerky zooming/rotating during 2 finger
manongjohn 6b57d9
        // panning
manongjohn 6b57d9
        if ((deltaPoint.manhattanLength() > 100) && !m_zooming) {
manongjohn 6b57d9
          m_panning = true;
manongjohn 6b57d9
        }
manongjohn 6b57d9
      }
manongjohn 6b57d9
      if (m_panning) {
manongjohn 6e9f12
        QPointF curPos =
manongjohn 6e9f12
            m_touchDevice == QTouchDevice::TouchScreen
manongjohn 6e9f12
                ? mapToScene(panPoint.pos().toPoint())
manongjohn 6e9f12
                : mapToScene(panPoint.pos().toPoint()) * getDevPixRatio();
manongjohn 6e9f12
        QPointF lastPos =
manongjohn 6e9f12
            m_touchDevice == QTouchDevice::TouchScreen
manongjohn 6e9f12
                ? mapToScene(panPoint.lastPos().toPoint())
manongjohn 6e9f12
                : mapToScene(panPoint.lastPos().toPoint()) * getDevPixRatio();
manongjohn 6e9f12
        QPointF centerDelta = curPos - lastPos;
manongjohn fe6ab3
        panQt(centerDelta);
manongjohn 6b57d9
      }
manongjohn 6b57d9
    }
manongjohn 6b57d9
  }
manongjohn 6b57d9
  if (type == QEvent::TouchEnd || type == QEvent::TouchCancel) {
manongjohn 6b57d9
    m_touchActive = false;
manongjohn 6b57d9
    m_panning     = false;
manongjohn 6b57d9
  }
manongjohn 6b57d9
  e->accept();
manongjohn 6b57d9
}
manongjohn a99cb6
manongjohn a99cb6
bool SchematicSceneViewer::event(QEvent *e) {
manongjohn ebce7c
  /*
manongjohn 6087a0
  switch (e->type()) {
manongjohn 6087a0
  case QEvent::TabletPress: {
manongjohn 6087a0
    QTabletEvent *te = static_cast<qtabletevent *="">(e);</qtabletevent>
manongjohn 6087a0
    qDebug() << "[event] TabletPress: pointerType(" << te->pointerType()
manongjohn 6087a0
             << ") device(" << te->device() << ")";
manongjohn 6087a0
  } break;
manongjohn 6087a0
  case QEvent::TabletRelease:
manongjohn 6087a0
    qDebug() << "[event] TabletRelease";
manongjohn 6087a0
    break;
manongjohn 6087a0
  case QEvent::TouchBegin:
manongjohn 6087a0
    qDebug() << "[event] TouchBegin";
manongjohn 6087a0
    break;
manongjohn 6087a0
  case QEvent::TouchEnd:
manongjohn 6087a0
    qDebug() << "[event] TouchEnd";
manongjohn 6087a0
    break;
manongjohn 6087a0
  case QEvent::TouchCancel:
manongjohn 6087a0
    qDebug() << "[event] TouchCancel";
manongjohn 6087a0
    break;
manongjohn 6087a0
  case QEvent::MouseButtonPress:
manongjohn 6087a0
    qDebug() << "[event] MouseButtonPress";
manongjohn 6087a0
    break;
manongjohn 6087a0
  case QEvent::MouseButtonDblClick:
manongjohn 6087a0
    qDebug() << "[event] MouseButtonDblClick";
manongjohn 6087a0
    break;
manongjohn 6087a0
  case QEvent::MouseButtonRelease:
manongjohn 6087a0
    qDebug() << "[event] MouseButtonRelease";
manongjohn 6087a0
    break;
manongjohn 6087a0
  case QEvent::Gesture:
manongjohn 6087a0
    qDebug() << "[event] Gesture";
manongjohn 6087a0
    break;
manongjohn 6087a0
  default:
manongjohn 6087a0
    break;
manongjohn 6087a0
  }
manongjohn ebce7c
  */
manongjohn ebce7c
Kite 521c84
  if (e->type() == QEvent::Gesture &&
Kite 521c84
      CommandManager::instance()
Kite 521c84
          ->getAction(MI_TouchGestureControl)
Kite 521c84
          ->isChecked()) {
manongjohn f5d48a
    gestureEvent(static_cast<qgestureevent *="">(e));</qgestureevent>
manongjohn f5d48a
    return true;
manongjohn f5d48a
  }
manongjohn 0b7d7e
  if ((e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchEnd ||
manongjohn 0b7d7e
       e->type() == QEvent::TouchCancel || e->type() == QEvent::TouchUpdate) &&
manongjohn 0b7d7e
      CommandManager::instance()
manongjohn 0b7d7e
          ->getAction(MI_TouchGestureControl)
manongjohn 0b7d7e
          ->isChecked()) {
manongjohn f5d48a
    touchEvent(static_cast<qtouchevent *="">(e), e->type());</qtouchevent>
manongjohn f5d48a
    m_gestureActive = true;
manongjohn f5d48a
    return true;
manongjohn a99cb6
  }
manongjohn a99cb6
  return QGraphicsView::event(e);
manongjohn a99cb6
}
manongjohn a99cb6
manongjohn a99cb6
//------------------------------------------------------------------
manongjohn a99cb6
manongjohn a99cb6
void SchematicSceneViewer::setCursorMode(CursorMode cursorMode) {
manongjohn a99cb6
  m_cursorMode = cursorMode;
manongjohn a99cb6
}
manongjohn a99cb6
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SchematicViewer
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SchematicViewer::SchematicViewer(QWidget *parent)
Shinya Kitaoka 120a6e
    : QWidget(parent)
Shinya Kitaoka 120a6e
    , m_fullSchematic(true)
Shinya Kitaoka 120a6e
    , m_maximizedNode(false)
manongjohn a99cb6
    , m_sceneHandle(0)
manongjohn a99cb6
    , m_cursorMode(CursorMode::Select) {
Shinya Kitaoka 120a6e
  m_viewer     = new SchematicSceneViewer(this);
Shinya Kitaoka 120a6e
  m_stageScene = new StageSchematicScene(this);
Shinya Kitaoka 120a6e
  m_fxScene    = new FxSchematicScene(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_commonToolbar = new QToolBar(m_viewer);
Shinya Kitaoka 120a6e
  m_stageToolbar  = new QToolBar(m_viewer);
Shinya Kitaoka 120a6e
  m_fxToolbar     = new QToolBar(m_viewer);
Shinya Kitaoka 120a6e
  m_swapToolbar   = new QToolBar(m_viewer);
Toshihiro Shimizu 890ddd
shun_iwasawa 4a5f42
  m_commonToolbar->setObjectName("MediumPaddingToolBar");
shun_iwasawa 4a5f42
  m_stageToolbar->setObjectName("MediumPaddingToolBar");
shun_iwasawa 4a5f42
  m_fxToolbar->setObjectName("MediumPaddingToolBar");
shun_iwasawa 4a5f42
  m_swapToolbar->setObjectName("MediumPaddingToolBar");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  createToolbars();
Shinya Kitaoka 120a6e
  createActions();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // layout
Shinya Kitaoka 120a6e
  QVBoxLayout *mainLayout = new QVBoxLayout();
Jeremy Bullock 915f19
  mainLayout->setMargin(0);
Shinya Kitaoka 120a6e
  mainLayout->setSpacing(0);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_viewer, 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    QFrame *bottomFrame = new QFrame(this);
Shinya Kitaoka 120a6e
    bottomFrame->setObjectName("SchematicBottomFrame");
Shinya Kitaoka 120a6e
    QHBoxLayout *horizontalLayout = new QHBoxLayout();
Shinya Kitaoka 120a6e
    horizontalLayout->setMargin(0);
Shinya Kitaoka 120a6e
    horizontalLayout->setSpacing(0);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      horizontalLayout->addWidget(m_commonToolbar);
Shinya Kitaoka 120a6e
      horizontalLayout->addStretch();
Shinya Kitaoka 120a6e
      horizontalLayout->addWidget(m_fxToolbar);
Shinya Kitaoka 120a6e
      horizontalLayout->addWidget(m_stageToolbar);
Shinya Kitaoka 120a6e
      horizontalLayout->addWidget(m_swapToolbar);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    bottomFrame->setLayout(horizontalLayout);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    mainLayout->addWidget(bottomFrame, 0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setLayout(mainLayout);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(m_fxScene, SIGNAL(showPreview(TFxP)), this,
Shinya Kitaoka 120a6e
          SIGNAL(showPreview(TFxP)));
Shinya Kitaoka 120a6e
  connect(m_fxScene, SIGNAL(doCollapse(const QList<tfxp> &)), this,</tfxp>
Shinya Kitaoka 120a6e
          SIGNAL(doCollapse(const QList<tfxp> &)));</tfxp>
Shinya Kitaoka 120a6e
  connect(m_stageScene, SIGNAL(doCollapse(QList<tstageobjectid>)), this,</tstageobjectid>
Shinya Kitaoka 120a6e
          SIGNAL(doCollapse(QList<tstageobjectid>)));</tstageobjectid>
Shinya Kitaoka 120a6e
  connect(m_fxScene, SIGNAL(doExplodeChild(const QList<tfxp> &)), this,</tfxp>
Shinya Kitaoka 120a6e
          SIGNAL(doExplodeChild(const QList<tfxp> &)));</tfxp>
Shinya Kitaoka 120a6e
  connect(m_stageScene, SIGNAL(doExplodeChild(QList<tstageobjectid>)), this,</tstageobjectid>
Shinya Kitaoka 120a6e
          SIGNAL(doExplodeChild(QList<tstageobjectid>)));</tstageobjectid>
Shinya Kitaoka 120a6e
  connect(m_stageScene, SIGNAL(editObject()), this, SIGNAL(editObject()));
Shinya Kitaoka 120a6e
  connect(m_fxScene, SIGNAL(editObject()), this, SIGNAL(editObject()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_viewer->setScene(m_stageScene);
Shinya Kitaoka 120a6e
  m_fxToolbar->hide();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setFocusProxy(m_viewer);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SchematicViewer::~SchematicViewer() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
manongjohn d6e3cc
void SchematicViewer::getNodeColor(int ltype, QColor &nodeColor) {
manongjohn d6e3cc
  switch (ltype) {
manongjohn d6e3cc
  case TZI_XSHLEVEL:
manongjohn d6e3cc
  case OVL_XSHLEVEL:
manongjohn d6e3cc
    nodeColor = getFullcolorColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case PLI_XSHLEVEL:
manongjohn d6e3cc
    nodeColor = getVectorColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case TZP_XSHLEVEL:
manongjohn d6e3cc
    nodeColor = getLevelColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case ZERARYFX_XSHLEVEL:
manongjohn d6e3cc
    nodeColor = getFxColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case CHILD_XSHLEVEL:
manongjohn d6e3cc
    nodeColor = getChildColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case MESH_XSHLEVEL:
manongjohn d6e3cc
    nodeColor = getMeshColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case PLT_XSHLEVEL:
manongjohn d6e3cc
    nodeColor = getPaletteColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case eNormalFx:
manongjohn d6e3cc
    nodeColor = getNormalFxColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case eZeraryFx:
manongjohn d6e3cc
    nodeColor = getFxColumnColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case eMacroFx:
manongjohn d6e3cc
    nodeColor = getMacroFxColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case eGroupedFx:
manongjohn d6e3cc
    nodeColor = getGroupColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case eNormalImageAdjustFx:
manongjohn d6e3cc
    nodeColor = getImageAdjustFxColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case eNormalLayerBlendingFx:
manongjohn d6e3cc
    nodeColor = getLayerBlendingFxColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  case eNormalMatteFx:
manongjohn d6e3cc
    nodeColor = getMatteFxColor();
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  default:
manongjohn d6e3cc
    nodeColor = grey210;
manongjohn d6e3cc
    break;
manongjohn d6e3cc
  }
manongjohn d6e3cc
}
manongjohn d6e3cc
manongjohn d6e3cc
//------------------------------------------------------------------
manongjohn d6e3cc
Shinya Kitaoka 120a6e
void SchematicViewer::setApplication(TApplication *app) {
Shinya Kitaoka 120a6e
  m_stageScene->setXsheetHandle(app->getCurrentXsheet());
Shinya Kitaoka 120a6e
  m_stageScene->setObjectHandle(app->getCurrentObject());
Shinya Kitaoka 120a6e
  m_stageScene->setFxHandle(app->getCurrentFx());
Shinya Kitaoka 120a6e
  m_stageScene->setColumnHandle(app->getCurrentColumn());
Shinya Kitaoka 120a6e
  m_stageScene->setSceneHandle(app->getCurrentScene());
Shinya Kitaoka 120a6e
  m_stageScene->setFrameHandle(app->getCurrentFrame());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_fxScene->setApplication(app);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SchematicViewer::updateSchematic() {
Shinya Kitaoka 120a6e
  m_stageScene->updateScene();
Shinya Kitaoka 120a6e
  m_fxScene->updateScene();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SchematicViewer::setSchematicScene(SchematicScene *scene) {
Shinya Kitaoka 120a6e
  if (scene) {
Shinya Kitaoka 120a6e
    m_viewer->setScene(scene);
Shinya Kitaoka 120a6e
    m_viewer->centerOn(scene->sceneRect().center());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SchematicViewer::createToolbars() {
Shinya Kitaoka 120a6e
  // Initialize them
Shinya Kitaoka 120a6e
  m_stageToolbar->setMovable(false);
Kite 521c84
  m_stageToolbar->setIconSize(QSize(20, 20));
Shinya Kitaoka 120a6e
  m_stageToolbar->setLayoutDirection(Qt::RightToLeft);
Shinya Kitaoka 120a6e
  m_stageToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_commonToolbar->setMovable(false);
Kite 521c84
  m_commonToolbar->setIconSize(QSize(20, 20));
Shinya Kitaoka 120a6e
  m_commonToolbar->setLayoutDirection(Qt::RightToLeft);
Shinya Kitaoka 120a6e
  m_commonToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_fxToolbar->setMovable(false);
Kite 521c84
  m_fxToolbar->setIconSize(QSize(20, 20));
Shinya Kitaoka 120a6e
  m_fxToolbar->setLayoutDirection(Qt::RightToLeft);
Shinya Kitaoka 120a6e
  m_fxToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_swapToolbar->setMovable(false);
Kite 521c84
  m_swapToolbar->setIconSize(QSize(20, 20));
Shinya Kitaoka 120a6e
  m_swapToolbar->setLayoutDirection(Qt::RightToLeft);
Shinya Kitaoka 120a6e
  m_swapToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SchematicViewer::createActions() {
Shinya Kitaoka 120a6e
  // Create all actions
Shinya Kitaoka 120a6e
  QAction *addPegbar = 0, *addSpline = 0, *addCamera = 0, *insertFx = 0,
manongjohn d6e3cc
          *addOutputFx = 0, *switchPort = 0, *iconifyNodes = 0;
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    // Fit schematic
Kite 521c84
    QIcon fitSchematicIcon = createQIcon("fit_to_window");
Shinya Kitaoka 120a6e
    m_fitSchematic =
Shinya Kitaoka 120a6e
        new QAction(fitSchematicIcon, tr("&Fit to Window"), m_commonToolbar);
Shinya Kitaoka 120a6e
    connect(m_fitSchematic, SIGNAL(triggered()), m_viewer, SLOT(fitScene()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Center On
Kite 521c84
    QIcon centerOnIcon = createQIcon("focus");
Shinya Kitaoka 120a6e
    m_centerOn =
Shinya Kitaoka 120a6e
        new QAction(centerOnIcon, tr("&Focus on Current"), m_commonToolbar);
Shinya Kitaoka 120a6e
    connect(m_centerOn, SIGNAL(triggered()), m_viewer, SLOT(centerOnCurrent()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Reorder schematic
Kite 521c84
    QIcon reorderIcon = createQIcon("reorder", false);
Shinya Kitaoka 120a6e
    m_reorder = new QAction(reorderIcon, tr("&Reorder Nodes"), m_commonToolbar);
Shinya Kitaoka 120a6e
    connect(m_reorder, SIGNAL(triggered()), m_viewer, SLOT(reorderScene()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Normalize schematic schematic
Kite 521c84
    QIcon normalizeIcon = createQIcon("actual_pixel_size");
Shinya Kitaoka 120a6e
    m_normalize =
Shinya Kitaoka 120a6e
        new QAction(normalizeIcon, tr("&Reset Size"), m_commonToolbar);
Shinya Kitaoka 120a6e
    connect(m_normalize, SIGNAL(triggered()), m_viewer, SLOT(normalizeScene()));
Toshihiro Shimizu 890ddd
Kite 521c84
    QIcon nodeSizeIcon =
Kite 521c84
        createQIcon(m_maximizedNode ? "minimizenodes" : "maximizenodes");
Kite 521c84
    m_nodeSize =
Kite 521c84
        new QAction(nodeSizeIcon, m_maximizedNode ? tr("&Minimize Nodes")
Kite 521c84
                                                  : tr("&Maximize Nodes"),
Kite 521c84
                    m_commonToolbar);
Shinya Kitaoka 120a6e
    connect(m_nodeSize, SIGNAL(triggered()), this, SLOT(changeNodeSize()));
Toshihiro Shimizu 890ddd
Kite 521c84
    QIcon selectModeIcon = createQIcon("selection_schematic");
manongjohn a99cb6
    m_selectMode =
manongjohn a99cb6
        new QAction(selectModeIcon, tr("&Selection Mode"), m_commonToolbar);
manongjohn a99cb6
    m_selectMode->setCheckable(true);
manongjohn a99cb6
    connect(m_selectMode, SIGNAL(triggered()), this, SLOT(selectModeEnabled()));
manongjohn a99cb6
Kite 521c84
    QIcon zoomModeIcon = createQIcon("zoom_schematic");
manongjohn a99cb6
    m_zoomMode = new QAction(zoomModeIcon, tr("&Zoom Mode"), m_commonToolbar);
manongjohn a99cb6
    m_zoomMode->setCheckable(true);
manongjohn a99cb6
    connect(m_zoomMode, SIGNAL(triggered()), this, SLOT(zoomModeEnabled()));
manongjohn a99cb6
Kite 521c84
    QIcon handModeIcon = createQIcon("hand_schematic");
manongjohn a99cb6
    m_handMode = new QAction(handModeIcon, tr("&Hand Mode"), m_commonToolbar);
manongjohn a99cb6
    m_handMode->setCheckable(true);
manongjohn a99cb6
    connect(m_handMode, SIGNAL(triggered()), this, SLOT(handModeEnabled()));
manongjohn a99cb6
manongjohn a99cb6
    setCursorMode(m_cursorMode);
manongjohn a99cb6
Shinya Kitaoka 120a6e
    if (m_fullSchematic) {
Shinya Kitaoka 120a6e
      // AddPegbar
Shinya Kitaoka 120a6e
      addPegbar           = new QAction(tr("&New Pegbar"), m_stageToolbar);
Kite 521c84
      QIcon addPegbarIcon = createQIcon("pegbar");
Shinya Kitaoka 120a6e
      addPegbar->setIcon(addPegbarIcon);
Shinya Kitaoka 120a6e
      connect(addPegbar, SIGNAL(triggered()), m_stageScene,
Shinya Kitaoka 120a6e
              SLOT(onPegbarAdded()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      // AddCamera
Shinya Kitaoka 120a6e
      addCamera           = new QAction(tr("&New Camera"), m_stageToolbar);
Kite 521c84
      QIcon addCameraIcon = createQIcon("camera");
Shinya Kitaoka 120a6e
      addCamera->setIcon(addCameraIcon);
Shinya Kitaoka 120a6e
      connect(addCamera, SIGNAL(triggered()), m_stageScene,
Shinya Kitaoka 120a6e
              SLOT(onCameraAdded()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      // AddSpline
Shinya Kitaoka 120a6e
      addSpline           = new QAction(tr("&New Motion Path"), m_stageToolbar);
Kite 521c84
      QIcon addSplineIcon = createQIcon("motionpath");
Shinya Kitaoka 120a6e
      addSpline->setIcon(addSplineIcon);
Shinya Kitaoka 120a6e
      connect(addSpline, SIGNAL(triggered()), m_stageScene,
Shinya Kitaoka 120a6e
              SLOT(onSplineAdded()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      // Switch display of stage schematic's output port
Shinya Kitaoka 120a6e
      switchPort =
Shinya Kitaoka 120a6e
          new QAction(tr("&Swtich output port display mode"), m_stageToolbar);
Shinya Kitaoka 120a6e
      switchPort->setCheckable(true);
Shinya Kitaoka 120a6e
      switchPort->setChecked(m_stageScene->isShowLetterOnPortFlagEnabled());
Kite 521c84
      QIcon switchPortIcon = createQIcon("switchport");
Shinya Kitaoka 120a6e
      switchPort->setIcon(switchPortIcon);
Shinya Kitaoka 120a6e
      connect(switchPort, SIGNAL(toggled(bool)), m_stageScene,
Shinya Kitaoka 120a6e
              SLOT(onSwitchPortModeToggled(bool)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // InsertFx
Shinya Kitaoka 120a6e
      insertFx = CommandManager::instance()->getAction("MI_InsertFx");
Shinya Kitaoka 120a6e
      if (insertFx) {
Kite 521c84
        QIcon insertFxIcon = createQIcon("fx_logo");
Shinya Kitaoka 120a6e
        insertFx->setIcon(insertFxIcon);
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      // AddOutputFx
Shinya Kitaoka 120a6e
      addOutputFx = CommandManager::instance()->getAction("MI_NewOutputFx");
Shinya Kitaoka 120a6e
manongjohn d6e3cc
      // Iconify Fx nodes
manongjohn d6e3cc
      iconifyNodes = new QAction(tr("&Toggle node icons"), m_fxToolbar);
manongjohn d6e3cc
      iconifyNodes->setCheckable(true);
manongjohn d6e3cc
      iconifyNodes->setChecked(!m_fxScene->isNormalIconView());
Kite 521c84
      QIcon iconifyNodesIcon = createQIcon("iconifynodes");
manongjohn d6e3cc
      iconifyNodes->setIcon(iconifyNodesIcon);
manongjohn d6e3cc
      connect(iconifyNodes, SIGNAL(toggled(bool)), m_fxScene,
manongjohn d6e3cc
              SLOT(onIconifyNodesToggled(bool)));
manongjohn d6e3cc
Shinya Kitaoka 120a6e
      // Swap fx/stage schematic
Kite 521c84
      QIcon changeSchematicIcon = createQIcon("swap");
Shinya Kitaoka 120a6e
      m_changeScene =
Shinya Kitaoka 120a6e
          CommandManager::instance()->getAction("A_FxSchematicToggle", true);
Shinya Kitaoka 120a6e
      if (m_changeScene) {
Shinya Kitaoka 120a6e
        m_changeScene->setIcon(changeSchematicIcon);
Shinya Kitaoka 120a6e
        connect(m_changeScene, SIGNAL(triggered()), this,
Shinya Kitaoka 120a6e
                SLOT(onSceneChanged()));
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        m_changeScene = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Add actions to toolbars (in reverse)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_commonToolbar->addSeparator();
Shinya Kitaoka 120a6e
  m_commonToolbar->addAction(m_nodeSize);
Shinya Kitaoka 120a6e
  m_commonToolbar->addAction(m_normalize);
Shinya Kitaoka 120a6e
  m_commonToolbar->addAction(m_reorder);
Shinya Kitaoka 120a6e
  m_commonToolbar->addAction(m_centerOn);
Shinya Kitaoka 120a6e
  m_commonToolbar->addAction(m_fitSchematic);
manongjohn a99cb6
  m_commonToolbar->addSeparator();
manongjohn a99cb6
  m_commonToolbar->addAction(m_handMode);
manongjohn a99cb6
  m_commonToolbar->addAction(m_zoomMode);
manongjohn a99cb6
  m_commonToolbar->addAction(m_selectMode);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_fullSchematic) {
Shinya Kitaoka 120a6e
    m_stageToolbar->addSeparator();
Shinya Kitaoka 120a6e
    m_stageToolbar->addAction(switchPort);
Shinya Kitaoka 120a6e
    m_stageToolbar->addSeparator();
Shinya Kitaoka 120a6e
    m_stageToolbar->addAction(addSpline);
Shinya Kitaoka 120a6e
    m_stageToolbar->addAction(addCamera);
Shinya Kitaoka 120a6e
    m_stageToolbar->addAction(addPegbar);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_fxToolbar->addSeparator();
manongjohn d6e3cc
    m_fxToolbar->addAction(iconifyNodes);
manongjohn d6e3cc
    m_fxToolbar->addSeparator();
Shinya Kitaoka 120a6e
    m_fxToolbar->addAction(addOutputFx);
Shinya Kitaoka 120a6e
    m_fxToolbar->addAction(insertFx);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_changeScene) m_swapToolbar->addAction(m_changeScene);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicViewer::setStageSchematic() {
Shinya Kitaoka 120a6e
  if (m_viewer->scene() != m_stageScene) {
Shinya Kitaoka 120a6e
    m_viewer->setScene(m_stageScene);
Shinya Kitaoka 120a6e
    QRectF rect = m_stageScene->itemsBoundingRect();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_viewer->resetMatrix();
Shinya Kitaoka 120a6e
    m_viewer->centerOn(rect.center());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_fxToolbar->hide();
Shinya Kitaoka 120a6e
    m_stageToolbar->show();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_viewer->update();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  parentWidget()->setWindowTitle(QObject::tr("Stage Schematic"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicViewer::setFxSchematic() {
Shinya Kitaoka 120a6e
  if (m_viewer->scene() != m_fxScene) {
Shinya Kitaoka 120a6e
    m_viewer->setScene(m_fxScene);
Shinya Kitaoka 120a6e
    QRectF rect = m_fxScene->itemsBoundingRect();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_viewer->resetMatrix();
Shinya Kitaoka 120a6e
    m_viewer->centerOn(rect.center());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_stageToolbar->hide();
Shinya Kitaoka 120a6e
    m_fxToolbar->show();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // check if the fx scene was small scaled (icon view mode)
manongjohn d6e3cc
    if (!m_fxScene->isNormalIconView()) m_fxScene->updateScene();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_viewer->update();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  parentWidget()->setWindowTitle(QObject::tr("FX Schematic"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicViewer::onSceneChanged() {
Shinya Kitaoka 120a6e
  if (!hasFocus()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QGraphicsScene *scene = m_viewer->scene();
Shinya Kitaoka 120a6e
  if (scene == m_fxScene)
Shinya Kitaoka 120a6e
    setStageSchematic();
Shinya Kitaoka 120a6e
  else if (scene == m_stageScene)
Shinya Kitaoka 120a6e
    setFxSchematic();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicViewer::onSceneSwitched() {
Shinya Kitaoka 120a6e
  m_maximizedNode = m_fxScene->getXsheetHandle()
Shinya Kitaoka 120a6e
                        ->getXsheet()
Shinya Kitaoka 120a6e
                        ->getFxDag()
Shinya Kitaoka 120a6e
                        ->getDagGridDimension() == 0;
Kite 521c84
  QIcon nodeSizeIcon =
Kite 521c84
      createQIcon(m_maximizedNode ? "minimizenodes" : "maximizenodes");
Shinya Kitaoka 120a6e
  m_nodeSize->setIcon(nodeSizeIcon);
Shinya Kitaoka 120a6e
  QString label(m_maximizedNode ? tr("&Minimize Nodes")
Shinya Kitaoka 120a6e
                                : tr("&Maximize Nodes"));
Shinya Kitaoka 120a6e
  m_nodeSize->setText(label);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // reset schematic
Shinya Kitaoka 120a6e
  m_viewer->resetMatrix();
Shinya Kitaoka 120a6e
  m_viewer->centerOn(m_viewer->scene()->itemsBoundingRect().center());
manongjohn d6e3cc
  if (m_viewer->scene() == m_fxScene && !m_fxScene->isNormalIconView())
Shinya Kitaoka 120a6e
    m_fxScene->updateScene();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool SchematicViewer::isStageSchematicViewed() {
Shinya Kitaoka 120a6e
  QGraphicsScene *scene = m_viewer->scene();
Shinya Kitaoka 120a6e
  return scene == m_stageScene;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicViewer::setStageSchematicViewed(bool isStageSchematic) {
Shinya Kitaoka 120a6e
  if (!m_fullSchematic) isStageSchematic = true;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isStageSchematic == isStageSchematicViewed()) return;
Shinya Kitaoka 120a6e
  if (isStageSchematic)
Shinya Kitaoka 120a6e
    setStageSchematic();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    setFxSchematic();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
shun-iwasawa 44381c
// called when the signals xshLevelChanged or objectSwitched is emited
Shinya Kitaoka 120a6e
void SchematicViewer::updateScenes() {
Shinya Kitaoka 120a6e
  TStageObjectId id = m_stageScene->getCurrentObject();
Shinya Kitaoka 120a6e
  if (id.isColumn()) {
Shinya Kitaoka 120a6e
    m_stageScene->update();
Shinya Kitaoka 120a6e
    TXsheet *xsh = m_stageScene->getXsheetHandle()->getXsheet();
Shinya Kitaoka 120a6e
    if (!xsh) return;
Shinya Kitaoka 120a6e
    TXshColumn *column = xsh->getColumn(id.getIndex());
shun-iwasawa 44381c
    if (!column || !column->getZeraryFxColumn()) return;
shun-iwasawa 44381c
    TFx *fx = column->getZeraryFxColumn()->getZeraryColumnFx();
shun-iwasawa 44381c
    m_fxScene->getFxHandle()->setFx(fx);
Shinya Kitaoka 120a6e
    m_fxScene->update();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SchematicViewer::changeNodeSize() {
Shinya Kitaoka 120a6e
  m_maximizedNode = !m_maximizedNode;
Shinya Kitaoka 120a6e
  // aggiono l'icona del pulsante;
Shinya Kitaoka 120a6e
  m_fxScene->resizeNodes(m_maximizedNode);
Shinya Kitaoka 120a6e
  m_stageScene->resizeNodes(m_maximizedNode);
Kite 521c84
  QIcon nodeSizeIcon =
Kite 521c84
      createQIcon(m_maximizedNode ? "minimizenodes" : "maximizenodes");
Shinya Kitaoka 120a6e
  m_nodeSize->setIcon(nodeSizeIcon);
Shinya Kitaoka 120a6e
  QString label(m_maximizedNode ? tr("&Minimize Nodes")
Shinya Kitaoka 120a6e
                                : tr("&Maximize Nodes"));
Shinya Kitaoka 120a6e
  m_nodeSize->setText(label);
Toshihiro Shimizu 890ddd
}
manongjohn a99cb6
manongjohn a99cb6
//------------------------------------------------------------------
manongjohn a99cb6
manongjohn d6e3cc
QColor SchematicViewer::getSelectedNodeTextColor() {
manongjohn d6e3cc
  // get colors
manongjohn d6e3cc
  TPixel currentColumnPixel;
manongjohn d6e3cc
  Preferences::instance()->getCurrentColumnData(currentColumnPixel);
manongjohn d6e3cc
  QColor currentColumnColor((int)currentColumnPixel.r,
manongjohn d6e3cc
                            (int)currentColumnPixel.g,
manongjohn d6e3cc
                            (int)currentColumnPixel.b, 255);
manongjohn d6e3cc
  return currentColumnColor;
manongjohn d6e3cc
}
manongjohn 71163f
manongjohn 71163f
//------------------------------------------------------------------
manongjohn 71163f
manongjohn a99cb6
void SchematicViewer::setCursorMode(CursorMode cursorMode) {
manongjohn a99cb6
  m_cursorMode = cursorMode;
manongjohn a99cb6
  m_viewer->setCursorMode(m_cursorMode);
manongjohn a99cb6
manongjohn a99cb6
  m_selectMode->setChecked((m_cursorMode == CursorMode::Select));
manongjohn a99cb6
  m_zoomMode->setChecked((m_cursorMode == CursorMode::Zoom));
manongjohn a99cb6
  m_handMode->setChecked((m_cursorMode == CursorMode::Hand));
manongjohn a99cb6
}
manongjohn a99cb6
manongjohn a99cb6
//------------------------------------------------------------------
manongjohn a99cb6
manongjohn 3c9f8d
void SchematicViewer::selectModeEnabled() { setCursorMode(CursorMode::Select); }
manongjohn a99cb6
manongjohn a99cb6
//------------------------------------------------------------------
manongjohn a99cb6
manongjohn 3c9f8d
void SchematicViewer::zoomModeEnabled() { setCursorMode(CursorMode::Zoom); }
manongjohn a99cb6
manongjohn a99cb6
//------------------------------------------------------------------
manongjohn a99cb6
manongjohn 3c9f8d
void SchematicViewer::handModeEnabled() { setCursorMode(CursorMode::Hand); }