diff --git a/toonz/sources/common/tvrender/tpalette.cpp b/toonz/sources/common/tvrender/tpalette.cpp index fd5735a..e9fc009 100644 --- a/toonz/sources/common/tvrender/tpalette.cpp +++ b/toonz/sources/common/tvrender/tpalette.cpp @@ -193,7 +193,8 @@ TPalette::TPalette() , m_mutex(QMutex::Recursive) , m_isLocked(false) , m_askOverwriteFlag(false) - , m_shortcutScopeIndex(0) { + , m_shortcutScopeIndex(0) + , m_currentStyleId(1) { QString tempName(QObject::tr("colors")); std::wstring pageName = tempName.toStdWString(); Page *page = addPage(pageName); diff --git a/toonz/sources/include/toonz/tpalettehandle.h b/toonz/sources/include/toonz/tpalettehandle.h index 30539ff..5539e36 100644 --- a/toonz/sources/include/toonz/tpalettehandle.h +++ b/toonz/sources/include/toonz/tpalettehandle.h @@ -44,7 +44,7 @@ public: TColorStyle *getStyle() const; - void setPalette(TPalette *palette, int styleIndex = 1); + void setPalette(TPalette *palette, int styleIndex = -1); void setStyleIndex(int index, bool forceEmit = false); diff --git a/toonz/sources/include/toonzqt/paletteviewer.h b/toonz/sources/include/toonzqt/paletteviewer.h index a42a069..10c6abf 100644 --- a/toonz/sources/include/toonzqt/paletteviewer.h +++ b/toonz/sources/include/toonzqt/paletteviewer.h @@ -162,6 +162,8 @@ protected slots: void onNameDisplayMode(QAction *); void setIsLocked(bool lock); + + void onSwitchToPage(int pageIndex); }; #endif // PALETTEVIEWER_H diff --git a/toonz/sources/include/toonzqt/paletteviewergui.h b/toonz/sources/include/toonzqt/paletteviewergui.h index 5e03c6d..505054c 100644 --- a/toonz/sources/include/toonzqt/paletteviewergui.h +++ b/toonz/sources/include/toonzqt/paletteviewergui.h @@ -211,6 +211,7 @@ private: signals: void changeWindowTitleSignal(); + void switchToPage(int); }; //**************************************************************************** diff --git a/toonz/sources/include/tpalette.h b/toonz/sources/include/tpalette.h index 63c41e7..0e77668 100644 --- a/toonz/sources/include/tpalette.h +++ b/toonz/sources/include/tpalette.h @@ -132,13 +132,13 @@ public: //! \return The insertion index in the page, or \p -1 on failure int addStyle(int styleId); //!< Adds the specified style Id to the page (at //! the \a back - //! of the page). - /*! -\warning The supplied style must have been allocated with \a new. -\warning Style ownership is surrendered to the palette. -\return The insertion index in the page, or \p -1 on failure. - In case of failure, the supplied style is \a deleted. -*/ + //! of the page). + /*! + \warning The supplied style must have been allocated with \a new. + \warning Style ownership is surrendered to the palette. + \return The insertion index in the page, or \p -1 on failure. + In case of failure, the supplied style is \a deleted. + */ int addStyle(TColorStyle *style); //!< Adds the specified style to the //! palette, and assigns it //! to this page. @@ -214,6 +214,8 @@ private: int m_shortcutScopeIndex; + int m_currentStyleId; + public: TPalette(); ~TPalette(); @@ -425,6 +427,9 @@ between RGBA color components. void nextShortcutScope(bool invert); + void setCurrentStyleId(int id) { m_currentStyleId = id; } + int getCurrentStyleId() const { return m_currentStyleId; } + public: // Deprecated functions diff --git a/toonz/sources/toonzlib/tpalettehandle.cpp b/toonz/sources/toonzlib/tpalettehandle.cpp index fd0835e..7a310b1 100644 --- a/toonz/sources/toonzlib/tpalettehandle.cpp +++ b/toonz/sources/toonzlib/tpalettehandle.cpp @@ -130,6 +130,17 @@ bool TPaletteHandle::disconnectBroadcasts(const QObject *receiver) { //----------------------------------------------------------------------------- void TPaletteHandle::setPalette(TPalette *palette, int styleIndex) { + if (palette) { + if (styleIndex < 0) { + styleIndex = palette->getCurrentStyleId(); + if (!palette->getStylePage(styleIndex)) { // in case the style is deleted + styleIndex = 1; + palette->setCurrentStyleId(styleIndex); + } + } else + palette->setCurrentStyleId(styleIndex); + } + if (m_palette == palette) setStyleIndex(styleIndex); else { @@ -147,6 +158,7 @@ void TPaletteHandle::setPalette(TPalette *palette, int styleIndex) { void TPaletteHandle::setStyleIndex(int index, bool forceEmit) { if (m_styleIndex != index || m_styleParamIndex != 0 || forceEmit) { + if (m_palette) m_palette->setCurrentStyleId(index); m_styleIndex = index; m_styleParamIndex = 0; emit broadcastColorStyleSwitched(); diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cpp index ddb8ace..9299590 100644 --- a/toonz/sources/toonzqt/paletteviewer.cpp +++ b/toonz/sources/toonzqt/paletteviewer.cpp @@ -39,40 +39,40 @@ using namespace PaletteViewerGUI; //============================================================================= /*! \class PaletteViewer - \brief The PaletteViewer class provides an object to view and - manage palette view. - - Inherits \b QWidget. - - This object allows to show and manage palette; it's possible - distinguish three - view type, class can show: current level palette, current studio - palette or - current cleanup palette, using setPalette() to set palette - viewer. - The object is composed of a vertical layout with three widget: - \li a tab bar \b PaletteViewerGUI::TabBar in which are displayed - palette page - \b createTabBar(); - \li a central frame \b PaletteViewerGUI::PageViewer in which are - displayed - all style of current page in palette - \li a button bar, \b createToolBar(), \b createPaletteToolBar() - and \b createSavePaletteToolBar(); - - A collection of method allows you to manage this object and its - interaction - with palette. - */ +\brief The PaletteViewer class provides an object to view and +manage palette view. + +Inherits \b QWidget. + +This object allows to show and manage palette; it's possible +distinguish three +view type, class can show: current level palette, current studio +palette or +current cleanup palette, using setPalette() to set palette +viewer. +The object is composed of a vertical layout with three widget: +\li a tab bar \b PaletteViewerGUI::TabBar in which are displayed +palette page +\b createTabBar(); +\li a central frame \b PaletteViewerGUI::PageViewer in which are +displayed +all style of current page in palette +\li a button bar, \b createToolBar(), \b createPaletteToolBar() +and \b createSavePaletteToolBar(); + +A collection of method allows you to manage this object and its +interaction +with palette. +*/ /*! \fn const TPaletteP PaletteViewer::&getPalette() const - Return current viewer palette. - */ +Return current viewer palette. +*/ /*! \fn void PaletteViewer::createToolBar() - Create down button bar. - */ +Create down button bar. +*/ /*! \fn void PaletteViewer::updateToolBar() - Update button bar. - */ +Update button bar. +*/ PaletteViewer::PaletteViewer(QWidget *parent, PaletteViewType viewType, bool hasSaveToolBar, bool hasPageCommand, bool hasPasteColors) @@ -115,7 +115,7 @@ PaletteViewer::PaletteViewer(QWidget *parent, PaletteViewType viewType, toolbarScrollWidget->setObjectName( "ToolBarContainer"); // Toonz's qss files are instructed to leave a - // 1px grey margin on top for scroll buttons + // 1px grey margin on top for scroll buttons QWidget *toolBarWidget = new QWidget; // children of this parent name. toolbarScrollWidget->setWidget(toolBarWidget); toolBarWidget->setSizePolicy(QSizePolicy::MinimumExpanding, @@ -169,6 +169,8 @@ PaletteViewer::PaletteViewer(QWidget *parent, PaletteViewType viewType, SLOT(movePage(int, int))); connect(m_pageViewer, SIGNAL(changeWindowTitleSignal()), this, SLOT(changeWindowTitle())); + connect(m_pageViewer, SIGNAL(switchToPage(int)), this, + SLOT(onSwitchToPage(int))); changeWindowTitle(); @@ -235,7 +237,7 @@ 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); @@ -437,8 +439,8 @@ void PaletteViewer::createPaletteToolBar() { //----------------------------------------------------------------------------- /*! Create left part of button bar; insert different actions in according to - current viewer palette type. - */ +current viewer palette type. +*/ void PaletteViewer::createSavePaletteToolBar() { m_savePaletteToolBar->clear(); m_savePaletteToolBar->setMovable(false); @@ -515,7 +517,7 @@ void PaletteViewer::updateTabBar() { //----------------------------------------------------------------------------- /*! Update right button bar, enable its action if current viewer palette is - * empty. +* empty. */ void PaletteViewer::updatePaletteToolBar() { if (!m_paletteToolBar) return; @@ -541,7 +543,7 @@ void PaletteViewer::updatePaletteToolBar() { //----------------------------------------------------------------------------- /*! Update left button bar, enable its action if current viewer palette is - * empty. +* empty. */ void PaletteViewer::updateSavePaletteToolBar() { if (!m_savePaletteToolBar) return; @@ -669,8 +671,8 @@ void PaletteViewer::hideEvent(QHideEvent *) { //----------------------------------------------------------------------------- /*! If currente palette viewer exist verify event data, if is a PaletteData or - has urls accept event. - */ +has urls accept event. +*/ void PaletteViewer::dragEnterEvent(QDragEnterEvent *event) { TPalette *palette = getPalette(); if (!palette || m_viewType == CLEANUP_PALETTE) return; @@ -682,7 +684,7 @@ void PaletteViewer::dragEnterEvent(QDragEnterEvent *event) { // Sto "draggando" stili. if (paletteData->hasStyleIndeces()) { m_pageViewer->createDropPage(); - if (!palette) m_pagesBar->setCurrentIndex(palette->getPageCount() - 1); + if (!palette) onSwitchToPage(palette->getPageCount() - 1); } // Accetto l'evento event->acceptProposedAction(); @@ -735,8 +737,11 @@ void PaletteViewer::dropEvent(QDropEvent *event) { if (ret == 0) return; } StudioPaletteCmd::loadIntoCurrentPalette(m_paletteHandle, path); - } else + } else { + int nextPageIndex = m_paletteHandle->getPalette()->getPageCount(); StudioPaletteCmd::mergeIntoCurrentPalette(m_paletteHandle, path); + if (!i) onSwitchToPage(nextPageIndex); + } if (loadPalette) { TFilePath refImagePath = @@ -770,8 +775,11 @@ void PaletteViewer::dropEvent(QDropEvent *event) { if (ret == 0) return; } StudioPaletteCmd::loadIntoCurrentPalette(m_paletteHandle, palette); - } else + } else { + int nextPageIndex = m_paletteHandle->getPalette()->getPageCount(); StudioPaletteCmd::mergeIntoCurrentPalette(m_paletteHandle, palette); + onSwitchToPage(nextPageIndex); + } } } @@ -812,8 +820,8 @@ void PaletteViewer::setPageView(int currentIndexPage) { //----------------------------------------------------------------------------- /*! If current palette viewer is not empty create emit a signal to create new - palette page. - */ +palette page. +*/ void PaletteViewer::addNewPage() { TPalette *palette = getPalette(); if (palette) { @@ -821,14 +829,15 @@ void PaletteViewer::addNewPage() { updateTabBar(); PaletteCmd::addPage(m_paletteHandle); + onSwitchToPage(m_paletteHandle->getPalette()->getPageCount() - 1); } } //----------------------------------------------------------------------------- /*! Create a new style in current page view of current palette viewer emit a - signal - to create a new style. - */ +signal +to create a new style. +*/ void PaletteViewer::addNewColor() { if (!getPalette() || getPalette()->isLocked()) return; @@ -867,8 +876,8 @@ void PaletteViewer::deletePage() { //----------------------------------------------------------------------------- /*! If current palette view is studio palette and palette has a global name - save current viewer palette in studio palette. - */ +save current viewer palette in studio palette. +*/ void PaletteViewer::saveStudioPalette() { StudioPalette *sp = StudioPalette::instance(); TPalette *palette = getPalette(); @@ -941,7 +950,7 @@ void PaletteViewer::onColorStyleSwitched() { if (indexInPage == -1) { if (!palette->getStylePage(styleIndex)) return; int pageIndex = palette->getStylePage(styleIndex)->getIndex(); - m_pagesBar->setCurrentIndex(pageIndex); + onSwitchToPage(pageIndex); indexInPage = m_pageViewer->getPage()->search(styleIndex); } @@ -959,7 +968,7 @@ void PaletteViewer::onColorStyleSwitched() { void PaletteViewer::onPaletteChanged() { int index = m_pagesBar->currentIndex(); updateTabBar(); - m_pagesBar->setCurrentIndex(index); + onSwitchToPage(index); m_pageViewer->update(); @@ -973,6 +982,17 @@ void PaletteViewer::onPaletteChanged() { void PaletteViewer::onPaletteSwitched() { updateView(); + int pageIndex = 0; + if (m_paletteHandle) { + TPalette *palette = m_paletteHandle->getPalette(); + if (palette) { + int currentStyleId = palette->getCurrentStyleId(); + TPalette::Page *page = palette->getStylePage(currentStyleId); + if (page) pageIndex = page->getIndex(); + } + } + onSwitchToPage(pageIndex); + // update GUI according to the "lock" property if (getPalette() && m_viewType != CLEANUP_PALETTE && (m_lockPaletteAction || m_lockPaletteToolButton)) { @@ -1031,8 +1051,8 @@ void PaletteViewer::onNameDisplayMode(QAction *action) { //----------------------------------------------------------------------------- /*! If current view type is LEVEL_PALETTE add to window title current level - name and current frame. - */ +name and current frame. +*/ void PaletteViewer::changeWindowTitle() { QString name = tr("Palette"); QWidget *titleOwner; @@ -1074,11 +1094,11 @@ 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); - m_pagesBar->setCurrentIndex(dstIndex); + onSwitchToPage(dstIndex); } //----------------------------------------------------------------------------- @@ -1093,3 +1113,7 @@ void PaletteViewer::setIsLocked(bool lock) { // notify for updating the style editor m_paletteHandle->notifyPaletteLockChanged(); } + +void PaletteViewer::onSwitchToPage(int pageIndex) { + m_pagesBar->setCurrentIndex(pageIndex); +} diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index db6c68e..c3450ed 100644 --- a/toonz/sources/toonzqt/paletteviewergui.cpp +++ b/toonz/sources/toonzqt/paletteviewergui.cpp @@ -1047,7 +1047,10 @@ void PageViewer::addNewColor() { //----------------------------------------------------------------------------- void PageViewer::addNewPage() { - PaletteCmd::addPage(getPaletteHandle()); + TPaletteHandle *paletteHandle = getPaletteHandle(); + PaletteCmd::addPage(paletteHandle); + if (paletteHandle) + emit switchToPage(paletteHandle->getPalette()->getPageCount() - 1); update(); }