diff --git a/toonz/sources/include/toonzqt/paletteviewergui.h b/toonz/sources/include/toonzqt/paletteviewergui.h index 390722c..3cc54aa 100644 --- a/toonz/sources/include/toonzqt/paletteviewergui.h +++ b/toonz/sources/include/toonzqt/paletteviewergui.h @@ -199,12 +199,6 @@ protected: void zoomInChip(); void zoomOutChip(); -protected slots: - - void toggleLink(); - void eraseToggleLink(); - void removeLink(); - private: DVGui::LineEdit *m_renameTextField; QPoint m_dragStartPosition; diff --git a/toonz/sources/include/toonzqt/selectioncommandids.h b/toonz/sources/include/toonzqt/selectioncommandids.h index 0dd6b73..99ebe5e 100644 --- a/toonz/sources/include/toonzqt/selectioncommandids.h +++ b/toonz/sources/include/toonzqt/selectioncommandids.h @@ -12,6 +12,8 @@ #define MI_PasteColors "MI_PasteColors" #define MI_PasteNames "MI_PasteNames" #define MI_GetColorFromStudioPalette "MI_GetColorFromStudioPalette" +#define MI_ToggleLinkToStudioPalette "MI_ToggleLinkToStudioPalette" +#define MI_RemoveReferenceToStudioPalette "MI_RemoveReferenceToStudioPalette" #define MI_Clear "MI_Clear" #define MI_SelectAll "MI_SelectAll" #define MI_InvertSelection "MI_InvertSelection" diff --git a/toonz/sources/include/toonzqt/styleselection.h b/toonz/sources/include/toonzqt/styleselection.h index fb78637..6e5099e 100644 --- a/toonz/sources/include/toonzqt/styleselection.h +++ b/toonz/sources/include/toonzqt/styleselection.h @@ -95,9 +95,11 @@ public: void toggleKeyframe(int frame); // remove link from the studio palette (if linked) - bool removeLink(); + void removeLink(); // get back the style from the studio palette (if linked) void getBackOriginalStyle(); + // return true if there is at least one linked style in the selection + bool hasLinkedStyle(); }; #endif // STYLESELECTION_INCLUDED diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index b2b2e24..f606135 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -1640,6 +1640,10 @@ void MainWindow::defineActions() { createRightClickMenuAction(MI_PasteNames, tr("Paste Name"), ""); createRightClickMenuAction(MI_GetColorFromStudioPalette, tr("Get Color from Studio Palette"), ""); + createRightClickMenuAction(MI_ToggleLinkToStudioPalette, + tr("Toggle Link to Studio Palette"), ""); + createRightClickMenuAction(MI_RemoveReferenceToStudioPalette, + tr("Remove Reference to Studio Palette"), ""); createMenuEditAction(MI_Clear, tr("&Delete"), "Delete"); createMenuEditAction(MI_Insert, tr("&Insert"), "Ins"); createMenuEditAction(MI_Group, tr("&Group"), "Ctrl+G"); diff --git a/toonz/sources/toonzlib/studiopalettecmd.cpp b/toonz/sources/toonzlib/studiopalettecmd.cpp index 8cf07e9..c8023ec 100644 --- a/toonz/sources/toonzlib/studiopalettecmd.cpp +++ b/toonz/sources/toonzlib/studiopalettecmd.cpp @@ -501,7 +501,11 @@ void StudioPaletteCmd::loadIntoCurrentPalette(TPaletteHandle *paletteHandle, // keep the color model path unchanged TFilePath oldRefImagePath = current->getRefImgPath(); + std::wstring oldGlobalName = current->getGlobalName(); current->assign(palette, true); + // keep global name unchanged + current->setGlobalName(oldGlobalName); + current->setDirtyFlag(true); current->setRefImgPath(oldRefImagePath); diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cpp index faace8b..b7a59ea 100644 --- a/toonz/sources/toonzqt/paletteviewer.cpp +++ b/toonz/sources/toonzqt/paletteviewer.cpp @@ -911,10 +911,7 @@ void PaletteViewer::saveStudioPalette() { if (ret == 2 || ret == 0) return; sp->setPalette(fp, getPalette(), false); - question = "Do you want to update all linked styles in current scene ?"; - ret = DVGui::MsgBox(question, tr("Update"), tr("Don't Update"), 0); - if (ret == 1) - StudioPaletteCmd::updateAllLinkedStyles(m_paletteHandle, m_xsheetHandle); + StudioPaletteCmd::updateAllLinkedStyles(m_paletteHandle, m_xsheetHandle); palette->setDirtyFlag(false); } diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index b22622c..bf826a7 100644 --- a/toonz/sources/toonzqt/paletteviewergui.cpp +++ b/toonz/sources/toonzqt/paletteviewergui.cpp @@ -1023,27 +1023,21 @@ void PageViewer::contextMenuEvent(QContextMenuEvent *event) { // remove links from studio palette if (m_viewType == LEVEL_PALETTE && m_styleSelection && - !m_styleSelection->isEmpty() && !isLocked) { + !m_styleSelection->isEmpty() && !isLocked && + m_styleSelection->hasLinkedStyle()) { menu.addSeparator(); - QAction *removeLinkAct = menu.addAction(tr("Remove Links")); - connect(removeLinkAct, SIGNAL(triggered()), this, SLOT(removeLink())); + QAction *toggleStyleLink = cmd->getAction("MI_ToggleLinkToStudioPalette"); + menu.addAction(toggleStyleLink); + QAction *removeStyleLink = + cmd->getAction("MI_RemoveReferenceToStudioPalette"); + menu.addAction(removeStyleLink); + QAction *getBackOriginalAct = + cmd->getAction("MI_GetColorFromStudioPalette"); + menu.addAction(getBackOriginalAct); } if (((indexPage == 0 && index > 0) || (indexPage > 0 && index >= 0)) && index < getChipCount() && !isLocked) { - // iwsw commented out temporarly - /* - wstring globalName = m_page->getStyle(index)->getGlobalName(); - if (m_viewType != STUDIO_PALETTE && - globalName != L"" && - (globalName[0] == L'-' || globalName[0] == L'+')) - { - createMenuAction(menu, "MI_ToggleLinkToStudioPalette", tr("Toggle - Link to Studio Palette"), "toggleLink()"); - createMenuAction(menu, "MI_RemoveReferenceToStudioPalette", - tr("Remove Reference to Studio Palette"), "eraseToggleLink()"); - } - */ if (pasteValueAct) pasteValueAct->setEnabled(true); if (pasteColorsAct) pasteColorsAct->setEnabled(true); @@ -1061,29 +1055,20 @@ void PageViewer::contextMenuEvent(QContextMenuEvent *event) { clearAct->setEnabled(false); } - // get color from the original studio palette - if (m_viewType == LEVEL_PALETTE && m_styleSelection && - !m_styleSelection->isEmpty() && !isLocked) { + if (m_page) { menu.addSeparator(); - QAction *getBackOriginalAct = - cmd->getAction("MI_GetColorFromStudioPalette"); - menu.addAction(getBackOriginalAct); + QAction *newStyle = menu.addAction(tr("New Style")); + connect(newStyle, SIGNAL(triggered()), SLOT(addNewColor())); + QAction *newPage = menu.addAction(tr("New Page")); + connect(newPage, SIGNAL(triggered()), SLOT(addNewPage())); } - // iwsw commented out temporarly /* - if (m_viewType != STUDIO_PALETTE) - { - menu.addSeparator(); + if (m_viewType != STUDIO_PALETTE) { menu.addAction(cmd->getAction(MI_EraseUnusedStyles)); } */ - if (m_page) { - QAction *newStyle = menu.addAction(tr("New Style")); - connect(newStyle, SIGNAL(triggered()), SLOT(addNewColor())); - QAction *newPage = menu.addAction(tr("New Page")); - connect(newPage, SIGNAL(triggered()), SLOT(addNewPage())); - } + menu.exec(event->globalPos()); } @@ -1370,25 +1355,6 @@ void PageViewer::onStyleRenamed() { PaletteCmd::renamePaletteStyle(getPaletteHandle(), newName); } -//----------------------------------------------------------------------------- -/*! Recall \b TStyleSelection::toggleLink() to current page style selection. -*/ -void PageViewer::toggleLink() { - if (!m_page || !m_styleSelection || m_styleSelection->isEmpty()) return; - m_styleSelection->toggleLink(); - update(); - emit changeWindowTitleSignal(); -} - -//----------------------------------------------------------------------------- -/*! Recall \b TStyleSelection::eraseToggleLink() to current page style - * selection. -*/ -void PageViewer::eraseToggleLink() { - if (!m_page || !m_styleSelection || m_styleSelection->isEmpty()) return; - m_styleSelection->eraseToggleLink(); -} - //============================================================================= /*! \class PaletteViewerGUI::PaletteTabBar \brief The PaletteTabBar class provides a bar with tab to show @@ -1652,13 +1618,6 @@ void PageViewer::updateCommandLocks() { cmd->getAction("MI_BlendColors")->setEnabled(!isLocked); cmd->getAction("MI_PasteNames")->setEnabled(!isLocked); cmd->getAction("MI_GetColorFromStudioPalette")->setEnabled(!isLocked); -} - -//----------------------------------------------------------------------------- -/*! remove link and revert to the normal style -*/ -void PageViewer::removeLink() { - if (!m_page || !m_styleSelection || m_styleSelection->isEmpty()) return; - - if (m_styleSelection->removeLink()) emit changeWindowTitleSignal(); + cmd->getAction("MI_ToggleLinkToStudioPalette")->setEnabled(!isLocked); + cmd->getAction("MI_RemoveReferenceToStudioPalette")->setEnabled(!isLocked); } diff --git a/toonz/sources/toonzqt/studiopaletteviewer.cpp b/toonz/sources/toonzqt/studiopaletteviewer.cpp index 052335e..bb6b00e 100644 --- a/toonz/sources/toonzqt/studiopaletteviewer.cpp +++ b/toonz/sources/toonzqt/studiopaletteviewer.cpp @@ -497,6 +497,7 @@ void StudioPaletteTreeViewer::onCurrentItemChanged(QTreeWidgetItem *current, m_currentPalette = StudioPalette::instance()->getPalette(newPath, false); m_studioPaletteHandle->setPalette(m_currentPalette.getPointer()); m_studioPaletteHandle->notifyPaletteSwitched(); + StudioPaletteCmd::updateAllLinkedStyles(m_levelPaletteHandle, m_xsheetHandle); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonzqt/styleselection.cpp b/toonz/sources/toonzqt/styleselection.cpp index 024ace0..99f9bb9 100644 --- a/toonz/sources/toonzqt/styleselection.cpp +++ b/toonz/sources/toonzqt/styleselection.cpp @@ -505,9 +505,14 @@ void TStyleSelection::enableCommands() { enableCommand(this, MI_PasteNames, &TStyleSelection::pasteStylesName); // available only for level palette - if (m_paletteHandle->getPalette()->getGlobalName() == L"") + if (m_paletteHandle->getPalette()->getGlobalName() == L"") { enableCommand(this, MI_GetColorFromStudioPalette, &TStyleSelection::getBackOriginalStyle); + enableCommand(this, MI_ToggleLinkToStudioPalette, + &TStyleSelection::toggleLink); + enableCommand(this, MI_RemoveReferenceToStudioPalette, + &TStyleSelection::removeLink); + } } enableCommand(this, MI_Clear, &TStyleSelection::deleteStyles); enableCommand(this, MI_EraseUnusedStyles, &TStyleSelection::eraseUnsedStyle); @@ -1408,14 +1413,15 @@ public: void TStyleSelection::toggleLink() { TPalette *palette = getPalette(); if (!palette || m_pageIndex < 0) return; + if (isEmpty() || palette->isLocked()) return; int n = m_styleIndicesInPage.size(); if (n <= 0) return; std::vector> oldColorStylesLinked; std::vector> newColorStylesLinked; - bool somethingHasBeenLinked = false; - + bool somethingHasBeenLinked = false; + bool somethingChanged = false; bool currentStyleIsInSelection = false; TPalette::Page *page = palette->getPage(m_pageIndex); @@ -1435,6 +1441,7 @@ void TStyleSelection::toggleLink() { name[0] = name[0] == L'-' ? L'+' : L'-'; cs->setGlobalName(name); if (name[0] == L'+') somethingHasBeenLinked = true; + somethingChanged = true; } undo->setColorStyle(index, oldCs, name); @@ -1442,6 +1449,13 @@ void TStyleSelection::toggleLink() { palette->getPage(m_pageIndex)->search(m_paletteHandle->getStyleIndex())) currentStyleIsInSelection = true; } + + // if nothing changed, do not set dirty flag, nor register undo + if (!somethingChanged) { + delete undo; + return; + } + if (somethingHasBeenLinked) StudioPalette::instance()->updateLinkedColors(palette); @@ -1460,6 +1474,7 @@ void TStyleSelection::toggleLink() { void TStyleSelection::eraseToggleLink() { TPalette *palette = getPalette(); if (!palette || m_pageIndex < 0) return; + if (isEmpty() || palette->isLocked()) return; int n = m_styleIndicesInPage.size(); if (n <= 0) return; @@ -1575,7 +1590,7 @@ public: int getSize() const override { return sizeof(*this); } QString getHistoryString() override { - return QObject::tr("Remove Link in Palette : %1") + return QObject::tr("Remove Reference in Palette : %1") .arg(QString::fromStdWString(m_palette->getPaletteName())); } int getHistoryType() override { return HistoryType::Palette; } @@ -1585,11 +1600,11 @@ public: /*! remove link from studio palette. Delete the global and the orginal names. * return true if something changed */ -bool TStyleSelection::removeLink() { +void TStyleSelection::removeLink() { TPalette *palette = getPalette(); - if (!palette || m_pageIndex < 0) return false; + if (!palette || m_pageIndex < 0) return; int n = m_styleIndicesInPage.size(); - if (n <= 0) return false; + if (n <= 0) return; TPalette::Page *page = palette->getPage(m_pageIndex); assert(page); @@ -1614,12 +1629,10 @@ bool TStyleSelection::removeLink() { } if (somethingChanged) { - palette->setDirtyFlag(true); + m_paletteHandle->notifyColorStyleChanged(false); TUndoManager::manager()->add(undo); } else delete undo; - - return somethingChanged; } //============================================================================= @@ -1781,3 +1794,26 @@ void TStyleSelection::getBackOriginalStyle() { } else delete undo; } + +//----------------------------------------------------------------------------- +/*! return true if there is at least one linked style in the selection +*/ + +bool TStyleSelection::hasLinkedStyle() { + TPalette *palette = getPalette(); + if (!palette || m_pageIndex < 0 || isEmpty()) return false; + if (m_styleIndicesInPage.size() <= 0) return false; + + TPalette::Page *page = palette->getPage(m_pageIndex); + assert(page); + + // for each selected style + for (std::set::iterator it = m_styleIndicesInPage.begin(); + it != m_styleIndicesInPage.end(); ++it) { + TColorStyle *cs = page->getStyle(*it); + std::wstring gname = cs->getGlobalName(); + // if the style has link, return true + if (gname != L"" && (gname[0] == L'-' || gname[0] == L'+')) return true; + } + return false; +}