tahoma2d/toonz/sources/toonzqt/functionviewer.cpp
Jeremy Bullock af90cdedbe
UI update and Icons from Konero (#126)
* add multi arc mockup

* implement mutli arc

* add join and smooth option

* reset multiarc and arc when deactivated

* create self loop if the last point is the same as the first

* make join option in multiarc consistent with tape tool

* fix a bug where thickness don't affect mutliarc in vector level

* remove join option in geometric tool

* stop mutliarc after closing shape

* double click can also end multi arc

* fix a bug where multiArc will produce buggy stroke

* fix a bug where geometric tools is not deactivated

* add multiArc shortcut

* rewrite multiArc

* revert changes to tvectorimage

* add undo data for multiArc

* Paste as Copy Command for XSheet

* Remove unneeded code

* Bug fix

* prevent guide lines from jumping around in MultiArc

* make stroke color consistent in MultiArc

* remove color in MultiArc's undo data

* make color consistent in MultiArc with previous version

* Fix single image raster levels

* fix compilation error

* fix a bug where multiArc might generate bugged stroke

* Remove ICONV dep (#3304)

* fix crash on saving studio palette

* Move to Paste Special Menu

* Don't Set Fixed Width if Docking a Floating Panel

* Update how_to_build_win.md

New draft of pr for requested changes to windows build instructions.

* fix geometric tool multiarc smooth option

* fix level saving failure

* fix wrong warning after saving palette

* fix a bug where moving a control point while holding alt has unintended result

* fix travis-install (#3389)

* Fix assert debug crash in flipconsole.cpp

Fix crash when using the viewer controls in the console (debug)

* Redraw Audio Waveform

Fills the waveform rather than outlines it.

* Update .gitignore

* fix undo data when drawing arc and mutliarc

* fix overwriting raster drawing palette (#3387)

* mode sensitive fx settings

* Create New Style Command Button (#3394)

* Create New Style Command Button

This PR creates a new button in the pallette editor that creates a new style.  Button is large and easy access for a faster and easier workflow.  Original code developed by Turtletooth for Tahoma.  Given permission to develop within Openoonz.

Co-Authored-By: Jeremy Bullock <turtletooth@users.noreply.github.com>

* Update paletteviewergui.cpp

Made changes to the PR per request by Shun.

* Fixed a space within the code that wasn't suppose to be there.

Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com>

* tahoma license (#3396)

* new style button optional

* fix loading pegbars (removing updateKeyframes)

* periodic random expression

* add fx in linear color space
this commit is based on source for the ComposeAdd plugin fx by DWANGO Co., Ltd.
in dwango_opentoonz_plugins and opentoonz_plugin_utility repositories.

* fractal noise iwa fx

* skip unnecessary icon invalidation

* fix frame range fill with tablet

* stop function editor to open by dbl clicking key

* Expanding the radius of the rotation handle.

This just changes when the cursor transforms into the rotation tool.

(cherry picked from commit 7722ae989bbdc6aa5cb48df7a4c08bae1fe6ea39)

* fix vector img patern stroke style

* Update Stylesheets

- Support the new icon sizes
- XSheet and Timeline significantly redesigned
- Lots of margin fixes and refactoring
- Remove deprecated icons, as some icons are moved into binary
- New Light theme

* New Icons

- Redesigns almost every icon as symbolic
- Adds icons for most commands

* Add Option for Icon Themes

- Adds option for icon themes
- Removes useless label from Preferences category list

* Update Icon Functions

- Adds themePath() boolean
- Adds function for recoloring black pixels in pixmaps to any color
- Rebuilds createQIcon to use fromTheme() and recolorPixmap()
- Removes createQIconOnOff as it seemed to be a rarely used duplicate of createQIcon
- Removes a grey horizontal line drawn above the console play bar in the viewer

* Set Default Icon Theme and Paths

- Sets search paths for icons for use with QIcon::fromTheme()
- Sets default start icon theme on first install
- Sets flag for displaying icons in menus, so we can selectively hide them

* Set Icons for Commands

- Sets icons for the commands
- Hides icons being displayed in menus as most icons are 20x20, they will look blurry when shrunk to 16x16
- Selectively allows icons to display for Tools in menus

* Change Icon Sizes, General Fixes and Stylesheet Additions

- Change icon sizes to new size
- Remove margin around FX Editor window
- Remove white line under color sliders in Style Editor
- Make keyframe icons uniform and color stylable in the stylesheets
- Removes deprecated stylesheet strings
- Redesign GUI for palette list view
- Make tree list header sort row stylable
- Remove black lines from scrollbars in New Project window
- Remove margin around combobox in Level Strip
- Alter how some lines are drawn in the Timeline to fix some alpha issues
- Make conditional fixed onion skin and normal onion skin dots contrast more against a light background area to make sure they have good visibility
- Make text always viewable in the FPS field in console bar
- Increase size of radio buttons in Cleanup Settings
- Increase size of switches in motion path nodes
- Remove unessesary "Layer" label in Timeline and other rects
- Various colors made stylable in the stylesheets; palette numpad and selection frame, cleanup settings border, scene cast folder path, schematic lines, ruler, xsheet lines, keyframes, cell input box and more
- Moves some external stylesheet icons into binary

* Make TPanelTitleBar Icon States Stylable

- Makes icon states for TPanelTitleBar buttons stylable in stylesheets

* Travis Fixes

* Swap Startup Popup Logos

They were in the wrong folders

* Revert "Swap Startup Popup Logos"

This reverts commit 815908a9f3e725f48507dab8a2270bdfa045649d.

* Fix Startup Popup Logo

It wasn't switching

* Feedback Changes

- Change render visualization to clapboard
- Fix text contrast on levels in XSheet

* Make Cell Selection More Clear

* Darken Light Theme and Tint Empty Cell Selection

* Fix missing icons

* Fix memo button

* Bring back colors

* Hide Motion Tab

* Fix Play Range Area (Light)

Make play range area more visible

* Vector Column Color

Co-authored-by: pojienie <pojienie@gmail.com>
Co-authored-by: rim <11380091+rozhuk-im@users.noreply.github.com>
Co-authored-by: shun-iwasawa <shun.iwasawa@ghibli.jp>
Co-authored-by: Rodney <rodney.baker@gmail.com>
Co-authored-by: DoctorRyan <65507211+DoctorRyan@users.noreply.github.com>
Co-authored-by: shun-iwasawa <shun-iwasawa@users.noreply.github.com>
Co-authored-by: Kite <konero@users.noreply.github.com>
Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com>
Co-authored-by: DoctorRyan <doctorryan1969.gmail.com>
2020-08-31 12:51:22 -06:00

763 lines
No EOL
24 KiB
C++

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