Group styles into sets (directory based)

This commit is contained in:
manongjohn 2021-09-11 17:35:45 -04:00
parent ce5a89a7b1
commit fcb60bb72e
17 changed files with 424 additions and 231 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View file

@ -927,13 +927,28 @@ TPixel32 TTextureStyle::getMainColor() const
//*************************************************************************************
TRasterImagePatternStrokeStyle::TRasterImagePatternStrokeStyle()
: m_level(), m_name(""), m_space(0), m_rotation(0) {}
: m_level(), m_name(""), m_space(0), m_rotation(0) {
m_basePath = getRootDir();
}
//-----------------------------------------------------------------------------
TRasterImagePatternStrokeStyle::TRasterImagePatternStrokeStyle(
const std::string &patternName)
: m_level(), m_name(patternName), m_space(20), m_rotation(0) {
m_basePath = getRootDir();
if (m_name != "") loadLevel(m_name);
}
//-----------------------------------------------------------------------------
TRasterImagePatternStrokeStyle::TRasterImagePatternStrokeStyle(
TFilePath basePath, const std::string &patternName)
: m_level()
, m_name(patternName)
, m_space(20)
, m_rotation(0)
, m_basePath(basePath) {
if (m_name != "") loadLevel(m_name);
}
@ -1070,11 +1085,11 @@ void TRasterImagePatternStrokeStyle::loadLevel(const std::string &patternName) {
m_name = patternName;
// getRootDir() e' nulla se non si e' chiamata la setRoot(..)
assert(!getRootDir().isEmpty());
assert(!m_basePath.isEmpty());
// leggo tutti i livelli contenuti
TFilePathSet fps;
TSystem::readDirectory(fps, getRootDir());
TSystem::readDirectory(fps, m_basePath);
// prendo il primo livello il cui nome sia patternName
// (puo' essere un pli, ma anche un png, ecc.)
@ -1324,13 +1339,28 @@ void TRasterImagePatternStrokeStyle::getObsoleteTagIds(
//*************************************************************************************
TVectorImagePatternStrokeStyle::TVectorImagePatternStrokeStyle()
: m_level(), m_name(""), m_space(0), m_rotation(0) {}
: m_level(), m_name(""), m_space(0), m_rotation(0) {
m_basePath = getRootDir();
}
//-----------------------------------------------------------------------------
TVectorImagePatternStrokeStyle::TVectorImagePatternStrokeStyle(
const std::string &patternName)
: m_level(), m_name(patternName), m_space(20), m_rotation(0) {
m_basePath = getRootDir();
loadLevel(patternName);
}
//-----------------------------------------------------------------------------
TVectorImagePatternStrokeStyle::TVectorImagePatternStrokeStyle(
TFilePath basePath, const std::string &patternName)
: m_level()
, m_name(patternName)
, m_space(20)
, m_rotation(0)
, m_basePath(basePath) {
loadLevel(patternName);
}
@ -1459,9 +1489,9 @@ void TVectorImagePatternStrokeStyle::setParamValue(int index, double value) {
void TVectorImagePatternStrokeStyle::loadLevel(const std::string &patternName) {
m_level = TLevelP();
m_name = patternName;
assert(!getRootDir()
.isEmpty()); // se e' vuota, non si e' chiamata la setRoot(..)
TFilePath fp = getRootDir() + (patternName + ".pli");
assert(
!m_basePath.isEmpty()); // se e' vuota, non si e' chiamata la setRoot(..)
TFilePath fp = m_basePath + (patternName + ".pli");
TLevelReaderP lr(fp);
m_level = lr->loadInfo();
TLevel::Iterator frameIt;

View file

@ -169,13 +169,25 @@ const TColorStyle *VectorBrushProp::getColorStyle() const { return m_style; }
// Vector Brush Style implementation
//**********************************************************************
TVectorBrushStyle::TVectorBrushStyle() : m_colorCount(0) {}
TVectorBrushStyle::TVectorBrushStyle() : m_colorCount(0) {
m_basePath = getRootDir();
}
//-----------------------------------------------------------------
TVectorBrushStyle::TVectorBrushStyle(const std::string &brushName,
TVectorImageP vi)
: m_brush(vi) {
m_basePath = getRootDir();
loadBrush(brushName);
}
//-----------------------------------------------------------------
TVectorBrushStyle::TVectorBrushStyle(TFilePath basePath,
const std::string &brushName,
TVectorImageP vi)
: m_brush(vi), m_basePath(basePath) {
loadBrush(brushName);
}
@ -193,7 +205,7 @@ void TVectorBrushStyle::loadBrush(const std::string &brushName) {
if (!m_brush) {
// Load the image associated with fp
TFilePath fp(m_rootDir + TFilePath(brushName + ".pli"));
TFilePath fp(m_basePath + TFilePath(brushName + ".pli"));
TLevelReaderP lr(fp);
TLevelP level = lr->loadInfo();

View file

@ -48,7 +48,6 @@ public:
private:
QList<PatternData> m_patterns;
TFilePath m_rootPath;
TFilePath m_stylesFolder;
QString m_filters;
QSize m_chipSize;
@ -66,9 +65,6 @@ public:
int getPatternCount();
PatternData getPattern(int index);
static TFilePath getRootPath();
static void setRootPath(const TFilePath &rootPath);
void loadItems();
private:

View file

@ -532,7 +532,6 @@ protected:
QPoint m_chipOrigin;
QSize m_chipSize;
int m_chipPerRow;
static TFilePath m_rootPath;
public:
StyleChooserPage(QWidget *parent = 0);
@ -547,8 +546,6 @@ public:
//! \see StyleEditor::setRootPath()
// TOGLIERE
static void setRootPath(const TFilePath &rootPath);
static TFilePath getRootPath() { return m_rootPath; }
protected:
int m_currentIndex;
@ -659,13 +656,11 @@ class DVAPI StyleEditor final : public QWidget, public SaveLoadQSettings {
//! and style.
PlainColorPage *m_plainColorPage;
StyleChooserPage *m_textureStylePage;
StyleEditorPage *m_specialStylePage;
StyleChooserPage *m_customStylePage;
StyleChooserPage *m_vectorBrushesStylePage;
StyleChooserPage *m_mypaintBrushesStylePage;
SettingsPage *m_settingsPage;
QScrollArea *m_textureArea;
QScrollArea *m_vectorArea;
QScrollArea *m_rasterArea;
QAction *m_wheelAction;
QAction *m_hsvAction;
QAction *m_alphaAction;
@ -682,6 +677,25 @@ class DVAPI StyleEditor final : public QWidget, public SaveLoadQSettings {
bool m_enabledFirstAndLastTab;
bool m_colorPageIsVertical = true;
std::vector<QPushButton *> m_textureButtons;
std::vector<QPushButton *> m_vectorButtons;
std::vector<QPushButton *> m_rasterButtons;
std::vector<QLabel *> m_textureLabels;
std::vector<QLabel *> m_vectorLabels;
std::vector<QLabel *> m_rasterLabels;
enum StylePageType {
Texture,
VectorGenerated,
VectorCustom,
VectorBrush,
Raster
};
std::vector<StyleEditorPage *> m_texturePages;
std::vector<StyleEditorPage *> m_vectorPages;
std::vector<StyleEditorPage *> m_rasterPages;
public:
StyleEditor(PaletteController *, QWidget *parent = 0);
~StyleEditor();
@ -696,12 +710,6 @@ public:
TPalette *getPalette() { return m_paletteHandle->getPalette(); }
int getStyleIndex() { return m_paletteHandle->getStyleIndex(); }
/*! rootPath generally is STUFFDIR/Library. Contains directories 'textures'
and
'custom styles' */
// TOGLIERE
void setRootPath(const TFilePath &rootPath);
void enableAutopaintToggle(bool enabled) {
m_settingsPage->enableAutopaintToggle(enabled);
}
@ -712,6 +720,9 @@ public:
void updateColorCalibration();
void createStylePage(StylePageType pageType, TFilePath styleFolder,
QString filters = QString("*"));
protected:
/*! Return false if style is linked and style must be set to null.*/
bool setStyle(TColorStyle *currentStyle);
@ -770,16 +781,15 @@ protected slots:
void onParamStyleChanged(bool isDragging);
void onSpecialButtonToggled(bool on);
void onCustomButtonToggled(bool on);
void onVectorBrushButtonToggled(bool on);
void onHexChanged();
void onHexEdited(const QString &text);
void onHideMenu();
private:
QFrame *createBottomWidget();
QFrame *createTexturePage();
QFrame *createVectorPage();
QFrame *createRasterPage();
void updateTabBar();
void copyEditedStyleToPalette(bool isDragging);

View file

@ -232,10 +232,13 @@ protected:
TLevelP m_level;
std::string m_name;
double m_space, m_rotation;
TFilePath m_basePath;
public:
TRasterImagePatternStrokeStyle();
TRasterImagePatternStrokeStyle(const std::string &patternName);
TRasterImagePatternStrokeStyle(TFilePath basePath,
const std::string &patternName);
bool isRegionStyle() const override { return false; }
bool isStrokeStyle() const override { return true; }
@ -308,10 +311,13 @@ protected:
TLevelP m_level;
std::string m_name;
double m_space, m_rotation;
TFilePath m_basePath;
public:
TVectorImagePatternStrokeStyle();
TVectorImagePatternStrokeStyle(const std::string &patternName);
TVectorImagePatternStrokeStyle(TFilePath basePath,
const std::string &patternName);
bool isRegionStyle() const override { return false; }
bool isStrokeStyle() const override { return true; }

View file

@ -28,11 +28,14 @@ class DVAPI TVectorBrushStyle final : public TColorStyle {
std::string m_brushName;
TVectorImageP m_brush;
int m_colorCount;
TFilePath m_basePath;
public:
TVectorBrushStyle();
TVectorBrushStyle(const std::string &brushName,
TVectorImageP vi = TVectorImageP());
TVectorBrushStyle(TFilePath basePath, const std::string &brushName,
TVectorImageP vi = TVectorImageP());
~TVectorBrushStyle();
TColorStyle *clone() const override;

View file

@ -200,8 +200,6 @@ static void initToonzEnv(QHash<QString, QString> &argPathValues) {
TVectorImagePatternStrokeStyle::setRootDir(library);
TVectorBrushStyle::setRootDir(library);
CustomStyleManager::setRootPath(library);
// sembra indispensabile nella lettura dei .tab 2.2:
TPalette::setRootDir(library);
TImageStyle::setLibraryDir(library);

View file

@ -27,10 +27,6 @@
namespace {
TFilePath rootPath;
//-----------------------------------------------------------------------------
void convertRaster32ToImage(TRaster32P ras, QImage *image) {
int lx = ras->getLx();
int ly = ras->getLy();
@ -236,25 +232,12 @@ CustomStyleManager::PatternData CustomStyleManager::getPattern(int index) {
//-----------------------------------------------------------------------------
TFilePath CustomStyleManager::getRootPath() { return ::rootPath; }
//-----------------------------------------------------------------------------
void CustomStyleManager::setRootPath(const TFilePath &rootPath) {
::rootPath = rootPath;
}
//-----------------------------------------------------------------------------
void CustomStyleManager::loadItems() {
// Build the folder to be read
const TFilePath &rootFP(getRootPath());
assert(rootFP != TFilePath());
if (rootFP == TFilePath()) return;
if (m_stylesFolder == TFilePath()) return;
QDir patternDir(
QString::fromStdWString((rootFP + m_stylesFolder).getWideString()));
QDir patternDir(QString::fromStdWString(m_stylesFolder.getWideString()));
patternDir.setNameFilters(m_filters.split(' '));
// Read the said folder

View file

@ -1905,10 +1905,6 @@ void PlainColorPage::onWheelSliderReleased()
// StyleChooserPage implementation
//*****************************************************************************
TFilePath StyleChooserPage::m_rootPath;
//-----------------------------------------------------------------------------
StyleChooserPage::StyleChooserPage(QWidget *parent)
: StyleEditorPage(parent)
, m_chipOrigin(5, 3)
@ -2005,30 +2001,32 @@ void StyleChooserPage::mousePressEvent(QMouseEvent *event) {
void StyleChooserPage::mouseReleaseEvent(QMouseEvent *event) {}
//-----------------------------------------------------------------------------
// TOGLIERE
void StyleChooserPage::setRootPath(const TFilePath &rootPath) {
m_rootPath = rootPath;
}
//*****************************************************************************
// CustomStyleChooser definition
//*****************************************************************************
class CustomStyleChooserPage final : public StyleChooserPage {
public:
CustomStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {}
TFilePath m_stylesFolder;
QString m_filters;
CustomStyleManager *m_styleManager;
static CustomStyleManager *styleManager();
public:
CustomStyleChooserPage(TFilePath stylesFolder = TFilePath(),
QString filters = QString(), QWidget *parent = 0)
: StyleChooserPage(parent) {
m_stylesFolder = stylesFolder;
m_filters = filters;
m_styleManager = new CustomStyleManager(m_stylesFolder, m_filters);
}
bool event(QEvent *e) override;
void showEvent(QShowEvent *) override {
connect(styleManager(), SIGNAL(patternAdded()), this, SLOT(computeSize()));
styleManager()->loadItems();
connect(m_styleManager, SIGNAL(patternAdded()), this, SLOT(computeSize()));
m_styleManager->loadItems();
}
void hideEvent(QHideEvent *) override {
disconnect(styleManager(), SIGNAL(patternAdded()), this,
disconnect(m_styleManager, SIGNAL(patternAdded()), this,
SLOT(computeSize()));
}
bool loadIfNeeded() override { return false; } // serve?
@ -2039,7 +2037,7 @@ else return false;
*/
int getChipCount() const override {
return styleManager()->getPatternCount() + 1;
return m_styleManager->getPatternCount() + 1;
}
void drawChip(QPainter &p, QRect rect, int index) override {
@ -2050,7 +2048,7 @@ else return false;
index -= 1;
assert(0 <= index && index <= getChipCount());
CustomStyleManager::PatternData pattern =
styleManager()->getPattern(index);
m_styleManager->getPattern(index);
if (pattern.m_image && !pattern.m_image->isNull())
p.drawImage(rect, *pattern.m_image);
}
@ -2060,24 +2058,15 @@ else return false;
//-----------------------------------------------------------------------------
CustomStyleManager *CustomStyleChooserPage::styleManager() {
static const QString filters("*.pli *.tif *.png *.tga *.tiff *.sgi *.rgb");
static CustomStyleManager theManager(TFilePath("custom styles"), filters);
return &theManager;
}
//-----------------------------------------------------------------------------
bool CustomStyleChooserPage::event(QEvent *e) {
// Intercept tooltip events
if (e->type() != QEvent::ToolTip) return StyleChooserPage::event(e);
// see StyleChooserPage::paintEvent
CustomStyleManager *manager = styleManager();
QHelpEvent *he = static_cast<QHelpEvent *>(e);
int chipIdx = posToIndex(he->pos());
int chipCount = manager->getPatternCount();
int chipCount = m_styleManager->getPatternCount();
if (chipIdx == 0) {
QToolTip::showText(he->globalPos(),
QObject::tr("Plain color", "CustomStyleChooserPage"));
@ -2085,7 +2074,8 @@ bool CustomStyleChooserPage::event(QEvent *e) {
chipIdx--;
if (chipIdx < 0 || chipIdx >= chipCount) return false;
CustomStyleManager::PatternData pattern = manager->getPattern(chipIdx);
CustomStyleManager::PatternData pattern =
m_styleManager->getPattern(chipIdx);
QToolTip::showText(he->globalPos(),
QString::fromStdString(pattern.m_patternName));
}
@ -2102,16 +2092,16 @@ void CustomStyleChooserPage::onSelect(int index) {
emit styleSelected(cs);
} else {
index--;
CustomStyleManager::PatternData pattern = styleManager()->getPattern(index);
CustomStyleManager::PatternData pattern = m_styleManager->getPattern(index);
if (m_currentIndex < 0) return;
std::string name = pattern.m_patternName;
if (pattern.m_isVector) {
TVectorImagePatternStrokeStyle cs(name);
TVectorImagePatternStrokeStyle cs(m_stylesFolder, name);
emit styleSelected(cs);
} else {
TRasterImagePatternStrokeStyle cs(name);
TRasterImagePatternStrokeStyle cs(m_stylesFolder, name);
emit styleSelected(cs);
}
}
@ -2122,27 +2112,34 @@ void CustomStyleChooserPage::onSelect(int index) {
//*****************************************************************************
class VectorBrushStyleChooserPage final : public StyleChooserPage {
public:
VectorBrushStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {
m_chipSize = QSize(60, 25);
}
TFilePath m_stylesFolder;
QString m_filters;
CustomStyleManager *m_styleManager;
static CustomStyleManager *styleManager();
public:
VectorBrushStyleChooserPage(TFilePath stylesFolder = TFilePath(),
QString filters = QString(), QWidget *parent = 0)
: StyleChooserPage(parent) {
m_stylesFolder = stylesFolder;
m_filters = filters;
m_chipSize = QSize(60, 25);
m_styleManager = new CustomStyleManager(m_stylesFolder, m_filters);
}
bool event(QEvent *e) override;
void showEvent(QShowEvent *) override {
connect(styleManager(), SIGNAL(patternAdded()), this, SLOT(computeSize()));
styleManager()->loadItems();
connect(m_styleManager, SIGNAL(patternAdded()), this, SLOT(computeSize()));
m_styleManager->loadItems();
}
void hideEvent(QHideEvent *) override {
disconnect(styleManager(), SIGNAL(patternAdded()), this,
disconnect(m_styleManager, SIGNAL(patternAdded()), this,
SLOT(computeSize()));
}
bool loadIfNeeded() override { return false; }
int getChipCount() const override {
return styleManager()->getPatternCount() + 1;
return m_styleManager->getPatternCount() + 1;
}
void drawChip(QPainter &p, QRect rect, int index) override;
@ -2151,27 +2148,19 @@ public:
//-----------------------------------------------------------------------------
CustomStyleManager *VectorBrushStyleChooserPage::styleManager() {
static CustomStyleManager theManager(TFilePath("vector brushes"), "*.pli",
QSize(60, 25));
return &theManager;
}
//-----------------------------------------------------------------------------
bool VectorBrushStyleChooserPage::event(QEvent *e) {
// Intercept tooltip events
if (e->type() != QEvent::ToolTip) return StyleChooserPage::event(e);
// see StyleChooserPage::paintEvent
CustomStyleManager *manager = styleManager();
QHelpEvent *he = static_cast<QHelpEvent *>(e);
int chipIdx = posToIndex(he->pos()), chipCount = getChipCount();
if (chipIdx < 0 || chipIdx >= chipCount) return false;
if (chipIdx > 0) {
CustomStyleManager::PatternData pattern = manager->getPattern(chipIdx - 1);
CustomStyleManager::PatternData pattern =
m_styleManager->getPattern(chipIdx - 1);
QToolTip::showText(he->globalPos(),
QString::fromStdString(pattern.m_patternName));
} else
@ -2191,7 +2180,7 @@ void VectorBrushStyleChooserPage::drawChip(QPainter &p, QRect rect, int index) {
} else {
assert(0 <= index && index < getChipCount());
CustomStyleManager::PatternData pattern =
styleManager()->getPattern(index - 1);
m_styleManager->getPattern(index - 1);
p.drawImage(rect, *pattern.m_image);
}
}
@ -2204,7 +2193,7 @@ void VectorBrushStyleChooserPage::onSelect(int index) {
if (index > 0) {
--index;
CustomStyleManager::PatternData pattern = styleManager()->getPattern(index);
CustomStyleManager::PatternData pattern = m_styleManager->getPattern(index);
if (m_currentIndex < 0) return;
@ -2212,7 +2201,7 @@ void VectorBrushStyleChooserPage::onSelect(int index) {
assert(pattern.m_isVector);
if (!pattern.m_isVector) return;
TVectorBrushStyle cs(name);
TVectorBrushStyle cs(m_stylesFolder, name);
emit styleSelected(cs);
} else {
TSolidColorStyle cs(TPixel32::Black);
@ -2232,11 +2221,18 @@ struct Texture {
//-----------------------------------------------------------------------------
class TextureStyleChooserPage final : public StyleChooserPage {
static std::vector<Texture> m_textures;
static bool m_loaded;
std::vector<Texture> m_textures;
bool m_loaded = false;
TFilePath m_stylesFolder;
QString m_filters;
public:
TextureStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {}
TextureStyleChooserPage(TFilePath stylesFolder = TFilePath(),
QString filters = QString(), QWidget *parent = 0)
: StyleChooserPage(parent) {
m_stylesFolder = stylesFolder;
m_filters = filters;
}
bool loadIfNeeded() override {
if (!m_loaded) {
@ -2249,8 +2245,8 @@ public:
int getChipCount() const override { return m_textures.size() + 1; }
static void loadTexture(const TFilePath &fp);
static void loadItems();
void loadTexture(const TFilePath &fp);
void loadItems();
void drawChip(QPainter &p, QRect rect, int index) override {
if (index == 0) {
@ -2270,11 +2266,6 @@ public:
//-----------------------------------------------------------------------------
std::vector<Texture> TextureStyleChooserPage::m_textures;
bool TextureStyleChooserPage::m_loaded(false);
//-----------------------------------------------------------------------------
void TextureStyleChooserPage::loadTexture(const TFilePath &fp) {
if (fp == TFilePath()) {
TRaster32P ras(25, 25);
@ -2316,11 +2307,10 @@ void TextureStyleChooserPage::loadTexture(const TFilePath &fp) {
void TextureStyleChooserPage::loadItems() {
m_textures.clear();
if (getRootPath() == TFilePath()) return;
TFilePath texturePath = getRootPath() + "textures";
if (m_stylesFolder == TFilePath()) return;
TFilePathSet fps;
try {
fps = TSystem::readDirectory(texturePath);
fps = TSystem::readDirectory(m_stylesFolder);
} catch (...) {
return;
}
@ -2344,8 +2334,9 @@ void TextureStyleChooserPage::onSelect(int index) {
--index;
assert(0 <= index && index < (int)m_textures.size());
TTextureStyle style(m_textures[index].m_raster,
TFilePath(m_textures[index].m_name.toStdWString()));
TTextureStyle style(
m_textures[index].m_raster,
m_stylesFolder + TFilePath(m_textures[index].m_name.toStdWString()));
emit styleSelected(style);
} else {
TSolidColorStyle cs(TPixel32::Black);
@ -2385,22 +2376,27 @@ bool TextureStyleChooserPage::event(QEvent *e) {
//*****************************************************************************
class MyPaintBrushStyleChooserPage final : public StyleChooserPage {
std::vector<TMyPaintBrushStyle> m_brushes;
bool m_loaded = false;
TFilePath m_stylesFolder;
QString m_filters;
public:
struct Brush {
TRasterP m_raster;
QString m_name;
};
private:
static std::vector<TMyPaintBrushStyle> m_brushes;
public:
MyPaintBrushStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {
m_chipSize = QSize(64, 64);
MyPaintBrushStyleChooserPage(TFilePath stylesFolder = TFilePath(),
QString filters = QString(), QWidget *parent = 0)
: StyleChooserPage(parent) {
m_stylesFolder = stylesFolder;
m_filters = filters;
m_chipSize = QSize(64, 64);
}
bool loadIfNeeded() override {
static bool m_loaded = false;
if (!m_loaded) {
loadItems();
m_loaded = true;
@ -2411,7 +2407,7 @@ public:
int getChipCount() const override { return m_brushes.size() + 1; }
static void loadItems();
void loadItems();
void drawChip(QPainter &p, QRect rect, int index) override {
assert(0 <= index && index <= (int)m_brushes.size());
@ -2441,7 +2437,8 @@ public:
if (index == 0) {
toolTip = QObject::tr("Plain color", "MyPaintBrushStyleChooserPage");
} else if (index > 0 && index <= (int)m_brushes.size()) {
toolTip = m_brushes[index - 1].getPath().getQString();
toolTip =
m_brushes[index - 1].getPath().withoutParentDir().getQString();
}
QToolTip::showText(helpEvent->globalPos(), toolTip);
e->accept();
@ -2452,24 +2449,22 @@ public:
//-----------------------------------------------------------------------------
std::vector<TMyPaintBrushStyle> MyPaintBrushStyleChooserPage::m_brushes;
//-----------------------------------------------------------------------------
void MyPaintBrushStyleChooserPage::loadItems() {
m_brushes.clear();
std::set<TFilePath> brushFiles;
TFilePathSet dirs = TMyPaintBrushStyle::getBrushesDirs();
for (TFilePathSet::iterator i = dirs.begin(); i != dirs.end(); ++i) {
TFileStatus fs(*i);
if (fs.doesExist() && fs.isDirectory()) {
TFilePathSet files = TSystem::readDirectoryTree(*i, false, true);
for (TFilePathSet::iterator j = files.begin(); j != files.end(); ++j)
if (j->getType() == TMyPaintBrushStyle::getBrushType())
brushFiles.insert(*j - *i);
}
if (m_stylesFolder == TFilePath()) return;
std::set<TFilePath> brushFiles;
TFilePathSet fps;
try {
fps = TSystem::readDirectory(m_stylesFolder);
} catch (...) {
return;
}
if (fps.empty()) return;
int count = 0;
for (TFilePathSet::iterator it = fps.begin(); it != fps.end(); it++)
if (it->getType() == TMyPaintBrushStyle::getBrushType())
brushFiles.insert(*it);
// reserve memory to avoid reallocation
m_brushes.reserve(brushFiles.size());
@ -2485,11 +2480,16 @@ void MyPaintBrushStyleChooserPage::loadItems() {
class SpecialStyleChooserPage final : public StyleChooserPage {
static std::vector<std::pair<int, QImage *>> m_customStyles;
static bool m_loaded;
static TFilePath m_stylesFolder;
static QString m_filters;
public:
SpecialStyleChooserPage(QWidget *parent = 0,
const TFilePath &rootDir = TFilePath())
: StyleChooserPage(parent) {}
SpecialStyleChooserPage(TFilePath stylesFolder = TFilePath(),
QString filters = QString(), QWidget *parent = 0)
: StyleChooserPage(parent) {
m_stylesFolder = stylesFolder;
m_filters = filters;
}
bool loadIfNeeded() override {
if (!m_loaded) {
@ -2510,6 +2510,11 @@ public:
//-----------------------------------------------------------------------------
TFilePath SpecialStyleChooserPage::m_stylesFolder;
QString SpecialStyleChooserPage::m_filters;
//-----------------------------------------------------------------------------
std::vector<std::pair<int, QImage *>> SpecialStyleChooserPage::m_customStyles;
bool SpecialStyleChooserPage::m_loaded(false);
@ -3096,7 +3101,6 @@ StyleEditor::StyleEditor(PaletteController *paletteController, QWidget *parent)
setFocusPolicy(Qt::NoFocus);
// TOGLIERE
TFilePath libraryPath = ToonzFolder::getLibraryFolder();
setRootPath(libraryPath);
m_styleBar = new DVGui::TabBar(this);
m_styleBar->setDrawBase(false);
@ -3110,21 +3114,35 @@ StyleEditor::StyleEditor(PaletteController *paletteController, QWidget *parent)
m_colorParameterSelector = new ColorParameterSelector(this);
m_plainColorPage = new PlainColorPage(0);
m_textureStylePage = new TextureStyleChooserPage(0);
m_specialStylePage = new SpecialStyleChooserPage(0);
m_customStylePage = new CustomStyleChooserPage(0);
m_vectorBrushesStylePage = new VectorBrushStyleChooserPage(0);
m_mypaintBrushesStylePage = new MyPaintBrushStyleChooserPage(0);
m_specialStylePage = new SpecialStyleChooserPage();
m_settingsPage = new SettingsPage(0);
QWidget *emptyPage = new StyleEditorPage(0);
// Create Style Pages
createStylePage(StylePageType::Texture, libraryPath + TFilePath("textures"));
createStylePage(StylePageType::VectorGenerated, TFilePath());
createStylePage(StylePageType::VectorCustom,
libraryPath + TFilePath("custom styles"),
QString("*.pli *.tif *.png *.tga *.tiff *.sgi *.rgb"));
createStylePage(StylePageType::VectorBrush,
libraryPath + TFilePath("vector brushes"), QString("*.pli"));
TFilePathSet dirs = TMyPaintBrushStyle::getBrushesDirs();
for (TFilePathSet::iterator i = dirs.begin(); i != dirs.end(); ++i) {
TFileStatus fs(*i);
if (fs.doesExist() && fs.isDirectory())
createStylePage(StylePageType::Raster, *i, QString("*.myb"));
}
// For the plainColorPage and the settingsPage
// I create a "fake" QScrollArea (without ScrollingBar
// in order to use the styleSheet to stylish its background
QScrollArea *plainArea = makeChooserPageWithoutScrollBar(m_plainColorPage);
QScrollArea *textureArea = makeChooserPage(m_textureStylePage);
QScrollArea *mypaintBrushesArea = makeChooserPage(m_mypaintBrushesStylePage);
QScrollArea *textureOutsideArea =
makeChooserPageWithoutScrollBar(createTexturePage());
QScrollArea *rasterOutsideArea =
makeChooserPageWithoutScrollBar(createRasterPage());
QScrollArea *settingsArea = makeChooserPageWithoutScrollBar(m_settingsPage);
QScrollArea *vectorOutsideArea =
makeChooserPageWithoutScrollBar(createVectorPage());
@ -3132,9 +3150,9 @@ StyleEditor::StyleEditor(PaletteController *paletteController, QWidget *parent)
m_styleChooser = new QStackedWidget(this);
m_styleChooser->addWidget(plainArea);
m_styleChooser->addWidget(textureArea);
m_styleChooser->addWidget(textureOutsideArea);
m_styleChooser->addWidget(vectorOutsideArea);
m_styleChooser->addWidget(mypaintBrushesArea);
m_styleChooser->addWidget(rasterOutsideArea);
m_styleChooser->addWidget(settingsArea);
m_styleChooser->addWidget(makeChooserPageWithoutScrollBar(emptyPage));
m_styleChooser->setFocusPolicy(Qt::NoFocus);
@ -3227,21 +3245,33 @@ StyleEditor::StyleEditor(PaletteController *paletteController, QWidget *parent)
SLOT(setPage(int)));
ret = ret && connect(m_colorParameterSelector, SIGNAL(colorParamChanged()),
this, SLOT(onColorParamChanged()));
ret = ret &&
connect(m_textureStylePage, SIGNAL(styleSelected(const TColorStyle &)),
this, SLOT(selectStyle(const TColorStyle &)));
ret = ret &&
connect(m_specialStylePage, SIGNAL(styleSelected(const TColorStyle &)),
this, SLOT(selectStyle(const TColorStyle &)));
ret = ret &&
connect(m_customStylePage, SIGNAL(styleSelected(const TColorStyle &)),
this, SLOT(selectStyle(const TColorStyle &)));
ret = ret && connect(m_vectorBrushesStylePage,
SIGNAL(styleSelected(const TColorStyle &)), this,
SLOT(selectStyle(const TColorStyle &)));
ret = ret && connect(m_mypaintBrushesStylePage,
SIGNAL(styleSelected(const TColorStyle &)), this,
SLOT(selectStyle(const TColorStyle &)));
std::vector<StyleEditorPage *>::iterator itP = m_texturePages.begin();
std::vector<QPushButton *>::iterator itB = m_textureButtons.begin();
for (; itP != m_texturePages.end(); itP++, itB++) {
ret = ret && connect(*itP, SIGNAL(styleSelected(const TColorStyle &)), this,
SLOT(selectStyle(const TColorStyle &)));
ret = ret &&
connect(*itB, SIGNAL(toggled(bool)), *itP, SLOT(setVisible(bool)));
}
itP = m_vectorPages.begin();
itB = m_vectorButtons.begin();
for (; itP != m_vectorPages.end(); itP++, itB++) {
ret = ret && connect(*itP, SIGNAL(styleSelected(const TColorStyle &)), this,
SLOT(selectStyle(const TColorStyle &)));
ret = ret &&
connect(*itB, SIGNAL(toggled(bool)), *itP, SLOT(setVisible(bool)));
}
itP = m_rasterPages.begin();
itB = m_rasterButtons.begin();
for (; itP != m_rasterPages.end(); itP++, itB++) {
ret = ret && connect(*itP, SIGNAL(styleSelected(const TColorStyle &)), this,
SLOT(selectStyle(const TColorStyle &)));
ret = ret &&
connect(*itB, SIGNAL(toggled(bool)), *itP, SLOT(setVisible(bool)));
}
ret = ret && connect(m_settingsPage, SIGNAL(paramStyleChanged(bool)), this,
SLOT(onParamStyleChanged(bool)));
ret = ret && connect(m_plainColorPage,
@ -3365,44 +3395,83 @@ QFrame *StyleEditor::createBottomWidget() {
//-----------------------------------------------------------------------------
QFrame *StyleEditor::createTexturePage() {
QFrame *textureOutsideFrame = new QFrame(this);
textureOutsideFrame->setMinimumWidth(50);
/* ------ layout ------ */
QVBoxLayout *textureOutsideLayout = new QVBoxLayout();
textureOutsideLayout->setMargin(0);
textureOutsideLayout->setSpacing(0);
textureOutsideLayout->setSizeConstraint(QLayout::SetNoConstraint);
{
QVBoxLayout *textureLayout = new QVBoxLayout();
textureLayout->setMargin(0);
textureLayout->setSpacing(0);
textureLayout->setSizeConstraint(QLayout::SetNoConstraint);
{
std::vector<StyleEditorPage *>::iterator itP = m_texturePages.begin();
std::vector<QLabel *>::iterator itL = m_textureLabels.begin();
std::vector<QPushButton *>::iterator itB = m_textureButtons.begin();
for (; itP != m_texturePages.end(); itP++, itL++, itB++) {
QHBoxLayout *setLabelLay = new QHBoxLayout();
setLabelLay->setMargin(0);
setLabelLay->setSpacing(3);
{
setLabelLay->addWidget(*itB, 0);
setLabelLay->addWidget(*itL, 0);
setLabelLay->addStretch(1);
}
textureLayout->addLayout(setLabelLay);
textureLayout->addWidget(*itP);
}
textureLayout->addStretch();
}
QFrame *textureFrame = new QFrame(this);
textureFrame->setMinimumWidth(50);
textureFrame->setLayout(textureLayout);
m_textureArea = makeChooserPage(textureFrame);
m_textureArea->setMinimumWidth(50);
textureOutsideLayout->addWidget(m_textureArea);
}
textureOutsideFrame->setLayout(textureOutsideLayout);
return textureOutsideFrame;
}
//-----------------------------------------------------------------------------
QFrame *StyleEditor::createVectorPage() {
QFrame *vectorOutsideFrame = new QFrame(this);
vectorOutsideFrame->setMinimumWidth(50);
QPushButton *specialButton = new QPushButton(tr("Generated"), this);
QPushButton *customButton = new QPushButton(tr("Trail"), this);
QPushButton *vectorBrushButton = new QPushButton(tr("Vector Brush"), this);
specialButton->setCheckable(true);
customButton->setCheckable(true);
vectorBrushButton->setCheckable(true);
specialButton->setChecked(true);
customButton->setChecked(true);
vectorBrushButton->setChecked(true);
/* ------ layout ------ */
QVBoxLayout *vectorOutsideLayout = new QVBoxLayout();
vectorOutsideLayout->setMargin(0);
vectorOutsideLayout->setSpacing(0);
vectorOutsideLayout->setSizeConstraint(QLayout::SetNoConstraint);
{
QHBoxLayout *vectorButtonLayout = new QHBoxLayout();
vectorButtonLayout->setSizeConstraint(QLayout::SetNoConstraint);
{
vectorButtonLayout->addWidget(specialButton);
vectorButtonLayout->addWidget(customButton);
vectorButtonLayout->addWidget(vectorBrushButton);
}
vectorOutsideLayout->addLayout(vectorButtonLayout);
QVBoxLayout *vectorLayout = new QVBoxLayout();
vectorLayout->setMargin(0);
vectorLayout->setSpacing(0);
vectorLayout->setSizeConstraint(QLayout::SetNoConstraint);
{
vectorLayout->addWidget(m_specialStylePage);
vectorLayout->addWidget(m_customStylePage);
vectorLayout->addWidget(m_vectorBrushesStylePage);
std::vector<StyleEditorPage *>::iterator itP = m_vectorPages.begin();
std::vector<QLabel *>::iterator itL = m_vectorLabels.begin();
std::vector<QPushButton *>::iterator itB = m_vectorButtons.begin();
for (; itP != m_vectorPages.end(); itP++, itL++, itB++) {
QHBoxLayout *setLabelLay = new QHBoxLayout();
setLabelLay->setMargin(0);
setLabelLay->setSpacing(3);
{
setLabelLay->addWidget(*itB, 0);
setLabelLay->addWidget(*itL, 0);
setLabelLay->addStretch(1);
}
vectorLayout->addLayout(setLabelLay);
vectorLayout->addWidget(*itP);
}
vectorLayout->addStretch();
}
QFrame *vectorFrame = new QFrame(this);
vectorFrame->setMinimumWidth(50);
@ -3413,20 +3482,57 @@ QFrame *StyleEditor::createVectorPage() {
}
vectorOutsideFrame->setLayout(vectorOutsideLayout);
/* ------ signal-slot connections ------ */
bool ret = true;
ret = ret && connect(specialButton, SIGNAL(toggled(bool)), this,
SLOT(onSpecialButtonToggled(bool)));
ret = ret && connect(customButton, SIGNAL(toggled(bool)), this,
SLOT(onCustomButtonToggled(bool)));
ret = ret && connect(vectorBrushButton, SIGNAL(toggled(bool)), this,
SLOT(onVectorBrushButtonToggled(bool)));
assert(ret);
return vectorOutsideFrame;
}
//-----------------------------------------------------------------------------
QFrame *StyleEditor::createRasterPage() {
QFrame *rasterOutsideFrame = new QFrame(this);
rasterOutsideFrame->setMinimumWidth(50);
/* ------ layout ------ */
QVBoxLayout *rasterOutsideLayout = new QVBoxLayout();
rasterOutsideLayout->setMargin(0);
rasterOutsideLayout->setSpacing(0);
rasterOutsideLayout->setSizeConstraint(QLayout::SetNoConstraint);
{
QVBoxLayout *rasterLayout = new QVBoxLayout();
rasterLayout->setMargin(0);
rasterLayout->setSpacing(0);
rasterLayout->setSizeConstraint(QLayout::SetNoConstraint);
{
std::vector<StyleEditorPage *>::iterator itP = m_rasterPages.begin();
std::vector<QLabel *>::iterator itL = m_rasterLabels.begin();
std::vector<QPushButton *>::iterator itB = m_rasterButtons.begin();
for (; itP != m_rasterPages.end(); itP++, itL++, itB++) {
QHBoxLayout *setLabelLay = new QHBoxLayout();
setLabelLay->setMargin(0);
setLabelLay->setSpacing(3);
{
setLabelLay->addWidget(*itB, 0);
setLabelLay->addWidget(*itL, 0);
setLabelLay->addStretch(1);
}
rasterLayout->addLayout(setLabelLay);
rasterLayout->addWidget(*itP);
}
rasterLayout->addStretch();
}
QFrame *rasterFrame = new QFrame(this);
rasterFrame->setMinimumWidth(50);
rasterFrame->setLayout(rasterLayout);
m_rasterArea = makeChooserPage(rasterFrame);
m_rasterArea->setMinimumWidth(50);
rasterOutsideLayout->addWidget(m_rasterArea);
}
rasterOutsideFrame->setLayout(rasterOutsideLayout);
return rasterOutsideFrame;
}
//-----------------------------------------------------------------------------
void StyleEditor::updateTabBar() {
m_styleBar->clearTabBar();
if (m_enabled && !m_enabledOnlyFirstTab && !m_enabledFirstAndLastTab) {
@ -3605,12 +3711,6 @@ void StyleEditor::onCleanupStyleChanged(bool isDragging) {
onStyleChanged(isDragging);
}
//-----------------------------------------------------------------------------
// TOGLIERE
void StyleEditor::setRootPath(const TFilePath &rootPath) {
m_textureStylePage->setRootPath(rootPath);
}
//-----------------------------------------------------------------------------
void StyleEditor::copyEditedStyleToPalette(bool isDragging) {
@ -4061,30 +4161,6 @@ void StyleEditor::onHexChanged() {
//-----------------------------------------------------------------------------
void StyleEditor::onSpecialButtonToggled(bool on) {
m_specialStylePage->setVisible(on);
m_vectorArea->widget()->resize(m_vectorArea->widget()->sizeHint());
qApp->processEvents();
}
//-----------------------------------------------------------------------------
void StyleEditor::onCustomButtonToggled(bool on) {
m_customStylePage->setVisible(on);
m_vectorArea->widget()->resize(m_vectorArea->widget()->sizeHint());
qApp->processEvents();
}
//-----------------------------------------------------------------------------
void StyleEditor::onVectorBrushButtonToggled(bool on) {
m_vectorBrushesStylePage->setVisible(on);
m_vectorArea->widget()->resize(m_vectorArea->widget()->sizeHint());
qApp->processEvents();
}
//-----------------------------------------------------------------------------
void StyleEditor::save(QSettings &settings) const {
settings.setValue("isVertical", m_plainColorPage->getIsVertical());
int visibleParts = 0;
@ -4132,3 +4208,82 @@ void StyleEditor::load(QSettings &settings) {
void StyleEditor::updateColorCalibration() {
m_plainColorPage->updateColorCalibration();
}
void StyleEditor::createStylePage(StylePageType pageType, TFilePath styleFolder,
QString filters) {
if (styleFolder != TFilePath()) {
// Load subfolders first
try {
QStringList fpList;
TSystem::readDirectory_DirItems(fpList, styleFolder);
QStringList::iterator fpListIt;
for (fpListIt = fpList.begin(); fpListIt != fpList.end(); fpListIt++)
createStylePage(pageType, styleFolder + TFilePath(*fpListIt), filters);
} catch (...) {
// Do nothing
}
// Let's look for files
TFilePathSet fps;
try {
QDir patternDir(QString::fromStdWString(styleFolder.getWideString()));
patternDir.setNameFilters(filters.split(' '));
TSystem::readDirectory(fps, patternDir);
} catch (...) {
return;
}
if (fps.empty()) return;
}
QString label = styleFolder.withoutParentDir().getQString();
label[0] = label[0].toUpper();
if (pageType == StylePageType::Raster &&
!styleFolder.getQString().contains("mypaint brushes"))
label += tr(" (External)");
QPushButton *button = new QPushButton("", this);
button->setObjectName("menuToggleButton");
button->setFixedSize(15, 15);
button->setIcon(createQIcon("menu_toggle"));
button->setCheckable(true);
button->setChecked(true);
button->setFocusPolicy(Qt::NoFocus);
switch (pageType) {
case StylePageType::Texture: {
m_texturePages.push_back(new TextureStyleChooserPage(styleFolder, filters));
m_textureLabels.push_back(new QLabel(label, this));
m_textureButtons.push_back(button);
break;
}
case StylePageType::VectorGenerated: {
m_vectorPages.push_back(m_specialStylePage);
m_vectorLabels.push_back(new QLabel("Generated"));
m_vectorButtons.push_back(button);
break;
}
case StylePageType::VectorCustom: {
m_vectorPages.push_back(new CustomStyleChooserPage(styleFolder, filters));
m_vectorLabels.push_back(new QLabel(label, this));
m_vectorButtons.push_back(button);
break;
}
case StylePageType::VectorBrush: {
m_vectorPages.push_back(
new VectorBrushStyleChooserPage(styleFolder, filters));
m_vectorLabels.push_back(new QLabel(label, this));
m_vectorButtons.push_back(button);
break;
}
case StylePageType::Raster: {
m_rasterLabels.push_back(new QLabel(label));
m_rasterPages.push_back(
new MyPaintBrushStyleChooserPage(styleFolder, filters));
m_rasterButtons.push_back(button);
break;
}
}
}