|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/functiontoolbar.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/doublefield.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/functionkeyframenavigator.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/functionselection.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/framenavigator.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/gutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/menubarcommand.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/doubleparamcmd.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qlabel></qlabel>
|
|
Toshihiro Shimizu |
890ddd |
#include <qapplication></qapplication>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* two states: curve_defined / curve_not_defined
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
* three widgets: value_fld, frame_nav, keyframe_nav
|
|
Toshihiro Shimizu |
890ddd |
(if curve_not_defined only keyframe_nav is visible)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
* user actions
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
- value_fld changed / keyframe_nav changed (key icon) => modify current curve
|
|
Toshihiro Shimizu |
890ddd |
- frame_nav changed / keyframe_nav changed (arrows) => modify the 'extern' frame
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
* 'extern' events:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
- 'extern' frame changed => update fields
|
|
Toshihiro Shimizu |
890ddd |
- curve selected => update fields (and possibly change status)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FunctionToolbar::FunctionToolbar(QWidget *parent)
|
|
Toshihiro Shimizu |
890ddd |
: DVGui::ToolBar(parent), m_frameHandle(0), m_curve(0), m_selection(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setFixedHeight(28);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_valueToolbar = new DVGui::ToolBar();
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeToolbar = new DVGui::ToolBar();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// value field
|
|
Toshihiro Shimizu |
890ddd |
m_valueToolbar->addWidget(new QLabel(tr("Value")));
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld = new DVGui::MeasuredDoubleLineEdit();
|
|
Toshihiro Shimizu |
890ddd |
// frame navigator
|
|
Toshihiro Shimizu |
890ddd |
m_frameNavigator = new FrameNavigator(this);
|
|
Toshihiro Shimizu |
890ddd |
// keyframe navigator
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigator = new FunctionKeyframeNavigator(this);
|
|
Toshihiro Shimizu |
890ddd |
QWidget *space = new QWidget(this);
|
|
Toshihiro Shimizu |
890ddd |
DVGui::ToolBar *spaceToolBar = new DVGui::ToolBar();
|
|
Toshihiro Shimizu |
890ddd |
spaceToolBar->addWidget(space);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setStyleSheet("height:14px;margin-right:5px;margin-top:2px;");
|
|
Toshihiro Shimizu |
890ddd |
space->setMinimumHeight(22);
|
|
Toshihiro Shimizu |
890ddd |
space->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon toggleIcon = createQIconOnOffPNG("swap", false);
|
|
Toshihiro Shimizu |
890ddd |
QAction *toggleAction = new QAction(tr("&Function Editor Toggle"), this);
|
|
Toshihiro Shimizu |
890ddd |
assert(toggleAction);
|
|
Toshihiro Shimizu |
890ddd |
toggleAction->setIcon(toggleIcon);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----layout
|
|
Toshihiro Shimizu |
890ddd |
m_valueFldAction = addWidget(m_valueToolbar);
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigatorAction = addWidget(m_keyframeToolbar);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_valueToolbar->addWidget(m_valueFld);
|
|
Toshihiro Shimizu |
890ddd |
m_valueToolbar->addSeparator();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeToolbar->addWidget(m_keyframeNavigator);
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeToolbar->addSeparator();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
addWidget(m_frameNavigator);
|
|
Toshihiro Shimizu |
890ddd |
addSeparator();
|
|
Toshihiro Shimizu |
890ddd |
addWidget(spaceToolBar);
|
|
Toshihiro Shimizu |
890ddd |
addSeparator();
|
|
Toshihiro Shimizu |
890ddd |
addAction(toggleAction);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ret = connect(m_valueFld, SIGNAL(valueChanged()), this, SLOT(onValueFieldChanged()));
|
|
Toshihiro Shimizu |
890ddd |
ret = ret && connect(m_frameNavigator, SIGNAL(frameSwitched()), this, SLOT(onNavFrameSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
ret = ret && connect(toggleAction, SIGNAL(triggered()), this, SIGNAL(numericalColumnToggled()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_valueFldAction->setVisible(false);
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigatorAction->setVisible(false);
|
|
Toshihiro Shimizu |
890ddd |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FunctionToolbar::~FunctionToolbar()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_curve) {
|
|
Toshihiro Shimizu |
890ddd |
m_curve->removeObserver(this);
|
|
Toshihiro Shimizu |
890ddd |
m_curve->release();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool FunctionToolbar::anyWidgetHasFocus()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return hasFocus() ||
|
|
Toshihiro Shimizu |
890ddd |
m_valueToolbar->hasFocus() ||
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeToolbar->hasFocus() ||
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->hasFocus() ||
|
|
Toshihiro Shimizu |
890ddd |
m_frameNavigator->anyWidgetHasFocus() ||
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigator->hasFocus();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::setCurve(TDoubleParam *curve)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (curve == m_curve)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
bool curveDefined = curve != 0;
|
|
Toshihiro Shimizu |
890ddd |
m_valueFldAction->setVisible(curveDefined);
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigatorAction->setVisible(curveDefined);
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigator->setCurve(curve);
|
|
Toshihiro Shimizu |
890ddd |
if (curve) {
|
|
Toshihiro Shimizu |
890ddd |
curve->addObserver(this);
|
|
Toshihiro Shimizu |
890ddd |
curve->addRef();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (m_curve) {
|
|
Toshihiro Shimizu |
890ddd |
m_curve->removeObserver(this);
|
|
Toshihiro Shimizu |
890ddd |
m_curve->release();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_curve = curve;
|
|
Toshihiro Shimizu |
890ddd |
if (m_curve) {
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setMeasure(m_curve->getMeasureName());
|
|
Toshihiro Shimizu |
890ddd |
setFrame(m_frameNavigator->getFrame());
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setMeasure("");
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setValue(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::setFrame(double frame)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_frameNavigator->setFrame(tround(frame), false);
|
|
Toshihiro Shimizu |
890ddd |
if (m_curve)
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setValue(m_curve->getValue(frame));
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setValue(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::onValueFieldChanged()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_curve)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
int frame = m_frameNavigator->getFrame();
|
|
Toshihiro Shimizu |
890ddd |
double value = m_valueFld->getValue();
|
|
Toshihiro Shimizu |
890ddd |
double fValue = m_curve->getValue(frame);
|
|
Toshihiro Shimizu |
890ddd |
if (value == fValue)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
KeyframeSetter::setValue(m_curve, frame, value);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::onFrameSwitched()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setFrame(m_frameHandle->getFrame());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::onNavFrameSwitched()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_frameHandle)
|
|
Toshihiro Shimizu |
890ddd |
m_frameHandle->setFrame(m_frameNavigator->getFrame());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::onSelectionChanged()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_selection) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_selection->getSelectedKeyframeCount() == 1) {
|
|
Toshihiro Shimizu |
890ddd |
QPair<tdoubleparam *,="" int=""> k = m_selection->getSelectedKeyframe(0);</tdoubleparam>
|
|
Toshihiro Shimizu |
890ddd |
if (k.first == m_curve) {
|
|
Toshihiro Shimizu |
890ddd |
int frame = m_curve->keyframeIndexToFrame(k.second);
|
|
Toshihiro Shimizu |
890ddd |
setFrame(frame);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else if (m_selection->getSelectedKeyframeCount() > 1) {
|
|
Toshihiro Shimizu |
890ddd |
setFrame(m_frameHandle->getFrame());
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setText("");
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_frameHandle && m_curve)
|
|
Toshihiro Shimizu |
890ddd |
setFrame(m_frameHandle->getFrame());
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_valueFld->setText("");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::setFrameHandle(TFrameHandle *frameHandle)
|
|
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)
|
|
Toshihiro Shimizu |
890ddd |
connect(m_frameHandle, SIGNAL(frameSwitched()), this, SLOT(onFrameSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigator->setFrameHandle(frameHandle);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::setSelection(FunctionSelection *selection)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_selection != selection) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_selection)
|
|
Toshihiro Shimizu |
890ddd |
disconnect(m_selection, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
|
|
Toshihiro Shimizu |
890ddd |
m_selection = selection;
|
|
Toshihiro Shimizu |
890ddd |
if (m_selection)
|
|
Toshihiro Shimizu |
890ddd |
connect(m_selection, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void FunctionToolbar::onChange(const TParamChange &)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_keyframeNavigator->update();
|
|
Toshihiro Shimizu |
890ddd |
}
|