* scribo/demo/viewer/Makefile.am
* demo/viewer/image_region.cc,
* viewer/image_region.hh,
* viewer/image_region.hxx: Change regions depths to have a hierarchy.
* demo/viewer/image_scene.cc,
* demo/viewer/image_scene.hh: Change mouse click behaviour.
* demo/viewer/key_widget.cc,
* demo/viewer/key_widget.hh: Add new items (text line and paragraph)
* demo/viewer/viewer.cc,
* demo/viewer/viewer.hh: Chnage XML parsing to support extended format.
* scribo/demo/viewer/common.hh: Add new RegionId's.
---
scribo/ChangeLog | 23 +++-
scribo/demo/viewer/Makefile.am | 9 +-
scribo/demo/viewer/common.hh | 26 ++--
scribo/demo/viewer/image_region.cc | 23 ++-
scribo/demo/viewer/image_region.hh | 2 +
scribo/demo/viewer/image_region.hxx | 15 +-
scribo/demo/viewer/image_scene.cc | 72 +++++---
scribo/demo/viewer/image_scene.hh | 2 +
scribo/demo/viewer/key_widget.cc | 29 +++-
scribo/demo/viewer/key_widget.hh | 3 +-
scribo/demo/viewer/viewer.cc | 346 +++++++++++++++++++++++++++--------
scribo/demo/viewer/viewer.hh | 10 +-
12 files changed, 434 insertions(+), 126 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 9b8392e..6cab6a1 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,9 +1,30 @@
2010-06-30 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
+ Extended XML mode support.
+
+ * scribo/demo/viewer/Makefile.am
+
+ * demo/viewer/image_region.cc,
+ * viewer/image_region.hh,
+ * viewer/image_region.hxx: Change regions depths to have a hierarchy.
+
+ * demo/viewer/image_scene.cc,
+ * demo/viewer/image_scene.hh: Change mouse click behaviour.
+
+ * demo/viewer/key_widget.cc,
+ * demo/viewer/key_widget.hh: Add new items (text line and paragraph)
+
+ * demo/viewer/viewer.cc,
+ * demo/viewer/viewer.hh: Chnage XML parsing to support extended format.
+
+ * scribo/demo/viewer/common.hh: Add new RegionId's.
+
+2010-06-30 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
+
New features in Qt interface.
* demo/viewer/browser_widget.hh: Improve picture browser.
- * demo/viewer/step_widget.cc Add a "step chooser" to load several XML files
related to one picture.
+ * demo/viewer/step_widget.cc: Add a "step chooser" to load several XML files
related to one picture.
2010-06-30 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
diff --git a/scribo/demo/viewer/Makefile.am b/scribo/demo/viewer/Makefile.am
index 0a6213a..a0112c6 100644
--- a/scribo/demo/viewer/Makefile.am
+++ b/scribo/demo/viewer/Makefile.am
@@ -28,7 +28,8 @@ viewer_SOURCES = $(BUILT_SOURCES) \
dommodel.cc \
domitem.cc \
image_region.cc \
- help_dialog.cc
+ help_dialog.cc \
+ step_widget.cc
viewer_CPPFLAGS = $(QT_CPPFLAGS) $(AM_CPPFLAGS) -I$(srcdir)
viewer_CXXFLAGS = $(QT_CXXFLAGS) $(AM_CXXFLAGS) -O3
@@ -46,7 +47,8 @@ BUILT_SOURCES = viewer.moc.cc \
dommodel.moc.cc \
domitem.moc.cc \
image_region.moc.cc \
- help_dialog.moc.cc
+ help_dialog.moc.cc \
+ step_widget.moc.cc
include_HEADERS = viewer.hh \
viewer.hxx \
@@ -62,6 +64,7 @@ include_HEADERS = viewer.hh \
image_region.hh \
image_region.hxx \
common.hh \
- help_dialog.hh
+ help_dialog.hh \
+ step_widget.hh
EXTRA_DIST = README
diff --git a/scribo/demo/viewer/common.hh b/scribo/demo/viewer/common.hh
index ba4f3b1..346ea51 100644
--- a/scribo/demo/viewer/common.hh
+++ b/scribo/demo/viewer/common.hh
@@ -20,17 +20,19 @@ namespace region
typedef QVector<QPair<QString, QColor> > KeyMap;
enum RegionId
- {
- Text = 0,
- Image,
- Noise,
- Separator,
- Table,
- LineDrawing,
- Graphic,
- Chart,
- Maths
- };
-};
+ {
+ Text = 0,
+ Paragraph,
+ Line,
+ Image,
+ Noise,
+ Separator,
+ Table,
+ LineDrawing,
+ Graphic,
+ Chart,
+ Maths
+ };
+}
#endif /* !COMMON_HH_ */
diff --git a/scribo/demo/viewer/image_region.cc b/scribo/demo/viewer/image_region.cc
index f2e9970..04e3c9b 100644
--- a/scribo/demo/viewer/image_region.cc
+++ b/scribo/demo/viewer/image_region.cc
@@ -35,10 +35,15 @@ ImageRegion::ImageRegion(region::RegionId id,
fill_(fill),
draw_(draw),
selected_(false),
- alpha_(30)
+ alpha_(50)
{
setCursor(Qt::ArrowCursor);
- setZValue(1);
+ if (id_ == region::Paragraph)
+ setZValue(2);
+ else if (id_ == region::Line)
+ setZValue(3);
+ else
+ setZValue(1);
if (points.size() == 0)
return;
@@ -57,6 +62,11 @@ ImageRegion::~ImageRegion()
{
}
+region::RegionId ImageRegion::id()
+{
+ return id_;
+}
+
void
ImageRegion::paint(QPainter* painter,
const QStyleOptionGraphicsItem*,
@@ -103,7 +113,7 @@ ImageRegion::select()
if (!selected_)
{
selected_ = true;
- setZValue(2);
+ setZValue(4);
prepareGeometryChange();
scene()->invalidate();
update();
@@ -116,7 +126,12 @@ ImageRegion::deselect()
if (selected_)
{
selected_ = false;
- setZValue(1);
+ if (id_ == region::Paragraph)
+ setZValue(2);
+ else if (id_ == region::Line)
+ setZValue(3);
+ else
+ setZValue(1);
prepareGeometryChange();
scene()->invalidate();
update();
diff --git a/scribo/demo/viewer/image_region.hh b/scribo/demo/viewer/image_region.hh
index 7f65c02..38aecb4 100644
--- a/scribo/demo/viewer/image_region.hh
+++ b/scribo/demo/viewer/image_region.hh
@@ -36,6 +36,7 @@ public:
~ImageRegion();
+ region::RegionId id();
void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget = 0);
@@ -43,6 +44,7 @@ public:
const QModelIndex& index() const;
QRectF boundingRect() const;
QPainterPath shape() const;
+ QString name() { return name_; }
public slots:
void setOutline(bool outline);
diff --git a/scribo/demo/viewer/image_region.hxx b/scribo/demo/viewer/image_region.hxx
index de8ec11..50dc93d 100644
--- a/scribo/demo/viewer/image_region.hxx
+++ b/scribo/demo/viewer/image_region.hxx
@@ -56,9 +56,14 @@ void
ImageRegion::setDrawIfSameId(int id, bool draw)
{
if (id == id_)
- draw_ = draw;
- scene()->invalidate();
- update();
+ {
+ draw_ = draw;
+ if (scene())
+ {
+ scene()->invalidate();
+ update();
+ }
+ }
}
inline
@@ -73,8 +78,8 @@ inline
QRectF
ImageRegion::boundingRect() const
{
- if (selected_)
- return mapFromScene(scene()->sceneRect()).boundingRect();
+// if (selected_)
+// return mapFromScene(scene()->sceneRect()).boundingRect();
return rect_;
}
diff --git a/scribo/demo/viewer/image_scene.cc b/scribo/demo/viewer/image_scene.cc
index 14eac76..bbc75c3 100644
--- a/scribo/demo/viewer/image_scene.cc
+++ b/scribo/demo/viewer/image_scene.cc
@@ -31,30 +31,58 @@ void
ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
QGraphicsScene::mousePressEvent(event);
- ImageRegion* item = dynamic_cast<ImageRegion*>(itemAt(event->pos()));
- if (item)
- {
- if (item != selected_)
- {
- if (selected_)
- {
- selected_->deselect();
- emit deselected(selected_->index());
- }
- selected_ = item;
- item->select();
- emit selected(item->index());
- }
- }
- else
- {
- if (selected_)
+ QList<QGraphicsItem *> items_list = items(event->pos()); // includes both
ImageRegions and the picture.
+
+ // Selection is under the mouse click (at event->pos()).
+ bool selection_is_clicked = items_list.contains(selected_);
+
+ foreach(QGraphicsItem* elt, items_list)
{
- selected_->deselect();
- emit deselected(selected_->index());
- selected_ = 0;
+ ImageRegion* item = dynamic_cast<ImageRegion*>(elt);
+ if (item)
+ {
+ if (item != selected_)
+ {
+ if (selected_)
+ {
+ if ( (item->boundingRect().intersects(selected_->boundingRect())))
+ {
+ int item_area = item->boundingRect().size().height() *
item->boundingRect().size().width();
+ int selected_area = selected_->boundingRect().size().height() *
selected_->boundingRect().size().width();
+
+ if (selected_area < item_area && selection_is_clicked)
+ return;
+ else
+ {
+ selected_->deselect();
+ emit deselected(selected_->index());
+ selected_ = 0;
+ }
+ }
+ else
+ {
+ selected_->deselect();
+ emit deselected(selected_->index());
+ selected_ = 0;
+ }
+ }
+ selected_ = item;
+ item->select();
+ emit selected(item->index());
+ return;
+ }
+ }
+ else
+ {
+ if ( (selected_)
+ && (items_list.size() == 1) )// no ImageRegion, only the picture
+ {
+ selected_->deselect();
+ emit deselected(selected_->index());
+ selected_ = 0;
+ }
+ }
}
- }
}
ImageScene::~ImageScene()
diff --git a/scribo/demo/viewer/image_scene.hh b/scribo/demo/viewer/image_scene.hh
index eb95462..64ab590 100644
--- a/scribo/demo/viewer/image_scene.hh
+++ b/scribo/demo/viewer/image_scene.hh
@@ -1,3 +1,4 @@
+
//
// Document layout viewer.
//
@@ -37,6 +38,7 @@ signals:
private:
ImageRegion* selected_;
+ QVector<ImageRegion*> region_vector_;
};
#endif /* !IMAGE_SCENE_HH_ */
diff --git a/scribo/demo/viewer/key_widget.cc b/scribo/demo/viewer/key_widget.cc
index af817b3..93c2cf0 100644
--- a/scribo/demo/viewer/key_widget.cc
+++ b/scribo/demo/viewer/key_widget.cc
@@ -26,7 +26,9 @@ KeyWidget::KeyWidget(const region::KeyMap& key_map)
layout->addWidget(items_);
for (int i = 0; i < key_map.size(); ++i)
- add_item_(key_map[i].first, key_map[i].second);
+ add_item_(key_map[i].first, key_map[i].second,
+ (i == region::Paragraph) ||
+ (i == region::Line) );
setLayout(layout);
@@ -34,8 +36,29 @@ KeyWidget::KeyWidget(const region::KeyMap& key_map)
this, SLOT(update(QListWidgetItem*)));
}
+void
+KeyWidget::change_mode(bool b)
+{
+ int id_region = region::Paragraph;
+ int id_line = region::Line;
+ if (b)
+ {
+ items_->item(id_region)->setCheckState(Qt::Checked);
+ items_->item(id_region)->setHidden(false);
+ items_->item(id_line)->setCheckState(Qt::Checked);
+ items_->item(id_line)->setHidden(false);
+ }
+ else
+ {
+ items_->item(id_region)->setCheckState(Qt::Unchecked);
+ items_->item(id_region)->setHidden(true);
+ items_->item(id_line)->setCheckState(Qt::Unchecked);
+ items_->item(id_line)->setHidden(true);
+ }
+}
+
void
-KeyWidget::add_item_(QString text, QColor color)
+KeyWidget::add_item_(QString text, QColor color, bool b)
{
QListWidgetItem* item = new QListWidgetItem(text);
QPixmap pixmap(10, 6);
@@ -44,6 +67,8 @@ KeyWidget::add_item_(QString text, QColor color)
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setCheckState(Qt::Checked);
items_->addItem(item);
+ int id = items_->row(item);
+ items_->item(id)->setHidden(b);
}
bool
diff --git a/scribo/demo/viewer/key_widget.hh b/scribo/demo/viewer/key_widget.hh
index 2f8a8c6..e5259e2 100644
--- a/scribo/demo/viewer/key_widget.hh
+++ b/scribo/demo/viewer/key_widget.hh
@@ -34,9 +34,10 @@ signals:
private slots:
void update(QListWidgetItem* slot);
+ void change_mode(bool b);
private:
- void add_item_(QString text, QColor color);
+ void add_item_(QString text, QColor color, bool b);
QListWidget* items_;
};
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index 622a805..8bafc39 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -18,6 +18,7 @@
#include "browser_widget.hh"
#include "image_widget.hh"
#include "xml_widget.hh"
+#include "step_widget.hh"
#include "image_scene.hh"
#include "image_region.hh"
#include "help_dialog.hh"
@@ -33,12 +34,16 @@ Viewer::Viewer(int &argc, char** argv)
scene_(new ImageScene()),
files_(new QDirModel()),
doc_layout_(0),
- key_map_(9),
- no_cache_(false)
+ key_map_(11),
+ no_cache_(false),
+ extended_mode_(false),
+ xml_file_(QString(""))
{
// Key map
- key_map_[region::Text] = qMakePair(tr("Text"), QColor(0, 200, 0));
+ 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));
key_map_[region::Noise] = qMakePair(tr("Noise"), QColor(43, 39, 128));
key_map_[region::Separator] = qMakePair(tr("Separator"), QColor(0, 0, 255));
@@ -52,6 +57,8 @@ 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;
region_ids_["separator_region"] = region::Separator;
@@ -96,6 +103,7 @@ Viewer::Viewer(int &argc, char** argv)
connect(fill_action_, SIGNAL(toggled(bool)),
this, SIGNAL(setFill(bool)));
option_menu->addAction(fill_action_);
+
QAction* cache_action = new QAction(tr("Disable cache"), file_menu);
cache_action->setStatusTip(tr("Disable the image cache (useful for"
" large images)."));
@@ -105,6 +113,15 @@ Viewer::Viewer(int &argc, char** argv)
this, SLOT(useCache(bool)));
option_menu->addAction(cache_action);
+ QAction* extended_action = new QAction(tr("Extended mode"), file_menu);
+ extended_action->setStatusTip(tr("If enabled, some features not supported by
ICDAR"
+ " are added such as text regions or text lines"));
+ extended_action->setCheckable(true);
+ extended_action->setChecked(false);
+ connect(extended_action, SIGNAL(toggled(bool)),
+ this, SLOT(useExtended(bool)));
+ option_menu->addAction(extended_action);
+
QMenu* help_menu = win_->menuBar()->addMenu(tr("Help"));
QAction* about_action = new QAction(tr("About"), help_menu);
about_action->setStatusTip(tr("About this program."));
@@ -116,6 +133,7 @@ Viewer::Viewer(int &argc, char** argv)
QSplitter* v_splitter = new QSplitter(Qt::Vertical);
QSplitter* v_splitter2 = new QSplitter(Qt::Vertical);
+ StepWidget* step_widget = new StepWidget();
PropertyWidget* property_wgt = new PropertyWidget();
XmlWidget* xml_wgt = new XmlWidget();
BrowserWidget* browser_wgt =
@@ -126,6 +144,7 @@ Viewer::Viewer(int &argc, char** argv)
scene_->setBackgroundBrush(scene_->palette().window());
v_splitter->addWidget(property_wgt);
+ v_splitter->addWidget(step_widget);
v_splitter->addWidget(key_wgt_);
v_splitter->addWidget(browser_wgt);
@@ -138,7 +157,7 @@ Viewer::Viewer(int &argc, char** argv)
win_->setCentralWidget(h_splitter);
QList<int> v_sizes;
- v_sizes << 300 << 200 << 500;
+ v_sizes << 300 << 200 << 200 << 300;
v_splitter->setSizes(v_sizes);
QList<int> v_sizes2;
@@ -150,15 +169,25 @@ Viewer::Viewer(int &argc, char** argv)
h_splitter->setSizes(h_sizes);
connect(browser_wgt, SIGNAL(activated(QString)),
+ step_widget, SLOT(fill_steps(QString)));
+
+ connect(step_widget, SIGNAL(load_image(QString)),
this, SLOT(load(QString)));
+ connect(step_widget, SIGNAL(load_xml(QString)),
+ this, SLOT(load_xml(QString)));
+
connect(this, SIGNAL(updated(DomModel*)),
property_wgt, SLOT(update(DomModel*)));
+ connect(this, SIGNAL(mode_changed(bool)),
+ key_wgt_, SLOT(change_mode(bool)));
connect(this, SIGNAL(updated(DomModel*)),
xml_wgt, SLOT(update(DomModel*)));
connect(this, SIGNAL(updated(DomModel*)),
image_wgt, SLOT(update()));
+
connect(key_wgt_, SIGNAL(updated(int, bool)),
this, SIGNAL(key_updated(int, bool)));
+
connect(scene_, SIGNAL(selected(QModelIndex)),
property_wgt, SLOT(select(QModelIndex)));
connect(scene_, SIGNAL(deselected(QModelIndex)),
@@ -167,36 +196,33 @@ Viewer::Viewer(int &argc, char** argv)
xml_wgt, SLOT(select(QModelIndex)));
connect(scene_, SIGNAL(deselected(QModelIndex)),
xml_wgt, SLOT(deselect(QModelIndex)));
+
connect(image_wgt, SIGNAL(scaleUpdated(qreal)),
this, SLOT(maybeChangeCacheMode(qreal)));
}
void
-Viewer::load(QString filename)
+Viewer::load_xml(QString filename)
{
+ QString xml_file = filename;
+ xml_file_ = filename;
+
app_->setOverrideCursor(QCursor(Qt::WaitCursor));
- scene_->clear();
- image_ = 0;
- // Load the image in a pixmap that is directly shown on screen.
- // This is very slow when used with the normal rendering system.
- // OpenGL might speed up things a bit.
- image_ = new QGraphicsPixmapItem(QPixmap(filename));
- image_->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
- image_->setZValue(0);
+ scene_->removeItem(image_);
+ scene_->clear();
scene_->addItem(image_);
+
+ scene_->update();
if (doc_layout_)
- {
- doc_layout_->deleteLater();
- doc_layout_ = 0;
- }
-
- // FIXME: Ugly
- QString xml_file = filename;
- xml_file.chop(4);
- xml_file += ".xml";
-
+ {
+ doc_layout_->deleteLater();
+ doc_layout_ = 0;
+ }
+
+ emit updated(doc_layout_);
+
if (QFile::exists(xml_file))
{
QFile file(xml_file);
@@ -207,70 +233,223 @@ Viewer::load(QString filename)
{
doc_layout_ = new DomModel(document, this);
}
+ else
+ {
+ app_->restoreOverrideCursor();
+ QMessageBox msgBox;
+ msgBox.setText("Error while loading the XML file, please choose another.");
+ msgBox.exec();
+ }
file.close();
}
}
+ xml_to_layout();
+
+ app_->restoreOverrideCursor();
+}
+
+void
+Viewer::xml_to_layout()
+{
// Add layout info to the scene.
if (doc_layout_)
- {
- QModelIndex pgGts = doc_layout_->index(1, 0);
- QModelIndex page = doc_layout_->index(1, 0, pgGts);
- QModelIndex region;
- QModelIndex attributes;
- QModelIndex coords;
- QModelIndex point;
- for (int i = 0; true; ++i)
{
- region = doc_layout_->index(i, 0, page);
- attributes = doc_layout_->index(i, 1, page);
- QString name = doc_layout_->data(region, Qt::DisplayRole).toString();
- region::RegionId id = static_cast<region::RegionId>(region_ids_[name]);
+ QModelIndex pgGts = doc_layout_->index(1, 0);
+ QModelIndex page = doc_layout_->index(1, 0, pgGts);
+ QModelIndex region;
+ QModelIndex attributes;
+ QModelIndex coords;
+ QModelIndex point;
+ for (int i = 0; true; ++i)
+ {
+ region = doc_layout_->index(i, 0, page);
+ attributes = doc_layout_->index(i, 1, page);
+ QString name = doc_layout_->data(region, Qt::DisplayRole).toString();
+ region::RegionId id = static_cast<region::RegionId>(region_ids_[name]);
+
+ coords = doc_layout_->index(0, 0, region);
+ if (!region.isValid() || !coords.isValid())
+ break;
+
+ QVector<QPoint> points;
+ for (int j = 0; true; ++j)
+ {
+ // Navigate to the coordinate list
+ point = doc_layout_->index(j, 1, coords);
+ if (!point.isValid())
+ break;
+
+ QMap<QString, QVariant> data =
+ doc_layout_->data(point, Qt::UserRole).toMap();
+ int x = data["x"].toInt();
+ int y = data["y"].toInt();
+ points << QPoint(x, y);
+ }
+
+ // Create region
+ ImageRegion* r = new ImageRegion(id,
+ key_map_[id].first,
+ key_map_[id].second,
+ attributes, points,
+ outline_action_->isChecked(),
+ fill_action_->isChecked(),
+ precise_action_->isChecked(),
+ key_wgt_->isChecked(id));
+
+ 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);
+
+ // EXTENDED MODE
+ if (extended_mode_)
+ {
+ for (int k = 1; true; ++k)
+ {
+ QModelIndex paragraph = doc_layout_->index(k, 0, region);
+ QModelIndex attributes_par = doc_layout_->index(k, 1, region);
+ if (!paragraph.isValid())
+ break;
+
+ QString name_par = doc_layout_->data(paragraph, Qt::DisplayRole).toString();
+ region::RegionId id_par =
static_cast<region::RegionId>(region_ids_[name_par]);
+
+ QDebug(&name_par) << name_par;
+
+ QModelIndex par_coords = doc_layout_->index(0, 0, paragraph);
+ QModelIndex point_par;
+ QVector<QPoint> points_par;
+ for (int m = 0; true; ++m)
+ {
+ // Navigate to the coordinate list
+ point_par = doc_layout_->index(m, 1, par_coords);
+ if (!point_par.isValid())
+ break;
+
+ QMap<QString, QVariant> data_par =
+ doc_layout_->data(point_par, Qt::UserRole).toMap();
+ int x = data_par["x"].toInt();
+ int y = data_par["y"].toInt();
+ points_par << QPoint(x, y);
+ }
+
+ // Create region
+ ImageRegion* r_par = new ImageRegion(id_par,
+ key_map_[id_par].first,
+ key_map_[id_par].second,
+ attributes_par, points_par,
+ outline_action_->isChecked(),
+ fill_action_->isChecked(),
+ precise_action_->isChecked(),
+ key_wgt_->isChecked(id_par));
+
+ connect(this, SIGNAL(key_updated(int, bool)),
+ r_par, SLOT(setDrawIfSameId(int, bool)));
+ connect(this, SIGNAL(setOutline(bool)),
+ r_par, SLOT(setOutline(bool)));
+ connect(this, SIGNAL(setPrecise(bool)),
+ r_par, SLOT(setPrecise(bool)));
+ connect(this, SIGNAL(setFill(bool)),
+ r_par, SLOT(setFill(bool)));
+
+ scene_->addItem(r_par);
+
+ for (int l = 1; true; ++l)
+ {
+ QModelIndex line = doc_layout_->index(l, 0, paragraph);
+ QModelIndex attributes_line = doc_layout_->index(l, 1, paragraph);
+ if (!line.isValid())
+ break;
+
+ QString name_line = doc_layout_->data(line, Qt::DisplayRole).toString();
+ region::RegionId id_line =
static_cast<region::RegionId>(region_ids_[name_line]);
+
+ QModelIndex line_coords = doc_layout_->index(0, 0, line);
+ QModelIndex point_line;
+ QVector<QPoint> points_line;
+ for (int n = 0; true; ++n)
+ {
+ // Navigate to the coordinate list
+ point_line = doc_layout_->index(n, 1, line_coords);
+ if (!point_line.isValid())
+ break;
+
+ QMap<QString, QVariant> data_line =
+ doc_layout_->data(point_line, Qt::UserRole).toMap();
+ int x = data_line["x"].toInt();
+ int y = data_line["y"].toInt();
+ points_line << QPoint(x, y);
+ }
+
+ // Create region
+ ImageRegion* r_line = new ImageRegion(id_line,
+ key_map_[id_line].first,
+ key_map_[id_line].second,
+ attributes_line, points_line,
+ outline_action_->isChecked(),
+ fill_action_->isChecked(),
+ precise_action_->isChecked(),
+ key_wgt_->isChecked(id_line));
+
+ connect(this, SIGNAL(key_updated(int, bool)),
+ r_line, SLOT(setDrawIfSameId(int, bool)));
+ connect(this, SIGNAL(setOutline(bool)),
+ r_line, SLOT(setOutline(bool)));
+ connect(this, SIGNAL(setPrecise(bool)),
+ r_line, SLOT(setPrecise(bool)));
+ connect(this, SIGNAL(setFill(bool)),
+ r_line, SLOT(setFill(bool)));
+
+ scene_->addItem(r_line);
+ }
+ }
+ }
+ // END OF EXTENDED MODE
+
+ }
+
+ emit updated(doc_layout_);
+ }
+}
- coords = doc_layout_->index(0, 0, region);
- if (!region.isValid() || !coords.isValid())
- break;
+void
+Viewer::load(QString filename)
+{
+ app_->setOverrideCursor(QCursor(Qt::WaitCursor));
+ scene_->clear();
+ scene_->update();
+ image_ = 0;
+ xml_file_ = "";
- QVector<QPoint> points;
- for (int j = 0; true; ++j)
- {
- // Navigate to the coordinate list
- point = doc_layout_->index(j, 1, coords);
- if (!point.isValid())
- break;
-
- QMap<QString, QVariant> data =
- doc_layout_->data(point, Qt::UserRole).toMap();
- int x = data["x"].toInt();
- int y = data["y"].toInt();
- points << QPoint(x, y);
- }
+ // Load the image in a pixmap that is directly shown on screen.
+ // This is very slow when used with the normal rendering system.
+ // OpenGL might speed up things a bit.
+ image_ = new QGraphicsPixmapItem(QPixmap(filename));
+ image_->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
+ image_->setZValue(0);
+ scene_->addItem(image_);
- // Create region
- ImageRegion* r = new ImageRegion(id,
- key_map_[id].first,
- key_map_[id].second,
- attributes, points,
- outline_action_->isChecked(),
- fill_action_->isChecked(),
- precise_action_->isChecked(),
- key_wgt_->isChecked(id));
-
- 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);
- }
- }
+ if (no_cache_)
+ image_->setCacheMode(QGraphicsItem::NoCache);
+ else
+ image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
- emit updated(doc_layout_);
+ if (doc_layout_)
+ {
+ doc_layout_->deleteLater();
+ doc_layout_ = 0;
+ }
app_->restoreOverrideCursor();
+
+ emit updated(doc_layout_);
}
int
@@ -299,10 +478,27 @@ Viewer::maybeChangeCacheMode(qreal scale)
}
}
+void Viewer::useExtended(bool b)
+{
+ extended_mode_ = b;
+ if (xml_file_ != QString(""))
+ load_xml(xml_file_);
+
+ emit mode_changed (b);
+}
+
void
Viewer::useCache(bool b)
{
no_cache_ = b;
if (b)
- image_->setCacheMode(QGraphicsItem::NoCache);
+ {
+ if (image_)
+ image_->setCacheMode(QGraphicsItem::NoCache);
+ }
+ else
+ if (image_)
+ image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
+
+// LocalWords: hh
diff --git a/scribo/demo/viewer/viewer.hh b/scribo/demo/viewer/viewer.hh
index d579847..d13ef91 100644
--- a/scribo/demo/viewer/viewer.hh
+++ b/scribo/demo/viewer/viewer.hh
@@ -21,6 +21,7 @@
class ImageScene;
class DomModel;
class KeyWidget;
+class ImageRegion;
class Viewer
: public QObject
@@ -39,21 +40,26 @@ public slots:
// name is found.
void load(QString filename);
void help();
-
+ void load_xml(QString filename);
void maybeChangeCacheMode(qreal scale);
void useCache(bool b);
+ void useExtended(bool b);
signals:
void updated(DomModel* model);
+ void loaded(DomModel* model);
void key_updated(int key, bool checked);
void setOutline(bool b);
void setPrecise(bool b);
void setFill(bool b);
+ void mode_changed(bool b);
private:
Viewer(int &argc, char** argv);
Viewer();
+ void xml_to_layout();
+
QApplication* app_;
QMainWindow* win_;
@@ -73,6 +79,8 @@ private:
region::KeyMap key_map_;
bool no_cache_;
+ bool extended_mode_;
+ QString xml_file_;
};
#include "viewer.hxx"
--
1.5.6.5