Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/functionviewer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/functionselection.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/functionpanel.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/functiontreeviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/functionsheet.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/functionsegmentviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/functiontoolbar.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/swatchviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvscrollwidget.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjecttree.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tfxhandle.h"
Campbell Barton d0e335
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxdag.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshzeraryfxcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/tproject.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tparamcontainer.h"
Toshihiro Shimizu 890ddd
#include "tunit.h"
Jeremy Bullock 4ce953
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tstopwatch.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qwheelevent></qwheelevent>
Toshihiro Shimizu 890ddd
#include <qboxlayout></qboxlayout>
Toshihiro Shimizu 890ddd
#include <qpushbutton></qpushbutton>
Toshihiro Shimizu 890ddd
#include <qstackedwidget></qstackedwidget>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Campbell Barton d0e335
#include <qtoolbar></qtoolbar>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Jeremy Bullock 4ce953
TEnv::IntVar FunctionEditorToggleStatus("FunctionEditorToggleStatus", 0);
Jeremy Bullock 4ce953
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// FunctionPanel
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FunctionViewer::FunctionViewer(QWidget *parent, Qt::WindowFlags flags)
Shinya Kitaoka 120a6e
    : QSplitter(parent)
Shinya Kitaoka 120a6e
    , m_xshHandle(0)
Shinya Kitaoka 120a6e
    , m_frameHandle(0)
Shinya Kitaoka 120a6e
    , m_objectHandle(0)
Shinya Kitaoka 120a6e
    , m_fxHandle(0)
Shinya Kitaoka 120a6e
    , m_columnHandle(0)
Shinya Kitaoka 120a6e
    , m_curve(0)
Shinya Kitaoka 120a6e
    , m_selection(new FunctionSelection())
Shinya Kitaoka 120a6e
    , m_sceneHandle(0) {
Shinya Kitaoka 120a6e
  setObjectName("FunctionEditor");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Prepare local timeline
Shinya Kitaoka 120a6e
  m_localFrame.setFrame(0);
Shinya Kitaoka 120a6e
  setFocusPolicy(Qt::NoFocus);
Jeremy Bullock 4ce953
  m_toggleStart = Preferences::instance()->getFunctionEditorToggle();
Jeremy Bullock 4ce953
  if (m_toggleStart ==
Jeremy Bullock 4ce953
      Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup) {
Jeremy Bullock 4ce953
    m_functionGraph    = new FunctionPanel(this, false);
Jeremy Bullock 4ce953
    m_numericalColumns = new FunctionSheet(this, true);
Jeremy Bullock 4ce953
  } else if (m_toggleStart == Preferences::FunctionEditorToggle::
Jeremy Bullock 4ce953
                                  ToggleBetweenGraphAndSpreadsheet) {
Jeremy Bullock 4ce953
    m_functionGraph    = new FunctionPanel(this, false);
Jeremy Bullock 4ce953
    m_numericalColumns = new FunctionSheet(this, false);
Jeremy Bullock 4ce953
  } else {
Jeremy Bullock 4ce953
    // default values are graph is floating
Jeremy Bullock 4ce953
    // and spreadsheet is not floating
Jeremy Bullock 4ce953
    m_functionGraph    = new FunctionPanel(this);
Jeremy Bullock 4ce953
    m_numericalColumns = new FunctionSheet(this);
Jeremy Bullock 4ce953
  }
Jeremy Bullock 4ce953
  m_treeView = new FunctionTreeView(this);
Shinya Kitaoka 120a6e
Jeremy Bullock 4ce953
  m_toolbar = new FunctionToolbar;
Shinya Kitaoka 120a6e
  m_segmentViewer =
Shinya Kitaoka 120a6e
      new FunctionSegmentViewer(this, m_numericalColumns, m_functionGraph);
Shinya Kitaoka 120a6e
  QWidget *leftPanel  = new QWidget();
Shinya Kitaoka 120a6e
  QWidget *rightPanel = new QWidget();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----
Shinya Kitaoka 120a6e
  m_treeView->resize(150, m_treeView->size().height());
Shinya Kitaoka 120a6e
  m_treeView->setMinimumWidth(0);
Kite 521c84
  m_treeView->setIconSize(QSize(21, 18));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FunctionTreeModel *ftModel =
Shinya Kitaoka 120a6e
      dynamic_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Shinya Kitaoka 120a6e
  m_functionGraph->setModel(ftModel);
Shinya Kitaoka 120a6e
  m_numericalColumns->setModel(ftModel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_functionGraph->setSelection(getSelection());
Shinya Kitaoka 120a6e
  m_numericalColumns->setSelection(getSelection());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_numericalColumns->setViewer(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_toolbar->setSelection(m_selection);
Shinya Kitaoka 120a6e
  m_toolbar->setFocusPolicy(Qt::NoFocus);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_toolbar->setFrameHandle(
Shinya Kitaoka 120a6e
      &m_localFrame);  // The function editor adopts an internal timeline
Shinya Kitaoka 120a6e
  m_functionGraph->setFrameHandle(
Shinya Kitaoka 120a6e
      &m_localFrame);  // synchronized among its various sub-widgets.
Shinya Kitaoka 120a6e
  m_numericalColumns->setFrameHandle(
Shinya Kitaoka 120a6e
      &m_localFrame);  // In case an external m_frameHandle is specified,
Shinya Kitaoka 120a6e
                       // it synchronizes with that, too.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //---- layout
Shinya Kitaoka 120a6e
shun-iwasawa 855b12
  QString layout = Preferences::instance()->getLoadedXsheetLayout();
shun-iwasawa 855b12
  bool toolBarOnBottom =
shun-iwasawa 855b12
      layout == QString("Minimum") &&
shun-iwasawa 855b12
      Preferences::instance()->isExpandFunctionHeaderEnabled() &&
shun-iwasawa 855b12
      m_toggleStart !=
shun-iwasawa 855b12
          Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup;
shun-iwasawa 855b12
Jeremy Bullock 15fcba
  m_leftLayout = new QVBoxLayout();
Jeremy Bullock 15fcba
  m_leftLayout->setMargin(0);
Jeremy Bullock 15fcba
  m_leftLayout->setSpacing(0);
Shinya Kitaoka 120a6e
  {
shun-iwasawa 855b12
    if (!toolBarOnBottom) m_leftLayout->addWidget(m_toolbar);
shun-iwasawa 855b12
    m_spacing = 35;
shun-iwasawa 855b12
    if (layout == QString("Compact"))
shun-iwasawa 855b12
      m_spacing -= 18;
shun-iwasawa 855b12
    else if (toolBarOnBottom) {
shun-iwasawa 855b12
      m_spacing = 3;  // m_spacing is used for the height of spacer widget
shun-iwasawa 855b12
      m_leftLayout->addSpacing(m_spacing);
shun-iwasawa 855b12
    }
Jeremy Bullock 4ce953
Jeremy Bullock 4ce953
    if (m_toggleStart !=
Jeremy Bullock 4ce953
        Preferences::FunctionEditorToggle::ShowGraphEditorInPopup)
Jeremy Bullock 4ce953
      m_leftLayout->addWidget(m_functionGraph);
Jeremy Bullock 4ce953
    if (m_toggleStart !=
Jeremy Bullock 4ce953
        Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup)
Jeremy Bullock 4ce953
      m_leftLayout->addWidget(m_numericalColumns);
shun-iwasawa 855b12
    // display the toolbar on the bottom in Minimum layout
shun-iwasawa 855b12
    if (toolBarOnBottom) m_leftLayout->addWidget(m_toolbar);
Shinya Kitaoka 120a6e
  }
Jeremy Bullock 4ce953
Jeremy Bullock 15fcba
  leftPanel->setLayout(m_leftLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  addWidget(leftPanel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QVBoxLayout *rightLayout = new QVBoxLayout();
Shinya Kitaoka 120a6e
  rightLayout->setMargin(0);
Shinya Kitaoka 120a6e
  rightLayout->setSpacing(5);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    rightLayout->addWidget(m_segmentViewer, 0);
Shinya Kitaoka 120a6e
    rightLayout->addWidget(m_treeView, 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  rightPanel->setLayout(rightLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  addWidget(rightPanel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //--- set the splitter's default size
Shinya Kitaoka 120a6e
  setSizes(QList<int>() << 500 << 200);</int>
Shinya Kitaoka 120a6e
  setStretchFactor(0, 5);
Shinya Kitaoka 120a6e
  setStretchFactor(1, 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //---- signal-slot connections
Shinya Kitaoka 120a6e
  bool ret = true;
Shinya Kitaoka 120a6e
  ret      = ret && connect(m_toolbar, SIGNAL(numericalColumnToggled()), this,
shun-iwasawa 443318
                            SLOT(toggleMode()));
shun-iwasawa 4a3868
  ret      = ret && connect(ftModel, SIGNAL(activeChannelsChanged()),
shun-iwasawa 443318
                            m_functionGraph, SLOT(update()));
shun-iwasawa 4a3868
  ret      = ret && connect(ftModel, SIGNAL(activeChannelsChanged()),
shun-iwasawa 443318
                            m_numericalColumns, SLOT(updateAll()));
shun-iwasawa 4a3868
  ret      = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_treeView,
shun-iwasawa 443318
                            SLOT(update()));
Shinya Kitaoka 120a6e
  ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_functionGraph,
Shinya Kitaoka 120a6e
                       SLOT(update()));
Shinya Kitaoka 120a6e
  ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_numericalColumns,
Shinya Kitaoka 120a6e
                       SLOT(updateAll()));
Shinya Kitaoka 120a6e
  ret = ret && connect(ftModel, SIGNAL(curveSelected(TDoubleParam *)), this,
Shinya Kitaoka 120a6e
                       SLOT(onCurveSelected(TDoubleParam *)));
Shinya Kitaoka 120a6e
  ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_segmentViewer,
Shinya Kitaoka 120a6e
                       SLOT(onCurveChanged()));
Shinya Kitaoka 120a6e
  ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), this,
Shinya Kitaoka 120a6e
                       SLOT(onCurveChanged(bool)));
Shinya Kitaoka 120a6e
  ret = ret && connect(&m_localFrame, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
                       SLOT(onFrameSwitched()));
Shinya Kitaoka 120a6e
  ret = ret && connect(getSelection(), SIGNAL(selectionChanged()), this,
Shinya Kitaoka 120a6e
                       SLOT(onSelectionChanged()));
Shinya Kitaoka 120a6e
  ret = ret && connect(m_functionGraph, SIGNAL(keyframeSelected(double)),
Shinya Kitaoka 120a6e
                       m_toolbar, SLOT(setFrame(double)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ret = ret && connect(m_treeView, SIGNAL(switchCurrentObject(TStageObject *)),
Shinya Kitaoka 120a6e
                       this, SLOT(doSwitchCurrentObject(TStageObject *)));
Shinya Kitaoka 120a6e
  ret = ret && connect(m_treeView, SIGNAL(switchCurrentFx(TFx *)), this,
Shinya Kitaoka 120a6e
                       SLOT(doSwitchCurrentFx(TFx *)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ret = ret &&
Shinya Kitaoka 120a6e
        connect(ftModel,
Shinya Kitaoka 120a6e
                SIGNAL(currentChannelChanged(FunctionTreeModel::Channel *)),
Shinya Kitaoka 120a6e
                m_numericalColumns,
Shinya Kitaoka 120a6e
                SLOT(onCurrentChannelChanged(FunctionTreeModel::Channel *)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(ret);
Jeremy Bullock 4ce953
  if (m_toggleStart ==
shun-iwasawa 855b12
      Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup) {
Jeremy Bullock 4ce953
    m_numericalColumns->hide();
shun-iwasawa 855b12
    if (QSpacerItem *spacer = m_leftLayout->itemAt(0)->spacerItem())
shun-iwasawa 855b12
      spacer->changeSize(0, 0);
shun-iwasawa 855b12
  } else {
shun-iwasawa 855b12
    bool toolBarVisible =
shun-iwasawa 855b12
        Preferences::instance()->isShowXSheetToolbarEnabled() &&
shun-iwasawa 855b12
        Preferences::instance()->isExpandFunctionHeaderEnabled();
shun-iwasawa 855b12
    if (QSpacerItem *spacer = m_leftLayout->itemAt(0)->spacerItem()) {
shun-iwasawa 855b12
      spacer->changeSize(1, m_spacing + ((toolBarVisible) ? 10 : 0),
shun-iwasawa 855b12
                         QSizePolicy::Fixed, QSizePolicy::Fixed);
shun-iwasawa 855b12
      spacer->invalidate();
shun-iwasawa 855b12
    } else
shun-iwasawa 855b12
      m_leftLayout->setSpacing(m_spacing + ((toolBarVisible) ? 30 : 0));
shun-iwasawa 855b12
    if (m_toggleStart ==
shun-iwasawa 855b12
        Preferences::FunctionEditorToggle::ShowGraphEditorInPopup) {
shun-iwasawa 855b12
      m_functionGraph->hide();
shun-iwasawa 855b12
    }
shun-iwasawa 855b12
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FunctionViewer::~FunctionViewer() {
Shinya Kitaoka 120a6e
  delete m_selection;
Shinya Kitaoka 120a6e
  m_toolbar->setFrameHandle(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::showEvent(QShowEvent *) {
Shinya Kitaoka 120a6e
  refreshModel();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Connect handles
Shinya Kitaoka 120a6e
  bool ret = true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_xshHandle) {
shun-iwasawa 855b12
    ret = ret && connect(m_xshHandle, SIGNAL(xsheetChanged()), this,
shun-iwasawa 855b12
                         SLOT(refreshModel()));
shun-iwasawa 855b12
    ret = ret && connect(m_xshHandle, SIGNAL(xsheetSwitched()), this,
shun-iwasawa 855b12
                         SLOT(rebuildModel()));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
manongjohn 4be4bb
  if (m_frameHandle) {
shun-iwasawa 855b12
    ret = ret && connect(m_frameHandle, SIGNAL(frameSwitched()), this,
shun-iwasawa 855b12
                         SLOT(propagateExternalSetFrame()));
shun-iwasawa 855b12
    ret = ret && connect(m_frameHandle, SIGNAL(triggerNextKeyframe(QWidget *)),
shun-iwasawa 855b12
                         m_toolbar, SLOT(onNextKeyframe(QWidget *)));
shun-iwasawa 855b12
    ret = ret && connect(m_frameHandle, SIGNAL(triggerPrevKeyframe(QWidget *)),
shun-iwasawa 855b12
                         m_toolbar, SLOT(onPrevKeyframe(QWidget *)));
manongjohn 4be4bb
  }
manongjohn 4be4bb
Shinya Kitaoka 120a6e
  if (m_objectHandle) {
shun-iwasawa 855b12
    ret = ret && connect(m_objectHandle, SIGNAL(objectSwitched()), this,
shun-iwasawa 855b12
                         SLOT(onStageObjectSwitched()));
shun-iwasawa 855b12
    ret = ret && connect(m_objectHandle, SIGNAL(objectChanged(bool)), this,
shun-iwasawa 855b12
                         SLOT(onStageObjectChanged(bool)));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_fxHandle)
shun-iwasawa 855b12
    ret = ret &&
shun-iwasawa 855b12
          connect(m_fxHandle, SIGNAL(fxSwitched()), this, SLOT(onFxSwitched()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // display animated channels when the scene is switched
shun-iwasawa 855b12
  if (m_sceneHandle) {
shun-iwasawa 855b12
    ret = ret && connect(m_sceneHandle, SIGNAL(sceneSwitched()), m_treeView,
shun-iwasawa 855b12
                         SLOT(displayAnimatedChannels()));
shun-iwasawa 855b12
    ret = ret &&
shun-iwasawa 855b12
          connect(m_sceneHandle, SIGNAL(preferenceChanged(const QString &)),
shun-iwasawa 855b12
                  this, SLOT(onPreferenceChanged(const QString &)));
shun-iwasawa 855b12
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(ret);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_treeView->setExpanded(m_treeView->model()->index(0, 0), true);
Shinya Kitaoka 120a6e
  m_treeView->setExpanded(m_treeView->model()->index(1, 0), true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FunctionTreeModel *ftm =
Shinya Kitaoka 120a6e
      static_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_objectHandle) {
Shinya Kitaoka 120a6e
    assert(m_xshHandle);
Shinya Kitaoka 120a6e
    TXsheet *xsh = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    const TStageObjectId &objId = m_objectHandle->getObjectId();
Shinya Kitaoka 120a6e
    ftm->setCurrentStageObject((objId == TStageObjectId::NoneId)
Shinya Kitaoka 120a6e
                                   ? (TStageObject *)0
Shinya Kitaoka 120a6e
                                   : xsh->getStageObject(objId));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_fxHandle) ftm->setCurrentFx(m_fxHandle->getFx());
shun-iwasawa 855b12
  onPreferenceChanged("");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::hideEvent(QHideEvent *) {
Shinya Kitaoka 120a6e
  if (m_xshHandle) m_xshHandle->disconnect(this);
manongjohn 4be4bb
  if (m_frameHandle) {
manongjohn 4be4bb
    m_frameHandle->disconnect(this);
manongjohn 4be4bb
    m_frameHandle->disconnect(m_toolbar);
manongjohn 4be4bb
  }
Shinya Kitaoka 120a6e
  if (m_objectHandle) m_objectHandle->disconnect(this);
Shinya Kitaoka 120a6e
  if (m_fxHandle) m_fxHandle->disconnect(this);
Shinya Kitaoka 120a6e
  if (m_sceneHandle) m_sceneHandle->disconnect(this);
Jeremy Bullock 4ce953
  if (m_toggleStart ==
Jeremy Bullock 4ce953
      Preferences::FunctionEditorToggle::ShowGraphEditorInPopup) {
Jeremy Bullock 4ce953
    if (m_functionGraph->isVisible()) m_functionGraph->hide();
Jeremy Bullock 4ce953
  }
Jeremy Bullock 4ce953
  if (m_toggleStart ==
Jeremy Bullock 4ce953
      Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup) {
Jeremy Bullock 4ce953
    if (m_numericalColumns->isVisible()) m_numericalColumns->hide();
Jeremy Bullock 4ce953
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::openContextMenu(TreeModel::Item *item,
Shinya Kitaoka 120a6e
                                     const QPoint &globalPos) {
Shinya Kitaoka 120a6e
  m_treeView->openContextMenu(item, globalPos);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::rebuildModel() {
Shinya Kitaoka 120a6e
  getSelection()->selectNone();
Shinya Kitaoka 120a6e
  onCurveSelected(0);
Shinya Kitaoka 120a6e
  m_functionGraph->getModel()->resetAll();
Shinya Kitaoka 120a6e
  refreshModel();
Shinya Kitaoka 120a6e
  m_treeView->displayAnimatedChannels();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::refreshModel() {
Shinya Kitaoka 120a6e
  TXsheet *xsh = m_xshHandle ? m_xshHandle->getXsheet() : 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_functionGraph->getModel()->refreshData(xsh);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (xsh) {
Shinya Kitaoka 120a6e
    int rowCount = xsh->getFrameCount();
Shinya Kitaoka 120a6e
    m_numericalColumns->setRowCount(rowCount);
Shinya Kitaoka 120a6e
    m_numericalColumns->updateAll();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    ToonzScene *scene = xsh->getScene();
Shinya Kitaoka 120a6e
    if (!scene)  // This seems wrong. It should rather be
Shinya Kitaoka 120a6e
      return;    // asserted - though I'm not touching it now...
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    TFilePath scenePath = scene->getScenePath().getParentDir();
Shinya Kitaoka 120a6e
    if (scene->isUntitled())
Shinya Kitaoka 120a6e
      scenePath =
Shinya Kitaoka 120a6e
          TProjectManager::instance()->getCurrentProject()->getScenesPath();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_treeView->setCurrentScenePath(scenePath);
Toshihiro Shimizu 890ddd
shun-iwasawa fe3506
    int distance, offset, secDistance;
shun-iwasawa fe3506
    scene->getProperties()->getMarkers(distance, offset, secDistance);
shun-iwasawa fe3506
    m_numericalColumns->setMarkRow(distance, offset, secDistance);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_treeView->updateAll();
Shinya Kitaoka 120a6e
  m_toolbar->setCurve(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::setXsheetHandle(TXsheetHandle *xshHandle) {
Shinya Kitaoka 120a6e
  if (xshHandle == m_xshHandle) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_xshHandle) m_xshHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_xshHandle = xshHandle;
Shinya Kitaoka 120a6e
  m_segmentViewer->setXsheetHandle(xshHandle);
shun-iwasawa 4a3868
  m_treeView->setXsheetHandle(xshHandle);
shun-iwasawa 692990
  m_numericalColumns->setXsheetHandle(xshHandle);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_xshHandle && isVisible()) {
Shinya Kitaoka 120a6e
    TXsheet *xsh = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
    m_functionGraph->getModel()->refreshData(xsh);
Toshihiro Shimizu 890ddd
Jeremy Bullock 15fcba
    bool ret = connect(m_xshHandle, SIGNAL(xsheetChanged()), this,
Jeremy Bullock 15fcba
                       SLOT(refreshModel()));
Shinya Kitaoka 120a6e
    assert(ret);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::setFrameHandle(TFrameHandle *frameHandle) {
Shinya Kitaoka 120a6e
  if (m_frameHandle == frameHandle) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_frameHandle) m_frameHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_frameHandle = frameHandle;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_frameHandle && isVisible()) {
Shinya Kitaoka 120a6e
    bool ret = connect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
                       SLOT(propagateExternalSetFrame()));
Shinya Kitaoka 120a6e
    assert(ret);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::setObjectHandle(TObjectHandle *objectHandle) {
Shinya Kitaoka 120a6e
  if (objectHandle == m_objectHandle) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_objectHandle) m_objectHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_objectHandle = objectHandle;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_objectHandle && isVisible()) {
Shinya Kitaoka 120a6e
    m_treeView->updateAll();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    bool ret = true;
Shinya Kitaoka 120a6e
    ret      = connect(m_objectHandle, SIGNAL(objectSwitched()), this,
shun-iwasawa 443318
                       SLOT(onStageObjectSwitched())) &&
Shinya Kitaoka 120a6e
          ret;
Shinya Kitaoka 120a6e
    ret = connect(m_objectHandle, SIGNAL(objectChanged(bool)), this,
Shinya Kitaoka 120a6e
                  SLOT(onStageObjectChanged(bool))) &&
Shinya Kitaoka 120a6e
          ret;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    assert(ret);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  FunctionTreeModel *ftModel =
Shinya Kitaoka 120a6e
      static_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Shinya Kitaoka 120a6e
  if (ftModel) ftModel->setObjectHandle(objectHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::setFxHandle(TFxHandle *fxHandle) {
Shinya Kitaoka 120a6e
  if (fxHandle == m_fxHandle) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_fxHandle) m_fxHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_fxHandle = fxHandle;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isVisible()) {
Shinya Kitaoka 120a6e
    m_treeView->updateAll();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    bool ret =
Shinya Kitaoka 120a6e
        connect(m_fxHandle, SIGNAL(fxSwitched()), this, SLOT(onFxSwitched()));
Shinya Kitaoka 120a6e
    assert(ret);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  FunctionTreeModel *ftModel =
Shinya Kitaoka 120a6e
      static_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Shinya Kitaoka 120a6e
  if (ftModel) ftModel->setFxHandle(fxHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::setColumnHandle(TColumnHandle *columnHandle) {
Shinya Kitaoka 120a6e
  if (columnHandle == m_columnHandle) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_columnHandle = columnHandle;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isVisible()) m_treeView->updateAll();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onFrameSwitched() {
Shinya Kitaoka 120a6e
  int frame = m_localFrame.getFrame();
Shinya Kitaoka 120a6e
  m_segmentViewer->setSegmentByFrame(m_curve, frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_frameHandle) m_frameHandle->setFrame(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::toggleMode() {
Shinya Kitaoka 120a6e
  if (isHidden()) return;
Jeremy Bullock 4ce953
  if (m_toggleStart ==
Jeremy Bullock 4ce953
      Preferences::FunctionEditorToggle::ShowGraphEditorInPopup) {
Jeremy Bullock 4ce953
    if (m_functionGraph->isVisible()) {
Jeremy Bullock 4ce953
      m_functionGraph->hide();
Jeremy Bullock 4ce953
    } else {
Jeremy Bullock 4ce953
      m_functionGraph->show();
Jeremy Bullock 4ce953
    }
Jeremy Bullock 4ce953
  } else if (m_toggleStart == Preferences::FunctionEditorToggle::
Jeremy Bullock 4ce953
                                  ShowFunctionSpreadsheetInPopup) {
Jeremy Bullock 4ce953
    if (m_numericalColumns->isVisible()) {
Jeremy Bullock 4ce953
      m_numericalColumns->hide();
Jeremy Bullock 4ce953
    } else {
Jeremy Bullock 4ce953
      m_numericalColumns->show();
Jeremy Bullock 4ce953
    }
Jeremy Bullock 4ce953
  } else if (m_toggleStart == Preferences::FunctionEditorToggle::
Jeremy Bullock 4ce953
                                  ToggleBetweenGraphAndSpreadsheet) {
Jeremy Bullock 4ce953
    if (m_functionGraph->isVisible()) {
Jeremy Bullock 4ce953
      m_functionGraph->hide();
Jeremy Bullock 4ce953
      m_numericalColumns->show();
shun-iwasawa 855b12
      bool toolBarVisible =
shun-iwasawa 855b12
          Preferences::instance()->isShowXSheetToolbarEnabled() &&
shun-iwasawa 855b12
          Preferences::instance()->isExpandFunctionHeaderEnabled();
shun-iwasawa 855b12
      if (QSpacerItem *spacer = m_leftLayout->itemAt(0)->spacerItem()) {
shun-iwasawa 855b12
        spacer->changeSize(1, m_spacing + ((toolBarVisible) ? 10 : 0),
shun-iwasawa 855b12
                           QSizePolicy::Fixed, QSizePolicy::Fixed);
shun-iwasawa 855b12
        spacer->invalidate();
shun-iwasawa 855b12
        m_numericalColumns->updateHeaderHeight();
shun-iwasawa 855b12
        m_leftLayout->setSpacing(0);
shun-iwasawa 855b12
      } else
shun-iwasawa 855b12
        m_leftLayout->setSpacing(m_spacing + ((toolBarVisible) ? 30 : 0));
shun-iwasawa 855b12
      updateGeometry();
Jeremy Bullock 4ce953
      m_toggleStatus = 0;
Jeremy Bullock 4ce953
    } else {
Jeremy Bullock 4ce953
      m_functionGraph->show();
Jeremy Bullock 4ce953
      m_numericalColumns->hide();
Jeremy Bullock 4ce953
      m_leftLayout->setSpacing(0);
shun-iwasawa 855b12
      if (QSpacerItem *spacer = m_leftLayout->itemAt(0)->spacerItem()) {
shun-iwasawa 855b12
        spacer->changeSize(0, 0);
shun-iwasawa 855b12
        spacer->invalidate();
shun-iwasawa 855b12
      }
Jeremy Bullock 4ce953
      m_toggleStatus = 1;
Jeremy Bullock 4ce953
    }
Jeremy Bullock 4ce953
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onCurveChanged(bool isDragging) {
Shinya Kitaoka 120a6e
  if (m_objectHandle) m_objectHandle->notifyObjectIdChanged(isDragging);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // emit signal if the current channel belongs to Fx in order to update the
Shinya Kitaoka 120a6e
  // preview fx
Shinya Kitaoka 120a6e
  if (m_fxHandle) {
Shinya Kitaoka 120a6e
    FunctionTreeModel *ftModel =
Shinya Kitaoka 120a6e
        dynamic_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Shinya Kitaoka 120a6e
    if (ftModel) {
Shinya Kitaoka 120a6e
      FunctionTreeModel::Channel *currChan = ftModel->getCurrentChannel();
Shinya Kitaoka 120a6e
      if (currChan) {
shun-iwasawa 443318
        // カレントチャンネルがFxChannelGroupに含まれていたらEmit
Shinya Kitaoka 120a6e
        FxChannelGroup *fxChanGroup =
Shinya Kitaoka 120a6e
            dynamic_cast<fxchannelgroup *="">(currChan->getChannelGroup());</fxchannelgroup>
Shinya Kitaoka 120a6e
        if (fxChanGroup) m_fxHandle->notifyFxChanged();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onCurveSelected(TDoubleParam *curve) {
Shinya Kitaoka 120a6e
  m_curve = curve;
Shinya Kitaoka 120a6e
  m_toolbar->setCurve(curve);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QPair<tdoubleparam *,="" int=""> selectedSegment =</tdoubleparam>
Shinya Kitaoka 120a6e
      getSelection()->getSelectedSegment();
Shinya Kitaoka 120a6e
  if (selectedSegment.first)
Shinya Kitaoka 120a6e
    m_segmentViewer->setSegment(selectedSegment.first, selectedSegment.second);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_segmentViewer->setSegment(m_curve, -1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onValueFieldChanged() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onXsheetChanged() {
Shinya Kitaoka 120a6e
  TXsheet *xsh = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
  int rowCount = xsh->getFrameCount();
Shinya Kitaoka 120a6e
  m_numericalColumns->setRowCount(rowCount);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onStageObjectSwitched() {
Shinya Kitaoka 120a6e
  TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const TStageObjectId &objId = m_objectHandle->getObjectId();
Shinya Kitaoka 120a6e
  TStageObject *obj           = (objId == TStageObjectId::NoneId)
shun-iwasawa 443318
                                    ? (TStageObject *)0
shun-iwasawa 443318
                                    : xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static_cast<functiontreemodel *="">(m_treeView->model())</functiontreemodel>
Shinya Kitaoka 120a6e
      ->setCurrentStageObject(obj);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_treeView->updateAll();
Shinya Kitaoka 120a6e
  m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onStageObjectChanged(bool isDragging) {
Shinya Kitaoka 120a6e
  TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const TStageObjectId &objId = m_objectHandle->getObjectId();
Shinya Kitaoka 120a6e
  TStageObject *obj           = (objId == TStageObjectId::NoneId)
shun-iwasawa 443318
                                    ? (TStageObject *)0
shun-iwasawa 443318
                                    : xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static_cast<functiontreemodel *="">(m_treeView->model())</functiontreemodel>
Shinya Kitaoka 120a6e
      ->setCurrentStageObject(obj);
Toshihiro Shimizu 890ddd
shun_iwasawa 768e20
  if (!isDragging) {
shun_iwasawa 768e20
    m_treeView->updateAll();
shun_iwasawa 768e20
    m_numericalColumns->updateAll();
shun_iwasawa 768e20
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onFxSwitched() {
Shinya Kitaoka 120a6e
  TFx *fx              = m_fxHandle->getFx();
Shinya Kitaoka 120a6e
  TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
shun-iwasawa 4a3868
  if (zfx) fx = zfx->getZeraryFx();
Shinya Kitaoka 120a6e
  static_cast<functiontreemodel *="">(m_treeView->model())->setCurrentFx(fx);</functiontreemodel>
Shinya Kitaoka 120a6e
  m_treeView->updateAll();
Shinya Kitaoka 120a6e
  m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::onSelectionChanged() {
Shinya Kitaoka 120a6e
  QPair<tdoubleparam *,="" int=""> selectedSegment =</tdoubleparam>
Shinya Kitaoka 120a6e
      getSelection()->getSelectedSegment();
Shinya Kitaoka 120a6e
  if (selectedSegment.first) {
Shinya Kitaoka 120a6e
    if (selectedSegment.first != m_curve) {
Shinya Kitaoka 120a6e
      m_curve = selectedSegment.first;
Shinya Kitaoka 120a6e
      m_toolbar->setCurve(selectedSegment.first);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_segmentViewer->setSegment(selectedSegment.first, selectedSegment.second);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_segmentViewer->setSegment(m_curve, -1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // update curves
Shinya Kitaoka 120a6e
  if (m_functionGraph->isVisible() && !m_functionGraph->hasFocus())
Shinya Kitaoka 120a6e
    m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::doSwitchCurrentObject(TStageObject *obj) {
Shinya Kitaoka 120a6e
  TStageObjectId id = obj->getId();
Shinya Kitaoka 120a6e
  if (id.isColumn())
Shinya Kitaoka 120a6e
    m_columnHandle->setColumnIndex(id.getIndex());
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_objectHandle->setObjectId(id);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 855b12
void FunctionViewer::onPreferenceChanged(const QString &prefName) {
shun-iwasawa 855b12
  if (prefName != "XSheetToolbar" && !prefName.isEmpty()) return;
shun-iwasawa 855b12
  if (!Preferences::instance()->isExpandFunctionHeaderEnabled()) return;
shun-iwasawa 855b12
  if (m_toggleStart ==
shun-iwasawa 855b12
      Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup)
shun-iwasawa 855b12
    return;
shun-iwasawa 855b12
shun-iwasawa 855b12
  if (m_toggleStart ==
shun-iwasawa 855b12
          Preferences::FunctionEditorToggle::ToggleBetweenGraphAndSpreadsheet &&
shun-iwasawa 855b12
      m_toggleStatus == 1) {
shun-iwasawa 855b12
    m_numericalColumns->hide();
shun-iwasawa 855b12
    m_functionGraph->show();
shun-iwasawa 855b12
    m_leftLayout->setSpacing(0);
shun-iwasawa 855b12
    if (QSpacerItem *spacer = m_leftLayout->itemAt(0)->spacerItem()) {
shun-iwasawa 855b12
      spacer->changeSize(0, 0);
shun-iwasawa 855b12
      spacer->invalidate();
shun-iwasawa 855b12
    }
shun-iwasawa 855b12
    return;
shun-iwasawa 855b12
  }
shun-iwasawa 855b12
shun-iwasawa 855b12
  // spreadsheet is shown
shun-iwasawa 855b12
  bool toolBarVisible =
shun-iwasawa 855b12
      Preferences::instance()->isShowXSheetToolbarEnabled() &&
shun-iwasawa 855b12
      Preferences::instance()->isExpandFunctionHeaderEnabled();
shun-iwasawa 855b12
  m_functionGraph->hide();
shun-iwasawa 855b12
  m_numericalColumns->show();
shun-iwasawa 855b12
  if (QSpacerItem *spacer = m_leftLayout->itemAt(0)->spacerItem()) {
shun-iwasawa 855b12
    spacer->changeSize(1, m_spacing + ((toolBarVisible) ? 10 : 0),
shun-iwasawa 855b12
                       QSizePolicy::Fixed, QSizePolicy::Fixed);
shun-iwasawa 855b12
    spacer->invalidate();
shun-iwasawa 855b12
    m_numericalColumns->updateHeaderHeight();
shun-iwasawa 855b12
    m_leftLayout->setSpacing(0);
shun-iwasawa 855b12
  } else
shun-iwasawa 855b12
    m_leftLayout->setSpacing(m_spacing + ((toolBarVisible) ? 30 : 0));
shun-iwasawa 855b12
  updateGeometry();
shun-iwasawa 855b12
}
shun-iwasawa 855b12
shun-iwasawa 855b12
//-----------------------------------------------------------------------------
shun-iwasawa 855b12
Shinya Kitaoka 120a6e
void FunctionViewer::doSwitchCurrentFx(TFx *fx) {
Shinya Kitaoka 120a6e
  if (!fx) {
Shinya Kitaoka 120a6e
    m_fxHandle->setFx(0);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (fx->isZerary()) {
Shinya Kitaoka 120a6e
    TXsheet *xsh = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
    int i, columnCount = xsh->getColumnCount();
Shinya Kitaoka 120a6e
    for (i = 0; i < columnCount; i++) {
Shinya Kitaoka 120a6e
      TXshColumn *column = xsh->getColumn(i);
Shinya Kitaoka 120a6e
      TXshZeraryFxColumn *zfx =
Shinya Kitaoka 120a6e
          dynamic_cast<txshzeraryfxcolumn *="">(xsh->getColumn(i));</txshzeraryfxcolumn>
Shinya Kitaoka 120a6e
      if (!zfx) continue;
Shinya Kitaoka 120a6e
      if (zfx->getZeraryColumnFx()->getZeraryFx() == fx) {
Shinya Kitaoka 120a6e
        fx = zfx->getZeraryColumnFx();
Shinya Kitaoka 120a6e
        m_columnHandle->setColumnIndex(i);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // Forbid update of the swatch upon column switch. This would generate
Shinya Kitaoka 120a6e
  // a useless render...
Shinya Kitaoka 120a6e
  SwatchViewer::suspendRendering(true, false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int columnIndex = fx->getReferenceColumnIndex();
Shinya Kitaoka 120a6e
  if (columnIndex >= 0) m_columnHandle->setColumnIndex(columnIndex);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  SwatchViewer::suspendRendering(false);
Shinya Kitaoka 120a6e
  m_fxHandle->setFx(fx);
Shinya Kitaoka 120a6e
  emit editObject();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::propagateExternalSetFrame() {
Shinya Kitaoka 120a6e
  assert(m_frameHandle);
Shinya Kitaoka 120a6e
  m_localFrame.setFrame(m_frameHandle->getFrame());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::addParameter(TParam *parameter, const TFilePath &folder) {
Shinya Kitaoka 120a6e
  static_cast<functiontreemodel *="">(m_treeView->model())</functiontreemodel>
Shinya Kitaoka 120a6e
      ->addParameter(parameter, folder);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::setFocusColumnsOrGraph() {
Shinya Kitaoka 120a6e
  m_numericalColumns->setFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::clearFocusColumnsAndGraph() {
Shinya Kitaoka 120a6e
  m_functionGraph->clearFocus();
Shinya Kitaoka 120a6e
  m_numericalColumns->clearFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FunctionViewer::columnsOrGraphHasFocus() {
Shinya Kitaoka 120a6e
  return m_functionGraph->hasFocus() ||
Shinya Kitaoka 120a6e
         m_numericalColumns->anyWidgetHasFocus() ||
Shinya Kitaoka 120a6e
         m_toolbar->anyWidgetHasFocus() || m_segmentViewer->anyWidgetHasFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionViewer::setSceneHandle(TSceneHandle *sceneHandle) {
Shinya Kitaoka 120a6e
  m_sceneHandle = sceneHandle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FunctionViewer::isExpressionPageActive() {
Shinya Kitaoka 120a6e
  return m_segmentViewer->isExpressionPageActive();
Toshihiro Shimizu 890ddd
}
Jeremy Bullock 4ce953
Jeremy Bullock 4ce953
//----------------------------------------------------------------------------
Jeremy Bullock 4ce953
Jeremy Bullock 4ce953
void FunctionViewer::save(QSettings &settings) const {
Jeremy Bullock 4ce953
  settings.setValue("toggleStatus", m_toggleStatus);
shun-iwasawa 260cd7
  settings.setValue("showIbtwnValuesInSheet",
shun-iwasawa 260cd7
                    m_numericalColumns->isIbtwnValueVisible());
shun-iwasawa 692990
  settings.setValue("syncSize", m_numericalColumns->isSyncSize());
Jeremy Bullock 4ce953
}
Jeremy Bullock 4ce953
Jeremy Bullock 4ce953
//----------------------------------------------------------------------------
Jeremy Bullock 4ce953
Jeremy Bullock 4ce953
void FunctionViewer::load(QSettings &settings) {
Jeremy Bullock 4ce953
  QVariant toggleStatus = settings.value("toggleStatus");
Jeremy Bullock 4ce953
  if (toggleStatus.canConvert(QVariant::Int)) {
Jeremy Bullock 4ce953
    m_toggleStatus = toggleStatus.toInt();
Jeremy Bullock 4ce953
  }
shun-iwasawa 260cd7
shun-iwasawa 260cd7
  bool ibtwnVisible = settings
shun-iwasawa 260cd7
                          .value("showIbtwnValuesInSheet",
shun-iwasawa 260cd7
                                 m_numericalColumns->isIbtwnValueVisible())
shun-iwasawa 260cd7
                          .toBool();
shun-iwasawa 260cd7
  m_numericalColumns->setIbtwnValueVisible(ibtwnVisible);
shun-iwasawa 692990
shun-iwasawa 692990
  bool syncSize =
shun-iwasawa 692990
      settings.value("syncSize", m_numericalColumns->isSyncSize()).toBool();
shun-iwasawa 692990
  m_numericalColumns->setSyncSize(syncSize);
Jeremy Bullock 4ce953
}
shun-iwasawa 2ce475
shun-iwasawa 2ce475
//-----------------------------------------------------------------------------
shun-iwasawa 2ce475
shun-iwasawa 2ce475
QColor FunctionViewer::getCurrentTextColor() const {
shun-iwasawa 2ce475
  // get colors
shun-iwasawa 2ce475
  TPixel currentColumnPixel;
shun-iwasawa 2ce475
  Preferences::instance()->getCurrentColumnData(currentColumnPixel);
shun-iwasawa 2ce475
  QColor currentColumnColor((int)currentColumnPixel.r,
shun-iwasawa 2ce475
                            (int)currentColumnPixel.g,
shun-iwasawa 2ce475
                            (int)currentColumnPixel.b, 255);
shun-iwasawa 2ce475
  return currentColumnColor;
shun-iwasawa 2ce475
}