02c9ee2 Cloth to have finished xml widget multiple selection. Finished pages widget : when deleting, testing if the widget has the focus. Also reimplement some stuff in the scene : add RootGraphicalItem to prepare the region widget. TODO : Finish xml widget multiple selection (problem : can t add prperlythe new selected item without clear selection and add new selection).

--- GScribo/GScribo.pro | 11 ++- GScribo/GScribo.pro.user | 32 ++++---- .../PagesWidget/{listmodel.cpp => pagesmodel.cpp} | 14 ++-- GScribo/PagesWidget/{listmodel.h => pagesmodel.h} | 16 ++-- GScribo/PagesWidget/pageswidget.h | 10 ++- GScribo/Rendering/polygonitem.cpp | 47 ++-------- GScribo/Rendering/polygonitem.h | 31 +++++-- GScribo/Rendering/rootgraphicsitem.h | 27 ++++++ GScribo/Rendering/scene.cpp | 95 +++++++++++++------ GScribo/Rendering/scene.h | 42 ++++++--- GScribo/XmlWidget/selectionproxy.h | 19 ++++- GScribo/XmlWidget/xmldelegate.h | 1 + GScribo/XmlWidget/xmlitem.cpp | 2 +- GScribo/XmlWidget/xmlitem.h | 26 +++--- GScribo/XmlWidget/xmlmodel.cpp | 2 +- GScribo/XmlWidget/xmlview.cpp | 77 ++++++++++++++++ GScribo/XmlWidget/xmlview.h | 51 +++++++++++ GScribo/XmlWidget/xmlwidget.cpp | 24 +---- GScribo/XmlWidget/xmlwidget.h | 26 ++---- GScribo/listmodel.o | Bin 0 -> 226616 bytes GScribo/mainwindow.cpp | 34 ++++--- GScribo/mainwindow.h | 1 + GScribo/moc_listmodel.cpp | 79 ++++++++++++++++ GScribo/moc_listmodel.o | Bin 0 -> 217712 bytes GScribo/region.h | 4 +- GScribo/xml.cpp | 62 +++++++------ GScribo/xml.h | 27 +++--- 27 files changed, 520 insertions(+), 240 deletions(-) rename GScribo/PagesWidget/{listmodel.cpp => pagesmodel.cpp} (68%) rename GScribo/PagesWidget/{listmodel.h => pagesmodel.h} (73%) create mode 100644 GScribo/Rendering/rootgraphicsitem.h create mode 100644 GScribo/XmlWidget/xmlview.cpp create mode 100644 GScribo/XmlWidget/xmlview.h create mode 100644 GScribo/listmodel.o create mode 100644 GScribo/moc_listmodel.cpp create mode 100644 GScribo/moc_listmodel.o diff --git a/GScribo/GScribo.pro b/GScribo/GScribo.pro index a7f730e..0d4784c 100644 --- a/GScribo/GScribo.pro +++ b/GScribo/GScribo.pro @@ -18,7 +18,7 @@ SOURCES += main.cpp \ Rendering/selection.cpp \ Rendering/polygonitem.cpp \ PagesWidget/pageswidget.cpp \ - PagesWidget/listmodel.cpp \ + PagesWidget/pagesmodel.cpp \ Preferences/segmentationoptions.cpp \ Preferences/preprocessingoptions.cpp \ Preferences/ocroptions.cpp \ @@ -29,7 +29,8 @@ SOURCES += main.cpp \ XmlWidget/xmlitem.cpp \ XmlWidget/xmlattributes.cpp \ XmlWidget/attributemodel.cpp \ - PagesWidget/pagesdelegate.cpp + PagesWidget/pagesdelegate.cpp \ + XmlWidget/xmlview.cpp HEADERS += mainwindow.h \ variantpointer.h \ configs.h \ @@ -40,7 +41,7 @@ HEADERS += mainwindow.h \ Rendering/selection.h \ Rendering/polygonitem.h \ PagesWidget/pageswidget.h \ - PagesWidget/listmodel.h \ + PagesWidget/pagesmodel.h \ Preferences/segmentationoptions.h \ Preferences/preprocessingoptions.h \ Preferences/ocroptions.h \ @@ -54,7 +55,9 @@ HEADERS += mainwindow.h \ XmlWidget/selectionproxy.h \ XmlWidget/xmldelegate.h \ XmlWidget/attributemodel.h \ - PagesWidget/pagesdelegate.h + PagesWidget/pagesdelegate.h \ + Rendering/rootgraphicsitem.h \ + XmlWidget/xmlview.h FORMS += mainwindow.ui \ Preferences/preferencesdialog.ui \ Preferences/ocroptions.ui \ diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user index 98084bd..4243d4d 100644 --- a/GScribo/GScribo.pro.user +++ b/GScribo/GScribo.pro.user @@ -76,7 +76,7 @@ <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-8HhQV0Db3w,guid=820a1dac27c5f8287b84357100000031</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-HTSk420eki,guid=679213ffd1e640ac61b4a56900013d29</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> @@ -87,22 +87,22 @@ <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/GScribo/XmlWidget</value> + <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/games</value> <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</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=2149</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vKpzBP2096/agent.2096</value> + <value type="QString">SSH_AGENT_PID=6726</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-DIRIVy6673/agent.6673</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</value> - <value type="QString">XAUTHORITY=/tmp/.gdmYQPASW</value> + <value type="QString">WINDOWID=10485796</value> + <value type="QString">WINDOWPATH=7:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmD2O2RW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360245257.460868-2058632410</value> + <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360326402.458705-1535460395</value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> <value type="QString">XTERM_VERSION=XTerm(261)</value> @@ -125,7 +125,7 @@ <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-8HhQV0Db3w,guid=820a1dac27c5f8287b84357100000031</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-HTSk420eki,guid=679213ffd1e640ac61b4a56900013d29</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> @@ -136,22 +136,22 @@ <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/GScribo/XmlWidget</value> + <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/games</value> <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</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=2149</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vKpzBP2096/agent.2096</value> + <value type="QString">SSH_AGENT_PID=6726</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-DIRIVy6673/agent.6673</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</value> - <value type="QString">XAUTHORITY=/tmp/.gdmYQPASW</value> + <value type="QString">WINDOWID=10485796</value> + <value type="QString">WINDOWPATH=7:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmD2O2RW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360245257.460868-2058632410</value> + <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360326402.458705-1535460395</value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> <value type="QString">XTERM_VERSION=XTerm(261)</value> diff --git a/GScribo/PagesWidget/listmodel.cpp b/GScribo/PagesWidget/pagesmodel.cpp similarity index 68% rename from GScribo/PagesWidget/listmodel.cpp rename to GScribo/PagesWidget/pagesmodel.cpp index 4426087..82bf581 100644 --- a/GScribo/PagesWidget/listmodel.cpp +++ b/GScribo/PagesWidget/pagesmodel.cpp @@ -1,12 +1,12 @@ -#include "listmodel.h" +#include "pagesmodel.h" -ListModel::ListModel(QObject *parent): +PagesModel::PagesModel(QObject *parent): QAbstractListModel(parent) { currentRow_ = 0; } -QVariant ListModel::data(const QModelIndex& index, int role) const +QVariant PagesModel::data(const QModelIndex& index, int role) const { if(!index.isValid()) return QVariant(); @@ -23,19 +23,17 @@ QVariant ListModel::data(const QModelIndex& index, int role) const return QVariant(); } -void ListModel::addPicture(const QString& filename, const QPixmap& pixmap) +void PagesModel::addPicture(const QString& filename, const QPixmap& pixmap) { beginInsertRows(QModelIndex(), 0, 0); - beginResetModel(); pixmaps_.prepend(pixmap.scaled(QSize(200, 200), Qt::KeepAspectRatio, Qt::SmoothTransformation)); filenames_.prepend(filename); endInsertRows(); - //endResetModel(); } -void ListModel::removePixmap(const QModelIndex &parent) +void PagesModel::removePixmap(const QModelIndex &parent) { int row = parent.row(); @@ -47,7 +45,7 @@ void ListModel::removePixmap(const QModelIndex &parent) endRemoveRows(); } -void ListModel::setCurrentRow(int currentRow) +void PagesModel::setCurrentRow(int currentRow) { beginResetModel(); currentRow_ = currentRow; diff --git a/GScribo/PagesWidget/listmodel.h b/GScribo/PagesWidget/pagesmodel.h similarity index 73% rename from GScribo/PagesWidget/listmodel.h rename to GScribo/PagesWidget/pagesmodel.h index 46bc04e..4c18842 100644 --- a/GScribo/PagesWidget/listmodel.h +++ b/GScribo/PagesWidget/pagesmodel.h @@ -1,17 +1,17 @@ -#ifndef LISTMODEL_H -#define LISTMODEL_H +#ifndef PAGESMODEL_H +#define PAGESMODEL_H #include <QAbstractListModel> #include <QIcon> #include <QList> -class ListModel: +class PagesModel: public QAbstractListModel { Q_OBJECT public: - explicit ListModel(QObject *parent = 0); + explicit PagesModel(QObject *parent = 0); inline QStringList filenames() const; inline int rowCount(const QModelIndex& parent = QModelIndex()) const; @@ -31,13 +31,13 @@ class ListModel: void removePixmap(const QModelIndex& parent); }; -inline QStringList ListModel::filenames() const +inline QStringList PagesModel::filenames() const { return filenames_; } -inline int ListModel::rowCount(const QModelIndex&) const +inline int PagesModel::rowCount(const QModelIndex&) const { return filenames_.count(); } -inline int ListModel::currentRow() const +inline int PagesModel::currentRow() const { return currentRow_; } -#endif // LISTMODEL_H +#endif // PAGESMODEL_H diff --git a/GScribo/PagesWidget/pageswidget.h b/GScribo/PagesWidget/pageswidget.h index f802728..eb6488c 100644 --- a/GScribo/PagesWidget/pageswidget.h +++ b/GScribo/PagesWidget/pageswidget.h @@ -5,7 +5,7 @@ #include <QShortcut> #include "pagesdelegate.h" -#include "listmodel.h" +#include "pagesmodel.h" class PagesWidget: public QListView @@ -21,8 +21,11 @@ class PagesWidget: inline void addPicture(const QString& filename, const QPixmap& pixmap); + protected: + inline void focusOutEvent(QFocusEvent *event); + private: - ListModel model_; + PagesModel model_; public slots: void removeSelection(); @@ -46,4 +49,7 @@ inline void PagesWidget::setCurrentRow(int currentRow) inline void PagesWidget::addPicture(const QString& filename, const QPixmap& pixmap) { model_.addPicture(filename, pixmap); } +inline void PagesWidget::focusOutEvent(QFocusEvent *event) +{ QListView::focusOutEvent(event); clearSelection(); } + #endif // PAGESWIDGET_H diff --git a/GScribo/Rendering/polygonitem.cpp b/GScribo/Rendering/polygonitem.cpp index 7c84d0c..1a294fc 100644 --- a/GScribo/Rendering/polygonitem.cpp +++ b/GScribo/Rendering/polygonitem.cpp @@ -12,14 +12,6 @@ PolygonItem::PolygonItem(const QPolygonF &polygon, QGraphicsItem *parent, QGraph init(); } -PolygonItem::~PolygonItem() -{ - // Delete all childs. - QGraphicsItem *child; - foreach(child, childItems()) - delete child; -} - void PolygonItem::init() { xmlItem_ = 0; @@ -49,40 +41,19 @@ void PolygonItem::setColor(const QColor& color) setBrush(unselectedBrush_); } -bool PolygonItem::isSelected(const QRectF& rect, bool clic) -{ - if(clic) - return (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().contains(rect.bottomRight())) && - shape().contains(rect.bottomRight()); - else - return (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().intersects(rect)) && - shape().intersects(rect); -} - -void PolygonItem::setSelected(const QRectF& rect, bool clic) +void PolygonItem::setSelected(bool isSelected) { - if(isSelected(rect, clic)) - { - // Select graphical and xml item. - select(); - xmlItem_->select(); - - // If we are on a line, select the text xml item. - if(region_ == GraphicRegion::Line) - static_cast<PolygonItem *>(parentItem())->xmlItem()->select(); - } - else + if(isSelected) { - // Unselect graphical and xml item. - unselect(); - xmlItem_->unselect(); + isSelected_ = true; + setPen(selectedPen_); + setBrush(selectedBrush_); } - // Set selection for line items. - if(region_ == GraphicRegion::Text) + else { - QGraphicsItem *child; - foreach(child, childItems()) - static_cast<PolygonItem *>(child)->setSelected(rect, clic); + isSelected_ = false; + setPen(unselectedPen_); + setBrush(unselectedBrush_); } } diff --git a/GScribo/Rendering/polygonitem.h b/GScribo/Rendering/polygonitem.h index affdc2b..672ca97 100644 --- a/GScribo/Rendering/polygonitem.h +++ b/GScribo/Rendering/polygonitem.h @@ -5,17 +5,17 @@ #include <QTreeWidgetItem> #include <QPen> -#include "XmlWidget/xmlitem.h" #include "variantpointer.h" #include "region.h" +class XmlItem; + class PolygonItem : public QGraphicsPolygonItem { public: explicit PolygonItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); explicit PolygonItem(const QPolygonF& path, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); - ~PolygonItem(); void setColor(const QColor& color); inline QColor color() const; @@ -26,8 +26,11 @@ class PolygonItem : inline void loadData(const GraphicRegion::Data& data); inline int region() const; - bool isSelected(const QRectF& rect, bool clic); - void setSelected(const QRectF& rect, bool clic); + inline bool intersects(const QRectF& rect); + inline bool contains(const QPointF& point); + + void setSelected(bool isSelected); + inline bool isSelected(); inline void unselect(); inline void select(); @@ -36,6 +39,7 @@ class PolygonItem : XmlItem *xmlItem_; int region_; + bool isSelected_; QPen selectedPen_; QPen unselectedPen_; @@ -52,18 +56,25 @@ inline XmlItem *PolygonItem::xmlItem() const inline QColor PolygonItem::color() const { return selectedBrush_.color(); } -inline void PolygonItem::loadData(const GraphicRegion::Data& data) -{ region_ = data.region; setColor(data.color); setZValue(data.zValue); } - inline int PolygonItem::region() const { return region_; } +inline bool PolygonItem::isSelected() +{ return isSelected_; } + inline void PolygonItem::select() -{ if(pen() != selectedPen_) { setPen(selectedPen_); setBrush(selectedBrush_); } } +{ setSelected(true); } inline void PolygonItem::unselect() -{ if(pen() != unselectedPen_) { setPen(unselectedPen_); setBrush(unselectedBrush_);} } +{ setSelected(false); } + +inline void PolygonItem::loadData(const GraphicRegion::Data& data) +{ region_ = data.region; setColor(data.color); setZValue(data.zValue); } + +inline bool PolygonItem::contains(const QPointF& point) +{ return (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().contains(point)) && shape().contains(point); } -Q_DECLARE_METATYPE(PolygonItem *) +inline bool PolygonItem::intersects(const QRectF& rect) +{ return (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().intersects(rect)) && shape().intersects(rect); } #endif // POLYGONITEM_H diff --git a/GScribo/Rendering/rootgraphicsitem.h b/GScribo/Rendering/rootgraphicsitem.h new file mode 100644 index 0000000..81a2e84 --- /dev/null +++ b/GScribo/Rendering/rootgraphicsitem.h @@ -0,0 +1,27 @@ +#ifndef ROOTGRAPHICSITEM_H +#define ROOTGRAPHICSITEM_H + +#include <QGraphicsItem> + +#include "region.h" + +class RootGraphicsItem : + public QGraphicsPolygonItem +{ + public: + explicit RootGraphicsItem(int numberRegion) { childsFromRegion_.fill(QList<QGraphicsItem *>(), numberRegion); } + + inline QList<QGraphicsItem *> childsFrom(GraphicRegion::Id region) const; + inline void addItemFrom(QGraphicsItem *graphicalItem, GraphicRegion::Id region); + + private: + QVector<QList<QGraphicsItem *> > childsFromRegion_; +}; + +inline QList<QGraphicsItem *> RootGraphicsItem::childsFrom(GraphicRegion::Id region) const +{ return childsFromRegion_[region]; } + +inline void RootGraphicsItem::addItemFrom(QGraphicsItem *graphicalItem, GraphicRegion::Id region) +{ childsFromRegion_[region] << graphicalItem; } + +#endif // ROOTGRAPHICSITEM_H diff --git a/GScribo/Rendering/scene.cpp b/GScribo/Rendering/scene.cpp index 25a0f15..26a6b57 100644 --- a/GScribo/Rendering/scene.cpp +++ b/GScribo/Rendering/scene.cpp @@ -21,7 +21,6 @@ Scene::Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent): void Scene::init() { isPressing_ = false; - click_ = false; rootItem_ = 0; // Disable the scene size adaptation to items rect with a non null rect. @@ -36,15 +35,30 @@ void Scene::clear() if(rootItem_) delete rootItem_; + selectedItems_.clear(); rootItem_ = 0; } +void Scene::clearSelection() +{ + QGraphicsItem *child; + PolygonItem *polygonItem; + + // Unselect all items. + foreach(child, selectedItems_) + { + polygonItem = static_cast<PolygonItem *>(child); + polygonItem->unselect(); + } + + selectedItems_.clear(); +} + void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if(event->button() == Qt::LeftButton && !isPressing_) { isPressing_ = true; - click_ = true; pressPos_ = event->scenePos(); selection_.show(); @@ -55,8 +69,6 @@ void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(isPressing_) { - click_ = false; - // Adapt if the selection rectangle has a negative size. if(pressPos_.x() < event->scenePos().x()) selection_.setRect(pressPos_.x(), 0, event->scenePos().x()-pressPos_.x(), 0); @@ -76,16 +88,19 @@ void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { isPressing_ = false; - // If no selection, store the click position in the selection rectangle. - if(click_) - selection_.setRect(QRectF(QPointF(0, 0), event->scenePos())); - // Redraw all items in selection. if(rootItem_) { + clearSelection(); emit beginSelection(); - selectItems(selection_.rect(), click_); - emit endSelection(); + + // Check if it is a click. + if(selection_.rect().width() * selection_.rect().height() == 0) + selectItems(event->scenePos()); + else + selectItems(selection_.rect()); + + emit endSelection(selectedItems_); } selection_.setRect(0, 0, 0, 0); @@ -93,38 +108,58 @@ void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } -void Scene::selectItem(PolygonItem *graphicalItem) +void Scene::selectItems(const QList<PolygonItem *>& selectedItems, bool addToSelection) +{ + if(!addToSelection) + clearSelection(); + + PolygonItem *child; + foreach(child, selectedItems) + { + if(!child->isSelected()) + { + child->select(); + selectedItems_ << child; + } + } +} + +void Scene::selectItems(QGraphicsItem *root, const QPointF& point, const QRectF& rect) { QGraphicsItem *child; PolygonItem *polygonItem; - // Unselect all items. - foreach(child, rootItem_->childItems()) + // Check if it is a click. + if(!point.isNull()) { - polygonItem = static_cast<PolygonItem *>(child); - polygonItem->unselect(); - - // Unselect lines. - foreach(child, polygonItem->childItems()) + foreach(child, root->childItems()) { polygonItem = static_cast<PolygonItem *>(child); - polygonItem->unselect(); + + if(polygonItem->contains(point)) + { + polygonItem->select(); + selectedItems_ << polygonItem; + } } } - // Select the good item. - graphicalItem->select(); - views()[0]->centerOn(graphicalItem); -} + else + { + foreach(child, root->childItems()) + { + polygonItem = static_cast<PolygonItem *>(child); -void Scene::selectItems(const QRectF& rect, bool clic) -{ - QGraphicsItem *child; - foreach(child, rootItem_->childItems()) - static_cast<PolygonItem *>(child)->setSelected(rect, clic); + if(polygonItem->intersects(rect)) + { + polygonItem->select(); + selectedItems_ << polygonItem; + } + } + } } -void Scene::setRootItem(QGraphicsItem *rootItem) +void Scene::setRootItem(RootGraphicsItem *rootItem) { // Delete all items. clear(); @@ -133,7 +168,7 @@ void Scene::setRootItem(QGraphicsItem *rootItem) addItem(rootItem); } -void Scene::changeScene(const QString& filename, QGraphicsItem *rootItem) +void Scene::changeScene(const QString& filename, RootGraphicsItem *rootItem) { backgroundPath_ = filename; diff --git a/GScribo/Rendering/scene.h b/GScribo/Rendering/scene.h index a11ff2c..7409bc5 100644 --- a/GScribo/Rendering/scene.h +++ b/GScribo/Rendering/scene.h @@ -6,8 +6,9 @@ #include <QGraphicsScene> #include <QFileDialog> -#include "selection.h" +#include "rootgraphicsitem.h" #include "polygonitem.h" +#include "selection.h" class Scene : public QGraphicsScene @@ -20,12 +21,15 @@ class Scene : explicit Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0); inline QString backgroundPath() const; - void setRootItem(QGraphicsItem *graphicalItem); - inline QGraphicsItem *rootItem() const; - void clear(); - void changeScene(const QString& filename, QGraphicsItem *rootItem = 0); - void selectItems(const QRectF& rect, bool clic); + void setRootItem(RootGraphicsItem *graphicalItem); + inline RootGraphicsItem *rootItem() const; + + inline QList<QGraphicsItem *> selectedItems() const; + void selectItems(const QRectF& rect); + void selectItems(const QPointF& point); + + void changeScene(const QString& filename, RootGraphicsItem *rootItem = 0); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -34,26 +38,40 @@ class Scene : private: void init(); + void selectItems(QGraphicsItem *root, const QPointF& point, const QRectF& rect); + + QString backgroundPath_; + RootGraphicsItem *rootItem_; - QGraphicsItem *rootItem_; Selection selection_; + QList<QGraphicsItem *> selectedItems_; + QPointF pressPos_; bool isPressing_; - bool click_; - QString backgroundPath_; public slots: - void selectItem(PolygonItem *graphicalItem); + void clear(); + void clearSelection(); + void selectItems(const QList<PolygonItem *>& selectedItems, bool addToSelection); signals: void beginSelection(); - void endSelection(); + void endSelection(const QList<QGraphicsItem *>& selectedItems); }; inline QString Scene::backgroundPath() const { return backgroundPath_; } -inline QGraphicsItem *Scene::rootItem() const +inline RootGraphicsItem *Scene::rootItem() const { return rootItem_; } +inline QList<QGraphicsItem *> Scene::selectedItems() const +{ return selectedItems_; } + +inline void Scene::selectItems(const QPointF& point) +{ selectItems(rootItem_, point, QRectF()); } + +inline void Scene::selectItems(const QRectF& rect) +{ selectItems(rootItem_, QPointF(), rect); } + #endif // SCENE_H diff --git a/GScribo/XmlWidget/selectionproxy.h b/GScribo/XmlWidget/selectionproxy.h index 32edae4..ff55bd4 100644 --- a/GScribo/XmlWidget/selectionproxy.h +++ b/GScribo/XmlWidget/selectionproxy.h @@ -10,21 +10,34 @@ class SelectionProxy : public QSortFilterProxyModel { public: - explicit SelectionProxy(QObject *parent = 0) : QSortFilterProxyModel(parent) { } + explicit SelectionProxy(QObject *parent = 0) : QSortFilterProxyModel(parent) { isAllSelected_ = true; } + inline void beginResetModel(); inline void endResetModel(); + inline void selectAll(); + inline bool isAllSelected(); + protected: inline bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const; + + private: + bool isAllSelected_; }; inline bool SelectionProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const -{ QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); return index.data(filterRole()).toBool(); } +{ return isAllSelected_ || sourceModel()->index(sourceRow, 0, sourceParent).data(filterRole()).toBool(); } inline void SelectionProxy::beginResetModel() -{ QSortFilterProxyModel::beginResetModel(); } +{ isAllSelected_ = false; QSortFilterProxyModel::beginResetModel(); } inline void SelectionProxy::endResetModel() { QSortFilterProxyModel::endResetModel(); } +inline void SelectionProxy::selectAll() +{ isAllSelected_ = true; } + +inline bool SelectionProxy::isAllSelected() +{ return isAllSelected_; } + #endif // SELECTIONPROXY_H diff --git a/GScribo/XmlWidget/xmldelegate.h b/GScribo/XmlWidget/xmldelegate.h index 35b3089..0da3ce9 100644 --- a/GScribo/XmlWidget/xmldelegate.h +++ b/GScribo/XmlWidget/xmldelegate.h @@ -2,6 +2,7 @@ #define XMLDELEGATE_H #include <QStyledItemDelegate> +#include<QPainter> class XmlDelegate : public QStyledItemDelegate diff --git a/GScribo/XmlWidget/xmlitem.cpp b/GScribo/XmlWidget/xmlitem.cpp index ec635ba..f2499cf 100644 --- a/GScribo/XmlWidget/xmlitem.cpp +++ b/GScribo/XmlWidget/xmlitem.cpp @@ -21,7 +21,7 @@ XmlItem::~XmlItem() void XmlItem::init(XmlItem *parent, XmlItem *precItem) { - isSelected_ = true; + isVisible_ = false; graphicalItem_ = 0; parent_ = parent; diff --git a/GScribo/XmlWidget/xmlitem.h b/GScribo/XmlWidget/xmlitem.h index b72d96d..6e01573 100644 --- a/GScribo/XmlWidget/xmlitem.h +++ b/GScribo/XmlWidget/xmlitem.h @@ -24,10 +24,10 @@ class XmlItem inline PolygonItem *graphicalItem(); inline void setGraphicalItem(PolygonItem *graphicalItem); - inline bool isSelected() const; - inline void setSelected(bool selected); - inline void select(); - inline void unselect(); + inline bool isVisible() const; + inline void setVisible(bool visible); + inline void show(); + inline void hide(); inline QString text() const; inline int row() const; @@ -37,7 +37,7 @@ class XmlItem void init(XmlItem *parent = 0, XmlItem *precItem = 0); int row_; - bool isSelected_; + bool isVisible_; QList<XmlItem *> childs_; XmlItem *parent_; PolygonItem *graphicalItem_; @@ -63,17 +63,17 @@ inline PolygonItem *XmlItem::graphicalItem() inline void XmlItem::setGraphicalItem(PolygonItem *graphicalItem) { graphicalItem_ = graphicalItem; } -inline bool XmlItem::isSelected() const -{ return isSelected_; } +inline bool XmlItem::isVisible() const +{ return isVisible_; } -inline void XmlItem::setSelected(bool selected) -{ isSelected_ = selected; } +inline void XmlItem::setVisible(bool visible) +{ isVisible_ = visible; } -inline void XmlItem::select() -{ isSelected_ = true; } +inline void XmlItem::show() +{ isVisible_ = true; } -inline void XmlItem::unselect() -{ isSelected_ = false; } +inline void XmlItem::hide() +{ isVisible_ = false; } inline QString XmlItem::text() const { return text_; } diff --git a/GScribo/XmlWidget/xmlmodel.cpp b/GScribo/XmlWidget/xmlmodel.cpp index 460ddb4..ccc9443 100644 --- a/GScribo/XmlWidget/xmlmodel.cpp +++ b/GScribo/XmlWidget/xmlmodel.cpp @@ -37,7 +37,7 @@ QVariant XmlModel::data(const QModelIndex& index, int role) const return static_cast<XmlItem *>(index.internalPointer())->text(); case Qt::UserRole+1: - return static_cast<XmlItem *>(index.internalPointer())->isSelected(); + return static_cast<XmlItem *>(index.internalPointer())->isVisible(); case Qt::UserRole+2: return QVariant::fromValue(static_cast<XmlItem *>(index.internalPointer())->attributes()); diff --git a/GScribo/XmlWidget/xmlview.cpp b/GScribo/XmlWidget/xmlview.cpp new file mode 100644 index 0000000..e7488e0 --- /dev/null +++ b/GScribo/XmlWidget/xmlview.cpp @@ -0,0 +1,77 @@ +#include "xmlview.h" + +XmlView::XmlView(QWidget *parent) : + QTreeView(parent) +{ + proxy_.setFilterRole(Qt::UserRole+1); + proxy_.setDynamicSortFilter(true); + + setUniformRowHeights(true); + setItemDelegate(new XmlDelegate(Qt::UserRole)); + setSelectionMode(QAbstractItemView::ExtendedSelection); +} + +void XmlView::hideVisibles() +{ + XmlItem *child; + foreach(child, visibleItems_) + child->hide(); + + visibleItems_.clear(); +} + +void XmlView::onEndGraphicalSelection(const QList<QGraphicsItem *>& selectedItems) +{ + hideVisibles(); + + if(selectedItems.isEmpty()) + proxy_.selectAll(); + else + { + QGraphicsItem *child; + XmlItem *xmlItem; + foreach(child, selectedItems) + { + xmlItem = static_cast<PolygonItem *>(child)->xmlItem(); + xmlItem->show(); + visibleItems_ << xmlItem; + } + } + + proxy_.endResetModel(); + + emit resetAttributes(); + expandAll(); +} + +void XmlView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) +{ + QTreeView::selectionChanged(selected, deselected); + + if(!proxy_.isAllSelected()) + { + //if(emptySelection_) + //emit resetGraphicalSelection(); + + if(!selected.isEmpty()) + { + QList<PolygonItem *> sel; + QModelIndex index; + + foreach(index, selected.indexes()) + { + PolygonItem *graphicalItem = VariantPointer<PolygonItem>::fromQVariant(index.data(Qt::UserRole+3)); + + if(graphicalItem) + sel << graphicalItem; + } + + //emptySelection_ = false; + emit selection(sel, true); + } + //else + //emit resetGraphicalSelection(); + } + //else + //emptySelection_ = true; +} diff --git a/GScribo/XmlWidget/xmlview.h b/GScribo/XmlWidget/xmlview.h new file mode 100644 index 0000000..ce2b745 --- /dev/null +++ b/GScribo/XmlWidget/xmlview.h @@ -0,0 +1,51 @@ +#ifndef XMLVIEW_H +#define XMLVIEW_H + +#include <QGraphicsItem> +#include <QTreeView> + +#include "Rendering/polygonitem.h" +#include "selectionproxy.h" +#include "xmldelegate.h" +#include "xmlitem.h" + +class XmlView : + public QTreeView +{ + Q_OBJECT + + public: + explicit XmlView(QWidget *parent = 0); + + inline QList<XmlItem *> visibleItems() const; + void hideVisibles(); + + inline void setModel(QAbstractItemModel *model); + + protected: + void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); + + private: + QList<XmlItem *> visibleItems_; + SelectionProxy proxy_; + + public slots: + inline void onBeginGraphicalSelection(); + void onEndGraphicalSelection(const QList<QGraphicsItem *>& selectedItems); + + signals: + void selection(const QList<PolygonItem *>& selectedItems, bool addToSelection); + void resetGraphicalSelection(); + void resetAttributes(); +}; + +inline QList<XmlItem *> XmlView::visibleItems() const +{ return visibleItems_; } + +inline void XmlView::onBeginGraphicalSelection() +{ proxy_.beginResetModel(); } + +inline void XmlView::setModel(QAbstractItemModel *model) +{ proxy_.setSourceModel(model); QTreeView::setModel(&proxy_); } + +#endif // XMLVIEW_H diff --git a/GScribo/XmlWidget/xmlwidget.cpp b/GScribo/XmlWidget/xmlwidget.cpp index 3b0e055..b01aab3 100644 --- a/GScribo/XmlWidget/xmlwidget.cpp +++ b/GScribo/XmlWidget/xmlwidget.cpp @@ -10,41 +10,27 @@ XmlWidget::XmlWidget(QWidget *parent) : proxy_.setSourceModel(&model_); proxy_.setDynamicSortFilter(true); - selectionProxy_.setFilterRole(Qt::UserRole+1); - selectionProxy_.setSourceModel(&proxy_); - selectionProxy_.setDynamicSortFilter(true); - - selection_.setModel(&selectionProxy_); - selection_.setUniformRowHeights(true); - selection_.setItemDelegate(new XmlDelegate(Qt::UserRole)); + view_.setModel(&proxy_); + view_.setItemDelegate(new XmlDelegate(Qt::UserRole)); property_.setModel(&attributesModel_); property_.setUniformRowHeights(true); - property_.setItemsExpandable(false); property_.setColumnWidth(0, property_.width() / 2.5); property_.setSelectionMode(QAbstractItemView::NoSelection); property_.setItemDelegateForColumn(0, new XmlDelegate(Qt::UserRole)); property_.setItemDelegateForColumn(1, new XmlDelegate(Qt::UserRole+1)); - hLayout->addWidget(&selection_); + hLayout->addWidget(&view_); hLayout->addWidget(&property_); setLayout(hLayout); - connect(&selection_, SIGNAL(clicked(QModelIndex)), this, SLOT(onClick(QModelIndex))); + connect(&view_, SIGNAL(resetAttributes()), &property_, SLOT(reset())); } void XmlWidget::changeView(XmlItem *rootItem) { attributesModel_.reset(); model_.load(rootItem); -} - -void XmlWidget::onClick(const QModelIndex& index) -{ - attributesModel_.load(index.data(Qt::UserRole+2).value<XmlAttributes>()); - PolygonItem *graphicalItem = VariantPointer<PolygonItem>::fromQVariant(index.data(Qt::UserRole+3)); - - if(graphicalItem) - emit select(graphicalItem); + view_.expandAll(); } diff --git a/GScribo/XmlWidget/xmlwidget.h b/GScribo/XmlWidget/xmlwidget.h index a8063f9..9681f27 100644 --- a/GScribo/XmlWidget/xmlwidget.h +++ b/GScribo/XmlWidget/xmlwidget.h @@ -16,6 +16,7 @@ #include "variantpointer.h" #include "xmldelegate.h" #include "xmlmodel.h" +#include "xmlview.h" class XmlWidget : public QWidget @@ -25,33 +26,26 @@ class XmlWidget : public: explicit XmlWidget(QWidget *parent = 0); + inline XmlView *view(); + inline QTreeView *property(); + void changeView(XmlItem *rootItem); private: QSortFilterProxyModel proxy_; - SelectionProxy selectionProxy_; + SelectionProxy proxy2_; XmlModel model_; AttributeModel attributesModel_; - QTreeView selection_; + XmlView view_; QTreeView property_; - - public slots: - inline void onBeginGraphicalSelection(); - inline void onEndGraphicalSelection(); - - private slots: - void onClick(const QModelIndex& index); - - signals: - void select(PolygonItem *polygonItem); }; -inline void XmlWidget::onBeginGraphicalSelection() -{ selectionProxy_.beginResetModel(); } +inline XmlView *XmlWidget::view() +{ return &view_; } -inline void XmlWidget::onEndGraphicalSelection() -{ selectionProxy_.endResetModel(); attributesModel_.reset(); selection_.expandAll(); } +inline QTreeView *XmlWidget::property() +{ return &property_; } #endif // XMLWIDGET_H diff --git a/GScribo/listmodel.o b/GScribo/listmodel.o new file mode 100644 index 0000000..e1dcd0f Binary files /dev/null and b/GScribo/listmodel.o differ diff --git a/GScribo/mainwindow.cpp b/GScribo/mainwindow.cpp index 55a8f00..25c25d3 100644 --- a/GScribo/mainwindow.cpp +++ b/GScribo/mainwindow.cpp @@ -38,8 +38,7 @@ void MainWindow::initGraphicsRegion() void MainWindow::initPageWidget() { dockPages.setWindowTitle(tr("Pages")); - dockPages.setFeatures(QDockWidget::DockWidgetClosable); - //dockPages.setFixedWidth(190); + dockPages.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); dockPages.setWidget(&pagesWidget); addDockWidget(Qt::LeftDockWidgetArea, &dockPages); @@ -48,7 +47,7 @@ void MainWindow::initPageWidget() void MainWindow::initXmlWidget() { dockXml.setWindowTitle(tr("Xml")); - dockXml.setFeatures(QDockWidget::DockWidgetClosable); + dockXml.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); dockXml.setWidget(&xmlWidget); addDockWidget(Qt::BottomDockWidgetArea, &dockXml); @@ -72,9 +71,6 @@ void MainWindow::initToolBar() QAction *segment = ui->mainToolBar->addAction(tr("Segment")); connect(segment, SIGNAL(triggered()), this, SLOT(onSegment())); - - QAction *del = ui->mainToolBar->addAction(tr("Delete")); - connect(del, SIGNAL(triggered()), &pagesWidget, SLOT(removeSelection())); } void MainWindow::initMenuBar() @@ -95,7 +91,7 @@ void MainWindow::onFileChanged(const QString& filename) xml.load(xmlPath); scene.changeScene(filename, xml.graphicItem()); - xmlWidget.changeView(xml.treeItem()); + xmlWidget.changeView(xml.xmlItem()); } } @@ -134,10 +130,11 @@ void MainWindow::onOpen() } pagesWidget.setCurrentRow(0); - onFileChanged(path); + pagesWidget.scrollToTop(); } - else - onFileChanged(path); + + // Change current scene. + onFileChanged(path); } } @@ -161,7 +158,7 @@ void MainWindow::onSegment() void MainWindow::onXmlSaved(const QString& filename) { xml.load(filename); - xmlWidget.changeView(xml.treeItem()); + xmlWidget.changeView(xml.xmlItem()); scene.setRootItem(xml.graphicItem()); } @@ -171,15 +168,22 @@ void MainWindow::onPreferences() //preferenceDialog->show(); } +void MainWindow::onDelete() +{ + if(pagesWidget.hasFocus()) + pagesWidget.removeSelection(); +} + void MainWindow::connectWidgets() { // If double click on a picture of the page widget -> draw it on background scene. connect(&pagesWidget, SIGNAL(imageSelectionned(QString)), this, SLOT(onFileChanged(QString))); // Connect the scene to the xml widget and vice versa. - connect(&scene, SIGNAL(beginSelection()), &xmlWidget, SLOT(onBeginGraphicalSelection())); - connect(&scene, SIGNAL(endSelection()), &xmlWidget, SLOT(onEndGraphicalSelection())); - connect(&xmlWidget, SIGNAL(select(PolygonItem*)), &scene, SLOT(selectItem(PolygonItem*))); + connect(&scene, SIGNAL(beginSelection()), xmlWidget.view(), SLOT(onBeginGraphicalSelection())); + connect(&scene, SIGNAL(endSelection(QList<QGraphicsItem*>)), xmlWidget.view(), SLOT(onEndGraphicalSelection(QList<QGraphicsItem*>))); + connect(xmlWidget.view(), SIGNAL(selection(QList<PolygonItem*>,bool)), &scene, SLOT(selectItems(QList<PolygonItem*>, bool))); + connect(xmlWidget.view(), SIGNAL(resetGraphicalSelection()), &scene, SLOT(clearSelection())); /*connect(&runner, SIGNAL(progress()), &progressDialog, SLOT(run())); connect(&runner, SIGNAL(new_progress_max_value(int)), &progressDialog, SLOT(setMaximum(int))); @@ -191,7 +195,7 @@ void MainWindow::connectWidgets() void MainWindow::connectShortcuts() { QShortcut *del = new QShortcut(Qt::Key_Delete, &pagesWidget); - connect(del, SIGNAL(activated()), &pagesWidget, SLOT(removeSelection())); + connect(del, SIGNAL(activated()), this, SLOT(onDelete())); } void MainWindow::changeEvent(QEvent *e) diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h index 28132ca..ca79802 100644 --- a/GScribo/mainwindow.h +++ b/GScribo/mainwindow.h @@ -65,6 +65,7 @@ class MainWindow: void onXmlSaved(const QString& filename); void onPreferences(); void onFileChanged(const QString& filename); + void onDelete(); }; #endif // MAINWINDOW_H diff --git a/GScribo/moc_listmodel.cpp b/GScribo/moc_listmodel.cpp new file mode 100644 index 0000000..c1d5bdc --- /dev/null +++ b/GScribo/moc_listmodel.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'listmodel.h' +** +** Created: Fri Feb 8 10:30:41 2013 +** by: The Qt Meta Object Compiler version 62 (Qt 4.6.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "PagesWidget/listmodel.h" +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'listmodel.h' doesn't include <QObject>." +#elif Q_MOC_OUTPUT_REVISION != 62 +#error "This file was generated using the moc from 4.6.3. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +static const uint qt_meta_data_ListModel[] = { + + // content: + 4, // revision + 0, // classname + 0, 0, // classinfo + 1, 14, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 0, // signalCount + + // slots: signature, parameters, type, tag, flags + 18, 11, 10, 10, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_ListModel[] = { + "ListModel\0\0parent\0removePixmap(QModelIndex)\0" +}; + +const QMetaObject ListModel::staticMetaObject = { + { &QAbstractListModel::staticMetaObject, qt_meta_stringdata_ListModel, + qt_meta_data_ListModel, 0 } +}; + +#ifdef Q_NO_DATA_RELOCATION +const QMetaObject &ListModel::getStaticMetaObject() { return staticMetaObject; } +#endif //Q_NO_DATA_RELOCATION + +const QMetaObject *ListModel::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; +} + +void *ListModel::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_ListModel)) + return static_cast<void*>(const_cast< ListModel*>(this)); + return QAbstractListModel::qt_metacast(_clname); +} + +int ListModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QAbstractListModel::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + switch (_id) { + case 0: removePixmap((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; + default: ; + } + _id -= 1; + } + return _id; +} +QT_END_MOC_NAMESPACE diff --git a/GScribo/moc_listmodel.o b/GScribo/moc_listmodel.o new file mode 100644 index 0000000..53d3716 Binary files /dev/null and b/GScribo/moc_listmodel.o differ diff --git a/GScribo/region.h b/GScribo/region.h index e0c456e..1343ea6 100644 --- a/GScribo/region.h +++ b/GScribo/region.h @@ -7,7 +7,7 @@ namespace GraphicRegion { enum Id { - Text, + Text = 0, Line, Baseline, Meanline, @@ -27,7 +27,7 @@ namespace GraphicRegion { QColor color; QString name; - int region; + GraphicRegion::Id region; int zValue; }; } diff --git a/GScribo/xml.cpp b/GScribo/xml.cpp index 8a273db..36ad7e6 100644 --- a/GScribo/xml.cpp +++ b/GScribo/xml.cpp @@ -2,23 +2,23 @@ static const GraphicRegion::Data itemsData[] = { - /* COLOR | NAME | REGION | ZVALUE */ - { QColor::fromRgb(255, 0, 0, 90), "Line", (int)GraphicRegion::Line, 2 }, - { QColor::fromRgb(0, 100, 0, 90), "TextRegion", (int)GraphicRegion::Text, 1 }, - { QColor::fromRgb(0, 0, 255, 90), "VerticalSeparatorRegion", (int)GraphicRegion::VerticalSeparator, 2 }, - { QColor::fromRgb(0, 0, 255, 90), "HorizontalSeparatorRegion", (int)GraphicRegion::HorizontalSeparator, 2 }, - { QColor::fromRgb(0, 0, 128, 90), "WhitespaceSeparatorRegion", (int)GraphicRegion::WhiteSpaceSeparator, 2 }, - { QColor::fromRgb(255, 120, 0, 90), "ImageRegion", (int)GraphicRegion::Image, 1 }, - { QColor::fromRgb(43, 39, 128, 90), "NoiseRegion", (int)GraphicRegion::Noise, 2 }, - { QColor::fromRgb(220, 246, 0, 90), "TableRegion", (int)GraphicRegion::Table, 2 }, - { QColor::fromRgb(170, 0, 255, 90), "MathsRegion", (int)GraphicRegion::Maths, 2 }, - { QColor::fromRgb(255, 0, 144, 90), "GraphicRegion", (int)GraphicRegion::Graphic, 2 }, - { QColor::fromRgb(0, 204, 255, 90), "ChartRegion", (int)GraphicRegion::Chart, 2 } + /* COLOR | NAME | REGION | ZVALUE */ + { QColor::fromRgb(255, 0, 0, 90), "Line", GraphicRegion::Line, 2 }, + { QColor::fromRgb(0, 100, 0, 90), "TextRegion", GraphicRegion::Text, 1 }, + { QColor::fromRgb(0, 0, 255, 90), "VerticalSeparatorRegion", GraphicRegion::VerticalSeparator, 2 }, + { QColor::fromRgb(0, 0, 255, 90), "HorizontalSeparatorRegion", GraphicRegion::HorizontalSeparator, 2 }, + { QColor::fromRgb(0, 0, 128, 90), "WhitespaceSeparatorRegion", GraphicRegion::WhiteSpaceSeparator, 2 }, + { QColor::fromRgb(255, 120, 0, 90), "ImageRegion", GraphicRegion::Image, 1 }, + { QColor::fromRgb(43, 39, 128, 90), "NoiseRegion", GraphicRegion::Noise, 2 }, + { QColor::fromRgb(220, 246, 0, 90), "TableRegion", GraphicRegion::Table, 2 }, + { QColor::fromRgb(170, 0, 255, 90), "MathsRegion", GraphicRegion::Maths, 2 }, + { QColor::fromRgb(255, 0, 144, 90), "GraphicRegion", GraphicRegion::Graphic, 2 }, + { QColor::fromRgb(0, 204, 255, 90), "ChartRegion", GraphicRegion::Chart, 2 } }; Xml::Xml(const QString& filename) { - path = filename; + filename_ = filename; load(filename); } @@ -42,29 +42,30 @@ void Xml::load(const QString& filename) { if(filename.isEmpty()) { - tItem = 0; - gItem = 0; + xmlItem_ = 0; + graphicalItem_ = 0; return; } // Reset graphic and tree items; - tItem = new XmlItem; - gItem = new QGraphicsPolygonItem; + xmlItem_ = new XmlItem; + graphicalItem_ = new RootGraphicsItem(11); QFile xmlFile(filename); xmlFile.open(QIODevice::ReadOnly); // Fill new xml tree. - xml.clear(); - xml.setContent(&xmlFile); + xml_.clear(); + xml_.setContent(&xmlFile); xmlFile.close(); - QDomElement root = xml.documentElement(); - tItem->load(root); + QDomElement root = xml_.documentElement(); + xmlItem_->load(root); + xmlItem_->show(); root = root.firstChild().toElement(); - XmlItem *parentTreeItem = init(root, tItem); + XmlItem *parentTreeItem = init(root, xmlItem_); // Run through the xml file structure by structure. root = root.nextSibling().firstChild().toElement(); @@ -89,6 +90,7 @@ XmlItem *Xml::init(const QDomElement& root, XmlItem *rootTreeItem) // Add "PAGE" root node and return it. metadataItem = new XmlItem(root.nextSibling().toElement(), rootTreeItem, metadataItem); + metadataItem->show(); return metadataItem; } @@ -121,22 +123,23 @@ void Xml::processNode(const QDomElement& root, const GraphicRegion::Data& data, } // Create the graphical item from data structure. - PolygonItem *polygonItem = new PolygonItem(polygon, gItem); + PolygonItem *polygonItem = new PolygonItem(polygon, graphicalItem_); polygonItem->loadData(data); + graphicalItem_->addItemFrom(polygonItem, data.region); // Store xml item and graphical item in each object for selection. regionItem->setGraphicalItem(polygonItem); polygonItem->setXmlItem(regionItem); if(data.region == GraphicRegion::Text) - processLineNode(root.firstChild().nextSiblingElement("Line"), polygonItem, coordsItem); + processLineNode(root.firstChild().nextSiblingElement("Line"), coordsItem); // Run through all nodes from the same data structure recursively. processNode(root.nextSiblingElement(data.name), data, pageItem); } } -void Xml::processLineNode(const QDomElement& root, PolygonItem *parentPolygonItem, XmlItem *precItem) +void Xml::processLineNode(const QDomElement& root, XmlItem *precItem) { if(!root.isNull()) { @@ -178,8 +181,9 @@ void Xml::processLineNode(const QDomElement& root, PolygonItem *parentPolygonIte } // Create the graphical item from data structure. - PolygonItem *polygonItem = new PolygonItem(polygon, parentPolygonItem); + PolygonItem *polygonItem = new PolygonItem(polygon, graphicalItem_); polygonItem->loadData(itemsData[0]); + graphicalItem_->addItemFrom(polygonItem, GraphicRegion::Line); // Store xml item and graphical item in each object for selection. lineItem->setGraphicalItem(polygonItem); @@ -188,7 +192,7 @@ void Xml::processLineNode(const QDomElement& root, PolygonItem *parentPolygonIte // Get meanline and baseline. processTypoNode(root, QPoint(xMin, xMax), polygonItem); // Run through all line nodes recursively. - processLineNode(root.nextSiblingElement("Line"), parentPolygonItem, lineItem); + processLineNode(root.nextSiblingElement("Line"), lineItem); } } @@ -196,11 +200,11 @@ void Xml::processTypoNode(const QDomElement& root, const QPoint& xPoint, Polygon { int yPos = root.attribute("baseline", "null").toInt(); QGraphicsLineItem *baselineItem = new QGraphicsLineItem(QLine(QPoint(xPoint.x(), yPos), QPoint(xPoint.y(), yPos)), parentPolygonItem); - baselineItem->setData(0, QVariant::fromValue((int)GraphicRegion::Baseline)); baselineItem->setZValue(3); + graphicalItem_->addItemFrom(baselineItem, GraphicRegion::Baseline); yPos = root.attribute("meanline", "null").toInt(); QGraphicsLineItem *meanlineItem = new QGraphicsLineItem(QLine(QPoint(xPoint.x(), yPos), QPoint(xPoint.y(), yPos)), parentPolygonItem); - meanlineItem->setData(0, QVariant::fromValue((int)GraphicRegion::Meanline)); meanlineItem->setZValue(3); + graphicalItem_->addItemFrom(baselineItem, GraphicRegion::Meanline); } diff --git a/GScribo/xml.h b/GScribo/xml.h index 6637260..fb8d9b7 100644 --- a/GScribo/xml.h +++ b/GScribo/xml.h @@ -8,6 +8,7 @@ #include <climits> #include <QFile> +#include "Rendering/rootgraphicsitem.h" #include "Rendering/polygonitem.h" #include "XmlWidget/xmlitem.h" #include "variantpointer.h" @@ -19,8 +20,8 @@ class Xml public: explicit Xml(const QString& filename = QString()); - inline XmlItem *treeItem(); - inline QGraphicsItem *graphicItem(); + inline XmlItem *xmlItem(); + inline RootGraphicsItem *graphicItem(); inline QDomDocument document() const; inline QString filename() const; @@ -30,25 +31,25 @@ class Xml private: XmlItem *init(const QDomElement& root, XmlItem *rootTreeItem); void processNode(const QDomElement& root, const GraphicRegion::Data& data, XmlItem *rootTreeItem); - void processLineNode(const QDomElement& root, PolygonItem *parentPolygonItem, XmlItem *rootTreeItem); + void processLineNode(const QDomElement& root, XmlItem *rootTreeItem); void processTypoNode(const QDomElement& root, const QPoint& xPoint, PolygonItem *rootPolygonItem); - QGraphicsPolygonItem *gItem; - XmlItem *tItem; - QDomDocument xml; - QString path; + RootGraphicsItem *graphicalItem_; + XmlItem *xmlItem_; + QDomDocument xml_; + QString filename_; }; -inline XmlItem *Xml::treeItem() -{ return tItem; } +inline XmlItem *Xml::xmlItem() +{ return xmlItem_; } -inline QGraphicsItem *Xml::graphicItem() -{ return gItem; } +inline RootGraphicsItem *Xml::graphicItem() +{ return graphicalItem_; } inline QDomDocument Xml::document() const -{ return xml; } +{ return xml_; } inline QString Xml::filename() const -{ return path; } +{ return filename_; } #endif // XML_H -- 1.7.2.5
participants (1)
-
Antoine Froger