bool LevelMoverTool::canMoveColumns(const TPoint &pos) { TXsheet *xsh = getViewer()->getXsheet(); if (pos.x < 0) return false; if (pos.x != m_lastPos.x) { int count = 0; // controlla il tipo for (int i = 0; i < m_range.lx; i++) { int srcIndex = m_lastPos.x + i; int dstIndex = pos.x + i; TXshColumn *srcColumn = xsh->getColumn(srcIndex); if (srcColumn && srcColumn->isLocked()) continue; TXshColumn *dstColumn = xsh->getColumn(dstIndex); TXshColumn::ColumnType srcType = TXshColumn::eLevelType; if (srcColumn) srcType = srcColumn->getColumnType(); if (srcType == TXshColumn::eZeraryFxType) return false; /* qDebug() << "check: " << srcIndex << ":" << (srcColumn ? QString::number(srcType) : "empty") << " => " << dstIndex << ":" << (dstColumn ? QString::number(dstColumn->getColumnType()) : "empty"); */ if (dstColumn && !dstColumn->isEmpty() && dstColumn->getColumnType() != srcType) { return false; } if (!dstColumn || dstColumn->isLocked() == false) { count++; } } if (count == 0) return false; } return true; }
bool CellsMover::canMoveCells(const TPoint &pos) { TXsheet *xsh = getXsheet(); if (pos.x < 0) return false; if (pos.x != m_startPos.x) { int count = 0; // controlla il tipo int i = 0; while (i < m_rowCount * m_colCount) { TXshColumn::ColumnType srcType = getColumnTypeFromCell(i); int dstIndex = pos.x + i; TXshColumn *dstColumn = xsh->getColumn(dstIndex); if (srcType == TXshColumn::eZeraryFxType) return false; if (dstColumn && !dstColumn->isEmpty() && dstColumn->getColumnType() != srcType) return false; if (!dstColumn || dstColumn->isLocked() == false) count++; i += m_rowCount; } if (count == 0) return false; } if ((m_qualifiers & CellsMover::eInsertCells) || (m_qualifiers & CellsMover::eOverwriteCells)) return true; int count = 0; for (int i = 0; i < m_colCount; i++) { for (int j = 0; j < m_rowCount; j++) { if (!xsh->getCell(pos.y + j, pos.x + i).isEmpty()) return false; count++; } } if (count == 0) return false; return true; }
void RowArea::mousePressEvent(QMouseEvent *event) { m_viewer->setQtModifiers(event->modifiers()); if (event->button() == Qt::LeftButton) { bool playRangeModifierisClicked = false; TApp *app = TApp::instance(); TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet(); TPoint pos(event->pos().x(), event->pos().y()); int row = m_viewer->yToRow(pos.y); QRect visibleRect = visibleRegion().boundingRect(); int playR0, playR1, step; XsheetGUI::getPlayRange(playR0, playR1, step); bool playRangeEnabled = playR0 <= playR1; if (!playRangeEnabled) { TXsheet *xsh = m_viewer->getXsheet(); playR1 = xsh->getFrameCount() - 1; playR0 = 0; } if (playR1 == -1) { //getFrameCount = 0 i.e. xsheet is empty setDragTool(XsheetGUI::DragTool::makeCurrentFrameModifierTool(m_viewer)); } else if (m_xa <= pos.x && pos.x <= m_xa + 10 && (row == playR0 || row == playR1)) { if (!playRangeEnabled) XsheetGUI::setPlayRange(playR0, playR1, step); setDragTool(XsheetGUI::DragTool::makePlayRangeModifierTool(m_viewer)); playRangeModifierisClicked = true; } else setDragTool(XsheetGUI::DragTool::makeCurrentFrameModifierTool(m_viewer)); //when shift+click the row area, select a single row region in the cell area if (!playRangeModifierisClicked && 0 != (event->modifiers() & Qt::ShiftModifier)) { int filledCol; for (filledCol = xsh->getColumnCount() - 1; filledCol >= 0; filledCol--) { TXshColumn *currentColumn = xsh->getColumn(filledCol); if (!currentColumn) continue; if (!currentColumn->isEmpty()) break; } m_viewer->getCellSelection()->selectNone(); m_viewer->getCellSelection()->selectCells(row, 0, row, tmax(0, filledCol)); m_viewer->updateCellRowAree(); } m_viewer->dragToolClick(event); event->accept(); } // left-click // pan by middle-drag else if (event->button() == Qt::MidButton) { m_pos = event->pos(); m_isPanning = true; } }
// isTotallyEmptyColumn == column empty, no fx bool LevelMoverTool::isTotallyEmptyColumn(int col) const { if (col < 0) return false; TXsheet *xsh = getViewer()->getXsheet(); TXshColumn *column = xsh->getColumn(col); if (!column) return true; if (!column->isEmpty()) return false; if (column->getFx()->getOutputConnectionCount() != 0) return false; // bisogna controllare lo stage object return true; }
void LevelMoverTool::onCellChange(int row, int col) { TXsheet *xsh = getViewer()->getXsheet(); TPoint pos = TPoint(col, row) + m_grabOffset; if (pos.y < 0) pos.y = 0; if (pos.x < 0) return; if (pos == m_aimedPos) return; m_aimedPos = pos; TPoint delta = m_aimedPos - m_lastPos; m_validPos = canMoveColumns(pos); if (!m_validPos) return; CellsMover *cellsMover = m_undo->getCellsMover(); if (m_moved) cellsMover->undoMoveCells(); m_validPos = canMove(pos); if (m_validPos) { //---------------------- if (delta.x != 0 && (m_qualifiers & CellsMover::eMoveColumns)) { // spostamento di colonne int colCount = m_range.lx; bool emptySrc = true; for (int i = 0; i < colCount; i++) { TXshColumn *column = xsh->getColumn(m_lastPos.x + i); if (column && !column->isEmpty()) { emptySrc = false; break; } } bool lockedDst = false; bool emptyDst = true; for (int i = 0; i < colCount; i++) { if (!isTotallyEmptyColumn(pos.x + i)) emptyDst = false; TXshColumn *column = xsh->getColumn(pos.x + i); if (column && column->isLocked()) lockedDst = true; } if (emptySrc) { if (m_lastPos.x == m_startPos.x) m_undo->getCellsMover()->m_uffa |= 1; // first column(s) has/have been cleared cellsMover->emptyColumns(m_lastPos.x); } if (emptyDst && !lockedDst) { if (pos.x == m_startPos.x) m_undo->getCellsMover()->m_uffa &= ~1; // first column(s) has/have been restored else m_undo->getCellsMover()->m_uffa |= 2; // columns data have been copied on the current position cellsMover->restoreColumns(pos.x); } else { m_undo->getCellsMover()->m_uffa &= ~2; // no columns data have been copied on the current position } } //---------------------- m_lastPos = pos; cellsMover->setPos(pos.y, pos.x); cellsMover->saveCells(); cellsMover->moveCells(); m_moved = true; } else { cellsMover->moveCells(); } xsh->updateFrameCount(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); if (cellsMover->getColumnTypeFromCell(0) == TXshColumn::eSoundType) TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged(); TRect selection(m_aimedPos, m_range); getViewer()->getCellSelection()->selectCells(selection.y0, selection.x0, selection.y1, selection.x1); }
QString TTool::updateEnabled() { // Disable every tool during playback if (m_application->getCurrentFrame()->isPlaying()) return (enable(false), QString()); // Release Generic tools at once int toolType = getToolType(); int targetType = getTargetType(); if (toolType == TTool::GenericTool) return (enable(true), QString()); // Retrieve vars and view modes TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet(); int rowIndex = m_application->getCurrentFrame()->getFrame(); int columnIndex = m_application->getCurrentColumn()->getColumnIndex(); TXshColumn *column = (columnIndex >= 0) ? xsh->getColumn(columnIndex) : 0; TXshLevel *xl = m_application->getCurrentLevel()->getLevel(); TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0; int levelType = sl ? sl->getType() : NO_XSHLEVEL; TStageObject *obj = xsh->getStageObject(TStageObjectId::ColumnId(columnIndex)); bool spline = m_application->getCurrentObject()->isSpline(); bool filmstrip = m_application->getCurrentFrame()->isEditingLevel(); /*-- MultiLayerStylePickerONのときは、現状に関わらず使用可能 --*/ if (m_name == T_StylePicker && Preferences::instance()->isMultiLayerStylePickerEnabled()) return (enable(true), QString()); // Check against unplaced columns (not in filmstrip mode) if (column && !filmstrip) { if (column->isLocked()) return (enable(false), QObject::tr("The current column is locked.")); else if (!column->isCamstandVisible()) return (enable(false), QObject::tr("The current column is hidden.")); else if (column->getSoundColumn()) return (enable(false), QObject::tr("It is not possible to edit the audio column.")); else if (column->getSoundTextColumn()) return ( enable(false), QObject::tr( "Note columns can only be edited in the xsheet or timeline.")); if (toolType == TTool::ColumnTool) { // Check column target if (column->getLevelColumn() && !(targetType & LevelColumns)) return ( enable(false), QObject::tr("The current tool cannot be used on a Level column.")); if (column->getMeshColumn() && !(targetType & MeshColumns)) return ( enable(false), QObject::tr("The current tool cannot be used on a Mesh column.")); } } // Check column tools if (toolType == TTool::ColumnTool) { if (filmstrip) return ( enable(false), QObject::tr("The current tool cannot be used in Level Strip mode.")); if ((!column || column->isEmpty()) && !(targetType & TTool::EmptyTarget)) return (enable(false), QString()); } // Check LevelRead & LevelWrite tools if (toolType & TTool::LevelTool) { // Check against splines if (spline) { return (targetType & Splines) ? (enable(true), QString()) : (enable(false), QObject::tr("The current tool cannot be " "used to edit a motion path.")); } // Check against empty levels if (!xl) return (targetType & EmptyTarget) ? (enable(true), QString()) : (enable(false), QString()); // Check against simple-level-edness if (!sl) return (enable(false), QObject::tr("The current level is not editable.")); // Does it // happen at // all btw? // Check against level types { if ((levelType == PLI_XSHLEVEL) && !(targetType & VectorImage)) return ( enable(false), QObject::tr("The current tool cannot be used on a Vector Level.")); if ((levelType == TZP_XSHLEVEL) && !(targetType & ToonzImage)) return ( enable(false), QObject::tr("The current tool cannot be used on a Toonz Level.")); if ((levelType == OVL_XSHLEVEL) && !(targetType & RasterImage)) return ( enable(false), QObject::tr("The current tool cannot be used on a Raster Level.")); if ((levelType == MESH_XSHLEVEL) && !(targetType & MeshImage)) return ( enable(false), QObject::tr("The current tool cannot be used on a Mesh Level.")); } // Check against impossibly traceable movements on the column if ((levelType & LEVELCOLUMN_XSHLEVEL) && !filmstrip) { // Test for Mesh-deformed levels const TStageObjectId &parentId = obj->getParent(); if (parentId.isColumn() && obj->getParentHandle()[0] != 'H') { TXshSimpleLevel *parentSl = xsh->getCell(rowIndex, parentId.getIndex()).getSimpleLevel(); if (parentSl && parentSl->getType() == MESH_XSHLEVEL) return ( enable(false), QObject::tr( "The current tool cannot be used on a mesh-deformed level")); } } // Check TTool::ImageType tools if (toolType == TTool::LevelWriteTool) { // Check level against read-only status if (sl->isReadOnly()) { const std::set<TFrameId> &editableFrames = sl->getEditableRange(); TFrameId currentFid = getCurrentFid(); if (editableFrames.find(currentFid) == editableFrames.end()) return ( enable(false), QObject::tr( "The current frame is locked: any editing is forbidden.")); } // Check level type write support if (sl->getPath().getType() == "psd" || // We don't have the API to write psd files sl->is16BitChannelLevel() || // Inherited by previous implementation. // Could be fixed? sl->getProperties()->getBpp() == 1) // Black & White images. Again, could be fixed? return (enable(false), QObject::tr("The current level is not editable.")); } } return (enable(true), QString()); }