From 2d063f7ba2d5690b507753a502e8f961652df5cb Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: May 01 2023 03:33:18 +0000 Subject: studio palette tweaks - changed mark of studio palette's link parent styles - enabled to remove link of styles in the studio palette (making the styles link parent) --- diff --git a/toonz/sources/include/toonzqt/styleselection.h b/toonz/sources/include/toonzqt/styleselection.h index 0c561f2..4074c7d 100644 --- a/toonz/sources/include/toonzqt/styleselection.h +++ b/toonz/sources/include/toonzqt/styleselection.h @@ -98,7 +98,9 @@ public: 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 + + // return true if there is at least one linked style in the selection. + // link parent styles are not counted bool hasLinkedStyle(); }; diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index 1a992f6..3c934ab 100644 --- a/toonz/sources/toonzqt/paletteviewergui.cpp +++ b/toonz/sources/toonzqt/paletteviewergui.cpp @@ -542,7 +542,10 @@ void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect, p.setPen(Qt::black); p.drawRect(rect); - if (globalName[0] == L'+') { + if (style->getOriginalName().empty()) { + p.setBrush(Qt::black); + p.drawRect(rect.adjusted(2, 2, -2, -2)); + } else if (globalName[0] == L'+') { QPointF a(x + 2, y + 2); QPointF b(x + 2, y + 5); QPointF c(x + 5, y + 2); @@ -589,6 +592,8 @@ void PageViewer::paintEvent(QPaintEvent *e) { TPalette *palette = (m_page) ? m_page->getPalette() : 0; if (!palette) return; + bool isStudioPalette = palette->getGlobalName() != L""; + // [i0,i1] = visible cell range QRect visibleRect = e->rect(); int i0 = posToIndex(visibleRect.topLeft()); @@ -648,7 +653,7 @@ void PageViewer::paintEvent(QPaintEvent *e) { } // toggle link - drawToggleLink(p, chipRect, m_page->getStyle(i)); + drawToggleLink(p, chipRect, style); } if (ShowNewStyleButton && !m_page->getPalette()->isLocked()) { int j = getChipCount(); @@ -1173,18 +1178,18 @@ void PageViewer::contextMenuEvent(QContextMenuEvent *event) { bool isLocked = m_page ? m_page->getPalette()->isLocked() : false; // remove links from studio palette - if (m_viewType == LEVEL_PALETTE && m_styleSelection && - !m_styleSelection->isEmpty() && !isLocked && + if (m_styleSelection && !m_styleSelection->isEmpty() && !isLocked && m_styleSelection->hasLinkedStyle()) { - menu.addSeparator(); - 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 (m_viewType == LEVEL_PALETTE) { + menu.addSeparator(); + menu.addAction(cmd->getAction("MI_ToggleLinkToStudioPalette")); + menu.addAction(cmd->getAction("MI_RemoveReferenceToStudioPalette")); + menu.addAction(cmd->getAction("MI_GetColorFromStudioPalette")); + } else if (m_viewType == STUDIO_PALETTE) { + menu.addSeparator(); + menu.addAction(cmd->getAction("MI_RemoveReferenceToStudioPalette")); + menu.addAction(cmd->getAction("MI_GetColorFromStudioPalette")); + } } if (((indexPage == 0 && index > 0) || (indexPage > 0 && index >= 0)) && diff --git a/toonz/sources/toonzqt/styleselection.cpp b/toonz/sources/toonzqt/styleselection.cpp index cf39024..97949ba 100644 --- a/toonz/sources/toonzqt/styleselection.cpp +++ b/toonz/sources/toonzqt/styleselection.cpp @@ -500,14 +500,14 @@ void TStyleSelection::enableCommands() { enableCommand(this, MI_PasteNames, &TStyleSelection::pasteStylesName); // available only for level palette - if (m_paletteHandle->getPalette()->getGlobalName() == L"") { - enableCommand(this, MI_GetColorFromStudioPalette, - &TStyleSelection::getBackOriginalStyle); + if (m_paletteHandle->getPalette()->getGlobalName().empty()) { enableCommand(this, MI_ToggleLinkToStudioPalette, &TStyleSelection::toggleLink); - enableCommand(this, MI_RemoveReferenceToStudioPalette, - &TStyleSelection::removeLink); } + enableCommand(this, MI_GetColorFromStudioPalette, + &TStyleSelection::getBackOriginalStyle); + enableCommand(this, MI_RemoveReferenceToStudioPalette, + &TStyleSelection::removeLink); } enableCommand(this, MI_Clear, &TStyleSelection::deleteStyles); enableCommand(this, MI_EraseUnusedStyles, &TStyleSelection::eraseUnusedStyle); @@ -1580,11 +1580,13 @@ class UndoRemoveLink final : public TUndo { bool m_oldEdittedFlag; }; std::vector m_styles; + bool m_isStudioPalette; public: UndoRemoveLink(TPaletteHandle *paletteHandle, int pageIndex) : m_paletteHandle(paletteHandle), m_pageIndex(pageIndex) { - m_palette = m_paletteHandle->getPalette(); + m_palette = m_paletteHandle->getPalette(); + m_isStudioPalette = !m_palette->getGlobalName().empty(); } ~UndoRemoveLink() {} @@ -1619,7 +1621,13 @@ public: for (i = 0; i < (int)m_styles.size(); i++) { ColorStyleData data = m_styles[i]; TColorStyle *cs = page->getStyle(data.m_indexInPage); - cs->setGlobalName(L""); + if (m_isStudioPalette) { + int styleId = page->getStyleId(m_styles[i].m_indexInPage); + std::wstring gname = + L"-" + m_palette->getGlobalName() + L"-" + std::to_wstring(styleId); + cs->setGlobalName(gname); + } else + cs->setGlobalName(L""); cs->setOriginalName(L""); cs->setIsEditedFlag(false); } @@ -1629,7 +1637,7 @@ public: int getSize() const override { return sizeof(*this); } QString getHistoryString() override { - return QObject::tr("Remove Reference in Palette : %1") + return QObject::tr("Remove Reference in Palette : %1") .arg(QString::fromStdWString(m_palette->getPaletteName())); } int getHistoryType() override { return HistoryType::Palette; } @@ -1637,7 +1645,9 @@ public: //----------------------------------------------------------------------------- /*! remove link from studio palette. Delete the global and the original names. - * return true if something changed + * return true if something changed. + * If the target palette is the studio palette, set the global name and make + * the styles "link parent". */ void TStyleSelection::removeLink() { TPalette *palette = getPalette(); @@ -1649,6 +1659,7 @@ void TStyleSelection::removeLink() { assert(page); bool somethingChanged = false; + bool isStudioPalette = !palette->getGlobalName().empty(); UndoRemoveLink *undo = new UndoRemoveLink(m_paletteHandle, m_pageIndex); @@ -1657,7 +1668,17 @@ void TStyleSelection::removeLink() { TColorStyle *cs = page->getStyle(*it); assert(cs); - if (cs->getGlobalName() != L"" || cs->getOriginalName() != L"") { + if (isStudioPalette && !cs->getOriginalName().empty()) { + undo->setColorStyle(*it, cs); + int styleId = page->getStyleId(*it); + std::wstring gname = + L"-" + palette->getGlobalName() + L"-" + std::to_wstring(styleId); + cs->setGlobalName(gname); + cs->setOriginalName(L""); + cs->setIsEditedFlag(false); + somethingChanged = true; + } else if (!isStudioPalette && + (cs->getGlobalName() != L"" || cs->getOriginalName() != L"")) { undo->setColorStyle(*it, cs); cs->setGlobalName(L""); @@ -1781,6 +1802,8 @@ void TStyleSelection::getBackOriginalStyle() { // if the style has no link if (gname == L"") continue; + // if the style is link parent + if (cs->getOriginalName().empty()) continue; // Find the palette from the table int k = gname.find_first_of(L'-', 1); @@ -1835,7 +1858,8 @@ void TStyleSelection::getBackOriginalStyle() { } //----------------------------------------------------------------------------- -/*! return true if there is at least one linked style in the selection +/*! return true if there is at least one linked style in the selection. + link parent styles are not counted */ bool TStyleSelection::hasLinkedStyle() { @@ -1846,13 +1870,18 @@ bool TStyleSelection::hasLinkedStyle() { TPalette::Page *page = palette->getPage(m_pageIndex); assert(page); + bool isStudioPalette = palette->getGlobalName() != L""; + // 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; + if (!gname.empty() && (gname[0] == L'+' || gname[0] == L'-') && + !cs->getOriginalName().empty()) { + return true; + } } return false; }