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"
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
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// FunctionPanel
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Toshihiro Shimizu 890ddd
FunctionViewer::FunctionViewer(QWidget *parent, Qt::WindowFlags flags)
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
FunctionViewer::FunctionViewer(QWidget *parent, Qt::WFlags flags)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	: QSplitter(parent), m_xshHandle(0), m_frameHandle(0), m_objectHandle(0), m_fxHandle(0), m_columnHandle(0), m_curve(0), m_selection(new FunctionSelection()), m_sceneHandle(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setObjectName("FunctionEditor");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Prepare local timeline
Toshihiro Shimizu 890ddd
	m_localFrame.setFrame(0);
Toshihiro Shimizu 890ddd
	setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_treeView = new FunctionTreeView(this);
Toshihiro Shimizu 890ddd
	m_functionGraph = new FunctionPanel(this);
Toshihiro Shimizu 890ddd
	m_numericalColumns = new FunctionSheet();
Toshihiro Shimizu 890ddd
	m_toolbar = new FunctionToolbar;
Toshihiro Shimizu 890ddd
	m_segmentViewer = new FunctionSegmentViewer(this, m_numericalColumns, m_functionGraph);
Toshihiro Shimizu 890ddd
	QWidget *leftPanel = new QWidget();
Toshihiro Shimizu 890ddd
	QWidget *rightPanel = new QWidget();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//----
Toshihiro Shimizu 890ddd
	m_treeView->resize(150, m_treeView->size().height());
Toshihiro Shimizu 890ddd
	m_treeView->setMinimumWidth(0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FunctionTreeModel *ftModel =
Toshihiro Shimizu 890ddd
		dynamic_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Toshihiro Shimizu 890ddd
	m_functionGraph->setModel(ftModel);
Toshihiro Shimizu 890ddd
	m_numericalColumns->setModel(ftModel);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_functionGraph->setSelection(getSelection());
Toshihiro Shimizu 890ddd
	m_numericalColumns->setSelection(getSelection());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_numericalColumns->setViewer(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_toolbar->setSelection(m_selection);
Toshihiro Shimizu 890ddd
	m_toolbar->setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_toolbar->setFrameHandle(&m_localFrame);		   // The function editor adopts an internal timeline
Toshihiro Shimizu 890ddd
	m_functionGraph->setFrameHandle(&m_localFrame);	// synchronized among its various sub-widgets.
Toshihiro Shimizu 890ddd
	m_numericalColumns->setFrameHandle(&m_localFrame); // In case an external m_frameHandle is specified,
Toshihiro Shimizu 890ddd
													   // it synchronizes with that, too.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//---- layout
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QVBoxLayout *leftLayout = new QVBoxLayout();
Toshihiro Shimizu 890ddd
	leftLayout->setMargin(0);
Toshihiro Shimizu 890ddd
	leftLayout->setSpacing(0);
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		leftLayout->addWidget(m_toolbar);
Toshihiro Shimizu 890ddd
		leftLayout->addSpacing(36);
Toshihiro Shimizu 890ddd
		leftLayout->addWidget(m_numericalColumns);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	leftPanel->setLayout(leftLayout);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	addWidget(leftPanel);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QVBoxLayout *rightLayout = new QVBoxLayout();
Toshihiro Shimizu 890ddd
	rightLayout->setMargin(0);
Toshihiro Shimizu 890ddd
	rightLayout->setSpacing(5);
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		rightLayout->addWidget(m_segmentViewer, 0);
Toshihiro Shimizu 890ddd
		rightLayout->addWidget(m_treeView, 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	rightPanel->setLayout(rightLayout);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	addWidget(rightPanel);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//--- set the splitter's default size
Toshihiro Shimizu 890ddd
	setSizes(QList<int>() << 500 << 200);</int>
Toshihiro Shimizu 890ddd
	setStretchFactor(0, 5);
Toshihiro Shimizu 890ddd
	setStretchFactor(1, 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//---- signal-slot connections
Toshihiro Shimizu 890ddd
	bool ret = true;
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_toolbar, SIGNAL(numericalColumnToggled()), this, SLOT(toggleMode()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(activeChannelsChanged()), m_functionGraph, SLOT(update()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(activeChannelsChanged()), m_numericalColumns, SLOT(updateAll()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_treeView, SLOT(update()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_functionGraph, SLOT(update()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_numericalColumns, SLOT(updateAll()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(curveSelected(TDoubleParam *)), this, SLOT(onCurveSelected(TDoubleParam *)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), m_segmentViewer, SLOT(onCurveChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(curveChanged(bool)), this, SLOT(onCurveChanged(bool)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(&m_localFrame, SIGNAL(frameSwitched()), this, SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(getSelection(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_functionGraph, SIGNAL(keyframeSelected(double)), m_toolbar, SLOT(setFrame(double)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_treeView, SIGNAL(switchCurrentObject(TStageObject *)),
Toshihiro Shimizu 890ddd
						 this, SLOT(doSwitchCurrentObject(TStageObject *)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_treeView, SIGNAL(switchCurrentFx(TFx *)),
Toshihiro Shimizu 890ddd
						 this, SLOT(doSwitchCurrentFx(TFx *)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ret = ret && connect(ftModel, SIGNAL(currentChannelChanged(FunctionTreeModel::Channel *)), m_numericalColumns, SLOT(onCurrentChannelChanged(FunctionTreeModel::Channel *)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_functionGraph->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FunctionViewer::~FunctionViewer()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_selection;
Toshihiro Shimizu 890ddd
	m_toolbar->setFrameHandle(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::showEvent(QShowEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	refreshModel();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Connect handles
Toshihiro Shimizu 890ddd
	bool ret = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_xshHandle) {
Toshihiro Shimizu 890ddd
		ret = connect(m_xshHandle, SIGNAL(xsheetChanged()), this, SLOT(refreshModel())) && ret;
Toshihiro Shimizu 890ddd
		ret = connect(m_xshHandle, SIGNAL(xsheetSwitched()), this, SLOT(rebuildModel())) && ret;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_frameHandle)
Toshihiro Shimizu 890ddd
		ret = connect(m_frameHandle, SIGNAL(frameSwitched()), this, SLOT(propagateExternalSetFrame())) && ret;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_objectHandle) {
Toshihiro Shimizu 890ddd
		ret = connect(m_objectHandle, SIGNAL(objectSwitched()), this, SLOT(onStageObjectSwitched())) && ret;
Toshihiro Shimizu 890ddd
		ret = connect(m_objectHandle, SIGNAL(objectChanged(bool)), this, SLOT(onStageObjectChanged(bool))) && ret;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_fxHandle)
Toshihiro Shimizu 890ddd
		ret = connect(m_fxHandle, SIGNAL(fxSwitched()), this, SLOT(onFxSwitched())) && ret;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//display animated channels when the scene is switched
Toshihiro Shimizu 890ddd
	if (m_sceneHandle)
Toshihiro Shimizu 890ddd
		ret = connect(m_sceneHandle, SIGNAL(sceneSwitched()), m_treeView, SLOT(displayAnimatedChannels())) && ret;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_treeView->setExpanded(m_treeView->model()->index(0, 0), true);
Toshihiro Shimizu 890ddd
	m_treeView->setExpanded(m_treeView->model()->index(1, 0), true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FunctionTreeModel *ftm = static_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_objectHandle) {
Toshihiro Shimizu 890ddd
		assert(m_xshHandle);
Toshihiro Shimizu 890ddd
		TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		const TStageObjectId &objId = m_objectHandle->getObjectId();
Toshihiro Shimizu 890ddd
		ftm->setCurrentStageObject((objId == TStageObjectId::NoneId) ? (TStageObject *)0 : xsh->getStageObject(objId));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_fxHandle)
Toshihiro Shimizu 890ddd
		ftm->setCurrentFx(m_fxHandle->getFx());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::hideEvent(QHideEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_xshHandle)
Toshihiro Shimizu 890ddd
		m_xshHandle->disconnect(this);
Toshihiro Shimizu 890ddd
	if (m_frameHandle)
Toshihiro Shimizu 890ddd
		m_frameHandle->disconnect(this);
Toshihiro Shimizu 890ddd
	if (m_objectHandle)
Toshihiro Shimizu 890ddd
		m_objectHandle->disconnect(this);
Toshihiro Shimizu 890ddd
	if (m_fxHandle)
Toshihiro Shimizu 890ddd
		m_fxHandle->disconnect(this);
Toshihiro Shimizu 890ddd
	if (m_sceneHandle)
Toshihiro Shimizu 890ddd
		m_sceneHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_functionGraph->isVisible())
Toshihiro Shimizu 890ddd
		m_functionGraph->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::openContextMenu(TreeModel::Item *item, const QPoint &globalPos)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_treeView->openContextMenu(item, globalPos);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::rebuildModel()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	getSelection()->selectNone();
Toshihiro Shimizu 890ddd
	onCurveSelected(0);
Toshihiro Shimizu 890ddd
	m_functionGraph->getModel()->resetAll();
Toshihiro Shimizu 890ddd
	refreshModel();
Toshihiro Shimizu 890ddd
	m_treeView->displayAnimatedChannels();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::refreshModel()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_xshHandle ? m_xshHandle->getXsheet() : 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_functionGraph->getModel()->refreshData(xsh);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (xsh) {
Toshihiro Shimizu 890ddd
		int rowCount = xsh->getFrameCount();
Toshihiro Shimizu 890ddd
		m_numericalColumns->setRowCount(rowCount);
Toshihiro Shimizu 890ddd
		m_numericalColumns->updateAll();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ToonzScene *scene = xsh->getScene();
Toshihiro Shimizu 890ddd
		if (!scene) // This seems wrong. It should rather be
Toshihiro Shimizu 890ddd
			return; // asserted - though I'm not touching it now...
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFilePath scenePath = scene->getScenePath().getParentDir();
Toshihiro Shimizu 890ddd
		if (scene->isUntitled())
Toshihiro Shimizu 890ddd
			scenePath = TProjectManager::instance()->getCurrentProject()->getScenesPath();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_treeView->setCurrentScenePath(scenePath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int distance, offset;
Toshihiro Shimizu 890ddd
		scene->getProperties()->getMarkers(distance, offset);
Toshihiro Shimizu 890ddd
		m_numericalColumns->setMarkRow(distance, offset);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_treeView->updateAll();
Toshihiro Shimizu 890ddd
	m_toolbar->setCurve(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::setXsheetHandle(TXsheetHandle *xshHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (xshHandle == m_xshHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_xshHandle)
Toshihiro Shimizu 890ddd
		m_xshHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_xshHandle = xshHandle;
Toshihiro Shimizu 890ddd
	m_segmentViewer->setXsheetHandle(xshHandle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_xshHandle && isVisible()) {
Toshihiro Shimizu 890ddd
		TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
		m_functionGraph->getModel()->refreshData(xsh);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bool ret = connect(m_xshHandle, SIGNAL(xsheetChanged), this, SLOT(refreshModel()));
Toshihiro Shimizu 890ddd
		assert(ret);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::setFrameHandle(TFrameHandle *frameHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_frameHandle == frameHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_frameHandle)
Toshihiro Shimizu 890ddd
		m_frameHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_frameHandle = frameHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_frameHandle && isVisible()) {
Toshihiro Shimizu 890ddd
		bool ret = connect(m_frameHandle, SIGNAL(frameSwitched()), this, SLOT(propagateExternalSetFrame()));
Toshihiro Shimizu 890ddd
		assert(ret);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::setObjectHandle(TObjectHandle *objectHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (objectHandle == m_objectHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_objectHandle)
Toshihiro Shimizu 890ddd
		m_objectHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_objectHandle = objectHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_objectHandle && isVisible()) {
Toshihiro Shimizu 890ddd
		m_treeView->updateAll();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bool ret = true;
Toshihiro Shimizu 890ddd
		ret = connect(m_objectHandle, SIGNAL(objectSwitched()), this, SLOT(onStageObjectSwitched())) && ret;
Toshihiro Shimizu 890ddd
		ret = connect(m_objectHandle, SIGNAL(objectChanged(bool)), this, SLOT(onStageObjectChanged(bool))) && ret;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		assert(ret);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FunctionTreeModel *ftModel = static_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Toshihiro Shimizu 890ddd
	if (ftModel)
Toshihiro Shimizu 890ddd
		ftModel->setObjectHandle(objectHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::setFxHandle(TFxHandle *fxHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (fxHandle == m_fxHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_fxHandle)
Toshihiro Shimizu 890ddd
		m_fxHandle->disconnect(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_fxHandle = fxHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (isVisible()) {
Toshihiro Shimizu 890ddd
		m_treeView->updateAll();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bool ret = connect(m_fxHandle, SIGNAL(fxSwitched()), this, SLOT(onFxSwitched()));
Toshihiro Shimizu 890ddd
		assert(ret);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FunctionTreeModel *ftModel = static_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Toshihiro Shimizu 890ddd
	if (ftModel)
Toshihiro Shimizu 890ddd
		ftModel->setFxHandle(fxHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::setColumnHandle(TColumnHandle *columnHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (columnHandle == m_columnHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_columnHandle = columnHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (isVisible())
Toshihiro Shimizu 890ddd
		m_treeView->updateAll();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onFrameSwitched()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int frame = m_localFrame.getFrame();
Toshihiro Shimizu 890ddd
	m_segmentViewer->setSegmentByFrame(m_curve, frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_frameHandle)
Toshihiro Shimizu 890ddd
		m_frameHandle->setFrame(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::toggleMode()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isHidden())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_functionGraph->isVisible())
Toshihiro Shimizu 890ddd
		m_functionGraph->hide();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		m_functionGraph->show();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onCurveChanged(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_objectHandle)
Toshihiro Shimizu 890ddd
		m_objectHandle->notifyObjectIdChanged(isDragging);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//emit signal if the current channel belongs to Fx in order to update the preview fx
Toshihiro Shimizu 890ddd
	if (m_fxHandle) {
Toshihiro Shimizu 890ddd
		FunctionTreeModel *ftModel =
Toshihiro Shimizu 890ddd
			dynamic_cast<functiontreemodel *="">(m_treeView->model());</functiontreemodel>
Toshihiro Shimizu 890ddd
		if (ftModel) {
Toshihiro Shimizu 890ddd
			FunctionTreeModel::Channel *currChan = ftModel->getCurrentChannel();
Toshihiro Shimizu 890ddd
			if (currChan) {
Toshihiro Shimizu 890ddd
				//カレントチャンネルがFxChannelGroupに含まれていたらEmit
Toshihiro Shimizu 890ddd
				FxChannelGroup *fxChanGroup =
Toshihiro Shimizu 890ddd
					dynamic_cast<fxchannelgroup *="">(currChan->getChannelGroup());</fxchannelgroup>
Toshihiro Shimizu 890ddd
				if (fxChanGroup)
Toshihiro Shimizu 890ddd
					m_fxHandle->notifyFxChanged();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onCurveSelected(TDoubleParam *curve)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_curve = curve;
Toshihiro Shimizu 890ddd
	m_toolbar->setCurve(curve);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QPair<tdoubleparam *,="" int=""> selectedSegment = getSelection()->getSelectedSegment();</tdoubleparam>
Toshihiro Shimizu 890ddd
	if (selectedSegment.first)
Toshihiro Shimizu 890ddd
		m_segmentViewer->setSegment(selectedSegment.first, selectedSegment.second);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		m_segmentViewer->setSegment(m_curve, -1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onValueFieldChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onXsheetChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
	int rowCount = xsh->getFrameCount();
Toshihiro Shimizu 890ddd
	m_numericalColumns->setRowCount(rowCount);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onStageObjectSwitched()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const TStageObjectId &objId = m_objectHandle->getObjectId();
Toshihiro Shimizu 890ddd
	TStageObject *obj = (objId == TStageObjectId::NoneId) ? (TStageObject *)0 : xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static_cast<functiontreemodel *="">(m_treeView->model())->setCurrentStageObject(obj);</functiontreemodel>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_treeView->updateAll();
Toshihiro Shimizu 890ddd
	m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onStageObjectChanged(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const TStageObjectId &objId = m_objectHandle->getObjectId();
Toshihiro Shimizu 890ddd
	TStageObject *obj = (objId == TStageObjectId::NoneId) ? (TStageObject *)0 : xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static_cast<functiontreemodel *="">(m_treeView->model())->setCurrentStageObject(obj);</functiontreemodel>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!isDragging)
Toshihiro Shimizu 890ddd
		m_treeView->updateAll();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onFxSwitched()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFx *fx = m_fxHandle->getFx();
Toshihiro Shimizu 890ddd
	TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Toshihiro Shimizu 890ddd
	if (zfx)
Toshihiro Shimizu 890ddd
		fx = zfx->getZeraryFx();
Toshihiro Shimizu 890ddd
	static_cast<functiontreemodel *="">(m_treeView->model())->setCurrentFx(fx);</functiontreemodel>
Toshihiro Shimizu 890ddd
	m_treeView->updateAll();
Toshihiro Shimizu 890ddd
	m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::onSelectionChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPair<tdoubleparam *,="" int=""> selectedSegment = getSelection()->getSelectedSegment();</tdoubleparam>
Toshihiro Shimizu 890ddd
	if (selectedSegment.first) {
Toshihiro Shimizu 890ddd
		if (selectedSegment.first != m_curve) {
Toshihiro Shimizu 890ddd
			m_curve = selectedSegment.first;
Toshihiro Shimizu 890ddd
			m_toolbar->setCurve(selectedSegment.first);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_segmentViewer->setSegment(selectedSegment.first, selectedSegment.second);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		m_segmentViewer->setSegment(m_curve, -1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// update curves
Toshihiro Shimizu 890ddd
	if (m_functionGraph->isVisible() && !m_functionGraph->hasFocus())
Toshihiro Shimizu 890ddd
		m_functionGraph->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::doSwitchCurrentObject(TStageObject *obj)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStageObjectId id = obj->getId();
Toshihiro Shimizu 890ddd
	if (id.isColumn())
Toshihiro Shimizu 890ddd
		m_columnHandle->setColumnIndex(id.getIndex());
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		m_objectHandle->setObjectId(id);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::doSwitchCurrentFx(TFx *fx)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!fx) {
Toshihiro Shimizu 890ddd
		m_fxHandle->setFx(0);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (fx->isZerary()) {
Toshihiro Shimizu 890ddd
		TXsheet *xsh = m_xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
		int i, columnCount = xsh->getColumnCount();
Toshihiro Shimizu 890ddd
		for (i = 0; i < columnCount; i++) {
Toshihiro Shimizu 890ddd
			TXshColumn *column = xsh->getColumn(i);
Toshihiro Shimizu 890ddd
			TXshZeraryFxColumn *zfx = dynamic_cast<txshzeraryfxcolumn *="">(xsh->getColumn(i));</txshzeraryfxcolumn>
Toshihiro Shimizu 890ddd
			if (!zfx)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			if (zfx->getZeraryColumnFx()->getZeraryFx() == fx) {
Toshihiro Shimizu 890ddd
				fx = zfx->getZeraryColumnFx();
Toshihiro Shimizu 890ddd
				m_columnHandle->setColumnIndex(i);
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// Forbid update of the swatch upon column switch. This would generate
Toshihiro Shimizu 890ddd
	// a useless render...
Toshihiro Shimizu 890ddd
	SwatchViewer::suspendRendering(true, false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int columnIndex = fx->getReferenceColumnIndex();
Toshihiro Shimizu 890ddd
	if (columnIndex >= 0)
Toshihiro Shimizu 890ddd
		m_columnHandle->setColumnIndex(columnIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SwatchViewer::suspendRendering(false);
Toshihiro Shimizu 890ddd
	m_fxHandle->setFx(fx);
Toshihiro Shimizu 890ddd
	emit editObject();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::propagateExternalSetFrame()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_frameHandle);
Toshihiro Shimizu 890ddd
	m_localFrame.setFrame(m_frameHandle->getFrame());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::addParameter(
Toshihiro Shimizu 890ddd
	TParam *parameter, const TFilePath &folder)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	static_cast<functiontreemodel *="">(m_treeView->model())->addParameter(parameter, folder);</functiontreemodel>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::setFocusColumnsOrGraph()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_numericalColumns->setFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::clearFocusColumnsAndGraph()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_functionGraph->clearFocus();
Toshihiro Shimizu 890ddd
	m_numericalColumns->clearFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool FunctionViewer::columnsOrGraphHasFocus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_functionGraph->hasFocus() || m_numericalColumns->anyWidgetHasFocus() || m_toolbar->anyWidgetHasFocus() || m_segmentViewer->anyWidgetHasFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FunctionViewer::setSceneHandle(TSceneHandle *sceneHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_sceneHandle = sceneHandle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool FunctionViewer::isExpressionPageActive()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_segmentViewer->isExpressionPageActive();
Toshihiro Shimizu 890ddd
}