Commits

Vincent Rabeux committed 59610f1

Added support for DoQuBook DegradationModel plugins.

  • Participants
  • Parent commits ce2bd0a

Comments (1)

Files changed (5)

documentImageCreator/src/gui/AncientDocumentEditor/CMakeLists.txt

 
 project(AncientDocumentEditor)
 
+option(NO_DOQUBOOK "deactivate doqubook even if installed on system" OFF)
+
+
 set(AncientDocumentEditor_DESCRIPTION "GUI to create synthetics documents. Developped for the ANR-Digidoc project")
 
 set(AncientDocumentEditor_AUTHOR "Vincent Rabeux <rabeux@labri.fr>")
 FIND_PACKAGE(DocumentCreator REQUIRED)
 include_directories(${DocumentCreator_INCLUDE_DIRS})
 
+
+if(NOT NO_DOQUBOOK)
+FIND_PACKAGE(DoQuBook QUIET)
+
+if(DoQuBook_FOUND)
+    message("==> Activating DoQuBook features")
+    add_definitions("-DDOQUBOOK_FOUND")
+    include_directories(${DoQuBook_INCLUDE_DIRS})
+    set(EXTRA_LIBS ${EXTRA_LIBS} ${DoQuBook_LIBRARIES})
+endif(DoQuBook_FOUND)
+
+endif(NOT NO_DOQUBOOK)
+
+
+
 INCLUDE( ${QT_USE_FILE} )
 
 
                @ONLY)
     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/AncientDocumentEditor.desktop DESTINATION  /usr/share/applications/)
 
-
-
 endif( UNIX AND NOT APPLE )
 
 
-
-
 QT4_ADD_RESOURCES(RCS ${AncientDocumentCreator_rcs} )
 QT4_WRAP_UI(UI ${AncientDocumentCreator_ui})
 QT4_WRAP_CPP(MOC ${AncientDocumentCreator_moc})
 INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
 INCLUDE_DIRECTORIES( ./src )
 
-SET(EXTRA_LIBS  ${QT_LIBRARIES} ${Lipsum4Qt_LIBRARIES} ${DocumentCreator_LIBRARIES})
+SET(EXTRA_LIBS  ${EXTRA_LIBS} ${QT_LIBRARIES} ${Lipsum4Qt_LIBRARIES} ${DocumentCreator_LIBRARIES})
 
 
  #IF( APPLE )

documentImageCreator/src/gui/AncientDocumentEditor/src/ancientdocumenteditor.cpp

 #include "Degradations/VersoImageChanger.hpp"
 
 #include "appconstants.h"
+
+
+#ifdef DOQUBOOK_FOUND
+#include <DoQuBook/PluginLoader.hpp>
+#include <DoQuBook/DegradationModel.hpp>
+#include <DoQuBook/DoQuBookPluginParamsDialog.hpp>
+using namespace DoQuBook;
+using namespace DoQuBook::gui;
+#endif
+
 using namespace IOManager;
 using namespace Core;
 using namespace Context;
 
 AncientDocumentEditor::AncientDocumentEditor()
 {
+#ifdef DOQUBOOK_FOUND
+    _loader = PluginLoader::instance();
+#endif
+
     hide();
     qsrand(QDateTime::currentDateTime ().toTime_t ());
     _docController = NULL;
     _docController->exportToImage(name + ".png"); //need graphicsview
 }
 
+#ifdef DOQUBOOK_FOUND
+void AncientDocumentEditor::openDoQuBookPluginForm()
+{
+    /// Get the plugin by its name
+    QAction *a = dynamic_cast<QAction*>(sender());
+    DegradationModelPtr plugin = _loader->getPlugin<DegradationModel>(a->text());
+
+    /// Save the current synthetic document to the temp dir and open it.
+    QString imagePath = QDir::tempPath()+"/tmp.png";
+    _docController->exportToImage(imagePath);
+    QImage img (imagePath);
+
+    /// Set the parameters of the plugin with a dialog.
+    QList<ExecutorParameterPtr> params = plugin->parameters();
+    DoQuBookPluginParamsDialog *d = new DoQuBookPluginParamsDialog(params, this);
+    d->exec();
+    QVariantMap filedUpParams = d->getParams();
+
+    QMessageBox msgBox;
+    msgBox.setText("Running... Please wait.");
+
+    /// run the plugin in an other thread while msgBox is diwplayed.
+    QFutureWatcher<QImage> watcher;
+    connect(&watcher, SIGNAL(finished()), &msgBox, SLOT(close()));
+    QFuture<QImage> futur = QtConcurrent::run(plugin.get(), &DegradationModel::degradate, img, filedUpParams);
+    watcher.setFuture(futur);
+    msgBox.exec();
+
+    /// if the user closes msgBox we still have to wait for the thread to finish
+    futur.waitForFinished();
+
+    /// ask the user where to save the result.
+    QString fileName = QFileDialog::getSaveFileName(this, "Save result image");
+    futur.result().save(fileName);
+}
+#endif
+
 void AncientDocumentEditor::update()
 {
     QString path = DocumentContext::instance()->getCurrentDocumentPath();
     _degradationsMenu = menuBar()->addMenu(tr("&Degradations"));
     _degradationsMenu->addAction(_applyBleedThrough);
 
+#ifdef DOQUBOOK_FOUND
+    /// Load any DoQuBook DegradationModel plugin and populate the _degradationsMenu menu.
+    QStringList plugins = _loader->listPlugins<DegradationModel>();
+    foreach (QString pluginName, plugins) {
+        QAction * a = new QAction(pluginName, this);
+        connect(a, SIGNAL(triggered()), this, SLOT(openDoQuBookPluginForm()));
+       _degradationsMenu->addAction(a);
+    }
+#endif
+
     _helpMenu = menuBar()->addMenu(tr("&Help"));
     _helpMenu->addAction(_aboutAct);
 }

documentImageCreator/src/gui/AncientDocumentEditor/src/ancientdocumenteditor.h

 #include "Document/documentpropertiesview.h"
 #include "VirtualKeyboard/keyboardview.h"
 
+#ifdef DOQUBOOK_FOUND
+#include <DoQuBook/PluginLoader.hpp>
+#endif
+
 using namespace Patterns;
 
 class AncientDocumentEditor : public QMainWindow, public Observer
     void addMatch();
     void generateDocument(QString cmdline);
 
+#ifdef DOQUBOOK_FOUND
+    /**
+     * @brief openDoQuBookPluginForm Opens the parameter form so that the user can specify
+     *   the parameters of the selectected plugin; Runs the plugin, and save the result.
+     */
+    void openDoQuBookPluginForm();
+#endif
+
 private:
     void createControllers();
     void createActions();
 
     /* Keyboard */
     QString _keyboard;
+
+#ifdef DOQUBOOK_FOUND
+    /* DoQuBook plugins */
+    DoQuBook::PluginLoader *_loader;
+#endif
+
 };
 
 #endif /* ANCIENTDOCUMENTEDITOR_H */

documentImageCreator/src/gui/AncientDocumentEditor/src/appconstants.h

-#ifndef APPCONSTANTS_H
-#define APPCONSTANTS_H
-
-const QString AppConfigFile = "C:/Program Files/AncientDocumentEditor/share/AncientDocumentEditor/application.ini";
-
-
-/* Groups config */
-const QString AppConfigMainGroup = "mainapp" ;
-const QString AppConfigKeyBoardGroup = "keyboard";
-const QString AppConfigFontGroup = "fonteditor" ;
-const QString AppConfigDocGroup = "doceditor";
-
-/* keys */
-const QString AppConfigFontFolderKey = "fontfolder" ;
-const QString AppConfigDefaultFontKey = "defaultfont" ;
-const QString AppConfigFontExtKey = "defaultfontextension" ;
-const QString AppConfigKbFolderKey = "formatsfolder" ;
-const QString AppConfigKbDefautlFormatKey = "defaultformat";
-const QString AppConfigPageSizeX="pagesizex";
-const QString AppConfigPageSizeY="pagesizey";
-const QString AppConfigBackgdFolderKey="backgroundfolder";
-const QString AppConfigDefaultBackbg="defaultbackground";
-const QString AppConfigXmlCheckerFolderKey="xmlcheckerfolder";
-const QString AppConfigDocumentXSDCheckerKey="documentxsdchecker";
-
-/* Some app displays */
-const static QString AppTitle = "Ancient Document Editor - ";
-const static QString DefaultPath = "New old document";
-const static QString ModifiedStr = "*";
-
-#endif // APPCONSTANTS_H
+#ifndef APPCONSTANTS_H
+#define APPCONSTANTS_H
+
+const QString AppConfigFile = "/usr/local/share/AncientDocumentEditor/application.ini";
+
+
+/* Groups config */
+const QString AppConfigMainGroup = "mainapp" ;
+const QString AppConfigKeyBoardGroup = "keyboard";
+const QString AppConfigFontGroup = "fonteditor" ;
+const QString AppConfigDocGroup = "doceditor";
+
+/* keys */
+const QString AppConfigFontFolderKey = "fontfolder" ;
+const QString AppConfigDefaultFontKey = "defaultfont" ;
+const QString AppConfigFontExtKey = "defaultfontextension" ;
+const QString AppConfigKbFolderKey = "formatsfolder" ;
+const QString AppConfigKbDefautlFormatKey = "defaultformat";
+const QString AppConfigPageSizeX="pagesizex";
+const QString AppConfigPageSizeY="pagesizey";
+const QString AppConfigBackgdFolderKey="backgroundfolder";
+const QString AppConfigDefaultBackbg="defaultbackground";
+const QString AppConfigXmlCheckerFolderKey="xmlcheckerfolder";
+const QString AppConfigDocumentXSDCheckerKey="documentxsdchecker";
+
+/* Some app displays */
+const static QString AppTitle = "Ancient Document Editor - ";
+const static QString DefaultPath = "New old document";
+const static QString ModifiedStr = "*";
+
+#endif // APPCONSTANTS_H

documentImageCreator/src/gui/AncientDocumentEditor/src/application.ini

-[mainapp]
-
-fontfolder=C:/Program Files/AncientDocumentEditor/share/AncientDocumentEditor/font/
-backgroundfolder=C:/Program Files/AncientDocumentEditor/share/AncientDocumentEditor/background/
-xmlcheckerfolder=C:/Program Files/AncientDocumentEditor/share/AncientDocumentEditor/xmlchecker/
-documentxsdchecker=document.xsd
-defaultfont=vesale 
-defaultfontextension=.of
-defaultbackground=vesale_0002.jpg
-pagesizex=1260
-pagesizey=1782
-
-[keyboard]
-formatsfolder=C:/Program Files/AncientDocumentEditor/share/AncientDocumentEditor/keyboard/
-defaultformat=fr_alternative.kb
+[mainapp]
+
+fontfolder=/usr/local/share/AncientDocumentEditor/font/
+backgroundfolder=/usr/local/share/AncientDocumentEditor/background/
+xmlcheckerfolder=/usr/local/share/AncientDocumentEditor/xmlchecker/
+documentxsdchecker=document.xsd
+defaultfont=vesale 
+defaultfontextension=.of
+defaultbackground=vesale_0002.jpg
+pagesizex=1260
+pagesizey=1782
+
+[keyboard]
+formatsfolder=/usr/local/share/AncientDocumentEditor/keyboard/
+defaultformat=fr_alternative.kb