Commit 7fd561dd authored by Florent D'Halluin's avatar Florent D'Halluin Committed by Guillaume Lazzara
Browse files

Add Document Layout Viewer.

* viewer/Makefile.am,
* viewer/README,
* viewer/browser_widget.cc,
* viewer/browser_widget.hh,
* viewer/common.hh,
* viewer/domitem.cc,
* viewer/domitem.hh,
* viewer/dommodel.cc,
* viewer/dommodel.hh,
* viewer/help_dialog.cc,
* viewer/help_dialog.hh,
* viewer/image_region.cc,
* viewer/image_region.hh,
* viewer/image_region.hxx,
* viewer/image_scene.cc,
* viewer/image_scene.hh,
* viewer/image_view.cc,
* viewer/image_view.hh,
* viewer/image_widget.cc,
* viewer/image_widget.hh,
* viewer/key_widget.cc,
* viewer/key_widget.hh,
* viewer/main.cc,
* viewer/property_widget.cc,
* viewer/property_widget.hh,
* viewer/viewer.cc,
* viewer/viewer.hh,
* viewer/viewer.hxx,
* viewer/xml_widget.cc,
* viewer/xml_widget.hh:
New.
parent 5c627b01
##
## 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 $(top_srcdir)/build-aux/autotroll.mk
bin_PROGRAMS = viewer
viewer_SOURCES = $(BUILT_SOURCES) \
viewer.cc \
main.cc \
image_widget.cc \
xml_widget.cc \
key_widget.cc \
property_widget.cc \
browser_widget.cc \
image_scene.cc \
image_view.cc \
dommodel.cc \
domitem.cc \
image_region.cc \
help_dialog.cc
viewer_CPPFLAGS = $(QT_CPPFLAGS) $(AM_CPPFLAGS) -I$(srcdir)
viewer_CXXFLAGS = $(QT_CXXFLAGS) $(AM_CXXFLAGS) -O3
viewer_LDFLAGS = $(QT_LDFLAGS) $(LDFLAGS)
viewer_LDADD = $(QT_LIBS) $(LDADD)
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
include_HEADERS = viewer.hh \
viewer.hxx \
image_widget.hh \
xml_widget.hh \
key_widget.hh \
property_widget.hh \
browser_widget.hh \
image_scene.hh \
image_view.hh \
dommodel.hh \
domitem.hh \
image_region.hh \
image_region.hxx \
common.hh \
help_dialog.hh
EXTRA_DIST = README
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.
__________________________________________________________________
Document Layout Viewer
Purpose:
- Display layout information about image documents.
Contact:
d-halluin@lrde.epita.fr
Usage:
- Get XML layout descriptions (PAGE format, ICDAR2009).
- Put XML and image files in the same directory, with the same name.
- Select an image within the application.
- Click on regions to display their attributes.
Infos:
- Everything is read-only.
- The DOM Model classes are a slightly modified Qt example.
//
// 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 "browser_widget.hh"
BrowserWidget::BrowserWidget(QDirModel* files)
: files_(files),
view_(new QListView()),
path_(new QLabel(""))
{
QLabel* title = new QLabel(tr("Images"));
title->setAlignment(Qt::AlignHCenter);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(title);
layout->addWidget(path_);
layout->addWidget(view_);
setLayout(layout);
view_->setModel(files);
files->setFilter(QDir::AllDirs | QDir::Files
| QDir::Readable | QDir::Drives);
view_->setRootIndex(files->index(QDir::currentPath()));
view_->setRowHidden(0, true);
path_->setText(files->filePath(view_->rootIndex()));
connect(view_, SIGNAL(activated(const QModelIndex&)),
this, SLOT(activate(const QModelIndex&)));
QStringList files_filters;
files_filters << "*.png" << "*.jpg"
<< "*.tif" << "*.ppm" << "*.pgm";
files->setNameFilters(files_filters);
}
void
BrowserWidget::activate(const QModelIndex& index)
{
if (files_->isDir(index))
{
view_->setRootIndex(index);
view_->setRowHidden(0, true);
path_->setText(files_->filePath(view_->rootIndex()));
return;
}
emit activated(files_->filePath(index));
}
BrowserWidget::~BrowserWidget()
{
}
//
// 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 BROWSER_WIDGET_HH_
# define BROWSER_WIDGET_HH_
# include <QtGui>
class BrowserWidget
: public QWidget
{
Q_OBJECT
public:
BrowserWidget(QDirModel* files);
~BrowserWidget();
public slots:
void activate(const QModelIndex& index);
signals:
void activated(QString filename);
private:
QDirModel* files_;
QListView* view_;
QLabel* path_;
};
#endif /* !BROWSER_WIDGET_HH_ */
//
// 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 COMMON_HH_
# define COMMON_HH_
namespace region
{
typedef QVector<QPair<QString, QColor> > KeyMap;
enum RegionId
{
Text = 0,
Image,
Noise,
Separator,
Table,
LineDrawing,
Graphic,
Chart,
Maths
};
};
#endif /* !COMMON_HH_ */
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@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@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;
}
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@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@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
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@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@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();
}
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@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