* demo/viewer/common.hh: Add new enums.
* demo/viewer/key_widget.cc,
* demo/viewer/key_widget.hh: Revamp code and add support for more
region types.
* demo/viewer/viewer.cc,
* demo/viewer/viewer.hh: Insert line blocks.
---
scribo/ChangeLog | 13 ++++
scribo/demo/viewer/common.hh | 11 ++++
scribo/demo/viewer/key_widget.cc | 123 ++++++++++++++++++-------------------
scribo/demo/viewer/key_widget.hh | 4 +-
scribo/demo/viewer/viewer.cc | 106 +++++++++++++++++++++++++++++++-
scribo/demo/viewer/viewer.hh | 1 +
6 files changed, 190 insertions(+), 68 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 52006a7..03705c9 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,16 @@
+2011-02-05 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Display baseline and meanline in Scribo viewer.
+
+ * demo/viewer/common.hh: Add new enums.
+
+ * demo/viewer/key_widget.cc,
+ * demo/viewer/key_widget.hh: Revamp code and add support for more
+ region types.
+
+ * demo/viewer/viewer.cc,
+ * demo/viewer/viewer.hh: Insert line blocks.
+
2011-02-04 Guillaume Lazzara <z(a)lrde.epita.fr>
Add printing support in Scribo viewer.
diff --git a/scribo/demo/viewer/common.hh b/scribo/demo/viewer/common.hh
index b2d8f7e..46f20c1 100644
--- a/scribo/demo/viewer/common.hh
+++ b/scribo/demo/viewer/common.hh
@@ -26,6 +26,9 @@ namespace region
{
Text = 0,
Line,
+
+ EndOfTextRegion,
+
Image,
Noise,
Separator,
@@ -34,6 +37,14 @@ namespace region
Graphic,
Chart,
Maths,
+
+ EndOfMiscRegion,
+
+ Baseline,
+ Meanline,
+
+ EndOfTypoRegion,
+
RegionIdCount
};
}
diff --git a/scribo/demo/viewer/key_widget.cc b/scribo/demo/viewer/key_widget.cc
index 3a4b47b..cc10308 100644
--- a/scribo/demo/viewer/key_widget.cc
+++ b/scribo/demo/viewer/key_widget.cc
@@ -19,29 +19,31 @@
#include "common.hh"
KeyWidget::KeyWidget(const region::KeyMap& key_map)
- : items_(new QTreeWidget()),
- text_(new QTreeWidgetItem(QStringList("Text"))),
- regions_(new QTreeWidgetItem(QStringList("Regions")))
+ : items_(new QTreeWidget())
{
+ item_list_.append(new QTreeWidgetItem(QStringList("Text")));
+ item_list_.append(new QTreeWidgetItem(QStringList("Regions")));
+ item_list_.append(new QTreeWidgetItem(QStringList("Typographical Lines")));
+
QLabel* title = new QLabel(tr("Key"));
title->setAlignment(Qt::AlignHCenter);
- items_->addTopLevelItem(text_);
- items_->addTopLevelItem(regions_);
+ foreach(QTreeWidgetItem* item, item_list_)
+ {
+ items_->addTopLevelItem(item);
+ item->setCheckState(0, Qt::Checked);
+ item->setExpanded(true);
+ }
items_->setHeaderHidden(true);
- text_->setCheckState(0, Qt::Checked);
- text_->setExpanded(true);
-
- regions_->setCheckState(0, Qt::Checked);
- regions_->setExpanded(true);
+ base_id_.append(0);
+ base_id_.append(region::EndOfTextRegion + 1);
+ base_id_.append(region::EndOfMiscRegion + 1);
+ base_id_.append(region::EndOfTypoRegion + 1);
- for (int i = 0; i < 2; ++i)
- add_item_(key_map.at(i).first, key_map.at(i).second,
- i == region::Line, text_);
-
- for (int i = 2; i < key_map.size(); ++i)
- add_item_(key_map.at(i).first, key_map.at(i).second, false, regions_);
+ for (int j = 0; j < base_id_.size() - 1; ++j)
+ for (int i = base_id_.at(j); i < base_id_.at(j + 1) - 1; ++i)
+ add_item_(key_map.at(i).first, key_map.at(i).second, false, item_list_.at(j));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(title);
@@ -55,11 +57,9 @@ KeyWidget::KeyWidget(const region::KeyMap& key_map)
void KeyWidget::update_all()
{
- for (int i = 0; i < text_->childCount(); ++i)
- update(text_->child(i));
-
- for (int i = 0; i < regions_->childCount(); ++i)
- update(regions_->child(i));
+ foreach(QTreeWidgetItem* item, item_list_)
+ for (int i = 0; i < item->childCount(); ++i)
+ update(item->child(i));
}
void KeyWidget::setAll(bool b)
@@ -70,8 +70,8 @@ void KeyWidget::setAll(bool b)
else
state = Qt::Unchecked;
- text_->setCheckState(0, state);
- regions_->setCheckState(0, state);
+ foreach(QTreeWidgetItem* item, item_list_)
+ item->setCheckState(0, state);
}
void KeyWidget::setAllCheck(QTreeWidgetItem* parent)
@@ -89,20 +89,8 @@ void KeyWidget::setAllCheck(QTreeWidgetItem* parent)
void
KeyWidget::change_mode(bool b)
{
- int id_line = region::Line;
-
- if (b)
- {
- //text_->child(id_region)->setCheckState(0, Qt::Checked);
- // 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_line)->setCheckState(0, Qt::Unchecked);
- text_->child(id_line)->setHidden(true);
- }
+ item_list_.at(0)->child(region::Line)->setHidden(!b);
+ // FIXME: we may like to hide also typographical objects.
}
void
@@ -118,43 +106,52 @@ KeyWidget::add_item_(QString text, QColor color, bool b,
QTreeWidgetItem* parent
item->setHidden(b);
}
- bool
+bool
KeyWidget::isChecked(region::RegionId id)
{
- QTreeWidgetItem* item = text_->child(id);
- if (item)
- return item->checkState(0) == Qt::Checked;
- else
- {
- item = regions_->child(id);
- if(item)
- return item->checkState(0) == Qt::Checked;
- else
- return false;
- }
+ QTreeWidgetItem* current_item = 0;
+
+ foreach(QTreeWidgetItem* item, item_list_)
+ {
+ current_item = item->child(id);
+ if (item)
+ break;
+ else
+ current_item = 0;
+ }
+
+ if (!current_item)
+ return false;
+
+ return current_item->checkState(0) == Qt::Checked;
}
void
-KeyWidget::update(QTreeWidgetItem* item)
+KeyWidget::update(QTreeWidgetItem* item_up)
{
int id = -1;
- if (item == text_ || item == regions_)
- {
- setAllCheck(item);
- }
- else
+
+ foreach(QTreeWidgetItem* item, item_list_)
+ if (item_up == item)
+ {
+ setAllCheck(item);
+ return;
+ }
+
+
+ int i = 0;
+ foreach(QTreeWidgetItem* item, item_list_)
{
- id = text_->indexOfChild(item);
- if (id == -1)
+ id = item->indexOfChild(item_up);
+ if (id != -1)
{
- // +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;
+ id += base_id_.at(i);
+ break;
}
- emit updated(id, item->checkState(0) == Qt::Checked);
+ ++i;
}
+
+ emit updated(id, item_up->checkState(0) == Qt::Checked);
}
KeyWidget::~KeyWidget()
diff --git a/scribo/demo/viewer/key_widget.hh b/scribo/demo/viewer/key_widget.hh
index fd0b514..1a3518e 100644
--- a/scribo/demo/viewer/key_widget.hh
+++ b/scribo/demo/viewer/key_widget.hh
@@ -48,8 +48,8 @@ private:
void add_item_(QString text, QColor color, bool b, QTreeWidgetItem* parent);
QTreeWidget* items_;
- QTreeWidgetItem* text_;
- QTreeWidgetItem* regions_;
+ QVector<QTreeWidgetItem*> item_list_;
+ QVector<int> base_id_;
};
#endif // ! SCRIBO_DEMO_VIEWER_KEY_WIDGET_HH
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index 57a67c2..1d48b1a 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -65,6 +65,9 @@ Viewer::Viewer(int &argc, char** argv)
key_map_[region::Chart] = qMakePair(tr("Chart"), QColor(0, 204, 255));
key_map_[region::Maths] = qMakePair(tr("Maths"), QColor(170, 0, 255));
+ key_map_[region::Baseline] = qMakePair(tr("Baseline"), QColor(128, 0, 255));
+ key_map_[region::Meanline] = qMakePair(tr("Meanline"), QColor(128, 0, 255));
+
// Region ids
region_ids_["text_region"] = region::Text;
@@ -78,7 +81,6 @@ Viewer::Viewer(int &argc, char** argv)
region_ids_["chart_region"] = region::Chart;
region_ids_["maths_region"] = region::Maths;
-
win_->resize(1152, 864);
win_->statusBar();
@@ -154,7 +156,7 @@ Viewer::Viewer(int &argc, char** argv)
precise_action_ = create_action("Precise outline", view_menu,
"1px outline relative to the image "
"(1px relative to the view if off).",
- "Ctrl+p");
+ "Shift+Ctrl+p");
precise_action_->setCheckable(true);
precise_action_->setChecked(false);
connect(precise_action_, SIGNAL(toggled(bool)),
@@ -432,6 +434,100 @@ Viewer::add_region(QDomNode father, QString attr_id)
scene_->addItem(r);
}
+
+void
+Viewer::add_typo_lines(QDomNode father, QString attr_id)
+{
+ // Retrieve typographical information
+ int baseline = father.toElement().attribute("baseline").toInt();
+ int meanline = father.toElement().attribute("meanline").toInt();
+
+ QRect bbox;
+
+ // Looking for bbox coordinates.
+ {
+ QDomNode coords = father.firstChild();
+ while (!coords.isNull() &&
!coords.toElement().tagName().contains("coords"))
+ coords = coords.nextSibling();
+
+ if (coords.isNull())
+ return;
+
+
+ QDomNode point = coords.firstChild();
+ QVector<QPoint> points;
+
+ while (!point.isNull())
+ {
+ int x = point.toElement().attribute("x", "0").toInt();
+ int y = point.toElement().attribute("y", "0").toInt();
+
+ points << QPoint(x, y);
+ point = point.nextSibling();
+ }
+
+ QPolygon polygon(points);
+ bbox = polygon.boundingRect();
+ }
+
+ // Creating blocks
+
+ // Baseline
+ {
+ QVector<QPoint> points;
+ points.append(QPoint(bbox.topLeft().x(), baseline));
+ points.append(QPoint(bbox.topRight().x(), baseline));
+
+ ImageRegion* r = new ImageRegion(region::Baseline,
+ key_map_[region::Baseline].first,
+ key_map_[region::Baseline].second,
+ attr_id, points,
+ outline_action_->isChecked(),
+ fill_action_->isChecked(),
+ precise_action_->isChecked(),
+ key_wgt_->isChecked(region::Baseline));
+
+ connect(this, SIGNAL(key_updated(int, bool)),
+ r, SLOT(setDrawIfSameId(int, bool)));
+ connect(this, SIGNAL(setOutline(bool)),
+ r, SLOT(setOutline(bool)));
+ connect(this, SIGNAL(setPrecise(bool)),
+ r, SLOT(setPrecise(bool)));
+ connect(this, SIGNAL(setFill(bool)),
+ r, SLOT(setFill(bool)));
+
+ scene_->addItem(r);
+ }
+
+ // Meanline
+ {
+ QVector<QPoint> points;
+ points.append(QPoint(bbox.topLeft().x(), meanline));
+ points.append(QPoint(bbox.topRight().x(), meanline));
+
+ ImageRegion* r = new ImageRegion(region::Meanline,
+ key_map_[region::Meanline].first,
+ key_map_[region::Meanline].second,
+ attr_id, points,
+ outline_action_->isChecked(),
+ fill_action_->isChecked(),
+ precise_action_->isChecked(),
+ key_wgt_->isChecked(region::Meanline));
+
+ connect(this, SIGNAL(key_updated(int, bool)),
+ r, SLOT(setDrawIfSameId(int, bool)));
+ connect(this, SIGNAL(setOutline(bool)),
+ r, SLOT(setOutline(bool)));
+ connect(this, SIGNAL(setPrecise(bool)),
+ r, SLOT(setPrecise(bool)));
+ connect(this, SIGNAL(setFill(bool)),
+ r, SLOT(setFill(bool)));
+
+ scene_->addItem(r);
+ }
+}
+
+
void
Viewer::load_xml(QString filename)
{
@@ -557,7 +653,11 @@ Viewer::load_xml(QString filename)
if (!line.isNull())
{
if (extended_mode_)
- add_region(line, attr_id);
+ {
+ QString line_id = line.toElement().attribute("id", "none");
+ add_region(line, line_id);
+ add_typo_lines(line, line_id);
+ }
add_text(line);
}
}
diff --git a/scribo/demo/viewer/viewer.hh b/scribo/demo/viewer/viewer.hh
index c4b99e8..c68dd02 100644
--- a/scribo/demo/viewer/viewer.hh
+++ b/scribo/demo/viewer/viewer.hh
@@ -84,6 +84,7 @@ private:
QPixmap load_base64(QString xml);
void add_region(QDomNode father, QString attr_id);
void add_text(QDomNode line);
+ void add_typo_lines(QDomNode father, QString attr_id);
QAction *create_action(QString name, QMenu* menu, QString status, QString shortcut);
void reset_progress_dialog();
void configure_printer(QPrinter& printer);
--
1.5.6.5