void Filmstrip::updateWindowTitle() { updateCurrentLevelComboItem(); TXshSimpleLevel *level = m_frames->getLevel(); QString levelName; if (!level) { parentWidget()->setWindowTitle(tr("Level Strip")); return; } else { levelName = QString::fromStdWString(level->getName()); if (level->getProperties()->getDirtyFlag()) levelName += " *"; } // parentWidget() is TPanel parentWidget()->setWindowTitle(tr("Level: ") + levelName); TFrameHandle *fh = TApp::instance()->getCurrentFrame(); if (fh->isEditingLevel() && fh->getFid().getNumber() >= 0) levelName += QString(" [#") + QString::number(fh->getFid().getNumber()) + QString("]"); m_chooseLevelCombo->setItemText(m_chooseLevelCombo->currentIndex(), levelName); }
/*! update combo items when the contents of scene cast are changed */ void Filmstrip::updateChooseLevelComboItems() { // clear items m_chooseLevelCombo->clear(); m_levels.clear(); std::map<TXshSimpleLevel *, TFrameId> new_workingFrames; // correct and register items ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); if (scene) { std::vector<TXshLevel *> levels; scene->getLevelSet()->listLevels(levels); std::vector<TXshLevel *>::iterator it; for (it = levels.begin(); it != levels.end(); ++it) { // register only TLV and PLI TXshSimpleLevel *sl = (*it)->getSimpleLevel(); if (sl) { // register only used level in xsheet if (!scene->getTopXsheet()->isLevelUsed(sl)) continue; m_levels.push_back(sl); // create new m_workingFrames map with the new levelset TFrameId fId; std::map<TXshSimpleLevel *, TFrameId>::iterator WFit = m_workingFrames.find(sl); if (WFit != m_workingFrames.end()) fId = WFit->second; else fId = sl->getFirstFid(); new_workingFrames.insert(std::make_pair(sl, fId)); QString levelName = QString::fromStdWString(sl->getName()); if (sl->getProperties()->getDirtyFlag()) levelName += " *"; // append the current working frame number to the item name if (fId != sl->getFirstFid() && fId.getNumber() >= 0) levelName += QString(" [#") + QString::number(fId.getNumber()) + QString("]"); m_chooseLevelCombo->addItem(levelName); } } } m_chooseLevelCombo->addItem(tr("- No Current Level -")); // swap the list m_workingFrames.clear(); m_workingFrames = new_workingFrames; // synchronize the current index of combo to the current level updateCurrentLevelComboItem(); }
static bool canMergeColumns(int column, int mColumn, bool forMatchlines) { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); if (xsh->getColumn(column)->isLocked()) return false; int start, end; xsh->getCellRange(column, start, end); if (start > end) return false; std::vector<TXshCell> cell(end - start + 1); std::vector<TXshCell> mCell(end - start + 1); xsh->getCells(start, column, cell.size(), &(cell[0])); xsh->getCells(start, mColumn, cell.size(), &(mCell[0])); TXshSimpleLevel *level = 0, *mLevel = 0; TXshLevelP xl; for (int i = 0; i < (int)cell.size(); i++) { if (cell[i].isEmpty() || mCell[i].isEmpty()) continue; if (!level) { level = cell[i].getSimpleLevel(); xl = cell[i].m_level; } else if (level != cell[i].getSimpleLevel()) return false; if (!mLevel) mLevel = mCell[i].getSimpleLevel(); else if (mLevel != mCell[i].getSimpleLevel()) return false; if (!mLevel || !level || // potrebbero non essere dei simplelevel (forMatchlines && (level->getType() != TZP_XSHLEVEL || mLevel->getType() != TZP_XSHLEVEL))) return false; else if (!forMatchlines) { if (level->getType() != mLevel->getType()) return false; if (level->getType() != PLI_XSHLEVEL && level->getType() != OVL_XSHLEVEL) return false; // Check level type write support. Based on TTool::updateEnabled() if (level->getType() == OVL_XSHLEVEL && (level->getPath().getType() == "psd" || // PSD files. level->is16BitChannelLevel() || // 16bpc images. level->getProperties()->getBpp() == 1)) { // Black & White images. return false; } } } return true; }
void BinarizePopup::apply() { if (getSelectedFrames() <= 0) { DVGui::error(tr("No raster frames selected")); return; } DVGui::ProgressDialog pd(tr("Binarizing images"), tr("Cancel"), 0, (int)m_frames.size(), 0); pd.show(); qApp->processEvents(); TBinarizer binarizer; binarizer.enableAlpha(!!m_alphaChk->checkState()); TUndoManager::manager()->beginBlock(); int count = 0; Frames::iterator it; for (it = m_frames.begin(); it != m_frames.end(); ++it) { TXshSimpleLevel *sl = it->first; if (!!m_alphaChk->checkState()) sl->getProperties()->setHasAlpha(true); TFrameId fid = it->second; TBinarizeUndo *undo = new TBinarizeUndo(sl, fid, binarizer.isAlphaEnabled()); TUndoManager::manager()->add(undo); TRasterImageP ri = sl->getFrame(fid, true); if (!ri) continue; // should never happen TRaster32P ras32 = ri->getRaster(); if (!ras32) continue; // not yet handled binarizer.process(ras32); pd.setValue(count++); qApp->processEvents(); sl->touchFrame(fid); sl->setDirtyFlag(true); IconGenerator::instance()->invalidate(sl, fid); } TUndoManager::manager()->endBlock(); TApp::instance()->getCurrentLevel()->notifyLevelChange(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void Filmstrip::onFrameSwitched() { TFrameHandle *fh = TApp::instance()->getCurrentFrame(); if (!fh->isEditingLevel()) return; TXshSimpleLevel *level = m_frames->getLevel(); std::map<TXshSimpleLevel *, TFrameId>::iterator WFit; WFit = m_workingFrames.find(level); if (WFit == m_workingFrames.end()) return; WFit->second = fh->getFid(); QString levelName = QString::fromStdWString(level->getName()); if (level->getProperties()->getDirtyFlag()) levelName += " *"; if (fh->getFid().getNumber() >= 0) levelName += QString(" [#") + QString::number(fh->getFid().getNumber()) + QString("]"); m_chooseLevelCombo->setItemText(m_chooseLevelCombo->currentIndex(), levelName); }
bool LevelCreatePopup::apply() { TApp *app = TApp::instance(); int row = app->getCurrentFrame()->getFrame(); int col = app->getCurrentColumn()->getColumnIndex(); int i, j; ToonzScene *scene = app->getCurrentScene()->getScene(); TXsheet *xsh = scene->getXsheet(); bool validColumn = true; if (xsh->getColumn(col)) validColumn = xsh->getColumn(col)->getColumnType() == TXshColumn::eLevelType; int from = (int)m_fromFld->getValue(); int to = (int)m_toFld->getValue(); int inc = (int)m_incFld->getValue(); int step = (int)m_stepFld->getValue(); double w = m_widthFld->getValue(); double h = m_heightFld->getValue(); double dpi = m_dpiFld->getValue(); int xres = std::max(tround(w * dpi), 1); int yres = std::max(tround(h * dpi), 1); int lType = getLevelType(); std::wstring levelName = m_nameFld->text().toStdWString(); // tolgo i blanks prima e dopo i = levelName.find_first_not_of(L' '); if (i == (int)std::wstring::npos) levelName = L""; else { int j = levelName.find_last_not_of(L' '); assert(j != (int)std::wstring::npos); levelName = levelName.substr(i, j - i + 1); } if (levelName.empty()) { error(tr("No level name specified: please choose a valid level name")); return false; } if (from > to) { error(tr("Invalid frame range")); return false; } if (inc <= 0) { error(tr("Invalid increment value")); return false; } if (step <= 0) { error(tr("Invalid step value")); return false; } int numFrames = step * (((to - from) / inc) + 1); if (scene->getLevelSet()->getLevel(levelName)) { error( tr("The level name specified is already used: please choose a " "different level name")); m_nameFld->selectAll(); return false; } TFilePath parentDir(m_pathFld->getPath().toStdWString()); TFilePath fp = scene->getDefaultLevelPath(lType, levelName).withParentDir(parentDir); TFilePath actualFp = scene->decodeFilePath(fp); if (TSystem::doesExistFileOrLevel(actualFp)) { error( tr("The level name specified is already used: please choose a " "different level name")); m_nameFld->selectAll(); return false; } parentDir = scene->decodeFilePath(parentDir); if (!TFileStatus(parentDir).doesExist()) { QString question; /*question = "Folder " +toQString(parentDir) + " doesn't exist.\nDo you want to create it?";*/ question = tr("Folder %1 doesn't exist.\nDo you want to create it?") .arg(toQString(parentDir)); int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No")); if (ret == 0 || ret == 2) return false; try { TSystem::mkDir(parentDir); DvDirModel::instance()->refreshFolder(parentDir.getParentDir()); } catch (...) { error(tr("Unable to create") + toQString(parentDir)); return false; } } TXshLevel *level = scene->createNewLevel(lType, levelName, TDimension(), 0, fp); TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(level); assert(sl); sl->setPath(fp, true); if (lType == TZP_XSHLEVEL || lType == OVL_XSHLEVEL) { sl->getProperties()->setDpiPolicy(LevelProperties::DP_ImageDpi); sl->getProperties()->setDpi(dpi); sl->getProperties()->setImageDpi(TPointD(dpi, dpi)); sl->getProperties()->setImageRes(TDimension(xres, yres)); } /*-- これからLevelを配置しようとしているセルが空いているかどうかのチェック * --*/ bool areColumnsShifted = false; TXshCell cell = xsh->getCell(row, col); bool isInRange = true; for (i = row; i < row + numFrames; i++) { if (!cell.isEmpty()) { isInRange = false; break; } cell = xsh->getCell(i, col); } if (!validColumn) { isInRange = false; } /*-- 別のLevelに占有されていた場合、Columnを1つ右に移動 --*/ if (!isInRange) { col += 1; TApp::instance()->getCurrentColumn()->setColumnIndex(col); areColumnsShifted = true; xsh->insertColumn(col); } CreateLevelUndo *undo = new CreateLevelUndo(row, col, numFrames, step, areColumnsShifted); TUndoManager::manager()->add(undo); for (i = from; i <= to; i += inc) { TFrameId fid(i); TXshCell cell(sl, fid); if (lType == PLI_XSHLEVEL) sl->setFrame(fid, new TVectorImage()); else if (lType == TZP_XSHLEVEL) { TRasterCM32P raster(xres, yres); raster->fill(TPixelCM32()); TToonzImageP ti(raster, TRect()); ti->setDpi(dpi, dpi); sl->setFrame(fid, ti); ti->setSavebox(TRect(0, 0, xres - 1, yres - 1)); } else if (lType == OVL_XSHLEVEL) { TRaster32P raster(xres, yres); raster->clear(); TRasterImageP ri(raster); ri->setDpi(dpi, dpi); sl->setFrame(fid, ri); } for (j = 0; j < step; j++) xsh->setCell(row++, col, cell); } if (lType == TZP_XSHLEVEL || lType == OVL_XSHLEVEL) { sl->save(fp); DvDirModel::instance()->refreshFolder(fp.getParentDir()); } undo->onAdd(sl); app->getCurrentScene()->notifySceneChanged(); app->getCurrentScene()->notifyCastChange(); app->getCurrentXsheet()->notifyXsheetChanged(); // Cambia l'immagine corrente ma non cambiano ne' il frame ne' la colonna // corrente // (entrambi notificano il cambiamento dell'immagine al tool). // devo verfificare che sia settato il tool giusto. app->getCurrentTool()->onImageChanged( (TImage::Type)app->getCurrentImageType()); return true; }
void FilmstripFrames::paintEvent(QPaintEvent *evt) { QPainter p(this); // p.setRenderHint(QPainter::Antialiasing, true); QRect clipRect = evt->rect(); p.fillRect(clipRect, Qt::black); // thumbnail rect, including offsets QRect iconImgRect = QRect(QPoint(fs_leftMargin + fs_iconMarginLR, fs_frameSpacing / 2 + fs_iconMarginTop), m_iconSize); // frame size with margins QSize frameSize = m_iconSize + QSize(fs_iconMarginLR * 2, fs_iconMarginTop + fs_iconMarginBottom); // .. and with offset QRect frameRect = QRect(QPoint(fs_leftMargin, fs_frameSpacing / 2), frameSize); int oneFrameHeight = frameSize.height() + fs_frameSpacing; // visible frame index range int i0 = y2index(clipRect.top()); int i1 = y2index(clipRect.bottom()); // fids, frameCount <- frames del livello std::vector<TFrameId> fids; TXshSimpleLevel *sl = getLevel(); if (sl) sl->getFids(fids); else { for (int i = i0; i <= i1; i++) { // draw white rectangles if obtaining the level is failed QRect iconRect = frameRect.translated(QPoint(0, oneFrameHeight * i)); p.setBrush(QColor(192, 192, 192)); p.setPen(Qt::NoPen); p.drawRect(iconRect); } return; } //--- compute navigator rect --- QRect naviRect; ComboViewerPanel *inknPaintViewerPanel = TApp::instance()->getInknPaintViewerPanel(); if (sl->getType() == TZP_XSHLEVEL && inknPaintViewerPanel) { // show navigator only if the inknpaint viewer is visible if (inknPaintViewerPanel->isVisible()) { SceneViewer *viewer = inknPaintViewerPanel->getSceneViewer(); // imgSize: image's pixel size QSize imgSize(sl->getProperties()->getImageRes().lx, sl->getProperties()->getImageRes().ly); // Viewer affine TAffine viewerAff = inknPaintViewerPanel->getSceneViewer()->getViewMatrix(); // pixel size which will be displayed with 100% scale in Viewer Stage TFrameId currentId = TApp::instance()->getCurrentFrame()->getFid(); double imgPixelWidth = (double)(imgSize.width()) / sl->getDpi(currentId).x * Stage::inch; double imgPixelHeight = (double)(imgSize.height()) / sl->getDpi(currentId).y * Stage::inch; // get the image's corner positions in viewer matrix (with current zoom // scale) TPointD imgTopRight = viewerAff * TPointD(imgPixelWidth / 2.0f, imgPixelHeight / 2.0f); TPointD imgBottomLeft = viewerAff * TPointD(-imgPixelWidth / 2.0f, -imgPixelHeight / 2.0f); // pixel size in viewer matrix ( with current zoom scale ) QSizeF imgSizeInViewer(imgTopRight.x - imgBottomLeft.x, imgTopRight.y - imgBottomLeft.y); // ratio of the Viewer frame's position and size QRectF naviRatio( (-(float)viewer->width() * 0.5f - (float)imgBottomLeft.x) / imgSizeInViewer.width(), 1.0f - ((float)viewer->height() * 0.5f - (float)imgBottomLeft.y) / imgSizeInViewer.height(), (float)viewer->width() / imgSizeInViewer.width(), (float)viewer->height() / imgSizeInViewer.height()); naviRect = QRect(iconImgRect.left() + (int)(naviRatio.left() * (float)iconImgRect.width()), iconImgRect.top() + (int)(naviRatio.top() * (float)iconImgRect.height()), (int)((float)iconImgRect.width() * naviRatio.width()), (int)((float)iconImgRect.height() * naviRatio.height())); // for drag move m_naviRectPos = naviRect.center(); naviRect = naviRect.intersected(frameRect); m_icon2ViewerRatio.setX(imgSizeInViewer.width() / (float)iconImgRect.width()); m_icon2ViewerRatio.setY(imgSizeInViewer.height() / (float)iconImgRect.height()); } } //--- compute navigator rect end --- int frameCount = (int)fids.size(); std::set<TFrameId> editableFrameRange; if (sl) editableFrameRange = sl->getEditableRange(); bool isReadOnly = false; if (sl) isReadOnly = sl->isReadOnly(); int i; int iconWidth = m_iconSize.width(); int x0 = m_frameLabelWidth; int x1 = x0 + iconWidth; int frameHeight = m_iconSize.height(); // linee orizzontali che separano i frames p.setPen(getLightLineColor()); for (i = i0; i <= i1; i++) { int y = index2y(i) + frameHeight; p.drawLine(0, y, x1, y); } TFilmstripSelection::InbetweenRange range = m_selection->getInbetweenRange(); // draw for each frames for (i = i0; i <= i1; i++) { QRect tmp_iconImgRect = iconImgRect.translated(QPoint(0, oneFrameHeight * i)); QRect tmp_frameRect = frameRect.translated(QPoint(0, oneFrameHeight * i)); bool isCurrentFrame = (i == sl->fid2index(TApp::instance()->getCurrentFrame()->getFid())); bool isSelected = (0 <= i && i < frameCount && m_selection->isSelected(fids[i])); if (0 <= i && i < frameCount) { TFrameId fid = fids[i]; // normal or inbetween (for vector levels) int flags = (sl->getType() == PLI_XSHLEVEL && range.first < fid && fid < range.second) ? F_INBETWEEN_RANGE : F_NORMAL; // draw icons drawFrameIcon(p, tmp_iconImgRect, i, fid, flags); p.setPen(Qt::NoPen); p.setBrush(Qt::NoBrush); p.drawRect(tmp_iconImgRect); // Frame number if (m_selection->isSelected(fids[i])) { if (TApp::instance()->getCurrentFrame()->isEditingLevel() && isCurrentFrame) p.setPen(Qt::red); else p.setPen(Qt::white); } else p.setPen(QColor(192, 192, 192)); p.setBrush(Qt::NoBrush); // for single frame QString text; if (fid.getNumber() == TFrameId::EMPTY_FRAME || fid.getNumber() == TFrameId::NO_FRAME) { text = QString("Single Frame"); } // for sequencial frame (with letter) else if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) { text = fidToFrameNumberWithLetter(fid.getNumber()); } // for sequencial frame else { text = QString::number(fid.getNumber()).rightJustified(4, '0'); } p.drawText(tmp_frameRect.adjusted(0, 0, -3, 2), text, QTextOption(Qt::AlignRight | Qt::AlignBottom)); p.setPen(Qt::NoPen); // Read-only frames (lock) if (0 <= i && i < frameCount) { if ((editableFrameRange.empty() && isReadOnly) || (isReadOnly && (!editableFrameRange.empty() && editableFrameRange.count(fids[i]) == 0))) { static QPixmap lockPixmap(":Resources/forbidden.png"); p.drawPixmap(tmp_frameRect.bottomLeft() + QPoint(3, -13), lockPixmap); } } } // navigator rect if (naviRect.isValid() && isCurrentFrame) { p.setPen(QPen(Qt::red, 1)); p.drawRect(naviRect.translated(0, oneFrameHeight * i)); p.setPen(Qt::NoPen); } // red frame for the current frame if (TApp::instance()->getCurrentFrame()->isEditingLevel() && (isCurrentFrame || isSelected)) { QPen pen; pen.setColor(Qt::red); pen.setWidth(2); pen.setJoinStyle(Qt::RoundJoin); p.setPen(pen); p.drawRect(tmp_frameRect.adjusted(-1, -1, 2, 2)); p.setPen(Qt::NoPen); } } // se sono in modalita' level edit faccio vedere la freccia che indica il // frame corrente if (TApp::instance()->getCurrentFrame()->isEditingLevel()) m_frameHeadGadget->draw(p, QColor(Qt::white), QColor(Qt::black)); }
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()); }