* demo/viewer/property_widget.cc,
* demo/viewer/property_widget.hh,
* demo/viewer/domitem.cc,
* demo/viewer/domitem.hh,
* demo/viewer/dommodel.cc,
* demo/viewer/dommodel.hh: Delete.
* demo/viewer/Makefile.am
* demo/viewer/browser_widget.cc: Fix, xmlc extension instead of xmle.
* demo/viewer/key_widget.cc,
* demo/viewer/step_widget.cc,
* demo/viewer/step_widget.hh,
* demo/viewer/image_scene.cc,
* demo/viewer/image_scene.hh,
* demo/viewer/help_dialog.cc,
* demo/viewer/image_region.cc,
* demo/viewer/image_region.hh,
* demo/viewer/image_region.hxx: Small changes.
* demo/viewer/viewer.cc,
* demo/viewer/viewer.hh: Add base 64 cropped pictures support, text viewer
and change XML parsing.
* demo/viewer/xml_widget.cc,
* demo/viewer/xml_widget.hh: Change widget, tree and attributes are together.
---
scribo/ChangeLog | 33 ++
scribo/demo/viewer/Makefile.am | 5 +-
scribo/demo/viewer/browser_widget.cc | 2 +-
scribo/demo/viewer/domitem.cc | 98 ------
scribo/demo/viewer/domitem.hh | 75 -----
scribo/demo/viewer/dommodel.cc | 198 ------------
scribo/demo/viewer/dommodel.hh | 85 -----
scribo/demo/viewer/help_dialog.cc | 6 +-
scribo/demo/viewer/image_region.cc | 6 +-
scribo/demo/viewer/image_region.hh | 9 +-
scribo/demo/viewer/image_region.hxx | 7 -
scribo/demo/viewer/image_scene.cc | 20 +-
scribo/demo/viewer/image_scene.hh | 4 +-
scribo/demo/viewer/key_widget.cc | 2 +-
scribo/demo/viewer/property_widget.cc | 73 -----
scribo/demo/viewer/property_widget.hh | 41 ---
scribo/demo/viewer/step_widget.cc | 4 +-
scribo/demo/viewer/step_widget.hh | 1 +
scribo/demo/viewer/viewer.cc | 547 +++++++++++++++++++--------------
scribo/demo/viewer/viewer.hh | 15 +-
scribo/demo/viewer/xml_widget.cc | 143 ++++++++-
scribo/demo/viewer/xml_widget.hh | 15 +-
22 files changed, 545 insertions(+), 844 deletions(-)
delete mode 100644 scribo/demo/viewer/domitem.cc
delete mode 100644 scribo/demo/viewer/domitem.hh
delete mode 100644 scribo/demo/viewer/dommodel.cc
delete mode 100644 scribo/demo/viewer/dommodel.hh
delete mode 100644 scribo/demo/viewer/property_widget.cc
delete mode 100644 scribo/demo/viewer/property_widget.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 1c9bdbd..0d78dc7 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,36 @@
+2010-07-20 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+
+ Some changes in XML interface.
+
+ * demo/viewer/property_widget.cc,
+ * demo/viewer/property_widget.hh,
+ * demo/viewer/domitem.cc,
+ * demo/viewer/domitem.hh,
+ * demo/viewer/dommodel.cc,
+ * demo/viewer/dommodel.hh: Delete.
+
+ * demo/viewer/Makefile.am
+
+ * demo/viewer/browser_widget.cc: Fix, xmlc extension instead of xmle.
+
+ * demo/viewer/key_widget.cc,
+ * demo/viewer/step_widget.cc,
+ * demo/viewer/step_widget.hh,
+ * demo/viewer/image_scene.cc,
+ * demo/viewer/image_scene.hh,
+ * demo/viewer/help_dialog.cc,
+ * demo/viewer/image_region.cc,
+ * demo/viewer/image_region.hh,
+ * demo/viewer/image_region.hxx: Small changes.
+
+ * demo/viewer/viewer.cc,
+ * demo/viewer/viewer.hh: Add base 64 cropped pictures support, text viewer
+ and change XML parsing.
+
+ * demo/viewer/xml_widget.cc,
+ * demo/viewer/xml_widget.hh: Change widget, tree and attributes are together.
+
+
2010-07-16 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
Base 64 support in Qt interface (xmlc extension)
diff --git a/scribo/demo/viewer/Makefile.am b/scribo/demo/viewer/Makefile.am
index eec19b9..d0f0d6f 100644
--- a/scribo/demo/viewer/Makefile.am
+++ b/scribo/demo/viewer/Makefile.am
@@ -14,6 +14,7 @@
include $(top_srcdir)/build-aux/autotroll.mk
+
bin_PROGRAMS = scribo-viewer
scribo_viewer_SOURCES = $(BUILT_SOURCES) \
viewer.cc \
@@ -40,16 +41,14 @@ BUILT_SOURCES = viewer.moc.cc \
image_widget.moc.cc \
xml_widget.moc.cc \
key_widget.moc.cc \
- property_widget.moc.cc \
browser_widget.moc.cc \
image_scene.moc.cc \
image_view.moc.cc \
- dommodel.moc.cc \
- domitem.moc.cc \
image_region.moc.cc \
help_dialog.moc.cc \
step_widget.moc.cc
+
noinst_HEADERS = viewer.hh \
viewer.hxx \
image_widget.hh \
diff --git a/scribo/demo/viewer/browser_widget.cc b/scribo/demo/viewer/browser_widget.cc
index 220a719..43de1e2 100644
--- a/scribo/demo/viewer/browser_widget.cc
+++ b/scribo/demo/viewer/browser_widget.cc
@@ -68,7 +68,7 @@ BrowserWidget::BrowserWidget(QDirModel* files, QString dir)
files_filters << "*.png" << "*.jpg"
<< "*.tif" << "*.ppm"
<< "*.pgm" << "*.pbm"
- << "*.pnm" << "*.xmle";
+ << "*.pnm" << "*.xmlc";
files->setNameFilters(files_filters);
}
diff --git a/scribo/demo/viewer/domitem.cc b/scribo/demo/viewer/domitem.cc
deleted file mode 100644
index 66e989a..0000000
--- a/scribo/demo/viewer/domitem.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#include <QtXml>
-
-#include "domitem.hh"
-
-DomItem::DomItem(QDomNode &node, int row, DomItem *parent)
-{
- domNode = node;
- // Record the item's location within its parent.
- rowNumber = row;
- parentItem = parent;
-}
-
-DomItem::~DomItem()
-{
- QHash<int,DomItem*>::iterator it;
- for (it = childItems.begin(); it != childItems.end(); ++it)
- delete it.value();
-}
-
-QDomNode DomItem::node() const
-{
- return domNode;
-}
-
-DomItem *DomItem::parent()
-{
- return parentItem;
-}
-
-DomItem *DomItem::child(int i)
-{
- if (childItems.contains(i))
- return childItems[i];
-
- if (i >= 0 && i < domNode.childNodes().count()) {
- QDomNode childNode = domNode.childNodes().item(i);
- DomItem *childItem = new DomItem(childNode, i, this);
- childItems[i] = childItem;
- return childItem;
- }
- return 0;
-}
-
-int DomItem::row()
-{
- return rowNumber;
-}
diff --git a/scribo/demo/viewer/domitem.hh b/scribo/demo/viewer/domitem.hh
deleted file mode 100644
index a5c22cc..0000000
--- a/scribo/demo/viewer/domitem.hh
+++ /dev/null
@@ -1,75 +0,0 @@
- /****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#ifndef DOMITEM_H
-#define DOMITEM_H
-
-#include <QDomNode>
-#include <QHash>
-
-class DomItem
-{
-public:
- DomItem(QDomNode &node, int row, DomItem *parent = 0);
- ~DomItem();
- DomItem *child(int i);
- DomItem *parent();
- QDomNode node() const;
- int row();
-
-private:
- QDomNode domNode;
- QHash<int,DomItem*> childItems;
- DomItem *parentItem;
- int rowNumber;
-};
-
-#endif
diff --git a/scribo/demo/viewer/dommodel.cc b/scribo/demo/viewer/dommodel.cc
deleted file mode 100644
index baaf9a7..0000000
--- a/scribo/demo/viewer/dommodel.cc
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#include <QtGui>
-#include <QtXml>
-
-#include "domitem.hh"
-#include "dommodel.hh"
-
-DomModel::DomModel(QDomDocument document, QObject *parent)
- : QAbstractItemModel(parent), domDocument(document)
-{
- rootItem = new DomItem(domDocument, 0);
-}
-
-DomModel::~DomModel()
-{
- delete rootItem;
-}
-
-int DomModel::columnCount(const QModelIndex &/*parent*/) const
-{
- return 3;
-}
-
-QVariant DomModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- DomItem *item = static_cast<DomItem*>(index.internalPointer());
- QDomNode node = item->node();
- QDomNamedNodeMap attributeMap = node.attributes();
-
- if (role == Qt::DisplayRole)
- {
- QStringList attributes;
-
- switch (index.column())
- {
- case 0:
- return node.nodeName();
- case 1:
- for (int i = 0; i < attributeMap.count(); ++i)
- {
- QDomNode attribute = attributeMap.item(i);
- attributes << attribute.nodeName() + "=\""
- + attribute.nodeValue() + "\"";
- }
- return attributes.join(" ");
- case 2:
- return node.nodeValue().split("\n").join(" ");
- default:
- return QVariant();
- }
- }
- else if (role == Qt::UserRole)
- {
- QMap<QString, QVariant> attributes;
- switch (index.column())
- {
- case 1:
- for (int i = 0; i < attributeMap.count(); ++i)
- {
- QDomNode attribute = attributeMap.item(i);
- attributes[attribute.nodeName()] = attribute.nodeValue();
- }
- return attributes;
- default:
- return QVariant();
- }
- }
- return QVariant();
-}
-
-Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return 0;
-
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-}
-
-QVariant DomModel::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
- switch (section) {
- case 0:
- return tr("Name");
- case 1:
- return tr("Attributes");
- case 2:
- return tr("Value");
- default:
- return QVariant();
- }
- }
-
- return QVariant();
-}
-
-QModelIndex DomModel::index(int row, int column, const QModelIndex &parent)
- const
-{
- if (!hasIndex(row, column, parent))
- return QModelIndex();
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-
- DomItem *childItem = parentItem->child(row);
- if (childItem)
- return createIndex(row, column, childItem);
- else
- return QModelIndex();
-}
-
-QModelIndex DomModel::parent(const QModelIndex &child) const
-{
- if (!child.isValid())
- return QModelIndex();
-
- DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
- DomItem *parentItem = childItem->parent();
-
- if (!parentItem || parentItem == rootItem)
- return QModelIndex();
-
- return createIndex(parentItem->row(), 0, parentItem);
-}
-
-int DomModel::rowCount(const QModelIndex &parent) const
-{
- if (parent.column() > 0)
- return 0;
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-
- return parentItem->node().childNodes().count();
-}
diff --git a/scribo/demo/viewer/dommodel.hh b/scribo/demo/viewer/dommodel.hh
deleted file mode 100644
index 16c5a23..0000000
--- a/scribo/demo/viewer/dommodel.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#ifndef DOMMODEL_H
-#define DOMMODEL_H
-
-#include <QAbstractItemModel>
-#include <QDomDocument>
-#include <QModelIndex>
-#include <QVariant>
-
-class DomItem;
-
-class DomModel : public QAbstractItemModel
-{
- Q_OBJECT
-
- public:
- DomModel(QDomDocument document, QObject *parent = 0);
- ~DomModel();
-
- QVariant data(const QModelIndex &index, int role) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex &child) const;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
-
-private:
- QDomDocument domDocument;
- DomItem *rootItem;
-};
-
-#endif
diff --git a/scribo/demo/viewer/help_dialog.cc b/scribo/demo/viewer/help_dialog.cc
index fe59d93..3ac5614 100644
--- a/scribo/demo/viewer/help_dialog.cc
+++ b/scribo/demo/viewer/help_dialog.cc
@@ -35,10 +35,8 @@ HelpDialog::HelpDialog()
" select regions to display their properties.\n"
" - Use the mouse or keyboard to move and zoom\n"
" (Arrows, PageUp, PageDown, Home, End).\n"
- "\n"
- "Contact: d-halluin(a)lrde.epita.fr\n"
- "\n"
- "Copyright Florent D'Halluin, 2009.\n");
+ "\n");
+
QLabel* label = new QLabel(help);
diff --git a/scribo/demo/viewer/image_region.cc b/scribo/demo/viewer/image_region.cc
index 04e3c9b..78b636c 100644
--- a/scribo/demo/viewer/image_region.cc
+++ b/scribo/demo/viewer/image_region.cc
@@ -17,7 +17,7 @@
ImageRegion::ImageRegion(region::RegionId id,
QString name,
QColor color,
- QModelIndex index,
+ QString attr_id,
const QVector<QPoint>& points,
bool outline,
bool fill,
@@ -27,7 +27,7 @@ ImageRegion::ImageRegion(region::RegionId id,
id_(id),
name_(name),
color_(color),
- index_(index),
+ attr_id_(attr_id),
shape_(),
rect_(),
outline_(outline),
@@ -65,7 +65,7 @@ ImageRegion::~ImageRegion()
region::RegionId ImageRegion::id()
{
return id_;
-}
+}
void
ImageRegion::paint(QPainter* painter,
diff --git a/scribo/demo/viewer/image_region.hh b/scribo/demo/viewer/image_region.hh
index 38aecb4..be1003d 100644
--- a/scribo/demo/viewer/image_region.hh
+++ b/scribo/demo/viewer/image_region.hh
@@ -27,7 +27,7 @@ public:
ImageRegion(region::RegionId id,
QString name,
QColor color,
- QModelIndex index,
+ QString attr_id,
const QVector<QPoint>& points,
bool outline,
bool fill,
@@ -36,15 +36,16 @@ public:
~ImageRegion();
- region::RegionId id();
+ region::RegionId id();
void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget = 0);
- const QModelIndex& index() const;
QRectF boundingRect() const;
QPainterPath shape() const;
QString name() { return name_; }
+ QRectF rect() { return rect_; }
+ QString attr_id() { return attr_id_; }
public slots:
void setOutline(bool outline);
@@ -60,7 +61,7 @@ private:
region::RegionId id_;
QString name_;
QColor color_;
- QModelIndex index_;
+ QString attr_id_;
QPainterPath shape_;
QRectF rect_;
bool outline_;
diff --git a/scribo/demo/viewer/image_region.hxx b/scribo/demo/viewer/image_region.hxx
index efcf493..0d23426 100644
--- a/scribo/demo/viewer/image_region.hxx
+++ b/scribo/demo/viewer/image_region.hxx
@@ -91,11 +91,4 @@ ImageRegion::shape() const
return shape_;
}
-inline
-const QModelIndex&
-ImageRegion::index() const
-{
- return index_;
-}
-
#endif /* !IMAGE_REGION_HXX_ */
diff --git a/scribo/demo/viewer/image_scene.cc b/scribo/demo/viewer/image_scene.cc
index 62b4b46..dd9d67e 100644
--- a/scribo/demo/viewer/image_scene.cc
+++ b/scribo/demo/viewer/image_scene.cc
@@ -31,7 +31,17 @@ void
ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
QGraphicsScene::mousePressEvent(event);
- QList<QGraphicsItem *> items_list = items(event->pos()); // includes both
ImageRegions and the picture.
+ QList<QGraphicsItem *> items_list = items(event->scenePos()); // includes both
ImageRegions and the picture.
+
+ if (items_list.isEmpty())
+ {
+ if (selected_)
+ {
+ selected_->deselect();
+ emit deselected();
+ selected_ = 0;
+ }
+ }
// Selection is under the mouse click (at event->pos()).
bool selection_is_clicked = items_list.contains(selected_);
@@ -55,20 +65,20 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
else
{
selected_->deselect();
- emit deselected(selected_->index());
+ emit deselected();
selected_ = 0;
}
}
else
{
selected_->deselect();
- emit deselected(selected_->index());
+ emit deselected();
selected_ = 0;
}
}
selected_ = item;
item->select();
- emit selected(item->index());
+ emit selected(item->attr_id(), item->name());
return;
}
}
@@ -78,7 +88,7 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
&& (items_list.size() == 1) )// no ImageRegion, only the picture
{
selected_->deselect();
- emit deselected(selected_->index());
+ emit deselected();
selected_ = 0;
}
}
diff --git a/scribo/demo/viewer/image_scene.hh b/scribo/demo/viewer/image_scene.hh
index 64ab590..6fb2c1f 100644
--- a/scribo/demo/viewer/image_scene.hh
+++ b/scribo/demo/viewer/image_scene.hh
@@ -33,8 +33,8 @@ public:
void clear();
signals:
- void selected(const QModelIndex& index);
- void deselected(const QModelIndex& index);
+ void selected(QString, QString);
+ void deselected();
private:
ImageRegion* selected_;
diff --git a/scribo/demo/viewer/key_widget.cc b/scribo/demo/viewer/key_widget.cc
index 47203c3..171c811 100644
--- a/scribo/demo/viewer/key_widget.cc
+++ b/scribo/demo/viewer/key_widget.cc
@@ -128,7 +128,7 @@ KeyWidget::update(QTreeWidgetItem* item)
int id;
id = text_->indexOfChild(item);
if (id == -1)
- id = regions_->indexOfChild(item) + 3;
+ id = regions_->indexOfChild(item) + 4;
emit updated(id, item->checkState(0) == Qt::Checked);
diff --git a/scribo/demo/viewer/property_widget.cc
b/scribo/demo/viewer/property_widget.cc
deleted file mode 100644
index 3d2f4d5..0000000
--- a/scribo/demo/viewer/property_widget.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#include "property_widget.hh"
-
-#include "dommodel.hh"
-
-PropertyWidget::PropertyWidget()
- : view_(new QTreeWidget()),
- model_(0)
-{
- QLabel* title = new QLabel(tr("Properties"));
- title->setAlignment(Qt::AlignHCenter);
-
- QVBoxLayout* layout = new QVBoxLayout;
- layout->addWidget(title);
- layout->addWidget(view_);
-
- view_->setColumnCount(2);
- view_->setSortingEnabled(true);
- view_->setRootIsDecorated(false);
- QStringList header_names;
- header_names << tr("Name") << tr("Value");
- view_->setHeaderItem(new QTreeWidgetItem(header_names));
-
- setLayout(layout);
-}
-
-void
-PropertyWidget::update(DomModel* model)
-{
- model_ = model;
-}
-
-void
-PropertyWidget::select(const QModelIndex& index)
-{
- if (!index.isValid())
- return;
-
- QMap<QString, QVariant> data =
- model_->data(index, Qt::UserRole).toMap();
-
- for (QMap<QString, QVariant>::iterator i = data.begin();
- i != data.end();
- ++i)
- {
- QStringList values;
- values << i.key() << i.value().toString();
- view_->addTopLevelItem(new QTreeWidgetItem(values));
- }
-}
-
-void
-PropertyWidget::deselect(const QModelIndex&)
-{
- view_->clear();
-}
-
-PropertyWidget::~PropertyWidget()
-{
-}
diff --git a/scribo/demo/viewer/property_widget.hh
b/scribo/demo/viewer/property_widget.hh
deleted file mode 100644
index fc4c755..0000000
--- a/scribo/demo/viewer/property_widget.hh
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#ifndef PROPERTY_WIDGET_HH_
-# define PROPERTY_WIDGET_HH_
-
-# include <QtGui>
-
-class DomModel;
-
-class PropertyWidget
- : public QWidget
-{
- Q_OBJECT
-
-public:
- PropertyWidget();
- ~PropertyWidget();
-
-public slots:
- void update(DomModel* model);
- void select(const QModelIndex& index);
- void deselect(const QModelIndex& index);
-
-private:
- QTreeWidget* view_;
- DomModel* model_;
-};
-
-#endif /* !PROPERTY_WIDGET_HH_ */
diff --git a/scribo/demo/viewer/step_widget.cc b/scribo/demo/viewer/step_widget.cc
index 207796d..010b270 100644
--- a/scribo/demo/viewer/step_widget.cc
+++ b/scribo/demo/viewer/step_widget.cc
@@ -75,11 +75,13 @@ void StepWidget::fill_steps(QString file, bool step, bool container)
if (container)
{
- emit load_image(file, true);
+ emit change_base(true);
+ // emit load_image(file, true);
emit load_xml(file);
}
else
{
+ emit change_base(false);
// image is loaded once
emit load_image(file, false);
diff --git a/scribo/demo/viewer/step_widget.hh b/scribo/demo/viewer/step_widget.hh
index 32602b0..c5d77df 100644
--- a/scribo/demo/viewer/step_widget.hh
+++ b/scribo/demo/viewer/step_widget.hh
@@ -45,6 +45,7 @@ signals:
void load_image(QString, bool);
void load_xml(QString);
void activated(QListWidgetItem*);
+ void change_base(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 e5ec717..090bb1b 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -1,19 +1,29 @@
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
-// Document layout viewer.
+// This file is part of Olena.
//
-// Copyright (C) 2009 Florent D'Halluin.
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
#include "viewer.hh"
-#include "property_widget.hh"
#include "key_widget.hh"
#include "browser_widget.hh"
#include "image_widget.hh"
@@ -22,8 +32,7 @@
#include "image_scene.hh"
#include "image_region.hh"
#include "help_dialog.hh"
-
-#include "dommodel.hh"
+#include <limits.h>
#include "common.hh"
@@ -37,7 +46,10 @@ Viewer::Viewer(int &argc, char** argv)
key_map_(11),
no_cache_(false),
extended_mode_(false),
- xml_file_(QString(""))
+ xml_file_(QString::Null()),
+ base64_(false),
+ text_(true),
+ use_image_(true)
{
// Key map
@@ -123,6 +135,23 @@ Viewer::Viewer(int &argc, char** argv)
this, SLOT(useExtended(bool)));
option_menu->addAction(extended_action);
+ QAction* show_image_action = new QAction(tr("Show pictures"), file_menu);
+ //show_image_action->setStatusTip(tr(""));
+
+ show_image_action->setCheckable(true);
+ show_image_action->setChecked(true);
+ connect(show_image_action, SIGNAL(toggled(bool)),
+ this, SLOT(useImage(bool)));
+ option_menu->addAction(show_image_action);
+
+ QAction* show_text_action = new QAction(tr("Show text"), file_menu);
+ show_text_action->setStatusTip(tr("Show detected text inside boxes."));
+ show_text_action->setCheckable(true);
+ show_text_action->setChecked(true);
+ connect(show_text_action, SIGNAL(toggled(bool)),
+ this, SLOT(useText(bool)));
+ option_menu->addAction(show_text_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."));
@@ -135,7 +164,6 @@ Viewer::Viewer(int &argc, char** argv)
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 =
new BrowserWidget(files_, argc != 2 ? QString() : argv[1]);
@@ -144,7 +172,6 @@ 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);
@@ -158,280 +185,302 @@ Viewer::Viewer(int &argc, char** argv)
win_->setCentralWidget(h_splitter);
QList<int> v_sizes;
- v_sizes << 200 << 200 << 300 << 400;
+ v_sizes << 200 << 300 << 300;
v_splitter->setSizes(v_sizes);
QList<int> v_sizes2;
- v_sizes2 << 500 << 100;
+ v_sizes2 << 650 << 150;
v_splitter2->setSizes(v_sizes2);
QList<int> h_sizes;
- h_sizes << 200 << 700;
+ h_sizes << 200 << 900;
h_splitter->setSizes(h_sizes);
connect(browser_wgt, SIGNAL(activated(QString, bool, bool)),
step_widget, SLOT(fill_steps(QString, bool, bool)));
+ connect(step_widget, SIGNAL(change_base(bool)),
+ this, SLOT(change_base(bool)));
connect(step_widget, SIGNAL(load_image(QString, bool)),
this, SLOT(load(QString, bool)));
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*)),
+ connect(this, SIGNAL(updated()),
image_wgt, SLOT(update()));
+ connect(this, SIGNAL(fill_xml(QString)),
+ xml_wgt, SLOT(fill_widget(QString)));
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)),
- property_wgt, SLOT(deselect(QModelIndex)));
- connect(scene_, SIGNAL(selected(QModelIndex)),
- xml_wgt, SLOT(select(QModelIndex)));
- connect(scene_, SIGNAL(deselected(QModelIndex)),
- xml_wgt, SLOT(deselect(QModelIndex)));
+ connect(scene_, SIGNAL(selected(QString, QString)),
+ xml_wgt, SLOT(select(QString, QString)));
+ connect(scene_, SIGNAL(deselected()),
+ xml_wgt, SLOT(deselect()));
connect(image_wgt, SIGNAL(scaleUpdated(qreal)),
this, SLOT(maybeChangeCacheMode(qreal)));
}
+
void
-Viewer::load_xml(QString filename)
+Viewer::add_text(QDomNode line, QDomNode region)
{
- QString xml_file = filename;
- xml_file_ = filename;
- app_->setOverrideCursor(QCursor(Qt::WaitCursor));
+ 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();
- scene_->removeItem(image_);
- scene_->clear();
- scene_->addItem(image_);
+ if (d_height < 0)
+ d_height = -d_height;
- scene_->update();
+ if ( (a_height - x_height) < (d_height))
+ a_height = x_height + d_height;
+
+ if ( (a_height - x_height) > (d_height))
+ d_height = a_height - x_height;
+
+ QDomNode coords = region.firstChild();
+
+ while (!coords.isNull() &&
!coords.toElement().tagName().contains("coords"))
+ coords = coords.nextSibling();
+
+ if (coords.isNull())
+ return;
+
+ QDomNode point = coords.firstChild();
- if (doc_layout_)
+ int x_min = INT_MAX;
+ int y_min = INT_MAX;
+
+ while (!point.isNull())
{
- doc_layout_->deleteLater();
- doc_layout_ = 0;
+ int x = point.toElement().attribute("x", "0").toInt();
+ int y = point.toElement().attribute("y", "0").toInt();
+
+ if (x < x_min)
+ x_min = x;
+
+ if (y < y_min)
+ y_min = y;
+
+ point = point.nextSibling();
}
- emit updated(doc_layout_);
+ QString text = line.toElement().attribute("text", "none");
+ QFont font("Times");
+ font.setPixelSize(a_height + d_height);
+ QGraphicsTextItem* text_item = scene_->addText(text, font);
+ text_item->setPos(x_min, y_min);
+ text_vector_ << text_item;
+ if (!text_)
+ scene_->removeItem(text_item);
- if (QFile::exists(xml_file))
- {
- QFile file(xml_file);
- if (file.open(QIODevice::ReadOnly))
+}
+
+void
+Viewer::add_region(QDomNode father, QString attr_id)
+{
+ QDomNode coords = father.firstChild();
+ QString name = father.toElement().tagName();
+ region::RegionId id = static_cast<region::RegionId>(region_ids_[name]);
+
+ 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())
{
- QDomDocument document;
- if (document.setContent(&file))
- {
- 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();
- }
- }
+ int x = point.toElement().attribute("x", "0").toInt();
+ int y = point.toElement().attribute("y", "0").toInt();
- xml_to_layout();
+ points << QPoint(x, y);
+ point = point.nextSibling();
+ }
- app_->restoreOverrideCursor();
+ ImageRegion* r = new ImageRegion(id,
+ key_map_[id].first,
+ key_map_[id].second,
+ attr_id, 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);
}
void
-Viewer::xml_to_layout()
+Viewer::load_xml(QString filename)
{
+ text_vector_.clear();
+ image_vector_.clear();
- /* /!\ XML parsing is VERY UGLY /!\
- TO DO: use same parsing as xml_transfrom. */
+ app_->setOverrideCursor(QCursor(Qt::WaitCursor));
+ emit fill_xml(filename);
+
+ if (image_ && image_->scene() && image_->scene() == scene_)
+ scene_->removeItem(image_);
+
+ scene_->clear();
+ if (!base64_ && use_image_)
+ scene_->addItem(image_);
- // Add layout info to the scene.
- if (doc_layout_)
+ scene_->update();
+
+ xml_file_ = filename;
+ QFile f_in(xml_file_);
+ f_in.open(QIODevice::ReadOnly);
+
+ QDomDocument doc;
+ doc.setContent(&f_in);
+ f_in.close();
+
+ QDomElement root = doc.documentElement();
+ QDomNode page = root.firstChild();
+
+ while (!page.isNull() &&
!page.toElement().tagName().contains("page"))
+ page = page.nextSibling();
+
+ if (page.isNull())
+ return;
+
+ int width = page.toElement().attribute("image_width",
"none").toInt();
+ int height = page.toElement().attribute("image_height",
"none").toInt();
+
+ scene_->setSceneRect(0, 0, width, height);
+
+ QDomNode region = page.firstChild();
+
+ while (!region.isNull())
{
- 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)
+ if
(region.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table|text)_region")))
+ {
+ QString attr_id = region.toElement().attribute("id", "none");
+ add_region(region, attr_id);
+
+ if ( base64_ &&
+
region.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table)_region")))
{
- // Navigate to the coordinate list
- point = doc_layout_->index(j, 1, coords);
- if (!point.isValid())
- break;
+ QDomNode container = region.firstChild();
- QMap<QString, QVariant> data =
- doc_layout_->data(point, Qt::UserRole).toMap();
- int x = data["x"].toInt();
- int y = data["y"].toInt();
+ while (!container.isNull() &&
!container.toElement().tagName().contains("container"))
+ container = container.nextSibling();
- points << QPoint(x, y);
- }
+ QDomNode coords = region.firstChild();
- // 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)
+ while (!coords.isNull() &&
!coords.toElement().tagName().contains("coords"))
+ coords = coords.nextSibling();
+
+ if (!container.isNull() && !coords.isNull())
{
- QModelIndex paragraph = doc_layout_->index(k, 0, region);
- QModelIndex attributes_par = doc_layout_->index(k, 1, region);
- if (!paragraph.isValid())
- break;
+ QDomNode child = container.firstChild();
- QString name_par = doc_layout_->data(paragraph, Qt::DisplayRole).toString();
- region::RegionId id_par =
static_cast<region::RegionId>(region_ids_[name_par]);
+ while (!child.isNull() &&
!child.toElement().tagName().contains("data"))
+ child = child.nextSibling();
- QDebug(&name_par) << name_par;
+ QPixmap pix;
+ QString data = child.toElement().text();
+ QByteArray ba;
+ ba = ba.append(data);
+ QByteArray out_ba = QByteArray::fromBase64(ba);
+ pix.loadFromData(out_ba);
- QModelIndex par_coords = doc_layout_->index(0, 0, paragraph);
- QModelIndex point_par;
+ QGraphicsPixmapItem* image = new QGraphicsPixmapItem(pix);
- QVector<QPoint> points_par;
- for (int m = 0; true; ++m)
+ QDomNode point = coords.firstChild();
+
+ int x_min = INT_MAX;
+ int y_min = INT_MAX;
+
+ while (!point.isNull())
{
- // 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);
+ int x = point.toElement().attribute("x", "0").toInt();
+ int y = point.toElement().attribute("y", "0").toInt();
+
+ if (x < x_min)
+ x_min = x;
+
+ if (y < y_min)
+ y_min = y;
+
+ point = point.nextSibling();
}
- // 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)
+ image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
+ image->setZValue(0);
+ image->setOffset(x_min, y_min);
+ if (use_image_)
+ scene_->addItem(image);
+ image_vector_ << image;
+
+ if (no_cache_)
+ image->setCacheMode(QGraphicsItem::NoCache);
+ else
+ image->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+
+ child = child.nextSibling();
+ }
+ }
+
+ if (extended_mode_ &&
+ region.toElement().tagName().contains("text_region"))
+ {
+ QDomNode para = region.firstChild();
+ while (!para.isNull() &&
!para.toElement().tagName().contains("paragraph"))
+ para = para.nextSibling();
+
+ if (!para.isNull())
+ {
+ add_region(para, attr_id);
+
+ QDomNode line = para.firstChild();
+ while (!line.isNull() &&
!line.toElement().tagName().contains("line"))
+ line = line.nextSibling();
+
+ if (!line.isNull())
{
- 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);
+ add_region(line, attr_id);
+ add_text(line, region);
}
}
}
- // END OF EXTENDED MODE
- }
+ }
- emit updated(doc_layout_);
- key_wgt_->update_all();
+ region = region.nextSibling();
}
+
+ emit updated();
+ scene_->update();
+ key_wgt_->update_all();
+
+ app_->restoreOverrideCursor();
}
void
Viewer::load(QString filename, bool b)
{
app_->setOverrideCursor(QCursor(Qt::WaitCursor));
+
scene_->clear();
scene_->update();
image_ = 0;
@@ -443,24 +492,21 @@ Viewer::load(QString filename, bool b)
image_ = new QGraphicsPixmapItem(load_base64(filename));
else
image_ = new QGraphicsPixmapItem(QPixmap(filename));
+
image_->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
image_->setZValue(0);
- scene_->addItem(image_);
+ if (use_image_)
+ scene_->addItem(image_);
if (no_cache_)
image_->setCacheMode(QGraphicsItem::NoCache);
else
image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
- if (doc_layout_)
- {
- doc_layout_->deleteLater();
- doc_layout_ = 0;
- }
-
app_->restoreOverrideCursor();
+ emit updated();
- emit updated(doc_layout_);
+ app_->restoreOverrideCursor();
}
int
@@ -493,10 +539,11 @@ void Viewer::useExtended(bool b)
{
extended_mode_ = b;
key_wgt_->update_all();
- if (xml_file_ != QString(""))
+
+ if (xml_file_ != QString::Null())
load_xml(xml_file_);
- emit mode_changed (b);
+ emit mode_changed(b);
}
void
@@ -557,4 +604,54 @@ QPixmap Viewer::load_base64(QString xml)
return pix;
}
-// LocalWords: hh
+void
+Viewer::useText(bool b)
+{
+ text_ = b;
+ if (!b)
+ {
+ for (int i = 0; i < text_vector_.size(); ++i)
+ scene_->removeItem(text_vector_[i]);
+ }
+ else
+ {
+ for (int i = 0; i < text_vector_.size(); ++i)
+ scene_->addItem(text_vector_[i]);
+ }
+
+ emit updated();
+ scene_->update();
+}
+
+void
+Viewer::useImage(bool b)
+{
+ use_image_ = b;
+ if (!b)
+ {
+ if (image_ && image_->scene() && image_->scene() == scene_)
+ scene_->removeItem(image_);
+
+ for (int i = 0; i < image_vector_.size(); ++i)
+ scene_->removeItem(image_vector_[i]);
+ }
+ else
+ {
+ if (image_ && image_->scene() == 0)
+ scene_->addItem(image_);
+
+ for (int i = 0; i < image_vector_.size(); ++i)
+ scene_->addItem(image_vector_[i]);
+ }
+
+
+
+ emit updated();
+ scene_->update();
+}
+
+void
+Viewer::change_base(bool b)
+{
+ base64_ = b;
+}
diff --git a/scribo/demo/viewer/viewer.hh b/scribo/demo/viewer/viewer.hh
index 7093da8..800bdd5 100644
--- a/scribo/demo/viewer/viewer.hh
+++ b/scribo/demo/viewer/viewer.hh
@@ -17,6 +17,7 @@
# include <QtGui>
# include "common.hh"
+# include <QDomNode>
class ImageScene;
class DomModel;
@@ -44,15 +45,18 @@ public slots:
void maybeChangeCacheMode(qreal scale);
void useCache(bool b);
void useExtended(bool b);
+ void useText(bool b);
+ void useImage(bool b);
+ void change_base(bool b);
signals:
- void updated(DomModel* model);
- void loaded(DomModel* model);
+ void updated();
void key_updated(int key, bool checked);
void setOutline(bool b);
void setPrecise(bool b);
void setFill(bool b);
void mode_changed(bool b);
+ void fill_xml(QString);
private:
Viewer(int &argc, char** argv);
@@ -60,6 +64,8 @@ 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);
QApplication* app_;
QMainWindow* win_;
@@ -82,6 +88,11 @@ private:
bool no_cache_;
bool extended_mode_;
QString xml_file_;
+ bool base64_;
+ bool text_;
+ bool use_image_;
+ QVector<QGraphicsTextItem *> text_vector_;
+ QVector<QGraphicsPixmapItem*> image_vector_;
};
#include "viewer.hxx"
diff --git a/scribo/demo/viewer/xml_widget.cc b/scribo/demo/viewer/xml_widget.cc
index 36f0406..a4ef2f6 100644
--- a/scribo/demo/viewer/xml_widget.cc
+++ b/scribo/demo/viewer/xml_widget.cc
@@ -14,39 +14,160 @@
#include "xml_widget.hh"
-#include "dommodel.hh"
-
XmlWidget::XmlWidget()
- : view_(new QTreeView()),
- model_(0)
+ : tree_(new QTreeWidget()),
+ property_(new QTreeWidget())
{
QLabel* title = new QLabel(tr("XML"));
title->setAlignment(Qt::AlignHCenter);
+ tree_->setHeaderHidden(true);
+
QVBoxLayout* layout = new QVBoxLayout;
+ QHBoxLayout *hlayout = new QHBoxLayout;
+
+ QStringList header_names;
+ header_names << tr("Name") << tr("Value");
+ property_->setHeaderItem(new QTreeWidgetItem(header_names));
+
+ hlayout->addWidget(tree_);
+ hlayout->addWidget(property_);
layout->addWidget(title);
- layout->addWidget(view_);
+ layout->addLayout(hlayout);
setLayout(layout);
+
+ connect(tree_, SIGNAL(itemDoubleClicked (QTreeWidgetItem*, int)),
+ this, SLOT(check_item (QTreeWidgetItem*) ) );
}
void
-XmlWidget::update(DomModel* model)
+XmlWidget::select(QString id, QString name)
{
- view_->setModel(model);
- // view_->resizeColumnToContents(2);
+ 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 (!n.isNull())
+ {
+ QTreeWidgetItem* item = node_map_.key(n);
+
+ tree_->setCurrentItem(item, 0);
+ item->setExpanded(true);
+ check_item(item);
+ }
}
void
-XmlWidget::select(const QModelIndex& index)
+XmlWidget::check_item (QTreeWidgetItem* item)
{
- view_->setCurrentIndex(index);
+ QDomNode node = node_map_[item];
+
+ if (node.hasAttributes())
+ {
+ property_->clear();
+ QDomNamedNodeMap attributes = node.toElement().attributes();
+
+ for (int i = 0; i < attributes.count(); ++i)
+ {
+ QStringList values;
+ values << attributes.item(i).toAttr().name() <<
attributes.item(i).toAttr().value();
+ property_->addTopLevelItem(new QTreeWidgetItem(values));
+ }
+ }
+
+ property_->resizeColumnToContents(0);
+}
+
+void XmlWidget::NFS(QDomNode node, QTreeWidgetItem* item)
+{
+ if (!node.isNull())
+ {
+ QString append;
+ if (node.toElement().tagName().contains("point"))
+ {
+ QString x = node.toElement().attribute("x", "0");
+ QString y = node.toElement().attribute("y", "0");
+ append.append(" = (" + x + ", " + y + ")");
+ }
+
+ QTreeWidgetItem* child =
+ new QTreeWidgetItem(QStringList(node.toElement().tagName() + node.nodeValue() +
append));
+
+ if (node.hasAttributes())
+ {
+ QString id = node.toElement().attribute("id", "none");
+ item_map_[id] = child;
+ }
+
+ node_map_[child] = node;
+ item->addChild(child);
+
+ QDomNode sibling = node.firstChild();
+ while (!sibling.isNull())
+ {
+ if (!sibling.toElement().tagName().contains("data"))
+ NFS(sibling, child);
+ sibling = sibling.nextSibling();
+ }
+ }
+}
+
+void XmlWidget::fill_widget(QString xml)
+{
+ node_map_.clear();
+ item_map_.clear();
+
+ tree_->clear();
+ property_->clear();
+ QFile f_in(xml);
+ f_in.open(QIODevice::ReadOnly);
+
+ QDomDocument doc;
+ doc.setContent(&f_in);
+ f_in.close();
+
+ int i = 0;
+
+ QDomElement root = doc.documentElement();
+ QTreeWidgetItem* root_item=
+ new QTreeWidgetItem(QStringList(root.tagName()));
+
+ tree_->addTopLevelItem(root_item);
+ root = root.firstChild().toElement();
+
+ while (!root.isNull())
+ {
+ ++i;
+ NFS(root, root_item);
+ root = root.nextSibling().toElement();
+ }
}
void
-XmlWidget::deselect(const QModelIndex&)
+XmlWidget::deselect()
{
+ property_->clear();
}
XmlWidget::~XmlWidget()
diff --git a/scribo/demo/viewer/xml_widget.hh b/scribo/demo/viewer/xml_widget.hh
index b3de3fa..c56a736 100644
--- a/scribo/demo/viewer/xml_widget.hh
+++ b/scribo/demo/viewer/xml_widget.hh
@@ -16,6 +16,7 @@
# define XML_WIDGET_HH_
# include <QtGui>
+# include <QDomNode>
class DomModel;
@@ -29,13 +30,17 @@ public:
~XmlWidget();
public slots:
- void update(DomModel* model);
- void select(const QModelIndex& index);
- void deselect(const QModelIndex& index);
+ void select(QString id, QString name);
+ void deselect();
+ void fill_widget(QString xml);
+ void check_item (QTreeWidgetItem* item);
private:
- QTreeView* view_;
- DomModel* model_;
+ void NFS(QDomNode node, QTreeWidgetItem* item);
+ QTreeWidget* tree_;
+ QTreeWidget* property_;
+ QMap<QString, QTreeWidgetItem*> item_map_;
+ QMap<QTreeWidgetItem*, QDomNode> node_map_;
};
#endif /* !XML_WIDGET_HH_ */
--
1.5.6.5