
--- XmlParser/XmlParser | Bin 0 -> 1161618 bytes XmlParser/XmlParser.pro.user | 32 +++++++------- XmlParser/mainwindow.cpp | 14 ++++--- XmlParser/polygonitem.cpp | 30 ++++++++----- XmlParser/polygonitem.h | 6 +- XmlParser/region.h | 12 +++++- XmlParser/scene.cpp | 15 ++++--- XmlParser/scene.h | 3 +- XmlParser/xml.cpp | 95 ++++++++++++++++++++++++++++++++++++++---- XmlParser/xml.h | 8 ++- 10 files changed, 158 insertions(+), 57 deletions(-) create mode 100755 XmlParser/XmlParser diff --git a/XmlParser/XmlParser b/XmlParser/XmlParser new file mode 100755 index 0000000..083bcef Binary files /dev/null and b/XmlParser/XmlParser differ diff --git a/XmlParser/XmlParser.pro.user b/XmlParser/XmlParser.pro.user index bc2cc08..8b1714e 100644 --- a/XmlParser/XmlParser.pro.user +++ b/XmlParser/XmlParser.pro.user @@ -76,14 +76,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-aIwwX1PdIW,guid=277c26e47ab43726f8468924005d78f8</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-cEQxLJuvtW,guid=fcd36bb11605fca6a463651e005eb9dd</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-zYFQHc</value> - <value type="QString">GNOME_KEYRING_PID=10639</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-r2voTB</value> + <value type="QString">GNOME_KEYRING_PID=13274</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> @@ -95,16 +95,16 @@ <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=10714</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-QUVfz10648/agent.10648</value> + <value type="QString">SSH_AGENT_PID=13349</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vxZwL13283/agent.13283</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=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmWM6XQW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmSQLVQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358173628.84883-879735171</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358255777.408983-704756310</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> @@ -128,14 +128,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-aIwwX1PdIW,guid=277c26e47ab43726f8468924005d78f8</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-cEQxLJuvtW,guid=fcd36bb11605fca6a463651e005eb9dd</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-zYFQHc</value> - <value type="QString">GNOME_KEYRING_PID=10639</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-r2voTB</value> + <value type="QString">GNOME_KEYRING_PID=13274</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> @@ -147,16 +147,16 @@ <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=10714</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-QUVfz10648/agent.10648</value> + <value type="QString">SSH_AGENT_PID=13349</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vxZwL13283/agent.13283</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=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmWM6XQW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmSQLVQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358173628.84883-879735171</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358255777.408983-704756310</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/XmlParser/mainwindow.cpp b/XmlParser/mainwindow.cpp index 86f69a7..2bf9df8 100644 --- a/XmlParser/mainwindow.cpp +++ b/XmlParser/mainwindow.cpp @@ -8,10 +8,9 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); ui->graphicsView->setGeometry(0, 0, ui->groupBox->width(), ui->groupBox->height()); Scene *scene = new Scene(ui->graphicsView); - scene->setSceneRect(ui->graphicsView->geometry()); + scene->setSceneRect(/*ui->graphicsView->geometry()*/0, 0, 1000, 1000); ui->graphicsView->setScene(scene); - Xml::parseItems("/lrde/home/stage/froger_a/olena/_build/scribo/src/out.xml", scene); - connect(scene, SIGNAL(sendString(QString&)), this, SLOT(on_action(QString&))); + Xml::parseItems("/tmp/mp00082c_gui.xml", scene); } MainWindow::~MainWindow() @@ -35,9 +34,12 @@ void MainWindow::changeEvent(QEvent *e) void MainWindow::on_actionOpen_triggered() { QPixmap pixmap(QFileDialog::getOpenFileName(this)); - QBrush brush(pixmap); - ui->graphicsView->scene()->setBackgroundBrush(brush); - ui->graphicsView->scene()->setSceneRect(pixmap.rect());; + QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap); + pixmapItem->setFlag(QGraphicsItem::ItemNegativeZStacksBehindParent, true); + pixmapItem->setZValue(-1); + pixmapItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + ui->graphicsView->scene()->setSceneRect(pixmap.rect()); + ui->graphicsView->scene()->addItem(pixmapItem); } /*void MainWindow::on_action(QString& string) diff --git a/XmlParser/polygonitem.cpp b/XmlParser/polygonitem.cpp index 4b80fda..5ab3e7e 100644 --- a/XmlParser/polygonitem.cpp +++ b/XmlParser/polygonitem.cpp @@ -14,23 +14,29 @@ PolygonItem::PolygonItem(const QPolygonF &polygon, QGraphicsItem *parent, QGraph void PolygonItem::init() { - setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemClipsToShape); + setCacheMode(QGraphicsItem::ItemCoordinateCache); + setFlags(QGraphicsItem::ItemClipsToShape); selectedPen = new QPen(Qt::SolidLine); unselectedPen = new QPen(Qt::SolidLine); - selectedPen->setWidthF(20); + selectedPen->setWidthF(3); unselectedPen->setWidth(0); selectedPen->setCapStyle(Qt::SquareCap); unselectedPen->setCapStyle(Qt::SquareCap); selectedBrush = new QBrush(Qt::SolidPattern); unselectedBrush = new QBrush(Qt::SolidPattern); + QRectF bRect(boundingRect()); + if(bRect.width() < 1) + bRect.setWidth(1); + if(bRect.height() < 1) + bRect.setHeight(1); } void PolygonItem::setColor(const QColor &color) { - selectedPen->setColor(color); + selectedPen->setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 200)); unselectedPen->setColor(color); selectedBrush->setColor(color); - unselectedBrush->setColor(color); + unselectedBrush->setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 30)); setPen(*selectedPen); setBrush(*selectedBrush); } @@ -40,17 +46,21 @@ QColor PolygonItem::color() const return selectedBrush->color(); } -void PolygonItem::repaint(const QRectF &rect) +void PolygonItem::repaint(const QRectF &rect, bool clic) { - if(isSelected()) + bool sel; + if(clic) + sel = (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().contains(rect.bottomRight())) && shape().contains(rect.bottomRight()); + else + sel = (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().intersects(rect)) && shape().intersects(rect); + if(sel) { if(pen() != *selectedPen) { setPen(*selectedPen); setBrush(*selectedBrush); + update(rect); } - else - return; } else { @@ -58,9 +68,7 @@ void PolygonItem::repaint(const QRectF &rect) { setPen(*unselectedPen); setBrush(*unselectedBrush); + update(rect); } - else - return; } - update(rect); } diff --git a/XmlParser/polygonitem.h b/XmlParser/polygonitem.h index 036ba4f..70ad085 100644 --- a/XmlParser/polygonitem.h +++ b/XmlParser/polygonitem.h @@ -1,7 +1,7 @@ #ifndef POLYGONITEM_H #define POLYGONITEM_H -#include <QGraphicsPolygonItem> +#include <QGraphicsPathItem> #include <QPen> class PolygonItem : @@ -11,7 +11,7 @@ class PolygonItem : public: explicit PolygonItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); - explicit PolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); + explicit PolygonItem(const QPolygonF& path, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); void setColor(const QColor& color); QColor color() const; @@ -24,7 +24,7 @@ class PolygonItem : QBrush *unselectedBrush; public slots: - void repaint(const QRectF& rect); + void repaint(const QRectF& rect, bool clic); }; #endif // POLYGONITEM_H diff --git a/XmlParser/region.h b/XmlParser/region.h index 49704ca..21d67d8 100644 --- a/XmlParser/region.h +++ b/XmlParser/region.h @@ -1,8 +1,18 @@ #ifndef REGION_H #define REGION_H -namespace GraphicsRegion +#include <QColor> + +namespace GraphicRegion { + struct Data + { + QColor color; + QString name; + int region; + int zValue; + }; + enum Id { Text = 0, diff --git a/XmlParser/scene.cpp b/XmlParser/scene.cpp index ebf0c01..79cc213 100644 --- a/XmlParser/scene.cpp +++ b/XmlParser/scene.cpp @@ -21,16 +21,17 @@ Scene::Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent): void Scene::init() { isPressing = false; + clic = false; selection = new Selection(this); -} +} void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if(event->button() == Qt::LeftButton && !isPressing) { isPressing = true; + clic = true; pressPos = event->scenePos(); - selection->show(); } } @@ -38,6 +39,7 @@ void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(isPressing) { + clic = false; if(pressPos.x() < event->scenePos().x()) selection->setRect(pressPos.x(), 0, event->scenePos().x()-pressPos.x(), 0); else @@ -54,12 +56,11 @@ void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if(event->button() == Qt::LeftButton) { isPressing = false; - QPainterPath path; - path.addRect(selection->rect()); - setSelectionArea(path, Qt::IntersectsItemShape); - emit repaintItems(selection->rect()); + if(clic) + emit repaintItems(QRectF(QPointF(0, 0), event->scenePos()), true); + else + emit repaintItems(selection->rect(), false); selection->setRect(0, 0, 0, 0); - selection->hide(); } } diff --git a/XmlParser/scene.h b/XmlParser/scene.h index 0e1b4e9..efeac73 100644 --- a/XmlParser/scene.h +++ b/XmlParser/scene.h @@ -22,7 +22,7 @@ class Scene : void mouseMoveEvent(QGraphicsSceneMouseEvent *event); signals: - void repaintItems(const QRectF& rect); + void repaintItems(const QRectF& rect, bool clic); void sendString(QString& string); private: @@ -32,6 +32,7 @@ class Scene : Selection *selection; QPointF pressPos; bool isPressing; + bool clic; }; #endif // SCENE_H diff --git a/XmlParser/xml.cpp b/XmlParser/xml.cpp index e81d587..40bf193 100644 --- a/XmlParser/xml.cpp +++ b/XmlParser/xml.cpp @@ -5,14 +5,36 @@ Xml::Xml() { } -void Xml::graphicsTypoRegion(const QDomElement &element, const QPoint &xPos, Scene *scene) +void Xml::graphicsRegion(const QDomElement& element, const GraphicRegion::Data& data, Scene *scene) +{ + if(!element.isNull()) + { + QPolygon polygon; + QDomElement elt = element.firstChild().firstChild().toElement(); + while(!elt.isNull()) + { + polygon << QPoint(elt.attribute("x", "null").toInt(), elt.attribute("y", "null").toInt()); + elt = elt.nextSibling().toElement(); + }; + PolygonItem *polygonRegion = new PolygonItem(polygon, 0, scene); + polygonRegion->setData(0, QVariant::fromValue(data.region)); + polygonRegion->setColor(data.color); + polygonRegion->setZValue(data.zValue); + connect(scene, SIGNAL(repaintItems(QRectF,bool)), polygonRegion, SLOT(repaint(QRectF,bool))); + graphicsRegion(element.nextSiblingElement(data.name), data, scene); + } +} + +void Xml::graphicsTypoRegion(const QDomElement& element, const QPoint& xPos, Scene *scene) { int yPos = element.attribute("baseline", "null").toInt(); QGraphicsLineItem *baselineRegion = new QGraphicsLineItem(QLine(QPoint(xPos.x(), yPos), QPoint(xPos.y(), yPos)), 0, scene); - baselineRegion->setData(0, QVariant::fromValue((int)GraphicsRegion::Baseline)); + baselineRegion->setData(0, QVariant::fromValue((int)GraphicRegion::Baseline)); + baselineRegion->setZValue(3); yPos = element.attribute("meanline", "null").toInt(); QGraphicsLineItem *meanlineRegion = new QGraphicsLineItem(QLine(QPoint(xPos.x(), yPos), QPoint(xPos.y(), yPos)), 0, scene); - meanlineRegion->setData(0, QVariant::fromValue((int)GraphicsRegion::Meanline)); + meanlineRegion->setData(0, QVariant::fromValue((int)GraphicRegion::Meanline)); + meanlineRegion->setZValue(3); } void Xml::graphicsLineRegion(const QDomElement &element, Scene *scene) @@ -36,10 +58,10 @@ void Xml::graphicsLineRegion(const QDomElement &element, Scene *scene) elt = elt.nextSibling().toElement(); } PolygonItem *lineRegion = new PolygonItem(polygonLine, 0, scene); - lineRegion->setData(0, QVariant::fromValue((int)GraphicsRegion::Line)); + lineRegion->setData(0, QVariant::fromValue((int)GraphicRegion::Line)); lineRegion->setColor(QColor::fromRgb(255, 0, 0, 80)); lineRegion->setZValue(2); - connect(scene, SIGNAL(repaintItems(QRectF)), lineRegion, SLOT(repaint(QRectF))); + connect(scene, SIGNAL(repaintItems(QRectF,bool)), lineRegion, SLOT(repaint(QRectF,bool))); graphicsTypoRegion(element, QPoint(xMin, xMax), scene); graphicsLineRegion(element.nextSiblingElement("Line"), scene); } @@ -58,9 +80,9 @@ void Xml::graphicsTextRegion(const QDomElement &element, Scene *scene) } PolygonItem *textRegion = new PolygonItem(polygonText, 0, scene); textRegion->setColor(QColor::fromRgb(0, 100, 0, 80)); - textRegion->setData(0, QVariant::fromValue((int)GraphicsRegion::Text)); - textRegion->setZValue(3); - connect(scene, SIGNAL(repaintItems(QRectF)), textRegion, SLOT(repaint(QRectF))); + textRegion->setData(0, QVariant::fromValue((int)GraphicRegion::Text)); + textRegion->setZValue(1); + connect(scene, SIGNAL(repaintItems(QRectF,bool)), textRegion, SLOT(repaint(QRectF,bool))); graphicsLineRegion(element.firstChild().nextSiblingElement("Line"), scene); graphicsTextRegion(element.nextSiblingElement("TextRegion"), scene); } @@ -74,5 +96,60 @@ void Xml::parseItems(const QString &filename, Scene *scene) xml.setContent(&xmlFile); xmlFile.close(); QVector<QGraphicsItem *> items; - graphicsTextRegion(xml.documentElement().firstChild().nextSiblingElement("Page").firstChild().toElement(), scene); + QDomElement element = xml.documentElement().firstChild().nextSiblingElement("Page").firstChild().toElement(); + graphicsTextRegion(element, scene); // TextRegion + LineRegion + Baseline + Meanline + GraphicRegion::Data verticalData; + verticalData.color = QColor::fromRgb(0, 0, 255, 80); + verticalData.name = "VerticalSeparatorRegion"; + verticalData.region = (int)GraphicRegion::VerticalSeparator; + verticalData.zValue = 2; + graphicsRegion(element.nextSiblingElement(verticalData.name), verticalData, scene); // VerticalRegion + GraphicRegion::Data horizontalData; + horizontalData.color = QColor::fromRgb(0, 0, 255, 80); + horizontalData.name = "HorizontalSeparatorRegion"; + horizontalData.region = (int)GraphicRegion::HorizontalSeparator; + horizontalData.zValue = 2; + graphicsRegion(element.nextSiblingElement(horizontalData.name), horizontalData, scene); // HorizontalRegion + GraphicRegion::Data spaceData; + spaceData.color = QColor::fromRgb(0, 0, 128, 80); + spaceData.name = "WhitespaceSeparatorRegion"; + spaceData.region = (int)GraphicRegion::WhiteSpaceSeparator; + spaceData.zValue = 2; + graphicsRegion(element.nextSiblingElement(spaceData.name), spaceData, scene); // WhitespaceRegion + GraphicRegion::Data imageData; + imageData.color = QColor::fromRgb(255, 120, 0, 80); + imageData.name = "ImageRegion"; + imageData.region = (int)GraphicRegion::Image; + imageData.zValue = 1; + graphicsRegion(element.nextSiblingElement(imageData.name), imageData, scene); // ImageRegion + GraphicRegion::Data noiseData; + noiseData.color = QColor::fromRgb(43, 39, 128, 80); + noiseData.name = "NoiseRegion"; + noiseData.region = (int)GraphicRegion::Noise; + noiseData.zValue = 2; + graphicsRegion(element.nextSiblingElement(noiseData.name), noiseData, scene); // NoiseRegion + GraphicRegion::Data tableData; + tableData.color = QColor::fromRgb(220, 246, 0, 80); + tableData.name = "TableRegion"; + tableData.region = (int)GraphicRegion::Table; + tableData.zValue = 2; + graphicsRegion(element.nextSiblingElement(tableData.name), tableData, scene); // TableRegion + GraphicRegion::Data mathsData; + mathsData.color = QColor::fromRgb(170, 0, 255, 80); + mathsData.name = "MathsRegion"; + mathsData.region = (int)GraphicRegion::Maths; + mathsData.zValue = 3; + graphicsRegion(element.nextSiblingElement(mathsData.name), mathsData, scene); // MathsRegion + GraphicRegion::Data graphicData; + graphicData.color = QColor::fromRgb(255, 0, 144, 80); + graphicData.name = "GraphicRegion"; + graphicData.region = (int)GraphicRegion::Graphic; + graphicData.zValue = 2; + graphicsRegion(element.nextSiblingElement(graphicData.name), graphicData, scene); // GraphicRegion + GraphicRegion::Data chartData; + chartData.color = QColor::fromRgb(0, 204, 255, 80); + chartData.name = "ChartRegion"; + chartData.region = (int)GraphicRegion::Chart; + chartData.zValue = 2; + graphicsRegion(element.nextSiblingElement(chartData.name), chartData, scene); // ChartRegion } diff --git a/XmlParser/xml.h b/XmlParser/xml.h index 7176713..c694a95 100644 --- a/XmlParser/xml.h +++ b/XmlParser/xml.h @@ -8,6 +8,7 @@ #include <climits> #include <QTextEdit> #include "polygonitem.h" +#include "region.h" #include "scene.h" class Xml: @@ -18,9 +19,10 @@ class Xml: static void parseItems(const QString &filename, Scene *scene); private: - static void graphicsTypoRegion(const QDomElement &element, const QPoint& xPos, Scene *scene); - static void graphicsLineRegion(const QDomElement &element, Scene *scene); - static void graphicsTextRegion(const QDomElement &element, Scene *scene); + static void graphicsRegion(const QDomElement& element, const GraphicRegion::Data& data, Scene *scene); + static void graphicsTypoRegion(const QDomElement& element, const QPoint& xPos, Scene *scene); + static void graphicsLineRegion(const QDomElement& element, Scene *scene); + static void graphicsTextRegion(const QDomElement& element, Scene *scene); }; #endif // XML_H -- 1.7.2.5