diff --git a/toonz/sources/common/tunit/tunit.cpp b/toonz/sources/common/tunit/tunit.cpp index 9c1f2ee2..22d8b990 100644 --- a/toonz/sources/common/tunit/tunit.cpp +++ b/toonz/sources/common/tunit/tunit.cpp @@ -347,22 +347,27 @@ TMeasureManager::TMeasureManager() { m->add(cameraYFld.clone()); add(m); + const double stage_inch = 53.33333; // Consider changing to 120 or 160 + TUnit fxLength(L"fxLength"), - fxInch(L"in", new TSimpleUnitConverter(1 / 53.33333)), - fxCm(L"cm", new TSimpleUnitConverter(2.54 / 53.33333)), - fxMm(L"mm", new TSimpleUnitConverter(25.4 / 53.33333)), - fxXfld(L"fld", new TSimpleUnitConverter(2 / 53.33333)); + fxInch(L"in", new TSimpleUnitConverter(1 / stage_inch)), + fxCm(L"cm", new TSimpleUnitConverter(2.54 / stage_inch)), + fxMm(L"mm", new TSimpleUnitConverter(25.4 / stage_inch)), + fxXfld(L"fld", new TSimpleUnitConverter(2 / stage_inch)), + fxPx(L"px", new TSimpleUnitConverter(1)); fxInch.addExtension(L"inch"); fxInch.addExtension(L"\""); fxInch.addExtension(L"''"); fxInch.setDefaultExtension(L"\""); fxXfld.addExtension(L"field"); fxXfld.addExtension(L"F"); + fxPx.addExtension(L"pixel"); m = new TMeasure("fxLength", fxLength.clone()); m->add(fxInch.clone()); m->add(fxCm.clone()); m->add(fxMm.clone()); m->add(fxXfld.clone()); + m->add(fxPx.clone()); add(m); m = new TMeasure("angle", degree.clone()); diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index 1badd26c..188526a0 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -122,6 +122,14 @@ public: QString getStyleSheet(int index) const; int getStyleSheetCount() const; + void setPixelsOnly(bool state); + bool getPixelsOnly() const { return m_pixelsOnly; } + + void storeOldUnits(); + void resetOldUnits(); + QString getOldUnits() const { return m_oldUnits; } + QString getOldCameraUnits() const { return m_oldCameraUnits; } + void setUnits(std::string s); QString getUnits() const { return m_units; } @@ -410,7 +418,8 @@ private: std::vector m_levelFormats; - QString m_units, m_cameraUnits, m_scanLevelType, m_currentRoomChoice; + QString m_units, m_cameraUnits, m_scanLevelType, m_currentRoomChoice, + m_oldUnits, m_oldCameraUnits; double m_defLevelWidth, m_defLevelHeight, m_defLevelDpi; @@ -432,7 +441,7 @@ private: m_generatedMovieViewEnabled, m_xsheetAutopanEnabled, m_ignoreAlphaonColumn1Enabled, m_previewAlwaysOpenNewFlipEnabled, m_rewindAfterPlaybackEnabled, m_fitToFlipbookEnabled, m_autosaveEnabled, - m_defaultViewerEnabled; + m_defaultViewerEnabled, m_pixelsOnly; bool m_rasterOptimizedMemory, m_saveUnpaintedInCleanup, m_askForOverrideRender, m_automaticSVNFolderRefreshEnabled, m_SVNEnabled, m_levelsBackupEnabled, m_minimizeSaveboxAfterEditing, diff --git a/toonz/sources/include/toonz/stage.h b/toonz/sources/include/toonz/stage.h index b25ad606..af6f99e1 100644 --- a/toonz/sources/include/toonz/stage.h +++ b/toonz/sources/include/toonz/stage.h @@ -43,6 +43,7 @@ namespace Stage { //============================================================================= DVVAR extern const double inch; +DVVAR extern const double vectorDpi; class Visitor; struct VisitArgs; diff --git a/toonz/sources/include/toonz/tcamera.h b/toonz/sources/include/toonz/tcamera.h index 79aeef50..3bf62b71 100644 --- a/toonz/sources/include/toonz/tcamera.h +++ b/toonz/sources/include/toonz/tcamera.h @@ -39,7 +39,8 @@ class DVAPI TCamera { public: /*! Constructs TCamera with default value, size (12,9) and resolution (768,576). - Constructs TCamera with default value, size (12,9) and resolution (1920,1080). + Constructs TCamera with default value, size (36, 20.25) and resolution +(1920,1080). - 05/31/16 */ TCamera(); diff --git a/toonz/sources/include/toonzqt/camerasettingswidget.h b/toonz/sources/include/toonzqt/camerasettingswidget.h index 14f7f2db..5cf3e0c2 100644 --- a/toonz/sources/include/toonzqt/camerasettingswidget.h +++ b/toonz/sources/include/toonzqt/camerasettingswidget.h @@ -28,6 +28,7 @@ class TCamera; class QRadioButton; class QComboBox; +class QLabel; class ResListManager; class TFilePath; class TXshSimpleLevel; @@ -82,6 +83,9 @@ class DVAPI CameraSettingsWidget final : public QFrame { double m_arValue; DVGui::IntLineEdit *m_xResFld, *m_yResFld; DVGui::DoubleLineEdit *m_xDpiFld, *m_yDpiFld; + QLabel *m_dpiLabel; + QLabel *m_resLabel; + QLabel *m_xLabel; QPushButton *m_fspChk; // Force Squared Pixel => dpix == dpiy @@ -147,6 +151,7 @@ public: protected: bool eventFilter(QObject *obj, QEvent *e) override; + void showEvent(QShowEvent *e) override; void hComputeLx(); void hComputeLy(); diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp index 75ba35dd..f19ee3be 100644 --- a/toonz/sources/tnztools/tooloptions.cpp +++ b/toonz/sources/tnztools/tooloptions.cpp @@ -1830,6 +1830,14 @@ RulerToolOptionsBox::RulerToolOptionsBox(QWidget *parent, TTool *tool) m_Afld->setMeasure("angle"); + if (Preferences::instance()->getUnits() == "pixel") { + m_Xfld->setMeasure("length.x"); + m_Yfld->setMeasure("length.y"); + m_Wfld->setMeasure("length.x"); + m_Hfld->setMeasure("length.y"); + m_Lfld->setMeasure("length.x"); + } + m_Xfld->setObjectName("RulerToolOptionValues"); m_Yfld->setObjectName("RulerToolOptionValues"); m_Wfld->setObjectName("RulerToolOptionValues"); diff --git a/toonz/sources/toonz/exportlevelpopup.cpp b/toonz/sources/toonz/exportlevelpopup.cpp index 3dfa0d98..35cef834 100644 --- a/toonz/sources/toonz/exportlevelpopup.cpp +++ b/toonz/sources/toonz/exportlevelpopup.cpp @@ -393,7 +393,19 @@ void ExportLevelPopup::showEvent(QShowEvent *se) { { TSelectionHandle *selectionHandle = TApp::instance()->getCurrentSelection(); TSelection *selection = selectionHandle->getSelection(); - + if (Preferences::instance()->getPixelsOnly()) { + m_exportOptions->m_widthFld->hide(); + m_exportOptions->m_heightFld->hide(); + m_exportOptions->m_widthLabel->hide(); + m_exportOptions->m_heightLabel->hide(); + m_exportOptions->m_dpiLabel->hide(); + } else { + m_exportOptions->m_widthFld->show(); + m_exportOptions->m_heightFld->show(); + m_exportOptions->m_widthLabel->show(); + m_exportOptions->m_heightLabel->show(); + m_exportOptions->m_dpiLabel->show(); + } selectionHandle->pushSelection(); selectionHandle->setSelection(selection); } @@ -730,6 +742,10 @@ ExportLevelPopup::ExportOptions::ExportOptions(QWidget *parent) m_hResFld = new DVGui::IntLineEdit; m_vResFld = new DVGui::IntLineEdit; m_dpiLabel = new QLabel; + m_widthLabel = new QLabel; + m_heightLabel = new QLabel; + m_widthLabel->setText("Width: "); + m_heightLabel->setText("Height: "); m_resScale = new DVGui::MeasuredDoubleLineEdit; m_widthFld->setRange(0, dmax); @@ -746,12 +762,9 @@ ExportLevelPopup::ExportOptions::ExportOptions(QWidget *parent) m_vResFld->setFixedSize(50, 20); m_hResFld->setFixedSize(50, 20); m_resScale->setFixedSize(50, 20); - - exportBoxLayout->addWidget(new QLabel(tr("Width:")), 0, 0, - Qt::AlignRight); + exportBoxLayout->addWidget(m_widthLabel, 0, 0, Qt::AlignRight); exportBoxLayout->addWidget(m_widthFld, 0, 1, Qt::AlignLeft); - exportBoxLayout->addWidget(new QLabel(tr("Height:")), 0, 2, - Qt::AlignRight); + exportBoxLayout->addWidget(m_heightLabel, 0, 2, Qt::AlignRight); exportBoxLayout->addWidget(m_heightFld, 0, 3, Qt::AlignLeft); exportBoxLayout->addWidget(m_dpiLabel, 0, 4, Qt::AlignRight); exportBoxLayout->addWidget(new QLabel(tr("H Resolution:")), 1, 0, diff --git a/toonz/sources/toonz/exportlevelpopup.h b/toonz/sources/toonz/exportlevelpopup.h index 4980cd36..5d87e04e 100644 --- a/toonz/sources/toonz/exportlevelpopup.h +++ b/toonz/sources/toonz/exportlevelpopup.h @@ -141,7 +141,7 @@ private: DVGui::MeasuredDoubleLineEdit *m_resScale; - QLabel *m_dpiLabel; + QLabel *m_dpiLabel, *m_widthLabel, *m_heightLabel; QComboBox *m_thicknessTransformMode; diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cpp index 69bf2b7f..106c7e2f 100644 --- a/toonz/sources/toonz/iocommand.cpp +++ b/toonz/sources/toonz/iocommand.cpp @@ -1257,7 +1257,8 @@ bool IoCmd::saveSceneIfNeeded(QString msg) { void IoCmd::newScene() { RenderingSuspender suspender; TApp *app = TApp::instance(); - double cameraDpi = 64.0; + double cameraDpi = 53.33333; // used to be 64, consider changing to 120 or + // 160 if (!saveSceneIfNeeded(QApplication::tr("New Scene"))) return; IconGenerator::instance()->clearRequests(); @@ -1286,6 +1287,13 @@ void IoCmd::newScene() { TDimensionD((double)res.lx / cameraDpi, (double)res.ly / cameraDpi)); scene->getProperties()->setBgColor(TPixel32::White); TProjectManager::instance()->initializeScene(scene); + if (Preferences::instance()->getPixelsOnly()) + { + TCamera *updateCamera = scene->getCurrentCamera(); + TDimension updateRes = updateCamera->getRes(); + updateCamera->setSize( + TDimensionD((double)updateRes.lx / cameraDpi, (double)updateRes.ly / cameraDpi)); + } // Must set current scene after initializeScene!! app->getCurrentScene()->setScene(scene); // initializeScene() load project cleanup palette: set it to cleanup palette diff --git a/toonz/sources/toonz/levelcreatepopup.cpp b/toonz/sources/toonz/levelcreatepopup.cpp index c47cdefd..8442974e 100644 --- a/toonz/sources/toonz/levelcreatepopup.cpp +++ b/toonz/sources/toonz/levelcreatepopup.cpp @@ -194,8 +194,14 @@ LevelCreatePopup::LevelCreatePopup() m_levelTypeOm->addItem(RasterLevel); m_levelTypeOm->addItem(ScanLevel); - m_widthFld->setMeasure("level.lx"); - m_heightFld->setMeasure("level.ly"); + if (Preferences::instance()->getUnits() == "pixel") { + m_widthFld->setMeasure("camera.lx"); + m_heightFld->setMeasure("camera.ly"); + } else { + m_widthFld->setMeasure("level.lx"); + m_heightFld->setMeasure("level.ly"); + } + m_widthFld->setRange(0.1, (std::numeric_limits::max)()); m_heightFld->setRange(0.1, (std::numeric_limits::max)()); m_dpiFld->setRange(0.1, (std::numeric_limits::max)()); @@ -329,6 +335,13 @@ void LevelCreatePopup::showEvent(QShowEvent *) { nextName(); update(); m_nameFld->setFocus(); + if (Preferences::instance()->getUnits() == "pixel") { + m_dpiFld->hide(); + m_dpiLabel->hide(); + } else { + m_dpiFld->show(); + m_dpiLabel->show(); + } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/levelsettingspopup.cpp b/toonz/sources/toonz/levelsettingspopup.cpp index 35d413c8..cf7bdc4a 100644 --- a/toonz/sources/toonz/levelsettingspopup.cpp +++ b/toonz/sources/toonz/levelsettingspopup.cpp @@ -132,6 +132,9 @@ LevelSettingsPopup::LevelSettingsPopup() m_cameraDpiLabel = new QLabel(tr("")); m_imageDpiLabel = new QLabel(tr("")); m_imageResLabel = new QLabel(tr("")); + m_cameraDpiTitle = new QLabel(tr("Camera DPI:")); + m_imageDpiTitle = new QLabel(tr("Image DPI:")); + m_imageResTitle = new QLabel(tr("Resolution:")); // subsampling m_subsamplingLabel = new QLabel(tr("Subsampling:")); @@ -159,6 +162,11 @@ LevelSettingsPopup::LevelSettingsPopup() m_widthFld->setMeasure("camera.lx"); m_heightFld->setMeasure("camera.ly"); + if (Preferences::instance()->getCameraUnits() == "pixel") { + m_widthFld->setDecimals(0); + m_heightFld->setDecimals(0); + } + m_doPremultiply->setChecked(false); m_doAntialias->setChecked(false); @@ -195,7 +203,11 @@ LevelSettingsPopup::LevelSettingsPopup() m_topLayout->addWidget(nameBox); //----DPI & Resolution - QGroupBox *dpiBox = new QGroupBox(tr("DPI && Resolution"), this); + QGroupBox *dpiBox; + if (Preferences::instance()->getUnits() == "pixel") + dpiBox = new QGroupBox(tr("Resolution"), this); + else + dpiBox = new QGroupBox(tr("DPI && Resolution"), this); QGridLayout *dpiLayout = new QGridLayout(); dpiLayout->setMargin(5); dpiLayout->setSpacing(5); @@ -212,13 +224,13 @@ LevelSettingsPopup::LevelSettingsPopup() Qt::AlignRight | Qt::AlignVCenter); dpiLayout->addWidget(m_heightFld, 2, 3); dpiLayout->addWidget(m_useCameraDpiBtn, 3, 1, 1, 3); - dpiLayout->addWidget(new QLabel(tr("Camera DPI:"), this), 4, 0, + dpiLayout->addWidget(m_cameraDpiTitle, 4, 0, Qt::AlignRight | Qt::AlignVCenter); dpiLayout->addWidget(m_cameraDpiLabel, 4, 1, 1, 3); - dpiLayout->addWidget(new QLabel(tr("Image DPI:"), this), 5, 0, + dpiLayout->addWidget(m_imageDpiTitle, 5, 0, Qt::AlignRight | Qt::AlignVCenter); dpiLayout->addWidget(m_imageDpiLabel, 5, 1, 1, 3); - dpiLayout->addWidget(new QLabel(tr("Resolution:"), this), 6, 0, + dpiLayout->addWidget(m_imageResTitle, 6, 0, Qt::AlignRight | Qt::AlignVCenter); dpiLayout->addWidget(m_imageResLabel, 6, 1, 1, 3); } @@ -307,6 +319,31 @@ void LevelSettingsPopup::showEvent(QShowEvent *e) { assert(ret); updateLevelSettings(); + if (Preferences::instance()->getUnits() == "pixel") { + m_dpiTypeOm->hide(); + m_dpiLabel->hide(); + m_dpiFld->hide(); + m_squarePixCB->hide(); + m_useCameraDpiBtn->hide(); + m_cameraDpiLabel->hide(); + m_imageDpiLabel->hide(); + m_imageDpiTitle->hide(); + m_cameraDpiTitle->hide(); + m_imageResTitle->hide(); + m_imageResLabel->hide(); + } else { + m_dpiTypeOm->show(); + m_dpiLabel->show(); + m_dpiFld->show(); + m_squarePixCB->show(); + m_useCameraDpiBtn->show(); + m_cameraDpiLabel->show(); + m_imageDpiLabel->show(); + m_imageDpiTitle->show(); + m_cameraDpiTitle->show(); + m_imageResTitle->show(); + m_imageResLabel->show(); + } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/levelsettingspopup.h b/toonz/sources/toonz/levelsettingspopup.h index 955ce107..a93d2149 100644 --- a/toonz/sources/toonz/levelsettingspopup.h +++ b/toonz/sources/toonz/levelsettingspopup.h @@ -56,6 +56,9 @@ class LevelSettingsPopup final : public DVGui::Dialog { QLabel *m_cameraDpiLabel; QLabel *m_imageDpiLabel; QLabel *m_imageResLabel; + QLabel *m_cameraDpiTitle; + QLabel *m_imageDpiTitle; + QLabel *m_imageResTitle; DVGui::CheckBox *m_doPremultiply; DVGui::CheckBox *m_whiteTransp; DVGui::CheckBox *m_doAntialias; diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index 77137805..c7cbfce1 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -7,6 +7,7 @@ #include "versioncontrol.h" #include "levelsettingspopup.h" #include "tapp.h" +#include "cleanupsettingsmodel.h" // TnzQt includes #include "toonzqt/tabbar.h" @@ -22,6 +23,8 @@ #include "toonz/txshlevelhandle.h" #include "toonz/txshleveltypes.h" #include "toonz/tscenehandle.h" +#include "toonz/toonzscene.h" +#include "toonz/tcamera.h" #include "toonz/levelproperties.h" #include "toonz/tonionskinmaskhandle.h" @@ -211,13 +214,77 @@ Preferences::LevelFormat PreferencesPopup::FormatProperties::levelFormat() // PreferencesPopup implementation //********************************************************************************** +void PreferencesPopup::onPixelsOnlyChanged(int index) { + bool enabled = index == Qt::Checked; + if (enabled) { + m_pref->setDefLevelDpi(53.33333); + m_pref->setPixelsOnly(true); + TCamera *camera; + camera = + TApp::instance()->getCurrentScene()->getScene()->getCurrentCamera(); + TDimension camRes = camera->getRes(); + TDimensionD camSize; + camSize.lx = camRes.lx / 53.33333; + camSize.ly = camRes.ly / 53.33333; + camera->setSize(camSize); + TDimension cleanupRes = CleanupSettingsModel::instance()->getCurrentParameters()->m_camera.getRes(); + TDimensionD cleanupSize; + cleanupSize.lx = cleanupRes.lx / 53.33333; + cleanupSize.ly = cleanupRes.ly / 53.33333; + CleanupSettingsModel::instance()->getCurrentParameters()->m_camera.setSize(cleanupSize); + m_pref->storeOldUnits(); + if (m_unitOm->currentIndex() != 4) m_unitOm->setCurrentIndex(4); + if (m_cameraUnitOm->currentIndex() != 4) m_cameraUnitOm->setCurrentIndex(4); + m_unitOm->setDisabled(true); + m_cameraUnitOm->setDisabled(true); + m_defLevelDpi->setDisabled(true); + m_defLevelDpi->setValue(53.33333); + m_defLevelWidth->setMeasure("camera.lx"); + m_defLevelHeight->setMeasure("camera.ly"); + m_defLevelWidth->setValue(m_pref->getDefLevelWidth()); + m_defLevelHeight->setValue(m_pref->getDefLevelHeight()); + m_defLevelHeight->setDecimals(0); + m_defLevelWidth->setDecimals(0); + + } else { + QString tempUnit; + int unitIndex; + tempUnit = m_pref->getOldUnits(); + unitIndex = m_unitOm->findText(tempUnit); + m_unitOm->setCurrentIndex(unitIndex); + tempUnit = m_pref->getOldCameraUnits(); + unitIndex = m_cameraUnitOm->findText(tempUnit); + m_cameraUnitOm->setCurrentIndex(unitIndex); + m_unitOm->setDisabled(false); + m_cameraUnitOm->setDisabled(false); + m_pref->setPixelsOnly(false); + int levelType = m_pref->getDefLevelType(); + bool isRaster = levelType != PLI_XSHLEVEL; + if (isRaster) { + m_defLevelDpi->setDisabled(false); + } + m_defLevelHeight->setMeasure("level.ly"); + m_defLevelWidth->setMeasure("level.lx"); + m_defLevelWidth->setValue(m_pref->getDefLevelWidth()); + m_defLevelHeight->setValue(m_pref->getDefLevelHeight()); + m_defLevelHeight->setDecimals(4); + m_defLevelWidth->setDecimals(4); + } +} + void PreferencesPopup::onUnitChanged(int index) { + if (index == 4 && m_pixelsOnlyCB->isChecked() == false) { + m_pixelsOnlyCB->setCheckState(Qt::Checked); + } m_pref->setUnits(::units[index].toStdString()); } //----------------------------------------------------------------------------- void PreferencesPopup::onCameraUnitChanged(int index) { + if (index == 4 && m_pixelsOnlyCB->isChecked() == false) { + m_pixelsOnlyCB->setChecked(true); + } m_pref->setCameraUnits(::units[index].toStdString()); } @@ -673,7 +740,7 @@ void PreferencesPopup::onDefLevelTypeChanged(int index) { bool isRaster = levelType != PLI_XSHLEVEL; m_defLevelWidth->setEnabled(isRaster); m_defLevelHeight->setEnabled(isRaster); - m_defLevelDpi->setEnabled(isRaster); + if (!m_pixelsOnlyCB->isChecked()) m_defLevelDpi->setEnabled(isRaster); } } @@ -834,8 +901,11 @@ PreferencesPopup::PreferencesPopup() languageType->setCurrentIndex(currentIndex); } QComboBox *styleSheetType = new QComboBox(this); - QComboBox *unitOm = new QComboBox(this); - QComboBox *cameraUnitOm = new QComboBox(this); + m_pixelsOnlyCB = + new CheckBox(tr("All imported images will use the same DPI"), this); + m_unitOm = new QComboBox(this); + m_cameraUnitOm = new QComboBox(this); + // Choose between standard and Studio Ghibli rooms QComboBox *roomChoice = new QComboBox(this); @@ -910,7 +980,7 @@ PreferencesPopup::PreferencesPopup() m_defLevelHeight = new MeasuredDoubleLineEdit(0); m_defLevelDpi = new DoubleLineEdit(0, 66.76); m_autocreationType = new QComboBox(this); - + m_dpiLabel = new QLabel(tr("DPI:"), this); CheckBox *keepOriginalCleanedUpCB = new CheckBox(tr("Keep Original Cleaned Up Drawings As Backup"), this); CheckBox *multiLayerStylePickerCB = new CheckBox( @@ -1014,18 +1084,24 @@ PreferencesPopup::PreferencesPopup() } styleSheetType->addItems(styleSheetList); styleSheetType->setCurrentIndex(currentIndex); - + bool po = m_pref->getPixelsOnly(); + m_pixelsOnlyCB->setChecked(po); + // m_pixelsOnlyCB->setChecked(true); + if (po) { + m_unitOm->setDisabled(true); + m_cameraUnitOm->setDisabled(true); + } QStringList type; - type << tr("cm") << tr("mm") << tr("inch") << tr("field"); - unitOm->addItems(type); + type << tr("cm") << tr("mm") << tr("inch") << tr("field") << tr("pixel"); + m_unitOm->addItems(type); int idx = std::find(::units, ::units + ::unitsCount, m_pref->getUnits()) - ::units; - unitOm->setCurrentIndex((idx < ::unitsCount) ? idx : ::inchIdx); - cameraUnitOm->addItems(type); + m_unitOm->setCurrentIndex((idx < ::unitsCount) ? idx : ::inchIdx); + m_cameraUnitOm->addItems(type); idx = std::find(::units, ::units + ::unitsCount, m_pref->getCameraUnits()) - ::units; - cameraUnitOm->setCurrentIndex((idx < ::unitsCount) ? idx : ::inchIdx); + m_cameraUnitOm->setCurrentIndex((idx < ::unitsCount) ? idx : ::inchIdx); QStringList roomList; int currentRoomIndex = 0; @@ -1121,12 +1197,21 @@ PreferencesPopup::PreferencesPopup() } } - m_defLevelWidth->setRange(0.1, (std::numeric_limits::max)()); - m_defLevelWidth->setMeasure("level.lx"); - m_defLevelWidth->setValue(m_pref->getDefLevelWidth()); - m_defLevelHeight->setRange(0.1, (std::numeric_limits::max)()); - m_defLevelHeight->setMeasure("level.ly"); - m_defLevelHeight->setValue(m_pref->getDefLevelHeight()); + if (Preferences::instance()->getUnits() == "pixel") { + m_defLevelWidth->setRange(0.1, (std::numeric_limits::max)()); + m_defLevelWidth->setMeasure("camera.lx"); + m_defLevelWidth->setValue(m_pref->getDefLevelWidth()); + m_defLevelHeight->setRange(0.1, (std::numeric_limits::max)()); + m_defLevelHeight->setMeasure("camera.ly"); + m_defLevelHeight->setValue(m_pref->getDefLevelHeight()); + } else { + m_defLevelWidth->setRange(0.1, (std::numeric_limits::max)()); + m_defLevelWidth->setMeasure("level.lx"); + m_defLevelWidth->setValue(m_pref->getDefLevelWidth()); + m_defLevelHeight->setRange(0.1, (std::numeric_limits::max)()); + m_defLevelHeight->setMeasure("level.ly"); + m_defLevelHeight->setValue(m_pref->getDefLevelHeight()); + } m_defLevelDpi->setRange(0.1, (std::numeric_limits::max)()); m_defLevelDpi->setValue(m_pref->getDefLevelDpi()); QStringList autocreationTypes; @@ -1261,17 +1346,21 @@ PreferencesPopup::PreferencesPopup() Qt::AlignRight | Qt::AlignVCenter); styleLay->addWidget(styleSheetType, 0, 1); - styleLay->addWidget(new QLabel(tr("Unit:"), this), 1, 0, + styleLay->addWidget(new QLabel(tr("Pixels Only:"), this), 1, 0, Qt::AlignRight | Qt::AlignVCenter); - styleLay->addWidget(unitOm, 1, 1); + styleLay->addWidget(m_pixelsOnlyCB, 1, 1); - styleLay->addWidget(new QLabel(tr("Camera Unit:"), this), 2, 0, + styleLay->addWidget(new QLabel(tr("Unit:"), this), 2, 0, Qt::AlignRight | Qt::AlignVCenter); - styleLay->addWidget(cameraUnitOm, 2, 1); + styleLay->addWidget(m_unitOm, 2, 1); - styleLay->addWidget(new QLabel(tr("Rooms *:"), this), 3, 0, + styleLay->addWidget(new QLabel(tr("Camera Unit:"), this), 3, 0, Qt::AlignRight | Qt::AlignVCenter); - styleLay->addWidget(roomChoice, 3, 1); + styleLay->addWidget(m_cameraUnitOm, 3, 1); + + styleLay->addWidget(new QLabel(tr("Rooms*:"), this), 4, 0, + Qt::AlignRight | Qt::AlignVCenter); + styleLay->addWidget(roomChoice, 4, 1); } styleLay->setColumnStretch(0, 0); styleLay->setColumnStretch(1, 0); @@ -1441,10 +1530,8 @@ PreferencesPopup::PreferencesPopup() drawingTopLay->addWidget(new QLabel(tr(" Height:")), 2, 2, Qt::AlignRight); drawingTopLay->addWidget(m_defLevelHeight, 2, 3); - - drawingTopLay->addWidget(new QLabel(tr("DPI:")), 3, 0, Qt::AlignRight); + drawingTopLay->addWidget(m_dpiLabel, 3, 0, Qt::AlignRight); drawingTopLay->addWidget(m_defLevelDpi, 3, 1); - drawingTopLay->addWidget(new QLabel(tr("Autocreation:")), 4, 0, Qt::AlignRight); drawingTopLay->addWidget(m_autocreationType, 4, 1, 1, 3); @@ -1463,6 +1550,11 @@ PreferencesPopup::PreferencesPopup() } drawingBox->setLayout(drawingFrameLay); stackedWidget->addWidget(drawingBox); + if (m_pixelsOnlyCB->isChecked()) { + m_defLevelDpi->setDisabled(true); + m_defLevelWidth->setDecimals(0); + m_defLevelHeight->setDecimals(0); + } //--- Xsheet -------------------------- QWidget *xsheetBox = new QWidget(this); @@ -1662,9 +1754,11 @@ PreferencesPopup::PreferencesPopup() //--- Interface ---------------------- ret = ret && connect(styleSheetType, SIGNAL(currentIndexChanged(int)), SLOT(onStyleSheetTypeChanged(int))); - ret = ret && connect(unitOm, SIGNAL(currentIndexChanged(int)), + ret = ret && connect(m_pixelsOnlyCB, SIGNAL(stateChanged(int)), + SLOT(onPixelsOnlyChanged(int))); + ret = ret && connect(m_unitOm, SIGNAL(currentIndexChanged(int)), SLOT(onUnitChanged(int))); - ret = ret && connect(cameraUnitOm, SIGNAL(currentIndexChanged(int)), + ret = ret && connect(m_cameraUnitOm, SIGNAL(currentIndexChanged(int)), SLOT(onCameraUnitChanged(int))); ret = ret && connect(roomChoice, SIGNAL(currentIndexChanged(int)), SLOT(onRoomChoiceChanged(int))); diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index 4fd3d15f..07f0c9de 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -51,12 +51,14 @@ private: QComboBox *m_keyframeType, *m_cellsDragBehaviour, *m_defScanLevelType, *m_defLevelType, *m_autocreationType, *m_levelFormatNames, - *m_columnIconOm; + *m_columnIconOm, *m_unitOm, *m_cameraUnitOm; DVGui::MeasuredDoubleLineEdit *m_defLevelWidth, *m_defLevelHeight; DVGui::DoubleLineEdit *m_defLevelDpi; + QLabel *m_dpiLabel; + DVGui::IntLineEdit *m_minuteFld, *m_chunkSizeFld, *m_iconSizeLx, *m_iconSizeLy, *m_viewShrink, *m_viewStep, *m_blanksCount, *m_onionPaperThickness, *m_animationStepField, *m_undoMemorySize, @@ -65,7 +67,7 @@ private: QPushButton *m_addLevelFormat, *m_removeLevelFormat, *m_editLevelFormat; DVGui::CheckBox *m_inksOnly, *m_enableVersionControl, *m_levelsBackup, - *m_onionSkinVisibility; + *m_onionSkinVisibility, *m_pixelsOnlyCB; private: // QWidget* create(const QString& lbl, bool def, const char* slot); @@ -73,6 +75,7 @@ private: private slots: + void onPixelsOnlyChanged(int index); void onUnitChanged(int index); void onCameraUnitChanged(int index); void onRoomChoiceChanged(int index); diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index e5fd106d..5f73e5d1 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -208,7 +208,8 @@ bool Preferences::LevelFormat::matches(const TFilePath &fp) const { //********************************************************************************** Preferences::Preferences() - : m_units("mm") + : m_pixelsOnly(false) + , m_units("mm") , m_cameraUnits("inch") , m_currentRoomChoice("Default") , m_scanLevelType("tif") @@ -373,7 +374,21 @@ Preferences::Preferences() setUndoMemorySize(m_undoMemorySize); m_blankColor = TPixel32(r, g, b); + // for Pixels only + + getValue(*m_settings, "pixelsOnly", + m_pixelsOnly); // doesn't work for some reason. + QString pos = m_settings->value("pixelsOnly").toString(); + if (pos == "true") m_pixelsOnly = true; + QString units; + units = m_settings->value("oldUnits", m_units).toString(); + m_oldUnits = units; + + units = m_settings->value("oldCameraUnits", m_cameraUnits).toString(); + m_oldCameraUnits = units; + // end for pixels only + units = m_settings->value("linearUnits").toString(); if (units != "") m_units = units; setUnits(m_units.toStdString()); @@ -929,6 +944,18 @@ static void setCurrentUnits(std::string measureName, std::string units) { //----------------------------------------------------------------- +void Preferences::setPixelsOnly(bool state) { + m_pixelsOnly = state; + m_settings->setValue("pixelsOnly", m_pixelsOnly); + if (state) { + storeOldUnits(); + } else { + resetOldUnits(); + } +} + +//----------------------------------------------------------------- + void Preferences::setUnits(std::string units) { m_units = QString::fromStdString(units); m_settings->setValue("linearUnits", m_units); @@ -952,6 +979,24 @@ void Preferences::setCameraUnits(std::string units) { //----------------------------------------------------------------- +void Preferences::storeOldUnits() { + m_oldUnits = getUnits(); + m_oldCameraUnits = getCameraUnits(); + m_settings->setValue("oldUnits", m_oldUnits); + m_settings->setValue("oldCameraUnits", m_oldCameraUnits); +} + +//----------------------------------------------------------------- + +void Preferences::resetOldUnits() { + if (m_oldUnits != "" && m_oldCameraUnits != "") { + setUnits(m_oldUnits.toStdString()); + setCameraUnits(m_oldCameraUnits.toStdString()); + } +} + +//----------------------------------------------------------------- + void Preferences::setCurrentRoomChoice(int currentRoomChoice) { m_currentRoomChoice = getRoomChoice(currentRoomChoice); m_settings->setValue("CurrentRoomChoice", m_currentRoomChoice); diff --git a/toonz/sources/toonzlib/stage.cpp b/toonz/sources/toonzlib/stage.cpp index 08e3d199..3c9610a9 100644 --- a/toonz/sources/toonzlib/stage.cpp +++ b/toonz/sources/toonzlib/stage.cpp @@ -69,7 +69,8 @@ typedef std::vector PlayerSet; thickness of images .pli. */ -const double Stage::inch = 53.33333; +const double Stage::inch = 53.33333; // consider changing to 120 or 160 +const double Stage::vectorDpi = 53.3333; namespace { void updateOnionSkinSize(const PlayerSet &players) { diff --git a/toonz/sources/toonzlib/tcamera.cpp b/toonz/sources/toonzlib/tcamera.cpp index 365e4710..97726621 100644 --- a/toonz/sources/toonzlib/tcamera.cpp +++ b/toonz/sources/toonzlib/tcamera.cpp @@ -10,7 +10,7 @@ TCamera::TCamera() //: m_size(12, 9), m_res(768, 576), m_xPrevalence(true) - : m_size(30, 16.875), + : m_size(36, 20.25), m_res(1920, 1080), m_xPrevalence(true) {} diff --git a/toonz/sources/toonzlib/toonzscene.cpp b/toonz/sources/toonzlib/toonzscene.cpp index 61e98cd7..e4125adc 100644 --- a/toonz/sources/toonzlib/toonzscene.cpp +++ b/toonz/sources/toonzlib/toonzscene.cpp @@ -1176,7 +1176,8 @@ TXshLevel *ToonzScene::loadLevel(const TFilePath &actualPath, // We must check whether the image actually has a dpi. const TPointD &imageDpi = xl->getImageDpi(); - if (imageDpi == TPointD()) { + if (imageDpi == TPointD() || + Preferences::instance()->getUnits() == "pixel") { // Change to "Custom Dpi" policy and use camera dpi TStageObjectId cameraId = getXsheet()->getStageObjectTree()->getCurrentCameraId(); diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp index edb8df69..173c33ef 100644 --- a/toonz/sources/toonzlib/txshsimplelevel.cpp +++ b/toonz/sources/toonzlib/txshsimplelevel.cpp @@ -2169,9 +2169,8 @@ TFilePath TXshSimpleLevel::getExistingHookFile( } assert(h >= 0); - return (h < 0) ? TFilePath() - : decodedLevelPath.getParentDir() + - TFilePath(hookFiles[h].toStdWString()); + return (h < 0) ? TFilePath() : decodedLevelPath.getParentDir() + + TFilePath(hookFiles[h].toStdWString()); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonzqt/camerasettingswidget.cpp b/toonz/sources/toonzqt/camerasettingswidget.cpp index 705ff6fb..4c531d39 100644 --- a/toonz/sources/toonzqt/camerasettingswidget.cpp +++ b/toonz/sources/toonzqt/camerasettingswidget.cpp @@ -20,6 +20,7 @@ #include "toonz/txshlevel.h" #include "toonz/txshsimplelevel.h" #include "toonz/txshleveltypes.h" +#include "toonz/preferences.h" // TnzCore includes #include "tconvert.h" @@ -193,6 +194,10 @@ CameraSettingsWidget::CameraSettingsWidget(bool forCleanup) m_xDpiFld = new DoubleLineEdit(); m_yDpiFld = new DoubleLineEdit(); + m_dpiLabel = new QLabel(tr("DPI")); + m_resLabel = new QLabel(tr("Pixels")); + m_xLabel = new QLabel(tr("x")); + m_fspChk = new QPushButton(""); m_useLevelSettingsBtn = new QPushButton(tr("Use Current Level Settings")); @@ -277,7 +282,8 @@ CameraSettingsWidget::CameraSettingsWidget(bool forCleanup) gridLay->addWidget(m_yPrev, 0, 4, Qt::AlignCenter); gridLay->addWidget(m_inchPrev, 1, 0, Qt::AlignRight | Qt::AlignVCenter); - gridLay->addWidget(new QLabel("Inch"), 1, 1, + QString units = Preferences::instance()->getCameraUnits(); + gridLay->addWidget(new QLabel(units), 1, 1, Qt::AlignRight | Qt::AlignVCenter); gridLay->addWidget(m_lxFld, 1, 2); gridLay->addWidget(new QLabel("x"), 1, 3, Qt::AlignCenter); @@ -288,14 +294,12 @@ CameraSettingsWidget::CameraSettingsWidget(bool forCleanup) gridLay->addWidget(m_arFld, 2, 4); gridLay->addWidget(m_dotPrev, 3, 0, Qt::AlignRight | Qt::AlignVCenter); - gridLay->addWidget(new QLabel("Pixel"), 3, 1, - Qt::AlignRight | Qt::AlignVCenter); + gridLay->addWidget(m_resLabel, 3, 1, Qt::AlignRight | Qt::AlignVCenter); gridLay->addWidget(m_xResFld, 3, 2); - gridLay->addWidget(new QLabel("x"), 3, 3, Qt::AlignCenter); + gridLay->addWidget(m_xLabel, 3, 3, Qt::AlignCenter); gridLay->addWidget(m_yResFld, 3, 4); - gridLay->addWidget(new QLabel("DPI"), 4, 1, - Qt::AlignRight | Qt::AlignVCenter); + gridLay->addWidget(m_dpiLabel, 4, 1, Qt::AlignRight | Qt::AlignVCenter); gridLay->addWidget(m_xDpiFld, 4, 2); gridLay->addWidget(m_fspChk, 4, 3, Qt::AlignCenter); gridLay->addWidget(m_yDpiFld, 4, 4); @@ -365,6 +369,30 @@ CameraSettingsWidget::CameraSettingsWidget(bool forCleanup) CameraSettingsWidget::~CameraSettingsWidget() { setCurrentLevel(0); } +void CameraSettingsWidget::showEvent(QShowEvent *e) { + if (Preferences::instance()->getCameraUnits() == "pixel") { + m_resLabel->hide(); + m_dpiLabel->hide(); + m_xLabel->hide(); + m_xResFld->hide(); + m_yResFld->hide(); + m_xDpiFld->hide(); + m_yDpiFld->hide(); + m_fspChk->hide(); + m_dotPrev->hide(); + } else { + m_resLabel->show(); + m_dpiLabel->show(); + m_xLabel->show(); + m_xResFld->show(); + m_yResFld->show(); + m_xDpiFld->show(); + m_yDpiFld->show(); + m_fspChk->show(); + m_dotPrev->show(); + } +} + void CameraSettingsWidget::loadPresetList() { if (m_presetListFile == "") return; m_presetListOm->clear();