tahoma2d/toonz/sources/include/toonzqt/paletteviewergui.h

320 lines
8.9 KiB
C
Raw Normal View History

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