Commit d7ea2d35 authored by Arthur Crepin-Leblond's avatar Arthur Crepin-Leblond Committed by Guillaume Lazzara
Browse files

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.
parent 6d0a92e1
2010-07-20 Arthur Crepin-Leblond <crepin@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@ptaouchnok.lrde.epita.fr>
Base 64 support in Qt interface (xmlc extension)
......
......@@ -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 \
......
......@@ -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);
}
......
/****************************************************************************
**
** 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
** 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 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
......@@ -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@lrde.epita.fr\n"
"\n"
"Copyright Florent D'Halluin, 2009.\n");
"\n");
QLabel* label = new QLabel(help);
......
......@@ -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,
......
......@@ -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_;
......
......@@ -91,11 +91,4 @@ ImageRegion::shape() const
return shape_;
}
inline
const QModelIndex&
ImageRegion::index() const
{
return index_;
}
#endif /* !IMAGE_REGION_HXX_ */
......@@ -31,7 +31,17 @@ void
ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)