Commit 20552137 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Plugin-DataControl: Allow copy and pasting of materials.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18480 383ad7c9-94d9-4d36-a494-682f7c89f535
parent fd035d1c
......@@ -154,6 +154,14 @@ void DataControlPlugin::pluginsInitialized() {
connect (copyMaterial, SIGNAL( triggered() ), this, SLOT ( slotCopyMaterialToTargeted() ));
emit addContextMenuItem(copyMaterial , DATA_ALL , CONTEXTOBJECTMENU);
QAction* copyMaterialToClipboard = new QAction(tr("Copy Material Properties to Clipboard"), 0);
connect (copyMaterialToClipboard, SIGNAL( triggered() ), this, SLOT ( slotCopyMaterialToClipboard() ));
emit addContextMenuItem(copyMaterialToClipboard , DATA_ALL , CONTEXTOBJECTMENU);
QAction* pasteMaterialFromClipboard = new QAction(tr("Paste Material Properties from Clipboard"), 0);
connect (pasteMaterialFromClipboard, SIGNAL( triggered() ), this, SLOT ( slotPasteMaterialFromClipboard() ));
emit addContextMenuItem(pasteMaterialFromClipboard , DATA_ALL , CONTEXTOBJECTMENU);
PluginFunctions::setDefaultViewObjectMarker (&objectMarker);
PluginFunctions::setViewObjectMarker (&objectMarker);
......
......@@ -234,6 +234,12 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
///Called by the popup menu to copy material properties
void slotCopyMaterialToTargeted();
///Called by the popup menu to copy material properties to clipboard
void slotCopyMaterialToClipboard();
///Called by the popup menu to paste material properties from clipboard
void slotPasteMaterialFromClipboard();
/** \brief Called when the material properties were changed inside the material dialog
*
* @param _node unused
......
......@@ -277,6 +277,8 @@ void DataControlPlugin::slotCustomContextMenuRequested ( const QPoint & _pos ) {
action->setIcon(icon);
menu.addAction(tr("Copy Material Properties to Targeted Objects"), this, SLOT ( slotCopyMaterialToTargeted() ));
menu.addAction(tr("Copy Material Properties to Clipboard"), this, SLOT ( slotCopyMaterialToClipboard() ));
menu.addAction(tr("Paste Material Properties from Clipboard"), this, SLOT ( slotPasteMaterialFromClipboard() ));
menu.addAction(tr("Group"),this,SLOT ( slotGroup() ));
......@@ -481,6 +483,87 @@ void DataControlPlugin::slotCopyMaterialToTargeted() {
}
}
void DataControlPlugin::slotCopyMaterialToClipboard() {
BaseObject* item = 0;
//check if it was called from object contextMenu or from the toolBox
QAction* action = dynamic_cast< QAction* > ( sender() );
if ( action ){
bool ok = false;
int id = action->data().toInt(&ok);
if ( ok && id > 0 )
PluginFunctions::getObject(id,item);
}
if ( item == 0 ){
// the slot was called from toolbox
QItemSelectionModel* selection = view_->selectionModel();
// Get all selected rows
QModelIndexList indexList = selection->selectedRows ( 0 );
int selectedRows = indexList.size();
if (selectedRows == 1){
int id = model_->itemId( indexList[0] );
if ( id > 0 )
PluginFunctions::getObject(id,item);
}
}
if ( item != 0 ){
BaseObjectData* itemData = dynamic_cast< BaseObjectData* > (item);
const ACG::SceneGraph::Material &sourceMaterial = itemData->materialNode()->material();
const QString materialJson = sourceMaterial.serializeToJson();
QApplication::clipboard()->setText(materialJson);
}
}
void DataControlPlugin::slotPasteMaterialFromClipboard() {
BaseObject* item = 0;
//check if it was called from object contextMenu or from the toolBox
QAction* action = dynamic_cast< QAction* > ( sender() );
if ( action ){
bool ok = false;
int id = action->data().toInt(&ok);
if ( ok && id > 0 )
PluginFunctions::getObject(id,item);
}
if ( item == 0 ){
// the slot was called from toolbox
QItemSelectionModel* selection = view_->selectionModel();
// Get all selected rows
QModelIndexList indexList = selection->selectedRows ( 0 );
int selectedRows = indexList.size();
if (selectedRows == 1){
int id = model_->itemId( indexList[0] );
if ( id > 0 )
PluginFunctions::getObject(id,item);
}
}
if ( item != 0 ){
BaseObjectData* itemData = dynamic_cast< BaseObjectData* > (item);
ACG::SceneGraph::Material &destMaterial = itemData->materialNode()->material();
destMaterial.deserializeFromJson(QApplication::clipboard()->text());
emit updateView();
}
}
void DataControlPlugin::slotMaterialProperties(){
BaseObject* item = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment