58 #include "DeserializeScreenshotMetadataPlugin.hh"
67 DeserializeScreenshotMetadataPlugin::DeserializeScreenshotMetadataPlugin() :
70 restore_from_screenshot_dlg(0) {
73 void DeserializeScreenshotMetadataPlugin::initializePlugin() {
76 void DeserializeScreenshotMetadataPlugin::pluginsInitialized() {
77 toolbar =
new QToolBar(tr(
"Restore from Screenshot"));
79 restoreAction =
new QAction(tr(
"Restore Scene From Screenshot"), toolbar);
80 restoreAction->setIcon(
81 QIcon(OpenFlipper::Options::iconDirStr() +
82 OpenFlipper::Options::dirSeparator() +
83 "restore_from_screenshot.png"));
85 toolbar->addAction(restoreAction);
87 emit addToolbar(toolbar);
89 connect(restoreAction, SIGNAL(triggered(
bool)),
this,
90 SLOT(slot_restore_from_screenshot()));
93 void DeserializeScreenshotMetadataPlugin::slot_do_restore_from_screenshot() {
94 if (!restore_from_screenshot_dlg)
return;
96 const QString restoreFileName =
97 restore_from_screenshot_dlg->getRestoreFileName();
99 QImage img(restoreFileName);
101 QMessageBox::warning(0, tr(
"Unable to load image"),
102 tr(
"Unable to load image. "
103 "Unrecognized format or file not existent."),
111 if (restore_from_screenshot_dlg->restore_viewer_cb->isChecked()) {
112 QString view = img.text(
"View");
113 if (!view.isEmpty()) {
121 if (restore_from_screenshot_dlg->restore_materials_cb->isChecked()) {
122 QString materials_json =
123 QString::fromUtf8(
"{") + img.text(
"Mesh Materials") +
124 QString::fromUtf8(
"}");
125 QVariantMap materials = ACG::json_to_variant_map(materials_json);
127 QMap<QString, ACG::SceneGraph::Material*> objname_to_material;
132 if (!o_it->materialNode())
continue;
134 objname_to_material[o_it->name()] = &o_it->materialNode()->material();
137 for (QVariantMap::const_iterator it = materials.begin();
138 it != materials.end(); ++it) {
140 if (objname_to_material.contains(it.key())) {
141 objname_to_material[it.key()]->deserializeFromVariantMap(
150 if (restore_from_screenshot_dlg->restore_objectmd_cb->isChecked()) {
151 QStringList textKeys = img.textKeys();
152 QVector<QPair<QString, QString> > metadata;
153 metadata.reserve(textKeys.size());
154 for (QStringList::iterator it = textKeys.begin();
155 it != textKeys.end(); ++it) {
156 metadata.push_back(QPair<QString, QString>(*it, img.text(*it)));
158 emit metadataDeserialized(metadata);
163 void DeserializeScreenshotMetadataPlugin::slot_restore_from_screenshot() {
164 if (!restore_from_screenshot_dlg) {
166 connect(restore_from_screenshot_dlg->restore_pb,
169 SLOT(slot_do_restore_from_screenshot()));
171 restore_from_screenshot_dlg->show();
172 restore_from_screenshot_dlg->raise();
175 void DeserializeScreenshotMetadataPlugin::slotGenericMetadataDeserialized(
176 QString key, QString value) {
180 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserialized(
181 QString object_name, QString value) {
185 #if QT_VERSION >= 0x050000
186 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserializedJson(
187 QString object_name, QJsonDocument value) {
194 #if QT_VERSION < 0x050000
const QStringList ALL_OBJECTS
Iterable object range.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.