2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef ICON_GENERATOR_H
|
|
|
|
#define ICON_GENERATOR_H
|
|
|
|
|
|
|
|
// TnzCore includes
|
|
|
|
#include "tthread.h"
|
|
|
|
#include "tgeometry.h"
|
|
|
|
#include "tfilepath.h"
|
|
|
|
#include "traster.h"
|
|
|
|
#include "timage.h"
|
|
|
|
#include "tpixel.h"
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QThreadStorage>
|
|
|
|
#include <QEventLoop>
|
|
|
|
|
|
|
|
// STD includes
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#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 TFilePath;
|
|
|
|
class TXshLevel;
|
|
|
|
class TStageObjectSpline;
|
|
|
|
class ToonzScene;
|
|
|
|
class TOfflineGL;
|
|
|
|
|
|
|
|
//==============================================================
|
|
|
|
|
|
|
|
//**********************************************************************************
|
|
|
|
// IconGenerator definition
|
|
|
|
//**********************************************************************************
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief The class responsible for icons management in Toonz.
|
|
|
|
|
|
|
|
\details It's a singleton class - in particular, rendered icons are stored in
|
2016-06-15 18:43:10 +12:00
|
|
|
a shared map container for fast retrieval upon repeated icon
|
|
|
|
requests.
|
|
|
|
|
|
|
|
IconGenerator provides methods to submit icon requests, and to
|
|
|
|
invalidate or
|
|
|
|
remove icons from the internal database. In order to keep outer
|
|
|
|
entities
|
|
|
|
informed of the icon generation status, an iconGenerated() signal is
|
|
|
|
emitted
|
2016-03-19 06:57:51 +13:00
|
|
|
once an icon has been generated.
|
|
|
|
*/
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI IconGenerator final : public QObject {
|
2016-06-15 18:43:10 +12:00
|
|
|
Q_OBJECT
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
class Settings {
|
|
|
|
public:
|
|
|
|
bool m_blackBgCheck;
|
|
|
|
bool m_transparencyCheck;
|
|
|
|
bool m_inksOnly;
|
|
|
|
int m_inkIndex;
|
|
|
|
int m_paintIndex;
|
|
|
|
|
|
|
|
Settings()
|
|
|
|
: m_transparencyCheck(false)
|
|
|
|
, m_blackBgCheck(false)
|
|
|
|
, m_inksOnly(false)
|
|
|
|
, m_inkIndex(-1)
|
|
|
|
, m_paintIndex(-1) {}
|
|
|
|
};
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
IconGenerator();
|
|
|
|
~IconGenerator();
|
|
|
|
|
|
|
|
static IconGenerator *instance();
|
|
|
|
|
|
|
|
void setSettings(const Settings &settings) { m_settings = settings; }
|
|
|
|
const Settings getSettings() const { return m_settings; }
|
|
|
|
static void setFilmstripIconSize(const TDimension &dim);
|
|
|
|
|
|
|
|
TDimension getIconSize() const;
|
|
|
|
|
|
|
|
TOfflineGL *getOfflineGLContext();
|
|
|
|
|
|
|
|
// icons from splines
|
|
|
|
QPixmap getIcon(TStageObjectSpline *spline);
|
|
|
|
void invalidate(TStageObjectSpline *spline);
|
|
|
|
void remove(TStageObjectSpline *spline);
|
|
|
|
|
|
|
|
// icons from toonz levels
|
|
|
|
QPixmap getIcon(TXshLevel *sl, const TFrameId &fid, bool filmStrip = true,
|
|
|
|
bool onDemand = false);
|
2020-05-17 16:24:15 +12:00
|
|
|
QPixmap getSizedIcon(TXshLevel *sl, const TFrameId &fid, std::string newId,
|
|
|
|
TDimension dim = TDimension(0, 0));
|
2016-06-15 18:43:10 +12:00
|
|
|
void invalidate(TXshLevel *sl, const TFrameId &fid,
|
|
|
|
bool onlyFilmStrip = false);
|
|
|
|
void remove(TXshLevel *sl, const TFrameId &fid, bool onlyFilmStrip = false);
|
|
|
|
|
|
|
|
// icons from files
|
|
|
|
QPixmap getIcon(const TFilePath &path,
|
|
|
|
const TFrameId &fid = TFrameId::NO_FRAME);
|
|
|
|
void invalidate(const TFilePath &path,
|
|
|
|
const TFrameId &fid = TFrameId::NO_FRAME);
|
|
|
|
void remove(const TFilePath &path, const TFrameId &fid = TFrameId::NO_FRAME);
|
|
|
|
|
|
|
|
QPixmap getSceneIcon(ToonzScene *scene); // Unused in Toonz
|
|
|
|
void invalidateSceneIcon();
|
|
|
|
|
|
|
|
void remap(const std::string &newIconId, const std::string &oldIconId);
|
|
|
|
|
|
|
|
void clearRequests();
|
|
|
|
void clearSceneIcons();
|
|
|
|
|
|
|
|
static TRaster32P generateVectorFileIcon(const TFilePath &path,
|
|
|
|
const TDimension &iconSize,
|
|
|
|
const TFrameId &fid);
|
|
|
|
static TRaster32P generateRasterFileIcon(const TFilePath &path,
|
|
|
|
const TDimension &iconSize,
|
|
|
|
const TFrameId &fid);
|
|
|
|
static TRaster32P generateSceneFileIcon(const TFilePath &path,
|
|
|
|
const TDimension &iconSize, int row);
|
|
|
|
static TRaster32P generateSplineFileIcon(const TFilePath &path,
|
|
|
|
const TDimension &iconSize);
|
|
|
|
static TRaster32P generateMeshFileIcon(const TFilePath &path,
|
|
|
|
const TDimension &iconSize,
|
|
|
|
const TFrameId &fid);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-07-08 05:06:59 +12:00
|
|
|
// This function is called when only colors of styles are changed in toonz
|
|
|
|
// raster levels. In such case it doesn't need to re-compute icons but needs
|
|
|
|
// to let panels to update. See TApp::onLevelColorStyleChanged() for details.
|
|
|
|
void notifyIconGenerated() { emit iconGenerated(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
signals:
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void iconGenerated();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void onStarted(TThread::RunnableP iconRenderer);
|
|
|
|
void onCanceled(TThread::RunnableP iconRenderer);
|
|
|
|
void onFinished(TThread::RunnableP iconRenderer);
|
|
|
|
void onException(TThread::RunnableP iconRenderer);
|
|
|
|
void onTerminated(TThread::RunnableP iconRenderer);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
TThread::Executor m_executor;
|
|
|
|
QThreadStorage<TOfflineGL *> m_contexts;
|
|
|
|
TDimension m_iconSize;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QEventLoop m_iconsTerminationLoop; //!< Event loop used to wait for icons
|
2016-06-20 14:23:05 +12:00
|
|
|
//! termination.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
Settings m_settings;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
void addTask(const std::string &id, TThread::RunnableP iconRenderer);
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//**********************************************************************************
|
|
|
|
// Related non-member functions
|
|
|
|
//**********************************************************************************
|
|
|
|
|
|
|
|
template <class It>
|
2016-06-15 18:43:10 +12:00
|
|
|
inline void invalidateIcons(TXshLevel *sl, It fBegin, It fEnd,
|
|
|
|
bool onlyFilmStrip = false) {
|
|
|
|
for (It ft = fBegin; ft != fEnd; ++ft)
|
|
|
|
IconGenerator::instance()->invalidate(sl, *ft, onlyFilmStrip);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <class C>
|
2016-06-15 18:43:10 +12:00
|
|
|
inline void invalidateIcons(TXshLevel *sl, const C &fids,
|
|
|
|
bool onlyFilmStrip = false) {
|
|
|
|
invalidateIcons(sl, fids.begin(), fids.end(), onlyFilmStrip);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename It>
|
2016-06-15 18:43:10 +12:00
|
|
|
inline void removeIcons(TXshLevel *sl, It fBegin, It fEnd,
|
|
|
|
bool onlyFilmStrip = false) {
|
|
|
|
for (It ft = fBegin; ft != fEnd; ++ft)
|
|
|
|
IconGenerator::instance()->remove(sl, *ft, onlyFilmStrip);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename C>
|
2016-06-15 18:43:10 +12:00
|
|
|
inline void removeIcons(TXshLevel *sl, const C &fids,
|
|
|
|
bool onlyFilmStrip = false) {
|
|
|
|
removeIcons(sl, fids.begin(), fids.end(), onlyFilmStrip);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // ICON_GENERATOR_H
|