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

210 lines
6.5 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 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.
*/
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
Merge changes from OpenToonz as of 7-7 (#77) * add multi arc mockup * implement mutli arc * add join and smooth option * reset multiarc and arc when deactivated * create self loop if the last point is the same as the first * make join option in multiarc consistent with tape tool * fix a bug where thickness don't affect mutliarc in vector level * remove join option in geometric tool * stop mutliarc after closing shape * double click can also end multi arc * fix a bug where multiArc will produce buggy stroke * fix a bug where geometric tools is not deactivated * add multiArc shortcut * rewrite multiArc * revert changes to tvectorimage * add undo data for multiArc * Paste as Copy Command for XSheet * Remove unneeded code * Bug fix * prevent guide lines from jumping around in MultiArc * make stroke color consistent in MultiArc * remove color in MultiArc's undo data * make color consistent in MultiArc with previous version * Fix single image raster levels * fix compilation error * fix a bug where multiArc might generate bugged stroke * Remove ICONV dep (#3304) * fix crash on saving studio palette * Move to Paste Special Menu * Don't Set Fixed Width if Docking a Floating Panel * Update how_to_build_win.md New draft of pr for requested changes to windows build instructions. * fix geometric tool multiarc smooth option * fix level saving failure * fix wrong warning after saving palette * fix a bug where moving a control point while holding alt has unintended result * fix overwriting raster drawing palette * Hide color swatch on color 0 Co-authored-by: pojienie <pojienie@gmail.com> Co-authored-by: rim <11380091+rozhuk-im@users.noreply.github.com> Co-authored-by: shun-iwasawa <shun.iwasawa@ghibli.jp> Co-authored-by: Rodney <rodney.baker@gmail.com> Co-authored-by: DoctorRyan <65507211+DoctorRyan@users.noreply.github.com>
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