* demo/viewer/common.hh,
* demo/viewer/image_region.cc,
* demo/viewer/key_widget.cc,
* demo/viewer/step_widget.cc,
* demo/viewer/viewer.cc,
* demo/viewer/viewer.hh,
* demo/viewer/xml_widget.cc: Get rid of the paragraph node and
consider text_region as a paragraph.
---
scribo/ChangeLog | 13 ++++++++
scribo/demo/viewer/common.hh | 7 ++--
scribo/demo/viewer/image_region.cc | 11 ++----
scribo/demo/viewer/key_widget.cc | 38 ++++++++++++----------
scribo/demo/viewer/step_widget.cc | 4 ++
scribo/demo/viewer/viewer.cc | 60 +++++++++++++++--------------------
scribo/demo/viewer/viewer.hh | 2 +-
scribo/demo/viewer/xml_widget.cc | 29 +++++------------
8 files changed, 81 insertions(+), 83 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 564ed4d..37d0ea8 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,18 @@
2011-01-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Handle paragraphs correctly in scribo-viewer.
+
+ * demo/viewer/common.hh,
+ * demo/viewer/image_region.cc,
+ * demo/viewer/key_widget.cc,
+ * demo/viewer/step_widget.cc,
+ * demo/viewer/viewer.cc,
+ * demo/viewer/viewer.hh,
+ * demo/viewer/xml_widget.cc: Get rid of the paragraph node and
+ consider text_region as a paragraph.
+
+2011-01-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add support for paragraphs.
* scribo/core/document.hh: Add support for paragraphs.
diff --git a/scribo/demo/viewer/common.hh b/scribo/demo/viewer/common.hh
index 7f67f82..b2d8f7e 100644
--- a/scribo/demo/viewer/common.hh
+++ b/scribo/demo/viewer/common.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -24,7 +25,6 @@ namespace region
enum RegionId
{
Text = 0,
- Paragraph,
Line,
Image,
Noise,
@@ -33,7 +33,8 @@ namespace region
LineDrawing,
Graphic,
Chart,
- Maths
+ Maths,
+ RegionIdCount
};
}
diff --git a/scribo/demo/viewer/image_region.cc b/scribo/demo/viewer/image_region.cc
index 19ca872..93d9d79 100644
--- a/scribo/demo/viewer/image_region.cc
+++ b/scribo/demo/viewer/image_region.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -40,9 +41,7 @@ ImageRegion::ImageRegion(region::RegionId id,
alpha_(50)
{
setCursor(Qt::ArrowCursor);
- if (id_ == region::Paragraph)
- setZValue(2);
- else if (id_ == region::Line)
+ if (id_ == region::Line)
setZValue(3);
else
setZValue(1);
@@ -128,9 +127,7 @@ ImageRegion::deselect()
if (selected_)
{
selected_ = false;
- if (id_ == region::Paragraph)
- setZValue(2);
- else if (id_ == region::Line)
+ if (id_ == region::Line)
setZValue(3);
else
setZValue(1);
diff --git a/scribo/demo/viewer/key_widget.cc b/scribo/demo/viewer/key_widget.cc
index 47cfbcf..3a4b47b 100644
--- a/scribo/demo/viewer/key_widget.cc
+++ b/scribo/demo/viewer/key_widget.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -35,12 +36,11 @@ KeyWidget::KeyWidget(const region::KeyMap& key_map)
regions_->setCheckState(0, Qt::Checked);
regions_->setExpanded(true);
- for (int i = 0; i < 3; ++i)
+ for (int i = 0; i < 2; ++i)
add_item_(key_map.at(i).first, key_map.at(i).second,
- i == region::Line ||
- i == region::Paragraph, text_);
+ i == region::Line, text_);
- for (int i = 3; i < key_map.size(); ++i)
+ for (int i = 2; i < key_map.size(); ++i)
add_item_(key_map.at(i).first, key_map.at(i).second, false, regions_);
QVBoxLayout* layout = new QVBoxLayout;
@@ -89,20 +89,17 @@ void KeyWidget::setAllCheck(QTreeWidgetItem* parent)
void
KeyWidget::change_mode(bool b)
{
- int id_region = region::Paragraph;
int id_line = region::Line;
if (b)
{
//text_->child(id_region)->setCheckState(0, Qt::Checked);
- text_->child(id_region)->setHidden(false);
// text_->child(id_line)->setCheckState(0, Qt::Checked);
text_->child(id_line)->setHidden(false);
}
else
{
//text_->child(id_region)->setCheckState(0, Qt::Unchecked);
- text_->child(id_region)->setHidden(true);
// text_->child(id_line)->setCheckState(0, Qt::Unchecked);
text_->child(id_line)->setHidden(true);
}
@@ -140,20 +137,27 @@ KeyWidget::isChecked(region::RegionId id)
void
KeyWidget::update(QTreeWidgetItem* item)
{
- int id;
- id = text_->indexOfChild(item);
- if (id == -1)
- id = regions_->indexOfChild(item) + 4;
-
- emit updated(id, item->checkState(0) == Qt::Checked);
-
+ int id = -1;
if (item == text_ || item == regions_)
+ {
+ setAllCheck(item);
+ }
+ else
+ {
+ id = text_->indexOfChild(item);
+ if (id == -1)
{
- setAllCheck(item);
- return;
+ // +2 since image region id starts from 0 to the number of
+ // region type without considering categories. There are 2
+ // elements in text category and the rest is in the region's
+ // one.
+ id = regions_->indexOfChild(item) + 2;
}
+ emit updated(id, item->checkState(0) == Qt::Checked);
+ }
}
KeyWidget::~KeyWidget()
{
}
+
diff --git a/scribo/demo/viewer/step_widget.cc b/scribo/demo/viewer/step_widget.cc
index 9d26971..77e9bd3 100644
--- a/scribo/demo/viewer/step_widget.cc
+++ b/scribo/demo/viewer/step_widget.cc
@@ -119,7 +119,11 @@ void StepWidget::fill_steps(QString file, bool step, bool container)
emit activated(list.first());
}
else
+ {
step_ = QString::Null();
+ if (view_->count())
+ emit activated(view_->item(0));
+ }
}
}
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index a633a2c..46172ce 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -40,7 +41,7 @@ Viewer::Viewer(int &argc, char** argv)
scene_(new ImageScene()),
files_(new QDirModel()),
doc_layout_(0),
- key_map_(11),
+ key_map_(region::RegionIdCount),
no_cache_(false),
extended_mode_(false),
xml_file_(QString::Null()),
@@ -52,7 +53,6 @@ Viewer::Viewer(int &argc, char** argv)
// Key map
key_map_[region::Text] = qMakePair(tr("Text Region"), QColor(0, 200, 0));
- key_map_[region::Paragraph] = qMakePair(tr("Paragraph"), QColor(0, 0, 255));
key_map_[region::Line] = qMakePair(tr("Text line"), QColor(255, 0, 0));
key_map_[region::Image] = qMakePair(tr("Image"), QColor(255, 120, 0));
@@ -68,7 +68,6 @@ Viewer::Viewer(int &argc, char** argv)
// Region ids
region_ids_["text_region"] = region::Text;
- region_ids_["paragraph"] = region::Paragraph;
region_ids_["line"] = region::Line;
region_ids_["image_region"] = region::Image;
region_ids_["noise_region"] = region::Noise;
@@ -297,6 +296,8 @@ Viewer::Viewer(int &argc, char** argv)
this, SLOT(run_progress()));
connect(&runner_, SIGNAL(xml_saved(const QString&)),
this, SLOT(on_xml_saved(const QString&)));
+
+ extended_action->setChecked(true);
}
@@ -308,12 +309,12 @@ Viewer::~Viewer()
}
void
-Viewer::add_text(QDomNode line, QDomNode region)
+Viewer::add_text(QDomNode line)
{
- int a_height = region.toElement().attribute("a_height",
"0").toInt();
- int d_height = region.toElement().attribute("d_height",
"0").toInt();
- int x_height = region.toElement().attribute("x_height",
"0").toInt();
+ int a_height = line.toElement().attribute("a_height",
"0").toInt();
+ int d_height = line.toElement().attribute("d_height",
"0").toInt();
+ int x_height = line.toElement().attribute("x_height",
"0").toInt();
if (d_height < 0)
d_height = -d_height;
@@ -324,7 +325,7 @@ Viewer::add_text(QDomNode line, QDomNode region)
if ( (a_height - x_height) > (d_height))
d_height = a_height - x_height;
- QDomNode coords = region.firstChild();
+ QDomNode coords = line.firstChild();
while (!coords.isNull() &&
!coords.toElement().tagName().contains("coords"))
coords = coords.nextSibling();
@@ -523,32 +524,25 @@ Viewer::load_xml(QString filename)
}
}
- // if ((extended_mode_ || text_) &&
if (region.toElement().tagName().contains("text_region"))
- {
- QDomNode para = region.firstChild();
- while (!para.isNull() &&
!para.toElement().tagName().contains("paragraph"))
- para = para.nextSibling();
-
- if (!para.isNull())
- {
- if (extended_mode_)
- add_region(para, attr_id);
-
- QDomNode line = para.firstChild();
- while (!line.isNull() &&
!line.toElement().tagName().contains("line"))
- line = line.nextSibling();
+ {
+ QDomNode line = region.firstChild();
- if (!line.isNull())
- {
- if (extended_mode_)
- add_region(line, attr_id);
- add_text(line, region);
- }
- }
+ do
+ {
+ while (!line.isNull() &&
!line.toElement().tagName().contains("line"))
+ line = line.nextSibling();
+
+ if (!line.isNull())
+ {
+ if (extended_mode_)
+ add_region(line, attr_id);
+ add_text(line);
+ }
}
-
- }
+ while (!(line = line.nextSiblingElement("line")).isNull());
+ }
+ }
region = region.nextSibling();
}
@@ -804,8 +798,6 @@ Viewer::export_as()
runner_.start_export(browser_wgt_->current(), step_widget_->current(),
output);
qDebug() << "Saving to " << output << " - "
<< browser_wgt_->current() << " - " <<
step_widget_->current();
}
-
- qDebug() << "Toggled";
}
diff --git a/scribo/demo/viewer/viewer.hh b/scribo/demo/viewer/viewer.hh
index f491c33..3aefaf6 100644
--- a/scribo/demo/viewer/viewer.hh
+++ b/scribo/demo/viewer/viewer.hh
@@ -78,7 +78,7 @@ private:
void xml_to_layout();
QPixmap load_base64(QString xml);
void add_region(QDomNode father, QString attr_id);
- void add_text(QDomNode line, QDomNode region);
+ void add_text(QDomNode line);
QAction *create_action(QString name, QMenu* menu, QString status, QString shortcut);
void reset_progress_dialog();
diff --git a/scribo/demo/viewer/xml_widget.cc b/scribo/demo/viewer/xml_widget.cc
index df68960..c45177b 100644
--- a/scribo/demo/viewer/xml_widget.cc
+++ b/scribo/demo/viewer/xml_widget.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -49,26 +50,12 @@ XmlWidget::select(QString id, QString name)
{
QDomNode n = node_map_[item_map_[id]];
- if (name.contains("Paragraph"))
- {
- n = n.firstChild();
- while (!n.isNull() &&
!n.toElement().tagName().contains("paragraph"))
- n = n.nextSibling();
- }
-
- if (name.contains("Text line"))
- {
- n = n.firstChild();
- while (!n.isNull() &&
!n.toElement().tagName().contains("paragraph"))
- n = n.nextSibling();
-
- if (!n.isNull())
- {
- n = n.firstChild();
- while (!n.isNull() && !n.toElement().tagName().contains("line"))
- n = n.nextSibling();
- }
- }
+ if (name.contains("Text line"))
+ {
+ n = n.firstChild();
+ while (!n.isNull() && !n.toElement().tagName().contains("line"))
+ n = n.nextSibling();
+ }
if (!n.isNull())
{
--
1.5.6.5