|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "functionpaneltools.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/functionselection.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qpainter></qpainter>
|
|
Toshihiro Shimizu |
890ddd |
#include <qmouseevent></qmouseevent>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MoveFrameDragTool::MoveFrameDragTool(FunctionPanel *panel,
|
|
Shinya Kitaoka |
120a6e |
TFrameHandle *frameHandle)
|
|
Shinya Kitaoka |
120a6e |
: m_panel(panel), m_frameHandle(frameHandle) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void MoveFrameDragTool::drag(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
double frame = m_panel->xToFrame(e->pos().x());
|
|
Shinya Kitaoka |
120a6e |
m_panel->getSelection()->deselectAllKeyframes();
|
|
Shinya Kitaoka |
120a6e |
m_frameHandle->setFrame(frame);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
PanDragTool::PanDragTool(FunctionPanel *panel, bool xLocked, bool yLocked)
|
|
Shinya Kitaoka |
120a6e |
: m_panel(panel), m_xLocked(xLocked), m_yLocked(yLocked) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void PanDragTool::click(QMouseEvent *e) { m_oldPos = e->pos(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void PanDragTool::drag(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
QPoint delta = e->pos() - m_oldPos;
|
|
Shinya Kitaoka |
120a6e |
if (m_xLocked) delta.setX(0);
|
|
Shinya Kitaoka |
120a6e |
if (m_yLocked) delta.setY(0);
|
|
Shinya Kitaoka |
120a6e |
m_panel->pan(delta);
|
|
Shinya Kitaoka |
120a6e |
m_oldPos = e->pos();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
/*--- Ruler部分ドラッグによるズーム ---*/
|
|
Shinya Kitaoka |
120a6e |
void ZoomDragTool::click(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
m_startPos = m_oldPos = m_startPos = e->pos();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ZoomDragTool::drag(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
QPoint delta = e->pos() - m_oldPos;
|
|
Shinya Kitaoka |
120a6e |
m_oldPos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
double sx = 1, sy = 1;
|
|
Shinya Kitaoka |
120a6e |
// reflect horizontal drag for frame zoom
|
|
Shinya Kitaoka |
120a6e |
double zoomFactor =
|
|
Shinya Kitaoka |
120a6e |
exp(-0.0075 * ((m_zoomType == FrameZoom) ? -delta.x() : delta.y()));
|
|
Shinya Kitaoka |
120a6e |
if (m_zoomType == FrameZoom)
|
|
Shinya Kitaoka |
120a6e |
sx = zoomFactor;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
sy = zoomFactor;
|
|
Shinya Kitaoka |
120a6e |
m_panel->zoom(sx, sy, m_startPos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ZoomDragTool::release(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
if ((e->pos() - m_startPos).manhattanLength() < 2) {
|
|
Shinya Kitaoka |
120a6e |
double frame = m_panel->xToFrame(e->pos().x());
|
|
Shinya Kitaoka |
120a6e |
if (m_panel->getFrameHandle()) m_panel->getFrameHandle()->setFrame(frame);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RectSelectTool::click(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
m_startPos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
m_rect = QRect();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RectSelectTool::drag(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
m_rect = QRect(m_startPos, e->pos()).normalized();
|
|
Shinya Kitaoka |
120a6e |
m_panel->getSelection()->deselectAllKeyframes();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < m_curve->getKeyframeCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
QPointF p = m_panel->getWinPos(m_curve, m_curve->getKeyframe(i));
|
|
Shinya Kitaoka |
120a6e |
if (m_rect.contains(tround(p.x()), tround(p.y())))
|
|
Shinya Kitaoka |
120a6e |
m_panel->getSelection()->select(m_curve, i);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_panel->update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RectSelectTool::release(QMouseEvent *e) { m_panel->update(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RectSelectTool::draw(QPainter &painter) {
|
|
Shinya Kitaoka |
120a6e |
painter.setPen(Qt::white);
|
|
Shinya Kitaoka |
120a6e |
painter.setBrush(QColor(255, 255, 255, 127));
|
|
Shinya Kitaoka |
120a6e |
if (!m_rect.isEmpty()) painter.drawRect(m_rect);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MovePointDragTool::MovePointDragTool(FunctionPanel *panel, TDoubleParam *curve)
|
|
Shinya Kitaoka |
120a6e |
: m_panel(panel)
|
|
Shinya Kitaoka |
120a6e |
, m_deltaFrame(0)
|
|
Shinya Kitaoka |
120a6e |
, m_speed0Length(0)
|
|
Shinya Kitaoka |
120a6e |
, m_speed0Index(-1)
|
|
Shinya Kitaoka |
120a6e |
, m_speed1Length(0)
|
|
Shinya Kitaoka |
120a6e |
, m_speed1Index(-1)
|
|
Shinya Kitaoka |
120a6e |
, m_groupEnabled(false)
|
|
Shinya Kitaoka |
120a6e |
, m_selection(0) {
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->beginBlock();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (curve) {
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = new KeyframeSetter(curve);
|
|
Shinya Kitaoka |
120a6e |
m_setters.push_back(setter);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_groupEnabled = true;
|
|
Shinya Kitaoka |
120a6e |
FunctionTreeModel *model = panel->getModel();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < model->getActiveChannelCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
FunctionTreeModel::Channel *channel = model->getActiveChannel(i);
|
|
Shinya Kitaoka |
120a6e |
if (channel && channel->getParam()) {
|
|
Shinya Kitaoka |
120a6e |
TDoubleParam *curve = channel->getParam();
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = new KeyframeSetter(curve);
|
|
Shinya Kitaoka |
120a6e |
m_setters.push_back(setter);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MovePointDragTool::~MovePointDragTool() {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) delete m_setters[i];
|
|
Shinya Kitaoka |
120a6e |
m_setters.clear();
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->endBlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MovePointDragTool::addKeyframe2(int kIndex) {
|
|
Shinya Kitaoka |
120a6e |
assert(m_setters.size() == 1);
|
|
Shinya Kitaoka |
120a6e |
if (m_setters.size() == 1) m_setters[0]->selectKeyframe(kIndex);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MovePointDragTool::createKeyframe(double frame) {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = m_setters[i];
|
|
Shinya Kitaoka |
120a6e |
int kIndex = setter->createKeyframe(tround(frame));
|
|
Shinya Kitaoka |
120a6e |
setter->selectKeyframe(kIndex);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MovePointDragTool::selectKeyframes(double frame) {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = m_setters[i];
|
|
Shinya Kitaoka |
120a6e |
TDoubleParam *curve = setter->getCurve();
|
|
Shinya Kitaoka |
120a6e |
setter->setPixelRatio(m_panel->getPixelRatio(curve));
|
|
Shinya Kitaoka |
120a6e |
int kIndex = curve->getClosestKeyframe(frame);
|
|
Shinya Kitaoka |
120a6e |
if (kIndex >= 0) {
|
|
Shinya Kitaoka |
120a6e |
double kf = curve->keyframeIndexToFrame(kIndex);
|
|
Shinya Kitaoka |
120a6e |
if (fabs(kf - frame) < 0.01) setter->selectKeyframe(kIndex);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MovePointDragTool::setSelection(FunctionSelection *selection) {
|
|
Shinya Kitaoka |
120a6e |
if (selection) {
|
|
Shinya Kitaoka |
120a6e |
assert(m_setters.size() == 1);
|
|
Shinya Kitaoka |
120a6e |
if (m_setters.size() == 1) {
|
|
Shinya Kitaoka |
120a6e |
TDoubleParam *curve = m_setters[0]->getCurve();
|
|
Shinya Kitaoka |
120a6e |
assert(curve);
|
|
Shinya Kitaoka |
120a6e |
if (curve) {
|
|
Shinya Kitaoka |
120a6e |
m_selection = selection;
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < curve->getKeyframeCount(); i++)
|
|
Shinya Kitaoka |
120a6e |
if (selection->isSelected(curve, i)) addKeyframe2(i);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
m_selection = selection;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MovePointDragTool::click(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
m_startPos = m_oldPos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
m_deltaFrame = 0;
|
|
Shinya Kitaoka |
120a6e |
double frame = m_panel->xToFrame(e->pos().x());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = m_setters[i];
|
|
Shinya Kitaoka |
120a6e |
TDoubleParam *curve = setter->getCurve();
|
|
Shinya Kitaoka |
120a6e |
setter->setPixelRatio(m_panel->getPixelRatio(curve));
|
|
Shinya Kitaoka |
120a6e |
if (!m_groupEnabled) {
|
|
Shinya Kitaoka |
120a6e |
int kIndex = curve->getClosestKeyframe(frame);
|
|
Shinya Kitaoka |
120a6e |
if (kIndex >= 0) {
|
|
Shinya Kitaoka |
120a6e |
double kf = curve->keyframeIndexToFrame(kIndex);
|
|
Shinya Kitaoka |
120a6e |
if (fabs(kf - frame) < 1) setter->selectKeyframe(kIndex);
|
|
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 MovePointDragTool::drag(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
QPoint pos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// if shift is pressed then apply constraints (only horizontal or vertical
|
|
Shinya Kitaoka |
120a6e |
// moves)
|
|
Shinya Kitaoka |
120a6e |
if (e->modifiers() & Qt::ShiftModifier) {
|
|
Shinya Kitaoka |
120a6e |
QPoint delta = e->pos() - m_startPos;
|
|
Shinya Kitaoka |
120a6e |
if (abs(delta.x()) > abs(delta.y()))
|
|
Shinya Kitaoka |
120a6e |
pos.setY(m_startPos.y());
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
pos.setX(m_startPos.x());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_groupEnabled) pos.setY(m_startPos.y());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPoint oldPos = m_oldPos;
|
|
Shinya Kitaoka |
120a6e |
m_oldPos = pos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// compute frame increment. it must be an integer
|
|
Shinya Kitaoka |
120a6e |
double totalDFrame =
|
|
Shinya Kitaoka |
120a6e |
tround(m_panel->xToFrame(pos.x()) - m_panel->xToFrame(m_startPos.x()));
|
|
Shinya Kitaoka |
120a6e |
double dFrame = totalDFrame - m_deltaFrame;
|
|
Shinya Kitaoka |
120a6e |
m_deltaFrame = totalDFrame;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = m_setters[i];
|
|
Shinya Kitaoka |
120a6e |
TDoubleParam *curve = setter->getCurve();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// compute value increment
|
|
Shinya Kitaoka |
120a6e |
double dValue = m_panel->yToValue(curve, pos.y()) -
|
|
Shinya Kitaoka |
120a6e |
m_panel->yToValue(curve, oldPos.y());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
setter->moveKeyframes(dFrame, dValue);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (m_selection != 0 && m_setters.size() == 1) {
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = m_setters[0];
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selection->deselectAllKeyframes();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < setter->getCurve()->getKeyframeCount(); i++)
|
|
Shinya Kitaoka |
120a6e |
if (setter->isSelected(i)) m_selection->select(setter->getCurve(), i);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_panel->update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MovePointDragTool::release(QMouseEvent *e) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MoveHandleDragTool::MoveHandleDragTool(FunctionPanel *panel,
|
|
Shinya Kitaoka |
120a6e |
TDoubleParam *curve, int kIndex,
|
|
Shinya Kitaoka |
120a6e |
Handle handle)
|
|
Shinya Kitaoka |
120a6e |
: m_panel(panel)
|
|
Shinya Kitaoka |
120a6e |
, m_curve(curve)
|
|
Shinya Kitaoka |
120a6e |
, m_kIndex(kIndex)
|
|
Shinya Kitaoka |
120a6e |
, m_handle(handle)
|
|
Shinya Kitaoka |
120a6e |
, m_deltaFrame(0)
|
|
Shinya Kitaoka |
120a6e |
, m_setter(curve, kIndex)
|
|
Shinya Kitaoka |
120a6e |
, m_segmentWidth(0)
|
|
Shinya Kitaoka |
120a6e |
, m_channelGroup(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MoveHandleDragTool::click(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
m_startPos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
// m_startPos = m_oldPos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
m_deltaFrame = 0;
|
|
Shinya Kitaoka |
120a6e |
m_keyframe = m_curve->getKeyframe(m_kIndex);
|
|
Shinya Kitaoka |
120a6e |
m_keyframe.m_value = m_curve->getValue(m_keyframe.m_frame);
|
|
Shinya Kitaoka |
120a6e |
if (m_handle == FunctionPanel::SpeedIn)
|
|
Shinya Kitaoka |
120a6e |
m_keyframe.m_value = m_curve->getValue(m_keyframe.m_frame, true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_channelGroup) {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < m_channelGroup->getChildCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TreeModel::Item *child = m_channelGroup->getChild(i);
|
|
Shinya Kitaoka |
120a6e |
FunctionTreeModel::Channel *channel =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<functiontreemodel::channel *="">(child);</functiontreemodel::channel>
|
|
Shinya Kitaoka |
120a6e |
if (channel && m_curve != channel->getParam()) {
|
|
Shinya Kitaoka |
120a6e |
if (channel->getParam()->isKeyframe(m_keyframe.m_frame)) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_handle == FunctionPanel::EaseInPercentage && m_kIndex > 0) {
|
|
Shinya Kitaoka |
120a6e |
double previousFrame = m_curve->keyframeIndexToFrame(m_kIndex - 1);
|
|
Shinya Kitaoka |
120a6e |
m_segmentWidth = m_keyframe.m_frame - previousFrame;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (m_handle == FunctionPanel::EaseOutPercentage &&
|
|
Shinya Kitaoka |
120a6e |
m_kIndex + 1 < m_curve->getKeyframeCount()) {
|
|
Shinya Kitaoka |
120a6e |
double nextFrame = m_curve->keyframeIndexToFrame(m_kIndex + 1);
|
|
Shinya Kitaoka |
120a6e |
m_segmentWidth = nextFrame - m_keyframe.m_frame;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TPointD speed;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_keyframe.m_linkedHandles) {
|
|
Shinya Kitaoka |
120a6e |
if (m_handle == FunctionPanel::SpeedIn &&
|
|
Shinya Kitaoka |
120a6e |
m_kIndex + 1 < m_curve->getKeyframeCount() &&
|
|
Shinya Kitaoka |
120a6e |
(m_keyframe.m_type != TDoubleKeyframe::SpeedInOut &&
|
|
Shinya Kitaoka |
120a6e |
(m_keyframe.m_type != TDoubleKeyframe::Expression ||
|
|
Shinya Kitaoka |
120a6e |
m_keyframe.m_expressionText.find("cycle") == std::string::npos)))
|
|
Shinya Kitaoka |
120a6e |
speed = m_curve->getSpeedIn(m_kIndex);
|
|
Shinya Kitaoka |
120a6e |
else if (m_handle == FunctionPanel::SpeedOut &&
|
|
Shinya Kitaoka |
120a6e |
m_keyframe.m_prevType != TDoubleKeyframe::SpeedInOut &&
|
|
Shinya Kitaoka |
120a6e |
m_kIndex > 0)
|
|
Shinya Kitaoka |
120a6e |
speed = m_curve->getSpeedOut(m_kIndex);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (norm2(speed) > 0.001) {
|
|
Shinya Kitaoka |
120a6e |
QPointF a = m_panel->getWinPos(m_curve, speed) -
|
|
Shinya Kitaoka |
120a6e |
m_panel->getWinPos(m_curve, TPointD());
|
|
Shinya Kitaoka |
120a6e |
double aa = 1.0 / sqrt(a.x() * a.x() + a.y() * a.y());
|
|
Shinya Kitaoka |
120a6e |
m_nSpeed = QPointF(-a.y() * aa, a.x() * aa);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
m_nSpeed = QPointF();
|
|
Shinya Kitaoka |
120a6e |
m_setter.setPixelRatio(m_panel->getPixelRatio(m_curve));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MoveHandleDragTool::drag(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_curve) return;
|
|
Shinya Kitaoka |
120a6e |
QPoint pos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// if shift is pressed then apply constraints (only horizontal or vertical
|
|
Shinya Kitaoka |
120a6e |
// moves)
|
|
Shinya Kitaoka |
120a6e |
if (e->modifiers() & Qt::ShiftModifier) {
|
|
Shinya Kitaoka |
120a6e |
QPoint delta = e->pos() - m_startPos;
|
|
Shinya Kitaoka |
120a6e |
if (abs(delta.x()) > abs(delta.y()))
|
|
Shinya Kitaoka |
120a6e |
pos.setY(m_startPos.y());
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
pos.setX(m_startPos.x());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// QPoint oldPos = m_oldPos;
|
|
Shinya Kitaoka |
120a6e |
// m_oldPos = pos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPointF p0 = m_panel->getWinPos(m_curve, m_keyframe);
|
|
Shinya Kitaoka |
120a6e |
QPointF posF(pos);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_nSpeed != QPointF(0, 0)) {
|
|
Shinya Kitaoka |
120a6e |
QPointF delta = posF - p0;
|
|
Shinya Kitaoka |
120a6e |
posF -= m_nSpeed * (delta.x() * m_nSpeed.x() + delta.y() * m_nSpeed.y());
|
|
Shinya Kitaoka |
120a6e |
if ((m_handle == FunctionPanel::SpeedIn && posF.x() > p0.x()) ||
|
|
Shinya Kitaoka |
120a6e |
(m_handle == FunctionPanel::SpeedOut && posF.x() < p0.x()))
|
|
Shinya Kitaoka |
120a6e |
posF = p0;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if ((m_handle == FunctionPanel::SpeedIn && posF.x() > p0.x()) ||
|
|
Shinya Kitaoka |
120a6e |
(m_handle == FunctionPanel::SpeedOut && posF.x() < p0.x()))
|
|
Shinya Kitaoka |
120a6e |
posF.setX(p0.x());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double frame = m_panel->xToFrame(posF.x());
|
|
Shinya Kitaoka |
120a6e |
double value = m_panel->yToValue(m_curve, posF.y());
|
|
Shinya Kitaoka |
120a6e |
TPointD handlePos(frame - m_keyframe.m_frame, value - m_keyframe.m_value);
|
|
Shinya Kitaoka |
120a6e |
switch (m_handle) {
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::SpeedIn:
|
|
Shinya Kitaoka |
120a6e |
if (m_keyframe.m_type != TDoubleKeyframe::SpeedInOut) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_setter.setSpeedIn(handlePos);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::SpeedOut:
|
|
Shinya Kitaoka |
120a6e |
m_setter.setSpeedOut(handlePos);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseIn:
|
|
Shinya Kitaoka |
120a6e |
m_setter.setEaseIn(handlePos.x);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseOut:
|
|
Shinya Kitaoka |
120a6e |
m_setter.setEaseOut(handlePos.x);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseInPercentage:
|
|
Shinya Kitaoka |
120a6e |
if (m_segmentWidth > 0)
|
|
Shinya Kitaoka |
120a6e |
m_setter.setEaseIn(100.0 * handlePos.x / m_segmentWidth);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseOutPercentage:
|
|
Shinya Kitaoka |
120a6e |
if (m_segmentWidth > 0)
|
|
Shinya Kitaoka |
120a6e |
m_setter.setEaseOut(100.0 * handlePos.x / m_segmentWidth);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case 100:
|
|
Shinya Kitaoka |
120a6e |
case 101:
|
|
Shinya Kitaoka |
120a6e |
case 102:
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
default:
|
|
Shinya Kitaoka |
120a6e |
assert(0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_panel->update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MoveHandleDragTool::release(QMouseEvent *e) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MoveGroupHandleDragTool::MoveGroupHandleDragTool(FunctionPanel *panel,
|
|
Shinya Kitaoka |
120a6e |
double keyframePosition,
|
|
Shinya Kitaoka |
120a6e |
Handle handle)
|
|
Shinya Kitaoka |
120a6e |
: m_panel(panel), m_keyframePosition(keyframePosition), m_handle(handle) {
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->beginBlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MoveGroupHandleDragTool::~MoveGroupHandleDragTool() {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) delete m_setters[i].second;
|
|
Shinya Kitaoka |
120a6e |
m_setters.clear();
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->endBlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MoveGroupHandleDragTool::click(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) delete m_setters[i].second;
|
|
Shinya Kitaoka |
120a6e |
m_setters.clear();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FunctionTreeModel *model = m_panel->getModel();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < model->getActiveChannelCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
FunctionTreeModel::Channel *channel = model->getActiveChannel(i);
|
|
Shinya Kitaoka |
120a6e |
if (channel && channel->getParam()) {
|
|
Shinya Kitaoka |
120a6e |
TDoubleParam *curve = channel->getParam();
|
|
Shinya Kitaoka |
120a6e |
int kIndex = curve->getClosestKeyframe(m_keyframePosition);
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = new KeyframeSetter(curve, kIndex);
|
|
Shinya Kitaoka |
120a6e |
setter->setPixelRatio(m_panel->getPixelRatio(curve));
|
|
Shinya Kitaoka |
120a6e |
TDoubleKeyframe kf = curve->getKeyframe(kIndex);
|
|
Shinya Kitaoka |
120a6e |
m_setters.push_back(std::make_pair(kf, setter));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MoveGroupHandleDragTool::drag(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
// if(!m_curve) return;
|
|
Shinya Kitaoka |
120a6e |
QPoint pos = e->pos();
|
|
Shinya Kitaoka |
120a6e |
QPointF posF(pos);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(m_nSpeed != QPointF(0,0))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
QPointF delta = posF-p0;
|
|
Shinya Kitaoka |
120a6e |
posF -= m_nSpeed*(delta.x()*m_nSpeed.x()+delta.y()*m_nSpeed.y());
|
|
Shinya Kitaoka |
120a6e |
if( m_handle == FunctionPanel::SpeedIn && posF.x()>p0.x()
|
|
Shinya Kitaoka |
120a6e |
|| m_handle == FunctionPanel::SpeedOut && posF.x()
|
|
Shinya Kitaoka |
120a6e |
posF = p0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
if( m_handle == FunctionPanel::SpeedIn && posF.x()>p0.x()
|
|
Shinya Kitaoka |
120a6e |
|| m_handle == FunctionPanel::SpeedOut && posF.x()
|
|
Shinya Kitaoka |
120a6e |
posF.setX(p0.x());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double frame = m_panel->xToFrame(posF.x());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TDoubleKeyframe kf = m_setters[i].first;
|
|
Shinya Kitaoka |
120a6e |
KeyframeSetter *setter = m_setters[i].second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_handle == 101) // why the magic numbers... use enums!
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
kf.m_speedOut.x = frame - kf.m_frame;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
switch (kf.m_type) {
|
|
Shinya Kitaoka |
120a6e |
case TDoubleKeyframe::SpeedInOut:
|
|
Shinya Kitaoka |
120a6e |
setter->setSpeedOut(kf.m_speedOut);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case TDoubleKeyframe::EaseInOut:
|
|
Shinya Kitaoka |
120a6e |
setter->setEaseOut(kf.m_speedOut.x);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
default:
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else if (m_handle == 102) // aagghhrrr
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
kf.m_speedIn.x = frame - kf.m_frame;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
switch (kf.m_prevType) {
|
|
Shinya Kitaoka |
120a6e |
case TDoubleKeyframe::SpeedInOut:
|
|
Shinya Kitaoka |
120a6e |
setter->setSpeedIn(kf.m_speedIn);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case TDoubleKeyframe::EaseInOut:
|
|
Shinya Kitaoka |
120a6e |
setter->setEaseIn(kf.m_speedIn.x);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
default:
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
switch(m_handle)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::SpeedIn:
|
|
Shinya Kitaoka |
120a6e |
if(m_keyframe.m_type != TDoubleKeyframe::SpeedInOut)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_setter.setSpeedIn(handlePos);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::SpeedOut:m_setter.setSpeedOut(handlePos); break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseIn:m_setter.setEaseIn(handlePos.x); break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseOut:m_setter.setEaseOut(handlePos.x); break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseInPercentage:
|
|
Shinya Kitaoka |
120a6e |
if(m_segmentWidth>0)
|
|
Shinya Kitaoka |
120a6e |
m_setter.setEaseIn(100.0*handlePos.x/m_segmentWidth);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case FunctionPanel::EaseOutPercentage:
|
|
Shinya Kitaoka |
120a6e |
if(m_segmentWidth>0)
|
|
Shinya Kitaoka |
120a6e |
m_setter.setEaseOut(100.0*handlePos.x/m_segmentWidth);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case 100:
|
|
Shinya Kitaoka |
120a6e |
case 101:
|
|
Shinya Kitaoka |
120a6e |
case 102:
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
default:assert(0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
m_panel->update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MoveGroupHandleDragTool::release(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)m_setters.size(); i++) delete m_setters[i].second;
|
|
Shinya Kitaoka |
120a6e |
m_setters.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|