From c323acf64c9b7efb48a43098016a75a845df8ca1 Mon Sep 17 00:00:00 2001 From: John Dancel Date: Mar 26 2019 10:21:46 +0000 Subject: Select camera with Camera Column Config button --- diff --git a/toonz/sources/include/toonz/tcolumnhandle.h b/toonz/sources/include/toonz/tcolumnhandle.h index 277c1d5..3cd2154 100644 --- a/toonz/sources/include/toonz/tcolumnhandle.h +++ b/toonz/sources/include/toonz/tcolumnhandle.h @@ -39,6 +39,7 @@ public: int getColumnIndex() const { return m_columnIndex; } void setColumnIndex(int index); + void notifyColumnIndexSwitched() { emit columnIndexSwitched(); } signals: void columnIndexSwitched(); diff --git a/toonz/sources/include/toonz/txsheet.h b/toonz/sources/include/toonz/txsheet.h index b7ee655..3268d02 100644 --- a/toonz/sources/include/toonz/txsheet.h +++ b/toonz/sources/include/toonz/txsheet.h @@ -156,6 +156,8 @@ private: TXshNoteSet *m_notes; SoundProperties *m_soundProperties; + int m_cameraColumnIndex; + DECLARE_CLASS_CODE public: @@ -557,6 +559,9 @@ in TXsheetImp. std::vector columnIndices, std::vector levels, int rowsCount); + void setCameraColumnIndex(int index) { m_cameraColumnIndex = index; } + int getCameraColumnIndex() { return m_cameraColumnIndex; } + protected: bool checkCircularReferences(TXsheet *childCandidate); diff --git a/toonz/sources/include/toonz/txsheethandle.h b/toonz/sources/include/toonz/txsheethandle.h index 12e5723..d851017 100644 --- a/toonz/sources/include/toonz/txsheethandle.h +++ b/toonz/sources/include/toonz/txsheethandle.h @@ -38,11 +38,13 @@ public: void notifyXsheetChanged() { emit xsheetChanged(); } void notifyXsheetSwitched() { emit xsheetSwitched(); } void notifyXsheetSoundChanged() { emit xsheetSoundChanged(); } + void changeXsheetCamera(int index) { emit xsheetCameraChange(index); } signals: void xsheetSwitched(); void xsheetChanged(); void xsheetSoundChanged(); + void xsheetCameraChange(int); }; #endif // TXSHEETHANDLE_H diff --git a/toonz/sources/tnztools/edittool.cpp b/toonz/sources/tnztools/edittool.cpp index 7319066..1e62f3d 100644 --- a/toonz/sources/tnztools/edittool.cpp +++ b/toonz/sources/tnztools/edittool.cpp @@ -1417,7 +1417,7 @@ void EditTool::draw() { tglColor(normalColor); glPushMatrix(); TStageObjectId currentCamId = - xsh->getStageObjectTree()->getCurrentCameraId(); + TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TAffine camParentAff = xsh->getParentPlacement(currentCamId, frame); TAffine camAff = xsh->getPlacement(currentCamId, frame); tglMultMatrix(camParentAff.inv() * @@ -1553,9 +1553,12 @@ m_foo.setFxHandle(getApplication()->getCurrentFx()); TStageObjectId objId = getObjectId(); if (objId == TStageObjectId::NoneId) { - int index = getColumnIndex(); - if (index == -1) objId = TStageObjectId::CameraId(0); - objId = TStageObjectId::ColumnId(index); + int index = getColumnIndex(); + TXsheet *xsh = TTool::getApplication()->getCurrentXsheet()->getXsheet(); + if (index == -1) + objId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); + else + objId = TStageObjectId::ColumnId(index); } TTool::getApplication()->getCurrentObject()->setObjectId(objId); } diff --git a/toonz/sources/tnztools/edittoolgadgets.cpp b/toonz/sources/tnztools/edittoolgadgets.cpp index 8dc24e5..3fb6f5d 100644 --- a/toonz/sources/tnztools/edittoolgadgets.cpp +++ b/toonz/sources/tnztools/edittoolgadgets.cpp @@ -1128,7 +1128,8 @@ void FxGadgetController::onFxSwitched() { if (referenceColumnIndex == -1) { TObjectHandle *oh = m_tool->getApplication()->getCurrentObject(); if (!oh->getObjectId().isCamera()) { - oh->setObjectId(TStageObjectId::CameraId(0)); + TXsheet *xsh = m_tool->getXsheet(); + oh->setObjectId(TStageObjectId::CameraId(xsh->getCameraColumnIndex())); } enabled = true; } else if (referenceColumnIndex == m_tool->getColumnIndex()) diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp index 3a0a997..b49b4cc 100644 --- a/toonz/sources/tnztools/tooloptions.cpp +++ b/toonz/sources/tnztools/tooloptions.cpp @@ -124,7 +124,8 @@ ToolOptionsBox::ToolOptionsBox(QWidget *parent, bool isScrollable) ToolOptionsBox::~ToolOptionsBox() { std::for_each(m_controls.begin(), m_controls.end(), std::default_delete()); - std::for_each(m_labels.begin(), m_labels.end(), std::default_delete()); + std::for_each(m_labels.begin(), m_labels.end(), + std::default_delete()); } //----------------------------------------------------------------------------- @@ -1117,6 +1118,11 @@ void ArrowToolOptionsBox::onCurrentStageObjectComboActivated(int index) { } // switch the current object m_objHandle->setObjectId(id); + if (id.isCamera()) { + TXsheet *xsh = m_xshHandle->getXsheet(); + if (xsh->getCameraColumnIndex() != id.getIndex()) + m_xshHandle->changeXsheetCamera(id.getIndex()); + } } //------------------------------------------------------------------------------ diff --git a/toonz/sources/toonz/cellkeyframeselection.cpp b/toonz/sources/toonz/cellkeyframeselection.cpp index a10a75a..44a9620 100644 --- a/toonz/sources/toonz/cellkeyframeselection.cpp +++ b/toonz/sources/toonz/cellkeyframeselection.cpp @@ -122,7 +122,8 @@ void TCellKeyframeSelection::selectCellsKeyframes(int r0, int c0, int r1, for (c = c0; c <= c1; c++) for (r = r0; r <= r1; r++) { TStageObjectId id = - c < 0 ? TStageObjectId::CameraId(0) : TStageObjectId::ColumnId(c); + c < 0 ? TStageObjectId::CameraId(xsh->getCameraColumnIndex()) + : TStageObjectId::ColumnId(c); TStageObject *stObj = xsh->getStageObject(id); if (stObj->isKeyframe(r)) m_keyframeSelection->select(r, c); } @@ -134,7 +135,8 @@ void TCellKeyframeSelection::selectCellKeyframe(int row, int col) { m_cellSelection->selectCell(row, col); TXsheet *xsh = m_xsheetHandle->getXsheet(); TStageObjectId id = - col < 0 ? TStageObjectId::CameraId(0) : TStageObjectId::ColumnId(col); + col < 0 ? TStageObjectId::CameraId(xsh->getCameraColumnIndex()) + : TStageObjectId::ColumnId(col); TStageObject *stObj = xsh->getStageObject(id); m_keyframeSelection->clear(); if (stObj->isKeyframe(row)) m_keyframeSelection->select(row, col); diff --git a/toonz/sources/toonz/cellselection.cpp b/toonz/sources/toonz/cellselection.cpp index fd041a9..c50f61c 100644 --- a/toonz/sources/toonz/cellselection.cpp +++ b/toonz/sources/toonz/cellselection.cpp @@ -1677,7 +1677,7 @@ void TCellSelection::pasteCells() { TKeyframeSelection selection; if (isEmpty() && TApp::instance()->getCurrentObject()->getObjectId() == - TStageObjectId::CameraId(0)) + TStageObjectId::CameraId(xsh->getCameraColumnIndex())) // Se la selezione e' vuota e l'objectId e' quello della camera sono nella // colonna di camera quindi devo selezionare la row corrente e -1. { @@ -1880,6 +1880,7 @@ void TCellSelection::insertCells() { //----------------------------------------------------------------------------- void TCellSelection::pasteKeyframesInto() { + TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); const TKeyframeData *keyframeData = dynamic_cast( QApplication::clipboard()->mimeData()); if (keyframeData) { @@ -1889,7 +1890,7 @@ void TCellSelection::pasteKeyframesInto() { TKeyframeSelection selection; if (isEmpty() && TApp::instance()->getCurrentObject()->getObjectId() == - TStageObjectId::CameraId(0)) + TStageObjectId::CameraId(xsh->getCameraColumnIndex())) // Se la selezione e' vuota e l'objectId e' quello della camera sono nella // colonna di camera quindi devo selezionare la row corrente e -1. { diff --git a/toonz/sources/toonz/cellselectioncommand.cpp b/toonz/sources/toonz/cellselectioncommand.cpp index 99c8fca..3c3655b 100644 --- a/toonz/sources/toonz/cellselectioncommand.cpp +++ b/toonz/sources/toonz/cellselectioncommand.cpp @@ -1238,7 +1238,8 @@ void TCellSelection::setKeyframes() { if (cell.getSoundLevel() || cell.getSoundTextLevel()) return; const TStageObjectId &id = - col >= 0 ? TStageObjectId::ColumnId(col) : TStageObjectId::CameraId(0); + col >= 0 ? TStageObjectId::ColumnId(col) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *obj = xsh->getStageObject(id); if (!obj) return; diff --git a/toonz/sources/toonz/keyframedata.cpp b/toonz/sources/toonz/keyframedata.cpp index b09f02c..00a818c 100644 --- a/toonz/sources/toonz/keyframedata.cpp +++ b/toonz/sources/toonz/keyframedata.cpp @@ -41,7 +41,8 @@ void TKeyframeData::setKeyframes(std::set positions, TXsheet *xsh, Position startPos) { if (positions.empty()) return; - TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId(); + TStageObjectId cameraId = + TStageObjectId::CameraId(xsh->getCameraColumnIndex()); std::set::iterator it = positions.begin(); int r0 = it->first; @@ -92,7 +93,8 @@ bool TKeyframeData::getKeyframes(std::set &positions, XsheetViewer *viewer = TApp::instance()->getCurrentXsheetViewer(); positions.clear(); - TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId(); + TStageObjectId cameraId = + TStageObjectId::CameraId(xsh->getCameraColumnIndex()); Iterator it; bool keyFrameChanged = false; for (it = m_keyData.begin(); it != m_keyData.end(); ++it) { diff --git a/toonz/sources/toonz/keyframemover.cpp b/toonz/sources/toonz/keyframemover.cpp index 39d1c39..158480d 100644 --- a/toonz/sources/toonz/keyframemover.cpp +++ b/toonz/sources/toonz/keyframemover.cpp @@ -48,7 +48,8 @@ void KeyframeMover::setKeyframes() { for (auto const &key : m_lastKeyframes) { int c = key.second; TStageObjectId objId = - c >= 0 ? TStageObjectId::ColumnId(c) : TStageObjectId::CameraId(0); + c >= 0 ? TStageObjectId::ColumnId(c) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *stObj = xsh->getStageObject(objId); TStageObject::KeyframeMap keyframes; stObj->getKeyframes(keyframes); @@ -66,7 +67,8 @@ void KeyframeMover::getKeyframes() { for (auto const &pos : m_startSelectedKeyframes) { int c = pos.second; TStageObjectId objId = - c >= 0 ? TStageObjectId::ColumnId(c) : TStageObjectId::CameraId(0); + c >= 0 ? TStageObjectId::ColumnId(c) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *stObj = xsh->getStageObject(objId); assert(stObj->isKeyframe(pos.first)); TStageObject::KeyframeMap keyframes; @@ -115,7 +117,8 @@ bool KeyframeMover::moveKeyframes( int c = posIt->second; int r = posIt->first; TStageObjectId objId = - c >= 0 ? TStageObjectId::ColumnId(c) : TStageObjectId::CameraId(0); + c >= 0 ? TStageObjectId::ColumnId(c) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *stObj = xsh->getStageObject(objId); if (r + dr < 0) { dr = -r; @@ -140,7 +143,8 @@ bool KeyframeMover::moveKeyframes( int c = revIt->second; int r = revIt->first; TStageObjectId objId = - c >= 0 ? TStageObjectId::ColumnId(c) : TStageObjectId::CameraId(0); + c >= 0 ? TStageObjectId::ColumnId(c) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *stObj = xsh->getStageObject(objId); if (m_qualifiers & eCopyKeyframes) { firstTime = true; @@ -154,7 +158,8 @@ bool KeyframeMover::moveKeyframes( int c = posIt->second; int r = posIt->first; TStageObjectId objId = - c >= 0 ? TStageObjectId::ColumnId(c) : TStageObjectId::CameraId(0); + c >= 0 ? TStageObjectId::ColumnId(c) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *stObj = xsh->getStageObject(objId); if (m_qualifiers & eCopyKeyframes) { firstTime = true; @@ -178,7 +183,8 @@ bool KeyframeMover::moveKeyframes( int c = posIt->second; int r = posIt->first; TStageObjectId objId = - c >= 0 ? TStageObjectId::ColumnId(c) : TStageObjectId::CameraId(0); + c >= 0 ? TStageObjectId::ColumnId(c) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *stObj = xsh->getStageObject(objId); if (r + dr < 0) dr = -r; if (dr == 0) notChange = true; @@ -192,7 +198,8 @@ bool KeyframeMover::moveKeyframes( int c = posIt->second; int r = posIt->first; TStageObjectId objId = - c >= 0 ? TStageObjectId::ColumnId(c) : TStageObjectId::CameraId(0); + c >= 0 ? TStageObjectId::ColumnId(c) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObject *stObj = xsh->getStageObject(objId); if (m_qualifiers & eOverwriteKeyframes) { diff --git a/toonz/sources/toonz/keyframeselection.cpp b/toonz/sources/toonz/keyframeselection.cpp index 385c7f5..d5761b0 100644 --- a/toonz/sources/toonz/keyframeselection.cpp +++ b/toonz/sources/toonz/keyframeselection.cpp @@ -48,7 +48,8 @@ bool shiftKeyframesWithoutUndo(int r0, int r1, int c0, int c1, bool cut) { int x; for (x = c0; x <= c1; x++) { TStageObject *stObj = xsh->getStageObject( - x >= 0 ? TStageObjectId::ColumnId(x) : TStageObjectId::CameraId(0)); + x >= 0 ? TStageObjectId::ColumnId(x) + : TStageObjectId::CameraId(xsh->getCameraColumnIndex())); std::set keyToShift; int kr0, kr1; stObj->getKeyframeRange(kr0, kr1); @@ -90,8 +91,9 @@ bool deleteKeyframesWithoutUndo( std::set *positions) { TApp *app = TApp::instance(); assert(app); - TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); - TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId(); + TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); + TStageObjectId cameraId = + TStageObjectId::CameraId(xsh->getCameraColumnIndex()); if (positions->empty()) return false; @@ -208,7 +210,9 @@ public: } void redo() const override { - deleteKeyframesWithoutUndo(&m_selection->getSelection()); + TKeyframeSelection *tempSelection = + new TKeyframeSelection(m_selection->getSelection()); + deleteKeyframesWithoutUndo(&tempSelection->getSelection()); if (m_r1 - m_r0 + 1 != 0) shiftKeyframesWithoutUndo(m_r0, m_r1, m_c0, m_c1, true); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); @@ -279,7 +283,8 @@ void TKeyframeSelection::setKeyframes() { TApp *app = TApp::instance(); TXsheetHandle *xsheetHandle = app->getCurrentXsheet(); TXsheet *xsh = xsheetHandle->getXsheet(); - TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId(); + TStageObjectId cameraId = + TStageObjectId::CameraId(xsh->getCameraColumnIndex()); if (isEmpty()) return; Position pos = *m_positions.begin(); int row = pos.first; diff --git a/toonz/sources/toonz/tapp.cpp b/toonz/sources/toonz/tapp.cpp index 4472023..fcfe1bf 100644 --- a/toonz/sources/toonz/tapp.cpp +++ b/toonz/sources/toonz/tapp.cpp @@ -508,8 +508,11 @@ void TApp::onColumnIndexSwitched() { int columnIndex = m_currentColumn->getColumnIndex(); if (columnIndex >= 0) m_currentObject->setObjectId(TStageObjectId::ColumnId(columnIndex)); - else - m_currentObject->setObjectId(TStageObjectId::CameraId(0)); + else { + TXsheet *xsh = getCurrentXsheet()->getXsheet(); + m_currentObject->setObjectId( + TStageObjectId::CameraId(xsh->getCameraColumnIndex())); + } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/xshcellviewer.cpp b/toonz/sources/toonz/xshcellviewer.cpp index 28a6b60..caa48b4 100644 --- a/toonz/sources/toonz/xshcellviewer.cpp +++ b/toonz/sources/toonz/xshcellviewer.cpp @@ -3017,7 +3017,7 @@ void CellArea::contextMenuEvent(QContextMenuEvent *event) { if (isKeyframeFrame && isKeyFrameArea(col, row, mouseInCell)) { TStageObjectId objectId; if (col < 0) - objectId = TStageObjectId::CameraId(0); + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else { // Set the current column and the current object objectId = TStageObjectId::ColumnId(col); m_viewer->setCurrentColumn(col); diff --git a/toonz/sources/toonz/xshcolumnviewer.cpp b/toonz/sources/toonz/xshcolumnviewer.cpp index d688516..73f7809 100644 --- a/toonz/sources/toonz/xshcolumnviewer.cpp +++ b/toonz/sources/toonz/xshcolumnviewer.cpp @@ -46,6 +46,8 @@ #include "toonz/txshlevelcolumn.h" #include "toonz/txshmeshcolumn.h" #include "toonz/tfxhandle.h" +#include "toonz/tcamera.h" +#include "toonz/tcolumnhandle.h" // TnzCore includes #include "tconvert.h" @@ -59,6 +61,7 @@ #include #include #include +#include #include //============================================================================= @@ -480,10 +483,12 @@ void RenameColumnField::show(const QRect &rect, int col) { setFont(font); m_col = col; - TXsheet *xsh = m_xsheetHandle->getXsheet(); + TXsheet *xsh = m_xsheetHandle->getXsheet(); + int cameraIndex = xsh->getCameraColumnIndex(); std::string name = col >= 0 ? xsh->getStageObject(TStageObjectId::ColumnId(col))->getName() - : xsh->getStageObject(TStageObjectId::CameraId(0))->getName(); + : xsh->getStageObject(TStageObjectId::CameraId(cameraIndex)) + ->getName(); TXshColumn *column = xsh->getColumn(col); TXshZeraryFxColumn *zColumn = dynamic_cast(column); if (zColumn) @@ -500,8 +505,9 @@ void RenameColumnField::show(const QRect &rect, int col) { void RenameColumnField::renameColumn() { std::string newName = text().toStdString(); + int cameraIndex = m_xsheetHandle->getXsheet()->getCameraColumnIndex(); TStageObjectId columnId = m_col >= 0 ? TStageObjectId::ColumnId(m_col) - : TStageObjectId::CameraId(0); + : TStageObjectId::CameraId(cameraIndex); TXshColumn *column = m_xsheetHandle->getXsheet()->getColumn(columnId.getIndex()); TXshZeraryFxColumn *zColumn = dynamic_cast(column); @@ -558,7 +564,8 @@ ColumnArea::DrawHeader::DrawHeader(ColumnArea *nArea, QPainter &nP, int nCol) // check if the column is current isCurrent = false; - if (currentColumnId == TStageObjectId::CameraId(0)) // CAMERA + if (currentColumnId == + TStageObjectId::CameraId(xsh->getCameraColumnIndex())) // CAMERA isCurrent = col == -1; else isCurrent = m_viewer->getCurrentColumn() == col; @@ -801,8 +808,7 @@ void ColumnArea::DrawHeader::drawConfig() const { TXshZeraryFxColumn *zColumn = dynamic_cast(column); - if (col < 0 || zColumn || column->getPaletteColumn() || - column->getSoundTextColumn()) + if (zColumn || column->getPaletteColumn() || column->getSoundTextColumn()) return; p.drawImage(configImgRect, icon); @@ -1152,7 +1158,8 @@ ColumnArea::ColumnArea(XsheetViewer *parent, Qt::WFlags flags) connect(actionGroup, SIGNAL(triggered(QAction *)), this, SLOT(onSubSampling(QAction *))); - + connect(xsheetHandle, SIGNAL(xsheetCameraChange(int)), this, + SLOT(onXsheetCameraChange(int))); setMouseTracking(true); } @@ -1297,7 +1304,8 @@ void ColumnArea::drawLevelColumnHead(QPainter &p, int col) { // check if the column is current bool isCurrent = false; - if (currentColumnId == TStageObjectId::CameraId(0)) // CAMERA + if (currentColumnId == + TStageObjectId::CameraId(xsh->getCameraColumnIndex())) // CAMERA isCurrent = col == -1; else isCurrent = m_viewer->getCurrentColumn() == col; @@ -1865,6 +1873,46 @@ void ColumnArea::openSoundColumnPopup() { m_soundColumnPopup->show(); } +void ColumnArea::openCameraColumnPopup(QPoint pos) { + QMenu menu(this); + + TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); + TStageObjectTree *tree = xsh->getStageObjectTree(); + int i, objCount = tree->getStageObjectCount(); + for (i = 0; i < objCount; i++) { + TStageObject *obj = tree->getStageObject(i); + if (!obj || !obj->getId().isCamera()) continue; + TStageObjectId objId = obj->getId(); + std::string objName = obj->getName(); + QAction *action = new QAction(QString::fromStdString(objName), this); + action->setData(objId.getIndex()); + connect(action, SIGNAL(triggered()), this, + SLOT(onCameraColumnChangedTriggered())); + menu.addAction(action); + } + + menu.exec(pos); +} + +void ColumnArea::onCameraColumnChangedTriggered() { + int newIndex = qobject_cast(sender())->data().toInt(); + onXsheetCameraChange(newIndex); +} + +//---------------------------------------------------------------- + +void ColumnArea::onXsheetCameraChange(int newIndex) { + int oldIndex = m_viewer->getXsheet()->getCameraColumnIndex(); + if (newIndex == oldIndex) return; + + TXsheetHandle *xsheetHandle = TApp::instance()->getCurrentXsheet(); + + CameraColumnSwitchUndo *undo = + new CameraColumnSwitchUndo(oldIndex, newIndex, xsheetHandle); + undo->redo(); + TUndoManager::manager()->add(undo); +} + //---------------------------------------------------------------- void ColumnArea::startTransparencyPopupTimer(QMouseEvent *e) { // AREA @@ -1914,20 +1962,11 @@ void ColumnArea::mousePressEvent(QMouseEvent *event) { return; } // set the clicked column to current - else { - if (m_col < 0) // CAMERA - { - TApp::instance() - ->getCurrentSelection() - ->getSelection() - ->makeNotCurrent(); - m_viewer->getColumnSelection()->selectNone(); - } - + else m_viewer->setCurrentColumn(m_col); - } + TXshColumn *column = xsh->getColumn(m_col); - bool isEmpty = !column || column->isEmpty(); + bool isEmpty = m_col < 0 ? false : (!column || column->isEmpty()); TApp::instance()->getCurrentObject()->setIsSpline(false); // get mouse position @@ -1938,7 +1977,7 @@ void ColumnArea::mousePressEvent(QMouseEvent *event) { // QPoint mouseInCell(x, y); int x = mouseInCell.x(), y = mouseInCell.y(); - if (!isEmpty && m_col >= 0) { + if (!isEmpty) { // grabbing the left side of the column enables column move if (o->rect(PredefinedRect::DRAG_LAYER).contains(mouseInCell) || (!o->flag(PredefinedFlag::DRAG_LAYER_VISIBLE) // If dragbar hidden, @@ -1946,17 +1985,19 @@ void ColumnArea::mousePressEvent(QMouseEvent *event) { // becomes dragbar && (o->rect(PredefinedRect::LAYER_NUMBER).contains(mouseInCell) || o->rect(PredefinedRect::LAYER_NAME).contains(mouseInCell)))) { - setDragTool(XsheetGUI::DragTool::makeColumnMoveTool(m_viewer)); + if (m_col >= 0) + setDragTool(XsheetGUI::DragTool::makeColumnMoveTool(m_viewer)); } // lock button else if (o->rect(PredefinedRect::LOCK_AREA).contains(mouseInCell) && event->button() == Qt::LeftButton) { - m_doOnRelease = isCtrlPressed ? ToggleAllLock : ToggleLock; + if (m_col >= 0) + m_doOnRelease = isCtrlPressed ? ToggleAllLock : ToggleLock; } // preview button else if (o->rect(PredefinedRect::EYE_AREA).contains(mouseInCell) && event->button() == Qt::LeftButton) { - if (column->getSoundTextColumn()) { + if (m_col < 0 || column->getSoundTextColumn()) { // do nothing } else { m_doOnRelease = @@ -1969,7 +2010,8 @@ void ColumnArea::mousePressEvent(QMouseEvent *event) { else if (o->rect(PredefinedRect::PREVIEW_LAYER_AREA) .contains(mouseInCell) && event->button() == Qt::LeftButton) { - if (column->getPaletteColumn() || column->getSoundTextColumn()) { + if (m_col < 0 || column->getPaletteColumn() || + column->getSoundTextColumn()) { // do nothing } else { m_doOnRelease = @@ -1985,8 +2027,8 @@ void ColumnArea::mousePressEvent(QMouseEvent *event) { TXshZeraryFxColumn *zColumn = dynamic_cast(column); - if (zColumn || column->getPaletteColumn() || - column->getSoundTextColumn()) { + if (column && (zColumn || column->getPaletteColumn() || + column->getSoundTextColumn())) { // do nothing } else m_doOnRelease = OpenSettings; @@ -2027,20 +2069,22 @@ void ColumnArea::mousePressEvent(QMouseEvent *event) { setDragTool(XsheetGUI::DragTool::makeColumnSelectionTool(m_viewer)); - // toggle columnIcon visibility with alt+click - TXshLevelColumn *levelColumn = column->getLevelColumn(); - TXshMeshColumn *meshColumn = column->getMeshColumn(); - if (Preferences::instance()->getColumnIconLoadingPolicy() == - Preferences::LoadOnDemand && - (event->modifiers() & Qt::AltModifier)) { - if (levelColumn) - levelColumn->setIconVisible(!levelColumn->isIconVisible()); - else if (meshColumn) - meshColumn->setIconVisible(!meshColumn->isIconVisible()); + if (column) { + // toggle columnIcon visibility with alt+click + TXshLevelColumn *levelColumn = column->getLevelColumn(); + TXshMeshColumn *meshColumn = column->getMeshColumn(); + if (Preferences::instance()->getColumnIconLoadingPolicy() == + Preferences::LoadOnDemand && + (event->modifiers() & Qt::AltModifier)) { + if (levelColumn) + levelColumn->setIconVisible(!levelColumn->isIconVisible()); + else if (meshColumn) + meshColumn->setIconVisible(!meshColumn->isIconVisible()); + } } } // synchronize the current column and the current fx - TApp::instance()->getCurrentFx()->setFx(column->getFx()); + if (column) TApp::instance()->getCurrentFx()->setFx(column->getFx()); } else { if (m_viewer->getColumnSelection()->isColumnSelected(m_col) && event->button() == Qt::RightButton) @@ -2178,7 +2222,7 @@ void ColumnArea::mouseReleaseEvent(QMouseEvent *event) { TApp *app = TApp::instance(); TXsheet *xsh = m_viewer->getXsheet(); int col, totcols = xsh->getColumnCount(); - if (m_doOnRelease != 0 && m_col != -1) { + if (m_doOnRelease != 0) { TXshColumn *column = xsh->getColumn(m_col); if (m_doOnRelease == ToggleTransparency) { column->setCamstandVisible(!column->isCamstandVisible()); @@ -2203,7 +2247,10 @@ void ColumnArea::mouseReleaseEvent(QMouseEvent *event) { mouseInCell.y() - configRect.bottom(); // distance from bottum edge of CONFIG button - if (column->getSoundColumn()) { + if (col < 0) { + openCameraColumnPopup( + QPoint(event->globalPos().x() + x, event->globalPos().y() - y)); + } else if (column->getSoundColumn()) { if (!m_soundColumnPopup) m_soundColumnPopup = new SoundColumnPopup(this); diff --git a/toonz/sources/toonz/xshcolumnviewer.h b/toonz/sources/toonz/xshcolumnviewer.h index d006981..3c1bd76 100644 --- a/toonz/sources/toonz/xshcolumnviewer.h +++ b/toonz/sources/toonz/xshcolumnviewer.h @@ -3,6 +3,17 @@ #ifndef XSHCOLUMNVIEWER_H #define XSHCOLUMNVIEWER_H +#include "tapp.h" + +#include "toonz/tstageobject.h" +#include "toonz/txsheethandle.h" +#include "toonz/tscenehandle.h" +#include "toonz/tcolumnhandle.h" +#include "toonz/txsheet.h" + +#include "../include/tundo.h" +#include "../include/historytypes.h" + #include #include #include @@ -149,6 +160,48 @@ protected slots: }; //============================================================================= +// CameraColumnSwitchUndo +//----------------------------------------------------------------------------- +class CameraColumnSwitchUndo final : public TUndo { + int m_oldCameraIndex, m_newCameraIndex; + TXsheetHandle *m_xsheetHandle; + +public: + CameraColumnSwitchUndo(int oldIndex, int newIndex, TXsheetHandle *xshHandle) + : m_oldCameraIndex(oldIndex) + , m_newCameraIndex(newIndex) + , m_xsheetHandle(xshHandle) {} + ~CameraColumnSwitchUndo() {} + + void undo() const override { + m_xsheetHandle->getXsheet()->setCameraColumnIndex(m_oldCameraIndex); + TApp::instance()->getCurrentScene()->notifySceneChanged(); + TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); + TApp::instance()->getCurrentColumn()->notifyColumnIndexSwitched(); + } + + void redo() const override { + m_xsheetHandle->getXsheet()->setCameraColumnIndex(m_newCameraIndex); + TApp::instance()->getCurrentScene()->notifySceneChanged(); + TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); + TApp::instance()->getCurrentColumn()->notifyColumnIndexSwitched(); + } + + int getSize() const override { return sizeof(*this); } + + QString getHistoryString() override { + TStageObjectId objId = TStageObjectId::CameraId(m_newCameraIndex); + TStageObject *obj = m_xsheetHandle->getXsheet()->getStageObject(objId); + std::string objName = obj->getName(); + QString str = QObject::tr("Camera Column Switch : ") + + QString::fromStdString(objName); + return str; + } + + int getHistoryType() override { return HistoryType::Xsheet; } +}; + +//============================================================================= // ColumnArea //----------------------------------------------------------------------------- @@ -326,6 +379,9 @@ protected slots: void onSubSampling(QAction *); void openTransparencyPopup(); void openSoundColumnPopup(); + void openCameraColumnPopup(QPoint pos); + void onCameraColumnChangedTriggered(); + void onXsheetCameraChange(int); }; //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/xsheetcmd.cpp b/toonz/sources/toonz/xsheetcmd.cpp index e6a72c4..379995f 100644 --- a/toonz/sources/toonz/xsheetcmd.cpp +++ b/toonz/sources/toonz/xsheetcmd.cpp @@ -101,7 +101,8 @@ bool isKeyframe(int r, int c) { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TStageObjectId objectId = - (c == -1) ? TStageObjectId::CameraId(0) : TStageObjectId::ColumnId(c); + (c == -1) ? TStageObjectId::CameraId(xsh->getCameraColumnIndex()) + : TStageObjectId::ColumnId(c); TStageObject *object = xsh->getStageObject(objectId); assert(object); @@ -162,7 +163,7 @@ void InsertSceneFrameUndo::doInsertSceneFrame(int frame) { if (c == -1) { #ifdef LINETEST - objectId = TStageObjectId::CameraId(0); + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); #else continue; #endif @@ -189,7 +190,7 @@ void InsertSceneFrameUndo::doRemoveSceneFrame(int frame) { if (c == -1) { #ifdef LINETEST - objectId = TStageObjectId::CameraId(0); + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); #else continue; #endif @@ -258,7 +259,8 @@ public: m_keyframes.resize(colsCount + 1); // Inserting the eventual camera keyframe at the end - TStageObject *cameraObj = xsh->getStageObject(TStageObjectId::CameraId(0)); + TStageObject *cameraObj = xsh->getStageObject( + TStageObjectId::CameraId(xsh->getCameraColumnIndex())); if (cameraObj->isKeyframe(m_frame)) m_keyframes[colsCount] = cameraObj->getKeyframe(m_frame); @@ -285,8 +287,8 @@ public: // Deal with the eventual camera keyframe if (m_keyframes[cellsCount].m_isKeyframe) { - TStageObject *cameraObj = - xsh->getStageObject(TStageObjectId::CameraId(0)); + TStageObject *cameraObj = xsh->getStageObject( + TStageObjectId::CameraId(xsh->getCameraColumnIndex())); cameraObj->setKeyframeWithoutUndo(m_frame, m_keyframes[cellsCount]); } @@ -376,7 +378,7 @@ void GlobalKeyframeUndo::doInsertGlobalKeyframes( if (c == -1) { #ifdef LINETEST - objectId = TStageObjectId::CameraId(0); + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); #else continue; #endif @@ -411,7 +413,7 @@ void GlobalKeyframeUndo::doRemoveGlobalKeyframes( if (c == -1) { #ifdef LINETEST - objectId = TStageObjectId::CameraId(0); + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); #else continue; #endif @@ -498,8 +500,9 @@ public: static TStageObject::Keyframe getKeyframe(int r, int c) { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); - TStageObjectId objectId = (c == -1) ? TStageObjectId::CameraId(0) - : TStageObjectId::ColumnId(c); + TStageObjectId objectId = + (c == -1) ? TStageObjectId::CameraId(xsh->getCameraColumnIndex()) + : TStageObjectId::ColumnId(c); TStageObject *object = xsh->getStageObject(objectId); assert(object); @@ -530,8 +533,9 @@ public: for (c = 0; c != cCount; ++c) { int col = m_columns[c]; - TStageObjectId objectId = (col == -1) ? TStageObjectId::CameraId(0) - : TStageObjectId::ColumnId(col); + TStageObjectId objectId = + (col == -1) ? TStageObjectId::CameraId(xsh->getCameraColumnIndex()) + : TStageObjectId::ColumnId(col); TStageObject *object = xsh->getStageObject(objectId); object->setKeyframeWithoutUndo(m_frame, m_keyframes[c]); @@ -1072,11 +1076,8 @@ public: int col; for (col = -1; col < xsh->getColumnCount(); col++) { TStageObjectId objectId; -#ifdef LINETEST - if (col == -1) objectId = TStageObjectId::CameraId(0); -#else - if (col == -1) continue; -#endif + if (col == -1 && Preferences::instance()->isXsheetCameraColumnEnabled()) + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else objectId = TStageObjectId::ColumnId(col); TStageObject *pegbar = xsh->getStageObject(objectId); @@ -1095,18 +1096,19 @@ public: void execute() override { TApp *app = TApp::instance(); + ToonzScene *scene = app->getCurrentScene()->getScene(); + TXsheet *xsh = scene->getXsheet(); TKeyframeSelection *selection = dynamic_cast( app->getCurrentSelection()->getSelection()); if (!selection) return; int col = app->getCurrentColumn()->getColumnIndex(); TStageObjectId objectId = app->getCurrentObject()->getObjectId(); - if (app->getCurrentObject()->getObjectId() == TStageObjectId::CameraId(0)) { - objectId = TStageObjectId::CameraId(0); + if (app->getCurrentObject()->getObjectId() == + TStageObjectId::CameraId(xsh->getCameraColumnIndex())) { + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); col = -1; } selection->selectNone(); - ToonzScene *scene = app->getCurrentScene()->getScene(); - TXsheet *xsh = scene->getXsheet(); TStageObject *pegbar = xsh->getStageObject(objectId); TStageObject::KeyframeMap keyframes; pegbar->getKeyframes(keyframes); @@ -1136,11 +1138,8 @@ public: int col; for (col = -1; col < xsh->getColumnCount(); col++) { TStageObjectId objectId; -#ifdef LINETEST - if (col == -1) objectId = TStageObjectId::CameraId(0); -#else - if (col == -1) continue; -#endif + if (col == -1 && Preferences::instance()->isXsheetCameraColumnEnabled()) + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else objectId = TStageObjectId::ColumnId(col); TStageObject *pegbar = xsh->getStageObject(objectId); @@ -1176,11 +1175,8 @@ public: TXsheet *xsh = scene->getXsheet(); for (int col = -1; col < xsh->getColumnCount(); col++) { TStageObjectId objectId; -#ifdef LINETEST - if (col == -1) objectId = TStageObjectId::CameraId(0); -#else - if (col == -1) continue; -#endif + if (col == -1 && Preferences::instance()->isXsheetCameraColumnEnabled()) + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else objectId = TStageObjectId::ColumnId(col); TStageObject *pegbar = xsh->getStageObject(objectId); @@ -1218,11 +1214,8 @@ public: int col; for (col = -1; col < xsh->getColumnCount(); col++) { TStageObjectId objectId; -#ifdef LINETEST - if (col == -1) objectId = TStageObjectId::CameraId(0); -#else - if (col == -1) continue; -#endif + if (col == -1 && Preferences::instance()->isXsheetCameraColumnEnabled()) + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else objectId = TStageObjectId::ColumnId(col); TStageObject *pegbar = xsh->getStageObject(objectId); @@ -1261,9 +1254,9 @@ public: TStageObjectId objectId = TApp::instance()->getCurrentObject()->getObjectId(); -#ifdef LINETEST - if (objectId == TStageObjectId::CameraId(0)) currentColumn = -1; -#endif + if (objectId == TStageObjectId::CameraId(xsh->getCameraColumnIndex()) && + Preferences::instance()->isXsheetCameraColumnEnabled()) + currentColumn = -1; TStageObject *pegbar = xsh->getStageObject(objectId); TStageObject::KeyframeMap keyframes; pegbar->getKeyframes(keyframes); @@ -1298,9 +1291,9 @@ public: TXsheet *xsh = scene->getXsheet(); TStageObjectId objectId = TApp::instance()->getCurrentObject()->getObjectId(); -#ifdef LINETEST - if (objectId == TStageObjectId::CameraId(0)) currentColumn = -1; -#endif + if (objectId == TStageObjectId::CameraId(xsh->getCameraColumnIndex()) && + Preferences::instance()->isXsheetCameraColumnEnabled()) + currentColumn = -1; TStageObject *pegbar = xsh->getStageObject(objectId); TStageObject::KeyframeMap keyframes; pegbar->getKeyframes(keyframes); @@ -1336,11 +1329,8 @@ public: int col; for (col = -1; col <= currentColumn; col++) { TStageObjectId objectId; -#ifdef LINETEST - if (col == -1) objectId = TStageObjectId::CameraId(0); -#else - if (col == -1) continue; -#endif + if (col == -1 && Preferences::instance()->isXsheetCameraColumnEnabled()) + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else objectId = TStageObjectId::ColumnId(col); TStageObject *pegbar = xsh->getStageObject(objectId); @@ -1374,20 +1364,21 @@ public: int currentRow = app->getCurrentFrame()->getFrame(); int currentColumn = app->getCurrentColumn()->getColumnIndex(); + ToonzScene *scene = app->getCurrentScene()->getScene(); + TXsheet *xsh = scene->getXsheet(); + TStageObjectId objectId = TApp::instance()->getCurrentObject()->getObjectId(); -#ifdef LINETEST - if (objectId == TStageObjectId::CameraId(0)) currentColumn = -1; -#endif + if (objectId == TStageObjectId::CameraId(xsh->getCameraColumnIndex()) && + Preferences::instance()->isXsheetCameraColumnEnabled()) + currentColumn = -1; selection->selectNone(); - ToonzScene *scene = app->getCurrentScene()->getScene(); - TXsheet *xsh = scene->getXsheet(); int col; for (col = currentColumn; col < xsh->getColumnCount(); col++) { TStageObjectId objectId; if (col == -1) - objectId = TStageObjectId::CameraId(0); + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else objectId = TStageObjectId::ColumnId(col); TStageObject *pegbar = xsh->getStageObject(objectId); @@ -1423,11 +1414,8 @@ public: int col; for (col = -1; col < xsh->getColumnCount(); col++) { TStageObjectId objectId; -#ifdef LINETEST - if (col == -1) objectId = TStageObjectId::CameraId(0); -#else - if (col == -1) continue; -#endif + if (col == -1 && Preferences::instance()->isXsheetCameraColumnEnabled()) + objectId = TStageObjectId::CameraId(xsh->getCameraColumnIndex()); else objectId = TStageObjectId::ColumnId(col); TStageObject *pegbar = xsh->getStageObject(objectId); diff --git a/toonz/sources/toonz/xsheetdragtool.cpp b/toonz/sources/toonz/xsheetdragtool.cpp index 747c87a..c4c1b58 100644 --- a/toonz/sources/toonz/xsheetdragtool.cpp +++ b/toonz/sources/toonz/xsheetdragtool.cpp @@ -1107,9 +1107,10 @@ public: void onClick(const CellPosition &pos) override { int row = pos.frame(), col = pos.layer(); - m_r0 = m_r1 = row; - TXsheet *xsh = getViewer()->getXsheet(); - TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId(); + m_r0 = m_r1 = row; + TXsheet *xsh = getViewer()->getXsheet(); + TStageObjectId cameraId = + TStageObjectId::CameraId(xsh->getCameraColumnIndex()); TStageObjectId objId = col >= 0 ? TStageObjectId::ColumnId(col) : cameraId; if (col >= 0 && xsh->getColumn(col) && xsh->getColumn(col)->isLocked()) { @@ -1738,12 +1739,12 @@ public: TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TStageObjectId columnId(getViewer()->getObjectId(m_firstCol)); if (m_firstCol == -1) - columnId = - getViewer()->getXsheet()->getStageObjectTree()->getCurrentCameraId(); + columnId = TStageObjectId::CameraId( + getViewer()->getXsheet()->getCameraColumnIndex()); TStageObjectId parentId(getViewer()->getObjectId(m_lastCol)); if (m_lastCol == -1) - parentId = - getViewer()->getXsheet()->getStageObjectTree()->getCurrentCameraId(); + parentId = TStageObjectId::CameraId( + getViewer()->getXsheet()->getCameraColumnIndex()); if (getViewer()->getXsheet()->getColumn(m_lastCol) && getViewer()->getXsheet()->getColumn(m_lastCol)->getSoundColumn()) return; diff --git a/toonz/sources/toonz/xsheetviewer.cpp b/toonz/sources/toonz/xsheetviewer.cpp index 95519b1..6e730cd 100644 --- a/toonz/sources/toonz/xsheetviewer.cpp +++ b/toonz/sources/toonz/xsheetviewer.cpp @@ -482,7 +482,8 @@ int XsheetViewer::getCurrentRow() const { //----------------------------------------------------------------------------- TStageObjectId XsheetViewer::getObjectId(int col) const { - if (col < 0) return TStageObjectId::CameraId(0); + TXsheet *xsh = getXsheet(); + if (col < 0) return TStageObjectId::CameraId(xsh->getCameraColumnIndex()); return TStageObjectId::ColumnId(col); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonzlib/tstageobjectcmd.cpp b/toonz/sources/toonzlib/tstageobjectcmd.cpp index 103fc36..9f843a3 100644 --- a/toonz/sources/toonzlib/tstageobjectcmd.cpp +++ b/toonz/sources/toonzlib/tstageobjectcmd.cpp @@ -792,6 +792,9 @@ void removeStageObjectNode(const TStageObjectId &id, TXsheetHandle *xshHandle, (id.isCamera() && xsh->getStageObjectTree()->getCurrentCameraId() == id)) return; + if (id.isCamera() && xsh->getCameraColumnIndex() == id.getIndex()) + xsh->setCameraColumnIndex(0); + // stacco tutti i figli e li attacco al padre QList linkedObjects; int pegbarsCount = xsh->getStageObjectTree()->getStageObjectCount(); diff --git a/toonz/sources/toonzlib/txsheet.cpp b/toonz/sources/toonzlib/txsheet.cpp index 3d22278..551f116 100644 --- a/toonz/sources/toonzlib/txsheet.cpp +++ b/toonz/sources/toonzlib/txsheet.cpp @@ -185,7 +185,8 @@ TXsheet::TXsheet() : TSmartObject(m_classCode) , m_player(0) , m_imp(new TXsheet::TXsheetImp) - , m_notes(new TXshNoteSet()) { + , m_notes(new TXshNoteSet()) + , m_cameraColumnIndex(0) { // extern TSyntax::Grammar *createXsheetGrammar(TXsheet*); m_soundProperties = new TXsheet::SoundProperties(); m_imp->m_handleManager = new XshHandleManager(this);