Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Add dockable FX Browser with schematic drag and drop

Rodney16661c844073
diff --git a/stuff/profiles/layouts/rooms/Default/room6.ini b/stuff/profiles/layouts/rooms/Default/room6.ini
index f7be49c39..70d3f1cd1 100644
--- a/stuff/profiles/layouts/rooms/Default/room6.ini
+++ b/stuff/profiles/layouts/rooms/Default/room6.ini
@@ -7,14 +7,14 @@ pane_1\toggleStatus=0
pane_1\showIbtwnValuesInSheet=true
pane_1\syncSize=true
pane_2\name=Schematic
-pane_2\geometry=@Rect(38 555 1411 432)
+pane_2\geometry=@Rect(292 555 1157 432)
pane_2\viewtype=0
pane_3\name=ToolBar
pane_3\geometry=@Rect(0 60 34 927)
pane_4\name=SceneViewer
pane_4\geometry=@Rect(504 60 945 491)
pane_4\viewerVisibleParts=3
-hierarchy="-1 1 [ 5 0 [ 3 [ [ 6 4 ] 2 ] [ 1 7 ] ] ] "
+hierarchy="-1 1 [ 5 0 [ 3 [ [ 6 4 ] [ 8 2 ] ] [ 1 7 ] ] ] "
name=Composite
pane_5\name=CommandBar
pane_5\geometry=@Rect(0 0 1920 26)
@@ -26,3 +26,5 @@ pane_7\toolbarOnTop=0
pane_7\toolbarVisibleMsk=1
pane_7\variableWidth=1
pane_7\viewtype=1
+pane_8\name=FxBrowser
+pane_8\geometry=@Rect(38 555 250 432)
diff --git a/toonz/sources/include/toonz/fxcommand.h b/toonz/sources/include/toonz/fxcommand.h
index da6559ba1..8cd918be0 100644
--- a/toonz/sources/include/toonz/fxcommand.h
+++ b/toonz/sources/include/toonz/fxcommand.h
@@ -64,7 +64,7 @@ DVAPI void insertFx(TFx *newFx, const QList<TFxP> &fxs,
const QList<Link> &links, TApplication *app, int colunIndex,
int rowIndex);
DVAPI void addFx(TFx *newFx, const QList<TFxP> &fxs, TApplication *app,
- int colunIndex, int rowIndex);
+ int colunIndex, int rowIndex, bool attachSource = true);
DVAPI void replaceFx(TFx *newFx, const QList<TFxP> &fxs,
TXsheetHandle *xshHandle, TFxHandle *fxHandle);
DVAPI void duplicateFx(TFx *src, TXsheetHandle *xshHandle, TFxHandle *fxHandle);
diff --git a/toonz/sources/include/toonzqt/fxschematicscene.h b/toonz/sources/include/toonzqt/fxschematicscene.h
index 2cefabcbb..39ad696b6 100644
--- a/toonz/sources/include/toonzqt/fxschematicscene.h
+++ b/toonz/sources/include/toonzqt/fxschematicscene.h
@@ -4,6 +4,7 @@
#define FXSCHEMATIC_H
#include "toonzqt/addfxcontextmenu.h"
+#include "toonz/fxcommand.h"
#include "schematicviewer.h"
#include "tgeometry.h"
#include <QMap>
@@ -12,6 +13,7 @@
// forward declaration
class FxSchematicNode;
+class FxSchematicLink;
class TFxHandle;
class FxSelection;
class FxSchematicNode;
@@ -25,6 +27,9 @@ class FxSchematicMacroEditor;
class TMacroFx;
enum SearchDirection { Both = 0, Input, Output };
+
+//! What dropping an Fx from the Fx browser onto the schematic will do.
+enum class DragDropAction { None = 0, Add, Insert, Replace };
//==================================================================
//
// FXSchematic
@@ -105,6 +110,14 @@ class FxSchematicScene final : public SchematicScene {
SchematicViewer *m_viewer;
+ // drag & drop of an Fx coming from the Fx browser
+ DragDropAction m_dragDropAction;
+ TFxP m_dragFx;
+ QList<TFxP> m_dropFxs;
+ QList<TFxCommand::Link> m_dropLinks;
+ FxSchematicLink *m_litLink;
+ FxSchematicNode *m_litNode;
+
public:
FxSchematicScene(QWidget *parent);
~FxSchematicScene();
@@ -159,8 +172,14 @@ protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
bool event(QEvent *e) override;
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *e) override;
+ void dragMoveEvent(QGraphicsSceneDragDropEvent *e) override;
+ void dropEvent(QGraphicsSceneDragDropEvent *e) override;
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent *e) override;
private:
+ void clearDropHighlights();
+
FxSchematicNode *addFxSchematicNode(TFx *fx);
FxSchematicNode *addGroupedFxSchematicNode(int groupId,
const QList<TFxP> &groupedFxs);
@@ -264,4 +283,4 @@ private:
const FxSchematicScene &operator=(const FxSchematicScene &);
};
-#endif // FXSCHEMATIC_H
\ No newline at end of file
+#endif // FXSCHEMATIC_H
diff --git a/toonz/sources/toonz/insertfxpopup.h b/toonz/sources/include/toonzqt/insertfxpopup.h
similarity index 62%
rename from toonz/sources/toonz/insertfxpopup.h
rename to toonz/sources/include/toonzqt/insertfxpopup.h
index 2a519965c..65a815f2d 100644
--- a/toonz/sources/toonz/insertfxpopup.h
+++ b/toonz/sources/include/toonzqt/insertfxpopup.h
@@ -3,11 +3,30 @@
#ifndef INSERTFXPOPUP_H
#define INSERTFXPOPUP_H
+#ifdef _MSC_VER
+#pragma warning(disable : 4251)
+#endif
+
#include <QTreeWidget>
+#include <QFrame>
+#include <QPoint>
+
+#include "tcommon.h"
#include "toonzqt/dvdialog.h"
+#include "toonz/tapplication.h"
#include "tfilepath.h"
#include "tstream.h"
+#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 declaration
class QTreeWidget;
class QTreeWidgetItem;
@@ -22,19 +41,32 @@ class TFx;
class FxTree final : public QTreeWidget {
Q_OBJECT
+ QPoint m_dragStartPos;
+ bool m_maybeDragging = false;
+
public:
+ FxTree(QWidget *parent = nullptr) : QTreeWidget(parent) {}
+
void searchItems(const QString &searchWord = QString());
private:
void displayAll(QTreeWidgetItem *item);
void hideAll(QTreeWidgetItem *item);
+
+ //! Build an Fx for the item under the cursor and start a drag carrying it.
+ void startFxDrag(QTreeWidgetItem *item);
+
+protected:
+ void mousePressEvent(QMouseEvent *) override;
+ void mouseMoveEvent(QMouseEvent *) override;
+ void mouseReleaseEvent(QMouseEvent *) override;
};
//=============================================================================
// InsertFxPopup
//-----------------------------------------------------------------------------
-class InsertFxPopup final : public DVGui::Dialog {
+class DVAPI InsertFxPopup final : public QFrame {
Q_OBJECT
FxTree *m_fxTree;
@@ -46,12 +78,19 @@ class InsertFxPopup final : public DVGui::Dialog {
QIcon m_presetIcon;
QIcon m_fxIcon;
+ TApplication *m_app;
+ QString m_searchText;
+
public:
- InsertFxPopup();
+ InsertFxPopup(QWidget *parent = nullptr,
+ Qt::WindowFlags flags = Qt::WindowFlags());
+ ~InsertFxPopup();
+
+ void setApplication(TApplication *app);
-private:
TFx *createFx();
+private:
void makeItem(QTreeWidgetItem *parent, std::string fxid);
void loadFolder(QTreeWidgetItem *parent);
@@ -69,7 +108,6 @@ public slots:
protected:
void showEvent(QShowEvent *) override;
- void hideEvent(QHideEvent *) override;
void contextMenuEvent(QContextMenuEvent *) override;
protected slots:
diff --git a/toonz/sources/include/toonzqt/pluginloader.h b/toonz/sources/include/toonzqt/pluginloader.h
index 4b6809d10..50f85e4c4 100644
--- a/toonz/sources/include/toonzqt/pluginloader.h
+++ b/toonz/sources/include/toonzqt/pluginloader.h
@@ -19,7 +19,7 @@
/* Plugin Loader の inter-module interfaces:
toonzqt 以下のモジュールからアクセスするのに必要 (see:
- toonz/insertfxpopup.cpp)
+ toonzqt/insertfxpopup.cpp)
implements in pluginhost.cpp */
class TFx;
diff --git a/toonz/sources/include/toonzqt/schematicnode.h b/toonz/sources/include/toonzqt/schematicnode.h
index 8b2652759..ca9ff84fa 100644
--- a/toonz/sources/include/toonzqt/schematicnode.h
+++ b/toonz/sources/include/toonzqt/schematicnode.h
@@ -245,6 +245,7 @@ class SchematicLink : public QObject, public QGraphicsItem {
QPainterPath m_path, m_hitPath;
bool m_lineShaped;
bool m_highlighted;
+ bool m_dropHighlighted;
public:
SchematicLink(QGraphicsItem *parent, QGraphicsScene *scene);
@@ -299,6 +300,9 @@ public:
bool isHighlighted() { return m_highlighted; }
void setHighlighted(bool value) { m_highlighted = value; }
+ bool isDropHighlighted() const { return m_dropHighlighted; }
+ void setDropHighlighted(bool value) { m_dropHighlighted = value; }
+
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
@@ -451,6 +455,8 @@ protected:
Qt::MouseButton m_buttonState;
QMap<int, SchematicPort *> m_ports;
+ bool m_dropHighlighted;
+
public:
SchematicNode(SchematicScene *scene);
~SchematicNode() override;
@@ -471,6 +477,9 @@ public:
void updateLinksGeometry();
virtual void onClicked(){};
+ bool isDropHighlighted() const { return m_dropHighlighted; }
+ void setDropHighlighted(bool value) { m_dropHighlighted = value; }
+
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override;
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txt
index 8e604640f..bd70d5672 100644
--- a/toonz/sources/toonz/CMakeLists.txt
+++ b/toonz/sources/toonz/CMakeLists.txt
@@ -51,7 +51,6 @@ set(MOC_HEADERS
histogrampopup.h
historypane.h
imageviewer.h
- insertfxpopup.h
layerfooterpanel.h
layerheaderpanel.h
levelcreatepopup.h
@@ -283,7 +282,6 @@ set(SOURCES
formatsettingspopups.cpp
fxparameditorpopup.cpp
histogrampopup.cpp
- insertfxpopup.cpp
layerfooterpanel.cpp
layerheaderpanel.cpp
levelcreatepopup.cpp
diff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cpp
index 9106cc31a..e748318e0 100644
--- a/toonz/sources/toonz/tpanels.cpp
+++ b/toonz/sources/toonz/tpanels.cpp
@@ -89,6 +89,8 @@
#include "../../toonz/locatorpopup.h"
+#include "toonzqt/insertfxpopup.h"
+
// TnzBase includes
#include "trasterfx.h"
#include "toutputproperties.h"
@@ -1725,12 +1727,6 @@ public:
void execute() override { zoomAndFitPanel(true); }
} zoomInAndFitPanel;
-//=============================================================================
-OpenFloatingPanel openFxBrowserCommand(MI_InsertFx, "FxBrowser",
- QObject::tr("Fx Browser"));
-
-//-----------------------------------------------------------------------------
-
//=============================================================================
// LocatorPanel
//-----------------------------------------------------------------------------
@@ -1765,3 +1761,41 @@ public:
//=============================================================================
OpenFloatingPanel openLocatorCommand(MI_OpenLocator, "Locator",
QObject::tr("Locator"));
+
+//-----------------------------------------------------------------------------
+
+//=============================================================================
+// FxBrowserPanel
+//-----------------------------------------------------------------------------
+
+FxBrowserPanel::FxBrowserPanel(QWidget *parent) : TPanel(parent) {
+ m_fxBrowser = new InsertFxPopup(this);
+ m_fxBrowser->setApplication(TApp::instance());
+
+ setWidget(m_fxBrowser);
+}
+
+//=============================================================================
+// FxBrowserFactory
+//-----------------------------------------------------------------------------
+
+class FxBrowserFactory final : public TPanelFactory {
+public:
+ FxBrowserFactory() : TPanelFactory("FxBrowser") {}
+
+ TPanel *createPanel(QWidget *parent) override {
+ FxBrowserPanel *panel = new FxBrowserPanel(parent);
+ panel->move(qApp->desktop()->screenGeometry(panel).center());
+ panel->setObjectName(getPanelType());
+ panel->setWindowTitle(QObject::tr("FX Browser"));
+ panel->setMinimumWidth(233);
+ return panel;
+ }
+
+ void initialize(TPanel *panel) override { assert(0); }
+
+} FxBrowserFactory;
+
+//=============================================================================
+OpenFloatingPanel openFxBrowserCommand(MI_InsertFx, "FxBrowser",
+ QObject::tr("FX Browser"));
diff --git a/toonz/sources/toonz/tpanels.h b/toonz/sources/toonz/tpanels.h
index 352807a2c..437b4b2c9 100644
--- a/toonz/sources/toonz/tpanels.h
+++ b/toonz/sources/toonz/tpanels.h
@@ -32,6 +32,7 @@ class VectorGuidedDrawingPane;
class FxSelection;
class StageObjectSelection;
class LocatorPopup;
+class InsertFxPopup;
//=========================================================
// PaletteViewerPanel
@@ -361,4 +362,17 @@ public:
LocatorPanel(QWidget *parent);
};
+//=========================================================
+// FxBrowserPanel
+//---------------------------------------------------------
+
+class FxBrowserPanel final : public TPanel {
+ Q_OBJECT
+
+ InsertFxPopup *m_fxBrowser;
+
+public:
+ FxBrowserPanel(QWidget *parent);
+};
+
#endif
diff --git a/toonz/sources/toonzlib/fxcommand.cpp b/toonz/sources/toonzlib/fxcommand.cpp
index 72566717c..aecc4c273 100644
--- a/toonz/sources/toonzlib/fxcommand.cpp
+++ b/toonz/sources/toonzlib/fxcommand.cpp
@@ -701,18 +701,22 @@ class InsertFxUndo final : public FxCommandUndo {
int m_colIdx;
bool m_columnReplacesHole;
bool m_attachOutputs;
+ //! When nothing is selected, whether to fall back on the current fx as the
+ //! new fx's input. False means "create the fx unconnected".
+ bool m_attachSource;
public:
InsertFxUndo(const TFxP &fx, int row, int col, const QList<TFxP> &selectedFxs,
QList<TFxCommand::Link> selectedLinks, TApplication *app,
- bool attachOutputs = true)
+ bool attachOutputs = true, bool attachSource = true)
: m_selectedFxs(selectedFxs)
, m_selectedLinks(selectedLinks)
, m_insertedColumn(0)
, m_app(app)
, m_colIdx(col)
, m_columnReplacesHole(false)
- , m_attachOutputs(attachOutputs) {
+ , m_attachOutputs(attachOutputs)
+ , m_attachSource(attachSource) {
initialize(fx, row, col);
}
@@ -765,6 +769,8 @@ void InsertFxUndo::initialize(const TFxP &newFx, int row, int col) {
TZeraryFx *zfx = dynamic_cast<TZeraryFx *>(fx);
if (has_fx_column(fx)) {
m_insertedColumn = InsertFxUndo::createZeraryFxColumn(xsh, fx, row);
+ m_insertedColumn->getZeraryColumnFx()->getAttributes()->setDagNodePos(
+ fx->getAttributes()->getDagNodePos());
locals.storeFx(xsh, fx);
@@ -772,8 +778,9 @@ void InsertFxUndo::initialize(const TFxP &newFx, int row, int col) {
m_columnReplacesHole = true;
} else {
if (m_selectedFxs.isEmpty() && m_selectedLinks.isEmpty()) {
- // Attempt retrieval of current Fx from the fxHandle
- if (TFx *currentFx = m_app->getCurrentFx()->getFx())
+ TFx *currentFx =
+ m_attachSource ? m_app->getCurrentFx()->getFx() : nullptr;
+ if (currentFx)
m_selectedFxs.push_back(currentFx);
else {
// Isolated case
@@ -936,11 +943,12 @@ void TFxCommand::insertFx(TFx *newFx, const QList<TFxP> &fxs,
//**********************************************************************
void TFxCommand::addFx(TFx *newFx, const QList<TFxP> &fxs, TApplication *app,
- int col, int row) {
+ int col, int row, bool attachSource) {
if (!newFx) return;
+ if (col < 0) col = 0;
- std::unique_ptr<FxCommandUndo> undo(
- new InsertFxUndo(newFx, row, col, fxs, QList<Link>(), app, false));
+ std::unique_ptr<FxCommandUndo> undo(new InsertFxUndo(
+ newFx, row, col, fxs, QList<Link>(), app, false, attachSource));
if (!undo->isConsistent()) return;
undo->redo();
diff --git a/toonz/sources/toonzqt/CMakeLists.txt b/toonz/sources/toonzqt/CMakeLists.txt
index c5289632e..0b1173a7d 100644
--- a/toonz/sources/toonzqt/CMakeLists.txt
+++ b/toonz/sources/toonzqt/CMakeLists.txt
@@ -39,6 +39,7 @@ set(MOC_HEADERS
../include/toonzqt/icongenerator.h
../include/toonzqt/imageutils.h
../include/toonzqt/infoviewer.h
+ ../include/toonzqt/insertfxpopup.h
../include/toonzqt/intfield.h
../include/toonzqt/intpairfield.h
../include/toonzqt/keyframenavigator.h
@@ -196,6 +197,7 @@ set(SOURCES
stylenameeditor.cpp
combohistogram.cpp
fxiconmanager.cpp
+ insertfxpopup.cpp
pluginhost.cpp
plugin_tile_interface.cpp
plugin_port_interface.cpp
diff --git a/toonz/sources/toonzqt/fxschematicscene.cpp b/toonz/sources/toonzqt/fxschematicscene.cpp
index 58754098e..0fd639496 100644
--- a/toonz/sources/toonzqt/fxschematicscene.cpp
+++ b/toonz/sources/toonzqt/fxschematicscene.cpp
@@ -21,7 +21,6 @@
#include "toonz/tcolumnfx.h"
#include "toonz/txshpalettecolumn.h"
#include "toonz/txshzeraryfxcolumn.h"
-#include "toonz/fxcommand.h"
#include "toonz/txsheethandle.h"
#include "toonz/tfxhandle.h"
#include "toonz/tscenehandle.h"
@@ -44,6 +43,8 @@
#include <QMenu>
#include <QApplication>
#include <QGraphicsSceneContextMenuEvent>
+#include <QGraphicsSceneDragDropEvent>
+#include <QMimeData>
#include <QStack>
TEnv::IntVar IconifyFxSchematicNodes("IconifyFxSchematicNodes", 0);
@@ -323,7 +324,10 @@ FxSchematicScene::FxSchematicScene(QWidget *parent)
, m_currentFxNode(0)
, m_gridDimension(eSmall)
, m_isNormalIconView(!IconifyFxSchematicNodes)
- , m_viewer() {
+ , m_viewer()
+ , m_dragDropAction(DragDropAction::None)
+ , m_litLink(0)
+ , m_litNode(0) {
m_viewer = (SchematicViewer *)parent;
m_selection = new FxSelection();
@@ -374,6 +378,7 @@ void FxSchematicScene::updateScene() {
m_connectionLinks.clearAll();
m_selectionOldPos.clear();
+ clearDropHighlights();
clearSelection();
clearAllItems();
@@ -1762,6 +1767,154 @@ bool FxSchematicScene::event(QEvent *e) {
//------------------------------------------------------------------
+void FxSchematicScene::clearDropHighlights() {
+ m_dragDropAction = DragDropAction::None;
+ m_dropFxs.clear();
+ m_dropLinks.clear();
+ if (m_litLink) {
+ m_litLink->setDropHighlighted(false);
+ m_litLink->update();
+ m_litLink = 0;
+ }
+ if (m_litNode) {
+ m_litNode->setDropHighlighted(false);
+ m_litNode->update();
+ m_litNode = 0;
+ }
+}
+
+//------------------------------------------------------------------
+
+void FxSchematicScene::dragEnterEvent(QGraphicsSceneDragDropEvent *e) {
+ clearDropHighlights();
+ m_dragFx = TFxP();
+ const FxsData *fxData = dynamic_cast<const FxsData *>(e->mimeData());
+ if (!fxData || !m_app || !(e->possibleActions() & Qt::CopyAction)) {
+ e->ignore();
+ return;
+ }
+
+ QList<TFxP> fxs;
+ QMap<TFx *, int> columnSizes;
+ QList<TXshColumnP> columns;
+ fxData->getFxs(fxs, columnSizes, columns);
+ if (fxs.size() != 1 || !columns.isEmpty()) {
+ e->ignore();
+ return;
+ }
+ m_dragFx = fxs.front();
+ e->setDropAction(Qt::CopyAction);
+ e->accept();
+}
+
+//------------------------------------------------------------------
+
+void FxSchematicScene::dragMoveEvent(QGraphicsSceneDragDropEvent *e) {
+ clearDropHighlights();
+ if (!m_dragFx || !dynamic_cast<const FxsData *>(e->mimeData())) {
+ e->ignore();
+ return;
+ }
+
+ TXsheet *xsh = m_xshHandle->getXsheet();
+ auto editableFx = [xsh](TFx *fx) {
+ return fx &&
+ (dynamic_cast<TColumnFx *>(fx) || dynamic_cast<TXsheetFx *>(fx) ||
+ dynamic_cast<TOutputFx *>(fx) ||
+ xsh->getFxDag()->getInternalFxs()->containsFx(fx));
+ };
+
+ QGraphicsItem *item = itemAt(e->scenePos(), QTransform());
+ FxSchematicLink *link = dynamic_cast<FxSchematicLink *>(item);
+ if (!item) {
+ m_dragDropAction = DragDropAction::Add;
+ } else if (link) {
+ if (link->isLineShaped() || m_dragFx->getInputPortCount() == 0) {
+ e->ignore();
+ return;
+ }
+ // Collapsed groups can represent several different connections.
+ if (!link->getStartPort() || !link->getEndPort() ||
+ dynamic_cast<FxGroupNode *>(link->getStartPort()->getNode()) ||
+ dynamic_cast<FxGroupNode *>(link->getEndPort()->getNode())) {
+ e->ignore();
+ return;
+ }
+ TFxCommand::Link bounds = m_selection->getBoundingFxs(link);
+ if (!editableFx(bounds.m_inputFx.getPointer()) ||
+ !editableFx(bounds.m_outputFx.getPointer())) {
+ e->ignore();
+ return;
+ }
+ m_dropLinks.append(bounds);
+ m_dragDropAction = DragDropAction::Insert;
+ link->setDropHighlighted(true);
+ link->update();
+ m_litLink = link;
+ } else {
+ FxSchematicNode *node = nullptr;
+ for (; item && !node; item = item->parentItem())
+ node = dynamic_cast<FxSchematicNode *>(item);
+ TFx *fx = node ? node->getFx() : nullptr;
+ if (!editableFx(fx) || dynamic_cast<FxGroupNode *>(node) ||
+ dynamic_cast<TXsheetFx *>(fx) || dynamic_cast<TOutputFx *>(fx) ||
+ (dynamic_cast<TColumnFx *>(fx) &&
+ !dynamic_cast<TZeraryColumnFx *>(fx))) {
+ e->ignore();
+ return;
+ }
+ m_dropFxs.append(fx);
+ m_dragDropAction = DragDropAction::Replace;
+ node->setDropHighlighted(true);
+ node->update();
+ m_litNode = node;
+ }
+
+ e->setDropAction(Qt::CopyAction);
+ e->accept();
+}
+
+//------------------------------------------------------------------
+
+void FxSchematicScene::dropEvent(QGraphicsSceneDragDropEvent *e) {
+ // Resolve the final position, including after a schematic rebuild.
+ dragMoveEvent(e);
+ TFxP dropFx = m_dragFx;
+ const DragDropAction action = m_dragDropAction;
+ const QList<TFxP> fxs = m_dropFxs;
+ const QList<TFxCommand::Link> links = m_dropLinks;
+ // Commands notify the scene synchronously and delete its graphics items.
+ clearDropHighlights();
+ m_dragFx = TFxP();
+ if (action == DragDropAction::None) return;
+
+ if (action == DragDropAction::Replace) {
+ TFxCommand::replaceFx(dropFx.getPointer(), fxs, m_xshHandle, m_fxHandle);
+ } else {
+ dropFx->getAttributes()->setDagNodePos(
+ TPointD(e->scenePos().x(), e->scenePos().y()));
+ const int col = m_columnHandle->getColumnIndex();
+ const int row = m_frameHandle->getFrameIndex();
+ if (action == DragDropAction::Insert)
+ TFxCommand::insertFx(dropFx.getPointer(), fxs, links, m_app, col, row);
+ else
+ TFxCommand::addFx(dropFx.getPointer(), QList<TFxP>(), m_app, col, row,
+ false);
+ }
+ e->setDropAction(Qt::CopyAction);
+ e->accept();
+}
+
+//------------------------------------------------------------------
+
+void FxSchematicScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *e) {
+ clearDropHighlights();
+ m_dragFx = TFxP();
+ e->accept();
+}
+
+//------------------------------------------------------------------
+
void FxSchematicScene::onInsertPaste() {
if (!m_selection->insertPasteSelection())
DVGui::error(
diff --git a/toonz/sources/toonz/insertfxpopup.cpp b/toonz/sources/toonzqt/insertfxpopup.cpp
similarity index 72%
rename from toonz/sources/toonz/insertfxpopup.cpp
rename to toonz/sources/toonzqt/insertfxpopup.cpp
index 2e0416c24..31fe5555f 100644
--- a/toonz/sources/toonz/insertfxpopup.cpp
+++ b/toonz/sources/toonzqt/insertfxpopup.cpp
@@ -1,10 +1,6 @@
-#include "insertfxpopup.h"
-
-// Tnz6 includes
-#include "menubarcommandids.h"
-#include "tapp.h"
+#include "toonzqt/insertfxpopup.h"
// TnzQt includes
#include "toonzqt/menubarcommand.h"
@@ -12,6 +8,7 @@
#include "toonzqt/fxselection.h"
#include "toonzqt/tselectionhandle.h"
#include "toonzqt/pluginloader.h" // inter-module plugin loader accessor
+#include "fxdata.h"
// TnzLib includes
#include "toonz/tscenehandle.h"
@@ -53,6 +50,12 @@
#include <QMainWindow>
#include <QLineEdit>
#include <QLabel>
+#include <QVBoxLayout>
+#include <QMimeData>
+#include <QDrag>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QApplication>
#include <memory>
@@ -90,7 +93,7 @@ TFx *createPresetFxByName(TFilePath path) {
//-----------------------------------------------------------------------------
// same as createMacroFxByPath() in addfxcontextmenu.cpp
-TFx *createMacroFxByPath(TFilePath path) {
+TFx *createMacroFxByPath(TFilePath path, TApplication *app) {
try {
TIStream is(path);
TPersist *p = 0;
@@ -99,7 +102,6 @@ TFx *createMacroFxByPath(TFilePath path) {
if (!fx) return 0;
fx->setName(path.getWideName());
// Assign a unic ID to each fx in the macro!
- TApp *app = TApp::instance();
TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
if (!xsh) return fx;
FxDag *fxDag = xsh->getFxDag();
@@ -142,6 +144,88 @@ TFx *createMacroFxByPath(TFilePath path) {
// FxTree
//=============================================================================
+//-----------------------------------------------------------------------------
+
+void FxTree::startFxDrag(QTreeWidgetItem *item) {
+ if (!item) return;
+
+ QString itemRole = item->data(0, Qt::UserRole).toString();
+ QString dragText = item->text(0);
+ if (itemRole.isEmpty() ||
+ TFileStatus(TFilePath(itemRole.toStdWString())).isDirectory())
+ return;
+
+ InsertFxPopup *popup = dynamic_cast<InsertFxPopup *>(parentWidget());
+ if (!popup) return;
+
+ TFx *fx = popup->createFx();
+ if (!fx) return;
+
+ // FxsData is the mime type the Fx schematic already understands
+ FxsData *fxData = new FxsData();
+ QList<TFxP> fxList;
+ fxList.append(fx);
+ fxData->setFxs(fxList, QList<TFxCommand::Link>(), QList<int>(), 0);
+
+ QFontMetrics fm(QApplication::font());
+ QRect textRect = fm.boundingRect(dragText).adjusted(-2, -2, 2, 2);
+ qreal dpr = devicePixelRatioF();
+ QPixmap pix(textRect.size() * dpr);
+ pix.setDevicePixelRatio(dpr);
+ pix.fill(Qt::transparent);
+ {
+ QPainter painter(&pix);
+ painter.fillRect(QRect(QPoint(0, 0), textRect.size()), Qt::white);
+ painter.setPen(Qt::black);
+ painter.drawText(QRect(QPoint(0, 0), textRect.size()), Qt::AlignCenter,
+ dragText);
+ }
+
+ // QDrag takes ownership of the mime data, which owns the Fx reference
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(fxData);
+ drag->setPixmap(pix);
+ drag->exec(Qt::CopyAction);
+}
+
+//-----------------------------------------------------------------------------
+
+void FxTree::mousePressEvent(QMouseEvent *event) {
+ m_maybeDragging = false;
+
+ QTreeWidgetItem *item = itemAt(event->pos());
+ if (item && event->button() == Qt::LeftButton) {
+ setCurrentItem(item);
+ m_dragStartPos = event->pos();
+ m_maybeDragging = true;
+ }
+
+ QTreeWidget::mousePressEvent(event);
+}
+
+//-----------------------------------------------------------------------------
+
+void FxTree::mouseMoveEvent(QMouseEvent *event) {
+ if (m_maybeDragging && (event->buttons() & Qt::LeftButton) &&
+ (event->pos() - m_dragStartPos).manhattanLength() >=
+ QApplication::startDragDistance()) {
+ m_maybeDragging = false;
+ startFxDrag(currentItem());
+ return;
+ }
+
+ QTreeWidget::mouseMoveEvent(event);
+}
+
+//-----------------------------------------------------------------------------
+
+void FxTree::mouseReleaseEvent(QMouseEvent *event) {
+ m_maybeDragging = false;
+ QTreeWidget::mouseReleaseEvent(event);
+}
+
+//-----------------------------------------------------------------------------
+
void FxTree::displayAll(QTreeWidgetItem *item) {
int childCount = item->childCount();
for (int i = 0; i < childCount; ++i) {
@@ -202,23 +286,21 @@ void FxTree::searchItems(const QString &searchWord) {
//=============================================================================
/*! \class InsertFxPopup
- \brief The InsertFxPopup class provides a dialog to browse fx
- and add it to
- current scene.
+ \brief The InsertFxPopup class provides a pane to browse fx and
+ add them to the current scene, either through its buttons or by dragging
+ them onto the Fx schematic.
- Inherits \b Dialog.
+ Inherits \b QFrame.
*/
-InsertFxPopup::InsertFxPopup()
- : Dialog(TApp::instance()->getMainWindow(), true, false, "InsertFx")
+InsertFxPopup::InsertFxPopup(QWidget *parent, Qt::WindowFlags flags)
+ : QFrame(parent, flags)
, m_folderIcon(QIcon())
, m_presetIcon(QIcon())
- , m_fxIcon(QIcon()) {
- setWindowTitle(tr("FX Browser"));
-
- setModal(false);
-
- setTopMargin(0);
- setTopSpacing(0);
+ , m_fxIcon(QIcon())
+ , m_app(nullptr) {
+ QVBoxLayout *browserLay = new QVBoxLayout();
+ browserLay->setContentsMargins(0, 0, 0, 0);
+ browserLay->setSpacing(0);
QHBoxLayout *searchLay = new QHBoxLayout();
QLineEdit *searchEdit = new QLineEdit(this);
@@ -227,11 +309,11 @@ InsertFxPopup::InsertFxPopup()
searchLay->setSpacing(5);
searchLay->addWidget(new QLabel(tr("Search:"), this), 0);
searchLay->addWidget(searchEdit);
- addLayout(searchLay);
+ browserLay->addLayout(searchLay);
connect(searchEdit, SIGNAL(textChanged(const QString &)), this,
SLOT(onSearchTextChanged(const QString &)));
- m_fxTree = new FxTree();
+ m_fxTree = new FxTree(this);
m_fxTree->setIconSize(QSize(18, 18));
m_fxTree->setColumnCount(1);
m_fxTree->header()->close();
@@ -273,31 +355,60 @@ InsertFxPopup::InsertFxPopup()
connect(m_fxTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
SLOT(onItemDoubleClicked(QTreeWidgetItem *, int)));
- addWidget(m_fxTree);
+ browserLay->addWidget(m_fxTree);
+
+ QHBoxLayout *buttonLay = new QHBoxLayout();
+ buttonLay->setContentsMargins(0, 3, 0, 3);
+ buttonLay->setSpacing(5);
+ buttonLay->setAlignment(Qt::AlignHCenter);
QPushButton *insertBtn = new QPushButton(tr("Insert"), this);
- insertBtn->setMinimumSize(90, 25);
+ insertBtn->setMinimumSize(65, 25);
insertBtn->setObjectName("PushButton_NoPadding");
connect(insertBtn, SIGNAL(clicked()), this, SLOT(onInsert()));
insertBtn->setDefault(true);
- m_buttonLayout->addWidget(insertBtn);
+ buttonLay->addWidget(insertBtn);
QPushButton *addBtn = new QPushButton(tr("Add"), this);
- addBtn->setMinimumSize(90, 25);
+ addBtn->setMinimumSize(65, 25);
addBtn->setObjectName("PushButton_NoPadding");
connect(addBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
- m_buttonLayout->addWidget(addBtn);
+ buttonLay->addWidget(addBtn);
QPushButton *replaceBtn = new QPushButton(tr("Replace"), this);
- replaceBtn->setMinimumSize(90, 25);
+ replaceBtn->setMinimumSize(65, 25);
replaceBtn->setObjectName("PushButton_NoPadding");
connect(replaceBtn, SIGNAL(clicked()), this, SLOT(onReplace()));
- m_buttonLayout->addWidget(replaceBtn);
+ buttonLay->addWidget(replaceBtn);
+
+ browserLay->addLayout(buttonLay);
+
+ setLayout(browserLay);
+
+ updatePresets();
+}
+
+//-------------------------------------------------------------------
+
+InsertFxPopup::~InsertFxPopup() {}
+
+//-------------------------------------------------------------------
+
+void InsertFxPopup::setApplication(TApplication *app) {
+ if (m_app) disconnect(m_app->getCurrentFx(), nullptr, this, nullptr);
+ m_app = app;
+ if (!m_app) return;
+
+ connect(m_app->getCurrentFx(), SIGNAL(fxPresetSaved()), this,
+ SLOT(updatePresets()));
+ connect(m_app->getCurrentFx(), SIGNAL(fxPresetRemoved()), this,
+ SLOT(updatePresets()));
}
//-------------------------------------------------------------------
void InsertFxPopup::onSearchTextChanged(const QString &text) {
+ m_searchText = text;
static bool busy = false;
if (busy) return;
busy = true;
@@ -377,8 +488,7 @@ bool InsertFxPopup::loadPreset(QTreeWidgetItem *item) {
QString str = item->data(0, Qt::UserRole).toString();
TFilePath presetsFilepath(m_presetFolder + str.toStdWString());
int i;
- for (i = item->childCount() - 1; i >= 0; i--)
- item->removeChild(item->child(i));
+ for (i = item->childCount() - 1; i >= 0; i--) delete item->takeChild(i);
if (TFileStatus(presetsFilepath).isDirectory()) {
TFilePathSet presets = TSystem::readDirectory(presetsFilepath);
if (!presets.empty()) {
@@ -432,28 +542,40 @@ void InsertFxPopup::loadMacro() {
//-----------------------------------------------------------------------------
void InsertFxPopup::onItemDoubleClicked(QTreeWidgetItem *w, int c) {
- if (w->childCount() == 0) // E' una foglia
+ if (w->childCount() != 0 || !m_app) return; // E' una foglia
+
+ FxSelection *selection =
+ dynamic_cast<FxSelection *>(m_app->getCurrentSelection()->getSelection());
+ if (selection &&
+ (!selection->getFxs().isEmpty() || !selection->getLinks().isEmpty()))
onInsert();
+ else {
+ TFxP fx = createFx();
+ TFxCommand::addFx(fx.getPointer(), QList<TFxP>(), m_app,
+ m_app->getCurrentColumn()->getColumnIndex(),
+ m_app->getCurrentFrame()->getFrameIndex(), false);
+ }
}
//-----------------------------------------------------------------------------
void InsertFxPopup::onInsert() {
+ if (!m_app) return;
+
TFx *fx = createFx();
if (fx) {
- TApp *app = TApp::instance();
- TXsheetHandle *xshHandle = app->getCurrentXsheet();
+ TXsheetHandle *xshHandle = m_app->getCurrentXsheet();
QList<TFxP> fxs;
QList<TFxCommand::Link> links;
- FxSelection *selection =
- dynamic_cast<FxSelection *>(app->getCurrentSelection()->getSelection());
+ FxSelection *selection = dynamic_cast<FxSelection *>(
+ m_app->getCurrentSelection()->getSelection());
if (selection) {
fxs = selection->getFxs();
links = selection->getLinks();
}
- TFxCommand::insertFx(fx, fxs, links, app,
- app->getCurrentColumn()->getColumnIndex(),
- app->getCurrentFrame()->getFrameIndex());
+ TFxCommand::insertFx(fx, fxs, links, m_app,
+ m_app->getCurrentColumn()->getColumnIndex(),
+ m_app->getCurrentFrame()->getFrameIndex());
xshHandle->notifyXsheetChanged();
}
}
@@ -461,16 +583,18 @@ void InsertFxPopup::onInsert() {
//-----------------------------------------------------------------------------
void InsertFxPopup::onAdd() {
+ if (!m_app) return;
+
TFx *fx = createFx();
if (fx) {
- TApp *app = TApp::instance();
- TXsheetHandle *xshHandle = app->getCurrentXsheet();
+ TXsheetHandle *xshHandle = m_app->getCurrentXsheet();
QList<TFxP> fxs;
- FxSelection *selection =
- dynamic_cast<FxSelection *>(app->getCurrentSelection()->getSelection());
+ FxSelection *selection = dynamic_cast<FxSelection *>(
+ m_app->getCurrentSelection()->getSelection());
if (selection) fxs = selection->getFxs();
- TFxCommand::addFx(fx, fxs, app, app->getCurrentColumn()->getColumnIndex(),
- app->getCurrentFrame()->getFrameIndex());
+ TFxCommand::addFx(fx, fxs, m_app,
+ m_app->getCurrentColumn()->getColumnIndex(),
+ m_app->getCurrentFrame()->getFrameIndex());
xshHandle->notifyXsheetChanged();
}
}
@@ -478,16 +602,17 @@ void InsertFxPopup::onAdd() {
//-----------------------------------------------------------------------------
void InsertFxPopup::onReplace() {
+ if (!m_app) return;
+
TFx *fx = createFx();
if (fx) {
- TApp *app = TApp::instance();
- TXsheetHandle *xshHandle = app->getCurrentXsheet();
+ TXsheetHandle *xshHandle = m_app->getCurrentXsheet();
QList<TFxP> fxs;
- FxSelection *selection =
- dynamic_cast<FxSelection *>(app->getCurrentSelection()->getSelection());
+ FxSelection *selection = dynamic_cast<FxSelection *>(
+ m_app->getCurrentSelection()->getSelection());
if (selection) fxs = selection->getFxs();
- TFxCommand::replaceFx(fx, fxs, app->getCurrentXsheet(),
- app->getCurrentFx());
+ TFxCommand::replaceFx(fx, fxs, m_app->getCurrentXsheet(),
+ m_app->getCurrentFx());
xshHandle->notifyXsheetChanged();
}
}
@@ -495,9 +620,7 @@ void InsertFxPopup::onReplace() {
//-----------------------------------------------------------------------------
TFx *InsertFxPopup::createFx() {
- TApp *app = TApp::instance();
- ToonzScene *scene = app->getCurrentScene()->getScene();
- TXsheet *xsh = scene->getXsheet();
+ if (!m_app) return 0;
QTreeWidgetItem *item = m_fxTree->currentItem();
if (item == NULL) return 0;
@@ -505,7 +628,7 @@ TFx *InsertFxPopup::createFx() {
QString text = item->data(0, Qt::UserRole).toString();
if (text.isEmpty()) return 0;
- TFx *fx;
+ TFx *fx = 0;
TFilePath path = TFilePath(text.toStdWString());
@@ -513,7 +636,7 @@ TFx *InsertFxPopup::createFx() {
TFileStatus(path.getParentDir()).isDirectory()) {
std::string folder = path.getParentDir().getName();
if (folder == "macroFx") // Devo caricare una macro
- fx = createMacroFxByPath(path);
+ fx = createMacroFxByPath(path, m_app);
else // Verifico se devo caricare un preset
{
folder = path.getParentDir().getParentDir().getName();
@@ -523,33 +646,22 @@ TFx *InsertFxPopup::createFx() {
} else
fx = createFxByName(text.toStdString());
- if (fx)
- return fx;
- else
- return 0;
+ return fx;
}
//-----------------------------------------------------------------------------
-void InsertFxPopup::showEvent(QShowEvent *) {
+void InsertFxPopup::showEvent(QShowEvent *event) {
updatePresets();
- connect(TApp::instance()->getCurrentFx(), SIGNAL(fxPresetSaved()),
- SLOT(updatePresets()));
-}
-
-//-----------------------------------------------------------------------------
-
-void InsertFxPopup::hideEvent(QHideEvent *e) {
- disconnect(TApp::instance()->getCurrentFx(), SIGNAL(fxPresetSaved()), this,
- SLOT(updatePresets()));
- Dialog::hideEvent(e);
+ QFrame::showEvent(event);
}
//-----------------------------------------------------------------------------
void InsertFxPopup::contextMenuEvent(QContextMenuEvent *event) {
QTreeWidgetItem *item = m_fxTree->currentItem();
- QString itemRole = item->data(0, Qt::UserRole).toString();
+ if (!item) return;
+ QString itemRole = item->data(0, Qt::UserRole).toString();
TFilePath path = TFilePath(itemRole.toStdWString());
if (TFileStatus(path).doesExist() &&
@@ -587,11 +699,8 @@ void InsertFxPopup::updatePresets() {
continue;
}
if (path.getName() == "macroFx") {
- int j;
- for (j = folder->childCount() - 1; j >= 0; j--)
- folder->removeChild(folder->child(j));
- m_fxTree->removeItemWidget(folder, 0);
delete folder;
+ --i;
} else if (path.getParentDir().getName() == "macroFx")
continue;
else
@@ -604,6 +713,7 @@ void InsertFxPopup::updatePresets() {
}
}
loadMacro();
+ if (!m_searchText.isEmpty()) m_fxTree->searchItems(m_searchText);
update();
}
@@ -612,7 +722,8 @@ void InsertFxPopup::updatePresets() {
void InsertFxPopup::removePreset() {
QTreeWidgetItem *item = m_fxTree->currentItem();
- QString itemRole = item->data(0, Qt::UserRole).toString();
+ if (!item) return;
+ QString itemRole = item->data(0, Qt::UserRole).toString();
TFilePath path = TFilePath(itemRole.toStdWString());
@@ -629,9 +740,5 @@ void InsertFxPopup::removePreset() {
}
m_fxTree->removeItemWidget(item, 0);
delete item;
- TApp::instance()->getCurrentFx()->notifyFxPresetRemoved();
+ if (m_app) m_app->getCurrentFx()->notifyFxPresetRemoved();
}
-
-//=============================================================================
-
-OpenPopupCommandHandler<InsertFxPopup> openInsertFxPopup(MI_InsertFx);
diff --git a/toonz/sources/toonzqt/schematicnode.cpp b/toonz/sources/toonzqt/schematicnode.cpp
index d77e02619..163ef5757 100644
--- a/toonz/sources/toonzqt/schematicnode.cpp
+++ b/toonz/sources/toonzqt/schematicnode.cpp
@@ -598,7 +598,8 @@ SchematicLink::SchematicLink(QGraphicsItem *parent, QGraphicsScene *scene)
, m_startPort(nullptr)
, m_endPort(nullptr)
, m_lineShaped(false)
- , m_highlighted(false) {
+ , m_highlighted(false)
+ , m_dropHighlighted(false) {
scene->addItem(this);
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemIsSelectable, true);
@@ -648,6 +649,10 @@ void SchematicLink::paint(QPainter *painter,
painter->setPen(QPen(viewer->getMotionPathSelectedLinkColor()));
else
painter->setPen(QColor(viewer->getMotionPathLinkColor()));
+ } else if (isDropHighlighted()) {
+ QPen pen(viewer->getSelectedLinkColor());
+ pen.setWidth(3);
+ painter->setPen(pen);
} else if (isSelected() || isHighlighted()) {
painter->setPen(QPen(viewer->getSelectedLinkColor()));
} else if (!m_lineShaped) {
@@ -1057,7 +1062,8 @@ SchematicNode::SchematicNode(SchematicScene *scene)
, m_scene(scene)
, m_width(0)
, m_height(0)
- , m_buttonState(Qt::NoButton) {
+ , m_buttonState(Qt::NoButton)
+ , m_dropHighlighted(false) {
scene->addItem(this);
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemIsSelectable, true);
@@ -1097,11 +1103,11 @@ void SchematicNode::paint(QPainter *painter,
if (!viewer) return;
QPen pen;
- if (isSelected()) {
+ if (isSelected() || isDropHighlighted()) {
painter->setBrush(QColor(0, 0, 0, 0));
pen.setColor(QColor(viewer->getSelectedBorderColor()));
- pen.setWidth(4.0);
+ pen.setWidth(isDropHighlighted() ? 7.0 : 4.0);
pen.setJoinStyle(Qt::RoundJoin);
painter->setPen(pen);
painter->drawRect(-2, -2, m_width + 4, m_height + 4);