Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef PALETTEVIEWERGUI_H
Toshihiro Shimizu 890ddd
#define PALETTEVIEWERGUI_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/selection.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/lineedit.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qframe></qframe>
Toshihiro Shimizu 890ddd
#include <qtabbar></qtabbar>
Toshihiro Shimizu 890ddd
#include <qshortcut></qshortcut>
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
//==============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//    Forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TXsheetHandle;
Toshihiro Shimizu 890ddd
class TFrameHandle;
Toshihiro Shimizu 890ddd
class TPaletteHandle;
Toshihiro Shimizu 890ddd
class TXshLevelHandle;
Toshihiro Shimizu 890ddd
class TStyleSelection;
Toshihiro Shimizu 890ddd
class TabBarContainter;
Toshihiro Shimizu 890ddd
class ChangeStyleCommand;
Toshihiro Shimizu 890ddd
class QMimeData;
Toshihiro Shimizu 890ddd
class StyleNameEditor;
Toshihiro Shimizu 890ddd
//==============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    PaletteViewerGUI  namespace
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  \brief    Contains classes pertaining the GUI of a Toonz Palette Viewer.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace PaletteViewerGUI {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// class for managing the palette's default style chip size
Shinya Kitaoka 120a6e
class DVAPI ChipSizeManager {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  int chipSize_Palette;
Shinya Kitaoka 120a6e
  int chipSize_Cleanup;
Shinya Kitaoka 120a6e
  int chipSize_Studio;
Shinya Kitaoka 120a6e
  static ChipSizeManager *instance() {
Shinya Kitaoka 120a6e
    static ChipSizeManager _instance;
Shinya Kitaoka 120a6e
    return &_instance;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  ChipSizeManager()
Shinya Kitaoka 120a6e
      : chipSize_Palette(2), chipSize_Cleanup(2), chipSize_Studio(2) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
enum PaletteViewType  //! Possible palette contents of a Palette Viewer.
Shinya Kitaoka 120a6e
{ LEVEL_PALETTE,      //!< Content palette is from a level.
Shinya Kitaoka 120a6e
  CLEANUP_PALETTE,    //!< Content palette is from cleanup settings.
Shinya Kitaoka 120a6e
  STUDIO_PALETTE      //!< Content palette is from a Studio Palette panel.
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    PageViewer  declaration
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI PageViewer final : public QFrame, public TSelection::View {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QColor m_textColor;  // text color used for list view
Shinya Kitaoka 120a6e
  Q_PROPERTY(QColor TextColor READ getTextColor WRITE setTextColor)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  enum ViewMode         //! Possible view modes for a Palette Viewer.
Shinya Kitaoka 120a6e
  { SmallChips,         //!< Small icons.
Shinya Kitaoka 120a6e
    MediumChips,        //!< Medium icons.
Shinya Kitaoka 120a6e
    LargeChips,         //!< Large icons with style names.
Shinya Kitaoka 120a6e
    List,               //!< Top-down list of all icons.
Shinya Kitaoka 120a6e
    SmallChipsWithName  //!< Small icons with overlayed style names (if
Shinya Kitaoka 38fd86
                        //! user-defined).
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // for displaying the linked style name from studio palette
Shinya Kitaoka 120a6e
  enum NameDisplayMode { Style, Original, StyleAndOriginal };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PageViewer(QWidget *parent = 0, PaletteViewType viewType = LEVEL_PALETTE,
Shinya Kitaoka 120a6e
             bool hasPasteColors = true);
Shinya Kitaoka 120a6e
  ~PageViewer();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setPaletteHandle(TPaletteHandle *paletteHandle);
Shinya Kitaoka 120a6e
  TPaletteHandle *getPaletteHandle() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setXsheetHandle(TXsheetHandle *xsheetHandle);
Shinya Kitaoka 120a6e
  TXsheetHandle *getXsheetHandle() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setFrameHandle(TFrameHandle *xsheetHandle);
Shinya Kitaoka 120a6e
  TFrameHandle *getFrameHandle() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // for clearing the cache when execute paste style command on styleSelection
Shinya Kitaoka 120a6e
  void setLevelHandle(TXshLevelHandle *levelHandle);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setCurrentStyleIndex(int index);
Shinya Kitaoka 120a6e
  int getCurrentStyleIndex() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setPage(TPalette::Page *page);
Shinya Kitaoka 120a6e
  TPalette::Page *getPage() const { return m_page; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setChangeStyleCommand(ChangeStyleCommand *changeStyleCommand) {
Shinya Kitaoka 120a6e
    m_changeStyleCommand = changeStyleCommand;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  ChangeStyleCommand *getChangeStyleCommand() const {
Shinya Kitaoka 120a6e
    return m_changeStyleCommand;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getChipCount() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ViewMode getViewMode() const { return m_viewMode; }
Shinya Kitaoka 120a6e
  void setViewMode(ViewMode mode);
Shinya Kitaoka 120a6e
  void setNameDisplayMode(NameDisplayMode mode);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PaletteViewerGUI::PaletteViewType getViewType() const { return m_viewType; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int posToIndex(const QPoint &pos) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QRect getItemRect(int index) const;
Shinya Kitaoka 120a6e
  QRect getColorChipRect(int index) const;
Shinya Kitaoka 120a6e
  QRect getColorNameRect(int index) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void drop(int indexInPage, const QMimeData *mimeData);
Shinya Kitaoka 120a6e
  void createDropPage();
Shinya Kitaoka 473e70
  void onSelectionChanged() override { update(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TStyleSelection *getSelection() const { return m_styleSelection; }
Shinya Kitaoka 120a6e
  void clearSelection();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // update the "lock"s for commands when the StyleSelection becomes current and
Shinya Kitaoka 120a6e
  // when the current palettte changed
Shinya Kitaoka 120a6e
  void updateCommandLocks();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setTextColor(const QColor &color) { m_textColor = color; }
Shinya Kitaoka 120a6e
  QColor getTextColor() const { return m_textColor; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void computeSize();
Shinya Kitaoka 120a6e
  void onFrameChanged();
Shinya Kitaoka 120a6e
  void onStyleRenamed();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void addNewColor();
Shinya Kitaoka 120a6e
  void addNewPage();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  QSize getChipSize() const;
Shinya Kitaoka 120a6e
  void drawColorChip(QPainter &p, QRect &chipRect, TColorStyle *style);
Shinya Kitaoka 120a6e
  void drawColorName(QPainter &p, QRect &nameRect, TColorStyle *style,
Shinya Kitaoka 120a6e
                     int styleIndex);
Shinya Kitaoka 120a6e
  void drawToggleLink(QPainter &p, QRect &chipRect, TColorStyle *style);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // event handlers
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void resizeEvent(QResizeEvent *) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QMouseEvent *event) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void mouseDoubleClickEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void contextMenuEvent(QContextMenuEvent *event) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void keyPressEvent(QKeyEvent *event) override;
Shinya Kitaoka 473e70
  void dragEnterEvent(QDragEnterEvent *event) override;
Shinya Kitaoka 473e70
  void dragMoveEvent(QDragMoveEvent *event) override;
Shinya Kitaoka 473e70
  void dropEvent(QDropEvent *event) override;
Shinya Kitaoka 473e70
  void dragLeaveEvent(QDragLeaveEvent *event) override;
Shinya Kitaoka 120a6e
  void startDragDrop();
Shinya Kitaoka 120a6e
  void createMenuAction(QMenu &menu, const char *id, QString name,
Shinya Kitaoka 120a6e
                        const char *slot);
Shinya Kitaoka 473e70
  void showEvent(QShowEvent *) override;
Shinya Kitaoka 473e70
  void hideEvent(QHideEvent *) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool event(QEvent *e) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void select(int indexInPage, QMouseEvent *event);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void zoomInChip();
Shinya Kitaoka 120a6e
  void zoomOutChip();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected slots:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void toggleLink();
Shinya Kitaoka 120a6e
  void eraseToggleLink();
Shinya Kitaoka 120a6e
  void removeLink();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  DVGui::LineEdit *m_renameTextField;
Shinya Kitaoka 120a6e
  QPoint m_dragStartPosition;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPalette::Page *m_page;
Shinya Kitaoka 120a6e
  QPoint m_chipsOrigin;
Shinya Kitaoka 120a6e
  int m_chipPerRow;
Shinya Kitaoka 120a6e
  ViewMode m_viewMode;
Shinya Kitaoka 120a6e
  NameDisplayMode m_nameDisplayMode;
Shinya Kitaoka 120a6e
  int m_dropPositionIndex;
Shinya Kitaoka 120a6e
  bool m_dropPageCreated;
Shinya Kitaoka 120a6e
  bool m_startDrag;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TStyleSelection *m_styleSelection;
Shinya Kitaoka 120a6e
  TFrameHandle *m_frameHandle;
Shinya Kitaoka 120a6e
  bool m_hasPasteColors;
Shinya Kitaoka 120a6e
  PaletteViewType m_viewType;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ChangeStyleCommand *m_changeStyleCommand;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QShortcut *m_zoomInShortCut;
Shinya Kitaoka 120a6e
  QShortcut *m_zoomOutShortCut;
Shinya Kitaoka 120a6e
  StyleNameEditor *m_styleNameEditor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void changeWindowTitleSignal();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    PaletteTabBar  declaration
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI PaletteTabBar final : public QTabBar {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PaletteTabBar(QWidget *parent, bool hasPageCommand);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setPageViewer(PageViewer *pageViewer) { m_pageViewer = pageViewer; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void updateTabName();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void tabTextChanged(int index);
Shinya Kitaoka 120a6e
  void movePage(int srcIndex, int dstIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void mouseDoubleClickEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void dragEnterEvent(QDragEnterEvent *event) override;
Shinya Kitaoka 473e70
  void dragMoveEvent(QDragMoveEvent *event) override;
Shinya Kitaoka 473e70
  void dropEvent(QDropEvent *event) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  DVGui::LineEdit *m_renameTextField;
Shinya Kitaoka 120a6e
  int m_renameTabIndex;
Shinya Kitaoka 120a6e
  PageViewer *m_pageViewer;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_hasPageCommand;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    PaletteIconWidget  declaration
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
        \brief    Special placeholder toolbar icon for \a starting a palette
Shinya Kitaoka 120a6e
   move
Shinya Kitaoka 120a6e
        through drag & drop.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        \details  This widget is currently employed as a mere mouse event filter
Shinya Kitaoka 120a6e
        to propagate drag & drop starts to a PaletteViewer ancestor
Shinya Kitaoka 120a6e
        in the widgets hierarchy.
Shinya Kitaoka 120a6e
        */
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI PaletteIconWidget final : public QWidget {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Shinya Kitaoka 120a6e
  PaletteIconWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  PaletteIconWidget(QWidget *parent = 0, Qt::WFlags flags = 0);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  ~PaletteIconWidget();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void startDrag();  //!< Emitted \a once whenever the icon is sensibly dragged
Shinya Kitaoka 120a6e
                     //!  by the user.
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void enterEvent(QEvent *event) override;
Shinya Kitaoka 473e70
  void leaveEvent(QEvent *event) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *event) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  QPoint m_mousePressPos;  //!< Mouse position at mouse press.
Shinya Kitaoka 120a6e
  bool m_isOver,           //!< Whether mouse is hovering on this widget.
Shinya Kitaoka 120a6e
      m_dragged;  //!< Whether user has started a drag operation on the icon.
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace PaletteViewerGUI
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // PALETTEVIEWERGUI_H