From efbb4aa291647e1fcf061680575c9f3e2019c8bb Mon Sep 17 00:00:00 2001 From: manongjohn <19245851+manongjohn@users.noreply.github.com> Date: Tue, 19 Sep 2023 07:35:40 -0400 Subject: [PATCH] Control file history information --- toonz/sources/common/tcontenthistory.cpp | 22 ++++++--- toonz/sources/image/pli/pli_io.cpp | 7 ++- toonz/sources/image/tzl/tiio_tzl.cpp | 9 +++- toonz/sources/include/tcontenthistory.h | 4 +- .../include/toonz/preferencesitemids.h | 2 + toonz/sources/toonz/preferencespopup.cpp | 48 +++++++++++++++---- toonz/sources/toonz/preferencespopup.h | 8 +++- toonz/sources/toonzlib/preferences.cpp | 5 ++ toonz/sources/toonzlib/toonzscene.cpp | 8 +++- toonz/sources/toonzlib/txshsimplelevel.cpp | 5 +- toonz/sources/toonzqt/infoviewer.cpp | 8 +++- 11 files changed, 103 insertions(+), 23 deletions(-) diff --git a/toonz/sources/common/tcontenthistory.cpp b/toonz/sources/common/tcontenthistory.cpp index b3ad752f..8af67e1c 100644 --- a/toonz/sources/common/tcontenthistory.cpp +++ b/toonz/sources/common/tcontenthistory.cpp @@ -26,8 +26,12 @@ using namespace std; //------------------------------------------------------- -TContentHistory::TContentHistory(bool isLevel) - : m_isLevel(isLevel), m_frozenHistory() {} +TContentHistory::TContentHistory(bool isLevel, QString altUsername, + bool recordEdit) + : m_isLevel(isLevel) + , m_frozenHistory() + , m_altUsername(altUsername) + , m_recordEdit(recordEdit) {} //------------------------------------------------------- @@ -36,7 +40,8 @@ TContentHistory::~TContentHistory() {} //------------------------------------------------------- TContentHistory *TContentHistory::clone() const { - TContentHistory *history = new TContentHistory(m_isLevel); + TContentHistory *history = + new TContentHistory(m_isLevel, m_altUsername, m_recordEdit); history->deserialize(serialize()); return history; } @@ -84,7 +89,7 @@ inline QString getStr(const TFrameId &id) { const QString Fmt = "dd MMM yy hh:mm"; static QString getLine(int counter, const QDateTime &date, - const set &frames) { + const set &frames, QString altUsername) { static QString user; static QString machine; if (user == "") { @@ -97,6 +102,8 @@ static QString getLine(int counter, const QDateTime &date, else if (value.startsWith("COMPUTERNAME=")) machine = blanks(value.right(value.size() - 13)); } + + if (!altUsername.isEmpty()) user = blanks(altUsername); } if (frames.empty()) @@ -149,7 +156,9 @@ const QString TContentHistory::currentToString() const { if (!m_isLevel) { assert(m_records.size() == 1); - return getLine(++counter, m_records.begin()->second, set()); + if (!m_recordEdit) return ""; + return getLine(++counter, m_records.begin()->second, set(), + m_altUsername); } QString out; @@ -168,7 +177,8 @@ const QString TContentHistory::currentToString() const { ++it1; } assert(!frames.empty()); - out += getLine(++counter, currDate, frames); + if (m_recordEdit) + out += getLine(++counter, currDate, frames, m_altUsername); if (it1 != dateSorted.end()) currDate = it1->first; } diff --git a/toonz/sources/image/pli/pli_io.cpp b/toonz/sources/image/pli/pli_io.cpp index e0585402..ea28e6fe 100644 --- a/toonz/sources/image/pli/pli_io.cpp +++ b/toonz/sources/image/pli/pli_io.cpp @@ -12,6 +12,7 @@ //#include #include "../compatibility/tfile_io.h" #include "tenv.h" +#include "toonz/preferences.h" /*=====================================================================*/ @@ -700,7 +701,11 @@ void ParsedPliImp::loadInfo(bool readPlt, TPalette *&palette, m_iChan.seekg(pos, ios::beg); TagElem *tagElem = readTag(); TextTag *textTag = (TextTag *)tagElem->m_tag; - history = new TContentHistory(true); + QString altUsername = + Preferences::instance()->getStringValue(recordAsUsername); + bool recordEdit = + Preferences::instance()->getBoolValue(recordFileHistory); + history = new TContentHistory(true, altUsername, recordEdit); history->deserialize(QString::fromStdString(textTag->m_text)); delete tagElem; } diff --git a/toonz/sources/image/tzl/tiio_tzl.cpp b/toonz/sources/image/tzl/tiio_tzl.cpp index 306c8031..e30faf30 100644 --- a/toonz/sources/image/tzl/tiio_tzl.cpp +++ b/toonz/sources/image/tzl/tiio_tzl.cpp @@ -18,6 +18,7 @@ #include "tenv.h" #include "tconvert.h" #include "trasterimage.h" +#include "toonz/preferences.h" #include @@ -1501,7 +1502,13 @@ TLevelReaderTzl::TLevelReaderTzl(const TFilePath &path) fread(&historyData[0], 1, lSize, historyChan); fclose(historyChan); - if (!m_contentHistory) m_contentHistory = new TContentHistory(true); + if (!m_contentHistory) { + QString altUsername = + Preferences::instance()->getStringValue(recordAsUsername); + bool recordEdit = + Preferences::instance()->getBoolValue(recordFileHistory); + m_contentHistory = new TContentHistory(true, altUsername, recordEdit); + } m_contentHistory->deserialize(QString::fromStdString(historyData)); } diff --git a/toonz/sources/include/tcontenthistory.h b/toonz/sources/include/tcontenthistory.h index 6dbd810c..76782827 100644 --- a/toonz/sources/include/tcontenthistory.h +++ b/toonz/sources/include/tcontenthistory.h @@ -29,12 +29,14 @@ class DVAPI TContentHistory { bool m_isLevel; std::map m_records; QString m_frozenHistory; + QString m_altUsername; + bool m_recordEdit; const QString currentToString() const; public: //! set isLevel=true if you want to keep track of single-frames modifications - TContentHistory(bool isLevel); + TContentHistory(bool isLevel, QString altUsername, bool recordEdit); ~TContentHistory(); diff --git a/toonz/sources/include/toonz/preferencesitemids.h b/toonz/sources/include/toonz/preferencesitemids.h index b6e4be1a..35c20aaa 100644 --- a/toonz/sources/include/toonz/preferencesitemids.h +++ b/toonz/sources/include/toonz/preferencesitemids.h @@ -73,6 +73,8 @@ enum PreferencesItemId { rasterBackgroundColor, resetUndoOnSavingLevel, defaultProjectPath, + recordFileHistory, + recordAsUsername, //---------- // Import / Export diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index 9b4983f4..79b22f7f 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -651,6 +651,17 @@ void PreferencesPopup::onColorCalibrationChanged() { //----------------------------------------------------------------------------- +void PreferencesPopup::onRecordAsUserChanged() { + QString username = m_pref->getStringValue(recordAsUsername); + if (username.isEmpty()) { + username = TSystem::getUserName(); + m_pref->setValue(recordAsUsername, QVariant::fromValue(username)); + getUI(recordAsUsername)->setText(username); + } +} + +//----------------------------------------------------------------------------- + void PreferencesPopup::onDefLevelTypeChanged() { bool isRaster = m_pref->getIntValue(DefLevelType) != PLI_XSHLEVEL && !m_pref->getBoolValue(newLevelSizeToCameraSizeEnabled); @@ -971,7 +982,8 @@ void PreferencesPopup::onImportPolicyExternallyChanged(int policy) { //----------------------------------------------------------------------------- QWidget* PreferencesPopup::createUI(PreferencesItemId id, - const QList& comboItems) { + const QList& comboItems, + bool isLineEdit) { PreferencesItem item = m_pref->getItem(id); // create widget depends on the parameter types QWidget* widget = nullptr; @@ -1039,6 +1051,12 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id, ret = connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(onChange())); widget = combo; + } else if (isLineEdit) { // create LineEdit + DVGui::LineEdit* lineEdit = + new DVGui::LineEdit(item.value.toString(), this); + ret = + connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(onChange())); + widget = lineEdit; } else { // create FileField DVGui::FileField* field = new DVGui::FileField(this, item.value.toString()); @@ -1115,16 +1133,18 @@ QGridLayout* PreferencesPopup::insertGroupBoxUI(PreferencesItemId id, //----------------------------------------------------------------------------- void PreferencesPopup::insertUI(PreferencesItemId id, QGridLayout* layout, - const QList& comboItems) { + const QList& comboItems, + bool isLineEdit) { PreferencesItem item = m_pref->getItem(id); - QWidget* widget = createUI(id, comboItems); + QWidget* widget = createUI(id, comboItems, isLineEdit); if (!widget) return; - bool isFileField = false; + bool isEditBox = false; if (item.type == QMetaType::QVariantMap || - (item.type == QMetaType::QString && dynamic_cast(widget))) - isFileField = true; + (item.type == QMetaType::QString && + (dynamic_cast(widget) || dynamic_cast(widget)))) + isEditBox = true; // CheckBox contains label in itself if (item.type == QMetaType::Bool) @@ -1133,8 +1153,8 @@ void PreferencesPopup::insertUI(PreferencesItemId id, QGridLayout* layout, int row = layout->rowCount(); layout->addWidget(new QLabel(getUIString(id), this), row, 0, Qt::AlignRight | Qt::AlignVCenter); - if (isFileField) - layout->addWidget(widget, row, 1, 1, 2); + if (isEditBox) + layout->addWidget(widget, row, 1, 1, (isLineEdit ? 1 : 2)); else { bool isWideComboBox = false; for (auto cbItem : comboItems) { @@ -1267,6 +1287,8 @@ QString PreferencesPopup::getUIString(PreferencesItemId id) { {resetUndoOnSavingLevel, tr("Clear Undo History when Saving Levels")}, {doNotShowPopupSaveScene, tr("Do not show Save Scene popup warning")}, {defaultProjectPath, tr("Default Project Path:")}, + {recordFileHistory, tr("Record File History* (tnz, pli, hst)")}, + {recordAsUsername, tr("History Username*:")}, // Import / Export {ffmpegPath, tr("Executable Directory:")}, @@ -1914,8 +1936,16 @@ QWidget* PreferencesPopup::createSavingPage() { insertUI(fastRenderPath, lay); + QGridLayout* recordHistoryLay = insertGroupBoxUI(recordFileHistory, lay); + { insertUI(recordAsUsername, recordHistoryLay, QList(), true); } + lay->setRowStretch(lay->rowCount(), 1); + insertFootNote(lay); widget->setLayout(lay); + + m_onEditedFuncMap.insert(recordAsUsername, + &PreferencesPopup::onRecordAsUserChanged); + return widget; } @@ -2391,6 +2421,8 @@ void PreferencesPopup::onChange() { m_pref->setValue(id, field->getValue()); else if (QGroupBox* groupBox = dynamic_cast(senderWidget)) m_pref->setValue(id, groupBox->isChecked()); + else if (LineEdit* lineEdit = dynamic_cast(senderWidget)) + m_pref->setValue(id, lineEdit->text()); else return; diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index 60cd637a..d252328a 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -102,10 +102,12 @@ private: QWidget* createUI( PreferencesItemId id, - const QList& comboItems = QList()); + const QList& comboItems = QList(), + bool isLineEdit = false); QGridLayout* insertGroupBoxUI(PreferencesItemId id, QGridLayout* layout); void insertUI(PreferencesItemId id, QGridLayout* layout, - const QList& comboItems = QList()); + const QList& comboItems = QList(), + bool isLineEdit = false); void insertDualUIs( PreferencesItemId leftId, PreferencesItemId rightId, QGridLayout* layout, const QList& leftComboItems = QList(), @@ -149,6 +151,8 @@ private: void onUnitChanged(); void beforeRoomChoiceChanged(); void onColorCalibrationChanged(); + // Saving + void onRecordAsUserChanged(); // Drawing void onDefLevelTypeChanged(); void onUseNumpadForSwitchingStylesClicked(); diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index 49d2dfe6..58eed0b7 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -497,6 +497,11 @@ void Preferences::definePreferenceItems() { define(defaultProjectPath, "defaultProjectPath", QMetaType::QString, documentsPath); + define(recordFileHistory, "recordFileHistory", QMetaType::Bool, true); + + QString userName = TSystem::getUserName(); + define(recordAsUsername, "recordAsUsername", QMetaType::QString, userName); + // Import / Export define(ffmpegPath, "ffmpegPath", QMetaType::QString, ""); define(ffmpegTimeout, "ffmpegTimeout", QMetaType::Int, 0, 0, diff --git a/toonz/sources/toonzlib/toonzscene.cpp b/toonz/sources/toonzlib/toonzscene.cpp index 3403024d..4b29f73b 100644 --- a/toonz/sources/toonzlib/toonzscene.cpp +++ b/toonz/sources/toonzlib/toonzscene.cpp @@ -1498,8 +1498,12 @@ TCamera *ToonzScene::getCurrentPreviewCamera() { //----------------------------------------------------------------------------- TContentHistory *ToonzScene::getContentHistory(bool createIfNeeded) { - if (!m_contentHistory && createIfNeeded) - m_contentHistory = new TContentHistory(false); + if (!m_contentHistory && createIfNeeded) { + QString altUsername = + Preferences::instance()->getStringValue(recordAsUsername); + bool recordEdit = Preferences::instance()->getBoolValue(recordFileHistory); + m_contentHistory = new TContentHistory(false, altUsername, recordEdit); + } return m_contentHistory; } diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp index 081c3744..7feb2bf3 100644 --- a/toonz/sources/toonzlib/txshsimplelevel.cpp +++ b/toonz/sources/toonzlib/txshsimplelevel.cpp @@ -331,7 +331,10 @@ void TXshSimpleLevel::touchFrame(const TFrameId &fid) { m_properties->setDirtyFlag(true); TContentHistory *ch = getContentHistory(); if (!ch) { - ch = new TContentHistory(true); + QString altUsername = + Preferences::instance()->getStringValue(recordAsUsername); + bool recordEdit = Preferences::instance()->getBoolValue(recordFileHistory); + ch = new TContentHistory(true, altUsername, recordEdit); setContentHistory(ch); } ch->frameModifiedNow(fid); diff --git a/toonz/sources/toonzqt/infoviewer.cpp b/toonz/sources/toonzqt/infoviewer.cpp index 7c182aa5..2860a7d4 100644 --- a/toonz/sources/toonzqt/infoviewer.cpp +++ b/toonz/sources/toonzqt/infoviewer.cpp @@ -225,7 +225,7 @@ InfoViewerImp::InfoViewerImp() create(eSampleSize, QObject::tr("Sample Size: ")); create(eSampleType, QObject::tr("Sample Type: ")); - m_historyLabel.setStyleSheet("color: rgb(0, 0, 200);"); + setLabelStyle(&m_historyLabel); m_history.setStyleSheet("font-size: 12px; font-family: \"courier\";"); // m_history.setStyleSheet("font-family: \"courier\";"); m_history.setReadOnly(true); @@ -344,6 +344,12 @@ void InfoViewerImp::setImageInfo() { } catch (...) { return; } + if (lr && m_path.getType() == "pli") { + try { + lr->loadInfo(); + } catch (...) { + } + } if (!m_fids.empty() && lr && ii) { setVal(eImageSize, QString::number(ii->m_lx) + " X " + QString::number(ii->m_ly));