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;
125 if (!o_it->materialNode())
continue;
127 objname_to_material[o_it->name()] = &o_it->materialNode()->material();
130 for (QVariantMap::const_iterator it = materials.begin();
131 it != materials.end(); ++it) {
133 if (objname_to_material.contains(it.key())) {
134 objname_to_material[it.key()]->deserializeFromVariantMap(
143 if (restore_from_screenshot_dlg->restore_objectmd_cb->isChecked()) {
144 QStringList textKeys = img.textKeys();
145 QVector<QPair<QString, QString> > metadata;
146 metadata.reserve(textKeys.size());
147 for (QStringList::iterator it = textKeys.begin();
148 it != textKeys.end(); ++it) {
149 metadata.push_back(QPair<QString, QString>(*it, img.text(*it)));
151 emit metadataDeserialized(metadata);
156 void DeserializeScreenshotMetadataPlugin::slot_restore_from_screenshot() {
157 if (!restore_from_screenshot_dlg) {
159 connect(restore_from_screenshot_dlg->restore_pb,
162 SLOT(slot_do_restore_from_screenshot()));
164 restore_from_screenshot_dlg->show();
165 restore_from_screenshot_dlg->raise();
168 void DeserializeScreenshotMetadataPlugin::slotGenericMetadataDeserialized(
169 QString key, QString value) {
173 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserialized(
174 QString object_name, QString value) {
178 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserializedJson(
179 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.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.