2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef STUDIOPALETTEVIEWER_H
|
|
|
|
#define STUDIOPALETTEVIEWER_H
|
|
|
|
|
|
|
|
#include "toonz/studiopalette.h"
|
2021-10-15 14:25:30 +13:00
|
|
|
#include "toonz/tapplication.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "toonz/tproject.h"
|
2021-10-15 14:25:30 +13:00
|
|
|
#include "toonzqt/paletteviewer.h"
|
2019-08-19 21:52:45 +12:00
|
|
|
#include "toonzqt/dvdialog.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QSplitter>
|
|
|
|
|
|
|
|
#undef DVAPI
|
|
|
|
#undef DVVAR
|
|
|
|
#ifdef TOONZQT_EXPORTS
|
|
|
|
#define DVAPI DV_EXPORT_API
|
|
|
|
#define DVVAR DV_EXPORT_VAR
|
|
|
|
#else
|
|
|
|
#define DVAPI DV_IMPORT_API
|
|
|
|
#define DVVAR DV_IMPORT_VAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// forward declaration
|
|
|
|
class QLabel;
|
|
|
|
class TPaletteHandle;
|
|
|
|
class TFrameHandle;
|
|
|
|
class PalettesScanPopup;
|
|
|
|
class TXsheetHandle;
|
|
|
|
class TXshLevelHandle;
|
2018-11-16 22:28:38 +13:00
|
|
|
class PaletteViewer;
|
2019-08-19 21:52:45 +12:00
|
|
|
namespace DVGui {
|
|
|
|
class IntField;
|
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
//=============================================================================
|
2016-06-15 18:43:10 +12:00
|
|
|
//! The StudioPaletteTreeViewer class provides an object to view and manage
|
2016-06-20 14:23:05 +12:00
|
|
|
//! palettes files.
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Inherits \b QTreeWidget, \b StudioPalette::Listener and \b
|
|
|
|
ProjectManager::Listener.
|
|
|
|
|
|
|
|
This object provides interface for class \b StudioPalette.
|
|
|
|
StudioPaletteTreeViewer is a \b QTreeWidget with three root item
|
|
|
|
related to level palette
|
|
|
|
folder and current project palette folder, the three root folder
|
|
|
|
of \b StudioPalette.
|
2016-03-19 06:57:51 +13:00
|
|
|
*/
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI StudioPaletteTreeViewer final : public QTreeWidget,
|
|
|
|
public StudioPalette::Listener,
|
|
|
|
public TProjectManager::Listener {
|
2016-06-15 18:43:10 +12:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
TPaletteP m_currentPalette;
|
|
|
|
|
|
|
|
PalettesScanPopup *m_palettesScanPopup;
|
|
|
|
QTreeWidgetItem *m_dropItem;
|
|
|
|
TPaletteHandle *m_levelPaletteHandle;
|
|
|
|
TPaletteHandle *m_studioPaletteHandle;
|
|
|
|
TXsheetHandle *m_xsheetHandle;
|
|
|
|
TXshLevelHandle *m_currentLevelHandle;
|
|
|
|
|
|
|
|
QIcon m_folderIcon;
|
|
|
|
QIcon m_levelPaletteIcon;
|
|
|
|
QIcon m_studioPaletteIcon;
|
|
|
|
// keep the checked item list in order to avoid multiple check
|
|
|
|
QSet<QTreeWidgetItem *> m_openedItems;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-01-15 20:30:19 +13:00
|
|
|
QPoint m_startPos;
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
StudioPaletteTreeViewer(QWidget *parent, TPaletteHandle *studioPaletteHandle,
|
|
|
|
TPaletteHandle *levelPaletteHandle,
|
|
|
|
TXsheetHandle *xsheetHandle,
|
|
|
|
TXshLevelHandle *currentLevelHandle);
|
|
|
|
~StudioPaletteTreeViewer();
|
|
|
|
|
|
|
|
void setLevelPaletteHandle(TPaletteHandle *paletteHandle);
|
|
|
|
TPaletteHandle *getLevelPaletteHandle() const { return m_levelPaletteHandle; }
|
|
|
|
|
|
|
|
void setCurrentLevelHandle(TXshLevelHandle *currentLevelHandle);
|
|
|
|
TXshLevelHandle *getCurrentLevelHandle() const {
|
|
|
|
return m_currentLevelHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setStdPaletteHandle(TPaletteHandle *stdPaletteHandle);
|
|
|
|
TPaletteHandle *getStdPaletteHandle() const { return m_studioPaletteHandle; }
|
|
|
|
|
2021-07-08 13:39:28 +12:00
|
|
|
/*! Overridden from StudioPalette::Listener. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void onStudioPaletteTreeChange() override { refresh(); }
|
2021-07-08 13:39:28 +12:00
|
|
|
/*! Overridden from StudioPalette::Listener. */
|
2016-06-20 14:23:05 +12:00
|
|
|
void onStudioPaletteMove(const TFilePath &dstPath,
|
|
|
|
const TFilePath &srcPath) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
refresh();
|
|
|
|
}
|
2021-07-08 13:39:28 +12:00
|
|
|
/*! Overridden from StudioPalette::Listener. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void onStudioPaletteChange(const TFilePath &palette) override { refresh(); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
2021-07-08 13:39:28 +12:00
|
|
|
/*! Overridden from TProjectManager::Listener. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void onProjectSwitched() override { resetProjectPaletteFolder(); }
|
2021-07-08 13:39:28 +12:00
|
|
|
/*! Overridden from TProjectManager::Listener. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void onProjectChanged() override { resetProjectPaletteFolder(); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
TFilePath getCurrentItemPath() { return getItemPath(currentItem()); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected slots:
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Refresh all item of three root item in tree and preserve current item. */
|
|
|
|
void refresh();
|
|
|
|
/*! Refresh item \b item and its children; take path concerning \b item and
|
|
|
|
compare \b StudioPalette folder in path with folder in item.
|
|
|
|
If are not equal add or remove child to current \b item.
|
|
|
|
Recall itself
|
|
|
|
for each item child. */
|
|
|
|
void refreshItem(QTreeWidgetItem *);
|
|
|
|
|
|
|
|
/*! Delete old project palette item and create the new one.*/
|
|
|
|
void resetProjectPaletteFolder();
|
|
|
|
|
|
|
|
void onItemClicked(QTreeWidgetItem *item, int column);
|
|
|
|
/*! If item \b item name change update path name in \b StudioPalette. */
|
|
|
|
void onItemChanged(QTreeWidgetItem *item, int column);
|
|
|
|
|
|
|
|
void onCurrentItemChanged(QTreeWidgetItem *current,
|
|
|
|
QTreeWidgetItem *previous);
|
|
|
|
/*! When expand a tree, prepare the child items of it */
|
|
|
|
void onTreeItemExpanded(QTreeWidgetItem *);
|
|
|
|
/*! Refresh tree only when this widget has focus*/
|
|
|
|
void onRefreshTreeShortcutTriggered();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public slots:
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Create a new \b StudioPalette palette in current item path. */
|
|
|
|
void addNewPalette();
|
|
|
|
/*! Create a new \b StudioPalette folder in current item path. */
|
|
|
|
void addNewFolder();
|
|
|
|
/*! Delete all item selected recalling \b deleteItem(). */
|
|
|
|
void deleteItems();
|
|
|
|
/*! Open a \b PalettesScanPopup. */
|
|
|
|
void searchForPalette();
|
|
|
|
/*! Recall \b StudioPaletteCmd::loadIntoCurrentPalette. */
|
|
|
|
void loadInCurrentPalette();
|
|
|
|
void loadInCurrentPaletteAndAdaptLevel();
|
|
|
|
/*! Recall \b StudioPaletteCmd::replaceWithCurrentPalette. */
|
|
|
|
void replaceCurrentPalette();
|
|
|
|
/*! Recall \b StudioPaletteCmd::mergeIntoCurrentPalette. */
|
|
|
|
void mergeToCurrentPalette();
|
|
|
|
/*! Convert level palette to studio palette. */
|
|
|
|
void convertToStudioPalette();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Delete \b item path from \b StudioPalette. If item is a not empty
|
|
|
|
folder send a question to know if must delete item or not. */
|
|
|
|
void deleteItem(QTreeWidgetItem *item);
|
|
|
|
|
|
|
|
/*! Create and refresh root item: Studio Palette and Cleanup Palette. */
|
|
|
|
QTreeWidgetItem *createRootItem(const TFilePath path);
|
|
|
|
/*! Return true if \b item match with Studio Palette or Cleanup Palette
|
|
|
|
* folder. */
|
|
|
|
bool isRootItem(QTreeWidgetItem *item);
|
|
|
|
|
|
|
|
/*! Create a new item related to path \b path. */
|
|
|
|
QTreeWidgetItem *createItem(const TFilePath path);
|
|
|
|
/*! Return path related to item \b item if \b item exist, otherwise return an
|
|
|
|
* empty path \b TFilePath. */
|
|
|
|
TFilePath getItemPath(QTreeWidgetItem *);
|
|
|
|
|
|
|
|
/*! Return current item path. */
|
|
|
|
TFilePath getCurrentFolderPath();
|
|
|
|
/*! Return item identified by \b path; if it doesn't exist return 0. */
|
|
|
|
QTreeWidgetItem *getItem(const TFilePath path);
|
|
|
|
/*! Return item child of \b parent identified by \b path; if it doesn't exist
|
|
|
|
* return 0. */
|
|
|
|
QTreeWidgetItem *getFolderItem(QTreeWidgetItem *parent, const TFilePath path);
|
|
|
|
|
|
|
|
void resetDropItem();
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Open a context menu considering current item data role \b Qt::UserRole. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Add an action to menu \b menu; the action has text \b name and its
|
|
|
|
\b triggered() signal is connetted with \b slot. */
|
|
|
|
void createMenuAction(QMenu &menu, const char *id, QString name,
|
|
|
|
const char *slot);
|
|
|
|
/*! If button left is pressed start drag and drop. */
|
2020-01-15 20:30:19 +13:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
2016-06-19 20:06:29 +12:00
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
2020-01-15 20:30:19 +13:00
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! If path related to current item exist and is a palette execute drag. */
|
|
|
|
void startDragDrop();
|
|
|
|
/*! Verify drag enter data, if it has an url and it's path is a palette or
|
|
|
|
data
|
|
|
|
is a PaletteData accept drag event. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Find item folder nearest to current position. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Execute drop event. If dropped palette is in studio palette folder move
|
|
|
|
palette, otherwise copy palette in current folder. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void dropEvent(QDropEvent *event) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Set dropItem to 0 and update the tree. */
|
2016-06-19 20:06:29 +12:00
|
|
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
2016-06-15 18:43:10 +12:00
|
|
|
//! The StudioPaletteViewer class provides an object to view and manage
|
2016-06-20 14:23:05 +12:00
|
|
|
//! studio palettes.
|
2016-03-19 06:57:51 +13:00
|
|
|
/*! Inherits \b QFrame.
|
2016-06-15 18:43:10 +12:00
|
|
|
This object is composed of a splitter \b QSplitter that contain
|
|
|
|
a vertical
|
|
|
|
layout and a \b PaletteViewer. Vertical layout contain a \b
|
|
|
|
StudioPaletteTreeViewer
|
|
|
|
and a toolbar, this object allows to manage the palettes in
|
|
|
|
studio palette folders.
|
|
|
|
\b PaletteViewer is set to fixed view type: \b
|
|
|
|
PaletteViewerGUI::STUDIO_PALETTE
|
|
|
|
allows to show and modify current studio palette selected in
|
|
|
|
tree.
|
2016-03-19 06:57:51 +13:00
|
|
|
*/
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI StudioPaletteViewer final : public QSplitter {
|
2016-06-15 18:43:10 +12:00
|
|
|
Q_OBJECT
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
StudioPaletteTreeViewer *m_studioPaletteTreeViewer;
|
2018-11-16 22:28:38 +13:00
|
|
|
PaletteViewer *m_studioPaletteViewer;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2021-10-15 14:25:30 +13:00
|
|
|
TApplication *m_app;
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
StudioPaletteViewer(QWidget *parent, TPaletteHandle *studioPaletteHandle,
|
|
|
|
TPaletteHandle *levelPaletteHandle,
|
|
|
|
TFrameHandle *frameHandle, TXsheetHandle *xsheetHandle,
|
|
|
|
TXshLevelHandle *currentLevelHandle);
|
|
|
|
~StudioPaletteViewer();
|
|
|
|
|
|
|
|
/*! In order to save current palette from the tool button in the PageViewer.*/
|
|
|
|
TFilePath getCurrentItemPath();
|
2018-11-16 22:28:38 +13:00
|
|
|
|
|
|
|
int getViewMode() const;
|
|
|
|
void setViewMode(int mode);
|
2021-10-15 14:25:30 +13:00
|
|
|
|
|
|
|
void setApplication(TApplication *app) {
|
|
|
|
m_app = app;
|
|
|
|
if (m_studioPaletteViewer) m_studioPaletteViewer->setApplication(app);
|
|
|
|
}
|
|
|
|
TApplication *getApplication() { return m_app; }
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2019-08-19 21:52:45 +12:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class AdjustPaletteDialog final : public DVGui::Dialog {
|
|
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
DVGui::IntField *m_tolerance;
|
|
|
|
|
|
|
|
public:
|
|
|
|
int getTolerance();
|
|
|
|
AdjustPaletteDialog();
|
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // STUDIOPALETTEVIEWER_H
|