Create/Modify/Remove style sets + misc fix and some refactoring

This commit is contained in:
manongjohn 2021-09-22 08:09:51 -04:00
parent 276a177ee6
commit 185efe7b70
11 changed files with 1579 additions and 498 deletions

View file

@ -218,6 +218,14 @@ public:
QString filters = QString("*"),
QSize chipSize = QSize(30, 30));
TFilePathSet getCustomStyleFolders();
TFilePathSet getTextureStyleFolders();
TFilePathSet getBrushStyleFolders();
void removeCustomStyleFolder(TFilePath styleFolder);
void removeTextureStyleFolder(TFilePath styleFolder);
void removeBrushStyleFolder(TFilePath styleFolder);
bool isLoading();
void signalLoadsFinished();
};

View file

@ -53,6 +53,7 @@ public:
virtual void setCurrentLevelStyleIndex(int index,
bool forceUpdate = false) = 0;
virtual void refreshStatusBar() = 0;
virtual void showMessage(QString message, int duration = 2000) = 0;
};
#endif // TAPPLICATION_H

View file

@ -217,4 +217,9 @@ protected:
QString DVAPI operator+(const QString &a, const TFilePath &fp);
//-----------------------------------------------------------------------------
// This is used to translate Windows keys to macOS keys
//
QString DVAPI trModKey(QString key);
#endif // GUTIL_H

View file

@ -9,6 +9,7 @@
#include "tpixel.h"
#include "tpalette.h"
#include "saveloadqsettings.h"
#include "../toonz/tapplication.h"
// TnzLib includes
#include "toonz/tpalettehandle.h"
@ -22,6 +23,7 @@
#include "toonzqt/colorfield.h"
#include "toonzqt/tabbar.h"
#include "toonzqt/glwidget_for_highdpi.h"
#include "toonzqt/dvdialog.h"
// Qt includes
#include <QWidget>
@ -34,6 +36,8 @@
#include <QPointF>
#include <QSettings>
#include <QSplitter>
#include <QRadioButton>
#include <QLabel>
#undef DVAPI
#undef DVVAR
@ -420,22 +424,11 @@ signals:
*/
class StyleEditorPage : public QFrame {
public:
bool m_favorite = false;
bool m_allowFavorite = false;
StyleEditor *m_editor;
std::vector<int> m_selection;
StyleEditorPage(QWidget *parent);
virtual void setFavorite(bool favorite) { m_favorite = favorite; }
bool isFavorite() { return m_favorite; }
void setAllowFavorite(bool allow) { m_allowFavorite = allow; }
bool allowFavorite() { return m_allowFavorite; }
void clearSelection() { m_selection.clear(); }
std::vector<int> getSelection() { return m_selection; }
};
//=============================================================================
@ -557,35 +550,63 @@ protected:
QSize m_chipSize;
int m_chipPerRow;
StylePageType m_pageType = StylePageType::Unknown;
TFilePath m_stylesFolder;
QString m_styleSetName;
bool m_allowPageDelete;
bool m_favorite = false;
bool m_allowFavorite = false;
bool m_external = false;
public:
StyleChooserPage(QWidget *parent = 0);
QSize getChipSize() const { return m_chipSize; }
TFilePath getStylesFolder() { return m_stylesFolder; }
void setPageType(StylePageType pageType) { m_pageType = pageType; }
StylePageType getPageType() { return m_pageType; }
virtual bool loadIfNeeded() = 0;
virtual void setFavorite(bool favorite) { m_favorite = favorite; }
bool isFavorite() { return m_favorite; }
void setAllowFavorite(bool allow) { m_allowFavorite = allow; }
bool allowFavorite() { return m_allowFavorite; }
virtual void setExternal(bool external) { m_external = external; }
bool isExternal() { return m_external; }
void clearSelection() { m_selection.clear(); }
std::vector<int> getSelection() { return m_selection; }
virtual void loadItems() {}
virtual bool loadIfNeeded() = 0;
virtual bool isLoading() { return false; }
virtual int getChipCount() const = 0;
virtual void drawChip(QPainter &p, QRect rect, int index) = 0;
virtual void onSelect(int index) {}
virtual void removeFavorite(){};
virtual void removeSelectedFavorites(std::vector<int> selection){};
virtual void addFavorite() {}
virtual void addSelectedFavorites(std::vector<int> selection){};
virtual void removeSelectedStylesFromSet(std::vector<int> selection){};
virtual void addSelectedStylesToSet(std::vector<int> selection,
TFilePath setPath){};
virtual void updateFavorite(){};
virtual void addSelectedStyles(std::vector<int> selection){};
virtual void addSelectedStylesToPalette(std::vector<int> selection){};
bool copyToFavorites(TFilePathSet srcFiles, TFilePath destDir);
bool deleteFromFavorites(TFilePathSet targetFiles);
bool copyFilesToStyleFolder(TFilePathSet srcFiles, TFilePath destDir);
bool deleteFilesFromStyleFolder(TFilePathSet targetFiles);
void processContextMenuEvent(QContextMenuEvent *event) {
contextMenuEvent(event);
}
void setStyleSetName(QString name) { m_styleSetName = name; }
QString getStyleSetName() { return m_styleSetName; }
void setAllowPageDelete(bool allowDelete) { m_allowPageDelete = allowDelete; }
bool canDeletePage() { return m_allowPageDelete; }
protected:
int m_currentIndex;
@ -598,19 +619,24 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override {}
void mouseReleaseEvent(QMouseEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
void enterEvent(QEvent *event) override;
protected slots:
void computeSize();
void onTogglePage(bool toggled);
void onRemoveFavorite();
void onRemoveAllFavorites();
void onAddFavorite();
void onAddStyle();
void onAddAllStyles();
void onRemoveStyleFromSet();
void onEmptySet();
void onAddStyleToFavorite();
void onAddStyleToPalette();
void onCopyStyleToSet();
void onMoveStyleToSet();
void onAddSetToPalette();
void onUpdateFavorite();
void onRemoveStyleSet();
void onReloadStyleSet();
void onLabelContextMenu(const QPoint &pos);
signals:
void styleSelected(const TColorStyle &style);
void favoritesUpdated();
void refreshFavorites();
};
@ -666,12 +692,61 @@ private slots:
using namespace StyleEditorGUI;
//=============================================================================
// Clickable Label
//-----------------------------------------------------------------------------
class ClickableLabel : public QLabel {
Q_OBJECT
public:
ClickableLabel(const QString &text, QWidget *parent = nullptr,
Qt::WindowFlags f = Qt::WindowFlags());
~ClickableLabel();
protected:
void mousePressEvent(QMouseEvent *event);
signals:
void click();
};
//=============================================================================
// New Style Set Popup
//-----------------------------------------------------------------------------
class NewStyleSetPopup : public DVGui::Dialog {
Q_OBJECT
protected:
DVGui::LineEdit *m_nameFld;
DVGui::CheckBox *m_isFavorite;
QButtonGroup *m_styleSetType;
QRadioButton *m_texture, *m_vectorCustom, *m_vectorBrush, *m_raster;
StyleEditor *m_editor;
StylePageType m_pageType;
public:
NewStyleSetPopup(StylePageType pageType, QWidget *parent);
protected:
void showEvent(QShowEvent *event) override { m_nameFld->setFocus(); }
public slots:
void createStyleSet();
private slots:
void onFavoriteToggled();
};
//=============================================================================
// StyleEditor
//-----------------------------------------------------------------------------
class DVAPI StyleEditor final : public QWidget, public SaveLoadQSettings {
Q_OBJECT
TApplication *m_app;
PaletteController *m_paletteController;
TPaletteHandle *m_paletteHandle;
@ -727,17 +802,21 @@ class DVAPI StyleEditor final : public QWidget, public SaveLoadQSettings {
bool m_enabledFirstAndLastTab;
bool m_colorPageIsVertical = true;
QScrollArea *m_textureOutsideArea;
QScrollArea *m_rasterOutsideArea;
QScrollArea *m_vectorOutsideArea;
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;
std::vector<ClickableLabel *> m_textureLabels;
std::vector<ClickableLabel *> m_vectorLabels;
std::vector<ClickableLabel *> m_rasterLabels;
std::vector<StyleEditorPage *> m_texturePages;
std::vector<StyleEditorPage *> m_vectorPages;
std::vector<StyleEditorPage *> m_rasterPages;
std::vector<StyleChooserPage *> m_texturePages;
std::vector<StyleChooserPage *> m_vectorPages;
std::vector<StyleChooserPage *> m_rasterPages;
QMenu *m_textureMenu;
QMenu *m_vectorMenu;
@ -750,6 +829,9 @@ public:
StyleEditor(PaletteController *, QWidget *parent = 0);
~StyleEditor();
void setApplication(TApplication *app) { m_app = app; }
TApplication *getApplication() { return m_app; }
void setPaletteHandle(TPaletteHandle *paletteHandle);
TPaletteHandle *getPaletteHandle() const { return m_paletteHandle; }
@ -774,7 +856,7 @@ public:
QString filters = QString("*"), bool isFavorite = false,
int dirDepth = 0);
void createStyleMenus();
void initializeStyleMenus();
bool isAltPressed() { return m_isAltPressed; }
bool isCtrlPressed() { return m_isCtrlPressed; }
@ -791,6 +873,18 @@ public:
QStringList savePageStates(StylePageType pageType) const;
void loadPageStates(StylePageType pageType, QStringList pageStateData);
void createNewStyleSet(StylePageType pageType, TFilePath pagePath,
bool isFavorite);
void removeStyleSet(QString styleSetName);
void removeStyleSetAtIndex(int index, int pageIndex);
std::vector<StyleChooserPage *> getStyleSetList(StylePageType pageType);
void setUpdated(TFilePath setPath);
TFilePath getSetStyleFolder(QString setName);
void updatePage(int pageIndex);
protected:
/*! Return false if style is linked and style must be set to null.*/
bool setStyle(TColorStyle *currentStyle);
@ -880,12 +974,16 @@ protected slots:
void onExpandAllVectorSet();
void onExpandAllRasterSet();
void onReloadFavorites();
void onUpdateFavorites();
void onRemoveSelectedFavorites();
void onAddSelectedFavorites();
void onAddSelectedStyles();
void onRemoveSelectedStylesFromFavorites();
void onAddSelectedStylesToFavorites();
void onAddSelectedStylesToPalette();
void onCopySelectedStylesToSet();
void onMoveSelectedStylesToSet();
void onRemoveSelectedStyleFromSet();
void onAddNewStyleSet();
private:
QFrame *createBottomWidget();

View file

@ -147,17 +147,6 @@ void StatusBar::updateInfoText() {
}
//-----------------------------------------------------------------------------
QString trModKey(QString key) {
#ifdef MACOSX
// Convert Windows key modifier to macOS modifier
key = key.replace("Ctrl", QString::fromStdWString(L"\u2318"));
key = key.replace("Shift", QString::fromStdWString(L"\u21e7"));
key = key.replace("Alt", QString::fromStdWString(L"\u2325"));
key = key.replace("Meta", QString::fromStdWString(L"\u2303"));
key = key.replace("+", "");
#endif
return key;
}
std::unordered_map<std::string, QString> StatusBar::makeMap(
QString spacer, QString cmdTextSeparator, QString cmd2TextSeparator) {

View file

@ -876,8 +876,8 @@ void TApp::setStatusBarFrameInfo(QString text) {
//-----------------------------------------------------------------------------
void TApp::showMessage(QString message) {
if (m_statusBar) m_statusBar->showMessage(message, 2000);
void TApp::showMessage(QString message, int duration) {
if (m_statusBar) m_statusBar->showMessage(message, duration);
}
//-----------------------------------------------------------------------------

View file

@ -206,7 +206,7 @@ public:
XsheetViewer *getCurrentXsheetViewer() const { return m_xsheetViewer; }
void showMessage(QString message);
void showMessage(QString message, int duration = 2000) override;
void sendShowTitleBars(bool on, bool force = false);
bool getShowTitleBars() { return m_showTitleBars; }
void setShowTitleBars(bool on);

View file

@ -918,6 +918,7 @@ StyleEditorPanel::StyleEditorPanel(QWidget *parent) : TPanel(parent) {
new StyleEditor(TApp::instance()->getPaletteController(), this);
setWidget(m_styleEditor);
m_styleEditor->setApplication(TApp::instance());
m_styleEditor->setLevelHandle(TApp::instance()->getCurrentLevel());
setMinimumWidth(200);
resize(340, 630);

View file

@ -608,3 +608,90 @@ void TStyleManager::signalLoadsFinished() {
if (cm->hasLoadedItems()) cm->signalLoadDone();
}
}
//---------------------------------------------------------
TFilePathSet TStyleManager::getCustomStyleFolders() {
TFilePathSet fps;
std::vector<CustomStyleManager *>::iterator it;
for (it = m_customStyleManagers.begin(); it != m_customStyleManagers.end();
it++) {
CustomStyleManager *cm = *it;
fps.push_back(cm->stylesFolder());
}
return fps;
}
//---------------------------------------------------------
TFilePathSet TStyleManager::getTextureStyleFolders() {
TFilePathSet fps;
std::vector<TextureStyleManager *>::iterator it;
for (it = m_textureStyleManagers.begin(); it != m_textureStyleManagers.end();
it++) {
TextureStyleManager *tm = *it;
fps.push_back(tm->stylesFolder());
}
return fps;
}
//---------------------------------------------------------
TFilePathSet TStyleManager::getBrushStyleFolders() {
TFilePathSet fps;
std::vector<BrushStyleManager *>::iterator it;
for (it = m_brushStyleManagers.begin(); it != m_brushStyleManagers.end();
it++) {
BrushStyleManager *rm = *it;
fps.push_back(rm->stylesFolder());
}
return fps;
}
//---------------------------------------------------------
void TStyleManager::removeCustomStyleFolder(TFilePath styleFolder) {
std::vector<std::pair<TFilePath, QString>>::iterator it;
int i = 0;
for (int i = 0; i < m_customStyleFolders.size(); i++) {
std::pair<TFilePath, QString> fpInfo = m_customStyleFolders[i];
if (fpInfo.first != styleFolder) continue;
m_customStyleFolders.erase(m_customStyleFolders.begin() + i);
m_customStyleManagers.erase(m_customStyleManagers.begin() + i);
break;
}
}
//---------------------------------------------------------
void TStyleManager::removeTextureStyleFolder(TFilePath styleFolder) {
std::vector<std::pair<TFilePath, QString>>::iterator it;
int i = 0;
for (int i = 0; i < m_textureStyleFolders.size(); i++) {
std::pair<TFilePath, QString> fpInfo = m_textureStyleFolders[i];
if (fpInfo.first != styleFolder) continue;
m_textureStyleFolders.erase(m_textureStyleFolders.begin() + i);
m_textureStyleManagers.erase(m_textureStyleManagers.begin() + i);
break;
}
}
//---------------------------------------------------------
void TStyleManager::removeBrushStyleFolder(TFilePath styleFolder) {
std::vector<std::pair<TFilePath, QString>>::iterator it;
int i = 0;
for (int i = 0; i < m_brushStyleFolders.size(); i++) {
std::pair<TFilePath, QString> fpInfo = m_brushStyleFolders[i];
if (fpInfo.first != styleFolder) continue;
m_brushStyleFolders.erase(m_brushStyleFolders.begin() + i);
m_brushStyleManagers.erase(m_brushStyleManagers.begin() + i);
break;
}
}

View file

@ -739,3 +739,17 @@ void ToolBarContainer::paintEvent(QPaintEvent *event) { QPainter p(this); }
QString operator+(const QString &a, const TFilePath &fp) {
return a + QString::fromStdWString(fp.getWideString());
}
//=============================================================================
QString trModKey(QString key) {
#ifdef MACOSX
// Convert Windows key modifier to macOS modifier
key = key.replace("Ctrl", QString::fromStdWString(L"\u2318"));
key = key.replace("Shift", QString::fromStdWString(L"\u21e7"));
key = key.replace("Alt", QString::fromStdWString(L"\u2325"));
key = key.replace("Meta", QString::fromStdWString(L"\u2303"));
key = key.replace("+", "");
#endif
return key;
}

File diff suppressed because it is too large Load diff