---
Test2/Region.h | 12 ++++++
Test2/Test2.pro | 7 ++-
Test2/Test2.pro.user | 40 +++++++++---------
Test2/customgraphicsitem.h | 18 ++++++++
Test2/customgraphicsview.cpp | 70 +++++++++++++++++++++++++++++++++
Test2/customgraphicsview.h | 35 ++++++++++++++++
Test2/customviewport.cpp | 6 +++
Test2/customviewport.h | 15 +++++++
Test2/debug.xml | 6 +++
Test2/graphicsregion.cpp | 14 +++++++
Test2/graphicsregion.h | 18 ++++++++
Test2/selectionpicture.cpp | 6 +++
Test2/selectionpicture.h | 13 ++++++
Test2/test2.cpp | 2 +
Test2/xml.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++
Test2/xml.h | 21 ++++++++++
16 files changed, 350 insertions(+), 22 deletions(-)
create mode 100644 Test2/Region.h
create mode 100644 Test2/customgraphicsitem.h
create mode 100644 Test2/customgraphicsview.cpp
create mode 100644 Test2/customgraphicsview.h
create mode 100644 Test2/customviewport.cpp
create mode 100644 Test2/customviewport.h
create mode 100644 Test2/debug.xml
create mode 100644 Test2/graphicsregion.cpp
create mode 100644 Test2/graphicsregion.h
create mode 100644 Test2/selectionpicture.cpp
create mode 100644 Test2/selectionpicture.h
create mode 100644 Test2/xml.cpp
create mode 100644 Test2/xml.h
diff --git a/Test2/Region.h b/Test2/Region.h
new file mode 100644
index 0000000..f4f4dd2
--- /dev/null
+++ b/Test2/Region.h
@@ -0,0 +1,12 @@
+#ifndef REGION_H
+#define REGION_H
+
+struct Text
+{
+};
+
+struct
+
+struct
+
+#endif // REGION_H
diff --git a/Test2/Test2.pro b/Test2/Test2.pro
index 3c20cfe..c2f0814 100644
--- a/Test2/Test2.pro
+++ b/Test2/Test2.pro
@@ -7,9 +7,12 @@ SOURCES += main.cpp \
test2.cpp \
picture.cpp \
customgraphicsview.cpp \
- xml.cpp
+ xml.cpp \
+ graphicsregion.cpp
HEADERS += test2.h \
picture.h \
customgraphicsview.h \
- xml.h
+ xml.h \
+ graphicsregion.h
FORMS += test2.ui
+QT += xml
diff --git a/Test2/Test2.pro.user b/Test2/Test2.pro.user
index 373596f..7e3c285 100644
--- a/Test2/Test2.pro.user
+++ b/Test2/Test2.pro.user
@@ -118,35 +118,35 @@
<valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName"
type="QString">Qt dans le PATH Debug</value>
<valuelist key="abstractProcess.Environment"
type="QVariantList">
- <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-paONMmMzu5,guid=50af68fe79cb2c7af74bdeaf0056c626</value>
+ <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-JY6dCjQGUb,guid=ce62a2610f9ec8cf68471053005813f4</value>
<value type="QString">DESKTOP_SESSION=fluxbox</value>
<value type="QString">DISPLAY=:0.0</value>
<value type="QString">GDMSESSION=fluxbox</value>
<value type="QString">GDM_LANG=fr_FR.UTF-8</value>
<value type="QString">GDM_XSERVER_LOCATION=local</value>
- <value
type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-b0p70j</value>
- <value type="QString">GNOME_KEYRING_PID=438</value>
+ <value
type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-TwjTUn</value>
+ <value type="QString">GNOME_KEYRING_PID=30663</value>
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
<value type="QString">HOME=/lrde/home/stage/froger_a</value>
<value type="QString">LANG=fr_FR.UTF-8</value>
<value
type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
<value type="QString">LOGNAME=froger_a</value>
- <value
type="QString">OLDPWD=/lrde/home/stage/froger_a/QT</value>
+ <value type="QString">OLDPWD=/lrde/home/stage/froger_a</value>
<value
type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value>
<value
type="QString">PWD=/lrde/home/stage/froger_a/QT/Test2</value>
<value type="QString">QTDIR=/usr/share/qt4</value>
<value type="QString">SHELL=/bin/bash</value>
<value type="QString">SHLVL=2</value>
- <value type="QString">SSH_AGENT_PID=513</value>
- <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-oHzmzjh447/agent.447</value>
+ <value type="QString">SSH_AGENT_PID=30738</value>
+ <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-nOqCI30672/agent.30672</value>
<value type="QString">TERM=xterm</value>
<value type="QString">USER=froger_a</value>
<value type="QString">USERNAME=froger_a</value>
- <value type="QString">WINDOWID=16777252</value>
- <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8</value>
- <value type="QString">XAUTHORITY=/tmp/.gdmGH9MQW</value>
+ <value type="QString">WINDOWID=10485796</value>
+ <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8</value>
+ <value type="QString">XAUTHORITY=/tmp/.gdmSXRMQW</value>
<value
type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value>
- <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357734634.5267-1601039943</value>
+ <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357820088.248297-1165703853</value>
<value type="QString">XPSERVERLIST=:64 </value>
<value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value>
<value type="QString">XTERM_SHELL=/bin/bash</value>
@@ -170,35 +170,35 @@
<valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName"
type="QString">Qt dans le PATH Debug</value>
<valuelist key="abstractProcess.Environment"
type="QVariantList">
- <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-paONMmMzu5,guid=50af68fe79cb2c7af74bdeaf0056c626</value>
+ <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-JY6dCjQGUb,guid=ce62a2610f9ec8cf68471053005813f4</value>
<value type="QString">DESKTOP_SESSION=fluxbox</value>
<value type="QString">DISPLAY=:0.0</value>
<value type="QString">GDMSESSION=fluxbox</value>
<value type="QString">GDM_LANG=fr_FR.UTF-8</value>
<value type="QString">GDM_XSERVER_LOCATION=local</value>
- <value
type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-b0p70j</value>
- <value type="QString">GNOME_KEYRING_PID=438</value>
+ <value
type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-TwjTUn</value>
+ <value type="QString">GNOME_KEYRING_PID=30663</value>
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
<value type="QString">HOME=/lrde/home/stage/froger_a</value>
<value type="QString">LANG=fr_FR.UTF-8</value>
<value
type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
<value type="QString">LOGNAME=froger_a</value>
- <value
type="QString">OLDPWD=/lrde/home/stage/froger_a/QT</value>
+ <value type="QString">OLDPWD=/lrde/home/stage/froger_a</value>
<value
type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value>
<value
type="QString">PWD=/lrde/home/stage/froger_a/QT/Test2</value>
<value type="QString">QTDIR=/usr/share/qt4</value>
<value type="QString">SHELL=/bin/bash</value>
<value type="QString">SHLVL=2</value>
- <value type="QString">SSH_AGENT_PID=513</value>
- <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-oHzmzjh447/agent.447</value>
+ <value type="QString">SSH_AGENT_PID=30738</value>
+ <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-nOqCI30672/agent.30672</value>
<value type="QString">TERM=xterm</value>
<value type="QString">USER=froger_a</value>
<value type="QString">USERNAME=froger_a</value>
- <value type="QString">WINDOWID=16777252</value>
- <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8</value>
- <value type="QString">XAUTHORITY=/tmp/.gdmGH9MQW</value>
+ <value type="QString">WINDOWID=10485796</value>
+ <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8</value>
+ <value type="QString">XAUTHORITY=/tmp/.gdmSXRMQW</value>
<value
type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value>
- <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357734634.5267-1601039943</value>
+ <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357820088.248297-1165703853</value>
<value type="QString">XPSERVERLIST=:64 </value>
<value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value>
<value type="QString">XTERM_SHELL=/bin/bash</value>
diff --git a/Test2/customgraphicsitem.h b/Test2/customgraphicsitem.h
new file mode 100644
index 0000000..688071b
--- /dev/null
+++ b/Test2/customgraphicsitem.h
@@ -0,0 +1,18 @@
+#ifndef CUSTOMGRAPHICSITEM_H
+#define CUSTOMGRAPHICSITEM_H
+
+#include <QGraphicsItem>
+#include <QRectF>
+#include <QPainter>
+
+class customGraphicsItem : public QGraphicsItem
+{
+ public:
+ customGraphicsItem(QRectF rectangle);
+ //void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget
*widget);
+
+ private:
+ QRectF rectangle;
+};
+
+#endif // CUSTOMGRAPHICSITEM_H
diff --git a/Test2/customgraphicsview.cpp b/Test2/customgraphicsview.cpp
new file mode 100644
index 0000000..d5e6120
--- /dev/null
+++ b/Test2/customgraphicsview.cpp
@@ -0,0 +1,70 @@
+#include "picture.h"
+#include "customgraphicsview.h"
+
+CustomGraphicsView::CustomGraphicsView(QTextEdit *textEdit)
+{
+ this->textEdit = textEdit;
+ color.setRgb(100, 200, 60, 100);
+ isPress = false;
+}
+
+QString CustomGraphicsView::mousePressPrinter()
+{
+ return "Mouse Press Position On View : " + QString::number(pressPos.x()) +
", " + QString::number(pressPos.y());
+}
+
+QString CustomGraphicsView::mouseReleasePrinter()
+{
+ return "Mouse Press Position On View : " + QString::number(pressPos.x()) +
", " + QString ::number(pressPos.y()) +
+ "\nMouse Release Position On View : " +
QString::number(releasePos.x()) + ", " + QString::number(releasePos.y());
+}
+
+QString CustomGraphicsView::mouseMovePrinter(qreal x, qreal y)
+{
+ return "Mouse Position On View : " + QString::number(x) + ", " +
QString::number(y);
+}
+
+void CustomGraphicsView::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && !isPress)
+ {
+ pressPos = event->posF();
+ rectangle.setX(pressPos.x());
+ rectangle.setY(pressPos.y());
+ isPress = true;
+ textEdit->setText(mousePressPrinter());
+ }
+}
+
+void CustomGraphicsView::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton)
+ {
+ releasePos = event->posF();
+ rectangle.setWidth(event->posF().x() - rectangle.x());
+ rectangle.setHeight(event->posF().y() - rectangle.y());
+ isPress = false;
+ textEdit->setText(mouseReleasePrinter());
+ viewport()->repaint();
+ }
+}
+
+void CustomGraphicsView::mouseMoveEvent(QMouseEvent *event)
+{
+ if(isPress)
+ {
+ rectangle.setWidth(event->posF().x() - rectangle.x());
+ rectangle.setHeight(event->posF().y() - rectangle.y());
+ textEdit->setText(mouseMovePrinter(event->posF().x(),
event->posF().y()));
+ viewport()->repaint();
+ }
+}
+
+void CustomGraphicsView::paintEvent(QPaintEvent *event)
+{
+ QGraphicsView::paintEvent(event);
+ QPainter *painter = new QPainter(viewport());
+ painter->drawRect(rectangle);
+ painter->fillRect(rectangle, color);
+ delete painter;
+}
diff --git a/Test2/customgraphicsview.h b/Test2/customgraphicsview.h
new file mode 100644
index 0000000..8c3ffec
--- /dev/null
+++ b/Test2/customgraphicsview.h
@@ -0,0 +1,35 @@
+#ifndef CUSTOMGRAPHICSVIEW_H
+#define CUSTOMGRAPHICSVIEW_H
+
+#include <QGraphicsView>
+#include <QTextEdit>
+#include <QMouseEvent>
+#include <QRectF>
+#include <QPainter>
+
+class CustomGraphicsView :
+ public QGraphicsView
+{
+ public:
+ CustomGraphicsView(QTextEdit *textEdit);
+
+ protected:
+ void mousePressEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+ private:
+ QString mousePressPrinter();
+ QString mouseReleasePrinter();
+ QString mouseMovePrinter(qreal x, qreal y);
+
+ QTextEdit *textEdit;
+ QPointF pressPos;
+ QPointF releasePos;
+ QRectF rectangle;
+ QColor color;
+ bool isPress;
+};
+
+#endif // CUSTOMGRAPHICSVIEW_H
diff --git a/Test2/customviewport.cpp b/Test2/customviewport.cpp
new file mode 100644
index 0000000..a600871
--- /dev/null
+++ b/Test2/customviewport.cpp
@@ -0,0 +1,6 @@
+#include "customviewport.h"
+
+CustomViewport::CustomViewport()
+{
+ this->mouse
+}
diff --git a/Test2/customviewport.h b/Test2/customviewport.h
new file mode 100644
index 0000000..7d66409
--- /dev/null
+++ b/Test2/customviewport.h
@@ -0,0 +1,15 @@
+#ifndef CUSTOMVIEWPORT_H
+#define CUSTOMVIEWPORT_H
+
+#include <QWidget>
+
+class CustomViewport : public QWidget
+{
+ public:
+ CustomViewport();
+
+ protected:
+ void
+};
+
+#endif // CUSTOMVIEWPORT_H
diff --git a/Test2/debug.xml b/Test2/debug.xml
new file mode 100644
index 0000000..840d615
--- /dev/null
+++ b/Test2/debug.xml
@@ -0,0 +1,6 @@
+Page
+Width = 2338
+Height = 3133
+TextRegion id = 1
+Point 0 x = 149, y = 303
+Point 1 x = 2325, y = 303
diff --git a/Test2/graphicsregion.cpp b/Test2/graphicsregion.cpp
new file mode 100644
index 0000000..54c7922
--- /dev/null
+++ b/Test2/graphicsregion.cpp
@@ -0,0 +1,14 @@
+#include "graphicsregion.h"
+
+GraphicsRegion::GraphicsRegion()
+{
+}
+
+void GraphicsRegion::setPainterPath(QPainterPath *painterPath)
+{
+ this->painterPath = painterPath;
+}
+
+void GraphicsRegion::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
+{
+}
diff --git a/Test2/graphicsregion.h b/Test2/graphicsregion.h
new file mode 100644
index 0000000..9b8f67c
--- /dev/null
+++ b/Test2/graphicsregion.h
@@ -0,0 +1,18 @@
+#ifndef GRAPHICSREGION_H
+#define GRAPHICSREGION_H
+
+#include <QGraphicsItem>
+
+class GraphicsRegion :
+ public QGraphicsItem
+{
+ public:
+ GraphicsRegion();
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget
*widget);
+ void setPainterPath(QPainterPath *painterPath);
+
+ private:
+ QPainterPath *painterPath;
+};
+
+#endif // GRAPHICSREGION_H
diff --git a/Test2/selectionpicture.cpp b/Test2/selectionpicture.cpp
new file mode 100644
index 0000000..b49185f
--- /dev/null
+++ b/Test2/selectionpicture.cpp
@@ -0,0 +1,6 @@
+#include "selectionpicture.h"
+
+selectionPicture::selectionPicture()
+{
+
+}
diff --git a/Test2/selectionpicture.h b/Test2/selectionpicture.h
new file mode 100644
index 0000000..f2e017b
--- /dev/null
+++ b/Test2/selectionpicture.h
@@ -0,0 +1,13 @@
+#ifndef SELECTIONPICTURE_H
+#define SELECTIONPICTURE_H
+
+#include <QPixmap>
+
+class selectionPicture :
+ public QPixmap
+{
+public:
+ selectionPicture();
+};
+
+#endif // SELECTIONPICTURE_H
diff --git a/Test2/test2.cpp b/Test2/test2.cpp
index 5b14207..57cb8c0 100644
--- a/Test2/test2.cpp
+++ b/Test2/test2.cpp
@@ -8,6 +8,7 @@
#include "picture.h"
#include "ui_test2.h"
#include "customgraphicsview.h"
+#include "xml.h"
Test2::Test2(QWidget *parent) :
QMainWindow(parent),
@@ -26,6 +27,7 @@ Test2::Test2(QWidget *parent) :
connect(shortcutZoomIn, SIGNAL(activated()), this,
SLOT(on_actionZoomIn_triggered()));
picture = new Picture();
graphicsView->scene()->addItem(picture);
+ Xml::mapItems("/tmp/mp00082c_gui.xml");
}
Test2::~Test2()
diff --git a/Test2/xml.cpp b/Test2/xml.cpp
new file mode 100644
index 0000000..a9ba069
--- /dev/null
+++ b/Test2/xml.cpp
@@ -0,0 +1,89 @@
+#include <QFile>
+#include <QTextStream>
+#include <climits>
+#include "xml.h"
+
+Xml::Xml()
+{
+}
+
+void Xml::graphicsTypoRegion(const QDomElement &element, const QString
&typologicalName, const QPoint &xPos, QMap<QString, GraphicsRegion *> *map)
+{
+ GraphicsRegion *typoRegion = new GraphicsRegion();
+ int yPos = element.attribute(typologicalName, "null").toInt();
+ typoRegion->setData(0, QVariant::fromValue(QString::number(-yPos)));
+ QPainterPath painterPath(QPoint(xPos.x(), yPos));
+ painterPath.lineTo(QPoint(xPos.y(), yPos));
+ typoRegion->setPainterPath(&painterPath);
+ map->insert(QString::number(-yPos), typoRegion);
+}
+
+void Xml::graphicsLineRegion(const QDomElement &element, QMap<QString,
GraphicsRegion *> *map)
+{
+ if(!element.isNull())
+ {
+ QPolygon polygonLine;
+ GraphicsRegion *lineRegion = new GraphicsRegion();
+ QString id = element.attribute("id", "null");
+ lineRegion->setData(0, QVariant::fromValue(id));
+ QDomElement elt = element.firstChild().firstChild().toElement();
+ int xMin = INT_MAX;
+ int xMax = -1;
+ int x, y;
+ while(!elt.isNull())
+ {
+ x = elt.attribute("x", "null").toInt();
+ y = elt.attribute("y", "null").toInt();
+ if (xMin > x)
+ xMin = x;
+ if (xMax < x)
+ xMax = x;
+ polygonLine << QPoint(x, y);
+ elt = elt.nextSibling().toElement();
+ }
+ QPainterPath painterPath;
+ painterPath.addPolygon(polygonLine);
+ map->insert(id, lineRegion);
+ graphicsTypoRegion(element.parentNode().toElement(), "baseline",
QPoint(xMin, xMax), map);
+ graphicsTypoRegion(element.parentNode().toElement(), "meanline",
QPoint(xMin, xMax), map);
+ graphicsLineRegion(element.nextSiblingElement("Line"), map);
+ }
+}
+
+void Xml::graphicsTextRegion(const QDomElement &element, QMap<QString,
GraphicsRegion *> *map)
+{
+ if(!element.isNull())
+ {
+ QPolygon polygonText;
+ GraphicsRegion *textRegion = new GraphicsRegion();
+ QString id = element.attribute("id", "null");
+ textRegion->setData(0, QVariant::fromValue(id));
+ QDomElement elt = element.firstChild().firstChild().toElement();
+ while(!elt.isNull())
+ {
+ polygonText << QPoint(elt.attribute("x",
"null").toInt(), elt.attribute("y", "null").toInt());
+ elt = elt.nextSibling().toElement();
+ }
+ QPainterPath painterPath;
+ painterPath.addPolygon(polygonText);
+ map->insert(id, textRegion);
+ graphicsLineRegion(element.firstChild().nextSiblingElement("Line"),
map);
+ graphicsTextRegion(element.nextSiblingElement("TextRegion"), map);
+ }
+}
+
+QMap<QString, GraphicsRegion *> Xml::mapItems(const QString &filename)
+{
+ QMap<QString, GraphicsRegion *> *map = new QMap<QString, GraphicsRegion
*>();
+ QFile xmlFile(filename);
+ xmlFile.open(QIODevice::ReadOnly);
+ QDomDocument xml;
+ xml.setContent(&xmlFile);
+ xmlFile.close();
+ QDomElement elt =
xml.documentElement().firstChild().nextSiblingElement("Page");
+ //int width = elt.attribute("imageWidth", "null").toInt();
+ //int height = elt.attribute("imageHeight", "null").toInt();
+ elt = elt.firstChild().toElement();
+ graphicsTextRegion(elt, map);
+ return *map;
+}
diff --git a/Test2/xml.h b/Test2/xml.h
new file mode 100644
index 0000000..65aaf73
--- /dev/null
+++ b/Test2/xml.h
@@ -0,0 +1,21 @@
+#ifndef XML_H
+#define XML_H
+
+#include <QString>
+#include <QPainterPath>
+#include <QDomElement>
+#include "graphicsregion.h"
+
+class Xml
+{
+ public:
+ Xml();
+ static QMap<QString, GraphicsRegion *> mapItems(const QString
&filename);
+
+ private:
+ static void graphicsTypoRegion(const QDomElement &element, const QString
&typologicalLine, const QPoint &xPos, QMap<QString, GraphicsRegion *>
*map);
+ static void graphicsLineRegion(const QDomElement &element, QMap<QString,
GraphicsRegion *> *map);
+ static void graphicsTextRegion(const QDomElement &element, QMap<QString,
GraphicsRegion *> *map);
+};
+
+#endif // XML_H
--
1.7.2.5