From b373379e6e964cf4d015138eac3ca92ac425af28 Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Jan 23 2020 03:17:43 +0000 Subject: delete unused styles --- diff --git a/toonz/sources/include/toonz/fullcolorpalette.h b/toonz/sources/include/toonz/fullcolorpalette.h index e1308f2..5622711 100644 --- a/toonz/sources/include/toonz/fullcolorpalette.h +++ b/toonz/sources/include/toonz/fullcolorpalette.h @@ -35,6 +35,7 @@ public: void clear(); TPalette *getPalette(ToonzScene *scene); void savePalette(ToonzScene *scene); + bool isFullColorPalette(TPalette *palette) { return m_palette == palette; } }; #endif // FULLCOLOR_PALETTE diff --git a/toonz/sources/include/toonzqt/paletteviewer.h b/toonz/sources/include/toonzqt/paletteviewer.h index 10c6abf..0d4c876 100644 --- a/toonz/sources/include/toonzqt/paletteviewer.h +++ b/toonz/sources/include/toonzqt/paletteviewer.h @@ -82,6 +82,7 @@ protected: TPaletteHandle *m_paletteHandle; TFrameHandle *m_frameHandle; TXsheetHandle *m_xsheetHandle; + TXshLevelHandle *m_levelHandle; QScrollArea *m_pageViewerScrollArea; PaletteViewerGUI::PageViewer *m_pageViewer; @@ -128,6 +129,7 @@ protected: void resizeEvent(QResizeEvent *event) override; void contextMenuEvent(QContextMenuEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; void showEvent(QShowEvent *) override; void hideEvent(QHideEvent *) override; diff --git a/toonz/sources/include/toonzqt/paletteviewergui.h b/toonz/sources/include/toonzqt/paletteviewergui.h index 505054c..6b77875 100644 --- a/toonz/sources/include/toonzqt/paletteviewergui.h +++ b/toonz/sources/include/toonzqt/paletteviewergui.h @@ -113,6 +113,7 @@ public: ViewMode getViewMode() const { return m_viewMode; } void setViewMode(ViewMode mode); + NameDisplayMode getNameDisplayMode() const { return m_nameDisplayMode; } void setNameDisplayMode(NameDisplayMode mode); PaletteViewerGUI::PaletteViewType getViewType() const { return m_viewType; } diff --git a/toonz/sources/include/toonzqt/styleselection.h b/toonz/sources/include/toonzqt/styleselection.h index 6e5099e..0c561f2 100644 --- a/toonz/sources/include/toonzqt/styleselection.h +++ b/toonz/sources/include/toonzqt/styleselection.h @@ -85,7 +85,7 @@ public: void pasteStylesColor(); void pasteStylesName(); void deleteStyles(); - void eraseUnsedStyle(); + void eraseUnusedStyle(); void blendStyles(); void toggleLink(); void eraseToggleLink(); diff --git a/toonz/sources/toonzlib/palettecmd.cpp b/toonz/sources/toonzlib/palettecmd.cpp index 9269f47..3c62462 100644 --- a/toonz/sources/toonzlib/palettecmd.cpp +++ b/toonz/sources/toonzlib/palettecmd.cpp @@ -91,7 +91,7 @@ bool isStyleUsed(const TVectorImageP vi, int styleId) { int regionCount = vi->getRegionCount(); for (i = 0; i < regionCount; i++) { TRegion *region = vi->getRegion(i); - if (region || region->getStyle() != styleId) return true; + if (region && region->getStyle() == styleId) return true; } return false; } diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cpp index c0b03f6..b35d01d 100644 --- a/toonz/sources/toonzqt/paletteviewer.cpp +++ b/toonz/sources/toonzqt/paletteviewer.cpp @@ -9,6 +9,7 @@ #include "toonzqt/dvdialog.h" #include "toonzqt/dvscrollwidget.h" #include "toonzqt/studiopaletteviewer.h" +#include "toonzqt/styleselection.h" #include "palettedata.h" // TnzLib includes @@ -19,6 +20,7 @@ #include "toonz/sceneproperties.h" #include "toonz/studiopalette.h" #include "toonz/tframehandle.h" +#include "toonz/fullcolorpalette.h" // TnzCore includes #include "tconvert.h" @@ -187,7 +189,7 @@ PaletteViewer::~PaletteViewer() { delete m_changeStyleCommand; } void PaletteViewer::setPaletteHandle(TPaletteHandle *paletteHandle) { if (m_paletteHandle == paletteHandle) return; - bool ret = true; + bool ret = true; if (m_paletteHandle) ret = ret && disconnect(m_paletteHandle, 0, this, 0); m_paletteHandle = paletteHandle; @@ -238,8 +240,8 @@ void PaletteViewer::setXsheetHandle(TXsheetHandle *xsheetHandle) { //----------------------------------------------------------------------------- /*!for clearing level cache after "paste style" command called from style -* selection -*/ + * selection + */ void PaletteViewer::setLevelHandle(TXshLevelHandle *levelHandle) { m_pageViewer->setLevelHandle(levelHandle); } @@ -281,7 +283,7 @@ void PaletteViewer::enableSaveAction(bool enable) { //----------------------------------------------------------------------------- /*! Create tab bar to select palette page. -*/ + */ void PaletteViewer::createTabBar() { m_pagesBar = new PaletteTabBar(this, m_hasPageCommand); @@ -295,7 +297,7 @@ void PaletteViewer::createTabBar() { //----------------------------------------------------------------------------- /*! Create right part of button bar. -*/ + */ void PaletteViewer::createPaletteToolBar() { m_paletteToolBar->clear(); m_paletteToolBar->setMovable(false); @@ -356,52 +358,48 @@ void PaletteViewer::createPaletteToolBar() { viewModeButton->setIcon(viewModeIcon); QMenu *viewMode = new QMenu(QString("Options"), viewModeButton); viewMode->setToolTip(tr("Options")); + viewMode->setLayoutDirection(Qt::LeftToRight); QActionGroup *viewModeGroup = new QActionGroup(viewMode); + viewModeGroup->setExclusive(true); connect(viewModeGroup, SIGNAL(triggered(QAction *)), this, SLOT(onViewMode(QAction *))); - QAction *smallThumbAct = - new QAction(tr("&Small Thumbnails View"), viewModeButton); - smallThumbAct->setData(PageViewer::SmallChips); - QAction *mediumThumbAct = - new QAction(tr("&Medium Thumbnails View"), viewModeButton); - mediumThumbAct->setData(PageViewer::MediumChips); - QAction *largeThumbAct = - new QAction(tr("&Large Thumbnails View"), viewModeButton); - largeThumbAct->setData(PageViewer::LargeChips); - - QAction *listAct = new QAction(tr("&List View"), viewModeButton); - listAct->setData(PageViewer::List); - - viewModeGroup->addAction(smallThumbAct); - viewModeGroup->addAction(mediumThumbAct); - viewModeGroup->addAction(largeThumbAct); - viewModeGroup->addAction(listAct); - - QAction *styleDisplayAct = new QAction(tr("Style Name"), viewModeButton); - styleDisplayAct->setData(PageViewer::Style); - QAction *originalDisplayAct = - new QAction(tr("StudioPalette Name"), viewModeButton); - originalDisplayAct->setData(PageViewer::Original); - QAction *bothDisplayAct = new QAction(tr("Both Names"), viewModeButton); - bothDisplayAct->setData(PageViewer::StyleAndOriginal); + auto addViewAction = [&](const QString &label, PageViewer::ViewMode mode) { + QAction *viewAction = new QAction(label, viewMode); + viewAction->setData(mode); + viewAction->setCheckable(true); + if (m_pageViewer->getViewMode() == mode) viewAction->setChecked(true); + viewModeGroup->addAction(viewAction); + viewMode->addAction(viewAction); + }; + + addViewAction(tr("&Small Thumbnails View"), PageViewer::SmallChips); + addViewAction(tr("&Medium Thumbnails View"), PageViewer::MediumChips); + addViewAction(tr("&Large Thumbnails View"), PageViewer::LargeChips); + addViewAction(tr("&List View"), PageViewer::List); + + viewMode->addSeparator(); QActionGroup *nameDisplayModeGroup = new QActionGroup(viewMode); + nameDisplayModeGroup->setExclusive(true); connect(nameDisplayModeGroup, SIGNAL(triggered(QAction *)), this, SLOT(onNameDisplayMode(QAction *))); - nameDisplayModeGroup->addAction(styleDisplayAct); - nameDisplayModeGroup->addAction(originalDisplayAct); - nameDisplayModeGroup->addAction(bothDisplayAct); - - viewMode->addAction(smallThumbAct); - viewMode->addAction(mediumThumbAct); - viewMode->addAction(largeThumbAct); - viewMode->addAction(listAct); - viewMode->addSeparator(); - viewMode->addAction(styleDisplayAct); - viewMode->addAction(originalDisplayAct); - viewMode->addAction(bothDisplayAct); + + auto addNameDisplayAction = [&](const QString &label, + PageViewer::NameDisplayMode mode) { + QAction *nameDisplayAction = new QAction(label, viewMode); + nameDisplayAction->setData(mode); + nameDisplayAction->setCheckable(true); + if (m_pageViewer->getNameDisplayMode() == mode) + nameDisplayAction->setChecked(true); + nameDisplayModeGroup->addAction(nameDisplayAction); + viewMode->addAction(nameDisplayAction); + }; + + addNameDisplayAction(tr("Style Name"), PageViewer::Style); + addNameDisplayAction(tr("StudioPalette Name"), PageViewer::Original); + addNameDisplayAction(tr("Both Names"), PageViewer::StyleAndOriginal); viewModeButton->setMenu(viewMode); @@ -492,7 +490,7 @@ void PaletteViewer::createSavePaletteToolBar() { //----------------------------------------------------------------------------- /*! Update page tab bar adding or removing tab in accord with viewer palette. -*/ + */ void PaletteViewer::updateTabBar() { int tabCount = m_pagesBar->count(); int i; @@ -518,8 +516,8 @@ void PaletteViewer::updateTabBar() { //----------------------------------------------------------------------------- /*! Update right button bar, enable its action if current viewer palette is -* empty. -*/ + * empty. + */ void PaletteViewer::updatePaletteToolBar() { if (!m_paletteToolBar) return; QList actions; @@ -544,8 +542,8 @@ void PaletteViewer::updatePaletteToolBar() { //----------------------------------------------------------------------------- /*! Update left button bar, enable its action if current viewer palette is -* empty. -*/ + * empty. + */ void PaletteViewer::updateSavePaletteToolBar() { if (!m_savePaletteToolBar) return; QList actions; @@ -567,7 +565,7 @@ void PaletteViewer::updateSavePaletteToolBar() { //----------------------------------------------------------------------------- /*! Resize the widget and its child. -*/ + */ void PaletteViewer::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); if (m_pageViewer) m_pageViewer->computeSize(); @@ -585,7 +583,7 @@ void PaletteViewer::setChangeStyleCommand( //----------------------------------------------------------------------------- /*! Create and open the Right-click menu. -*/ + */ void PaletteViewer::contextMenuEvent(QContextMenuEvent *event) { m_indexPageToDelete = -1; QPoint pos = event->pos(); @@ -619,11 +617,29 @@ void PaletteViewer::contextMenuEvent(QContextMenuEvent *event) { menu->addAction(CommandManager::instance()->getAction("MI_SavePaletteAs")); } + if (m_viewType == LEVEL_PALETTE && !getPalette()->isLocked() && + m_isSaveActionEnabled && + !FullColorPalette::instance()->isFullColorPalette(getPalette())) { + menu->addSeparator(); + menu->addAction( + CommandManager::instance()->getAction("MI_EraseUnusedStyles")); + } + menu->exec(event->globalPos()); } //----------------------------------------------------------------------------- +void PaletteViewer::mousePressEvent(QMouseEvent *event) { + QFrame::mousePressEvent(event); + if (event->button() == Qt::RightButton) { + m_pageViewer->getSelection()->makeCurrent(); + m_pageViewer->updateCommandLocks(); + } +} + +//----------------------------------------------------------------------------- + void PaletteViewer::showEvent(QShowEvent *) { onPaletteSwitched(); changeWindowTitle(); @@ -711,7 +727,7 @@ void PaletteViewer::dragEnterEvent(QDragEnterEvent *event) { //----------------------------------------------------------------------------- /*! Execute drop event. -*/ + */ void PaletteViewer::dropEvent(QDropEvent *event) { if (m_viewType == CLEANUP_PALETTE) return; const QMimeData *mimeData = event->mimeData(); @@ -792,7 +808,7 @@ void PaletteViewer::dropEvent(QDropEvent *event) { //----------------------------------------------------------------------------- /*! Start drag and drop; if current page exist set drag and drop event data. -*/ + */ void PaletteViewer::startDragDrop() { TRepetitionGuard guard; if (!guard.hasLock()) return; @@ -818,7 +834,7 @@ void PaletteViewer::clearStyleSelection() { m_pageViewer->clearSelection(); } //----------------------------------------------------------------------------- /*! Set current view page to \b currentIndexPage -*/ + */ void PaletteViewer::setPageView(int currentIndexPage) { TPalette *palette = getPalette(); TPalette::Page *page = palette ? palette->getPage(currentIndexPage) : 0; @@ -857,7 +873,7 @@ void PaletteViewer::addNewColor() { //----------------------------------------------------------------------------- /*! Emit a signal to delete a page of current palette viewer. -*/ + */ void PaletteViewer::deletePage() { TPalette *palette = getPalette(); if (!palette || palette->isLocked()) return; @@ -944,7 +960,7 @@ void PaletteViewer::saveStudioPalette() { //----------------------------------------------------------------------------- /*! If current color switched update current page view. -*/ + */ void PaletteViewer::onColorStyleSwitched() { TPalette *palette = getPalette(); @@ -978,7 +994,7 @@ void PaletteViewer::onColorStyleSwitched() { //----------------------------------------------------------------------------- /*! Update view. Remember current page bar index. -*/ + */ void PaletteViewer::onPaletteChanged() { int index = m_pagesBar->currentIndex(); updateTabBar(); @@ -1002,7 +1018,7 @@ void PaletteViewer::onPaletteSwitched() { if (palette) { int currentStyleId = palette->getCurrentStyleId(); TPalette::Page *page = palette->getStylePage(currentStyleId); - if (page) pageIndex = page->getIndex(); + if (page) pageIndex = page->getIndex(); } } onSwitchToPage(pageIndex); @@ -1038,7 +1054,7 @@ void PaletteViewer::onFrameSwitched() { //----------------------------------------------------------------------------- /*! Set a new name to palette page of index \b tabIndex. -*/ + */ void PaletteViewer::onTabTextChanged(int tabIndex) { if (!m_paletteHandle) return; QString newName = m_pagesBar->tabText(tabIndex); @@ -1048,7 +1064,7 @@ void PaletteViewer::onTabTextChanged(int tabIndex) { //----------------------------------------------------------------------------- /*! Change page style view mode. -*/ + */ void PaletteViewer::onViewMode(QAction *action) { int viewMode = action->data().toInt(); m_pageViewer->setViewMode((PageViewer::ViewMode)viewMode); @@ -1056,7 +1072,7 @@ void PaletteViewer::onViewMode(QAction *action) { //----------------------------------------------------------------------------- /*! Change name display mode on the style chips -*/ + */ void PaletteViewer::onNameDisplayMode(QAction *action) { int nameDisplayMode = action->data().toInt(); m_pageViewer->setNameDisplayMode( @@ -1108,8 +1124,8 @@ void PaletteViewer::changeWindowTitle() { //----------------------------------------------------------------------------- /*! Move palette view page from \b srcIndex page index to \b dstIndex page -* index. -*/ + * index. + */ void PaletteViewer::movePage(int srcIndex, int dstIndex) { PaletteCmd::movePalettePage(m_paletteHandle, srcIndex, dstIndex); onSwitchToPage(dstIndex); @@ -1117,7 +1133,7 @@ void PaletteViewer::movePage(int srcIndex, int dstIndex) { //----------------------------------------------------------------------------- /*! Process when the lock button toggled -*/ + */ void PaletteViewer::setIsLocked(bool lock) { if (m_viewType == CLEANUP_PALETTE) return; diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index c3450ed..a754942 100644 --- a/toonz/sources/toonzqt/paletteviewergui.cpp +++ b/toonz/sources/toonzqt/paletteviewergui.cpp @@ -194,7 +194,7 @@ TXsheetHandle *PageViewer::getXsheetHandle() const { //----------------------------------------------------------------------------- /*! for clearing the cache when executing paste style command from * StyleSelection -*/ + */ void PageViewer::setLevelHandle(TXshLevelHandle *levelHandle) { m_styleSelection->setLevelHandle(levelHandle); } @@ -228,7 +228,7 @@ int PageViewer::getCurrentStyleIndex() const { //----------------------------------------------------------------------------- /*! Set current page to \b page and update view. -*/ + */ void PageViewer::setPage(TPalette::Page *page) { m_page = page; computeSize(); @@ -237,7 +237,7 @@ void PageViewer::setPage(TPalette::Page *page) { //----------------------------------------------------------------------------- /*! Return chip count contained in current page. -*/ + */ int PageViewer::getChipCount() const { return m_page ? m_page->getStyleCount() : 0; } @@ -245,7 +245,7 @@ int PageViewer::getChipCount() const { //----------------------------------------------------------------------------- /*! Set current view mode \b PaletteViewerGUI::PageViewer::ViewMode to \b * viewMode and update view. -*/ + */ void PageViewer::setViewMode(ViewMode viewMode) { if (m_viewMode == viewMode) return; m_viewMode = viewMode; @@ -286,7 +286,7 @@ QRect PageViewer::getItemRect(int index) const { //----------------------------------------------------------------------------- /*! Return rect of color area of chip identified by \b index. -*/ + */ QRect PageViewer::getColorChipRect(int index) const { QRect rect = getItemRect(index); if (rect.isNull()) return rect; @@ -299,7 +299,7 @@ QRect PageViewer::getColorChipRect(int index) const { //----------------------------------------------------------------------------- /*! Return rect of chip identified by \b index name. (Not in \b SmallChips). -*/ + */ QRect PageViewer::getColorNameRect(int index) const { QRect rect = getItemRect(index); if (rect.isNull()) return rect; @@ -317,7 +317,7 @@ QRect PageViewer::getColorNameRect(int index) const { //----------------------------------------------------------------------------- /*! Add color to current page; if indexInPage == -1 add color at the bottom of * page. -*/ + */ void PageViewer::drop(int dstIndexInPage, const QMimeData *mimeData) { assert(m_page); TPalette *palette = m_page->getPalette(); @@ -325,7 +325,7 @@ void PageViewer::drop(int dstIndexInPage, const QMimeData *mimeData) { int dstPageIndex = m_page->getIndex(); if ((m_page->getStyleId(0) == 0 || m_page->getStyleId(1) == 1) && dstIndexInPage < 2) - dstIndexInPage = 2; + dstIndexInPage = 2; if (dstIndexInPage < 0) dstIndexInPage = m_page->getStyleCount(); const PaletteData *paletteData = dynamic_cast(mimeData); @@ -387,7 +387,7 @@ void PageViewer::drop(int dstIndexInPage, const QMimeData *mimeData) { //----------------------------------------------------------------------------- /*! Create an empty page to receive drop. -*/ + */ void PageViewer::createDropPage() { if (m_dropPageCreated) return; m_dropPageCreated = true; @@ -403,7 +403,7 @@ void PageViewer::clearSelection() { m_styleSelection->selectNone(); } //----------------------------------------------------------------------------- /*! Return page chip size, it depend from current \b * PaletteViewerGUI::PageViewer::ViewMode. -*/ + */ QSize PageViewer::getChipSize() const { if (m_viewMode == SmallChips || m_viewMode == SmallChipsWithName) return QSize(48, 33); @@ -417,7 +417,7 @@ QSize PageViewer::getChipSize() const { //----------------------------------------------------------------------------- /*! Draw a single chip style \b style in \b chipRect. -*/ + */ void PageViewer::drawColorChip(QPainter &p, QRect &chipRect, TColorStyle *style) { // draw with MainColor for TSolidColorStyle(3), TColorCleanupStyle(2001) @@ -439,7 +439,7 @@ void PageViewer::drawColorChip(QPainter &p, QRect &chipRect, //----------------------------------------------------------------------------- /*! Draw style \b style name in \b nameRect. -*/ + */ void PageViewer::drawColorName(QPainter &p, QRect &nameRect, TColorStyle *style, int styleIndex) { if (m_viewMode == SmallChips && style->getFlags() == 0) return; @@ -488,15 +488,15 @@ void PageViewer::drawColorName(QPainter &p, QRect &nameRect, TColorStyle *style, } if (m_viewMode == LargeChips) { - QString index = QString::number(styleIndex); - QFont font = p.font(); - int fontSize = font.pointSize(); + QString index = QString::number(styleIndex); + QFont font = p.font(); + int fontSize = font.pointSize(); if (fontSize == -1) fontSize = font.pixelSize(); - int length = index.length() * fontSize; - int w = (length > 11) ? (length) : 11; - int h = 11; - int x0 = nameRect.right() - w + 1; - int y0 = nameRect.top() - h - 1; + int length = index.length() * fontSize; + int w = (length > 11) ? (length) : 11; + int h = 11; + int x0 = nameRect.right() - w + 1; + int y0 = nameRect.top() - h - 1; p.drawText(nameRect.adjusted(6, 1, -6, -1), name); QRect indexRect(x0, y0, w, h); p.fillRect(indexRect, QBrush(Qt::white)); @@ -528,7 +528,7 @@ void PageViewer::drawColorName(QPainter &p, QRect &nameRect, TColorStyle *style, //----------------------------------------------------------------------------- /*! Draw the toggle to know if \b style is linked to a studio palette. -*/ + */ void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect, TColorStyle *style) { std::wstring globalName = style->getGlobalName(); @@ -556,7 +556,7 @@ void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect, //----------------------------------------------------------------------------- /*! Pain current page styles using current view mode. -*/ + */ void PageViewer::paintEvent(QPaintEvent *e) { QPainter p(this); if (m_chipPerRow == 0) { @@ -569,10 +569,10 @@ void PageViewer::paintEvent(QPaintEvent *e) { if (!palette) return; // [i0,i1] = range celle visibili - QRect visibleRect = e->rect(); - int i0 = posToIndex(visibleRect.topLeft()); - if (i0 < 0) i0 = 0; - int i1 = posToIndex(visibleRect.bottomRight()); + QRect visibleRect = e->rect(); + int i0 = posToIndex(visibleRect.topLeft()); + if (i0 < 0) i0 = 0; + int i1 = posToIndex(visibleRect.bottomRight()); if (i1 >= getChipCount()) i1 = getChipCount() - 1; if (m_viewMode == List) { @@ -879,7 +879,7 @@ void PageViewer::paintEvent(QPaintEvent *e) { //----------------------------------------------------------------------------- /*! Recall computeSize(). -*/ + */ void PageViewer::resizeEvent(QResizeEvent *) { computeSize(); } //----------------------------------------------------------------------------- @@ -957,7 +957,7 @@ void PageViewer::mousePressEvent(QMouseEvent *event) { //----------------------------------------------------------------------------- /*! If left botton is pressed start drag. -*/ + */ void PageViewer::mouseMoveEvent(QMouseEvent *event) { if (!m_page) return; if (m_viewType == CLEANUP_PALETTE) return; @@ -1057,7 +1057,7 @@ void PageViewer::addNewPage() { //----------------------------------------------------------------------------- /*! Create and open the Right-click menu in page. -*/ + */ void PageViewer::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); @@ -1144,19 +1144,13 @@ void PageViewer::contextMenuEvent(QContextMenuEvent *event) { connect(newPage, SIGNAL(triggered()), SLOT(addNewPage())); } - /* - if (m_viewType != STUDIO_PALETTE) { - menu.addAction(cmd->getAction(MI_EraseUnusedStyles)); - } - */ - menu.exec(event->globalPos()); } //----------------------------------------------------------------------------- /*! Accept drag enter event if evant data ha format \b * TStyleSelection::getMimeType(). -*/ + */ void PageViewer::dragEnterEvent(QDragEnterEvent *event) { if (!m_page) return; const PaletteData *paletteData = @@ -1176,7 +1170,7 @@ void PageViewer::dragEnterEvent(QDragEnterEvent *event) { if (index < 0) index = 0; else if (index > m_page->getStyleCount()) - index = m_page->getStyleCount(); + index = m_page->getStyleCount(); m_dropPositionIndex = index; update(); event->acceptProposedAction(); @@ -1196,7 +1190,7 @@ void PageViewer::dragMoveEvent(QDragMoveEvent *event) { if (index < 0) index = 0; else if (index > m_page->getStyleCount()) - index = m_page->getStyleCount(); + index = m_page->getStyleCount(); m_dropPositionIndex = index; update(); event->acceptProposedAction(); @@ -1205,7 +1199,7 @@ void PageViewer::dragMoveEvent(QDragMoveEvent *event) { //----------------------------------------------------------------------------- /*! If event data has correct format drop it in current drop position index. -*/ + */ void PageViewer::dropEvent(QDropEvent *event) { int dstIndexInPage = m_dropPositionIndex; m_dropPositionIndex = -1; @@ -1217,7 +1211,7 @@ void PageViewer::dropEvent(QDropEvent *event) { //----------------------------------------------------------------------------- /*! Set to -1 drag position index and update view. -*/ + */ void PageViewer::dragLeaveEvent(QDragLeaveEvent *event) { m_dropPositionIndex = -1; update(); @@ -1225,7 +1219,7 @@ void PageViewer::dragLeaveEvent(QDragLeaveEvent *event) { //----------------------------------------------------------------------------- /*! Start drag and drop; if current page exist set drag and drop event data. -*/ + */ void PageViewer::startDragDrop() { TRepetitionGuard guard; if (!guard.hasLock()) return; @@ -1272,9 +1266,8 @@ void PageViewer::keyPressEvent(QKeyEvent *e) { if (key == cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomIn))) zoomInChip(); - else if (key == - cManager->getKeyFromShortcut( - cManager->getShortcutFromId(V_ZoomOut))) + else if (key == cManager->getKeyFromShortcut( + cManager->getShortcutFromId(V_ZoomOut))) zoomOutChip(); else e->ignore(); @@ -1301,7 +1294,7 @@ void PageViewer::hideEvent(QHideEvent *) { //----------------------------------------------------------------------------- /*! Manage page tooltip. -*/ + */ bool PageViewer::event(QEvent *e) { if (m_page && e->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = dynamic_cast(e); @@ -1383,8 +1376,8 @@ void PageViewer::select(int indexInPage, QMouseEvent *event) { } bool isStyleChanged = false; - if (on) selected = true; - int styleIndex = m_page->getStyleId(indexInPage); + if (on) selected = true; + int styleIndex = m_page->getStyleId(indexInPage); if (selected) { setCurrentStyleIndex(styleIndex); @@ -1402,7 +1395,7 @@ void PageViewer::select(int indexInPage, QMouseEvent *event) { //----------------------------------------------------------------------------- /*! Compute page size in regard to chip count. -*/ + */ void PageViewer::computeSize() { if (!m_page) { m_chipPerRow = 0; @@ -1428,7 +1421,7 @@ void PageViewer::onFrameChanged() { //----------------------------------------------------------------------------- /*! Rename current style and update its view in current page. -*/ + */ // recall from m_renameTextField void PageViewer::onStyleRenamed() { m_renameTextField->hide(); @@ -1482,7 +1475,7 @@ PaletteTabBar::PaletteTabBar(QWidget *parent, bool hasPageCommand) //----------------------------------------------------------------------------- /*! Hide rename text field and recall \b QTabBar::mousePressEvent(). -*/ + */ void PaletteTabBar::mousePressEvent(QMouseEvent *event) { m_renameTextField->hide(); QTabBar::mousePressEvent(event); @@ -1513,7 +1506,7 @@ void PaletteTabBar::mouseMoveEvent(QMouseEvent *event) { //----------------------------------------------------------------------------- /*! Set a text field with focus in event position to edit tab name. -*/ + */ void PaletteTabBar::mouseDoubleClickEvent(QMouseEvent *event) { if (!m_hasPageCommand) return; if (m_pageViewer->getPage()->getPalette()->isLocked()) return; @@ -1531,7 +1524,7 @@ void PaletteTabBar::mouseDoubleClickEvent(QMouseEvent *event) { //----------------------------------------------------------------------------- /*! If event data is a paletteData accept drag event; otherwise return. -*/ + */ void PaletteTabBar::dragEnterEvent(QDragEnterEvent *event) { if (!m_hasPageCommand) return; const PaletteData *paletteData = @@ -1569,7 +1562,7 @@ void PaletteTabBar::dragMoveEvent(QDragMoveEvent *event) { //----------------------------------------------------------------------------- /*! Recall PageViewer::drop(). -*/ + */ void PaletteTabBar::dropEvent(QDropEvent *event) { if (!m_hasPageCommand) return; if (!dynamic_cast(event->mimeData())) return; @@ -1695,7 +1688,7 @@ void PageViewer::setNameDisplayMode(NameDisplayMode mode) { //----------------------------------------------------------------------------- /*! lock the commands when the styleSelection set to current -*/ + */ void PageViewer::updateCommandLocks() { if (!m_page) return; // iwasawa @@ -1713,4 +1706,5 @@ void PageViewer::updateCommandLocks() { cmd->getAction("MI_GetColorFromStudioPalette")->setEnabled(!isLocked); cmd->getAction("MI_ToggleLinkToStudioPalette")->setEnabled(!isLocked); cmd->getAction("MI_RemoveReferenceToStudioPalette")->setEnabled(!isLocked); + cmd->getAction("MI_EraseUnusedStyles")->setEnabled(!isLocked); } diff --git a/toonz/sources/toonzqt/styleselection.cpp b/toonz/sources/toonzqt/styleselection.cpp index 0711315..26d95b6 100644 --- a/toonz/sources/toonzqt/styleselection.cpp +++ b/toonz/sources/toonzqt/styleselection.cpp @@ -169,7 +169,7 @@ void deleteStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle, int pageIndex, std::set *styleIndicesInPage, int fir = 0) { if (!palette) palette = pltHandle->getPalette(); - int n = styleIndicesInPage->size(); + int n = styleIndicesInPage->size(); if (n == 0) return; TPalette::Page *page = palette->getPage(pageIndex); assert(page); @@ -510,7 +510,7 @@ void TStyleSelection::enableCommands() { } } enableCommand(this, MI_Clear, &TStyleSelection::deleteStyles); - enableCommand(this, MI_EraseUnusedStyles, &TStyleSelection::eraseUnsedStyle); + enableCommand(this, MI_EraseUnusedStyles, &TStyleSelection::eraseUnusedStyle); enableCommand(this, MI_BlendColors, &TStyleSelection::blendStyles); } @@ -694,7 +694,7 @@ void TStyleSelection::deleteStyles() { //------------------------------------------------------------------- -void TStyleSelection::eraseUnsedStyle() { +void TStyleSelection::eraseUnusedStyle() { std::set levels; int row, column, i, j; TPalette *palette = m_paletteHandle->getPalette(); @@ -728,26 +728,59 @@ void TStyleSelection::eraseUnsedStyle() { } } - TUndoManager::manager()->beginBlock(); - + // check if there are styles to be erased + QMap> styleIndicesInPageMap; + QString indicesStr; + int count = 0; // Butto gli stili non usati for (i = 0; i < pageCount; i++) { // Variabili usate per l'undo std::set styleIndicesInPage; - StyleData *data = new StyleData(); TPalette::Page *page = palette->getPage(i); assert(page); for (j = 0; j < page->getStyleCount(); j++) { int styleId = page->getStyleId(j); if (usedStyleIds[styleId]) continue; styleIndicesInPage.insert(j); - data->addStyle(styleId, page->getStyle(j)->clone()); + if (count < 10) indicesStr.append(QString::number(styleId) + ", "); + count++; } - // Se styleIndicesInPage e' vuoto ci sono stili da cancellare. - if (styleIndicesInPage.empty()) { - delete data; - continue; + if (!styleIndicesInPage.empty()) + styleIndicesInPageMap.insert(i, styleIndicesInPage); + } + + if (styleIndicesInPageMap.isEmpty()) { + DVGui::error(QObject::tr("There are no unused styles.")); + return; + } + if (count <= 10) + indicesStr.chop(2); + else + indicesStr.append( + QObject::tr("and %1 more styles.").arg(QString::number(count - 10))); + // open confirmation popup + QString question = + QObject::tr( + "Erasing unused styles with following indices. Are you sure?\n\n%1") + .arg(indicesStr); + int ret = + DVGui::MsgBox(question, QObject::tr("Erase"), QObject::tr("Cancel"), 0); + if (ret == 2 || ret == 0) return; + + TUndoManager::manager()->beginBlock(); + + QMap>::const_iterator styleMapItr = + styleIndicesInPageMap.constBegin(); + while (styleMapItr != styleIndicesInPageMap.constEnd()) { + int pageIndex = styleMapItr.key(); + std::set styleIndicesInPage = styleMapItr.value(); + StyleData *data = new StyleData(); + TPalette::Page *page = palette->getPage(pageIndex); + for (auto indexInPage : styleIndicesInPage) { + int styleId = page->getStyleId(indexInPage); + data->addStyle(styleId, page->getStyle(indexInPage)->clone()); } + // Cancello gli stili std::set::reverse_iterator it; for (it = styleIndicesInPage.rbegin(); it != styleIndicesInPage.rend(); @@ -755,9 +788,11 @@ void TStyleSelection::eraseUnsedStyle() { page->removeStyle(*it); // Undo DeleteStylesUndo *undo = new DeleteStylesUndo(this, data); - undo->setPageIndex(i); + undo->setPageIndex(pageIndex); undo->setStyleIndicesInPage(styleIndicesInPage); TUndoManager::manager()->add(undo); + + ++styleMapItr; } TUndoManager::manager()->endBlock(); m_paletteHandle->setStyleIndex(1); @@ -1436,7 +1471,7 @@ void TStyleSelection::toggleLink() { name[0] = name[0] == L'-' ? L'+' : L'-'; cs->setGlobalName(name); if (name[0] == L'+') somethingHasBeenLinked = true; - somethingChanged = true; + somethingChanged = true; } undo->setColorStyle(index, oldCs, name); @@ -1594,7 +1629,7 @@ public: //----------------------------------------------------------------------------- /*! remove link from studio palette. Delete the global and the orginal names. * return true if something changed -*/ + */ void TStyleSelection::removeLink() { TPalette *palette = getPalette(); if (!palette || m_pageIndex < 0) return; @@ -1709,7 +1744,7 @@ public: //----------------------------------------------------------------------------- /*! get the color from the linked style of the studio palette -*/ + */ void TStyleSelection::getBackOriginalStyle() { TPalette *palette = getPalette(); if (!palette || m_pageIndex < 0) return; @@ -1792,7 +1827,7 @@ void TStyleSelection::getBackOriginalStyle() { //----------------------------------------------------------------------------- /*! return true if there is at least one linked style in the selection -*/ + */ bool TStyleSelection::hasLinkedStyle() { TPalette *palette = getPalette();