Simplify uneditable check code

This commit is contained in:
justburner 2022-07-10 15:37:44 +01:00 committed by manongjohn
parent d56647ec7b
commit eaa9b0b636
15 changed files with 52 additions and 61 deletions

View file

@ -799,10 +799,15 @@ TFrameId TFilePath::getFrame() const {
bool TFilePath::isFfmpegType() const {
QString type = QString::fromStdString(getType()).toLower();
if (type == "gif" || type == "mp4" || type == "webm" || type == "mov")
return true;
else
return false;
return (type == "gif" || type == "mp4" || type == "webm" || type == "mov");
}
//-----------------------------------------------------------------------------
bool TFilePath::isUneditable() const {
QString type = QString::fromStdString(getType()).toLower();
return (type == "psd" || type == "gif" || type == "mp4" || type == "webm" ||
type == "mov");
}
//-----------------------------------------------------------------------------

View file

@ -247,6 +247,7 @@ If the path is "<alpha>:" a slash will be added*/
TFrameId getFrame() const;
bool isFfmpegType() const;
bool isUneditable() const;
bool isLevelName()
const; //{return getFrame() == TFrameId(TFrameId::EMPTY_FRAME);};
bool isAbsolute() const;

View file

@ -250,6 +250,19 @@ inline bool isMovieType(const TFilePath &fp) {
//-----------------------------------------------------------
inline bool isMovieTypeOpaque(std::string type) {
return (type == "avi" || type == "3gp" || type == "mp4");
}
//-----------------------------------------------------------
inline bool isMovieTypeOpaque(const TFilePath &fp) {
std::string type(fp.getType());
return isMovieTypeOpaque(type);
}
//-----------------------------------------------------------
inline bool isSequencialRequired(std::string type) {
return (type == "avi" || type == "3gp");
}
@ -263,6 +276,21 @@ inline bool isSequencialRequired(const TFilePath &fp) {
//-----------------------------------------------------------
inline bool isMultipleFrameType(std::string type) {
return (type == "tlv" || type == "tzl" || type == "pli" || type == "mov" ||
type == "avi" || type == "3gp" || type == "gif" || type == "mp4" ||
type == "webm");
}
//-----------------------------------------------------------
inline bool isMultipleFrameType(const TFilePath &fp) {
std::string type(fp.getType());
return isMultipleFrameType(type);
}
//-----------------------------------------------------------
inline bool doesSupportRandomAccess(const TFilePath &fp,
bool isToonzOutput = false) {
return (fp.getDots() == "..");

View file

@ -1108,12 +1108,7 @@ QString TTool::updateEnabled(int rowIndex, int columnIndex) {
"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->getPath().getType() == "gif" ||
sl->getPath().getType() == "mp4" ||
sl->getPath().getType() == "webm" ||
sl->getPath().getType() == "mov" ||
if (sl->getPath().isUneditable() ||
sl->is16BitChannelLevel() || // Inherited by previous
// implementation.
// Could be fixed?

View file

@ -494,10 +494,7 @@ bool pasteStrokesInCellWithoutUndo(
} else {
vi = cell.getImage(true);
sl = cell.getSimpleLevel();
if (sl->getType() == OVL_XSHLEVEL &&
(sl->getPath().getType() == "psd" || sl->getPath().getType() == "gif" ||
sl->getPath().getType() == "mp4" || sl->getPath().getType() == "webm" ||
sl->getPath().getType() == "mov"))
if (sl->getType() == OVL_XSHLEVEL && sl->getPath().isUneditable())
return false;
fid = cell.getFrameId();
if (!vi) {
@ -1765,11 +1762,7 @@ static void pasteRasterImageInCell(int row, int col,
} else {
TXshSimpleLevel *sl = cell.getSimpleLevel();
// don't do anything to ffmpeg level types
if (sl->getType() == OVL_XSHLEVEL && (sl->getPath().getType() == "psd" ||
sl->getPath().getType() == "gif" ||
sl->getPath().getType() == "mp4" ||
sl->getPath().getType() == "webm" ||
sl->getPath().getType() == "mov"))
if (sl->getType() == OVL_XSHLEVEL && sl->getPath().isUneditable())
return;
oldPalette = sl->getPalette();
}

View file

@ -1653,11 +1653,7 @@ void CloneLevelUndo::cloneLevels() const {
assert(lt->first && !lt->second.empty());
TXshSimpleLevel *srcSl = lt->first;
if (srcSl->getPath().getType() == "psd" ||
srcSl->getPath().getType() == "gif" ||
srcSl->getPath().getType() == "mp4" ||
srcSl->getPath().getType() == "webm" ||
srcSl->getPath().getType() == "mov")
if (srcSl->getPath().isUneditable())
continue;
const TFilePath &srcPath = srcSl->getPath();

View file

@ -249,11 +249,7 @@ static bool canMergeColumns(int column, int mColumn, bool forMatchlines) {
return false;
// Check level type write support. Based on TTool::updateEnabled()
if (level->getType() == OVL_XSHLEVEL &&
(level->getPath().getType() == "psd" || // PSD files.
level->getPath().getType() == "gif" ||
level->getPath().getType() == "mp4" ||
level->getPath().getType() == "webm" ||
level->getPath().getType() == "mov" ||
(level->getPath().isUneditable() ||
level->is16BitChannelLevel() || // 16bpc images.
level->getProperties()->getBpp() == 1)) { // Black & White images.
return false;

View file

@ -171,7 +171,7 @@ bool RenderController::addScene(MovieGenerator &g, ToonzScene *scene) {
}
if (r1 < r0) return false;
TPixel color = scene->getProperties()->getBgColor();
if (isMovieType(m_movieExt) && m_movieExt != "mov" && m_movieExt != "webm") color.m = 255;
if (isMovieTypeOpaque(m_movieExt)) color.m = 255;
g.setBackgroundColor(color);
g.addScene(*scene, r0, r1);
return true;

View file

@ -144,11 +144,6 @@ QMutex levelFileMutex;
} // namespace
inline bool isMultipleFrameType(std::string type) {
return (type == "tlv" || type == "tzl" || type == "pli" || type == "avi" ||
type == "gif" || type == "mp4" || type == "webm" || type == "mov");
}
//=============================================================================
// FileBrowser
//-----------------------------------------------------------------------------

View file

@ -1299,9 +1299,7 @@ void FilmstripFrames::contextMenuEvent(QContextMenuEvent *event) {
}
if (sl &&
(sl->getType() == TZP_XSHLEVEL || sl->getType() == PLI_XSHLEVEL ||
(sl->getType() == OVL_XSHLEVEL && sl->getPath().getType() != "gif" &&
sl->getPath().getType() != "mp4" && sl->getPath().getType() != "webm" &&
sl->getPath().getType() != "mov")))
(sl->getType() == OVL_XSHLEVEL && !sl->getPath().isUneditable())))
menu->addAction(cm->getAction(MI_RevertToLastSaved));
menu->addSeparator();
createSelectLevelMenu(menu);

View file

@ -57,9 +57,8 @@ void TFilmstripSelection::enableCommands() {
bool doEnable =
(type == PLI_XSHLEVEL || type == TZP_XSHLEVEL || type == MESH_XSHLEVEL ||
(type == OVL_XSHLEVEL && path.getType() != "psd" &&
path.getType() != "gif" && path.getType() != "mp4" &&
path.getType() != "webm" && path.getType() != "mov"));
(type == OVL_XSHLEVEL && !path.isUneditable()));
TRasterImageP ri = (TRasterImageP)sl->getSimpleLevel()->getFrame(
sl->getSimpleLevel()->getFirstFid(), false);

View file

@ -336,11 +336,7 @@ void doCloneLevelNoSave(const TCellSelection::Range &range,
if (!img && !fid.isStopFrame()) continue;
if (cell.getSimpleLevel() == 0 ||
cell.getSimpleLevel()->getPath().getType() == "psd" ||
cell.getSimpleLevel()->getPath().getType() == "gif" ||
cell.getSimpleLevel()->getPath().getType() == "mp4" ||
cell.getSimpleLevel()->getPath().getType() == "webm" ||
cell.getSimpleLevel()->getPath().getType() == "mov")
cell.getSimpleLevel()->getPath().isUneditable())
continue;
std::map<TXshSimpleLevel *, TXshLevelP>::iterator it =

View file

@ -447,7 +447,7 @@ void RenderCommand::rasterRender(bool isPreview) {
// depth). I tried to make OT to detect the mov settings and adaptively switch
// the behavior, but ended in vain :-(
// So I just omitted every mov from applying solid background as a quick fix.
if (isMovieType(ext) && ext != "mov" && ext != "webm") {
if (isMovieTypeOpaque(ext)) {
scene->getProperties()->setBgColor(currBgColor);
}
// for non alpha-enabled images (like jpg), background color will be inserted

View file

@ -16,6 +16,7 @@
// TnzCore includes
#include "tconvert.h"
#include "tlevel_io.h"
// Qt includes
#include <QTreeWidget>
@ -34,15 +35,6 @@ using namespace DVGui;
//=============================================================================
namespace {
bool isMovieType(std::string type) {
return (type == "avi" || type == "mp4" ||
type == "webm" || type == "mov");
}
}; // namespace
//=============================================================================
const std::vector<QAction *> &TasksViewer::getActions() const {
return m_actions;
}

View file

@ -119,9 +119,7 @@ bool isAreadOnlyLevel(const TFilePath &path) {
if (path.getDots() == "." ||
(path.getDots() == ".." &&
(path.getType() == "tlv" || path.getType() == "tpl"))) {
if (path.getType() == "psd" || path.getType() == "gif" ||
path.getType() == "mp4" || path.getType() == "webm" ||
path.getType() == "mov")
if (path.isUneditable())
return true;
if (!TSystem::doesExistFileOrLevel(path)) return false;
TFileStatus fs(path);
@ -2496,8 +2494,7 @@ bool TXshSimpleLevel::isFrameReadOnly(TFrameId fid) {
if (getProperties()->isStopMotionLevel()) return true;
TFilePath fullPath = getScene()->decodeFilePath(m_path);
std::string fileType = fullPath.getType();
if (fileType == "psd" || fileType == "gif" || fileType == "mp4" ||
fileType == "webm" || fileType == "mov")
if (fullPath.isUneditable())
return true;
TFilePath path =
fullPath.getDots() == ".." ? fullPath.withFrame(fid) : fullPath;