Skip to content

Commit

Permalink
Updated drag and drop from the texture tree, texture thumbs and clipb…
Browse files Browse the repository at this point in the history
…oard.

This also solves issue #13 (#13)
  • Loading branch information
spookyboo committed Apr 25, 2017
1 parent 8e831c8 commit 36a4c46
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 53 deletions.
6 changes: 2 additions & 4 deletions framework/header/node_editorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace Magus
void contextMenuItemSelected(QAction* action);

// Activated when something was dropped
void handleDropped (unsigned int type, const QString& name);
void handleDropped (const QString& objectName, const QString& name);

signals:
// Emitted when a node is added to the node editor
Expand All @@ -169,9 +169,7 @@ namespace Magus
void selectedNodesToBeAddedToCompound(void);

// Emitted when something is dropped
// type = 0 ==> it was a texture; name is not filled
// type = 1 ==> it was a samplerblock from the clipboard; name is filename json clip
void dropped (unsigned int type, const QString& name);
void dropped (const QString& objectName, const QString& name);

// Emitted when a user wants to copy the last selected node to a clipboard (which is handled outside of the editor)
void copiedToClipboard(QtNode*);
Expand Down
10 changes: 5 additions & 5 deletions framework/header/node_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ namespace Magus

signals:
// Emitted when something is dropped
void dropped(unsigned int type, const QString& name);
// ObjectName is the class name of the object
// name is the identifier of the object, for example a filename
void dropped(const QString& objectName, const QString& name);

protected:
virtual void dropEvent(QDropEvent* event)
{
QString name = event->mimeData()->text();
if (name == "")
emit dropped (0, name); // 0 = texture
else
emit dropped (1, name); // 1 = samplerblock from clipboard
QString objectName = event->mimeData()->objectName();
emit dropped (objectName, name);
event->acceptProposedAction();
}

Expand Down
1 change: 1 addition & 0 deletions framework/header/tool_default_texturewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Magus
const QSize& size,
QWidget* parent = 0);
virtual ~QtDefaultTextureAndText(void);
virtual void mouseMoveEvent(QMouseEvent *event);

// Returns the pixmap
const QPixmap* getPixmap (void);
Expand Down
6 changes: 5 additions & 1 deletion framework/header/tool_resourcetree_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ namespace Magus
int getSelectedResource (void);
QTreeWidgetItem* getSelectedResourceItem (void);

// Return the dragged resource (name)
const QString& getDraggedFullQualifiedResourceName (void);

// Return the first resource of a parent. If resourceId == 0, the first top-level resource is returned
int getFirstInParent (int parentId);

Expand Down Expand Up @@ -461,8 +464,8 @@ namespace Magus
QAction* getContextMenuAction(const QString& menuItemText);
void mouseClickHandler(QMouseEvent* event);
void mouseDoubleClickHandler(QMouseEvent* event);
void dragMoveHandler(QObject* object, QEvent* event);
void dropHandler(QObject* object, QEvent* event);
void mouseMoveHandler(QMouseEvent* event);
void resetSearch(void);
void findAndShowItems(const QString& searchPattern);
void hideParentIfChildrenAreHidden(int parentId);
Expand Down Expand Up @@ -507,6 +510,7 @@ namespace Magus
bool mCollapsed;
int assetIconWidth;
int assetIconHeight;
QString mDraggedResourceName; // Contains the resource that is dragged
};
}

Expand Down
6 changes: 3 additions & 3 deletions framework/src/node_editorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Magus
{
QVBoxLayout* mainLayout = new QVBoxLayout;
mView = new QtNodeGraphicsView(this);
connect(mView, SIGNAL(dropped(uint,QString)), this, SLOT(handleDropped(uint,QString))); // Check if something is dropped
connect(mView, SIGNAL(dropped(QString,QString)), this, SLOT(handleDropped(QString,QString))); // Check if something is dropped

QRect rcontent = mView->contentsRect();
//mView->setSceneRect(0, 0, rcontent.width() + 500, rcontent.height() + 500); // Prevent unwanted jumping and scrollbars
Expand Down Expand Up @@ -1467,9 +1467,9 @@ namespace Magus
}

//****************************************************************************/
void QtNodeEditor::handleDropped (unsigned int type, const QString& name)
void QtNodeEditor::handleDropped (const QString& objectName, const QString& name)
{
emit dropped(type, name);
emit dropped(objectName, name);
}

//****************************************************************************/
Expand Down
18 changes: 18 additions & 0 deletions framework/src/tool_default_texturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <QDropEvent>
#include <QProcess>
#include <QApplication>
#include <QDrag>
#include <QMimeData>
#include "magus_core.h"
#include "tool_default_texturewidget.h"

Expand Down Expand Up @@ -72,6 +74,22 @@ namespace Magus
{
}

//****************************************************************************/
void QtDefaultTextureAndText::mouseMoveEvent(QMouseEvent *event)
{
// If not left button - return
if (!(event->buttons() & Qt::LeftButton))
return;

// Start drag
QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData;
mimeData->setText(mName);
mimeData->setObjectName("QtDefaultTextureAndText");
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction | Qt::MoveAction);
}

//****************************************************************************/
const QPixmap* QtDefaultTextureAndText::getPixmap (void)
{
Expand Down
4 changes: 2 additions & 2 deletions framework/src/tool_generic_assetwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <QProcess>
#include <QDrag>
#include <QMimeData>

#include "tool_generic_assetwidget.h"

namespace Magus
Expand Down Expand Up @@ -84,8 +83,9 @@ namespace Magus
// Start drag
QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData;
drag->setMimeData(mimeData);
mimeData->setText(mName);
mimeData->setObjectName("QtGenericAssetAndText");
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction | Qt::MoveAction);
}

Expand Down
29 changes: 27 additions & 2 deletions framework/src/tool_resourcetree_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
#include <QImage>
#include <QPixmap>
#include <QTreeWidgetItem>
#include <QDrag>
#include <QMimeData>
#include "tool_resourcetree_widget.h"
#include "OgreLogManager.h"

namespace Magus
{
//****************************************************************************/
QtResourceTreeWidget::QtResourceTreeWidget(const QString& iconDir, QWidget* parent) : QWidget(parent)
{
mDraggedResourceName = "";
assetIconWidth = TOOL_RESOURCETREE_DEFAULT_ICON_WIDTH;
assetIconHeight = TOOL_RESOURCETREE_DEFAULT_ICON_HEIGHT;
mActionCreateToplevelGroupText = TOOL_RESOURCETREE_ACTION_CREATE_TOPLEVEL_GROUP;
Expand Down Expand Up @@ -166,7 +169,11 @@ namespace Magus
mouseDoubleClickHandler(mouseEvent);
break;

case QEvent::Drop:
case QEvent::MouseMove:
mouseMoveHandler(mouseEvent);
break;

case QEvent::Drop:
dropHandler(object, event);
break;
}
Expand Down Expand Up @@ -290,7 +297,7 @@ namespace Magus
}

//****************************************************************************/
void QtResourceTreeWidget::dropHandler(QObject* object, QEvent* event)
void QtResourceTreeWidget::dropHandler (QObject* object, QEvent* event)
{
event->accept();

Expand Down Expand Up @@ -338,6 +345,24 @@ namespace Magus
QMessageBox::information(0, "Warning", TOOL_RESOURCETREE_WARNING_4);
}

//****************************************************************************/
void QtResourceTreeWidget::mouseMoveHandler (QMouseEvent* event)
{
// If not left button - return
if (!(event->buttons() & Qt::LeftButton))
return;

// This is the dragged item; store it in mDraggedResourceName, otherwise it cannot be determined later on
QTreeWidgetItem* item = mResourceTree->currentItem();
mDraggedResourceName = getFullQualifiedNameFromItem(item);
}

//****************************************************************************/
const QString& QtResourceTreeWidget::getDraggedFullQualifiedResourceName(void)
{
return mDraggedResourceName;
}

//****************************************************************************/
void QtResourceTreeWidget::registerResource (int resourceId,
const QString& resourceName,
Expand Down
2 changes: 1 addition & 1 deletion source/header/nodeeditor_dockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class NodeEditorDockWidget : public QDockWidget

// Additional slots
void nodeToBeDeleted(QtNode* node);
void handleDropped (unsigned int type, const QString& name);
void handleDropped (const QString& objectName, const QString& name);
void handleCopiedToClipboard (QtNode* node);

private:
Expand Down
2 changes: 1 addition & 1 deletion source/header/texture_dockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TextureDockWidget : public QDockWidget
void addTextureFile (const QString& fileName);
void addTextureFile (const QString& fileName, const QString& group);
void deleteTexture (const QString& fileName);
const QString& getCurrentFileName (void);
const QString& getDraggedFileName (void);
const QPixmap* getCurrentPixmap (void);

// Empty the texture browser
Expand Down
2 changes: 1 addition & 1 deletion source/header/texture_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TextureMain : public QMainWindow
void addTextureFile (const QString& fileName);
void addTextureFile (const QString& fileName, const QString& group);
void deleteTexture (const QString& fileName);
const QString& getCurrentFileName (void);
const QString& getDraggedFileName (void);
const QPixmap* getCurrentPixmap (void);

// Empty the texture browser
Expand Down
5 changes: 4 additions & 1 deletion source/header/texture_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ class TextureTreeDockWidget : public QDockWidget
bool isResourceExisting(const QString& fileName);

void expand (int resourceId);
const QString& getCurrentFileName (void);
const QString& getDraggedFileName (void);
const QString& getCurrentThumb (void);
const QString& setSelectAssetQuiet(const QString& fileName); // This differs from the one in material_tree.h
int getResourceId(const QString& fileName);

// Get the selected resource
const QString& getCurrentResourceName (void);

// Clear all content in the resourcetree
void clearContent(void);

Expand Down
27 changes: 17 additions & 10 deletions source/src/nodeeditor_dockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ NodeEditorDockWidget::NodeEditorDockWidget(QString title, MainWindow* parent, Qt
connect(mNodeEditor, SIGNAL(nodeToBeRemoved(QtNode*)), this, SLOT(nodeToBeDeleted(QtNode*)));
connect(mNodeEditor, SIGNAL(nodeSelected(QtNode*)), this, SLOT(nodeSelected(QtNode*)));
connect(mNodeEditor, SIGNAL(nodeConnected(QtNode*,QtNode*)), this, SLOT(nodeConnected(QtNode*,QtNode*)));
connect(mNodeEditor, SIGNAL(dropped(uint,QString)), this, SLOT(handleDropped(uint,QString)));
connect(mNodeEditor, SIGNAL(dropped(QString,QString)), this, SLOT(handleDropped(QString,QString)));
connect(mNodeEditor, SIGNAL(copiedToClipboard(QtNode*)), this, SLOT(handleCopiedToClipboard(QtNode*)));
mInnerMain->setCentralWidget(mNodeEditor);
mHlmsPbsDatablockNode = 0;
Expand Down Expand Up @@ -577,17 +577,29 @@ EditorHlmsTypes NodeEditorDockWidget::getCurrentDatablockType(void)
}

//****************************************************************************/
void NodeEditorDockWidget::handleDropped (unsigned int type, const QString& name)
void NodeEditorDockWidget::handleDropped (const QString& objectName, const QString& name)
{
// Something was dropped on the node editor. This must be either the texture thumb, an item from the texture tree
// or something from the clipboard.
// In case of a texture: Use the currently selected item in the tree and create a texture/sampler node
// In case of a texture from the texture tree: Use the dragged item filename in the tree and create a texture/sampler node
// In case of a texture from the texture thumbs: Use the name from the mimedata and create a texture/sampler node
// In case of asset from the clipboard: Use the name from the mimedata and create a texture/sampler node
// nB: When a file from the file explorer is dropped, this function will not take that into account
// It currently assumes that it came from the texture tree-, thumbs widget or clipboard
if (type == 0)
if (objectName == "QtGenericAssetAndText")
{
// It was something from the clipboard; assume it was a samplerblock clip
mParent->useFromClipboard(name);
}
else
{
// It is a texture
QString fileName = mParent->mTextureDockWidget->getCurrentFileName();
QString fileName;
if (objectName == "QtDefaultTextureAndText")
fileName = name;
else
fileName = mParent->mTextureDockWidget->getDraggedFileName();

if (Magus::fileExist(fileName))
{
HlmsNodeSamplerblock* samplerNode = doNewSamplerblockAction();
Expand All @@ -612,11 +624,6 @@ void NodeEditorDockWidget::handleDropped (unsigned int type, const QString& name
}
}
}
else if (type == 1)
{
// It was something from the clipboard; assume it was a samplerblock clip
mParent->useFromClipboard(name);
}

// Rebuid the datablock again
generateDatablock();
Expand Down
4 changes: 2 additions & 2 deletions source/src/texture_dockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ void TextureDockWidget::deleteTexture (const QString& fileName)
}

//****************************************************************************/
const QString& TextureDockWidget::getCurrentFileName (void)
const QString& TextureDockWidget::getDraggedFileName (void)
{
return mTextureMain->getCurrentFileName();
return mTextureMain->getDraggedFileName();
}

//****************************************************************************/
Expand Down
6 changes: 3 additions & 3 deletions source/src/texture_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void TextureMain::handleTextureSelected(int toplevelId,
mTextureThumbsDockWidget->filter(names); // Also resets the filter

// Set the thumb of the selected item in the tree
QString selectedThumb = mTextureTreeDockWidget->getCurrentFileName();
QString selectedThumb = mTextureTreeDockWidget->getCurrentResourceName();
mTextureThumbsDockWidget->setSelectThumb(selectedThumb);
}
}
Expand Down Expand Up @@ -285,9 +285,9 @@ QMessageBox::StandardButton TextureMain::fileDoesNotExistsWarning(const QString&
}

//****************************************************************************/
const QString& TextureMain::getCurrentFileName (void)
const QString& TextureMain::getDraggedFileName (void)
{
return mTextureTreeDockWidget->getCurrentFileName();
return mTextureTreeDockWidget->getDraggedFileName();
}

//****************************************************************************/
Expand Down
26 changes: 9 additions & 17 deletions source/src/texture_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,25 +476,17 @@ void TextureTreeDockWidget::setResources(const QVector<Magus::QtResourceInfo*>&
}

//****************************************************************************/
const QString& TextureTreeDockWidget::getCurrentFileName (void)
const QString& TextureTreeDockWidget::getDraggedFileName (void)
{
mTempString = QString("");
int resourceId = mResourceTreeWidget->getSelectedResource();

QMap<int, QtSourcesInfo>::iterator iter;
QMap<int, QtSourcesInfo>::iterator iterStart = mSourceInfo.begin();
QMap<int, QtSourcesInfo>::iterator iterEnd = mSourceInfo.end();
for (iter = iterStart; iter != iterEnd; ++iter)
{
QtSourcesInfo info = iter.value();
if (resourceId == info.resourceId && info.resourceType == Magus::TOOL_RESOURCETREE_KEY_TYPE_ASSET)
{
// Found it
mTempString = info.fileName;
return mTempString;
}
}
return mResourceTreeWidget->getDraggedFullQualifiedResourceName();
}

//****************************************************************************/
const QString& TextureTreeDockWidget::getCurrentResourceName (void)
{
mTempString = "";
int id = mResourceTreeWidget->getSelectedResource();
mTempString = mResourceTreeWidget->getFullQualifiedName(id);
return mTempString;
}

Expand Down

0 comments on commit 36a4c46

Please sign in to comment.