OpenToonz - An open-source full-featured 2D animation creation software
C
Fix scroller entry duplication in CustomPanelEditor and migrate to QRegularExpression
andeoncf9efd1323a8
diff --git a/toonz/sources/toonz/custompaneleditorpopup.cpp b/toonz/sources/toonz/custompaneleditorpopup.cppindex e0a5d1984..488e8d24c 100644--- a/toonz/sources/toonz/custompaneleditorpopup.cpp+++ b/toonz/sources/toonz/custompaneleditorpopup.cpp@@ -40,29 +40,32 @@namespace {const TFilePath CustomPanelTemplateFolderName("custom panel templates");-const TFilePath customPaneTemplateFolderPath() {++TFilePath customPaneTemplateFolderPath() {return ToonzFolder::getLibraryFolder() + CustomPanelTemplateFolderName;}+const TFilePath CustomPanelFolderName("custompanels");-const TFilePath customPaneFolderPath() {++TFilePath customPaneFolderPath() {return ToonzFolder::getMyModuleDir() + CustomPanelFolderName;}QPoint relativePos(QWidget* child, QWidget* refParent) {- if (child->parentWidget() == refParent)+ if (child->parentWidget() == refParent) {return child->pos();- else+ } else {return child->pos() + relativePos(child->parentWidget(), refParent);+ }}-} // namespace+} // anonymous namespace//=============================================================================// CustomPanelUIField//------------------------------------------------------------------------------CustomPanelUIField::CustomPanelUIField(const int objId,- const QString objectName,+CustomPanelUIField::CustomPanelUIField(int objId, const QString& objectName,QWidget* parent, bool isFirst): QLabel(tr("Drag and set command"), parent), m_id(objId) {QFont fnt = font();@@ -72,19 +75,24 @@ CustomPanelUIField::CustomPanelUIField(const int objId,setAcceptDrops(true);// objName may be a commandId- if (setCommand(objectName)) return;+ if (setCommand(objectName)) {+ return;+ }if (objectName.startsWith("HScroller") ||objectName.startsWith("VScroller")) {QStringList ids = objectName.split("__");if (ids.size() == 3) {- setCommand((isFirst) ? ids[1] : ids[2]);+ setCommand(isFirst ? ids[1] : ids[2]);}}}-bool CustomPanelUIField::setCommand(QString commandId) {- if (m_commandId == commandId) return false;+bool CustomPanelUIField::setCommand(const QString& commandId) {+ if (m_commandId == commandId) {+ return false;+ }+if (commandId.isEmpty()) {m_commandId = commandId;setText(tr("Drag and set command"));@@ -94,22 +102,35 @@ bool CustomPanelUIField::setCommand(QString commandId) {QAction* action =CommandManager::instance()->getAction(commandId.toStdString().c_str());- if (!action) return false;+ if (!action) {+ return false;+ }m_commandId = commandId;QString tempText = action->text();- // removing accelerator key indicator++ // Remove accelerator key indicatorQRegularExpression re("&([^& ])");tempText = tempText.replace(re, "\\1");- // removing doubled &s++ // Remove doubled &stempText = tempText.replace("&&", "&");+setText(tempText);setStyleSheet("background-color: rgb(230, 230, 230); color: black;");return true;}-void CustomPanelUIField::enterEvent(QEvent* event) { emit highlight(m_id); }-void CustomPanelUIField::leaveEvent(QEvent* event) { emit highlight(-1); }+void CustomPanelUIField::enterEvent(QEvent* event) {+ Q_UNUSED(event);+ emit highlight(m_id);+}++void CustomPanelUIField::leaveEvent(QEvent* event) {+ Q_UNUSED(event);+ emit highlight(-1);+}+void CustomPanelUIField::dragEnterEvent(QDragEnterEvent* event) {QString txt = event->mimeData()->text();if (CommandManager::instance()->getAction(txt.toStdString().c_str())) {@@ -120,33 +141,42 @@ void CustomPanelUIField::dragEnterEvent(QDragEnterEvent* event) {}void CustomPanelUIField::dragLeaveEvent(QDragLeaveEvent* event) {+ Q_UNUSED(event);emit highlight(-1);}void CustomPanelUIField::dropEvent(QDropEvent* event) {QString oldCommandId = m_commandId;QString commandId = event->mimeData()->text();+if (setCommand(commandId)) {- // if dragged from the command tree, command can be duplicated- if (event->dropAction() == Qt::CopyAction)+ // If dragged from the command tree, command can be duplicated+ if (event->dropAction() == Qt::CopyAction) {emit commandChanged(QString(), QString());- else+ } else {emit commandChanged(oldCommandId, m_commandId);+ }}}void CustomPanelUIField::mousePressEvent(QMouseEvent* event) {- if (m_commandId.isEmpty()) return;+ if (m_commandId.isEmpty()) {+ return;+ }+QMimeData* mimeData = new QMimeData;mimeData->setText(m_commandId);QString dragPixmapTxt = text();QFontMetrics fm(QApplication::font());QPixmap pix(fm.boundingRect(dragPixmapTxt).adjusted(-2, -2, 2, 2).size());- QPainter painter(&pix);- painter.fillRect(pix.rect(), Qt::white);- painter.setPen(Qt::black);- painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);++ {+ QPainter painter(&pix);+ painter.fillRect(pix.rect(), Qt::white);+ painter.setPen(Qt::black);+ painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);+ }QDrag* drag = new QDrag(this);drag->setMimeData(mimeData);@@ -159,22 +189,30 @@ void CustomPanelUIField::mousePressEvent(QMouseEvent* event) {// UiPreviewWidget//------------------------------------------------------------------------------UiPreviewWidget::UiPreviewWidget(QPixmap uiPixmap, QList<UiEntry>& uiEntries,+UiPreviewWidget::UiPreviewWidget(const QPixmap& uiPixmap,+ const QList<UiEntry>& uiEntries,QWidget* parent): QWidget(parent), m_highlightUiId(-1), m_uiPixmap(uiPixmap) {- for (auto entry : uiEntries) m_rectTable.append(entry.rect);+ for (const auto& entry : uiEntries) {+ m_rectTable.append(entry.rect);+ }setFixedSize(m_uiPixmap.size());setAcceptDrops(true);setMouseTracking(true);}-void UiPreviewWidget::onViewerResize(QSize size) {- if (m_uiPixmap.isNull()) return;+void UiPreviewWidget::onViewerResize(const QSize& size) {+ if (m_uiPixmap.isNull()) {+ return;+ }+setFixedSize(std::max(size.width(), m_uiPixmap.width()),std::max(size.height(), m_uiPixmap.height()));}-void UiPreviewWidget::paintEvent(QPaintEvent*) {+void UiPreviewWidget::paintEvent(QPaintEvent* event) {+ Q_UNUSED(event);+QPainter p(this);p.translate((width() - m_uiPixmap.width()) / 2,(height() - m_uiPixmap.height()) / 2);@@ -182,25 +220,28 @@ void UiPreviewWidget::paintEvent(QPaintEvent*) {for (int id = 0; id < m_rectTable.count(); id++) {QRect uiRect = m_rectTable.at(id);- if (id == m_highlightUiId)+ if (id == m_highlightUiId) {p.setBrush(QColor(0, 255, 255, 64));- else+ } else {p.setBrush(Qt::NoBrush);+ }p.setPen(Qt::cyan);p.drawRect(uiRect);}}-void UiPreviewWidget::highlightUi(const int objId) {+void UiPreviewWidget::highlightUi(int objId) {m_highlightUiId = objId;update();}void UiPreviewWidget::mousePressEvent(QMouseEvent* event) {- if (m_highlightUiId >= 0) emit clicked(m_highlightUiId);+ if (m_highlightUiId >= 0) {+ emit clicked(m_highlightUiId);+ }}-void UiPreviewWidget::onMove(const QPoint pos) {+void UiPreviewWidget::onMove(const QPoint& pos) {QPoint offset((width() - m_uiPixmap.width()) / 2,(height() - m_uiPixmap.height()) / 2);@@ -253,7 +294,7 @@ UiPreviewArea::UiPreviewArea(QWidget* parent) : QScrollArea(parent) {}void UiPreviewArea::resizeEvent(QResizeEvent* event) {if (widget()) {- UiPreviewWidget* previewWidget = dynamic_cast<UiPreviewWidget*>(widget());+ UiPreviewWidget* previewWidget = qobject_cast<UiPreviewWidget*>(widget());if (previewWidget) {previewWidget->onViewerResize(event->size());}@@ -274,17 +315,20 @@ bool CustomPanelEditorPopup::loadTemplateList() {.arg(customPanelTemplateFolder.getQString()));return false;}+TFilePathSet fileList =TSystem::readDirectory(customPanelTemplateFolder, false, true, false);if (fileList.empty()) {DVGui::warning(tr("Template files not found."));return false;}+m_templateCombo->clear();- QList<QString> fileNames;- for (auto file : fileList) {- // accept only .ui files- if (file.getType() != "ui") continue;+ for (const auto& file : fileList) {+ // Accept only .ui files+ if (file.getType() != "ui") {+ continue;+ }m_templateCombo->addItem(QString::fromStdString(file.getName()),file.getQString());}@@ -296,22 +340,25 @@ bool CustomPanelEditorPopup::loadTemplateList() {return false;}- // then, insert user custom panel+ // Then, insert user custom panelTFilePath customPanelsFolder = customPaneFolderPath();if (TSystem::doesExistFileOrLevel(customPanelsFolder)) {TFilePathSet fileList2 =TSystem::readDirectory(customPanelsFolder, false, true, false);- for (auto file : fileList2) {- // accept only .ui files- if (file.getType() != "ui") continue;+ for (const auto& file : fileList2) {+ // Accept only .ui files+ if (file.getType() != "ui") {+ continue;+ }m_templateCombo->addItem(tr("%1 (Edit)").arg(QString::fromStdString(file.getName())),file.getQString());}}- if (m_templateCombo->count() > templateCount)+ if (m_templateCombo->count() > templateCount) {m_templateCombo->insertSeparator(templateCount);+ }return true;}@@ -319,14 +366,14 @@ bool CustomPanelEditorPopup::loadTemplateList() {//-----------------------------------------------------------------------------void CustomPanelEditorPopup::createFields() {+ // Clear existing fieldsfor (QWidget* child : m_UiFieldsContainer->findChildren<QWidget*>()) {delete child;}- QGridLayout* gridLay;- if (m_UiFieldsContainer->layout())- gridLay = dynamic_cast<QGridLayout*>(m_UiFieldsContainer->layout());- else {+ QGridLayout* gridLay =+ qobject_cast<QGridLayout*>(m_UiFieldsContainer->layout());+ if (!gridLay) {gridLay = new QGridLayout();gridLay->setContentsMargins(15, 15, 15, 15);gridLay->setHorizontalSpacing(10);@@ -337,16 +384,17 @@ void CustomPanelEditorPopup::createFields() {m_UiFieldsContainer->setLayout(gridLay);}- // for each entry+ // For each entryint uiCounts[2] = {0, 0};QString labelStr[2] = {tr("Button"), tr("Scroller")};int id = 0;int row = 0;+for (auto& entry : m_uiEntries) {if (entry.type == Button || entry.type == Scroller_Back) {- entry.field = new CustomPanelUIField(id, entry.objectName, this);- QString label =- labelStr[(int)entry.type] + QString::number(uiCounts[entry.type] + 1);+ entry.field = new CustomPanelUIField(id, entry.objectName, this);+ QString label = labelStr[static_cast<int>(entry.type)] ++ QString::number(uiCounts[entry.type] + 1);uiCounts[entry.type]++;gridLay->addWidget(new QLabel(label, this), row, 0, Qt::AlignRight);gridLay->addWidget(entry.field, row, 1);@@ -354,7 +402,10 @@ void CustomPanelEditorPopup::createFields() {entry.field = new CustomPanelUIField(id, entry.objectName, this, false);gridLay->addWidget(entry.field, row, 2);}- if (entry.type == Button || entry.type == Scroller_Fore) row++;++ if (entry.type == Button || entry.type == Scroller_Fore) {+ row++;+ }connect(entry.field, &CustomPanelUIField::highlight, this,&CustomPanelEditorPopup::onHighlight);@@ -366,11 +417,11 @@ void CustomPanelEditorPopup::createFields() {//------------------------------------------------------------------------------// create entries from a widget just loaded from .ui file+// Create entries from a widget just loaded from .ui filevoid CustomPanelEditorPopup::buildEntries(QWidget* customWidget) {m_uiEntries.clear();- // this will define child widgets positions+ // This will define child widgets positionscustomWidget->grab();QList<QWidget*> allWidgets = customWidget->findChildren<QWidget*>();@@ -382,64 +433,78 @@ void CustomPanelEditorPopup::buildEntries(QWidget* customWidget) {});for (auto widget : allWidgets) {- if (widget->objectName().isEmpty()) continue;- if (widget->layout() != nullptr) continue;- UiEntry entry;+ if (widget->objectName().isEmpty()) {+ continue;+ }+ if (widget->layout() != nullptr) {+ continue;+ }- entry.type = (dynamic_cast<QAbstractButton*>(widget))- ? (UiType)Button- : (UiType)Scroller_Back;+ UiEntry entry;+ entry.type = (qobject_cast<QAbstractButton*>(widget))+ ? static_cast<UiType>(Button)+ : static_cast<UiType>(Scroller_Back);entry.objectName = widget->objectName();- if (entry.type == Button)+ if (entry.type == Button) {entry.rect = QRect(relativePos(widget, customWidget), widget->size());- else { // Scroller_Back+ } else { // Scroller_Backentry.orientation =(widget->width() > widget->height()) ? Qt::Horizontal : Qt::Vertical;- if (entry.orientation == Qt::Horizontal)+ if (entry.orientation == Qt::Horizontal) {entry.rect = QRect(relativePos(widget, customWidget),QSize(widget->width() / 2, widget->height()));- else+ } else {entry.rect = QRect(relativePos(widget, customWidget),QSize(widget->width(), widget->height() / 2));+ }}m_uiEntries.append(entry);- // register Scroller_Fore+ // Register Scroller_Foreif (entry.type == Scroller_Back) {- entry.type = (UiType)Scroller_Fore;- if (entry.orientation == Qt::Horizontal)- entry.rect.translate(widget->width() / 2, 0);- else- entry.rect.translate(0, widget->height() / 2);-- m_uiEntries.append(entry);+ UiEntry foreEntry = entry;+ foreEntry.type = static_cast<UiType>(Scroller_Fore);+ if (foreEntry.orientation == Qt::Horizontal) {+ foreEntry.rect.translate(widget->width() / 2, 0);+ } else {+ foreEntry.rect.translate(0, widget->height() / 2);+ }+ m_uiEntries.append(foreEntry);}}}//------------------------------------------------------------------------------// update widget using the current entries+// Update widget using the current entriesvoid CustomPanelEditorPopup::updateControls(QWidget* customWidget) {QList<QWidget*> allWidgets = customWidget->findChildren<QWidget*>();for (auto widget : allWidgets) {QList<int> entryIds = entryIdByObjName(widget->objectName());- if (entryIds.isEmpty()) continue;+ if (entryIds.isEmpty()) {+ continue;+ }+UiEntry entry = m_uiEntries.at(entryIds.at(0));if (entry.type == Button) {QString commandId = entry.field->commandId();QAction* action = CommandManager::instance()->getAction(commandId.toStdString().c_str());- if (!action) continue;- QAbstractButton* button = dynamic_cast<QAbstractButton*>(widget);- QToolButton* tb = dynamic_cast<QToolButton*>(widget);+ if (!action) {+ continue;+ }++ QAbstractButton* button = qobject_cast<QAbstractButton*>(widget);+ QToolButton* tb = qobject_cast<QToolButton*>(widget);+CommandManager::instance()->enlargeIcon(commandId.toStdString().c_str(),button->iconSize());- if (tb)+ if (tb) {tb->setDefaultAction(action);- else if (button)+ } else if (button) {button->setIcon(action->icon());+ }}}}@@ -451,17 +516,20 @@ void CustomPanelEditorPopup::onTemplateSwitched() {QString fp = m_templateCombo->currentData().toString();QFile file(fp);- file.open(QFile::ReadOnly);- QWidget* customWidget = loader.load(&file, 0);+ if (!file.open(QFile::ReadOnly)) {+ return;+ }++ QWidget* customWidget = loader.load(&file, nullptr);file.close();- // create entries from a widget just loaded from .ui file+ // Create entries from a widget just loaded from .ui filebuildEntries(customWidget);- // objectName of each widget will be overwritten in this function+ // ObjectName of each widget will be overwritten in this functionCustomPanelManager::instance()->initializeControl(customWidget);- // create UI fields+ // Create UI fieldscreateFields();UiPreviewWidget* previewWidget =@@ -469,7 +537,7 @@ void CustomPanelEditorPopup::onTemplateSwitched() {if (m_previewArea->widget()) {UiPreviewWidget* oldPreview =- dynamic_cast<UiPreviewWidget*>(m_previewArea->widget());+ qobject_cast<UiPreviewWidget*>(m_previewArea->widget());if (oldPreview) {disconnect(oldPreview, &UiPreviewWidget::clicked, this,&CustomPanelEditorPopup::onPreviewClicked);@@ -489,31 +557,41 @@ void CustomPanelEditorPopup::onTemplateSwitched() {delete customWidget;- if (customPaneFolderPath().isAncestorOf(TFilePath(fp)))+ if (customPaneFolderPath().isAncestorOf(TFilePath(fp))) {m_panelNameEdit->setText(m_templateCombo->currentText().chopped(7));+ }updateGeometry();}+//-----------------------------------------------------------------------------void CustomPanelEditorPopup::onHighlight(int id) {- if (!m_previewArea->widget()) return;+ if (!m_previewArea->widget()) {+ return;+ }+UiPreviewWidget* previewWidget =- dynamic_cast<UiPreviewWidget*>(m_previewArea->widget());- if (!previewWidget) return;+ qobject_cast<UiPreviewWidget*>(m_previewArea->widget());+ if (!previewWidget) {+ return;+ }+previewWidget->highlightUi(id);}//------------------------------------------------------------------------------// set pixmap of updated ui to the preview-void CustomPanelEditorPopup::onCommandChanged(QString oldCmdId,- QString newCmdId) {+// Set pixmap of updated ui to the preview+void CustomPanelEditorPopup::onCommandChanged(const QString& oldCmdId,+ const QString& newCmdId) {// If the command is dragged from another field, then swap the commands.if (!newCmdId.isEmpty()) {CustomPanelUIField* senderField =- dynamic_cast<CustomPanelUIField*>(sender());- for (auto entry : m_uiEntries) {- if (!entry.field || entry.field == senderField) continue;+ qobject_cast<CustomPanelUIField*>(sender());+ for (auto& entry : m_uiEntries) {+ if (!entry.field || entry.field == senderField) {+ continue;+ }if (entry.field->commandId() == newCmdId) {entry.field->setCommand(oldCmdId);break;@@ -523,35 +601,49 @@ void CustomPanelEditorPopup::onCommandChanged(QString oldCmdId,QString fp = m_templateCombo->currentData().toString();QFile tmplFile(fp);- tmplFile.open(QFile::ReadOnly);+ if (!tmplFile.open(QFile::ReadOnly)) {+ return;+ }QUiLoader loader;- QWidget* customWidget = loader.load(&tmplFile, 0);+ QWidget* customWidget = loader.load(&tmplFile, nullptr);tmplFile.close();updateControls(customWidget);UiPreviewWidget* previewWidget =- dynamic_cast<UiPreviewWidget*>(m_previewArea->widget());- previewWidget->setUiPixmap(customWidget->grab());+ qobject_cast<UiPreviewWidget*>(m_previewArea->widget());+ if (previewWidget) {+ previewWidget->setUiPixmap(customWidget->grab());+ }+delete customWidget;}void CustomPanelEditorPopup::onPreviewClicked(int id) {CustomPanelUIField* field = m_uiEntries.at(id).field;- if (!field) return;+ if (!field) {+ return;+ }+QString commandId = field->commandId();- if (commandId.isEmpty()) return;+ if (commandId.isEmpty()) {+ return;+ }+QMimeData* mimeData = new QMimeData;mimeData->setText(commandId);QString dragPixmapTxt = field->text();QFontMetrics fm(QApplication::font());QPixmap pix(fm.boundingRect(dragPixmapTxt).adjusted(-2, -2, 2, 2).size());- QPainter painter(&pix);- painter.fillRect(pix.rect(), Qt::white);- painter.setPen(Qt::black);- painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);++ {+ QPainter painter(&pix);+ painter.fillRect(pix.rect(), Qt::white);+ painter.setPen(Qt::black);+ painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);+ }QDrag* drag = new QDrag(sender());drag->setMimeData(mimeData);@@ -560,26 +652,31 @@ void CustomPanelEditorPopup::onPreviewClicked(int id) {drag->exec(Qt::MoveAction);}-void CustomPanelEditorPopup::onPreviewDropped(int id, QString cmdId,+void CustomPanelEditorPopup::onPreviewDropped(int id, const QString& cmdId,bool fromTree) {CustomPanelUIField* field = m_uiEntries.at(id).field;- if (!field) return;+ if (!field) {+ return;+ }QString oldCommandId = field->commandId();if (field->setCommand(cmdId)) {- if (fromTree)- field->notifyCommandChanged(QString(), QString());- else- field->notifyCommandChanged(oldCommandId, cmdId);+ if (fromTree) {+ emit field->commandChanged(QString(), QString());+ } else {+ emit field->commandChanged(oldCommandId, cmdId);+ }}}//------------------------------------------------------------------------------QList<int> CustomPanelEditorPopup::entryIdByObjName(const QString objName) {+QList<int> CustomPanelEditorPopup::entryIdByObjName(const QString& objName) {QList<int> ret;for (int i = 0; i < m_uiEntries.size(); i++) {- if (m_uiEntries[i].objectName == objName) ret.append(i);+ if (m_uiEntries[i].objectName == objName) {+ ret.append(i);+ }}return ret;}@@ -589,16 +686,16 @@ void CustomPanelEditorPopup::replaceObjectNames(QDomElement& element) {while (!n.isNull()) {if (n.isElement()) {QDomElement e = n.toElement();- // check self+ // Check selfif (e.tagName() == "widget" && e.hasAttribute("name")) {QString objName = e.attribute("name");QList<int> entryIds = entryIdByObjName(objName);if (!entryIds.isEmpty()) {UiEntry entry = m_uiEntries.at(entryIds[0]);- if (entry.type == Button)+ if (entry.type == Button) {e.setAttribute("name", entry.field->commandId());- else { // Scroller+ } else { // ScrollerUiEntry entryFore = m_uiEntries.at(entryIds[1]);QStringList newNameList;newNameList.append((entry.orientation == Qt::Horizontal)@@ -610,7 +707,7 @@ void CustomPanelEditorPopup::replaceObjectNames(QDomElement& element) {}}}- // check recursively+ // Check recursivelyreplaceObjectNames(e);}n = n.nextSibling();@@ -623,7 +720,8 @@ void CustomPanelEditorPopup::onRegister() {DVGui::warning(tr("Please input the panel name."));return;}- // overwrite confirmation++ // Overwrite confirmationTFilePath customPanelPath =customPaneFolderPath() + TFilePath(panelName + ".ui");if (TSystem::doesExistFileOrLevel(customPanelPath)) {@@ -636,19 +734,20 @@ void CustomPanelEditorPopup::onRegister() {}}- // create folder if not exist+ // Create folder if not existif (!TSystem::touchParentDir(customPanelPath)) {DVGui::warning(tr("Failed to create folder."));return;}- // base template file+ // Base template fileQDomDocument doc(panelName);QFile tmplFile(m_templateCombo->currentData().toString());if (!tmplFile.open(QIODevice::ReadOnly)) {DVGui::warning(tr("Failed to open the template."));return;}+if (!doc.setContent(&tmplFile)) {tmplFile.close();return;@@ -663,13 +762,13 @@ void CustomPanelEditorPopup::onRegister() {DVGui::warning(tr("Failed to open the file for writing."));return;}+QTextStream stream(&file);stream.setCodec("UTF-8");stream << doc.toString();file.close();CustomPanelManager::instance()->loadCustomPanelEntries();-close();}@@ -759,9 +858,9 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()connect(searchEdit, &QLineEdit::textChanged, this,&CustomPanelEditorPopup::onSearchTextChanged);- // load template- bool ok = loadTemplateList();- if (!ok) {+ // Load template+ if (!loadTemplateList()) {+ // Handle template loading failure if needed}}@@ -769,7 +868,10 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()void CustomPanelEditorPopup::onSearchTextChanged(const QString& text) {static bool busy = false;- if (busy) return;+ if (busy) {+ return;+ }+busy = true;m_commandListTree->searchItems(text);busy = false;diff --git a/toonz/sources/toonz/custompaneleditorpopup.h b/toonz/sources/toonz/custompaneleditorpopup.hindex 2aa841d90..de9a98098 100644--- a/toonz/sources/toonz/custompaneleditorpopup.h+++ b/toonz/sources/toonz/custompaneleditorpopup.h@@ -15,13 +15,17 @@#include <QScrollArea>#include <QDomElement>-class QComboBox;+#include <QComboBox>+#include <QLineEdit>++// Forward declarationsclass CustomPanelUIField;class CommandListTree;enum UiType { Button = 0, Scroller_Back, Scroller_Fore, TypeCount };+struct UiEntry {- QString objectName; // object name before editing+ QString objectName; // Object name before editingUiType type;QRect rect;CustomPanelUIField* field;@@ -31,16 +35,19 @@ struct UiEntry {//=============================================================================// CustomPanelUIField//-----------------------------------------------------------------------------+class CustomPanelUIField : public QLabel {Q_OBJECT+int m_id;QString m_commandId;public:- CustomPanelUIField(const int id, const QString objectName,- QWidget* parent = nullptr, bool isFirst = true);- QString commandId() { return m_commandId; }- bool setCommand(QString commandId);+ explicit CustomPanelUIField(int id, const QString& objectName,+ QWidget* parent = nullptr, bool isFirst = true);++ QString commandId() const { return m_commandId; }+ bool setCommand(const QString& commandId);protected:void enterEvent(QEvent* event) override;@@ -49,40 +56,45 @@ protected:void dragLeaveEvent(QDragLeaveEvent* event) override;void dropEvent(QDropEvent* event) override;void mousePressEvent(QMouseEvent* event) override;+signals:- void highlight(int);- void commandChanged(QString, QString);+ void highlight(int id);+ void commandChanged(const QString& oldCmdId, const QString& newCmdId);public:- void notifyCommandChanged(QString oldCmdID, QString newCmdId) {- emit commandChanged(oldCmdID, newCmdId);+ void notifyCommandChanged(const QString& oldCmdId, const QString& newCmdId) {+ emit commandChanged(oldCmdId, newCmdId);}};+//=============================================================================// UiPreviewWidget//-----------------------------------------------------------------------------class UiPreviewWidget final : public QWidget {Q_OBJECT+int m_highlightUiId;QList<QRect> m_rectTable;QPixmap m_uiPixmap;- void onMove(const QPoint pos);+ void onMove(const QPoint& pos);public:- UiPreviewWidget(QPixmap uiPixmap, QList<UiEntry>& uiEntries,- QWidget* parent = nullptr);- void onViewerResize(QSize size);- void highlightUi(const int objId);- void setUiPixmap(QPixmap uiPixmap) {+ explicit UiPreviewWidget(const QPixmap& uiPixmap,+ const QList<UiEntry>& uiEntries,+ QWidget* parent = nullptr);++ void onViewerResize(const QSize& size);+ void highlightUi(int objId);++ void setUiPixmap(const QPixmap& uiPixmap) {m_uiPixmap = uiPixmap;update();}protected:- void paintEvent(QPaintEvent*) override;-+ void paintEvent(QPaintEvent* event) override;void mousePressEvent(QMouseEvent* event) override;void mouseMoveEvent(QMouseEvent* event) override;void dragEnterEvent(QDragEnterEvent* event) override;@@ -91,13 +103,18 @@ protected:signals:void clicked(int id);- void dropped(int id, QString cmdId, bool fromTree);+ void dropped(int id, const QString& cmdId, bool fromTree);};+//=============================================================================+// UiPreviewArea+//-----------------------------------------------------------------------------+class UiPreviewArea final : public QScrollArea {Q_OBJECT+public:- UiPreviewArea(QWidget* parent = nullptr);+ explicit UiPreviewArea(QWidget* parent = nullptr);protected:void resizeEvent(QResizeEvent* event) override;@@ -107,39 +124,37 @@ protected:// CustomPanelEditorPopup//------------------------------------------------------------------------------class CustomPanelEditorPopup : public DVGui::Dialog {+class CustomPanelEditorPopup final : public DVGui::Dialog {Q_OBJECT+private:CommandListTree* m_commandListTree;QWidget* m_UiFieldsContainer;UiPreviewArea* m_previewArea;-QComboBox* m_templateCombo;QLineEdit* m_panelNameEdit;QList<UiEntry> m_uiEntries;- QList<int> entryIdByObjName(const QString objName);-+ // Helper methods+ QList<int> entryIdByObjName(const QString& objName);bool loadTemplateList();void createFields();-void replaceObjectNames(QDomElement& element);-- // create entries from a widget just loaded from .ui file- void buildEntries(QWidget* customWidget);- // update widget using the current entries- void updateControls(QWidget* customWidget);+ void buildEntries(QWidget* customWidget); // Create entries from UI file+ void updateControls(+ QWidget* customWidget); // Update widget using current entriespublic:- CustomPanelEditorPopup();-protected slots:+ explicit CustomPanelEditorPopup();++private slots:void onTemplateSwitched();void onHighlight(int id);- void onCommandChanged(QString, QString);+ void onCommandChanged(const QString& oldCmdId, const QString& newCmdId);void onPreviewClicked(int id);- void onPreviewDropped(int id, QString cmdId, bool fromTree);+ void onPreviewDropped(int id, const QString& cmdId, bool fromTree);void onRegister();void onSearchTextChanged(const QString& text);};-#endif\ No newline at end of file+#endif // CUSTOMPANELEDITORPOPUP_H