* demo/viewer/Makefile.am,
* demo/viewer/demodir.hh.in: Update demodir replacement.
* demo/viewer/browser_widget.cc,
* demo/viewer/browser_widget.hh: Add a new method.
* demo/viewer/runner.cc,
* demo/viewer/runner.hh,
* demo/viewer/step_widget.cc,
* demo/viewer/step_widget.hh,
* demo/viewer/viewer.cc,
* demo/viewer/viewer.hh: Introduce "export as" functionality.
---
scribo/ChangeLog | 17 +++++
scribo/demo/viewer/Makefile.am | 4 +-
scribo/demo/viewer/browser_widget.cc | 6 ++
scribo/demo/viewer/browser_widget.hh | 2 +
scribo/demo/viewer/demodir.hh.in | 2 +-
scribo/demo/viewer/runner.cc | 115 +++++++++++++++++++++++++++++-----
scribo/demo/viewer/runner.hh | 16 ++++-
scribo/demo/viewer/step_widget.cc | 10 ++-
scribo/demo/viewer/step_widget.hh | 3 +
scribo/demo/viewer/viewer.cc | 53 +++++++++++++---
scribo/demo/viewer/viewer.hh | 6 ++
11 files changed, 202 insertions(+), 32 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 9185148..d163b69 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,20 @@
+2011-01-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Introduce "export as" functionality.
+
+ * demo/viewer/Makefile.am,
+ * demo/viewer/demodir.hh.in: Update demodir replacement.
+
+ * demo/viewer/browser_widget.cc,
+ * demo/viewer/browser_widget.hh: Add a new method.
+
+ * demo/viewer/runner.cc,
+ * demo/viewer/runner.hh,
+ * demo/viewer/step_widget.cc,
+ * demo/viewer/step_widget.hh,
+ * demo/viewer/viewer.cc,
+ * demo/viewer/viewer.hh: Introduce "export as" functionality.
+
2011-01-03 Guillaume Lazzara <z(a)lrde.epita.fr>
Add new files in EXTRA_DIST.
diff --git a/scribo/demo/viewer/Makefile.am b/scribo/demo/viewer/Makefile.am
index d5fffbf..8692915 100644
--- a/scribo/demo/viewer/Makefile.am
+++ b/scribo/demo/viewer/Makefile.am
@@ -99,8 +99,8 @@ noinst_HEADERS = viewer.hh \
# Generated files
do_subst = sed \
- -e 's|@bindir[@]|$(bindir)|g' \
- -e 's|@abs_srcdir[@]|$(abs_srcdir)|g'
+ -e 's|@bindir[@]|$(bindir)|g' \
+ -e 's|@abs_demodir[@]|$(abs_top_builddir)/scribo/demo|g'
demodir.hh: $(srcdir)/demodir.hh.in Makefile
rm -f $@ $@.tmp
diff --git a/scribo/demo/viewer/browser_widget.cc b/scribo/demo/viewer/browser_widget.cc
index 5a67d1e..17e1c61 100644
--- a/scribo/demo/viewer/browser_widget.cc
+++ b/scribo/demo/viewer/browser_widget.cc
@@ -130,3 +130,9 @@ BrowserWidget::change_pos(bool next)
BrowserWidget::~BrowserWidget()
{
}
+
+QString
+BrowserWidget::current() const
+{
+ return files_->filePath(view_->currentIndex());
+}
diff --git a/scribo/demo/viewer/browser_widget.hh b/scribo/demo/viewer/browser_widget.hh
index bbed1ac..9567c11 100644
--- a/scribo/demo/viewer/browser_widget.hh
+++ b/scribo/demo/viewer/browser_widget.hh
@@ -28,6 +28,8 @@ public:
BrowserWidget(QDirModel* files, QString dir = QString());
~BrowserWidget();
+ QString current() const;
+
public slots:
void activate(const QModelIndex& index, bool b = false);
void path_return_pressed();
diff --git a/scribo/demo/viewer/demodir.hh.in b/scribo/demo/viewer/demodir.hh.in
index 59149b9..e8a4a23 100644
--- a/scribo/demo/viewer/demodir.hh.in
+++ b/scribo/demo/viewer/demodir.hh.in
@@ -29,7 +29,7 @@
# define SCRIBO_PREFIX_BINDIR "@bindir@"
-# define SCRIBO_LOCAL_DEMODIR "@abs_srcdir@"
+# define SCRIBO_LOCAL_DEMODIR "@abs_demodir@"
#endif // !SCRIBO_DEMO_DEMODIR_HH
diff --git a/scribo/demo/viewer/runner.cc b/scribo/demo/viewer/runner.cc
index 1d0f4bb..085ef39 100644
--- a/scribo/demo/viewer/runner.cc
+++ b/scribo/demo/viewer/runner.cc
@@ -20,15 +20,36 @@
#include <mln/value/rgb8.hh>
#include <mln/io/magick/load.hh>
+#include "demodir.hh"
+
#include "process.hh"
#include "preprocess.hh"
#include "config.hh"
#include "defs.hh"
+
using namespace mln;
using namespace scribo::toolchain::internal;
+static
+QString get_pathto(const QString& file,
+ const QString localdirsuffix = QString())
+{
+ QFile f(SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix + "/" + file);
+ if (f.exists())
+ return SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix;
+
+ f.setFileName(SCRIBO_PREFIX_BINDIR "/" + file);
+ if (f.exists())
+ return SCRIBO_PREFIX_BINDIR;
+
+ qDebug() << "FATAL ERROR: Can't locate file: " + file;
+
+ return "";
+}
+
+
runner::runner(QObject *parent)
: QThread(parent)
{
@@ -36,26 +57,47 @@ runner::runner(QObject *parent)
}
-void runner::start(const QString& filename)
+void runner::run()
{
- filename_ = filename;
- QThread::start();
+ switch(mode_)
+ {
+ default:
+ case Demat:
+ {
+ image2d<value::rgb8> ima;
+ io::magick::load(ima, args_.at(0).toUtf8().constData());
+
+ image2d<bool> bin_ima = preprocess(ima);
+ process(ima, bin_ima);
+ }
+ break;
+
+ case Export:
+ export_as();
+ break;
+ }
+
+ emit finished();
+ qDebug() << "Done.";
}
-void runner::run()
+void runner::stop()
{
- QThread::setTerminationEnabled();
+ terminate();
+}
- image2d<value::rgb8> ima;
- io::magick::load(ima, filename_.toUtf8().constData());
- image2d<bool> bin_ima = preprocess(ima);
- process(ima, bin_ima);
- emit finished();
- qDebug() << "Done.";
+// Demat related stuff
+
+void runner::start_demat(const QString& filename)
+{
+ args_ << filename;
+ mode_ = Demat;
+
+ QThread::start();
}
@@ -95,7 +137,7 @@ void runner::process(const image2d<value::rgb8>&
original_ima,
{
emit new_step("Page segmentation");
- ::process f(filename_.toUtf8().constData());
+ ::process f(args_.at(0).toUtf8().constData());
connect(&f, SIGNAL(progress()), this, SIGNAL(progress()));
connect(&f, SIGNAL(new_progress_label(const QString&)),
@@ -117,7 +159,7 @@ void runner::process(const image2d<value::rgb8>&
original_ima,
f.save_doc_as_xml = true;
- QFileInfo file(filename_);
+ QFileInfo file(args_.at(0));
QString output_dir = QDir::tempPath();
if (conf->general_save_xml_enabled())
{
@@ -133,7 +175,6 @@ void runner::process(const image2d<value::rgb8>&
original_ima,
output_dir = QDir::tempPath();
}
f.output_file = (output_dir + "/" + file.baseName() +
"_gui.xml").toUtf8().constData();
- qDebug() << "Saving to " << f.output_file.c_str();
emit new_progress_max_value(f.nsteps());
@@ -144,7 +185,49 @@ void runner::process(const image2d<value::rgb8>&
original_ima,
}
-void runner::stop()
+
+// Export related stuff
+
+void runner::start_export(const QString& imgfile,
+ const QString& xmlfile, const QString& outfile)
{
- terminate();
+ args_ << imgfile << xmlfile << outfile;
+ mode_ = Export;
+
+ QThread::start();
+}
+
+
+void runner::export_as()
+{
+ emit new_step("Exporting document...");
+ emit new_progress_max_value(2);
+
+ // Checking output format
+ QFileInfo f(args_.at(2));
+
+ QString pathto_xml2doc = get_pathto("scribo-xml2doc", "xml2doc");
+
+ if (pathto_xml2doc.isEmpty())
+ {
+ QMessageBox::critical(0, "Fatal error", "Cannot export! Cannot find
scribo-xml2doc program!");
+ return;
+ }
+
+ emit progress();
+
+ int rvalue = 0;
+ if (f.suffix() == "pdf")
+ rvalue = system(QString("%1/scribo-xml2doc --pdf %2 %3 %4")
+ .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0))
+ .arg(args_.at(2)).toAscii().constData());
+ else if (f.suffix() == "html" || f.suffix() == "htm")
+ rvalue = system(QString("%1/scribo-xml2doc --html %2 %3 %4")
+ .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0))
+ .arg(args_.at(2)).toAscii().constData());
+ else
+ QMessageBox::critical(0, "Fatal error", "Cannot export! Invalid output
format!");
+
+ if (rvalue != 0)
+ QMessageBox::critical(0, "Fatal error", "Cannot export! Return value
is not 0!");
}
diff --git a/scribo/demo/viewer/runner.hh b/scribo/demo/viewer/runner.hh
index ed243ea..176dcd8 100644
--- a/scribo/demo/viewer/runner.hh
+++ b/scribo/demo/viewer/runner.hh
@@ -24,6 +24,12 @@
using namespace mln;
+enum RunMode
+{
+ Demat,
+ Export
+};
+
class runner : public QThread
{
Q_OBJECT;
@@ -31,7 +37,9 @@ class runner : public QThread
public:
runner(QObject *parent = 0);
- void start(const QString& filename);
+ void start_demat(const QString& filename);
+ void start_export(const QString& imgfile,
+ const QString& xmlfile, const QString& outfile);
public slots:
void stop();
@@ -48,13 +56,17 @@ private: // members
image2d<bool> preprocess(const image2d<value::rgb8>& ima);
void process(const image2d<value::rgb8>& original_ima,
const image2d<bool>& processed_ima);
+
+ void export_as();
+
virtual void run();
template <typename V>
unsigned find_best_scale(const mln::image2d<V>& ima);
private: // attributes
- QString filename_;
+ QStringList args_;
+ RunMode mode_;
};
diff --git a/scribo/demo/viewer/step_widget.cc b/scribo/demo/viewer/step_widget.cc
index 342b654..9d26971 100644
--- a/scribo/demo/viewer/step_widget.cc
+++ b/scribo/demo/viewer/step_widget.cc
@@ -38,6 +38,7 @@ StepWidget::StepWidget()
connect(this, SIGNAL(activated(QListWidgetItem*)),
this, SLOT(activate(QListWidgetItem*)));
+
}
StepWidget::~StepWidget()
@@ -62,6 +63,8 @@ void StepWidget::activate(QListWidgetItem* item)
}
else
qDebug() << "Step not found!";
+
+ emit step_selected(view_->count());
}
@@ -158,9 +161,10 @@ QListWidgetItem* StepWidget::add_element(const QString& element)
return item;
}
-
-
-
+QString StepWidget::current() const
+{
+ return map_.value(step_);
+}
diff --git a/scribo/demo/viewer/step_widget.hh b/scribo/demo/viewer/step_widget.hh
index b323167..f648ede 100644
--- a/scribo/demo/viewer/step_widget.hh
+++ b/scribo/demo/viewer/step_widget.hh
@@ -32,11 +32,14 @@ public:
~StepWidget();
QListWidgetItem* add_element(const QString& element);
+ QString current() const;
+
signals:
void load_image(QString, bool);
void load_xml(QString);
void activated(QListWidgetItem*);
void change_base(bool);
+ void step_selected(bool);
public slots:
void fill_steps(QString file, bool step = false, bool container = false);
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index dd0fbe4..a633a2c 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -99,6 +99,16 @@ Viewer::Viewer(int &argc, char** argv)
file_menu->addSeparator();
+ export_action_ = create_action("Export as...", file_menu,
+ "Export as...", "Shift+Ctrl+S");
+ connect(export_action_, SIGNAL(triggered()),
+ this, SLOT(export_as()));
+ file_menu->addAction(export_action_);
+ export_action_->setEnabled(false);
+
+ file_menu->addSeparator();
+
+
QAction* quit_action = create_action("Quit", file_menu,
"Exit the program.", "Ctrl+q");
connect(quit_action, SIGNAL(triggered()),
@@ -210,15 +220,17 @@ Viewer::Viewer(int &argc, char** argv)
step_widget_ = new StepWidget();
XmlWidget* xml_wgt = new XmlWidget();
- BrowserWidget* browser_wgt =
- new BrowserWidget(files_, argc != 2 ? QString() : argv[1]);
+ browser_wgt_ = new BrowserWidget(files_, argc != 2 ? QString() : argv[1]);
ImageWidget* image_wgt = new ImageWidget(scene_);
+ connect(step_widget_, SIGNAL(step_selected(bool)),
+ export_action_, SLOT(setEnabled(bool)));
+
scene_->setBackgroundBrush(scene_->palette().window());
v_splitter->addWidget(step_widget_);
v_splitter->addWidget(key_wgt_);
- v_splitter->addWidget(browser_wgt);
+ v_splitter->addWidget(browser_wgt_);
v_splitter2->addWidget(image_wgt);
v_splitter2->addWidget(xml_wgt);
@@ -240,7 +252,7 @@ Viewer::Viewer(int &argc, char** argv)
h_sizes << 200 << 900;
h_splitter->setSizes(h_sizes);
- connect(browser_wgt, SIGNAL(activated(QString, bool, bool)),
+ connect(browser_wgt_, SIGNAL(activated(QString, bool, bool)),
step_widget_, SLOT(fill_steps(QString, bool, bool)));
connect(step_widget_, SIGNAL(change_base(bool)),
@@ -753,10 +765,8 @@ Viewer::run_process()
{
if (!current_image_.isEmpty())
{
- pdialog_.setValue(0);
- pdialog_.setLabelText("");
- pdialog_.show();
- runner_.start(current_image_);
+ reset_progress_dialog();
+ runner_.start_demat(current_image_);
}
}
@@ -779,3 +789,30 @@ Viewer::on_xml_saved(const QString& filename)
QListWidgetItem *item = step_widget_->insert_new_entry(filename);
step_widget_->activate(item);
}
+
+
+void
+Viewer::export_as()
+{
+ QFileInfo f(browser_wgt_->current());
+ QString output_suggestion = f.baseName() + ".pdf";
+ QString output = QFileDialog::getSaveFileName(0, "Export document as...",
output_suggestion, tr("PDF (*.pdf);; HTML (*.html *.htm)"));
+
+ if (!output.isEmpty())
+ {
+ reset_progress_dialog();
+ runner_.start_export(browser_wgt_->current(), step_widget_->current(),
output);
+ qDebug() << "Saving to " << output << " - "
<< browser_wgt_->current() << " - " <<
step_widget_->current();
+ }
+
+ qDebug() << "Toggled";
+}
+
+
+void
+Viewer::reset_progress_dialog()
+{
+ pdialog_.setValue(0);
+ pdialog_.setLabelText("");
+ pdialog_.show();
+}
diff --git a/scribo/demo/viewer/viewer.hh b/scribo/demo/viewer/viewer.hh
index 93fc840..f491c33 100644
--- a/scribo/demo/viewer/viewer.hh
+++ b/scribo/demo/viewer/viewer.hh
@@ -27,6 +27,8 @@ class DomModel;
class KeyWidget;
class ImageRegion;
class StepWidget;
+class BrowserWidget;
+
class Viewer
: public QObject
@@ -58,6 +60,7 @@ private slots:
void run_process();
void run_progress();
void on_xml_saved(const QString& filename);
+ void export_as();
signals:
void updated();
@@ -77,10 +80,12 @@ private:
void add_region(QDomNode father, QString attr_id);
void add_text(QDomNode line, QDomNode region);
QAction *create_action(QString name, QMenu* menu, QString status, QString shortcut);
+ void reset_progress_dialog();
QApplication* app_;
QMainWindow* win_;
StepWidget* step_widget_;
+ BrowserWidget* browser_wgt_;
QGraphicsPixmapItem* image_;
@@ -91,6 +96,7 @@ private:
QAction* outline_action_;
QAction* fill_action_;
QAction* precise_action_;
+ QAction *export_action_;
KeyWidget* key_wgt_;
--
1.5.6.5