Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef STUDIOPALETTEVIEWER_H
Toshihiro Shimizu 890ddd
#define STUDIOPALETTEVIEWER_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/studiopalette.h"
Toshihiro Shimizu 890ddd
#include "toonz/tproject.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qtreewidget></qtreewidget>
Toshihiro Shimizu 890ddd
#include <qsplitter></qsplitter>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TOONZQT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
class QLabel;
Toshihiro Shimizu 890ddd
class TPaletteHandle;
Toshihiro Shimizu 890ddd
class TFrameHandle;
Toshihiro Shimizu 890ddd
class PalettesScanPopup;
Toshihiro Shimizu 890ddd
class TXsheetHandle;
Toshihiro Shimizu 890ddd
class TXshLevelHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
//!	The StudioPaletteTreeViewer class provides an object to view and manage
Shinya Kitaoka 38fd86
//! palettes files.
Shinya Kitaoka 120a6e
/*!	Inherits \b QTreeWidget, \b StudioPalette::Listener and \b
Shinya Kitaoka 120a6e
   ProjectManager::Listener.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                This object provides interface for class \b StudioPalette.
Shinya Kitaoka 120a6e
                StudioPaletteTreeViewer is a \b QTreeWidget with three root item
Shinya Kitaoka 120a6e
   related to level palette
Shinya Kitaoka 120a6e
                folder and current project palette folder, the three root folder
Shinya Kitaoka 120a6e
   of \b StudioPalette.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka d1f6c4
class DVAPI StudioPaletteTreeViewer final : public QTreeWidget,
Shinya Kitaoka d1f6c4
                                            public StudioPalette::Listener,
Shinya Kitaoka d1f6c4
                                            public TProjectManager::Listener {
Shinya Kitaoka 120a6e
  Q_OBJECT
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPaletteP m_currentPalette;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PalettesScanPopup *m_palettesScanPopup;
Shinya Kitaoka 120a6e
  QTreeWidgetItem *m_dropItem;
Shinya Kitaoka 120a6e
  TPaletteHandle *m_levelPaletteHandle;
Shinya Kitaoka 120a6e
  TPaletteHandle *m_studioPaletteHandle;
Shinya Kitaoka 120a6e
  TXsheetHandle *m_xsheetHandle;
Shinya Kitaoka 120a6e
  TXshLevelHandle *m_currentLevelHandle;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QIcon m_folderIcon;
Shinya Kitaoka 120a6e
  QIcon m_levelPaletteIcon;
Shinya Kitaoka 120a6e
  QIcon m_studioPaletteIcon;
Shinya Kitaoka 120a6e
  // keep the checked item list in order to avoid multiple check
Shinya Kitaoka 120a6e
  QSet<qtreewidgetitem *=""> m_openedItems;</qtreewidgetitem>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  StudioPaletteTreeViewer(QWidget *parent, TPaletteHandle *studioPaletteHandle,
Shinya Kitaoka 120a6e
                          TPaletteHandle *levelPaletteHandle,
Shinya Kitaoka 120a6e
                          TXsheetHandle *xsheetHandle,
Shinya Kitaoka 120a6e
                          TXshLevelHandle *currentLevelHandle);
Shinya Kitaoka 120a6e
  ~StudioPaletteTreeViewer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setLevelPaletteHandle(TPaletteHandle *paletteHandle);
Shinya Kitaoka 120a6e
  TPaletteHandle *getLevelPaletteHandle() const { return m_levelPaletteHandle; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setCurrentLevelHandle(TXshLevelHandle *currentLevelHandle);
Shinya Kitaoka 120a6e
  TXshLevelHandle *getCurrentLevelHandle() const {
Shinya Kitaoka 120a6e
    return m_currentLevelHandle;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setStdPaletteHandle(TPaletteHandle *stdPaletteHandle);
Shinya Kitaoka 120a6e
  TPaletteHandle *getStdPaletteHandle() const { return m_studioPaletteHandle; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!	Overriden from StudioPalette::Listener. */
Shinya Kitaoka 473e70
  void onStudioPaletteTreeChange() override { refresh(); }
Shinya Kitaoka 120a6e
  /*!	Overriden from StudioPalette::Listener. */
Shinya Kitaoka 38fd86
  void onStudioPaletteMove(const TFilePath &dstPath,
Shinya Kitaoka 38fd86
                           const TFilePath &srcPath) override {
Shinya Kitaoka 120a6e
    refresh();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*!	Overriden from StudioPalette::Listener. */
Shinya Kitaoka 473e70
  void onStudioPaletteChange(const TFilePath &palette) override { refresh(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!	Overriden from TProjectManager::Listener. */
Shinya Kitaoka 473e70
  void onProjectSwitched() override { resetProjectPaletteFolder(); }
Shinya Kitaoka 120a6e
  /*!	Overriden from TProjectManager::Listener. */
Shinya Kitaoka 473e70
  void onProjectChanged() override { resetProjectPaletteFolder(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFilePath getCurrentItemPath() { return getItemPath(currentItem()); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected slots:
Shinya Kitaoka 120a6e
  /*! Refresh all item of three root item in tree and preserve current item. */
Shinya Kitaoka 120a6e
  void refresh();
Shinya Kitaoka 120a6e
  /*! Refresh item \b item and its children; take path concerning \b item and
Shinya Kitaoka 120a6e
                  compare \b StudioPalette folder in path with folder in item.
Shinya Kitaoka 120a6e
                  If are not equal add or remove child to current \b item.
Shinya Kitaoka 120a6e
     Recall itself
Shinya Kitaoka 120a6e
                  for each item child. */
Shinya Kitaoka 120a6e
  void refreshItem(QTreeWidgetItem *);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Delete old project palette item and create the new one.*/
Shinya Kitaoka 120a6e
  void resetProjectPaletteFolder();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onItemClicked(QTreeWidgetItem *item, int column);
Shinya Kitaoka 120a6e
  /*! If item \b item name change update path name in \b StudioPalette. */
Shinya Kitaoka 120a6e
  void onItemChanged(QTreeWidgetItem *item, int column);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onCurrentItemChanged(QTreeWidgetItem *current,
Shinya Kitaoka 120a6e
                            QTreeWidgetItem *previous);
Shinya Kitaoka 120a6e
  /*! When expand a tree, prepare the child items of it */
Shinya Kitaoka 120a6e
  void onTreeItemExpanded(QTreeWidgetItem *);
Shinya Kitaoka 120a6e
  /*! Refresh tree only when this widget has focus*/
Shinya Kitaoka 120a6e
  void onRefreshTreeShortcutTriggered();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  /*! Create a new \b StudioPalette palette in current item path. */
Shinya Kitaoka 120a6e
  void addNewPalette();
Shinya Kitaoka 120a6e
  /*! Create a new \b StudioPalette folder in current item path. */
Shinya Kitaoka 120a6e
  void addNewFolder();
Shinya Kitaoka 120a6e
  /*! Delete all item selected recalling \b deleteItem(). */
Shinya Kitaoka 120a6e
  void deleteItems();
Shinya Kitaoka 120a6e
  /*! Open a \b PalettesScanPopup. */
Shinya Kitaoka 120a6e
  void searchForPalette();
Shinya Kitaoka 120a6e
  /*! Recall \b StudioPaletteCmd::loadIntoCurrentPalette. */
Shinya Kitaoka 120a6e
  void loadInCurrentPalette();
Shinya Kitaoka 120a6e
  void loadInCurrentPaletteAndAdaptLevel();
Shinya Kitaoka 120a6e
  /*! Recall \b StudioPaletteCmd::replaceWithCurrentPalette. */
Shinya Kitaoka 120a6e
  void replaceCurrentPalette();
Shinya Kitaoka 120a6e
  /*! Recall \b StudioPaletteCmd::mergeIntoCurrentPalette. */
Shinya Kitaoka 120a6e
  void mergeToCurrentPalette();
Shinya Kitaoka 120a6e
  /*! Convert level palette to studio palette. */
Shinya Kitaoka 120a6e
  void convertToStudioPalette();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  /*! Delete \b item path from \b StudioPalette. If item is a not empty
Shinya Kitaoka 120a6e
                  folder send a question to know if must delete item or not. */
Shinya Kitaoka 120a6e
  void deleteItem(QTreeWidgetItem *item);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Create and refresh root item: Studio Palette and Cleanup Palette. */
Shinya Kitaoka 120a6e
  QTreeWidgetItem *createRootItem(const TFilePath path);
Shinya Kitaoka 120a6e
  /*! Return true if \b item match with Studio Palette or Cleanup Palette
Shinya Kitaoka 120a6e
   * folder. */
Shinya Kitaoka 120a6e
  bool isRootItem(QTreeWidgetItem *item);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Create a new item related to path \b path. */
Shinya Kitaoka 120a6e
  QTreeWidgetItem *createItem(const TFilePath path);
Shinya Kitaoka 120a6e
  /*! Return path related to item \b item if \b item exist, otherwise return an
Shinya Kitaoka 120a6e
   * empty path \b TFilePath. */
Shinya Kitaoka 120a6e
  TFilePath getItemPath(QTreeWidgetItem *);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Return current item path. */
Shinya Kitaoka 120a6e
  TFilePath getCurrentFolderPath();
Shinya Kitaoka 120a6e
  /*! Return item identified by \b path; if it doesn't exist return 0. */
Shinya Kitaoka 120a6e
  QTreeWidgetItem *getItem(const TFilePath path);
Shinya Kitaoka 120a6e
  /*! Return item child of \b parent identified by \b path; if it doesn't exist
Shinya Kitaoka 120a6e
   * return 0. */
Shinya Kitaoka 120a6e
  QTreeWidgetItem *getFolderItem(QTreeWidgetItem *parent, const TFilePath path);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void resetDropItem();
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *event) override;
Shinya Kitaoka 120a6e
  /*! Open a context menu considering current item data role \b Qt::UserRole. */
Shinya Kitaoka 473e70
  void contextMenuEvent(QContextMenuEvent *event) override;
Shinya Kitaoka 120a6e
  /*! Add an action to menu \b menu; the action has text \b name and its
Shinya Kitaoka 120a6e
                  \b triggered() signal is connetted with \b slot. */
Shinya Kitaoka 120a6e
  void createMenuAction(QMenu &menu, const char *id, QString name,
Shinya Kitaoka 120a6e
                        const char *slot);
Shinya Kitaoka 120a6e
  /*! If button left is pressed start drag and drop. */
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *event) override;
Shinya Kitaoka 120a6e
  /*! If path related to current item exist and is a palette execute drag. */
Shinya Kitaoka 120a6e
  void startDragDrop();
Shinya Kitaoka 120a6e
  /*! Verify drag enter data, if it has an url and it's path is a palette or
Shinya Kitaoka 120a6e
     data
Shinya Kitaoka 120a6e
                  is a PaletteData accept drag event. */
Shinya Kitaoka 473e70
  void dragEnterEvent(QDragEnterEvent *event) override;
Shinya Kitaoka 120a6e
  /*! Find item folder nearest to current position. */
Shinya Kitaoka 473e70
  void dragMoveEvent(QDragMoveEvent *event) override;
Shinya Kitaoka 120a6e
  /*! Execute drop event. If dropped palette is in studio palette folder move
Shinya Kitaoka 120a6e
                  palette, otherwise copy palette in current folder. */
Shinya Kitaoka 473e70
  void dropEvent(QDropEvent *event) override;
Shinya Kitaoka 120a6e
  /*! Set dropItem to 0 and update the tree. */
Shinya Kitaoka 473e70
  void dragLeaveEvent(QDragLeaveEvent *event) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
//!	The StudioPaletteViewer class provides an object to view and manage
Shinya Kitaoka 38fd86
//! studio palettes.
Toshihiro Shimizu 890ddd
/*!	Inherits \b QFrame.
Shinya Kitaoka 120a6e
                This object is composed of a splitter \b QSplitter that contain
Shinya Kitaoka 120a6e
   a vertical
Shinya Kitaoka 120a6e
                layout and a \b PaletteViewer. Vertical layout contain a \b
Shinya Kitaoka 120a6e
   StudioPaletteTreeViewer
Shinya Kitaoka 120a6e
                and a toolbar, this object allows to manage the palettes in
Shinya Kitaoka 120a6e
   studio palette folders.
Shinya Kitaoka 120a6e
                \b PaletteViewer is set to fixed view type: \b
Shinya Kitaoka 120a6e
   PaletteViewerGUI::STUDIO_PALETTE
Shinya Kitaoka 120a6e
                allows to show and modify current studio palette selected in
Shinya Kitaoka 120a6e
   tree.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka d1f6c4
class DVAPI StudioPaletteViewer final : public QSplitter {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  StudioPaletteTreeViewer *m_studioPaletteTreeViewer;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  StudioPaletteViewer(QWidget *parent, TPaletteHandle *studioPaletteHandle,
Shinya Kitaoka 120a6e
                      TPaletteHandle *levelPaletteHandle,
Shinya Kitaoka 120a6e
                      TFrameHandle *frameHandle, TXsheetHandle *xsheetHandle,
Shinya Kitaoka 120a6e
                      TXshLevelHandle *currentLevelHandle);
Shinya Kitaoka 120a6e
  ~StudioPaletteViewer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! In order to save current palette from the tool button in the PageViewer.*/
Shinya Kitaoka 120a6e
  TFilePath getCurrentItemPath();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // STUDIOPALETTEVIEWER_H