diff --git a/toonz/sources/toonz/penciltestpopup_qt.cpp b/toonz/sources/toonz/penciltestpopup_qt.cpp index 3b5818f..aef2a90 100644 --- a/toonz/sources/toonz/penciltestpopup_qt.cpp +++ b/toonz/sources/toonz/penciltestpopup_qt.cpp @@ -177,7 +177,7 @@ inline void doPixBinary(QRgb* pix, int threshold) { gray = 255; else gray = 0; - *pix = qRgb(gray, gray, gray); + *pix = qRgb(gray, gray, gray); } //----------------------------------------------------------------------------- @@ -220,7 +220,7 @@ void onChange(QImage& img, int black, int white, float gamma, bool doGray) { void onChangeBW(QImage& img, int threshold) { int lx = img.width(), y, ly = img.height(); for (y = 0; y < ly; ++y) { - QRgb *pix = (QRgb *)img.scanLine(y), *endPix = (QRgb *)(pix + lx); + QRgb *pix = (QRgb*)img.scanLine(y), *endPix = (QRgb*)(pix + lx); while (pix < endPix) { doPixBinary(pix, threshold); ++pix; @@ -476,7 +476,7 @@ bool getRasterLevelSize(TXshLevel* level, TDimension& dim) { void ApplyLutTask::run() { int lx = m_img.width(); for (int y = m_fromY; y < m_toY; ++y) { - QRgb *pix = (QRgb *)m_img.scanLine(y), *endPix = (QRgb *)(pix + lx); + QRgb *pix = (QRgb*)m_img.scanLine(y), *endPix = (QRgb*)(pix + lx); while (pix < endPix) { doPix(pix, m_lut); ++pix; @@ -487,7 +487,7 @@ void ApplyLutTask::run() { void ApplyGrayLutTask::run() { int lx = m_img.width(); for (int y = m_fromY; y < m_toY; ++y) { - QRgb *pix = (QRgb *)m_img.scanLine(y), *endPix = (QRgb *)(pix + lx); + QRgb *pix = (QRgb*)m_img.scanLine(y), *endPix = (QRgb*)(pix + lx); while (pix < endPix) { doPixGray(pix, m_lut); ++pix; @@ -883,42 +883,44 @@ void MyVideoWidget::mouseReleaseEvent(QMouseEvent* event) { //============================================================================= -FrameNumberLineEdit::FrameNumberLineEdit(QWidget* parent, int value) +FrameNumberLineEdit::FrameNumberLineEdit(QWidget* parent, TFrameId fId, + bool acceptLetter) : LineEdit(parent) { - setFixedWidth(54); - m_intValidator = new QIntValidator(this); - setValue(value); - m_intValidator->setRange(1, 9999); + setFixedWidth(60); + if (acceptLetter) + m_regexpValidator = + new QRegExpValidator(QRegExp("^\\d{1,4}[A-Za-z]?$"), this); + else + m_regexpValidator = new QRegExpValidator(QRegExp("^\\d{1,4}$"), this); - QRegExp rx("^[0-9]{1,4}[A-Ia-i]?$"); - m_regexpValidator = new QRegExpValidator(rx, this); + m_regexpValidator_alt = + new QRegExpValidator(QRegExp("^\\d{1,3}[A-Ia-i]?$"), this); updateValidator(); + + setValue(fId); } //----------------------------------------------------------------------------- void FrameNumberLineEdit::updateValidator() { if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) - setValidator(m_regexpValidator); + setValidator(m_regexpValidator_alt); else - setValidator(m_intValidator); + setValidator(m_regexpValidator); } //----------------------------------------------------------------------------- -void FrameNumberLineEdit::setValue(int value) { - if (value <= 0) - value = 1; - else if (value > 9999) - value = 9999; - +void FrameNumberLineEdit::setValue(TFrameId fId) { QString str; if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) { - str = convertToFrameWithLetter(value, 3); + if (fId.getLetter() != '\0') { + // need some warning? + } + str = convertToFrameWithLetter(fId.getNumber(), 3); } else { - str.setNum(value); - while (str.length() < 4) str.push_front("0"); + str = QString::fromStdString(fId.expand()); } setText(str); setCursorPosition(0); @@ -926,18 +928,27 @@ void FrameNumberLineEdit::setValue(int value) { //----------------------------------------------------------------------------- -int FrameNumberLineEdit::getValue() { +TFrameId FrameNumberLineEdit::getValue() { if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) { QString str = text(); + int f; // if no letters added if (str.at(str.size() - 1).isDigit()) - return str.toInt() * 10; + f = str.toInt() * 10; else { - return str.left(str.size() - 1).toInt() * 10 + - letterToNum(str.at(str.size() - 1)); + f = str.left(str.size() - 1).toInt() * 10 + + letterToNum(str.at(str.size() - 1)); } - } else - return text().toInt(); + return TFrameId(f); + } else { + QRegExp rx("^(\\d{1,4})([A-Za-z]?)$"); + int pos = rx.indexIn(text()); + if (pos < 0) return TFrameId(); + if (rx.cap(2).isEmpty()) + return TFrameId(rx.cap(1).toInt()); + else + return TFrameId(rx.cap(1).toInt(), rx.cap(2).at(0).toLatin1()); + } } //----------------------------------------------------------------------------- @@ -1418,10 +1429,10 @@ void PencilTestSaveInFolderPopup::updateParentFolder() { PencilTestPopup::PencilTestPopup() // set the parent 0 in order to enable the popup behind the main window - : Dialog(0, false, false, "PencilTest"), - m_currentCamera(NULL), - m_captureWhiteBGCue(false), - m_captureCue(false) { + : Dialog(0, false, false, "PencilTest") + , m_currentCamera(NULL) + , m_captureWhiteBGCue(false) + , m_captureCue(false) { setWindowTitle(tr("Camera Capture")); // add maximize button to the dialog @@ -1747,7 +1758,7 @@ PencilTestPopup::PencilTestPopup() bool ret = true; ret = ret && connect(refreshCamListButton, SIGNAL(pressed()), this, SLOT(refreshCameraList())); - ret = ret && connect(m_cameraListCombo, SIGNAL(activated(int)), this, + ret = ret && connect(m_cameraListCombo, SIGNAL(activated(int)), this, SLOT(onCameraListComboActivated(int))); ret = ret && connect(m_resolutionCombo, SIGNAL(activated(const QString&)), this, SLOT(onResolutionComboActivated(const QString&))); @@ -2156,13 +2167,23 @@ void PencilTestPopup::onFrameCaptured(QImage& image) { if (importImage(image)) { m_videoWidget->setPreviousImage(image.copy()); if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) { - int f = m_frameNumberEdit->getValue(); + TFrameId fId = m_frameNumberEdit->getValue(); + int f = fId.getNumber(); if (f % 10 == 0) // next number - m_frameNumberEdit->setValue(((int)(f / 10) + 1) * 10); + m_frameNumberEdit->setValue(TFrameId(((int)(f / 10) + 1) * 10)); else // next alphabet - m_frameNumberEdit->setValue(f + 1); - } else - m_frameNumberEdit->setValue(m_frameNumberEdit->getValue() + 1); + m_frameNumberEdit->setValue(TFrameId(f + 1)); + } else { + TFrameId fId = m_frameNumberEdit->getValue(); + + if (fId.getLetter() == '\0' || fId.getLetter() == 'Z' || + fId.getLetter() == 'z') // next number + m_frameNumberEdit->setValue(TFrameId(fId.getNumber() + 1)); + else { // next alphabet + char letter = fId.getLetter() + 1; + m_frameNumberEdit->setValue(TFrameId(fId.getNumber(), letter)); + } + } /* notify */ TApp::instance()->getCurrentScene()->notifySceneChanged(); @@ -2454,7 +2475,7 @@ bool PencilTestPopup::importImage(QImage image) { return false; } - int frameNumber = m_frameNumberEdit->getValue(); + TFrameId fId = m_frameNumberEdit->getValue(); /* create parent directory if it does not exist */ TFilePath parentDir = @@ -2514,7 +2535,7 @@ bool PencilTestPopup::importImage(QImage image) { return false; } /* if the level already have the same frame, then ask if overwrite it */ - TFilePath frameFp(actualLevelFp.withFrame(frameNumber)); + TFilePath frameFp(actualLevelFp.withFrame(fId)); if (TFileStatus(frameFp).doesExist()) { if (!m_alwaysOverwrite) { QString question = @@ -2542,16 +2563,15 @@ bool PencilTestPopup::importImage(QImage image) { /* if the loaded level does not match in pixel size, then return */ sl = level->getSimpleLevel(); - if (!sl || - sl->getProperties()->getImageRes() != - TDimension(image.width(), image.height())) { + if (!sl || sl->getProperties()->getImageRes() != + TDimension(image.width(), image.height())) { error(tr( "The captured image size does not match with the existing level.")); return false; } /* confirm overwrite */ - TFilePath frameFp(actualLevelFp.withFrame(frameNumber)); + TFilePath frameFp(actualLevelFp.withFrame(fId)); if (TFileStatus(frameFp).doesExist()) { if (!m_alwaysOverwrite) { QString question = @@ -2569,7 +2589,7 @@ bool PencilTestPopup::importImage(QImage image) { else { TXshLevel* level = scene->createNewLevel(OVL_XSHLEVEL, levelName, TDimension(), 0, levelFp); - sl = level->getSimpleLevel(); + sl = level->getSimpleLevel(); sl->setPath(levelFp, true); sl->getProperties()->setDpiPolicy(LevelProperties::DP_CustomDpi); TPointD dpi; @@ -2598,7 +2618,6 @@ bool PencilTestPopup::importImage(QImage image) { state = NEWLEVEL; } - TFrameId fid(frameNumber); TPointD levelDpi = sl->getDpi(); /* create the raster */ TRaster32P raster(image.width(), image.height()); @@ -2607,7 +2626,7 @@ bool PencilTestPopup::importImage(QImage image) { TRasterImageP ri(raster); ri->setDpi(levelDpi.x, levelDpi.y); /* setting the frame */ - sl->setFrame(fid, ri); + sl->setFrame(fId, ri); /* set dirty flag */ sl->getProperties()->setDirtyFlag(true); @@ -2625,7 +2644,7 @@ bool PencilTestPopup::importImage(QImage image) { col += 1; xsh->insertColumn(col); } - xsh->setCell(row, col, TXshCell(sl, fid)); + xsh->setCell(row, col, TXshCell(sl, fId)); app->getCurrentColumn()->setColumnIndex(col); return true; } @@ -2637,7 +2656,7 @@ bool PencilTestPopup::importImage(QImage image) { int foundCol, foundRow = -1; // most possibly, it's in the current column int rowCheck; - if (findCell(xsh, col, TXshCell(sl, fid), rowCheck)) return true; + if (findCell(xsh, col, TXshCell(sl, fId), rowCheck)) return true; if (rowCheck >= 0) { foundRow = rowCheck; foundCol = col; @@ -2645,7 +2664,7 @@ bool PencilTestPopup::importImage(QImage image) { // search entire xsheet for (int c = 0; c < xsh->getColumnCount(); c++) { if (c == col) continue; - if (findCell(xsh, c, TXshCell(sl, fid), rowCheck)) return true; + if (findCell(xsh, c, TXshCell(sl, fId), rowCheck)) return true; if (rowCheck >= 0) { foundRow = rowCheck; foundCol = c; @@ -2657,7 +2676,7 @@ bool PencilTestPopup::importImage(QImage image) { int tmpRow = foundRow + 1; while (1) { if (xsh->getCell(tmpRow, foundCol).isEmpty()) { - xsh->setCell(tmpRow, foundCol, TXshCell(sl, fid)); + xsh->setCell(tmpRow, foundCol, TXshCell(sl, fId)); app->getCurrentColumn()->setColumnIndex(foundCol); break; } @@ -2671,7 +2690,7 @@ bool PencilTestPopup::importImage(QImage image) { col += 1; xsh->insertColumn(col); } - xsh->setCell(row, col, TXshCell(sl, fid)); + xsh->setCell(row, col, TXshCell(sl, fId)); app->getCurrentColumn()->setColumnIndex(col); } @@ -2727,7 +2746,7 @@ void PencilTestPopup::refreshFrameInfo() { TLevelSet* levelSet = currentScene->getLevelSet(); std::wstring levelName = m_levelNameEdit->text().toStdWString(); - int frameNumber = m_frameNumberEdit->getValue(); + TFrameId fId = m_frameNumberEdit->getValue(); TDimension camRes; if (m_subcameraButton->isChecked()) @@ -2757,8 +2776,8 @@ void PencilTestPopup::refreshFrameInfo() { bool levelExist = TSystem::doesExistFileOrLevel(actualLevelFp); // frame existence - TFilePath frameFp(actualLevelFp.withFrame(frameNumber)); - bool frameExist = false; + TFilePath frameFp(actualLevelFp.withFrame(fId)); + bool frameExist = false; if (levelExist) frameExist = TFileStatus(frameFp).doesExist(); // reset acceptable camera size @@ -2897,7 +2916,7 @@ void PencilTestPopup::refreshFrameInfo() { // Check if the target frame already exist in the level bool hasFrame = false; for (int f = 0; f < frameCount; f++) { - if (fids.at(f).getNumber() == frameNumber) { + if (fids.at(f) == fId) { hasFrame = true; break; } diff --git a/toonz/sources/toonz/penciltestpopup_qt.h b/toonz/sources/toonz/penciltestpopup_qt.h index 7c27155..ee320ae 100644 --- a/toonz/sources/toonz/penciltestpopup_qt.h +++ b/toonz/sources/toonz/penciltestpopup_qt.h @@ -6,6 +6,7 @@ #include "toonzqt/dvdialog.h" #include "toonzqt/lineedit.h" #include "toonz/namebuilder.h" +#include "tfilepath.h" #include #include @@ -186,20 +187,20 @@ signals: class FrameNumberLineEdit : public DVGui::LineEdit { Q_OBJECT /* having two validators and switch them according to the preferences*/ - QIntValidator* m_intValidator; - QRegExpValidator* m_regexpValidator; + QRegExpValidator *m_regexpValidator, *m_regexpValidator_alt; void updateValidator(); QString m_textOnFocusIn; public: - FrameNumberLineEdit(QWidget* parent = 0, int value = 1); + FrameNumberLineEdit(QWidget* parent = 0, TFrameId fId = TFrameId(1), + bool acceptLetter = true); ~FrameNumberLineEdit() {} /*! Set text in field to \b value. */ - void setValue(int value); + void setValue(TFrameId value); /*! Return an integer with text field value. */ - int getValue(); + TFrameId getValue(); protected: /*! If focus is lost and current text value is out of range emit signal