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

243 lines
6.1 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 SWATCHVIEWER_H
#define SWATCHVIEWER_H
#ifdef _MSC_VER
2016-03-19 06:57:51 +13:00
#pragma warning(disable : 4251)
#endif
#include "tcommon.h"
#include <QWidget>
#include "tfx.h"
#include "tparamset.h"
#include "trenderer.h"
#include "tthreadmessage.h"
#include "tthread.h"
#include "trop.h"
#include <QTouchDevice>
2016-03-19 06:57:51 +13:00
using namespace TThread;
#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 QTouchEvent;
class QGestureEvent;
2016-03-19 06:57:51 +13:00
//=============================================================================
2016-06-15 18:43:10 +12:00
class DVAPI BgPainter {
std::string m_name;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
BgPainter(std::string name) : m_name(name) {}
virtual ~BgPainter() {}
std::string getName() const { return m_name; }
virtual void paint(const TRaster32P &ras) = 0;
2016-03-19 06:57:51 +13:00
};
//=============================================================================
class DVAPI SolidColorBgPainter final : public BgPainter {
2016-06-15 18:43:10 +12:00
TPixel32 m_color;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
SolidColorBgPainter(std::string name, TPixel32 color)
: BgPainter(name), m_color(color) {}
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void paint(const TRaster32P &ras) override { ras->fill(m_color); }
2016-03-19 06:57:51 +13:00
};
//=============================================================================
class DVAPI CheckboardBgPainter final : public BgPainter {
2016-06-15 18:43:10 +12:00
TPixel32 m_c0, m_c1;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
CheckboardBgPainter(std::string name, TPixel32 c0, TPixel32 c1)
: BgPainter(name), m_c0(c0), m_c1(c1) {}
2016-06-19 20:06:29 +12:00
void paint(const TRaster32P &ras) override {
2016-06-15 18:43:10 +12:00
int n = 4, min = 4;
TDimensionD d(std::max(min, ras->getLx() / n),
std::max(min, ras->getLy() / n));
d.lx = d.ly = std::max(d.lx, d.ly);
TRop::checkBoard(ras, m_c0, m_c1, d, TPointD());
}
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*! \brief SwatchViewer.
2016-06-15 18:43:10 +12:00
Inherits \b QWidget.
2016-03-19 06:57:51 +13:00
*/
class DVAPI SwatchViewer final : public QWidget {
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
//! La classe \b Point gestisce un punto che e' collegato a parametri \b
//! TPointParam.
/*!Questo tipo di punti consentono di modificare alcuni parametri dell'effetto
corrente e
sono editabili dall'utente direttamente nello SwatchViewer*/
class Point {
public:
int m_index;
TPointParamP m_param;
bool m_pairFlag;
Point(int index, const TPointParamP &param)
: m_index(index), m_param(param), m_pairFlag(false) {}
};
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TFxP m_fx;
TFxP m_actualFxClone;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRaster32P m_raster;
TRaster32P m_content;
TAffine m_aff;
TAffine m_fxAff;
TAffine m_contentAff;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_cameraMode;
TRect m_cameraRect;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Qt::MouseButton m_mouseButton;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::vector<Point> m_points;
std::vector<std::pair<int, int>> m_pointPairs;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_selectedPoint;
TPointD m_pointPosDelta;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_enabled;
bool m_firstEnabled;
2016-06-15 18:43:10 +12:00
int m_frame;
TThread::Executor m_executor;
TThread::Mutex m_mutex;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRenderer m_renderer;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
BgPainter *m_bgPainter;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRaster32P m_crossIcon;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPoint m_pos;
TPoint m_firstPos;
TRaster32P m_oldContent, m_curContent;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_computing;
2016-03-19 06:57:51 +13:00
bool m_touchActive = false;
bool m_gestureActive = false;
QTouchDevice::DeviceType m_touchDevice = QTouchDevice::TouchScreen;
bool m_zooming = false;
bool m_panning = false;
double m_scaleFactor; // used for zoom gesture
bool m_stylusUsed = false;
2016-06-15 18:43:10 +12:00
friend class ContentRender;
2016-03-19 06:57:51 +13:00
public:
class ContentRender final : public TThread::Runnable {
2016-06-15 18:43:10 +12:00
public:
TRasterFxP m_fx;
TRasterP m_raster;
int m_frame;
TDimension m_size;
TAffine m_aff;
SwatchViewer *m_viewer;
bool m_started;
ContentRender(TRasterFx *fx, int frame, const TDimension &size,
SwatchViewer *viewer);
~ContentRender();
2016-06-19 20:06:29 +12:00
void run() override;
int taskLoad() override;
2016-06-15 18:43:10 +12:00
2016-06-19 20:06:29 +12:00
void onStarted(TThread::RunnableP task) override;
void onFinished(TThread::RunnableP task) override;
void onCanceled(TThread::RunnableP task) override;
2016-06-15 18:43:10 +12:00
};
2016-03-19 06:57:51 +13:00
#if QT_VERSION >= 0x050500
2016-06-15 18:43:10 +12:00
SwatchViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0);
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
SwatchViewer(QWidget *parent = 0, Qt::WFlags flags = 0);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
~SwatchViewer();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static void suspendRendering(bool suspend, bool blocking = true);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setCameraMode(bool enabled) { m_cameraMode = enabled; }
bool getCameraMode() const { return m_cameraMode; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setCameraSize(const TDimension &cameraSize);
TDimension getCameraSize() const { return m_cameraRect.getSize(); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setFx(const TFxP &fx, const TFxP &actualFx, int frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void updateFrame(int frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isEnabled() { return m_enabled; }
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
void setEnable(bool enabled);
void updateSize(const QSize &size);
void setBgPainter(TPixel32 color1, TPixel32 color2 = TPixel32());
void resetView();
void fitView();
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
void computeContent();
TPoint world2win(const TPointD &p) const;
TPointD win2world(const TPoint &p) const;
void zoom(const TPoint &pos, double factor);
void zoom(bool forward, bool reset);
void pan(const TPoint &delta);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void updateRaster();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TRaster32P &getContent() const { return m_content; }
void setContent(const TRaster32P &content, const TAffine &contentAff);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setAff(const TAffine &aff);
2016-03-19 06:57:51 +13:00
void contextMenuEvent(QContextMenuEvent *event) override;
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *) override;
void keyPressEvent(QKeyEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void hideEvent(QHideEvent *event) override;
2016-03-19 06:57:51 +13:00
void mouseDoubleClickEvent(QMouseEvent *event) override;
void tabletEvent(QTabletEvent *e) override;
void touchEvent(QTouchEvent *e, int type);
void gestureEvent(QGestureEvent *e);
bool event(QEvent *e) override;
private:
QPointF m_firstPanPoint;
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void pointPositionChanged(int index, const TPointD &p);
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // SWATCHVIEWER_H