|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "keyframemover.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Tnz6 includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tapp.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "xsheetviewer.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
9f6fb4 |
// TnzQt includes
|
|
shun_iwasawa |
9f6fb4 |
#include "historytypes.h"
|
|
shun_iwasawa |
9f6fb4 |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tscenehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheet.h"
|
|
manongjohn |
8fd04a |
#include "toonz/preferences.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 |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// KeyframeMover
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
KeyframeMover::KeyframeMover()
|
|
Shinya Kitaoka |
120a6e |
: m_qualifiers(eMoveKeyframes), m_lastKeyframeData(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
KeyframeMover::~KeyframeMover() {
|
|
Shinya Kitaoka |
120a6e |
delete m_lastKeyframeData;
|
|
Shinya Kitaoka |
120a6e |
m_lastKeyframeData = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TXsheet *KeyframeMover::getXsheet() const {
|
|
Shinya Kitaoka |
120a6e |
return TApp::instance()->getCurrentXsheet()->getXsheet();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMover::setKeyframes() {
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsh = getXsheet();
|
|
Shinya Kitaoka |
120a6e |
std::set<keyframeposition>::iterator posIt;</keyframeposition>
|
|
Shinya Kitaoka |
120a6e |
for (auto const &key : m_lastKeyframes) {
|
|
Shinya Kitaoka |
120a6e |
int c = key.second;
|
|
Shinya Kitaoka |
120a6e |
TStageObjectId objId =
|
|
John Dancel |
c323ac |
c >= 0 ? TStageObjectId::ColumnId(c)
|
|
John Dancel |
c323ac |
: TStageObjectId::CameraId(xsh->getCameraColumnIndex());
|
|
Shinya Kitaoka |
120a6e |
TStageObject *stObj = xsh->getStageObject(objId);
|
|
Shinya Kitaoka |
120a6e |
TStageObject::KeyframeMap keyframes;
|
|
Shinya Kitaoka |
120a6e |
stObj->getKeyframes(keyframes);
|
|
Shinya Kitaoka |
120a6e |
for (auto const &frame : keyframes) {
|
|
Shinya Kitaoka |
120a6e |
stObj->removeKeyframeWithoutUndo(frame.first);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_lastKeyframeData->getKeyframes(m_lastKeyframes, xsh);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMover::getKeyframes() {
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsh = getXsheet();
|
|
Shinya Kitaoka |
120a6e |
for (auto const &pos : m_startSelectedKeyframes) {
|
|
Shinya Kitaoka |
120a6e |
int c = pos.second;
|
|
Shinya Kitaoka |
120a6e |
TStageObjectId objId =
|
|
John Dancel |
c323ac |
c >= 0 ? TStageObjectId::ColumnId(c)
|
|
John Dancel |
c323ac |
: TStageObjectId::CameraId(xsh->getCameraColumnIndex());
|
|
Shinya Kitaoka |
120a6e |
TStageObject *stObj = xsh->getStageObject(objId);
|
|
Shinya Kitaoka |
120a6e |
assert(stObj->isKeyframe(pos.first));
|
|
Shinya Kitaoka |
120a6e |
TStageObject::KeyframeMap keyframes;
|
|
Shinya Kitaoka |
120a6e |
stObj->getKeyframes(keyframes);
|
|
Shinya Kitaoka |
120a6e |
for (auto const &frame : keyframes) {
|
|
Shinya Kitaoka |
120a6e |
m_lastKeyframes.insert(KeyframePosition(frame.first, c));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_lastKeyframeData) {
|
|
Shinya Kitaoka |
120a6e |
delete m_lastKeyframeData;
|
|
Shinya Kitaoka |
120a6e |
m_lastKeyframeData = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_lastKeyframeData = new TKeyframeData();
|
|
Shinya Kitaoka |
120a6e |
m_lastKeyframeData->setKeyframes(m_lastKeyframes, xsh);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMover::start(TKeyframeSelection *selection, int qualifiers) {
|
|
Shinya Kitaoka |
120a6e |
selection->unselectLockedColumn();
|
|
Shinya Kitaoka |
120a6e |
m_qualifiers = qualifiers;
|
|
Shinya Kitaoka |
120a6e |
std::set<tkeyframeselection::position> positions = selection->getSelection();</tkeyframeselection::position>
|
|
Shinya Kitaoka |
120a6e |
m_startSelectedKeyframes = positions;
|
|
Shinya Kitaoka |
120a6e |
getKeyframes();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
// If can't move keyframe return false; otherwise move keyframe
|
|
Shinya Kitaoka |
120a6e |
bool KeyframeMover::moveKeyframes(
|
|
Shinya Kitaoka |
120a6e |
int dr, std::set<tkeyframeselection::position> &newPositions,</tkeyframeselection::position>
|
|
Shinya Kitaoka |
120a6e |
TKeyframeSelection *selection) {
|
|
shun-iwasawa |
62f1df |
// return if there is no movement
|
|
shun-iwasawa |
62f1df |
if (dr == 0) return false;
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsh = getXsheet();
|
|
Shinya Kitaoka |
120a6e |
std::set<tkeyframeselection::position> positions;</tkeyframeselection::position>
|
|
Shinya Kitaoka |
120a6e |
if (selection)
|
|
Shinya Kitaoka |
120a6e |
positions = selection->getSelection();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
positions = m_startSelectedKeyframes;
|
|
Shinya Kitaoka |
120a6e |
if (positions.empty()) return false;
|
|
Shinya Kitaoka |
120a6e |
std::set<tkeyframeselection::position>::iterator posIt;</tkeyframeselection::position>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_qualifiers & eMoveKeyframes) {
|
|
Shinya Kitaoka |
120a6e |
for (posIt = positions.begin(); posIt != positions.end(); ++posIt) {
|
|
Shinya Kitaoka |
120a6e |
int c = posIt->second;
|
|
Shinya Kitaoka |
120a6e |
int r = posIt->first;
|
|
Shinya Kitaoka |
120a6e |
TStageObjectId objId =
|
|
John Dancel |
c323ac |
c >= 0 ? TStageObjectId::ColumnId(c)
|
|
John Dancel |
c323ac |
: TStageObjectId::CameraId(xsh->getCameraColumnIndex());
|
|
Shinya Kitaoka |
120a6e |
TStageObject *stObj = xsh->getStageObject(objId);
|
|
shun-iwasawa |
62f1df |
if (r + dr < 0) {
|
|
shun-iwasawa |
62f1df |
dr = -r;
|
|
shun-iwasawa |
62f1df |
// dragging backward stops when the selection reaches the first frame
|
|
shun-iwasawa |
62f1df |
if (dr == 0) return false;
|
|
shun-iwasawa |
62f1df |
}
|
|
shun-iwasawa |
62f1df |
if (stObj->isKeyframe(r + dr)) {
|
|
shun-iwasawa |
62f1df |
if (m_qualifiers & eCopyKeyframes) return false;
|
|
shun-iwasawa |
62f1df |
// occupying key may be dragged one which is to be moved out
|
|
shun-iwasawa |
62f1df |
else if (positions.count(TKeyframeSelection::Position(r + dr, c)) == 0)
|
|
shun-iwasawa |
62f1df |
return false;
|
|
shun-iwasawa |
62f1df |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool firstTime = false;
|
|
shun-iwasawa |
62f1df |
|
|
shun-iwasawa |
62f1df |
// move keys from the end of the selection on dragging forward
|
|
shun-iwasawa |
62f1df |
if (dr > 0) {
|
|
shun-iwasawa |
62f1df |
for (std::set<tkeyframeselection::position>::reverse_iterator revIt =</tkeyframeselection::position>
|
|
shun-iwasawa |
62f1df |
positions.rbegin();
|
|
shun-iwasawa |
62f1df |
revIt != positions.rend(); ++revIt) {
|
|
shun-iwasawa |
62f1df |
int c = revIt->second;
|
|
shun-iwasawa |
62f1df |
int r = revIt->first;
|
|
shun-iwasawa |
62f1df |
TStageObjectId objId =
|
|
John Dancel |
c323ac |
c >= 0 ? TStageObjectId::ColumnId(c)
|
|
John Dancel |
c323ac |
: TStageObjectId::CameraId(xsh->getCameraColumnIndex());
|
|
shun-iwasawa |
62f1df |
TStageObject *stObj = xsh->getStageObject(objId);
|
|
shun-iwasawa |
62f1df |
if (m_qualifiers & eCopyKeyframes) {
|
|
shun-iwasawa |
62f1df |
firstTime = true;
|
|
shun-iwasawa |
62f1df |
stObj->setKeyframeWithoutUndo(r + dr, stObj->getKeyframe(r));
|
|
shun-iwasawa |
62f1df |
} else
|
|
shun-iwasawa |
62f1df |
stObj->moveKeyframe(r + dr, r);
|
|
shun-iwasawa |
62f1df |
newPositions.insert(TKeyframeSelection::Position(r + dr, c));
|
|
shun-iwasawa |
62f1df |
}
|
|
shun-iwasawa |
62f1df |
} else { // ... and vice versa
|
|
shun-iwasawa |
62f1df |
for (posIt = positions.begin(); posIt != positions.end(); ++posIt) {
|
|
shun-iwasawa |
62f1df |
int c = posIt->second;
|
|
shun-iwasawa |
62f1df |
int r = posIt->first;
|
|
shun-iwasawa |
62f1df |
TStageObjectId objId =
|
|
John Dancel |
c323ac |
c >= 0 ? TStageObjectId::ColumnId(c)
|
|
John Dancel |
c323ac |
: TStageObjectId::CameraId(xsh->getCameraColumnIndex());
|
|
shun-iwasawa |
62f1df |
TStageObject *stObj = xsh->getStageObject(objId);
|
|
shun-iwasawa |
62f1df |
if (m_qualifiers & eCopyKeyframes) {
|
|
shun-iwasawa |
62f1df |
firstTime = true;
|
|
shun-iwasawa |
62f1df |
stObj->setKeyframeWithoutUndo(r + dr, stObj->getKeyframe(r));
|
|
shun-iwasawa |
62f1df |
} else
|
|
shun-iwasawa |
62f1df |
stObj->moveKeyframe(r + dr, r);
|
|
shun-iwasawa |
62f1df |
newPositions.insert(TKeyframeSelection::Position(r + dr, c));
|
|
shun-iwasawa |
62f1df |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (firstTime) {
|
|
Shinya Kitaoka |
120a6e |
m_qualifiers = 0;
|
|
Shinya Kitaoka |
120a6e |
m_qualifiers = eMoveKeyframes;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
setKeyframes();
|
|
Shinya Kitaoka |
120a6e |
bool notChange = false;
|
|
Shinya Kitaoka |
120a6e |
for (posIt = m_startSelectedKeyframes.begin();
|
|
Shinya Kitaoka |
120a6e |
posIt != m_startSelectedKeyframes.end(); ++posIt) {
|
|
Shinya Kitaoka |
120a6e |
int c = posIt->second;
|
|
Shinya Kitaoka |
120a6e |
int r = posIt->first;
|
|
Shinya Kitaoka |
120a6e |
TStageObjectId objId =
|
|
John Dancel |
c323ac |
c >= 0 ? TStageObjectId::ColumnId(c)
|
|
John Dancel |
c323ac |
: TStageObjectId::CameraId(xsh->getCameraColumnIndex());
|
|
Shinya Kitaoka |
120a6e |
TStageObject *stObj = xsh->getStageObject(objId);
|
|
Shinya Kitaoka |
120a6e |
if (r + dr < 0) dr = -r;
|
|
Shinya Kitaoka |
120a6e |
if (dr == 0) notChange = true;
|
|
Shinya Kitaoka |
120a6e |
newPositions.insert(TKeyframeSelection::Position(r, c));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (notChange) return true;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
newPositions.clear();
|
|
Shinya Kitaoka |
120a6e |
for (posIt = m_startSelectedKeyframes.begin();
|
|
Shinya Kitaoka |
120a6e |
posIt != m_startSelectedKeyframes.end(); ++posIt) {
|
|
Shinya Kitaoka |
120a6e |
int c = posIt->second;
|
|
Shinya Kitaoka |
120a6e |
int r = posIt->first;
|
|
Shinya Kitaoka |
120a6e |
TStageObjectId objId =
|
|
John Dancel |
c323ac |
c >= 0 ? TStageObjectId::ColumnId(c)
|
|
John Dancel |
c323ac |
: TStageObjectId::CameraId(xsh->getCameraColumnIndex());
|
|
Shinya Kitaoka |
120a6e |
TStageObject *stObj = xsh->getStageObject(objId);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_qualifiers & eOverwriteKeyframes) {
|
|
Shinya Kitaoka |
120a6e |
stObj->removeKeyframeWithoutUndo(r + dr);
|
|
Shinya Kitaoka |
120a6e |
if (m_qualifiers & eCopyKeyframes)
|
|
Shinya Kitaoka |
120a6e |
stObj->setKeyframeWithoutUndo(r + dr, stObj->getKeyframe(r));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
stObj->moveKeyframe(r + dr, r);
|
|
Shinya Kitaoka |
120a6e |
newPositions.insert(TKeyframeSelection::Position(r + dr, c));
|
|
Shinya Kitaoka |
120a6e |
} else if (m_qualifiers & eInsertKeyframes) {
|
|
Shinya Kitaoka |
120a6e |
int s = r;
|
|
Shinya Kitaoka |
120a6e |
TStageObject::Keyframe keyframe = stObj->getKeyframe(r);
|
|
Rozhuk Ivan |
823a31 |
if (!(m_qualifiers & eCopyKeyframes)) stObj->removeKeyframeWithoutUndo(r);
|
|
Shinya Kitaoka |
120a6e |
std::set<int> keyframeToShift;</int>
|
|
Shinya Kitaoka |
120a6e |
while (stObj->isKeyframe(s + dr) && s + dr != r) {
|
|
Shinya Kitaoka |
120a6e |
keyframeToShift.insert(s + dr);
|
|
Shinya Kitaoka |
120a6e |
s++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
stObj->moveKeyframes(keyframeToShift, 1);
|
|
Shinya Kitaoka |
120a6e |
stObj->setKeyframeWithoutUndo(r + dr, keyframe);
|
|
Shinya Kitaoka |
120a6e |
newPositions.insert(TKeyframeSelection::Position(r + dr, c));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// UndoMoveKeyFrame
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class UndoMoveKeyFrame final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
int m_dr;
|
|
Shinya Kitaoka |
120a6e |
KeyframeMover *m_mover;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
UndoMoveKeyFrame(int dr, KeyframeMover *mover) : m_dr(dr), m_mover(mover) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
m_mover->undoMoveKeyframe();
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
std::set<tkeyframeselection::position> newPositions;</tkeyframeselection::position>
|
|
Shinya Kitaoka |
120a6e |
m_mover->moveKeyframes(m_dr, newPositions);
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override { return QObject::tr("Move Keyframe"); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Xsheet; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// KeyframeMoverTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
KeyframeMoverTool::KeyframeMoverTool(XsheetViewer *viewer, bool justMovement)
|
|
Shinya Kitaoka |
120a6e |
: XsheetGUI::DragTool(viewer)
|
|
Shinya Kitaoka |
120a6e |
, m_startSelection()
|
|
Shinya Kitaoka |
120a6e |
, m_offset(0)
|
|
Shinya Kitaoka |
120a6e |
, m_firstRow(0)
|
|
Shinya Kitaoka |
120a6e |
, m_selecting(false)
|
|
Shinya Kitaoka |
120a6e |
, m_startPos()
|
|
Shinya Kitaoka |
120a6e |
, m_curPos()
|
|
Shinya Kitaoka |
120a6e |
, m_firstKeyframeMovement(false)
|
|
Shinya Kitaoka |
120a6e |
, m_justMovement(justMovement) {
|
|
manongjohn |
8fd04a |
m_mover = new KeyframeMover();
|
|
manongjohn |
3fe913 |
m_firstCol = Preferences::instance()->isXsheetCameraColumnVisible() ? -1 : 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TKeyframeSelection *KeyframeMoverTool::getSelection() {
|
|
Shinya Kitaoka |
120a6e |
return getViewer()->getKeyframeSelection();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMoverTool::ctrlSelect(int row, int col) {
|
|
Shinya Kitaoka |
120a6e |
TKeyframeSelection *selection = getSelection();
|
|
Shinya Kitaoka |
120a6e |
bool isSelected = selection->isSelected(row, col);
|
|
Shinya Kitaoka |
120a6e |
if (isSelected)
|
|
Shinya Kitaoka |
120a6e |
selection->unselect(row, col);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
selection->select(row, col);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMoverTool::shiftSelect(int row, int col) {
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsh = getViewer()->getXsheet();
|
|
Shinya Kitaoka |
120a6e |
int r0 = 0, c0 = 0, r1 = -1, c1 = -1;
|
|
manongjohn |
8fd04a |
int c = 0;
|
|
manongjohn |
3fe913 |
if (Preferences::instance()->isXsheetCameraColumnVisible()) {
|
|
manongjohn |
8fd04a |
c0--;
|
|
manongjohn |
8fd04a |
c1--;
|
|
manongjohn |
8fd04a |
c--;
|
|
manongjohn |
8fd04a |
}
|
|
manongjohn |
8fd04a |
for (; c < xsh->getColumnCount(); c++) {
|
|
Shinya Kitaoka |
120a6e |
TStageObject *obj = xsh->getStageObject(getViewer()->getObjectId(c));
|
|
Shinya Kitaoka |
120a6e |
int ra, rb;
|
|
Shinya Kitaoka |
120a6e |
obj->getKeyframeRange(ra, rb);
|
|
Shinya Kitaoka |
120a6e |
for (int r = ra; r <= rb; r++) {
|
|
Shinya Kitaoka |
120a6e |
if (getSelection()->isSelected(r, c)) {
|
|
Shinya Kitaoka |
120a6e |
if (r0 > r1)
|
|
Shinya Kitaoka |
120a6e |
r0 = r1 = r;
|
|
Shinya Kitaoka |
120a6e |
else if (r < r0)
|
|
Shinya Kitaoka |
120a6e |
r0 = r;
|
|
Shinya Kitaoka |
120a6e |
else if (r > r1)
|
|
Shinya Kitaoka |
120a6e |
r1 = r;
|
|
Shinya Kitaoka |
120a6e |
if (c0 > c1)
|
|
Shinya Kitaoka |
120a6e |
c0 = c1 = c;
|
|
Shinya Kitaoka |
120a6e |
else if (c < c0)
|
|
Shinya Kitaoka |
120a6e |
c0 = c;
|
|
Shinya Kitaoka |
120a6e |
else if (c > c1)
|
|
Shinya Kitaoka |
120a6e |
c1 = c;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (row >= r0 && col >= c0) {
|
|
Shinya Kitaoka |
120a6e |
r1 = row;
|
|
Shinya Kitaoka |
120a6e |
c1 = col;
|
|
Shinya Kitaoka |
120a6e |
} else if (row <= r1 && col <= c1) {
|
|
Shinya Kitaoka |
120a6e |
r0 = row;
|
|
Shinya Kitaoka |
120a6e |
c0 = col;
|
|
Shinya Kitaoka |
120a6e |
} else if (col <= c0) {
|
|
Shinya Kitaoka |
120a6e |
c0 = col;
|
|
Shinya Kitaoka |
120a6e |
r1 = row;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
c1 = col;
|
|
Shinya Kitaoka |
120a6e |
r0 = row;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int c = c0; c <= c1; c++) {
|
|
Shinya Kitaoka |
120a6e |
TStageObject *obj = xsh->getStageObject(getViewer()->getObjectId(c));
|
|
Shinya Kitaoka |
120a6e |
for (int r = r0; r <= r1; r++)
|
|
Shinya Kitaoka |
120a6e |
if (obj->isKeyframe(r)) getSelection()->select(r, c);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMoverTool::rectSelect(int row, int col) {
|
|
Shinya Kitaoka |
120a6e |
TKeyframeSelection *selection = getSelection();
|
|
Shinya Kitaoka |
120a6e |
selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsh = getViewer()->getXsheet();
|
|
Shinya Kitaoka |
120a6e |
int r0 = row, c0 = col, r1 = m_firstRow, c1 = m_firstCol;
|
|
otakuto |
ed7dcd |
if (r0 > r1) std::swap(r0, r1);
|
|
otakuto |
ed7dcd |
if (c0 > c1) std::swap(c0, c1);
|
|
Shinya Kitaoka |
120a6e |
for (int c = c0; c <= c1; c++) {
|
|
Shinya Kitaoka |
120a6e |
TStageObject *obj = xsh->getStageObject(getViewer()->getObjectId(c));
|
|
Shinya Kitaoka |
120a6e |
for (int r = r0; r <= r1; r++) {
|
|
Shinya Kitaoka |
120a6e |
if (obj->isKeyframe(r)) selection->select(r, c);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_startSelection = *getSelection();
|
|
Shinya Kitaoka |
120a6e |
refreshCellsArea();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool KeyframeMoverTool::canMove(const TPoint &pos) {
|
|
manongjohn |
dff49a |
const Orientation *o = getViewer()->orientation();
|
|
manongjohn |
dff49a |
TXsheet *xsh = getViewer()->getXsheet();
|
|
manongjohn |
dff49a |
|
|
manongjohn |
dff49a |
TPoint usePos = pos;
|
|
manongjohn |
dff49a |
if (!o->isVerticalTimeline()) {
|
|
manongjohn |
dff49a |
usePos.x = pos.y;
|
|
manongjohn |
dff49a |
usePos.y = pos.x;
|
|
manongjohn |
dff49a |
}
|
|
manongjohn |
dff49a |
|
|
manongjohn |
dff49a |
if (usePos.x < 0) return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
manongjohn |
dff49a |
int col = usePos.x;
|
|
Jaroslav |
203cc8 |
int startCol = getViewer()->xyToPosition(m_startPos).layer();
|
|
Shinya Kitaoka |
120a6e |
if (col != startCol) return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMoverTool::onCellChange(int row, int col) {
|
|
Shinya Kitaoka |
120a6e |
int lastRow = getSelection()->getFirstRow() + m_offset;
|
|
Shinya Kitaoka |
120a6e |
int firstRow = m_startSelection.getFirstRow() + m_offset;
|
|
Shinya Kitaoka |
120a6e |
int dr = row - lastRow;
|
|
Shinya Kitaoka |
120a6e |
int dfr = row - firstRow;
|
|
Shinya Kitaoka |
120a6e |
int d = (m_mover->getQualifiers() & KeyframeMover::eMoveKeyframes) ? dr : dfr;
|
|
Shinya Kitaoka |
120a6e |
std::set<tkeyframeselection::position> newPositions;</tkeyframeselection::position>
|
|
Shinya Kitaoka |
120a6e |
bool ret = m_mover->moveKeyframes(d, newPositions, getSelection());
|
|
Shinya Kitaoka |
120a6e |
if (!ret) return;
|
|
Shinya Kitaoka |
120a6e |
getSelection()->m_positions.clear();
|
|
Shinya Kitaoka |
120a6e |
getSelection()->m_positions.swap(newPositions);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMoverTool::onClick(const QMouseEvent *event) {
|
|
Jaroslav |
203cc8 |
m_firstKeyframeMovement = true;
|
|
Jaroslav |
203cc8 |
m_selecting = false;
|
|
Jaroslav |
203cc8 |
TXsheet *xsheet = getViewer()->getXsheet();
|
|
Jaroslav |
203cc8 |
CellPosition cellPosition = getViewer()->xyToPosition(event->pos());
|
|
Jaroslav |
203cc8 |
int row = cellPosition.frame();
|
|
Jaroslav |
203cc8 |
int col = cellPosition.layer();
|
|
Jaroslav |
203cc8 |
m_firstRow = row;
|
|
Jaroslav |
203cc8 |
m_firstCol = col;
|
|
Jaroslav |
203cc8 |
bool isSelected = getSelection()->isSelected(row, col);
|
|
Shinya Kitaoka |
120a6e |
if (!m_justMovement) {
|
|
Shinya Kitaoka |
120a6e |
if (event->modifiers() & Qt::ControlModifier)
|
|
Shinya Kitaoka |
120a6e |
ctrlSelect(row, col);
|
|
Shinya Kitaoka |
120a6e |
else if (event->modifiers() & Qt::ShiftModifier)
|
|
Shinya Kitaoka |
120a6e |
shiftSelect(row, col);
|
|
Shinya Kitaoka |
120a6e |
else if (!isSelected) {
|
|
Shinya Kitaoka |
120a6e |
getSelection()->selectNone();
|
|
Shinya Kitaoka |
120a6e |
getSelection()->select(row, col);
|
|
Shinya Kitaoka |
120a6e |
m_selecting = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
getSelection()->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (!getSelection()->isEmpty())
|
|
Shinya Kitaoka |
120a6e |
m_offset = row - getSelection()->getFirstRow();
|
|
Shinya Kitaoka |
120a6e |
m_startSelection = *getSelection();
|
|
Shinya Kitaoka |
120a6e |
getViewer()->update();
|
|
Shinya Kitaoka |
120a6e |
m_startPos = TPointD(event->pos().x(), event->pos().y());
|
|
Shinya Kitaoka |
120a6e |
m_curPos = m_startPos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMoverTool::onDrag(const QMouseEvent *e) {
|
|
Jaroslav |
203cc8 |
int x = e->pos().x();
|
|
Jaroslav |
203cc8 |
int y = e->pos().y();
|
|
Jaroslav |
203cc8 |
m_curPos = TPointD(x, y);
|
|
Jaroslav |
203cc8 |
CellPosition cellPosition = getViewer()->xyToPosition(e->pos());
|
|
Jaroslav |
203cc8 |
int row = cellPosition.frame();
|
|
Jaroslav |
203cc8 |
int col = cellPosition.layer();
|
|
Shinya Kitaoka |
120a6e |
if (m_selecting)
|
|
Shinya Kitaoka |
120a6e |
rectSelect(row, col);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
if (m_firstKeyframeMovement) {
|
|
Shinya Kitaoka |
120a6e |
int qualifiers = 0;
|
|
Shinya Kitaoka |
120a6e |
if (e->modifiers() & Qt::ControlModifier)
|
|
Shinya Kitaoka |
120a6e |
qualifiers |= KeyframeMover::eCopyKeyframes;
|
|
Shinya Kitaoka |
120a6e |
if (e->modifiers() & Qt::ShiftModifier)
|
|
Shinya Kitaoka |
120a6e |
qualifiers |= KeyframeMover::eInsertKeyframes;
|
|
Shinya Kitaoka |
120a6e |
else if (e->modifiers() & Qt::AltModifier)
|
|
Shinya Kitaoka |
120a6e |
qualifiers |= KeyframeMover::eOverwriteKeyframes;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
qualifiers |= KeyframeMover::eMoveKeyframes;
|
|
Shinya Kitaoka |
120a6e |
m_mover->start(getSelection(), qualifiers);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_firstKeyframeMovement = false;
|
|
Shinya Kitaoka |
120a6e |
onCellChange(row, col);
|
|
Shinya Kitaoka |
120a6e |
refreshCellsArea();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jaroslav |
203cc8 |
void KeyframeMoverTool::onRelease(const CellPosition &pos) {
|
|
Shinya Kitaoka |
120a6e |
if (m_selecting) {
|
|
Shinya Kitaoka |
120a6e |
m_selecting = false;
|
|
Shinya Kitaoka |
120a6e |
getViewer()->updateCells();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_offset = 0;
|
|
Shinya Kitaoka |
120a6e |
int dr = getSelection()->getFirstRow() - m_startSelection.getFirstRow();
|
|
Shinya Kitaoka |
120a6e |
if (dr) {
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new UndoMoveKeyFrame(dr, m_mover));
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentScene()->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void KeyframeMoverTool::drawCellsArea(QPainter &p) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_selecting) return;
|
|
Shinya Kitaoka |
120a6e |
QPen pen(Qt::DashLine);
|
|
Shinya Kitaoka |
120a6e |
pen.setColor(Qt::black);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(pen);
|
|
Shinya Kitaoka |
120a6e |
double endRectPosX = m_curPos.x - m_startPos.x;
|
|
Shinya Kitaoka |
120a6e |
double endRectPosY = m_curPos.y - m_startPos.y;
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(m_startPos.x, m_startPos.y, endRectPosX, endRectPosY);
|
|
Toshihiro Shimizu |
890ddd |
}
|