---
GScribo/GScribo.pro.user | 32 ++++++------
GScribo/PagesViewer/pageswidget.cpp | 3 +-
GScribo/PagesViewer/pageswidget.h | 3 +-
GScribo/Rendering/polygonitem.cpp | 31 -----------
GScribo/Rendering/polygonitem.h | 28 ++++------
GScribo/Rendering/scene.cpp | 88 ++++++++++++++++++------------
GScribo/Rendering/scene.h | 18 ++++---
GScribo/mainwindow.cpp | 60 +++++++--------------
GScribo/mainwindow.h | 2 +-
GScribo/xml.cpp | 17 ++++++
GScribo/xml.h | 14 ++++-
GScribo/xmlwidget.cpp | 101 +++++++++++++++++++++++++++++-----
GScribo/xmlwidget.h | 22 ++++++--
13 files changed, 246 insertions(+), 173 deletions(-)
diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user
index b6ad263..4d451eb 100644
--- a/GScribo/GScribo.pro.user
+++ b/GScribo/GScribo.pro.user
@@ -67,14 +67,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-VUZT78qyIG,guid=a51566d968c6324fbe10159500728107</value>
+ <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qmlsXLWJn3,guid=e4b2f30ca8d018ccce50314c0073cc47</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-E8RI9F</value>
- <value type="QString">GNOME_KEYRING_PID=8443</value>
+ <value
type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-tl4Csb</value>
+ <value type="QString">GNOME_KEYRING_PID=6905</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>
@@ -86,16 +86,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=8518</value>
- <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-FvhujW8452/agent.8452</value>
+ <value type="QString">SSH_AGENT_PID=6981</value>
+ <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-Xmeufp6914/agent.6914</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:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value>
- <value type="QString">XAUTHORITY=/tmp/.gdmOKGZRW</value>
+ <value
type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value>
+ <value type="QString">XAUTHORITY=/tmp/.gdmHN3NRW</value>
<value
type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value>
- <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359551947.439559-1116819102</value>
+ <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359636746.918575-1681926162</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>
@@ -119,14 +119,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-VUZT78qyIG,guid=a51566d968c6324fbe10159500728107</value>
+ <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qmlsXLWJn3,guid=e4b2f30ca8d018ccce50314c0073cc47</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-E8RI9F</value>
- <value type="QString">GNOME_KEYRING_PID=8443</value>
+ <value
type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-tl4Csb</value>
+ <value type="QString">GNOME_KEYRING_PID=6905</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>
@@ -138,16 +138,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=8518</value>
- <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-FvhujW8452/agent.8452</value>
+ <value type="QString">SSH_AGENT_PID=6981</value>
+ <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-Xmeufp6914/agent.6914</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:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value>
- <value type="QString">XAUTHORITY=/tmp/.gdmOKGZRW</value>
+ <value
type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value>
+ <value type="QString">XAUTHORITY=/tmp/.gdmHN3NRW</value>
<value
type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value>
- <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359551947.439559-1116819102</value>
+ <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359636746.918575-1681926162</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/GScribo/PagesViewer/pageswidget.cpp b/GScribo/PagesViewer/pageswidget.cpp
index 3f975b4..7140d73 100644
--- a/GScribo/PagesViewer/pageswidget.cpp
+++ b/GScribo/PagesViewer/pageswidget.cpp
@@ -28,7 +28,7 @@ void PagesWidget::getPixmap(const QModelIndex &index)
QPixmap pixmap = index.data(Qt::UserRole).value<QPixmap>();
QString filename = index.data(Qt::UserRole+1).toString();
- emit selectionClicked(filename, pixmap);
+ emit sceneChanged(filename, pixmap);
}
void PagesWidget::addPixmap(const QString& filename, const QPixmap &pixmap)
@@ -49,6 +49,7 @@ void PagesWidget::removeSelection()
for(int i = indexes.count()-1; i > -1; i--)
model.removePixmap(indexes[i]);
+ // Draw new pixmap on the scene.
getPixmap(model.index(indexes[0].row()));
clearSelection();
}
diff --git a/GScribo/PagesViewer/pageswidget.h b/GScribo/PagesViewer/pageswidget.h
index 07d32ac..60ea9b6 100644
--- a/GScribo/PagesViewer/pageswidget.h
+++ b/GScribo/PagesViewer/pageswidget.h
@@ -24,8 +24,7 @@ class PagesWidget:
void removeSelection();
signals:
- void clicked(const QModelIndex &index);
- void selectionClicked(const QString& filename, const QPixmap& pixmap);
+ void sceneChanged(const QString& filename, const QPixmap& pixmap);
};
#endif // PAGESWIDGET_H
diff --git a/GScribo/Rendering/polygonitem.cpp b/GScribo/Rendering/polygonitem.cpp
index 48dbad0..b447e28 100644
--- a/GScribo/Rendering/polygonitem.cpp
+++ b/GScribo/Rendering/polygonitem.cpp
@@ -27,11 +27,6 @@ void PolygonItem::init()
unselectedBrush.setStyle(Qt::SolidPattern);
}
-QColor PolygonItem::color() const
-{
- return selectedBrush.color();
-}
-
void PolygonItem::setColor(const QColor &color)
{
selectedPen.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(),
255));
@@ -43,29 +38,3 @@ void PolygonItem::setColor(const QColor &color)
setPen(unselectedPen);
setBrush(unselectedBrush);
}
-
-bool PolygonItem::repaint(const QRectF& rect, bool clic)
-{
- bool isSel = isSelected(rect, clic);
-
- // Change items brush and pen if it's selectionned or not.
- if(isSel)
- {
- if(pen() != selectedPen)
- {
- setPen(selectedPen);
- setBrush(selectedBrush);
- }
- }
-
- else
- {
- if(pen() != unselectedPen)
- {
- setPen(unselectedPen);
- setBrush(unselectedBrush);
- }
- }
-
- return isSel;
-}
diff --git a/GScribo/Rendering/polygonitem.h b/GScribo/Rendering/polygonitem.h
index 112da15..ca32774 100644
--- a/GScribo/Rendering/polygonitem.h
+++ b/GScribo/Rendering/polygonitem.h
@@ -16,14 +16,14 @@ class PolygonItem :
explicit PolygonItem(const QPolygonF& path, QGraphicsItem *parent = 0,
QGraphicsScene *scene = 0);
void setColor(const QColor& color);
- QColor color() const;
+ inline QColor color() const;
- inline bool isSelected(const QRectF& rect, bool clic);
- bool repaint(const QRectF &rect, bool clic);
inline void loadData(const GraphicRegion::Data& data);
+ inline bool isSelected(const QRectF& rect, bool clic);
inline void unselect();
inline void select();
+ inline void setSelected(bool selected);
private:
void init();
@@ -34,12 +34,11 @@ class PolygonItem :
QBrush unselectedBrush;
};
+inline QColor PolygonItem::color() const
+{ return selectedBrush.color(); }
+
inline void PolygonItem::loadData(const GraphicRegion::Data &data)
-{
- setData(0, data.region);
- setColor(data.color);
- setZValue(data.zValue);
-}
+{ setData(0, data.region); setColor(data.color); setZValue(data.zValue); }
inline bool PolygonItem::isSelected(const QRectF &rect, bool clic)
{
@@ -50,15 +49,12 @@ inline bool PolygonItem::isSelected(const QRectF &rect, bool
clic)
}
inline void PolygonItem::select()
-{
- setPen(selectedPen);
- setBrush(selectedBrush);
-}
+{ if(pen() != selectedPen) { setPen(selectedPen); setBrush(selectedBrush); } }
inline void PolygonItem::unselect()
-{
- setPen(unselectedPen);
- setBrush(unselectedBrush);
-}
+{ if(pen() != unselectedPen) { setPen(unselectedPen); setBrush(unselectedBrush); } }
+
+inline void PolygonItem::setSelected(bool selected)
+{ if(selected) select(); else unselect(); }
#endif // POLYGONITEM_H
diff --git a/GScribo/Rendering/scene.cpp b/GScribo/Rendering/scene.cpp
index eb86c6c..3b4c70b 100644
--- a/GScribo/Rendering/scene.cpp
+++ b/GScribo/Rendering/scene.cpp
@@ -1,7 +1,5 @@
#include "scene.h"
-/******************************************* Run through item childs run through LINES
! TODO ****************************************/
-/******************************************* Center */
Scene::Scene(QObject *parent):
QGraphicsScene(parent)
{
@@ -28,15 +26,12 @@ void Scene::init()
// Disable the scene size adaptation to items rect with a non null rect.
setSceneRect(0, 0, 0, 1);
- addItem(&selection);
-}
-QString Scene::backgroundPath() const
-{
- return path;
+ selection.setRect(0, 0, 0, 0);
+ addItem(&selection);
}
-void Scene::reset()
+void Scene::clear()
{
if(item)
delete item;
@@ -83,11 +78,11 @@ void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
// If no selection, store the click position in the selection rectangle.
if(clic)
- selection.setRect(QRectF(QPointF(0, 0), event->scenePos()));
+ selection.setRect(QRectF(QPointF(0, 0), event->scenePos()));
// Redraw all items in selection.
if(item)
- repaintSelection(selection.rect(), clic);
+ selectItems(selection.rect(), clic);
selection.setRect(0, 0, 0, 0);
selection.hide();
@@ -101,62 +96,84 @@ void Scene::selectItem(PolygonItem *graphicalItem)
QGraphicsItem *child;
PolygonItem *polygonItem;
+ // Unselect all items.
foreach(child, item->childItems())
{
polygonItem = static_cast<PolygonItem *>(child);
polygonItem->unselect();
- if(polygonItem->data(0).toInt() == GraphicRegion::Text)
+ // Unselect lines.
+ foreach(child, polygonItem->childItems())
{
- foreach(child, polygonItem->childItems())
- {
- polygonItem = static_cast<PolygonItem *>(child);
- polygonItem->unselect();
- }
+ polygonItem = static_cast<PolygonItem *>(child);
+ polygonItem->unselect();
}
}
+ // Select the good item.
graphicalItem->select();
+ views()[0]->centerOn(graphicalItem);
}
}
-void Scene::repaintSelection(const QRectF &rect, bool clic)
+void Scene::selectItems(const QRectF &rect, bool clic)
{
QGraphicsItem *child;
PolygonItem *polygonItem;
+ QList<QTreeWidgetItem *> selectionTree;
+ QTreeWidgetItem *treeItem;
bool isSel;
- emit clearTreeSelection();
-
// Redraw all items in the scene except selection.
foreach(child, item->childItems())
{
polygonItem = static_cast<PolygonItem *>(child);
- isSel = polygonItem->repaint(rect, clic);
+ isSel = polygonItem->isSelected(rect, clic);
- // If item selectionned, select it on the xml tree.
+ // If item selectionned, select it on the xml tree and the scene.
if(isSel)
- emit
selectTreeItem(VariantPointer<QTreeWidgetItem>::fromQVariant(polygonItem->data(1)));
+ {
+ polygonItem->select();
+ treeItem =
VariantPointer<QTreeWidgetItem>::fromQVariant(polygonItem->data(1));
+ treeItem = new QTreeWidgetItem(*treeItem);
+ selectionTree << treeItem;
+ }
+ else
+ polygonItem->unselect();
- // If the item is a text region.
if(polygonItem->data(0).toInt() == GraphicRegion::Text)
{
- // Run through each child lines items.
+ // Run through each child lines items and do the same.
foreach(child, polygonItem->childItems())
{
polygonItem = static_cast<PolygonItem *>(child);
- isSel = polygonItem->repaint(rect, clic);
+ isSel = polygonItem->isSelected(rect, clic);
if(isSel)
- emit
selectTreeItem(VariantPointer<QTreeWidgetItem>::fromQVariant(polygonItem->data(1)));
+ {
+ polygonItem->select();
+
+ // Check if the corresponding text region has been clicked.
+ if(treeItem)
+ treeItem->addChild(new
QTreeWidgetItem(*VariantPointer<QTreeWidgetItem>::fromQVariant(polygonItem->data(1))));
+ else
+ selectionTree << new
QTreeWidgetItem(*VariantPointer<QTreeWidgetItem>::fromQVariant(polygonItem->data(1)));
+ }
+ else
+ polygonItem->unselect();
}
}
+
+ treeItem = 0;
}
+
+ emit selectTreeItems(selectionTree);
}
void Scene::addPolygonItem(QGraphicsItem *item)
{
- reset();
+ // Delete all items in the scene.
+ clear();
this->item = item;
addItem(item);
@@ -164,16 +181,15 @@ void Scene::addPolygonItem(QGraphicsItem *item)
void Scene::changeScene(const QString& filename, const QPixmap& pixmap,
QGraphicsItem *item)
{
- if(path != filename)
- {
- reset();
+ path = filename;
- path = filename;
+ // Delete all items in the scene.
+ clear();
- setSceneRect(pixmap.rect());
- setBackgroundBrush(QBrush(pixmap));
+ setSceneRect(pixmap.rect());
+ setBackgroundBrush(QBrush(pixmap));
- if(item)
- addPolygonItem(item);
- }
+ // Add new items.
+ if(item)
+ addPolygonItem(item);
}
diff --git a/GScribo/Rendering/scene.h b/GScribo/Rendering/scene.h
index 0bd5d56..ac63f7f 100644
--- a/GScribo/Rendering/scene.h
+++ b/GScribo/Rendering/scene.h
@@ -2,6 +2,7 @@
#define SCENE_H
#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsView>
#include <QGraphicsScene>
#include <QFileDialog>
@@ -18,11 +19,12 @@ class Scene :
explicit Scene(const QRectF &sceneRect, QObject *parent = 0);
explicit Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent =
0);
- QString backgroundPath() const;
- void reset();
+ inline QString backgroundPath() const;
+
+ void clear();
void addPolygonItem(QGraphicsItem *item);
void changeScene(const QString& filename, const QPixmap& pixmap,
QGraphicsItem *item = 0);
- void repaintSelection(const QRectF& rect, bool clic);
+ void selectItems(const QRectF& rect, bool clic);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -36,15 +38,17 @@ class Scene :
Selection selection;
QPointF pressPos;
bool isPressing;
- QString path;
bool clic;
+ QString path;
public slots:
void selectItem(PolygonItem *graphicalItem);
signals:
- void selectTreeItem(QTreeWidgetItem *treeItem);
- void clearTreeSelection();
- };
+ void selectTreeItems(const QList<QTreeWidgetItem *>& selectionTree);
+};
+
+inline QString Scene::backgroundPath() const
+{ return path; }
#endif // SCENE_H
diff --git a/GScribo/mainwindow.cpp b/GScribo/mainwindow.cpp
index 6b098fc..c048456 100644
--- a/GScribo/mainwindow.cpp
+++ b/GScribo/mainwindow.cpp
@@ -84,11 +84,22 @@ void MainWindow::initMenuBar()
connect(preferences, SIGNAL(triggered()), SLOT(onPreferences()));
}
-void MainWindow::onPagesSelection(const QString &filename, const QPixmap
&pixmap)
+void MainWindow::onFileChanged(const QString &filename, const QPixmap &pixmap)
{
- xml = processTmpXml(filename);
- scene.changeScene(filename, pixmap, xml.graphicItem());
- xmlWidget.changeView(xml.treeItem());
+ // If it's not the current scene.
+ if(scene.backgroundPath() != filename)
+ {
+ QString xmlPath = Xml::getPath(filename);
+ // Check if the xml file exists to draw data in the scene.
+ if(QFile(xmlPath).exists())
+ {
+ xml.load(xmlPath);
+ scene.changeScene(filename, pixmap, xml.graphicItem());
+ xmlWidget.changeView(xml.treeItem());
+ }
+ else
+ scene.changeScene(filename, pixmap);
+ }
}
void MainWindow::onOpen()
@@ -110,43 +121,10 @@ void MainWindow::onOpen()
pagesWidget.addPixmap(path, pixmap);
}
- // Seek if xml file already exists and in that case, add it to the scene.
- xml = processTmpXml(path);
- scene.changeScene(path, pixmap, xml.graphicItem());
- xmlWidget.changeView(xml.treeItem());
+ onFileChanged(path, pixmap);
}
}
-Xml MainWindow::processTmpXml(const QString &filename) const
-{
- QString path = filename;
-
- // Get instance of the configuration settings.
- Configs * const conf = Configs::getInstance();
-
- // Get xml filename from image path.
- path.remove(0, path.lastIndexOf('/')+1);
- int pos = path.lastIndexOf('.');
- path.remove(pos, path.length()-pos);
- path += "_gui.xml";
-
- // Get full path of xml file.
- if(QDir::temp().exists(path))
- path = QDir::tempPath() + "/" + path;
- else if(QDir(conf->generalSaveXmlCustomDirPath()).exists(path))
- path = conf->generalSaveXmlCustomDirPath() + "/" + path;
- else
- path = QString();
-
- // Get xml file informations if it exists.
- if(path.isNull())
- return Xml();
- else
-
- return Xml(path);
-}
-
-
void MainWindow::onSegment()
{
if(scene.backgroundPath() != "")
@@ -180,12 +158,12 @@ void MainWindow::onPreferences()
void MainWindow::connectWidgets()
{
// If double click on a picture of the page widget -> draw it on background
scene.
- connect(&pagesWidget, SIGNAL(selectionClicked(QString,QPixmap)), this,
SLOT(onPagesSelection(QString,QPixmap)));
+ connect(&pagesWidget, SIGNAL(sceneChanged(QString,QPixmap)), this,
SLOT(onFileChanged(QString,QPixmap)));
// Connect scene selection with xml tree and vice versa.
- connect(&scene, SIGNAL(selectTreeItem(QTreeWidgetItem*)), &xmlWidget,
SLOT(selectItem(QTreeWidgetItem*)));
- connect(&scene, SIGNAL(clearTreeSelection()), &xmlWidget,
SLOT(clearSelection()));
+ connect(&scene, SIGNAL(selectTreeItems(QList<QTreeWidgetItem*>)),
&xmlWidget, SLOT(selectItems(QList<QTreeWidgetItem*>)));
connect(&xmlWidget, SIGNAL(selectGraphicalItem(PolygonItem*)), &scene,
SLOT(selectItem(PolygonItem*)));
+ connect(&pagesWidget, SIGNAL(removeTreeSelection()), &xmlWidget,
SLOT(clear()));
connect(&runner, SIGNAL(progress()), &progressDialog, SLOT(run()));
connect(&runner, SIGNAL(new_progress_max_value(int)), &progressDialog,
SLOT(setMaximum(int)));
diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h
index 9baab40..456ec65 100644
--- a/GScribo/mainwindow.h
+++ b/GScribo/mainwindow.h
@@ -64,7 +64,7 @@ class MainWindow:
void onSegment();
void onXmlSaved(const QString& filename);
void onPreferences();
- void onPagesSelection(const QString& filename, const QPixmap& pixmap);
+ void onFileChanged(const QString& filename, const QPixmap& pixmap);
};
#endif // MAINWINDOW_H
diff --git a/GScribo/xml.cpp b/GScribo/xml.cpp
index 59a3963..994d788 100644
--- a/GScribo/xml.cpp
+++ b/GScribo/xml.cpp
@@ -21,9 +21,26 @@ Xml::Xml(const QString &filename)
gItem = 0;
tItem = 0;
+ path = filename;
load(filename);
}
+QString Xml::getPath(const QString &filename)
+{
+ // Get instance of the configuration settings.
+ Configs *const conf = Configs::getInstance();
+
+ QString xmlPath = filename;
+
+ // Get xml filename from image path.
+ xmlPath.remove(0, xmlPath.lastIndexOf('/')+1);
+ int pos = xmlPath.lastIndexOf('.');
+ xmlPath.remove(pos, xmlPath.length()-pos);
+ xmlPath += "_gui.xml";
+
+ return conf->generalSaveXmlCustomDirPath() + "/" + xmlPath;
+}
+
void Xml::load(const QString &filename)
{
if(!filename.isEmpty())
diff --git a/GScribo/xml.h b/GScribo/xml.h
index 81b7583..67f460c 100644
--- a/GScribo/xml.h
+++ b/GScribo/xml.h
@@ -10,6 +10,7 @@
#include "Rendering/polygonitem.h"
#include "variantpointer.h"
+#include "configs.h"
#include "region.h"
class Xml
@@ -17,10 +18,13 @@ class Xml
public:
explicit Xml(const QString& filename = QString());
- void load(const QString& filename);
inline QTreeWidgetItem *treeItem();
inline QGraphicsItem *graphicItem();
- inline QDomDocument xmlDocument() const;
+ inline QDomDocument document() const;
+ inline QString filename() const;
+
+ static QString getPath(const QString& filename);
+ void load(const QString& filename);
private:
QTreeWidgetItem *init(const QDomElement& root, QTreeWidgetItem
*rootTreeItem);
@@ -32,6 +36,7 @@ class Xml
QGraphicsPolygonItem *gItem;
QTreeWidgetItem *tItem;
QDomDocument xml;
+ QString path;
};
inline QTreeWidgetItem *Xml::treeItem()
@@ -40,9 +45,12 @@ inline QTreeWidgetItem *Xml::treeItem()
inline QGraphicsItem *Xml::graphicItem()
{ return gItem; }
-inline QDomDocument Xml::xmlDocument() const
+inline QDomDocument Xml::document() const
{ return xml; }
+inline QString Xml::filename() const
+{ return path; }
+
inline QTreeWidgetItem *Xml::fillWidgetItem(const QString& tagName, QTreeWidgetItem
*rootTreeItem)
{
QTreeWidgetItem *treeItem = new QTreeWidgetItem(rootTreeItem, QStringList(tagName));
diff --git a/GScribo/xmlwidget.cpp b/GScribo/xmlwidget.cpp
index 34ec266..a128b95 100644
--- a/GScribo/xmlwidget.cpp
+++ b/GScribo/xmlwidget.cpp
@@ -3,33 +3,71 @@
XmlWidget::XmlWidget(QWidget *parent) :
QWidget(parent)
{
- viewer.setHeaderHidden(true);
-
QHBoxLayout *hLayout = new QHBoxLayout;
QStringList headerNames;
headerNames << tr("Name") << tr("Value");
property.setHeaderItem(new QTreeWidgetItem(headerNames));
+ viewer.setHeaderItem(new QTreeWidgetItem(QStringList("Tree")));
+ selection.setHeaderItem(new QTreeWidgetItem(QStringList("Selection")));
hLayout->addWidget(&viewer);
+ hLayout->addWidget(&selection);
hLayout->addWidget(&property);
setLayout(hLayout);
- connect(&viewer, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this,
SLOT(setSelectItem(QTreeWidgetItem*)));
+ connect(&viewer, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this,
SLOT(selectTreeItem(QTreeWidgetItem*)));
+ connect(&selection, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this,
SLOT(selectSelectedItem(QTreeWidgetItem*)));
+}
+
+XmlWidget::~XmlWidget()
+{
+ clear();
}
-void XmlWidget::setSelectItem(QTreeWidgetItem *treeItem)
+void XmlWidget::selectItem(QTreeWidgetItem *treeItem, bool fromSelection)
{
+ // Get graphical item corresponding to the tree item.
+ PolygonItem *graphicalItem =
VariantPointer<PolygonItem>::fromQVariant(treeItem->data(0, Qt::UserRole+1));
+
+ if(!fromSelection)
+ {
+ clearSelection();
+
+ QTreeWidgetItem *selectionedItem = new QTreeWidgetItem(*treeItem);
+ selectionedItems << selectionedItem;
+ selection.addTopLevelItem(selectionedItem);
+ }
+
+ // Told to the scene to select the corresponding graphical item.
+ emit selectGraphicalItem(graphicalItem);
+
viewer.setCurrentItem(treeItem, 0);
- treeItem->setExpanded(true);
// Fill property tree view.
fillProperty(treeItem);
+}
- // Emit signal to select corresponding graphical item on the scene.
- emit
selectGraphicalItem(VariantPointer<PolygonItem>::fromQVariant(treeItem->data(0,
Qt::UserRole+1)));
+void XmlWidget::selectItems(const QList<QTreeWidgetItem *>& selectionTree)
+{
+ clearSelection();
+
+ if(!selectionTree.isEmpty())
+ {
+ selectionedItems = selectionTree;
+
+ QTreeWidgetItem *treeItem;
+ foreach(treeItem, selectionTree)
+ {
+ selection.addTopLevelItem(treeItem);
+ /*selection.setCurrentItem(treeItem, 0);
+ treeItem->setExpanded(true);*/
+ }
+
+ fillProperty(treeItem);
+ }
}
void XmlWidget::fillProperty(QTreeWidgetItem *treeItem)
@@ -60,23 +98,56 @@ void XmlWidget::changeView(QTreeWidgetItem *treeItem)
if(treeItem != viewer.topLevelItem(0))
{
// Delete all dom nodes pointers inside items data.
- QTreeWidgetItem *topLevelItem = viewer.takeTopLevelItem(0);
- if(topLevelItem)
- {
- deleteItemsNode(topLevelItem);
- delete
VariantPointer<QDomNamedNodeMap>::fromQVariant(topLevelItem->data(0,
Qt::UserRole));
- delete topLevelItem;
- }
+ clear();
// Reset tree widgets.
- property.clear();
viewer.reset();
if(treeItem != 0)
+ {
viewer.addTopLevelItem(treeItem);
+ viewer.setCurrentItem(treeItem->child(1), 0);
+ treeItem->child(1)->setExpanded(true);
+ }
}
}
+void XmlWidget::clear()
+{
+ QTreeWidgetItem *topLevelItem = viewer.takeTopLevelItem(0);
+
+ // Delete top level item, all its childs and datas.
+ if(topLevelItem)
+ {
+ deleteItemsNode(topLevelItem);
+ delete
VariantPointer<QDomNamedNodeMap>::fromQVariant(topLevelItem->data(0,
Qt::UserRole));
+ delete topLevelItem;
+
+ clearSelection();
+ }
+}
+
+void XmlWidget::clearSelection()
+{
+ property.clear();
+
+ // Delete all selectionned items.
+ QTreeWidgetItem *item, *child;
+ foreach(item, selectionedItems)
+ {
+ // Delete selectionned lines.
+ for(int i = 0; i < item->childCount(); i++)
+ {
+ child = item->child(i);
+ delete child;
+ }
+
+ delete item;
+ }
+
+ selectionedItems = QList<QTreeWidgetItem *>();
+}
+
void XmlWidget::deleteItemsNode(QTreeWidgetItem *topLevelItem)
{
QTreeWidgetItem *item;
diff --git a/GScribo/xmlwidget.h b/GScribo/xmlwidget.h
index d6d8fe3..e1f23cc 100644
--- a/GScribo/xmlwidget.h
+++ b/GScribo/xmlwidget.h
@@ -1,6 +1,7 @@
#ifndef XMLWIDGET_H
#define XMLWIDGET_H
+#include <QGraphicsView>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <QDomElement>
@@ -17,25 +18,38 @@ class XmlWidget :
public:
explicit XmlWidget(QWidget *parent = 0);
+ ~XmlWidget();
void changeView(QTreeWidgetItem *treeItem);
+ void selectItem(QTreeWidgetItem *treeItem, bool fromSelection = false);
private:
void fillProperty(QTreeWidgetItem *treeItem);
void deleteItemsNode(QTreeWidgetItem *topLevelItem);
QTreeWidget viewer;
+ QTreeWidget selection;
QTreeWidget property;
+ QList<QTreeWidgetItem *> selectionedItems;
public slots:
- void setSelectItem(QTreeWidgetItem *treeItem);
- inline void clearSelection();
+ void selectItems(const QList<QTreeWidgetItem *>& selectionTree);
+
+ void clear();
+ void clearSelection();
+
+ private slots:
+ inline void selectTreeItem(QTreeWidgetItem *treeItem);
+ inline void selectSelectedItem(QTreeWidgetItem *selectedItem);
signals:
void selectGraphicalItem(PolygonItem *polygonItem);
};
-inline void XmlWidget::clearSelection()
-{ viewer.reset(); property.clear(); }
+inline void XmlWidget::selectTreeItem(QTreeWidgetItem *treeItem)
+{ selectItem(treeItem, false); }
+
+inline void XmlWidget::selectSelectedItem(QTreeWidgetItem *selectedItem)
+{ selectItem(selectedItem, true); }
#endif // XMLWIDGET_H
--
1.7.2.5