From f09fd344247315dd8e190d58dabdb40ae6269cda Mon Sep 17 00:00:00 2001 From: Jeremy Bullock Date: Jan 05 2017 04:19:49 +0000 Subject: Merge pull request #898 from shun-iwasawa/fix_saving_menubar Fix saving menu bar in non-English environment not to lose English titles --- diff --git a/toonz/sources/toonz/menubarpopup.cpp b/toonz/sources/toonz/menubarpopup.cpp index f104416..d8d4a71 100644 --- a/toonz/sources/toonz/menubarpopup.cpp +++ b/toonz/sources/toonz/menubarpopup.cpp @@ -71,9 +71,12 @@ public: //----------------------------------------------------------------------------- class MenuBarSubmenuItem final : public QTreeWidgetItem { + /*- title before translation -*/ + QString m_orgTitle; + public: MenuBarSubmenuItem(QTreeWidgetItem* parent, QString& title) - : QTreeWidgetItem(parent, UserType) { + : QTreeWidgetItem(parent, UserType), m_orgTitle(title) { setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled); /*- Menu title will be translated if the title is registered in translation @@ -86,6 +89,9 @@ public: setToolTip(0, QObject::tr( "[Drag] to move position, [Double Click] to edit title")); } + + QString getOrgTitle() const { return m_orgTitle; } + void setOrgTitle(const QString title) { m_orgTitle = title; } }; //============================================================================= @@ -115,6 +121,10 @@ MenuBarTree::MenuBarTree(TFilePath& path, QWidget* parent) } loadMenuTree(fp); + + bool ret = connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, + SLOT(onItemChanged(QTreeWidgetItem*, int))); + assert(ret); } //----------------------------------------------------------------------------- @@ -230,7 +240,8 @@ void MenuBarTree::saveMenuRecursive(QXmlStreamWriter& writer, writer.writeEmptyElement("separator"); else if (subMenu) { writer.writeStartElement("menu"); - writer.writeAttribute("title", subMenu->text(0)); + // save original title instead of translated one + writer.writeAttribute("title", subMenu->getOrgTitle()); saveMenuRecursive(writer, subMenu); @@ -326,6 +337,14 @@ void MenuBarTree::removeItem() { delete item; } +//----------------------------------------------------------------------------- + +void MenuBarTree::onItemChanged(QTreeWidgetItem* item, int column) { + MenuBarSubmenuItem* submenuItem = dynamic_cast(item); + if (!submenuItem) return; + submenuItem->setOrgTitle(submenuItem->text(0)); +} + //============================================================================= // CommandListTree //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/menubarpopup.h b/toonz/sources/toonz/menubarpopup.h index 5d0a44d..7d5ac26 100644 --- a/toonz/sources/toonz/menubarpopup.h +++ b/toonz/sources/toonz/menubarpopup.h @@ -39,6 +39,7 @@ protected: protected slots: void insertMenu(); void removeItem(); + void onItemChanged(QTreeWidgetItem*, int); }; //=============================================================================