51 #include "DeserializeScreenshotMetadataPlugin.hh" 56 #include <ACG/Scenegraph/MaterialNode.hh> 57 #include <QMessageBox> 62 DeserializeScreenshotMetadataPlugin::DeserializeScreenshotMetadataPlugin() :
65 restore_from_screenshot_dlg(0) {
68 void DeserializeScreenshotMetadataPlugin::initializePlugin() {
71 void DeserializeScreenshotMetadataPlugin::pluginsInitialized() {
72 toolbar =
new QToolBar(tr(
"Restore from Screenshot"));
74 restoreAction =
new QAction(tr(
"Restore Scene From Screenshot"), toolbar);
75 restoreAction->setIcon(
76 QIcon(OpenFlipper::Options::iconDirStr() +
77 OpenFlipper::Options::dirSeparator() +
78 "restore_from_screenshot.png"));
80 toolbar->addAction(restoreAction);
82 emit addToolbar(toolbar);
84 connect(restoreAction, SIGNAL(triggered(
bool)),
this,
85 SLOT(slot_restore_from_screenshot()));
88 void DeserializeScreenshotMetadataPlugin::slot_do_restore_from_screenshot() {
89 if (!restore_from_screenshot_dlg)
return;
91 const QString restoreFileName =
92 restore_from_screenshot_dlg->getRestoreFileName();
94 QImage img(restoreFileName);
96 QMessageBox::warning(0, tr(
"Unable to load image"),
97 tr(
"Unable to load image. " 98 "Unrecognized format or file not existent."),
106 if (restore_from_screenshot_dlg->restore_viewer_cb->isChecked()) {
107 QString view = img.text(
"View");
108 if (!view.isEmpty()) {
116 if (restore_from_screenshot_dlg->restore_materials_cb->isChecked()) {
117 QString materials_json =
118 QString::fromUtf8(
"{") + img.text(
"Mesh Materials") +
119 QString::fromUtf8(
"}");
120 QVariantMap materials = ACG::json_to_variant_map(materials_json);
122 QMap<QString, ACG::SceneGraph::Material*> objname_to_material;
127 if (!o_it->materialNode())
continue;
129 objname_to_material[o_it->name()] = &o_it->materialNode()->material();
132 for (QVariantMap::const_iterator it = materials.begin();
133 it != materials.end(); ++it) {
135 if (objname_to_material.contains(it.key())) {
136 objname_to_material[it.key()]->deserializeFromVariantMap(
145 if (restore_from_screenshot_dlg->restore_objectmd_cb->isChecked()) {
146 QStringList textKeys = img.textKeys();
147 QVector<QPair<QString, QString> > metadata;
148 metadata.reserve(textKeys.size());
149 for (QStringList::iterator it = textKeys.begin();
150 it != textKeys.end(); ++it) {
151 metadata.push_back(QPair<QString, QString>(*it, img.text(*it)));
153 emit metadataDeserialized(metadata);
158 void DeserializeScreenshotMetadataPlugin::slot_restore_from_screenshot() {
159 if (!restore_from_screenshot_dlg) {
161 connect(restore_from_screenshot_dlg->restore_pb,
164 SLOT(slot_do_restore_from_screenshot()));
166 restore_from_screenshot_dlg->show();
167 restore_from_screenshot_dlg->raise();
170 void DeserializeScreenshotMetadataPlugin::slotGenericMetadataDeserialized(
171 QString key, QString value) {
175 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserialized(
176 QString object_name, QString value) {
180 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserializedJson(
181 QString object_name, QJsonDocument value) {
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
const QStringList ALL_OBJECTS
Iterable object range.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.