* scribo/demo/viewer/BUGS, * scribo/demo/viewer/GScribo.pro, * scribo/demo/viewer/GScribo.pro.user, * scribo/demo/viewer/GScribo.pro.user.1.3, * scribo/demo/viewer/Makefile.am, * scribo/demo/viewer/PagesWidget/pagesdelegate.cc, * scribo/demo/viewer/PagesWidget/pagesdelegate.hh, * scribo/demo/viewer/PagesWidget/pagesmodel.cc, * scribo/demo/viewer/PagesWidget/pagesmodel.hh, * scribo/demo/viewer/PagesWidget/pageswidget.cc, * scribo/demo/viewer/PagesWidget/pageswidget.hh, * scribo/demo/viewer/Preferences/generaloptions.cc, * scribo/demo/viewer/Preferences/generaloptions.hh, * scribo/demo/viewer/Preferences/generaloptions.ui, * scribo/demo/viewer/Preferences/ocroptions.cc, * scribo/demo/viewer/Preferences/ocroptions.hh, * scribo/demo/viewer/Preferences/ocroptions.ui, * scribo/demo/viewer/Preferences/optionwidget.hh, * scribo/demo/viewer/Preferences/preferencesdialog.cc, * scribo/demo/viewer/Preferences/preferencesdialog.hh, * scribo/demo/viewer/Preferences/preferencesdialog.ui, * scribo/demo/viewer/Preferences/preprocessingoptions.cc, * scribo/demo/viewer/Preferences/preprocessingoptions.hh, * scribo/demo/viewer/Preferences/preprocessingoptions.ui, * scribo/demo/viewer/Preferences/segmentationoptions.cc, * scribo/demo/viewer/Preferences/segmentationoptions.hh, * scribo/demo/viewer/Preferences/segmentationoptions.ui, * scribo/demo/viewer/Processing/preprocess.cc, * scribo/demo/viewer/Processing/preprocess.hh, * scribo/demo/viewer/Processing/process.cc, * scribo/demo/viewer/Processing/process.hh, * scribo/demo/viewer/Processing/progressdialog.cc, * scribo/demo/viewer/Processing/progressdialog.hh, * scribo/demo/viewer/Processing/runner.cc, * scribo/demo/viewer/Processing/runner.hh, * scribo/demo/viewer/Rendering/abstractregionitem.hh, * scribo/demo/viewer/Rendering/backgroundtexture.hh, * scribo/demo/viewer/Rendering/graphicsview.cc, * scribo/demo/viewer/Rendering/graphicsview.hh, * scribo/demo/viewer/Rendering/regionitem.cc, * scribo/demo/viewer/Rendering/regionitem.hh, * scribo/demo/viewer/Rendering/rootgraphicsitem.cc, * scribo/demo/viewer/Rendering/rootgraphicsitem.hh, * scribo/demo/viewer/Rendering/scene.cc, * scribo/demo/viewer/Rendering/scene.hh, * scribo/demo/viewer/Rendering/selection.cc, * scribo/demo/viewer/Rendering/selection.hh, * scribo/demo/viewer/TODO, * scribo/demo/viewer/XmlWidget/attributesmodel.cc, * scribo/demo/viewer/XmlWidget/attributesmodel.hh, * scribo/demo/viewer/XmlWidget/selectionproxy.hh, * scribo/demo/viewer/XmlWidget/xmlattributes.cc, * scribo/demo/viewer/XmlWidget/xmlattributes.hh, * scribo/demo/viewer/XmlWidget/xmldelegate.hh, * scribo/demo/viewer/XmlWidget/xmlitem.cc, * scribo/demo/viewer/XmlWidget/xmlitem.hh, * scribo/demo/viewer/XmlWidget/xmlmodel.cc, * scribo/demo/viewer/XmlWidget/xmlmodel.hh, * scribo/demo/viewer/XmlWidget/xmlview.cc, * scribo/demo/viewer/XmlWidget/xmlview.hh, * scribo/demo/viewer/XmlWidget/xmlwidget.cc, * scribo/demo/viewer/XmlWidget/xmlwidget.hh, * scribo/demo/viewer/aboutdialog.cc, * scribo/demo/viewer/aboutdialog.hh, * scribo/demo/viewer/aboutdialog.ui, * scribo/demo/viewer/config.cc, * scribo/demo/viewer/configs.cc, * scribo/demo/viewer/configs.hh, * scribo/demo/viewer/defs.hh, * scribo/demo/viewer/dir.hh, * scribo/demo/viewer/dockwidget.cc, * scribo/demo/viewer/dockwidget.hh, * scribo/demo/viewer/general_options.hh, * scribo/demo/viewer/help_dialog.hh, * scribo/demo/viewer/image_scene.hh, * scribo/demo/viewer/image_view.hh, * scribo/demo/viewer/main.cc, * scribo/demo/viewer/mainwindow.cc, * scribo/demo/viewer/mainwindow.hh, * scribo/demo/viewer/mainwindow.ui, * scribo/demo/viewer/ocr_options.hh, * scribo/demo/viewer/option_widget.cc, * scribo/demo/viewer/option_widget.hh, * scribo/demo/viewer/preprocess.cc, * scribo/demo/viewer/preprocess.hh, * scribo/demo/viewer/process.cc, * scribo/demo/viewer/region.hh, * scribo/demo/viewer/regionwidget.cc, * scribo/demo/viewer/regionwidget.hh, * scribo/demo/viewer/variantpointer.cc, * scribo/demo/viewer/variantpointer.hh, * scribo/demo/viewer/xml.cc, * scribo/demo/viewer/xml.hh: New.
* scribo/demo/viewer/README, * scribo/demo/viewer/browser_widget.cc, * scribo/demo/viewer/browser_widget.hh, * scribo/demo/viewer/common.hh, * scribo/demo/viewer/config.hh, * scribo/demo/viewer/general_options.cc, * scribo/demo/viewer/general_options.ui, * scribo/demo/viewer/help_dialog.cc, * scribo/demo/viewer/help_dialog.ui, * scribo/demo/viewer/icons/olena_smaller.jpg, * scribo/demo/viewer/image_region.cc, * scribo/demo/viewer/image_region.hh, * scribo/demo/viewer/image_region.hxx, * scribo/demo/viewer/image_scene.cc, * scribo/demo/viewer/image_view.cc, * scribo/demo/viewer/image_widget.cc, * scribo/demo/viewer/image_widget.hh, * scribo/demo/viewer/key_widget.cc, * scribo/demo/viewer/key_widget.hh, * scribo/demo/viewer/ocr_options.cc, * scribo/demo/viewer/ocr_options.ui, * scribo/demo/viewer/preferences_dialog.cc, * scribo/demo/viewer/preferences_dialog.hh, * scribo/demo/viewer/preferences_dialog.ui, * scribo/demo/viewer/preprocessing_options.cc, * scribo/demo/viewer/preprocessing_options.hh, * scribo/demo/viewer/preprocessing_options.ui, * scribo/demo/viewer/process.hh, * scribo/demo/viewer/runner.cc, * scribo/demo/viewer/runner.hh, * scribo/demo/viewer/segmentation_options.cc, * scribo/demo/viewer/segmentation_options.hh, * scribo/demo/viewer/segmentation_options.ui, * scribo/demo/viewer/step_widget.cc, * scribo/demo/viewer/step_widget.hh, * scribo/demo/viewer/viewer.cc, * scribo/demo/viewer/viewer.hh, * scribo/demo/viewer/viewer.hxx, * scribo/demo/viewer/viewer.qrc , * scribo/demo/viewer/xml_widget.cc, * scribo/demo/viewer/xml_widget.hh: Remove. --- ChangeLog | 80 ++ GScribo/GScribo.pro | 83 -- GScribo/PagesWidget/pagesdelegate.cpp | 20 - GScribo/PagesWidget/pagesdelegate.h | 18 - GScribo/PagesWidget/pagesmodel.cpp | 55 -- GScribo/PagesWidget/pagesmodel.h | 43 - GScribo/PagesWidget/pageswidget.cpp | 49 - GScribo/PagesWidget/pageswidget.h | 55 -- GScribo/Preferences/generaloptions.cpp | 44 - GScribo/Preferences/generaloptions.h | 34 - GScribo/Preferences/ocroptions.cpp | 53 - GScribo/Preferences/ocroptions.h | 33 - GScribo/Preferences/preferencesdialog.cpp | 98 -- GScribo/Preferences/preferencesdialog.h | 42 - GScribo/Preferences/preprocessingoptions.cpp | 45 - GScribo/Preferences/preprocessingoptions.h | 32 - GScribo/Preferences/segmentationoptions.cpp | 33 - GScribo/Preferences/segmentationoptions.h | 31 - GScribo/Processing/preprocess.cpp | 11 - GScribo/Processing/preprocess.h | 26 - GScribo/Processing/process.cpp | 21 - GScribo/Processing/process.h | 29 - GScribo/Processing/progressdialog.cpp | 16 - GScribo/Processing/progressdialog.h | 22 - GScribo/Processing/runner.cpp | 183 ---- GScribo/Processing/runner.h | 58 -- GScribo/Rendering/graphicsview.cpp | 150 --- GScribo/Rendering/graphicsview.h | 43 - GScribo/Rendering/regionitem.cpp | 59 -- GScribo/Rendering/regionitem.h | 80 -- GScribo/Rendering/rootgraphicsitem.h | 30 - GScribo/Rendering/scene.cpp | 273 ------ GScribo/Rendering/scene.h | 118 --- GScribo/Rendering/selection.cpp | 36 - GScribo/XmlWidget/attributesmodel.cpp | 69 -- GScribo/XmlWidget/attributesmodel.h | 48 - GScribo/XmlWidget/selectionproxy.h | 47 - GScribo/XmlWidget/xmlattributes.cpp | 23 - GScribo/XmlWidget/xmlattributes.h | 33 - GScribo/XmlWidget/xmlitem.cpp | 43 - GScribo/XmlWidget/xmlitem.h | 90 -- GScribo/XmlWidget/xmlmodel.cpp | 87 -- GScribo/XmlWidget/xmlmodel.h | 44 - GScribo/XmlWidget/xmlview.cpp | 88 -- GScribo/XmlWidget/xmlview.h | 79 -- GScribo/XmlWidget/xmlwidget.cpp | 34 - GScribo/XmlWidget/xmlwidget.h | 54 - GScribo/aboutdialog.h | 25 - GScribo/aboutdialog.ui | 136 --- GScribo/configs.h | 134 --- GScribo/dockwidget.h | 22 - GScribo/main.cpp | 23 - GScribo/mainwindow.cpp | 415 -------- GScribo/mainwindow.h | 120 --- GScribo/region.h | 56 -- GScribo/regionwidget.cpp | 70 -- GScribo/regionwidget.h | 40 - GScribo/variantpointer.h | 19 - GScribo/xml.cpp | 206 ---- GScribo/xml.h | 93 -- scribo/ChangeLog | 140 +++ {GScribo => scribo/demo/viewer}/BUGS | 0 scribo/demo/viewer/GScribo.pro | 83 ++ {GScribo => scribo/demo/viewer}/GScribo.pro.user | 0 .../demo/viewer}/GScribo.pro.user.1.3 | 0 scribo/demo/viewer/Makefile.am | 204 +++-- scribo/demo/viewer/PagesWidget/pagesdelegate.cc | 38 + scribo/demo/viewer/PagesWidget/pagesdelegate.hh | 36 + scribo/demo/viewer/PagesWidget/pagesmodel.cc | 91 ++ scribo/demo/viewer/PagesWidget/pagesmodel.hh | 51 + scribo/demo/viewer/PagesWidget/pageswidget.cc | 119 +++ scribo/demo/viewer/PagesWidget/pageswidget.hh | 61 ++ scribo/demo/viewer/Preferences/generaloptions.cc | 60 ++ scribo/demo/viewer/Preferences/generaloptions.hh | 50 + .../demo/viewer}/Preferences/generaloptions.ui | 0 scribo/demo/viewer/Preferences/ocroptions.cc | 69 ++ scribo/demo/viewer/Preferences/ocroptions.hh | 49 + .../demo/viewer}/Preferences/ocroptions.ui | 0 .../demo/viewer/Preferences/optionwidget.hh | 0 .../demo/viewer/Preferences/preferencesdialog.cc | 120 +++ .../demo/viewer/Preferences/preferencesdialog.hh | 55 ++ .../demo/viewer}/Preferences/preferencesdialog.ui | 0 .../viewer/Preferences/preprocessingoptions.cc | 61 ++ .../viewer/Preferences/preprocessingoptions.hh | 48 + .../viewer}/Preferences/preprocessingoptions.ui | 0 .../demo/viewer/Preferences/segmentationoptions.cc | 49 + .../demo/viewer/Preferences/segmentationoptions.hh | 46 + .../viewer}/Preferences/segmentationoptions.ui | 0 scribo/demo/viewer/Processing/preprocess.cc | 27 + scribo/demo/viewer/Processing/preprocess.hh | 42 + scribo/demo/viewer/Processing/process.cc | 37 + scribo/demo/viewer/Processing/process.hh | 45 + scribo/demo/viewer/Processing/progressdialog.cc | 37 + scribo/demo/viewer/Processing/progressdialog.hh | 36 + scribo/demo/viewer/Processing/runner.cc | 199 ++++ scribo/demo/viewer/Processing/runner.hh | 74 ++ scribo/demo/viewer/README | 32 - .../demo/viewer/Rendering/abstractregionitem.hh | 0 .../demo/viewer/Rendering/backgroundtexture.hh | 0 scribo/demo/viewer/Rendering/graphicsview.cc | 165 ++++ scribo/demo/viewer/Rendering/graphicsview.hh | 59 ++ scribo/demo/viewer/Rendering/regionitem.cc | 130 +++ scribo/demo/viewer/Rendering/regionitem.hh | 66 ++ scribo/demo/viewer/Rendering/rootgraphicsitem.cc | 46 + scribo/demo/viewer/Rendering/rootgraphicsitem.hh | 39 + scribo/demo/viewer/Rendering/scene.cc | 289 ++++++ scribo/demo/viewer/Rendering/scene.hh | 118 +++ scribo/demo/viewer/Rendering/selection.cc | 52 + .../demo/viewer/Rendering/selection.hh | 0 {GScribo => scribo/demo/viewer}/TODO | 0 scribo/demo/viewer/XmlWidget/attributesmodel.cc | 108 ++ scribo/demo/viewer/XmlWidget/attributesmodel.hh | 55 ++ scribo/demo/viewer/XmlWidget/selectionproxy.hh | 47 + scribo/demo/viewer/XmlWidget/xmlattributes.cc | 49 + scribo/demo/viewer/XmlWidget/xmlattributes.hh | 44 + .../demo/viewer/XmlWidget/xmldelegate.hh | 0 scribo/demo/viewer/XmlWidget/xmlitem.cc | 59 ++ scribo/demo/viewer/XmlWidget/xmlitem.hh | 106 ++ scribo/demo/viewer/XmlWidget/xmlmodel.cc | 123 +++ scribo/demo/viewer/XmlWidget/xmlmodel.hh | 51 + scribo/demo/viewer/XmlWidget/xmlview.cc | 104 ++ scribo/demo/viewer/XmlWidget/xmlview.hh | 95 ++ scribo/demo/viewer/XmlWidget/xmlwidget.cc | 66 ++ scribo/demo/viewer/XmlWidget/xmlwidget.hh | 61 ++ scribo/demo/viewer/aboutdialog.cc | 31 + scribo/demo/viewer/aboutdialog.hh | 40 + scribo/demo/viewer/aboutdialog.ui | 136 +++ scribo/demo/viewer/browser_widget.cc | 138 --- scribo/demo/viewer/browser_widget.hh | 50 - scribo/demo/viewer/common.hh | 73 -- scribo/demo/viewer/config.cc | 182 ---- scribo/demo/viewer/config.hh | 78 -- scribo/demo/viewer/configs.cc | 149 +++ scribo/demo/viewer/configs.hh | 74 ++ scribo/demo/viewer/defs.hh | 31 - GScribo/dir.h => scribo/demo/viewer/dir.hh | 0 scribo/demo/viewer/dockwidget.cc | 34 + scribo/demo/viewer/dockwidget.hh | 36 + scribo/demo/viewer/general_options.cc | 60 -- scribo/demo/viewer/general_options.hh | 40 - scribo/demo/viewer/general_options.ui | 100 -- scribo/demo/viewer/help_dialog.cc | 23 - scribo/demo/viewer/help_dialog.hh | 31 - scribo/demo/viewer/help_dialog.ui | 138 --- scribo/demo/viewer/icons/olena_smaller.jpg | Bin 8028 -> 0 bytes scribo/demo/viewer/image_region.cc | 138 --- scribo/demo/viewer/image_region.hh | 79 -- scribo/demo/viewer/image_region.hxx | 106 -- scribo/demo/viewer/image_scene.cc | 104 -- scribo/demo/viewer/image_scene.hh | 45 - scribo/demo/viewer/image_view.cc | 80 -- scribo/demo/viewer/image_view.hh | 42 - scribo/demo/viewer/image_widget.cc | 61 -- scribo/demo/viewer/image_widget.hh | 47 - scribo/demo/viewer/key_widget.cc | 162 --- scribo/demo/viewer/key_widget.hh | 55 -- scribo/demo/viewer/main.cc | 44 +- scribo/demo/viewer/mainwindow.cc | 496 ++++++++++ scribo/demo/viewer/mainwindow.hh | 130 +++ {GScribo => scribo/demo/viewer}/mainwindow.ui | 0 scribo/demo/viewer/ocr_options.cc | 74 -- scribo/demo/viewer/ocr_options.hh | 40 - scribo/demo/viewer/ocr_options.ui | 62 -- scribo/demo/viewer/option_widget.cc | 30 - scribo/demo/viewer/option_widget.hh | 30 - scribo/demo/viewer/preferences_dialog.cc | 129 --- scribo/demo/viewer/preferences_dialog.hh | 45 - scribo/demo/viewer/preferences_dialog.ui | 121 --- scribo/demo/viewer/preprocess.cc | 29 - scribo/demo/viewer/preprocess.hh | 41 - scribo/demo/viewer/preprocessing_options.cc | 66 -- scribo/demo/viewer/preprocessing_options.hh | 38 - scribo/demo/viewer/preprocessing_options.ui | 76 -- scribo/demo/viewer/process.cc | 42 - scribo/demo/viewer/process.hh | 46 - scribo/demo/viewer/region.hh | 72 ++ scribo/demo/viewer/regionwidget.cc | 114 +++ scribo/demo/viewer/regionwidget.hh | 58 ++ scribo/demo/viewer/runner.cc | 243 ----- scribo/demo/viewer/runner.hh | 73 -- scribo/demo/viewer/segmentation_options.cc | 56 -- scribo/demo/viewer/segmentation_options.hh | 37 - scribo/demo/viewer/segmentation_options.ui | 52 - scribo/demo/viewer/step_widget.cc | 178 ---- scribo/demo/viewer/step_widget.hh | 56 -- scribo/demo/viewer/variantpointer.cc | 39 + scribo/demo/viewer/variantpointer.hh | 33 + scribo/demo/viewer/viewer.cc | 1021 -------------------- scribo/demo/viewer/viewer.hh | 132 --- scribo/demo/viewer/viewer.hxx | 38 - scribo/demo/viewer/viewer.qrc | 5 - scribo/demo/viewer/xml.cc | 253 +++++ scribo/demo/viewer/xml.hh | 91 ++ scribo/demo/viewer/xml_widget.cc | 164 ---- scribo/demo/viewer/xml_widget.hh | 48 - 195 files changed, 5660 insertions(+), 8997 deletions(-) delete mode 100644 GScribo/GScribo.pro delete mode 100644 GScribo/PagesWidget/pagesdelegate.cpp delete mode 100644 GScribo/PagesWidget/pagesdelegate.h delete mode 100644 GScribo/PagesWidget/pagesmodel.cpp delete mode 100644 GScribo/PagesWidget/pagesmodel.h delete mode 100644 GScribo/PagesWidget/pageswidget.cpp delete mode 100644 GScribo/PagesWidget/pageswidget.h delete mode 100644 GScribo/Preferences/generaloptions.cpp delete mode 100644 GScribo/Preferences/generaloptions.h delete mode 100644 GScribo/Preferences/ocroptions.cpp delete mode 100644 GScribo/Preferences/ocroptions.h delete mode 100644 GScribo/Preferences/preferencesdialog.cpp delete mode 100644 GScribo/Preferences/preferencesdialog.h delete mode 100644 GScribo/Preferences/preprocessingoptions.cpp delete mode 100644 GScribo/Preferences/preprocessingoptions.h delete mode 100644 GScribo/Preferences/segmentationoptions.cpp delete mode 100644 GScribo/Preferences/segmentationoptions.h delete mode 100644 GScribo/Processing/preprocess.cpp delete mode 100644 GScribo/Processing/preprocess.h delete mode 100644 GScribo/Processing/process.cpp delete mode 100644 GScribo/Processing/process.h delete mode 100644 GScribo/Processing/progressdialog.cpp delete mode 100644 GScribo/Processing/progressdialog.h delete mode 100644 GScribo/Processing/runner.cpp delete mode 100644 GScribo/Processing/runner.h delete mode 100644 GScribo/Rendering/graphicsview.cpp delete mode 100644 GScribo/Rendering/graphicsview.h delete mode 100644 GScribo/Rendering/regionitem.cpp delete mode 100644 GScribo/Rendering/regionitem.h delete mode 100644 GScribo/Rendering/rootgraphicsitem.h delete mode 100644 GScribo/Rendering/scene.cpp delete mode 100644 GScribo/Rendering/scene.h delete mode 100644 GScribo/Rendering/selection.cpp delete mode 100644 GScribo/XmlWidget/attributesmodel.cpp delete mode 100644 GScribo/XmlWidget/attributesmodel.h delete mode 100644 GScribo/XmlWidget/selectionproxy.h delete mode 100644 GScribo/XmlWidget/xmlattributes.cpp delete mode 100644 GScribo/XmlWidget/xmlattributes.h delete mode 100644 GScribo/XmlWidget/xmlitem.cpp delete mode 100644 GScribo/XmlWidget/xmlitem.h delete mode 100644 GScribo/XmlWidget/xmlmodel.cpp delete mode 100644 GScribo/XmlWidget/xmlmodel.h delete mode 100644 GScribo/XmlWidget/xmlview.cpp delete mode 100644 GScribo/XmlWidget/xmlview.h delete mode 100644 GScribo/XmlWidget/xmlwidget.cpp delete mode 100644 GScribo/XmlWidget/xmlwidget.h delete mode 100644 GScribo/aboutdialog.h delete mode 100644 GScribo/aboutdialog.ui delete mode 100644 GScribo/configs.h delete mode 100644 GScribo/dockwidget.h delete mode 100644 GScribo/main.cpp delete mode 100644 GScribo/mainwindow.cpp delete mode 100644 GScribo/mainwindow.h delete mode 100644 GScribo/region.h delete mode 100644 GScribo/regionwidget.cpp delete mode 100644 GScribo/regionwidget.h delete mode 100644 GScribo/variantpointer.h delete mode 100644 GScribo/xml.cpp delete mode 100644 GScribo/xml.h rename {GScribo => scribo/demo/viewer}/BUGS (100%) create mode 100644 scribo/demo/viewer/GScribo.pro rename {GScribo => scribo/demo/viewer}/GScribo.pro.user (100%) rename {GScribo => scribo/demo/viewer}/GScribo.pro.user.1.3 (100%) create mode 100644 scribo/demo/viewer/PagesWidget/pagesdelegate.cc create mode 100644 scribo/demo/viewer/PagesWidget/pagesdelegate.hh create mode 100644 scribo/demo/viewer/PagesWidget/pagesmodel.cc create mode 100644 scribo/demo/viewer/PagesWidget/pagesmodel.hh create mode 100644 scribo/demo/viewer/PagesWidget/pageswidget.cc create mode 100644 scribo/demo/viewer/PagesWidget/pageswidget.hh create mode 100644 scribo/demo/viewer/Preferences/generaloptions.cc create mode 100644 scribo/demo/viewer/Preferences/generaloptions.hh rename {GScribo => scribo/demo/viewer}/Preferences/generaloptions.ui (100%) create mode 100644 scribo/demo/viewer/Preferences/ocroptions.cc create mode 100644 scribo/demo/viewer/Preferences/ocroptions.hh rename {GScribo => scribo/demo/viewer}/Preferences/ocroptions.ui (100%) rename GScribo/Preferences/optionwidget.h => scribo/demo/viewer/Preferences/optionwidget.hh (100%) create mode 100644 scribo/demo/viewer/Preferences/preferencesdialog.cc create mode 100644 scribo/demo/viewer/Preferences/preferencesdialog.hh rename {GScribo => scribo/demo/viewer}/Preferences/preferencesdialog.ui (100%) create mode 100644 scribo/demo/viewer/Preferences/preprocessingoptions.cc create mode 100644 scribo/demo/viewer/Preferences/preprocessingoptions.hh rename {GScribo => scribo/demo/viewer}/Preferences/preprocessingoptions.ui (100%) create mode 100644 scribo/demo/viewer/Preferences/segmentationoptions.cc create mode 100644 scribo/demo/viewer/Preferences/segmentationoptions.hh rename {GScribo => scribo/demo/viewer}/Preferences/segmentationoptions.ui (100%) create mode 100644 scribo/demo/viewer/Processing/preprocess.cc create mode 100644 scribo/demo/viewer/Processing/preprocess.hh create mode 100644 scribo/demo/viewer/Processing/process.cc create mode 100644 scribo/demo/viewer/Processing/process.hh create mode 100644 scribo/demo/viewer/Processing/progressdialog.cc create mode 100644 scribo/demo/viewer/Processing/progressdialog.hh create mode 100644 scribo/demo/viewer/Processing/runner.cc create mode 100644 scribo/demo/viewer/Processing/runner.hh delete mode 100644 scribo/demo/viewer/README rename GScribo/Rendering/abstractregionitem.h => scribo/demo/viewer/Rendering/abstractregionitem.hh (100%) rename GScribo/Rendering/backgroundtexture.h => scribo/demo/viewer/Rendering/backgroundtexture.hh (100%) create mode 100644 scribo/demo/viewer/Rendering/graphicsview.cc create mode 100644 scribo/demo/viewer/Rendering/graphicsview.hh create mode 100644 scribo/demo/viewer/Rendering/regionitem.cc create mode 100644 scribo/demo/viewer/Rendering/regionitem.hh create mode 100644 scribo/demo/viewer/Rendering/rootgraphicsitem.cc create mode 100644 scribo/demo/viewer/Rendering/rootgraphicsitem.hh create mode 100644 scribo/demo/viewer/Rendering/scene.cc create mode 100644 scribo/demo/viewer/Rendering/scene.hh create mode 100644 scribo/demo/viewer/Rendering/selection.cc rename GScribo/Rendering/selection.h => scribo/demo/viewer/Rendering/selection.hh (100%) rename {GScribo => scribo/demo/viewer}/TODO (100%) create mode 100644 scribo/demo/viewer/XmlWidget/attributesmodel.cc create mode 100644 scribo/demo/viewer/XmlWidget/attributesmodel.hh create mode 100644 scribo/demo/viewer/XmlWidget/selectionproxy.hh create mode 100644 scribo/demo/viewer/XmlWidget/xmlattributes.cc create mode 100644 scribo/demo/viewer/XmlWidget/xmlattributes.hh rename GScribo/XmlWidget/xmldelegate.h => scribo/demo/viewer/XmlWidget/xmldelegate.hh (100%) create mode 100644 scribo/demo/viewer/XmlWidget/xmlitem.cc create mode 100644 scribo/demo/viewer/XmlWidget/xmlitem.hh create mode 100644 scribo/demo/viewer/XmlWidget/xmlmodel.cc create mode 100644 scribo/demo/viewer/XmlWidget/xmlmodel.hh create mode 100644 scribo/demo/viewer/XmlWidget/xmlview.cc create mode 100644 scribo/demo/viewer/XmlWidget/xmlview.hh create mode 100644 scribo/demo/viewer/XmlWidget/xmlwidget.cc create mode 100644 scribo/demo/viewer/XmlWidget/xmlwidget.hh create mode 100644 scribo/demo/viewer/aboutdialog.cc create mode 100644 scribo/demo/viewer/aboutdialog.hh create mode 100644 scribo/demo/viewer/aboutdialog.ui delete mode 100644 scribo/demo/viewer/browser_widget.cc delete mode 100644 scribo/demo/viewer/browser_widget.hh delete mode 100644 scribo/demo/viewer/common.hh delete mode 100644 scribo/demo/viewer/config.cc delete mode 100644 scribo/demo/viewer/config.hh create mode 100644 scribo/demo/viewer/configs.cc create mode 100644 scribo/demo/viewer/configs.hh delete mode 100644 scribo/demo/viewer/defs.hh rename GScribo/dir.h => scribo/demo/viewer/dir.hh (100%) create mode 100644 scribo/demo/viewer/dockwidget.cc create mode 100644 scribo/demo/viewer/dockwidget.hh delete mode 100644 scribo/demo/viewer/general_options.cc delete mode 100644 scribo/demo/viewer/general_options.hh delete mode 100644 scribo/demo/viewer/general_options.ui delete mode 100644 scribo/demo/viewer/help_dialog.cc delete mode 100644 scribo/demo/viewer/help_dialog.hh delete mode 100644 scribo/demo/viewer/help_dialog.ui delete mode 100644 scribo/demo/viewer/icons/olena_smaller.jpg delete mode 100644 scribo/demo/viewer/image_region.cc delete mode 100644 scribo/demo/viewer/image_region.hh delete mode 100644 scribo/demo/viewer/image_region.hxx delete mode 100644 scribo/demo/viewer/image_scene.cc delete mode 100644 scribo/demo/viewer/image_scene.hh delete mode 100644 scribo/demo/viewer/image_view.cc delete mode 100644 scribo/demo/viewer/image_view.hh delete mode 100644 scribo/demo/viewer/image_widget.cc delete mode 100644 scribo/demo/viewer/image_widget.hh delete mode 100644 scribo/demo/viewer/key_widget.cc delete mode 100644 scribo/demo/viewer/key_widget.hh create mode 100644 scribo/demo/viewer/mainwindow.cc create mode 100644 scribo/demo/viewer/mainwindow.hh rename {GScribo => scribo/demo/viewer}/mainwindow.ui (100%) delete mode 100644 scribo/demo/viewer/ocr_options.cc delete mode 100644 scribo/demo/viewer/ocr_options.hh delete mode 100644 scribo/demo/viewer/ocr_options.ui delete mode 100644 scribo/demo/viewer/option_widget.cc delete mode 100644 scribo/demo/viewer/option_widget.hh delete mode 100644 scribo/demo/viewer/preferences_dialog.cc delete mode 100644 scribo/demo/viewer/preferences_dialog.hh delete mode 100644 scribo/demo/viewer/preferences_dialog.ui delete mode 100644 scribo/demo/viewer/preprocess.cc delete mode 100644 scribo/demo/viewer/preprocess.hh delete mode 100644 scribo/demo/viewer/preprocessing_options.cc delete mode 100644 scribo/demo/viewer/preprocessing_options.hh delete mode 100644 scribo/demo/viewer/preprocessing_options.ui delete mode 100644 scribo/demo/viewer/process.cc delete mode 100644 scribo/demo/viewer/process.hh create mode 100644 scribo/demo/viewer/region.hh create mode 100644 scribo/demo/viewer/regionwidget.cc create mode 100644 scribo/demo/viewer/regionwidget.hh delete mode 100644 scribo/demo/viewer/runner.cc delete mode 100644 scribo/demo/viewer/runner.hh delete mode 100644 scribo/demo/viewer/segmentation_options.cc delete mode 100644 scribo/demo/viewer/segmentation_options.hh delete mode 100644 scribo/demo/viewer/segmentation_options.ui delete mode 100644 scribo/demo/viewer/step_widget.cc delete mode 100644 scribo/demo/viewer/step_widget.hh create mode 100644 scribo/demo/viewer/variantpointer.cc create mode 100644 scribo/demo/viewer/variantpointer.hh delete mode 100644 scribo/demo/viewer/viewer.cc delete mode 100644 scribo/demo/viewer/viewer.hh delete mode 100644 scribo/demo/viewer/viewer.hxx delete mode 100644 scribo/demo/viewer/viewer.qrc create mode 100644 scribo/demo/viewer/xml.cc create mode 100644 scribo/demo/viewer/xml.hh delete mode 100644 scribo/demo/viewer/xml_widget.cc delete mode 100644 scribo/demo/viewer/xml_widget.hh
diff --git a/ChangeLog b/ChangeLog index 5faf2a3..50a9ad3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,83 @@ +2013-02-27 Guillaume Lazzara z@lrde.epita.fr + + Move new viewer to scribo/demo. + + * GScribo/BUGS, + * GScribo/GScribo.pro, + * GScribo/GScribo.pro.user, + * GScribo/GScribo.pro.user.1.3, + * GScribo/PagesWidget/pagesdelegate.cpp, + * GScribo/PagesWidget/pagesdelegate.h, + * GScribo/PagesWidget/pagesmodel.cpp, + * GScribo/PagesWidget/pagesmodel.h, + * GScribo/PagesWidget/pageswidget.cpp, + * GScribo/PagesWidget/pageswidget.h, + * GScribo/Preferences/generaloptions.cpp, + * GScribo/Preferences/generaloptions.h, + * GScribo/Preferences/generaloptions.ui, + * GScribo/Preferences/ocroptions.cpp, + * GScribo/Preferences/ocroptions.h, + * GScribo/Preferences/ocroptions.ui, + * GScribo/Preferences/optionwidget.h, + * GScribo/Preferences/preferencesdialog.cpp, + * GScribo/Preferences/preferencesdialog.h, + * GScribo/Preferences/preferencesdialog.ui, + * GScribo/Preferences/preprocessingoptions.cpp, + * GScribo/Preferences/preprocessingoptions.h, + * GScribo/Preferences/preprocessingoptions.ui, + * GScribo/Preferences/segmentationoptions.cpp, + * GScribo/Preferences/segmentationoptions.h, + * GScribo/Preferences/segmentationoptions.ui, + * GScribo/Processing/preprocess.cpp, + * GScribo/Processing/preprocess.h, + * GScribo/Processing/process.cpp, + * GScribo/Processing/process.h, + * GScribo/Processing/progressdialog.cpp, + * GScribo/Processing/progressdialog.h, + * GScribo/Processing/runner.cpp, + * GScribo/Processing/runner.h, + * GScribo/Rendering/abstractregionitem.h, + * GScribo/Rendering/backgroundtexture.h, + * GScribo/Rendering/graphicsview.cpp, + * GScribo/Rendering/graphicsview.h, + * GScribo/Rendering/regionitem.cpp, + * GScribo/Rendering/regionitem.h, + * GScribo/Rendering/rootgraphicsitem.h, + * GScribo/Rendering/scene.cpp, + * GScribo/Rendering/scene.h, + * GScribo/Rendering/selection.cpp, + * GScribo/Rendering/selection.h, + * GScribo/TODO, + * GScribo/XmlWidget/attributesmodel.cpp, + * GScribo/XmlWidget/attributesmodel.h, + * GScribo/XmlWidget/selectionproxy.h, + * GScribo/XmlWidget/xmlattributes.cpp, + * GScribo/XmlWidget/xmlattributes.h, + * GScribo/XmlWidget/xmldelegate.h, + * GScribo/XmlWidget/xmlitem.cpp, + * GScribo/XmlWidget/xmlitem.h, + * GScribo/XmlWidget/xmlmodel.cpp, + * GScribo/XmlWidget/xmlmodel.h, + * GScribo/XmlWidget/xmlview.cpp, + * GScribo/XmlWidget/xmlview.h, + * GScribo/XmlWidget/xmlwidget.cpp, + * GScribo/XmlWidget/xmlwidget.h, + * GScribo/aboutdialog.h, + * GScribo/aboutdialog.ui, + * GScribo/configs.h, + * GScribo/dir.h, + * GScribo/dockwidget.h, + * GScribo/main.cpp, + * GScribo/mainwindow.cpp, + * GScribo/mainwindow.h, + * GScribo/mainwindow.ui, + * GScribo/region.h, + * GScribo/regionwidget.cpp, + * GScribo/regionwidget.h, + * GScribo/variantpointer.h, + * GScribo/xml.cpp, + * GScribo/xml.h: Move to scribo/demo. + 2011-11-16 Guillaume Lazzara z@lrde.epita.fr
* configure.ac: Link to libGraphicsMagick++ if GraphicsMagick++ is diff --git a/GScribo/GScribo.pro b/GScribo/GScribo.pro deleted file mode 100644 index 1495495..0000000 --- a/GScribo/GScribo.pro +++ /dev/null @@ -1,83 +0,0 @@ -# ------------------------------------------------- -# Project created by QtCreator 2013-01-21T09:20:54 -# ------------------------------------------------- -QT += xml -INCLUDEPATH += /lrde/home/stage/froger_a/olena/scribo/ \ - /lrde/home/stage/froger_a/olena/milena/ \ - /lrde/home/stage/froger_a/olena/_build/scribo/demo/ -QMAKE_CXXFLAGS += -DNDEBUG \ - -DMLN_WO_GLOBAL_VARS -LIBS += -I/usr/include/graphicsImage \ - -lGraphicsMagick++ \ - -ltesseract_full \ - -ltiff -TARGET = GScribo -TEMPLATE = app -SOURCES += regionwidget.cpp \ - mainwindow.cpp \ - main.cpp \ - xml.cpp \ - Rendering/scene.cpp \ - Rendering/selection.cpp \ - Rendering/regionitem.cpp \ - Rendering/graphicsview.cpp \ - PagesWidget/pageswidget.cpp \ - PagesWidget/pagesmodel.cpp \ - PagesWidget/pagesdelegate.cpp \ - Preferences/segmentationoptions.cpp \ - Preferences/preprocessingoptions.cpp \ - Preferences/ocroptions.cpp \ - Preferences/generaloptions.cpp \ - Preferences/preferencesdialog.cpp \ - Processing/progressdialog.cpp \ - Processing/preprocess.cpp \ - Processing/process.cpp \ - Processing/runner.cpp \ - XmlWidget/xmlwidget.cpp \ - XmlWidget/xmlmodel.cpp \ - XmlWidget/xmlitem.cpp \ - XmlWidget/xmlattributes.cpp \ - XmlWidget/attributesmodel.cpp \ - XmlWidget/xmlview.cpp -HEADERS += mainwindow.h \ - variantpointer.h \ - regionwidget.h \ - aboutdialog.h \ - configs.h \ - region.h \ - dir.h \ - xml.h \ - Rendering/scene.h \ - Rendering/selection.h \ - Rendering/regionitem.h \ - Rendering/graphicsview.h \ - PagesWidget/pageswidget.h \ - PagesWidget/pagesmodel.h \ - Processing/preprocess.h \ - Processing/process.h \ - Processing/runner.h \ - Processing/progressdialog.h \ - Preferences/segmentationoptions.h \ - Preferences/preprocessingoptions.h \ - Preferences/ocroptions.h \ - Preferences/generaloptions.h \ - Preferences/optionwidget.h \ - Preferences/preferencesdialog.h \ - XmlWidget/xmlwidget.h \ - XmlWidget/xmlmodel.h \ - XmlWidget/xmlitem.h \ - XmlWidget/xmlattributes.h \ - XmlWidget/selectionproxy.h \ - XmlWidget/xmldelegate.h \ - XmlWidget/attributesmodel.h \ - PagesWidget/pagesdelegate.h \ - Rendering/rootgraphicsitem.h \ - XmlWidget/xmlview.h \ - dockwidget.h -FORMS += mainwindow.ui \ - aboutdialog.ui \ - Preferences/preferencesdialog.ui \ - Preferences/ocroptions.ui \ - Preferences/segmentationoptions.ui \ - Preferences/generaloptions.ui \ - Preferences/preprocessingoptions.ui diff --git a/GScribo/PagesWidget/pagesdelegate.cpp b/GScribo/PagesWidget/pagesdelegate.cpp deleted file mode 100644 index 19a34c2..0000000 --- a/GScribo/PagesWidget/pagesdelegate.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "pagesdelegate.h" - -PagesDelegate::PagesDelegate(QObject *parent) : - QStyledItemDelegate(parent) -{ - pen_.setColor(QColor::fromRgb(255, 69, 0, 255)); - pen_.setWidth(2); -} - -void PagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -{ - QStyledItemDelegate::paint(painter, option, index); - - if(index.row() == index.data(Qt::UserRole+1).toInt()) - { - painter->setPen(pen_); - painter->drawRect(option.rect); - painter->fillRect(option.rect, QColor::fromRgb(255, 69, 0, 60)); - } -} diff --git a/GScribo/PagesWidget/pagesdelegate.h b/GScribo/PagesWidget/pagesdelegate.h deleted file mode 100644 index ff422ca..0000000 --- a/GScribo/PagesWidget/pagesdelegate.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PAGESDELEGATE_H -#define PAGESDELEGATE_H - -#include <QStyledItemDelegate> -#include <QPainter> - -class PagesDelegate : - public QStyledItemDelegate -{ - public: - explicit PagesDelegate(QObject *parent = 0); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - - private: - QPen pen_; -}; - -#endif // PAGESDELEGATE_H diff --git a/GScribo/PagesWidget/pagesmodel.cpp b/GScribo/PagesWidget/pagesmodel.cpp deleted file mode 100644 index faccb74..0000000 --- a/GScribo/PagesWidget/pagesmodel.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "pagesmodel.h" - -PagesModel::PagesModel(QObject *parent): - QAbstractListModel(parent) -{ - currentRow_ = 0; -} - -QVariant PagesModel::data(const QModelIndex& index, int role) const -{ - if(!index.isValid()) - return QVariant(); - - if(role == Qt::DecorationRole) - return pixmaps_[index.row()]; - - if(role == Qt::UserRole) - return filenames_[index.row()]; - - if(role == Qt::UserRole+1) - return currentRow_; - - return QVariant(); -} - -void PagesModel::addPicture(const QString& filename, const QPixmap& pixmap) -{ - beginInsertRows(QModelIndex(), 0, 0); - - pixmaps_.prepend(pixmap.scaled(QSize(200, 200), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - filenames_.prepend(filename); - - endInsertRows(); -} - -void PagesModel::removePixmap(const QModelIndex &parent) -{ - int row = parent.row(); - - beginRemoveRows(parent, row, row); - - pixmaps_.removeAt(row); - filenames_.removeAt(row); - - endRemoveRows(); -} - -void PagesModel::setCurrentRow(int currentRow) -{ - beginResetModel(); - - currentRow_ = currentRow; - - endResetModel(); -} diff --git a/GScribo/PagesWidget/pagesmodel.h b/GScribo/PagesWidget/pagesmodel.h deleted file mode 100644 index 4c18842..0000000 --- a/GScribo/PagesWidget/pagesmodel.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef PAGESMODEL_H -#define PAGESMODEL_H - -#include <QAbstractListModel> -#include <QIcon> -#include <QList> - -class PagesModel: - public QAbstractListModel -{ - Q_OBJECT - - public: - explicit PagesModel(QObject *parent = 0); - - inline QStringList filenames() const; - inline int rowCount(const QModelIndex& parent = QModelIndex()) const; - - inline int currentRow() const; - void setCurrentRow(int currentRow); - - QVariant data(const QModelIndex& index, int role = Qt::DecorationRole) const; - void addPicture(const QString& filename, const QPixmap& pixmap); - - private: - QStringList filenames_; - QList<QPixmap> pixmaps_; - int currentRow_; - - public slots: - void removePixmap(const QModelIndex& parent); -}; - -inline QStringList PagesModel::filenames() const -{ return filenames_; } - -inline int PagesModel::rowCount(const QModelIndex&) const -{ return filenames_.count(); } - -inline int PagesModel::currentRow() const -{ return currentRow_; } - -#endif // PAGESMODEL_H diff --git a/GScribo/PagesWidget/pageswidget.cpp b/GScribo/PagesWidget/pageswidget.cpp deleted file mode 100644 index 400046a..0000000 --- a/GScribo/PagesWidget/pageswidget.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "pageswidget.h" - -PagesWidget::PagesWidget(QWidget *parent): - QListView(parent) -{ - setUniformItemSizes(true); - setSelectionMode(QAbstractItemView::ExtendedSelection); - setViewMode(QListView::IconMode); - setIconSize(QSize(200, 200)); - setMovement(QListView::Static); - setResizeMode(QListView::Adjust); - setSpacing(10); - - setModel(&model_); - setItemDelegate(new PagesDelegate()); - - QShortcut *remove = new QShortcut(Qt::Key_Delete, this); - connect(remove, SIGNAL(activated()), this, SLOT(removeSelection())); - connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(getPicture(QModelIndex))); -} - -void PagesWidget::removeSelection() -{ - QModelIndexList indexes = selectionModel()->selectedIndexes(); - if(hasFocus() && indexes.count() > 0) - { - // Sort the list because after the first removal, the second row index may not be the good one. - qSort(indexes.begin(), indexes.end()); - - // From the highest row to the smallest to be sure to remove the good index. - for(int i = indexes.count()-1; i > -1; i--) - model_.removePixmap(indexes[i]); - - // Draw new image on the scene. - getPicture(model_.index(indexes[0].row())); - clearSelection(); - - model_.setCurrentRow(indexes[0].row()); - scrollTo(indexes[0]); - } -} - -void PagesWidget::getPicture(const QModelIndex& index) -{ - QString filename = index.data(Qt::UserRole).toString(); - model_.setCurrentRow(index.row()); - - emit imageSelectionned(filename); -} diff --git a/GScribo/PagesWidget/pageswidget.h b/GScribo/PagesWidget/pageswidget.h deleted file mode 100644 index eb6488c..0000000 --- a/GScribo/PagesWidget/pageswidget.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef PAGESWIDGET_H -#define PAGESWIDGET_H - -#include <QListView> -#include <QShortcut> - -#include "pagesdelegate.h" -#include "pagesmodel.h" - -class PagesWidget: - public QListView -{ - Q_OBJECT - - public: - explicit PagesWidget(QWidget *parent = 0); - - inline QStringList filenames() const; - inline int currentRow() const; - inline void setCurrentRow(int currentRow); - - inline void addPicture(const QString& filename, const QPixmap& pixmap); - - protected: - inline void focusOutEvent(QFocusEvent *event); - - private: - PagesModel model_; - - public slots: - void removeSelection(); - - private slots: - void getPicture(const QModelIndex& index); - - signals: - void imageSelectionned(const QString& filename); -}; - -inline QStringList PagesWidget::filenames() const -{ return model_.filenames(); } - -inline int PagesWidget::currentRow() const -{ return model_.currentRow(); } - -inline void PagesWidget::setCurrentRow(int currentRow) -{ model_.setCurrentRow(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/Preferences/generaloptions.cpp b/GScribo/Preferences/generaloptions.cpp deleted file mode 100644 index 620a8fd..0000000 --- a/GScribo/Preferences/generaloptions.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "generaloptions.h" -#include "ui_generaloptions.h" - -GeneralOptions::GeneralOptions(QWidget *parent) : - OptionWidget(parent), - ui(new Ui::GeneralOptions) -{ - ui->setupUi(this); - loadConfig(); -} - -GeneralOptions::~GeneralOptions() -{ - delete ui; -} - -void GeneralOptions::loadConfig() -{ - Configs *const conf = Configs::getInstance(); - - ui->saveXml->setChecked(conf->generalSaveXmlEnabled()); - ui->sameDir->setChecked(conf->generalSaveXmlSameDir()); - ui->customDir->setChecked(conf->generalSaveXmlCustomDir()); - ui->customDirValue->setText(conf->generalSaveXmlCustomDirPath()); -} - - -void GeneralOptions::saveConfig() -{ - Configs *const conf = Configs::getInstance(); - - conf->setGeneralSaveXmlEnabled(ui->saveXml->isChecked()); - conf->setGeneralSaveXmlSameDir(ui->sameDir->isChecked()); - conf->setGeneralSaveXmlCustomDir(ui->customDir->isChecked()); - conf->setGeneralSaveXmlCustomDirPath(ui->customDirValue->text()); -} - -void GeneralOptions::onCustomDirBrowseBtnClicked() -{ - QString dir = QFileDialog::getExistingDirectory(0, "Choose a directory"); - - if (!dir.isEmpty()) - ui->customDirValue->setText(dir); -} diff --git a/GScribo/Preferences/generaloptions.h b/GScribo/Preferences/generaloptions.h deleted file mode 100644 index 0c07129..0000000 --- a/GScribo/Preferences/generaloptions.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef GENERALOPTIONS_H -#define GENERALOPTIONS_H - -#include <QFileDialog> - -#include "optionwidget.h" -#include "configs.h" - -namespace Ui -{ - class GeneralOptions; -} - -class GeneralOptions : - public OptionWidget -{ - Q_OBJECT - - public: - explicit GeneralOptions(QWidget *parent = 0); - ~GeneralOptions(); - - virtual void loadConfig(); - virtual void saveConfig(); - - private: - Ui::GeneralOptions *ui; - - private slots: - void onCustomDirBrowseBtnClicked(); - -}; - -#endif // GENERAL_OPTIONS_H diff --git a/GScribo/Preferences/ocroptions.cpp b/GScribo/Preferences/ocroptions.cpp deleted file mode 100644 index fff05b2..0000000 --- a/GScribo/Preferences/ocroptions.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "ocroptions.h" -#include "ui_ocroptions.h" - -static const char *language[][2] = -{ - { "English", "eng" }, - { "French", "fra" }, - { 0, 0 } -}; - -OcrOptions::OcrOptions(QWidget *parent) : - OptionWidget(parent), - ui(new Ui::OcrOptions) -{ - ui->setupUi(this); - - for (unsigned i = 0; language[i][0]; ++i) - ui->ocr_language->insertItem(i, language[i][0]); - - loadConfig(); -} - -OcrOptions::~OcrOptions() -{ - delete ui; -} - -int OcrOptions::findIndex(const QString& lang) -{ - for (unsigned i = 0; language[i][0]; ++i) - if (lang == language[i][1]) - return i; - - return 0; -} - - -void OcrOptions::loadConfig() -{ - Configs *const conf = Configs::getInstance(); - - ui->enable_ocr->setChecked(conf->ocrEnabled()); - ui->ocr_language->setCurrentIndex(findIndex(conf->ocrLanguage())); -} - - -void OcrOptions::saveConfig() -{ - Configs *const conf = Configs::getInstance(); - - conf->setOcrEnabled(ui->enable_ocr->isChecked()); - conf->setOcrLanguage(language[ui->ocr_language->currentIndex()][1]); -} diff --git a/GScribo/Preferences/ocroptions.h b/GScribo/Preferences/ocroptions.h deleted file mode 100644 index 9ba8d53..0000000 --- a/GScribo/Preferences/ocroptions.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef OCR_OPTIONS_H -#define OCR_OPTIONS_H - -//#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - -#include "optionwidget.h" -#include "configs.h" -#include "region.h" - -namespace Ui -{ - class OcrOptions; -} - -class OcrOptions : - public OptionWidget -{ - Q_OBJECT - - public: - explicit OcrOptions(QWidget *parent = 0); - ~OcrOptions(); - - void loadConfig(); - void saveConfig(); - - private: - int findIndex(const QString& lang); - - Ui::OcrOptions *ui; -}; - -#endif // OCR_OPTIONS_H diff --git a/GScribo/Preferences/preferencesdialog.cpp b/GScribo/Preferences/preferencesdialog.cpp deleted file mode 100644 index 23a0dd6..0000000 --- a/GScribo/Preferences/preferencesdialog.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "preferencesdialog.h" -#include "ui_preferencesdialog.h" - -PreferencesDialog::PreferencesDialog(QWidget *parent) : - QDialog(parent, Qt::Dialog), - ui(new Ui::PreferencesDialog) -{ - ui->setupUi(this); - - // We may want to remove this useless object in the ui file. - delete ui->widget; - - connect(ui->optionList, SIGNAL(currentRowChanged(int)), this, SLOT(onOptionListCurrentRowChanged(int))); - setAttribute(Qt::WA_DeleteOnClose); - - loadOptionList(); - ui->optionList->setCurrentRow(0); -} - -PreferencesDialog::~PreferencesDialog() -{ - delete ui; -} - -void PreferencesDialog::loadOptionList() -{ - static const char *options[] = { "General", "Preprocessing", "Segmentation", "OCR", 0 }; - - int i; - for (i = 0; options[i]; ++i) - ui->optionList->insertItem(i, options[i]); - - widgets.fill(0, i); -} - -void PreferencesDialog::selectOptionWidget(int row) -{ - if(!widgets[row]) - { - QWidget *widget = 0; - - switch(row) - { - case 0: - widget = new GeneralOptions(this); - break; - - case 1: - widget = new PreprocessingOptions(this); - break; - - case 2: - widget = new SegmentationOptions(this); - break; - - case 3: - widget = new OcrOptions(this); - break; - } - - if(widget) - widgets[row] = widget; - } - - if(ui->horizontalLayout_2->count() == 2) - { - QWidget *current_widget = ui->horizontalLayout_2->itemAt(1)->widget(); - ui->horizontalLayout_2->removeWidget(current_widget); - current_widget->hide(); - } - - ui->horizontalLayout_2->insertWidget(1, widgets[row]); - widgets[row]->show(); -} - - -void PreferencesDialog::accept() -{ - for (int i = 0; i < widgets.size(); ++i) - { - if (widgets[i]) - { - static_cast<OptionWidget *>(widgets[i])->saveConfig(); - delete widgets[i]; - } - } - - QDialog::accept(); -} - - -void PreferencesDialog::reject() -{ - for (int i = 0; i < widgets.size(); ++i) - delete widgets[i]; - - QDialog::reject(); -} diff --git a/GScribo/Preferences/preferencesdialog.h b/GScribo/Preferences/preferencesdialog.h deleted file mode 100644 index b0b9b61..0000000 --- a/GScribo/Preferences/preferencesdialog.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef PREFERENCESDIALOG_H -#define PREFERENCESDIALOG_H - -#include <QDialog> - -#include "preprocessingoptions.h" -#include "segmentationoptions.h" -#include "generaloptions.h" -#include "ocroptions.h" - -namespace Ui -{ - class PreferencesDialog; -} - -class PreferencesDialog : - public QDialog -{ - Q_OBJECT - - public: - explicit PreferencesDialog(QWidget *parent = 0); - ~PreferencesDialog(); - - private: - void loadOptionList(); - void selectOptionWidget(int row); - - Ui::PreferencesDialog *ui; - QVector<QWidget *> widgets; - - private slots: - inline void onOptionListCurrentRowChanged(int row); - virtual void accept(); - virtual void reject(); - -}; - -inline void PreferencesDialog::onOptionListCurrentRowChanged(int row) -{ selectOptionWidget(row); } - -#endif // PREFERENCESDIALOG_H diff --git a/GScribo/Preferences/preprocessingoptions.cpp b/GScribo/Preferences/preprocessingoptions.cpp deleted file mode 100644 index 6639bae..0000000 --- a/GScribo/Preferences/preprocessingoptions.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "preprocessingoptions.h" -#include "ui_preprocessingoptions.h" - -using namespace scribo::toolchain::internal; - -PreprocessingOptions::PreprocessingOptions(QWidget *parent) : - OptionWidget(parent), - ui(new Ui::PreprocessingOptions) -{ - ui->setupUi(this); - - ui->bin_algoCbox->insertItem(Convert, "Violent convert"); - ui->bin_algoCbox->insertItem(Sauvola, "Local threshold"); - ui->bin_algoCbox->insertItem(SauvolaMs, "Local threshold multiscale"); - - loadConfig(); -} - -PreprocessingOptions::~PreprocessingOptions() -{ - delete ui; -} - -void PreprocessingOptions::loadConfig() -{ - Configs *const conf = Configs::getInstance(); - - ui->subsampleCb->setChecked(conf->preprocessingSubsample()); - ui->remove_bgCb->setChecked(conf->preprocessingRemoveBg()); - ui->deskewCb->setChecked(conf->preprocessingDeskew()); - ui->remove_noiseCb->setChecked(conf->preprocessingRemoveNoise()); - ui->bin_algoCbox->setCurrentIndex(conf->preprocessingBinAlgo()); -} - - -void PreprocessingOptions::saveConfig() -{ - Configs *const conf = Configs::getInstance(); - - conf->setPreprocessingSubsample(ui->subsampleCb->isChecked()); - conf->setPreprocessingRemoveBg(ui->remove_bgCb->isChecked()); - conf->setPreprocessingDeskew(ui->deskewCb->isChecked()); - conf->setPreprocessingRemoveNoise(ui->remove_noiseCb->isChecked()); - conf->setPreprocessingBinAlgo(ui->bin_algoCbox->currentIndex()); -} diff --git a/GScribo/Preferences/preprocessingoptions.h b/GScribo/Preferences/preprocessingoptions.h deleted file mode 100644 index 6cc0081..0000000 --- a/GScribo/Preferences/preprocessingoptions.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef PREPROCESSINGOPTIONS_H -#define PREPROCESSINGOPTIONS_H - -#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - -#include "optionwidget.h" -#include "region.h" -#include "configs.h" - -namespace Ui -{ - class PreprocessingOptions; -} - -class PreprocessingOptions : - public OptionWidget -{ - Q_OBJECT - - public: - explicit PreprocessingOptions(QWidget *parent = 0); - ~PreprocessingOptions(); - - void loadConfig(); - void saveConfig(); - - private: - Ui::PreprocessingOptions *ui; - -}; - -#endif // PREPROCESSINGOPTIONS_H diff --git a/GScribo/Preferences/segmentationoptions.cpp b/GScribo/Preferences/segmentationoptions.cpp deleted file mode 100644 index d35209f..0000000 --- a/GScribo/Preferences/segmentationoptions.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "segmentationoptions.h" -#include "ui_segmentationoptions.h" - -SegmentationOptions::SegmentationOptions(QWidget *parent) : - OptionWidget(parent), - ui(new Ui::SegmentationOptions) -{ - ui->setupUi(this); - - ui->find_sepsCbox->insertItem(Separator::Lines, "Lines"); - ui->find_sepsCbox->insertItem(Separator::Whitespaces, "Whitespaces"); - ui->find_sepsCbox->insertItem(Separator::Both, "Lines and whitespaces"); - - loadConfig(); -} - -SegmentationOptions::~SegmentationOptions() -{ - delete ui; -} - -void SegmentationOptions::loadConfig() -{ - Configs *const conf = Configs::getInstance(); - ui->find_sepsCbox->setCurrentIndex(conf->segmentationFindSeps()); -} - - -void SegmentationOptions::saveConfig() -{ - Configs *const conf = Configs::getInstance(); - conf->setSegmentationFindSeps(ui->find_sepsCbox->currentIndex()); -} diff --git a/GScribo/Preferences/segmentationoptions.h b/GScribo/Preferences/segmentationoptions.h deleted file mode 100644 index 1506bfa..0000000 --- a/GScribo/Preferences/segmentationoptions.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef SEGMENTATIONOPTIONS_H -#define SEGMENTATIONOPTIONS_H - -//#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - -#include "optionwidget.h" -#include "configs.h" -#include "region.h" - -namespace Ui -{ - class SegmentationOptions; -} - -class SegmentationOptions : - public OptionWidget -{ - Q_OBJECT - - public: - explicit SegmentationOptions(QWidget *parent = 0); - ~SegmentationOptions(); - - void loadConfig(); - void saveConfig(); - - private: - Ui::SegmentationOptions *ui; -}; - -#endif // SEGMENTATIONOPTIONS_H diff --git a/GScribo/Processing/preprocess.cpp b/GScribo/Processing/preprocess.cpp deleted file mode 100644 index f012d88..0000000 --- a/GScribo/Processing/preprocess.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "preprocess.h" - -void Preprocess::on_progress() -{ - emit progress(); -} - -void Preprocess::on_new_progress_label(const char *label) -{ - emit newProgressLabel(QString(label)); -} diff --git a/GScribo/Processing/preprocess.h b/GScribo/Processing/preprocess.h deleted file mode 100644 index d65357f..0000000 --- a/GScribo/Processing/preprocess.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef PREPROCESS_H -#define PREPROCESS_H - -#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> -#include <mln/core/image/image2d.hh> -#include <mln/value/rgb8.hh> -#include <QObject> - -using namespace scribo::toolchain::internal; - -class Preprocess : - public QObject, - public text_in_doc_preprocess_functor<mln::image2dmln::value::rgb8 > -{ - Q_OBJECT - - public: - virtual void on_progress(); - virtual void on_new_progress_label(const char *label); - - signals: - void newProgressLabel(const QString& label); - void progress(); -}; - -#endif // PREPROCESS_H diff --git a/GScribo/Processing/process.cpp b/GScribo/Processing/process.cpp deleted file mode 100644 index bd37480..0000000 --- a/GScribo/Processing/process.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "process.h" - -Process::Process(const char *doc_filename) - : superT(doc_filename) -{ -} - -void Process::on_progress() -{ - emit progress(); -} - -void Process::on_new_progress_label(const char *label) -{ - emit newProgressLabel(QString(label)); -} - -void Process::on_xml_saved() -{ - emit xmlSaved(QString(output_file.c_str())); -} diff --git a/GScribo/Processing/process.h b/GScribo/Processing/process.h deleted file mode 100644 index 579a988..0000000 --- a/GScribo/Processing/process.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef PROCESS_H -#define PROCESS_H - -#include <scribo/toolchain/internal/content_in_doc_functor.hh> -#include <mln/core/image/image2d.hh> -#include <QObject> - -using namespace scribo::toolchain::internal; - -struct Process : - public QObject, - public content_in_doc_functor<mln::image2d<bool> > -{ - Q_OBJECT - typedef content_in_doc_functor<mln::image2d<bool> > superT; - - public : - explicit Process(const char *docFilename); - virtual void on_progress(); - virtual void on_new_progress_label(const char *label); - virtual void on_xml_saved(); - - signals: - void newProgressLabel(const QString& label); - void progress(); - void xmlSaved(const QString& filename); -}; - -#endif // PROCESS_H diff --git a/GScribo/Processing/progressdialog.cpp b/GScribo/Processing/progressdialog.cpp deleted file mode 100644 index 7f9d833..0000000 --- a/GScribo/Processing/progressdialog.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "progressdialog.h" - -ProgressDialog::ProgressDialog(QWidget *parent): - QProgressDialog(parent, Qt::Dialog) -{ - setAutoClose(false); - setCancelButton(0); - hide(); -} - -void ProgressDialog::reset() -{ - setValue(0); - setLabelText("Initilization"); - show(); -} diff --git a/GScribo/Processing/progressdialog.h b/GScribo/Processing/progressdialog.h deleted file mode 100644 index 822d9ba..0000000 --- a/GScribo/Processing/progressdialog.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef PROGRESSDIALOG_H -#define PROGRESSDIALOG_H - -#include <QProgressDialog> - -class ProgressDialog : - public QProgressDialog -{ - Q_OBJECT - - public: - explicit ProgressDialog(QWidget *parent = 0); - void reset(); - - public slots: - inline void run(); -}; - -void ProgressDialog::run() -{ setValue(value()+1); } - -#endif // PROGRESSDIALOG_H diff --git a/GScribo/Processing/runner.cpp b/GScribo/Processing/runner.cpp deleted file mode 100644 index c02223c..0000000 --- a/GScribo/Processing/runner.cpp +++ /dev/null @@ -1,183 +0,0 @@ -#include "runner.h" - -using namespace mln; -using namespace scribo::toolchain::internal; - -static QString get_pathto(const QString& file, const QString localdirsuffix = QString()) -{ - QFile f(SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix + "/" + file); - if (f.exists()) - return SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix; - f.setFileName(SCRIBO_PREFIX_BINDIR "/" + file); - if (f.exists()) - return SCRIBO_PREFIX_BINDIR; - - return ""; -} - -Runner::Runner(QObject *parent) : - QThread(parent) -{ - moveToThread(this); -} - -void Runner::run() -{ - if(mode_ == Demat) - { - image2dvalue::rgb8 ima; - for(int i = 0; i < args_.count(); i++) - { - io::magick::load(ima, args_.at(i).toUtf8().constData()); - image2d<bool> bin_ima = preprocess(ima); - process(ima, bin_ima, i); - } - } - - else if(mode_ == Export) - export_as(); - - emit finished(); -} - -void Runner::stop() -{ - terminate(); -} - -// Demat related stuff -void Runner::start_demat(const QStringList& filenames) -{ - args_.clear(); - args_ = filenames; - mode_ = Demat; - QThread::start(); -} - - -image2d<bool> Runner::preprocess(const image2dvalue::rgb8& ima) -{ - emit new_step("Preprocessing"); - Preprocess f; - - // Load config. - Configs *const conf = Configs::getInstance(); - - connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); - connect(&f, SIGNAL(newProgressLabel(QString)), - this, SIGNAL(new_progress_label(const QString&))); - - f.enable_subsample = conf->preprocessingSubsample(); - f.enable_fg_extraction = conf->preprocessingRemoveBg(); - f.enable_deskew = conf->preprocessingDeskew(); - f.enable_denoising = conf->preprocessingRemoveNoise(); - - f.binarization_algo = static_cast<Binarization_Algo>(conf->preprocessingBinAlgo()); - - emit new_progress_max_value(f.nsteps()); - - // Perform preprocessing. - f(ima); - - return f.output; -} - - -void Runner::process(const image2dvalue::rgb8& original_ima, - const image2d<bool>& processed_ima, int arg) -{ - emit new_step("Page segmentation"); - - Process f(args_.at(arg).toUtf8().constData()); - - connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); - connect(&f, SIGNAL(newProgressLabel(QString)), - this, SIGNAL(new_progress_label(QString))); - connect(&f, SIGNAL(xmlSaved(QString)), - this, SIGNAL(xml_saved(const QString&))); - - // Load config. - Configs *const conf = Configs::getInstance(); - - Separator::FindSeparator find_seps = static_castSeparator::FindSeparator(conf->segmentationFindSeps()); - f.enable_line_seps = (find_seps == Separator::Lines - || find_seps == Separator::Both); - f.enable_whitespace_seps = (find_seps == Separator::Whitespaces - || find_seps == Separator::Both); - f.enable_ocr = conf->ocrEnabled(); - f.ocr_language = conf->ocrLanguage().toAscii().data(); - f.xml_format = scribo::io::xml::PageExtended; - - - f.save_doc_as_xml = true; - QFileInfo file(args_.at(arg)); - QString output_dir = QDir::tempPath(); - if (conf->generalSaveXmlEnabled()) - { - if (conf->generalSaveXmlSameDir()) - output_dir = file.absolutePath(); - else if (conf->generalSaveXmlCustomDir()) - output_dir = conf->generalSaveXmlCustomDirPath(); - - QDir dir(output_dir); - if (!dir.exists() && !dir.mkpath(output_dir)) - output_dir = QDir::tempPath(); - } - QString filename = (output_dir + "/" + file.baseName() + "_gui.xml"); - f.output_file = filename.toUtf8().constData(); - emit new_progress_max_value(f.nsteps()); - - // Perform text detection. - f(original_ima, processed_ima); -} - -// Export related stuff -void Runner::start_export(const QString& imgfile, - const QString& xmlfile, const QString& outfile) -{ - args_.clear(); - args_ << imgfile << xmlfile << outfile; - mode_ = Export; - - QThread::start(); -} - -void Runner::export_as() -{ - emit new_step("Exporting document"); - emit new_progress_max_value(2); - - // Checking output format - QFileInfo f(args_.at(2)); - - QString pathto_xml2doc = get_pathto("scribo-xml2doc", "xml2doc"); - - if (pathto_xml2doc.isEmpty()) - { - QMessageBox::critical(0, "Fatal error", "Cannot export! Cannot find scribo-xml2doc program!"); - return; - } - - emit progress(); - - int rvalue = 0; - if (f.suffix() == "pdf") - { - emit new_step("Exporting as PDF"); - rvalue = system(QString("%1/scribo-xml2doc --pdf %2 %3 %4") - .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) - .arg(args_.at(2)).toAscii().constData()); - } - else if (f.suffix() == "html" || f.suffix() == "htm") - { - emit new_step("Exporting as HTML"); - rvalue = system(QString("%1/scribo-xml2doc --html %2 %3 %4") - .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) - .arg(args_.at(2)).toAscii().constData()); - } - else - QMessageBox::critical(0, "Fatal error", "Cannot export! Invalid output format!"); - - if (rvalue != 0) - QMessageBox::critical(0, "Fatal error", "Cannot export! Return value is not 0!"); -} diff --git a/GScribo/Processing/runner.h b/GScribo/Processing/runner.h deleted file mode 100644 index 721086a..0000000 --- a/GScribo/Processing/runner.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef RUNNER_H -#define RUNNER_H - -#include <mln/core/image/image2d.hh> -#include <mln/io/magick/load.hh> -#include <mln/value/rgb8.hh> -#include <QStringList> -#include <QMessageBox> -#include <QThread> -#include <QFile> - -#include "preprocess.h" -#include "process.h" -#include "configs.h" -#include "region.h" -#include "dir.h" - -using namespace mln; - -enum RunMode -{ - Demat, - Export -}; - -class Runner : - public QThread -{ - Q_OBJECT - - public: - explicit Runner(QObject *parent = 0); - void start_demat(const QStringList& filenames); - void start_export(const QString& imgfile, const QString& xmlfile, const QString& outfile); - - private: - image2d<bool> preprocess(const image2dvalue::rgb8& ima); - void process(const image2dvalue::rgb8& original_ima, const image2d<bool>& processed_ima, int arg); - void export_as(); - virtual void run(); - template <typename V> unsigned find_best_scale(const mln::image2d<V>& ima); - - QStringList args_; - RunMode mode_; - - public slots: - void stop(); - - signals: - void new_step(const QString& step_name); - void new_progress_max_value(int i); - void new_progress_label(const QString& msg); - void xml_saved(const QString& filename); - void progress(); - void finished(); -}; - -#endif // RUNNER_H diff --git a/GScribo/Rendering/graphicsview.cpp b/GScribo/Rendering/graphicsview.cpp deleted file mode 100644 index 336d5c2..0000000 --- a/GScribo/Rendering/graphicsview.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "graphicsview.h" -#include <QDebug> - -GraphicsView::GraphicsView(QWidget *parent) : - QGraphicsView(parent) -{ - init(); -} - -GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) : - QGraphicsView(scene, parent) -{ - init(); -} - -void GraphicsView::init() -{ - isRightClicking_ = false; - scaleRatio_ = QSizeF(1, 1); - setTransformationAnchor(GraphicsView::AnchorUnderMouse); - setBackgroundBrush(QBrush(Qt::lightGray)); - - // Important to hide scroll bars : when they appear, it triggers the resizeEvent. - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); -} - -void GraphicsView::mousePressEvent(QMouseEvent *event) -{ - if(event->button() == Qt::RightButton) - { - emit beginDrag(); - setDragMode(QGraphicsView::ScrollHandDrag); - } - - QMouseEvent *mouseEvent = new QMouseEvent(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, - Qt::LeftButton, Qt::MetaModifier); - event->ignore(); - QGraphicsView::mousePressEvent(mouseEvent); -} - -void GraphicsView::mouseReleaseEvent(QMouseEvent *event) -{ - if(event->button() == Qt::RightButton) - { - setDragMode(GraphicsView::NoDrag); - emit endDrag(); - } - - QGraphicsView::mouseReleaseEvent(event); -} - -void GraphicsView::wheelEvent(QWheelEvent *event) -{ - if(event->modifiers() & Qt::ControlModifier) - { - // Current wheel have an angle of 15 degrees by steps with a delta of + or - 120. A good scale is +- 0.1 in that case. - // So we have to adapt for wheel whith better precision. - qreal degrees = 1 + static_cast<qreal>(event->delta()) / 1200; - qreal nextScaleRatio = degrees * isWidthGreater_ ? scaleRatio_.width() : - scaleRatio_.height(); - if(event->delta() > 0) - { - if(nextScaleRatio <= 20) - { - scaleRatio_ *= degrees; - scale(degrees, degrees); - } - } - else - { - if(nextScaleRatio >= 1.1) - { - scaleRatio_ *= degrees; - scale(degrees, degrees); - } - else if(isContainedInView_) - { - QGraphicsView::fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); - scaleRatio_ = QSizeF(1, 1); - } - } - } - else - QGraphicsView::wheelEvent(event); -} - -void GraphicsView::keyPressEvent(QKeyEvent* event) -{ - // Bitwise AND to check if at least CTRL is pushed. - if(event->modifiers() & Qt::ControlModifier) - { - qreal nextScaleRatio; - if(event->key() == Qt::Key_Plus) - { - nextScaleRatio = 1.2 * isWidthGreater_ ? scaleRatio_.width() : - scaleRatio_.height(); - if(nextScaleRatio <= 19) - { - scaleRatio_ *= 1.2; - scale(1.2, 1.2); - } - } - else if(event->key() == Qt::Key_Minus) - { - nextScaleRatio = 0.8 * isWidthGreater_ ? scaleRatio_.width() : - scaleRatio_.height(); - if(nextScaleRatio >= 1.2) - { - scaleRatio_ *= 0.8; - scale(0.8, 0.8); - } - else if(isContainedInView_) - { - QGraphicsView::fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); - scaleRatio_ = QSizeF(1, 1); - } - } - } - - QGraphicsView::keyPressEvent(event); -} - -void GraphicsView::fitInView(const QRectF& rect) -{ - setFocus(); - isWidthGreater_ = static_cast<qreal>(rect.width()) / static_cast<qreal>(rect.height()) > 1 ? true : - false; - qreal ratio = isWidthGreater_ ? static_cast<qreal>(width()) / static_cast<qreal>(rect.width()) : - static_cast<qreal>(height()) / static_cast<qreal>(rect.height()); - - isContainedInView_ = ratio < 1 ? true : false; - if(isContainedInView_) - { - scaleRatio_ = QSizeF(1, 1); - QGraphicsView::fitInView(rect, Qt::KeepAspectRatio); - } -} - -void GraphicsView::resizeEvent(QResizeEvent *event) -{ - if(scene()->items().count() > 1) - { - qreal ratio = isWidthGreater_ ? static_cast<qreal>(event->size().width()) / static_cast<qreal>(event->oldSize().width()) : - static_cast<qreal>(event->size().height()) / static_cast<qreal>(event->oldSize().height()); - scale(ratio, ratio); - } - - QGraphicsView::resizeEvent(event); -} diff --git a/GScribo/Rendering/graphicsview.h b/GScribo/Rendering/graphicsview.h deleted file mode 100644 index 285f4cd..0000000 --- a/GScribo/Rendering/graphicsview.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef GRAPHICSVIEW_H -#define GRAPHICSVIEW_H - -#include <QGraphicsView> -#include <QWheelEvent> -#include <QScrollBar> - -class GraphicsView : - public QGraphicsView -{ - Q_OBJECT - - public: - explicit GraphicsView(QWidget *parent = 0); - explicit GraphicsView(QGraphicsScene *scene, QWidget *parent = 0); - - protected: - void init(); - - void resizeEvent(QResizeEvent *event); - - void wheelEvent(QWheelEvent *event); - void keyPressEvent(QKeyEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - - private: - bool isWidthGreater_; - bool isContainedInView_; - QSizeF scaleRatio_; - - bool isRightClicking_; - QPointF prevMousePos_; - - public slots: - void fitInView(const QRectF& rect); - - signals: - void beginDrag(); - void endDrag(); -}; - -#endif // GRAPHICSVIEW_H diff --git a/GScribo/Rendering/regionitem.cpp b/GScribo/Rendering/regionitem.cpp deleted file mode 100644 index 77cbcb3..0000000 --- a/GScribo/Rendering/regionitem.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "regionitem.h" - -RegionItem::RegionItem(QGraphicsItem *parent, QGraphicsScene *scene) - : QGraphicsPolygonItem(parent, scene) -{ - init(); -} - -RegionItem::RegionItem(const QPolygonF& polygon, QGraphicsItem *parent, QGraphicsScene *scene): - QGraphicsPolygonItem(polygon, parent, scene) -{ - init(); -} - -void RegionItem::init() -{ - xmlItem_ = 0; - - selectedPen_.setStyle(Qt::SolidLine); - unselectedPen_.setStyle(Qt::SolidLine); - - selectedPen_.setWidthF(2); - unselectedPen_.setWidth(0); - - selectedPen_.setCapStyle(Qt::SquareCap); - unselectedPen_.setCapStyle(Qt::SquareCap); - - selectedBrush_.setStyle(Qt::SolidPattern); - unselectedBrush_.setStyle(Qt::SolidPattern); -} - -void RegionItem::setColor(const QColor& color) -{ - selectedPen_.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 255)); - unselectedPen_.setColor(color); - - selectedBrush_.setColor(color); - unselectedBrush_.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 40)); - - setPen(unselectedPen_); - setBrush(unselectedBrush_); -} - -void RegionItem::setSelected(bool isSelected) -{ - if(isSelected) - { - isSelected_ = true; - setPen(selectedPen_); - setBrush(selectedBrush_); - } - - else - { - isSelected_ = false; - setPen(unselectedPen_); - setBrush(unselectedBrush_); - } -} diff --git a/GScribo/Rendering/regionitem.h b/GScribo/Rendering/regionitem.h deleted file mode 100644 index 3e8eb11..0000000 --- a/GScribo/Rendering/regionitem.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef RegionITEM_H -#define RegionITEM_H - -#include <QGraphicsPolygonItem> -#include <QTreeWidgetItem> -#include <QPen> - -#include "variantpointer.h" -#include "region.h" - -class XmlItem; - -class RegionItem : - public QGraphicsPolygonItem -{ - public: - explicit RegionItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); - explicit RegionItem(const QPolygonF& path, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); - - void setColor(const QColor& color); - inline QColor color() const; - - inline void setXmlItem(XmlItem *xmlItem); - inline XmlItem *xmlItem() const; - - inline void loadData(const GraphicsRegion::Data& data); - inline int region() const; - - 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(); - - private: - void init(); - - XmlItem *xmlItem_; - int region_; - bool isSelected_; - - QPen selectedPen_; - QPen unselectedPen_; - QBrush selectedBrush_; - QBrush unselectedBrush_; -}; - -inline void RegionItem::setXmlItem(XmlItem *xmlItem) -{ xmlItem_ = xmlItem; } - -inline XmlItem *RegionItem::xmlItem() const -{ return xmlItem_; } - -inline QColor RegionItem::color() const -{ return selectedBrush_.color(); } - -inline int RegionItem::region() const -{ return region_; } - -inline bool RegionItem::isSelected() -{ return isSelected_; } - -inline void RegionItem::select() -{ setSelected(true); } - -inline void RegionItem::unselect() -{ setSelected(false); } - -inline void RegionItem::loadData(const GraphicsRegion::Data& data) -{ region_ = data.region; setColor(data.color); setZValue(data.zValue); } - -inline bool RegionItem::contains(const QPointF& point) -{ return (boundingRect().width() * boundingRect().height() == 0 || boundingRect().contains(point)) && shape().contains(point); } - -inline bool RegionItem::intersects(const QRectF& rect) -{ return (boundingRect().width() * boundingRect().height() == 0 || boundingRect().intersects(rect)) && shape().intersects(rect); } - -#endif // RegionITEM_H diff --git a/GScribo/Rendering/rootgraphicsitem.h b/GScribo/Rendering/rootgraphicsitem.h deleted file mode 100644 index 2e95297..0000000 --- a/GScribo/Rendering/rootgraphicsitem.h +++ /dev/null @@ -1,30 +0,0 @@ -#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); } - ~RootGraphicsItem() - { foreach(QList<QGraphicsItem *> list, childsFromRegion_) { foreach(QGraphicsItem *child, list) delete child; } } - - inline void addItemFrom(QGraphicsItem *graphicalItem, const GraphicsRegion::Id& region); - inline QList<QGraphicsItem *> childsFrom(const GraphicsRegion::Id& region) const; - - private: - QVector<QList<QGraphicsItem *> > childsFromRegion_; -}; - -inline QList<QGraphicsItem *> RootGraphicsItem::childsFrom(const GraphicsRegion::Id& region) const -{ return childsFromRegion_[region]; } - -inline void RootGraphicsItem::addItemFrom(QGraphicsItem *graphicalItem, const GraphicsRegion::Id& region) -{ childsFromRegion_[region] << graphicalItem; } - -#endif // ROOTGRAPHICSITEM_H diff --git a/GScribo/Rendering/scene.cpp b/GScribo/Rendering/scene.cpp deleted file mode 100644 index 903bb97..0000000 --- a/GScribo/Rendering/scene.cpp +++ /dev/null @@ -1,273 +0,0 @@ -#include "scene.h" - -Scene::Scene(QObject *parent): - QGraphicsScene(parent) -{ - init(); -} - -Scene::Scene(const QRectF &sceneRect, QObject *parent): - QGraphicsScene(sceneRect, parent) -{ - init(); -} - -Scene::Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent): - QGraphicsScene(x, y, width, height, parent) -{ - init(); -} - -void Scene::init() -{ - isPressing_ = false; - isSelectionDisabled_ = false; - backgroundPixmap_ = 0; - root_ = 0; - - selection_.hide(); - addItem(&selection_); -} - -void Scene::clearAll() -{ - if(root_) - delete root_; - - if(backgroundPixmap_) - delete backgroundPixmap_; - - selectedRegions_.clear(); - backgroundPath_ = QString(); - backgroundPixmap_ = 0; - root_ = 0; -} - -void Scene::clearRegions() -{ - if(root_) - delete root_; - - selectedRegions_.clear(); - root_ = 0; -} - -void Scene::clearSelection() -{ - QGraphicsItem *child; - RegionItem *regionItem; - - // Unselect all items. - foreach(child, selectedRegions_) - { - regionItem = static_cast<RegionItem *>(child); - regionItem->unselect(); - } - - selectedRegions_.clear(); - emit selectionCleared(); -} - -void Scene::selectAll() -{ - RegionItem *item; - foreach(QGraphicsItem *child, root_->childItems()) - { - item = static_cast<RegionItem *>(child); - item->select(); - selectedRegions_ << item; - } -} - -void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if(!backgroundPath_.isEmpty() && event->button() == Qt::LeftButton && !isSelectionDisabled_) - { - isPressing_ = true; - - baseSelection_.clear(); - pressPos_ = event->scenePos(); - selection_.show(); - } -} - -void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if(isPressing_) - { - // 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); - else - selection_.setRect(event->scenePos().x(), 0, pressPos_.x()-event->scenePos().x(), 0); - - if(pressPos_.y() < event->scenePos().y()) - selection_.setRect(selection_.rect().x(), pressPos_.y(), selection_.rect().width(), event->scenePos().y()-pressPos_.y()); - else - selection_.setRect(selection_.rect().x(), event->scenePos().y(), selection_.rect().width(), pressPos_.y()-event->scenePos().y()); - } -} - -void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - if(event->button() == Qt::LeftButton) - { - isPressing_ = false; - - // Redraw all items in selection. - if(root_) - { - clearSelection(); - - // Check if it is a click. - if(selection_.rect().width() * selection_.rect().height() == 0) - select(event->scenePos()); - else - select(selection_.rect()); - - baseSelection_ = selectedRegions(); - emit newSelection(selectedRegions_); - } - - selection_.setRect(QRect()); - selection_.hide(); - } -} - -void Scene::select(QGraphicsItem *root, const QPointF& point, const QRectF& rect) -{ - QGraphicsItem *child; - RegionItem *regionItem; - - // Check if it is a click. - if(!point.isNull()) - { - foreach(child, root->childItems()) - { - regionItem = static_cast<RegionItem *>(child); - - if(regionItem->contains(point)) - { - regionItem->select(); - selectedRegions_ << regionItem; - } - } - } - else - { - foreach(child, root->childItems()) - { - regionItem = static_cast<RegionItem *>(child); - - if(regionItem->intersects(rect)) - { - regionItem->select(); - selectedRegions_ << regionItem; - } - } - } - - emit newSelection(); -} - -void Scene::select(const QList<RegionItem *>& selectedRegions) -{ - RegionItem *child; - foreach(child, selectedRegions) - { - if(!child->isSelected()) - { - child->select(); - selectedRegions_ << child; - } - } - - ensureVisible(selectedRegions_.last()); - emit newSelection(); -} - -void Scene::unselect(const QList<RegionItem *>& unselectedRegions) -{ - RegionItem *child; - foreach(child, unselectedRegions) - { - if(child->isSelected()) - { - child->unselect(); - selectedRegions_.removeOne(child); - } - } - - // Check if after the removal, the selected list isn't empty. - if(!selectedRegions_.isEmpty()) - ensureVisible(selectedRegions_.last()); - - emit newSelection(); -} - - -void Scene::ensureVisible(QGraphicsItem *graphicalItem) -{ - QGraphicsView *view; - foreach (view, views()) - view->ensureVisible(graphicalItem); -} - -void Scene::setVisible(const GraphicsRegion::Id& region, bool visible) -{ - if(root_) - { - QGraphicsItem *child; - - if(visible) - { - foreach(child, root_->childsFrom(region)) - child->setVisible(true); - } - - else - { - foreach(child, root_->childsFrom(region)) - child->setVisible(false); - } - } -} - -void Scene::setRoot(RootGraphicsItem *root) -{ - // Delete all items. - clearRegions(); - - root_ = root; - addItem(root); - - // Add typo lines separately because can't be selected. - QGraphicsItem *line; - foreach(line, root->childsFrom(GraphicsRegion::Baseline)) - addItem(line); - - foreach(line, root->childsFrom(GraphicsRegion::Meanline)) - addItem(line); -} - -void Scene::changeScene(const QString& filename, RootGraphicsItem *root) -{ - // Delete all items. - clearAll(); - backgroundPath_ = filename; - - if(!filename.isEmpty()) - { - QPixmap pixmap(filename); - setSceneRect(pixmap.rect()); - // Create the background item and dock it at the maximal depth of the scene. - backgroundPixmap_ = new QGraphicsPixmapItem(pixmap, 0, this); - backgroundPixmap_->setZValue(INT_MIN); - } - else - setSceneRect(QRectF()); - - // Add new items. - if(root) - setRoot(root); -} diff --git a/GScribo/Rendering/scene.h b/GScribo/Rendering/scene.h deleted file mode 100644 index 129359b..0000000 --- a/GScribo/Rendering/scene.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef SCENE_H -#define SCENE_H - -#include <QGraphicsSceneMouseEvent> -#include <QGraphicsView> -#include <QGraphicsScene> -#include <QFileDialog> -#include <climits> - -#include "rootgraphicsitem.h" -#include "regionitem.h" -#include "selection.h" - -class Scene : - public QGraphicsScene -{ - Q_OBJECT - - public: - explicit Scene(QObject *parent = 0); - explicit Scene(const QRectF &sceneRect, QObject *parent = 0); - explicit Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0); - - inline QString backgroundPath() const; - inline QGraphicsPixmapItem *backgroundPixmap() const; - - inline QList<RegionItem *> selectedRegions() const; - - void setRoot(RootGraphicsItem *rootItem); - inline RootGraphicsItem *root() const; - - void select(const QRectF& rect); - void select(const QPointF& point); - void selectAll(); - - inline bool selectionEnable() const; - inline void setSelectionEnable(bool enable); - - void changeScene(const QString& filename, RootGraphicsItem *root = 0); - - protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - - private: - void init(); - void select(QGraphicsItem *root, const QPointF& point, const QRectF& rect); - - QGraphicsView *mainView_; - RootGraphicsItem *root_; - - QString backgroundPath_; - QGraphicsPixmapItem *backgroundPixmap_; - - Selection selection_; - QList<RegionItem *> selectedRegions_; - QList<RegionItem *> baseSelection_; - - QPointF pressPos_; - bool isPressing_; - bool isSelectionDisabled_; - - public slots: - void clearAll(); - void clearRegions(); - void clearSelection(); - - void select(const QList<RegionItem *>& selectedRegions); - inline void selectBase(); - void unselect(const QList<RegionItem *>& unselectedItems); - - void setVisible(const GraphicsRegion::Id& region, bool visible); - void ensureVisible(QGraphicsItem *graphicsItem); - - inline void disableSelection(); - inline void enableSelection(); - - signals: - void selectionCleared(); - void newSelection(); - void newSelection(const QList<RegionItem *>& selectedRegions); -}; - -inline QString Scene::backgroundPath() const -{ return backgroundPath_; } - -inline QGraphicsPixmapItem *Scene::backgroundPixmap() const -{ return backgroundPixmap_; } - -inline RootGraphicsItem *Scene::root() const -{ return root_; } - -inline QList<RegionItem *> Scene::selectedRegions() const -{ return selectedRegions_; } - -inline void Scene::selectBase() -{ select(baseSelection_); } - -inline void Scene::select(const QPointF& point) -{ select(root_, point, QRectF()); } - -inline void Scene::select(const QRectF& rect) -{ select(root_, QPointF(), rect); } - -inline void Scene::setSelectionEnable(bool enable) -{ isSelectionDisabled_ = !enable; } - -inline bool Scene::selectionEnable() const -{ return isSelectionDisabled_; } - -inline void Scene::disableSelection() -{ setSelectionEnable(false); } - -inline void Scene::enableSelection() -{ setSelectionEnable(true); } - -#endif // SCENE_H diff --git a/GScribo/Rendering/selection.cpp b/GScribo/Rendering/selection.cpp deleted file mode 100644 index f5c3f4a..0000000 --- a/GScribo/Rendering/selection.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "selection.h" - -Selection::Selection(QGraphicsScene *scene): - QGraphicsRectItem(0, scene) -{ - init(); -} - -Selection::Selection(const QRectF &rect, QGraphicsScene *scene): - QGraphicsRectItem(rect, 0, scene) -{ - init(); -} - -Selection::Selection(qreal x, qreal y, qreal width, qreal height, QGraphicsScene *scene): - QGraphicsRectItem(x, y, width, height, 0, scene) -{ - init(); -} - -void Selection::init() -{ - // Always drawn on top of the scene. - setZValue(INT_MAX); - - QPen pen; - pen.setStyle(Qt::SolidLine); - pen.setCapStyle(Qt::SquareCap); - pen.setCosmetic(true); - setPen(pen); - - QBrush brush; - brush.setStyle(Qt::SolidPattern); - brush.setColor(QColor::fromRgb(80, 200, 10, 60)); - setBrush(brush); -} diff --git a/GScribo/XmlWidget/attributesmodel.cpp b/GScribo/XmlWidget/attributesmodel.cpp deleted file mode 100644 index 783fafb..0000000 --- a/GScribo/XmlWidget/attributesmodel.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "attributesmodel.h" - -AttributesModel::AttributesModel(const XmlAttributes& attributes, QObject *parent) : - QAbstractItemModel(parent) -{ - attributes_ = attributes; -} - -AttributesModel::AttributesModel(const XmlAttributes& attributes, QAbstractItemModelPrivate& dd, QObject *parent) : - QAbstractItemModel(dd, parent) -{ - attributes_ = attributes; -} - -QVariant AttributesModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if(orientation == Qt::Horizontal && role == Qt::DisplayRole) - { - switch(section) - { - case 0: - return tr("Name"); - - case 1: - return tr("Value"); - - default: - return QVariant(); - } - } - - return QVariant(); -} - -QVariant AttributesModel::data(const QModelIndex& index, int role) const -{ - if(!index.isValid()) - return QVariant(); - - switch(role) - { - case Qt::UserRole: - return attributes_.names()[index.row()]; - - case Qt::UserRole+1: - return attributes_.values()[index.row()]; - - default: - return QVariant(); - } -} - -void AttributesModel::load(const XmlAttributes& attributes) -{ - beginResetModel(); - - attributes_ = attributes; - - endResetModel(); -} - -void AttributesModel::reset() -{ - beginResetModel(); - - attributes_ = XmlAttributes(); - - endResetModel(); -} diff --git a/GScribo/XmlWidget/attributesmodel.h b/GScribo/XmlWidget/attributesmodel.h deleted file mode 100644 index 1dd3289..0000000 --- a/GScribo/XmlWidget/attributesmodel.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef ATTRIBUTESMODEL_H -#define ATTRIBUTESMODEL_H - -#include <QAbstractItemModel> - -#include "xmlattributes.h" - -class AttributesModel : - public QAbstractItemModel -{ - Q_OBJECT - - public: - explicit AttributesModel(const XmlAttributes& attributes = XmlAttributes(), QObject *parent = 0); - explicit AttributesModel(const XmlAttributes& attributes, QAbstractItemModelPrivate& dd, QObject *parent = 0); - - inline int rowCount(const QModelIndex& parent) const; - inline int columnCount(const QModelIndex& parent) const; - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - QVariant data(const QModelIndex& index, int role) const; - - inline QModelIndex index(int row, int column, const QModelIndex &parent) const; - inline QModelIndex parent(const QModelIndex &child) const; - - public slots: - void reset(); - - private: - XmlAttributes attributes_; - - public slots: - void load(const XmlAttributes& attributes); -}; - -inline int AttributesModel::rowCount(const QModelIndex&) const -{ return attributes_.names().count(); } - -inline int AttributesModel::columnCount(const QModelIndex&) const -{ return 2; } - -inline QModelIndex AttributesModel::index(int row, int column, const QModelIndex& parent) const -{ if(!hasIndex(row, column, parent)) return QModelIndex(); return createIndex(row, column, 0); } - -inline QModelIndex AttributesModel::parent(const QModelIndex&) const -{ return QModelIndex(); } - -#endif // ATTRIBUTESMODEL_H diff --git a/GScribo/XmlWidget/selectionproxy.h b/GScribo/XmlWidget/selectionproxy.h deleted file mode 100644 index 604c46a..0000000 --- a/GScribo/XmlWidget/selectionproxy.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef SELECTIONPROXY_H -#define SELECTIONPROXY_H - -#include <QSortFilterProxyModel> -#include <QDebug> - -#include "xmlitem.h" - -class SelectionProxy : - public QSortFilterProxyModel -{ - public: - explicit SelectionProxy(QObject *parent = 0) : QSortFilterProxyModel(parent) { isAllDisplayed_ = true; } - - inline void displayAll(); - inline bool isAllDisplayed(); - - inline void beginResetModel(); - inline void endResetModel(); - inline void invalidateFilter(); - - protected: - inline bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const; - - private: - bool isAllDisplayed_; -}; - -inline bool SelectionProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const -{ return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent) && (isAllDisplayed_ || sourceModel()->index(sourceRow, 0, sourceParent).data(Qt::UserRole+2).value<XmlItem *>()->isVisible()); } - -inline void SelectionProxy::beginResetModel() -{ isAllDisplayed_ = false; QSortFilterProxyModel::beginResetModel(); } - -inline void SelectionProxy::endResetModel() -{ QSortFilterProxyModel::endResetModel(); } - -inline void SelectionProxy::displayAll() -{ isAllDisplayed_ = true; } - -inline bool SelectionProxy::isAllDisplayed() -{ return isAllDisplayed_; } - -inline void SelectionProxy::invalidateFilter() -{ QSortFilterProxyModel::invalidateFilter(); } - -#endif // SELECTIONPROXY_H diff --git a/GScribo/XmlWidget/xmlattributes.cpp b/GScribo/XmlWidget/xmlattributes.cpp deleted file mode 100644 index 0c4221f..0000000 --- a/GScribo/XmlWidget/xmlattributes.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "xmlattributes.h" - -XmlAttributes::XmlAttributes() -{ -} - -XmlAttributes::XmlAttributes(const QDomNamedNodeMap& node) -{ - load(node); -} - -void XmlAttributes::load(const QDomNamedNodeMap& node) -{ - QDomAttr attr; - - for(int i = 0; i < node.count(); i++) - { - attr = node.item(i).toAttr(); - - names_ << attr.name(); - values_ << attr.value(); - } -} diff --git a/GScribo/XmlWidget/xmlattributes.h b/GScribo/XmlWidget/xmlattributes.h deleted file mode 100644 index 8dbf547..0000000 --- a/GScribo/XmlWidget/xmlattributes.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef XMLATTRIBUTES_H -#define XMLATTRIBUTES_H - -#include <QDomNamedNodeMap> -#include <QStringList> -#include <QVariant> - -class XmlAttributes -{ - public: - explicit XmlAttributes(); - explicit XmlAttributes(const QDomNamedNodeMap& node); - - void load(const QDomNamedNodeMap& node); - - inline QStringList names() const; - inline QStringList values() const; - - private: - QStringList names_; - QStringList values_; -}; - -inline QStringList XmlAttributes::names() const -{ return names_; } - -inline QStringList XmlAttributes::values() const -{ return values_; } - -Q_DECLARE_METATYPE(XmlAttributes) -Q_DECLARE_METATYPE(XmlAttributes *) - -#endif // XMLATTRIBUTES_H diff --git a/GScribo/XmlWidget/xmlitem.cpp b/GScribo/XmlWidget/xmlitem.cpp deleted file mode 100644 index 53d09aa..0000000 --- a/GScribo/XmlWidget/xmlitem.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "xmlitem.h" - -XmlItem::XmlItem(XmlItem *parent, XmlItem *precItem) -{ - init(parent, precItem); -} - -XmlItem::XmlItem(const QDomElement& node, XmlItem *parent, XmlItem *precItem) -{ - init(parent, precItem); - load(node); -} - -XmlItem::~XmlItem() -{ - // Delete all childs. - XmlItem *child; - foreach(child, childs_) - delete child; -} - -void XmlItem::init(XmlItem *parent, XmlItem *precItem) -{ - isVisible_ = false; - regionItem_ = 0; - parent_ = parent; - - if(parent) - parent->addChild(this); - - if(precItem) - row_ = precItem->row()+1; - else - row_ = 0; -} - -void XmlItem::load(const QDomElement& node) -{ - text_ = node.tagName(); - - // Load attributes. - attributes_.load(node.attributes()); -} diff --git a/GScribo/XmlWidget/xmlitem.h b/GScribo/XmlWidget/xmlitem.h deleted file mode 100644 index 5b14ba7..0000000 --- a/GScribo/XmlWidget/xmlitem.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef XMLITEM_H -#define XMLITEM_H - -#include <QDomElement> - -#include "xmlattributes.h" - -class RegionItem; - -class XmlItem -{ - public: - explicit XmlItem(XmlItem *parent = 0, XmlItem *precItem = 0); - explicit XmlItem(const QDomElement& node, XmlItem *parent = 0, XmlItem *precItem = 0); - ~XmlItem(); - - void load(const QDomElement& node); - - inline QList<XmlItem *> childs() const; - inline XmlItem *child(int i) const; - inline void addChild(XmlItem *child); - inline XmlItem *parent() const; - - inline RegionItem *regionItem(); - inline void setRegionItem(RegionItem *regionItem); - - inline bool isVisible() const; - inline void setVisible(bool visible); - inline void show(); - inline void hide(); - - inline QString text() const; - inline int row() const; - inline XmlAttributes attributes() const; - - private: - void init(XmlItem *parent = 0, XmlItem *precItem = 0); - - int row_; - bool isVisible_; - QList<XmlItem *> childs_; - XmlItem *parent_; - RegionItem *regionItem_; - QString text_; - XmlAttributes attributes_; -}; - -inline QList<XmlItem *> XmlItem::childs() const -{ return childs_; } - -inline XmlItem *XmlItem::child(int i) const -{ if(i > -1 && i < childs_.count()) return childs_[i]; return 0; } - -inline void XmlItem::addChild(XmlItem *child) -{ childs_ << child; } - -inline XmlItem *XmlItem::parent() const -{ return parent_; } - -inline RegionItem *XmlItem::regionItem() -{ return regionItem_; } - -inline void XmlItem::setRegionItem(RegionItem *regionItem) -{ regionItem_ = regionItem; } - -inline bool XmlItem::isVisible() const -{ return isVisible_; } - -inline void XmlItem::setVisible(bool visible) -{ isVisible_ = visible; } - -inline void XmlItem::show() -{ isVisible_ = true; } - -inline void XmlItem::hide() -{ isVisible_ = false; } - -inline QString XmlItem::text() const -{ return text_; } - -inline int XmlItem::row() const -{ return row_; } - -inline XmlAttributes XmlItem::attributes() const -{ return attributes_; } - -Q_DECLARE_METATYPE(XmlItem) -Q_DECLARE_METATYPE(XmlItem *) - -#endif // XMLITEM_H diff --git a/GScribo/XmlWidget/xmlmodel.cpp b/GScribo/XmlWidget/xmlmodel.cpp deleted file mode 100644 index 0f58075..0000000 --- a/GScribo/XmlWidget/xmlmodel.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "xmlmodel.h" - -XmlModel::XmlModel(XmlItem *rootItem, QObject *parent) : - QAbstractItemModel(parent) -{ - rootItem_ = rootItem; -} - -XmlModel::XmlModel(XmlItem *rootItem, QAbstractItemModelPrivate& dd, QObject *parent) : - QAbstractItemModel(dd, parent) -{ - rootItem_ = rootItem; -} - -XmlModel::~XmlModel() -{ - if(rootItem_) - delete rootItem_; -} - -QVariant XmlModel::headerData(int, Qt::Orientation orientation, int role) const -{ - if(orientation == Qt::Horizontal && role == Qt::DisplayRole) - return tr("Tree"); - - return QVariant(); -} - -QVariant XmlModel::data(const QModelIndex& index, int role) const -{ - if(!index.isValid()) - return QVariant(); - - switch(role) - { - case Qt::UserRole: - return static_cast<XmlItem *>(index.internalPointer())->text(); - - case Qt::UserRole+1: - return QVariant::fromValue(static_cast<XmlItem *>(index.internalPointer())->attributes()); - - case Qt::UserRole+2: - return QVariant::fromValue(static_cast<XmlItem *>(index.internalPointer())); - - default: - return QVariant(); - } -} - -QModelIndex XmlModel::index(int row, int column, const QModelIndex& parent) const -{ - if(!hasIndex(row, column, parent)) - return QModelIndex(); - - XmlItem *childItem = toXmlItem(parent)->child(row); - - // Create the model index from the child item. - if(childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); -} - -QModelIndex XmlModel::parent(const QModelIndex& child) const -{ - if(!child.isValid()) - return QModelIndex(); - - XmlItem *parentItem = static_cast<XmlItem *>(child.internalPointer())->parent(); - - if(!parentItem || parentItem == rootItem_) - return QModelIndex(); - - return createIndex(parentItem->row(), 0, parentItem); -} - -void XmlModel::load(XmlItem *rootItem) -{ - beginResetModel(); - - if(rootItem_) - delete rootItem_; - - rootItem_ = rootItem; - - endResetModel(); -} diff --git a/GScribo/XmlWidget/xmlmodel.h b/GScribo/XmlWidget/xmlmodel.h deleted file mode 100644 index 7e74e6f..0000000 --- a/GScribo/XmlWidget/xmlmodel.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef XMLMODEL_H -#define XMLMODEL_H - -#include <QAbstractItemModel> - -#include "variantpointer.h" -#include "xmlitem.h" - -class XmlModel : - public QAbstractItemModel -{ - public: - explicit XmlModel(XmlItem *rootItem = 0, QObject *parent = 0); - explicit XmlModel(XmlItem *rootItem, QAbstractItemModelPrivate& dd, QObject *parent = 0); - ~XmlModel(); - - void load(XmlItem *rootItem); - - inline int rowCount(const QModelIndex& parent) const; - inline int columnCount(const QModelIndex& parent) const; - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - - QVariant data(const QModelIndex& index, int role) const; - - QModelIndex index(int row, int column, const QModelIndex& parent) const; - QModelIndex parent(const QModelIndex& child) const; - - private: - inline XmlItem *toXmlItem(const QModelIndex& index) const; - - XmlItem *rootItem_; -}; - -inline XmlItem *XmlModel::toXmlItem(const QModelIndex& parent) const -{ return !parent.isValid() ? rootItem_ : static_cast<XmlItem *>(parent.internalPointer()); } - -inline int XmlModel::rowCount(const QModelIndex& parent) const -{ if(rootItem_) return toXmlItem(parent)->childs().count(); return 0; } - -inline int XmlModel::columnCount(const QModelIndex&) const -{ return 1; } - -#endif // XMLMODEL_H diff --git a/GScribo/XmlWidget/xmlview.cpp b/GScribo/XmlWidget/xmlview.cpp deleted file mode 100644 index 70a79b7..0000000 --- a/GScribo/XmlWidget/xmlview.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "xmlview.h" - -XmlView::XmlView(QWidget *parent) : - QTreeView(parent) -{ - proxy_.setFilterRole(Qt::UserRole); - proxy_.setDynamicSortFilter(true); - - setUniformRowHeights(true); - setItemDelegate(new XmlDelegate(Qt::UserRole)); - setSelectionMode(QAbstractItemView::ExtendedSelection); -} - -void XmlView::hideAll() -{ - proxy_.beginResetModel(); - - XmlItem *child; - foreach(child, displayedItems_) - child->hide(); - - displayedItems_.clear(); - emit resetProperty(); - - proxy_.endResetModel(); -} - -void XmlView::display(QList<XmlItem *> displayedItems, bool addToDisplayedList) -{ - proxy_.beginResetModel(); - - if(!addToDisplayedList) - hideAll(); - - XmlItem *child; - foreach(child, displayedItems) - { - child->show(); - displayedItems_ << child; - } - - proxy_.endResetModel(); - - expandAll(); -} - -QList<XmlItem *> XmlView::transform(const QModelIndexList& modelIndexList) const -{ - QList<XmlItem *> selectedItems; - QModelIndex index; - - foreach(index, modelIndexList) - selectedItems << index.data(Qt::UserRole+2).value<XmlItem *>(); - - return selectedItems; -} - -void XmlView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) -{ - QTreeView::selectionChanged(selected, deselected); - - if(selected.indexes() == selectedIndexes()) - emit resetSelection(); - - if(!selectedIndexes().isEmpty()) - { - QList<XmlItem *> xmlItems; - if(!selected.isEmpty()) - { - xmlItems = transform(selected.indexes()); - emit select(xmlItems); - } - else - { - xmlItems = transform(deselected.indexes()); - emit unselect(xmlItems); - } - - emit loadAttributes(xmlItems.last()->attributes()); - } - else - { - emit resetProperty(); - emit emptySelection(); - } - - emit newSelection(); -} diff --git a/GScribo/XmlWidget/xmlview.h b/GScribo/XmlWidget/xmlview.h deleted file mode 100644 index fef7386..0000000 --- a/GScribo/XmlWidget/xmlview.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef XMLVIEW_H -#define XMLVIEW_H - -#include <QGraphicsItem> -#include <QTreeView> - -#include "Rendering/regionitem.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 *> displayedItems() const; - void hideAll(); - - inline QList<XmlItem *> selectedItems() const; - - inline void setModel(QAbstractItemModel *model); - - protected: - void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); - - private: - QList<XmlItem *> transform(const QModelIndexList& modelIndexList) const; - void display(QList<XmlItem *> displayedItems, bool addToDisplayedList); - - SelectionProxy proxy_; - QList<XmlItem *> displayedItems_; - - public slots: - inline void display(QList<XmlItem *> displayedItems); - inline void displayOnly(QList<XmlItem *> displayedItems); - - inline void displayAll(); - - inline void setFilterString(const QString& filterString); - - signals: - void loadAttributes(const XmlAttributes& xmlAttributes); - - void select(const QList<XmlItem *>& selectedItems); - void unselect(const QList<XmlItem *>& unselectedItems); - - void newSelection(); - void emptySelection(); - - void resetSelection(); - void resetProperty(); -}; - -inline QList<XmlItem *> XmlView::displayedItems() const -{ return displayedItems_; } - -inline void XmlView::display(QList<XmlItem *> displayedItems) -{ display(displayedItems, true); } - -inline void XmlView::displayOnly(QList<XmlItem *> displayedItems) -{ display(displayedItems, false); } - -inline void XmlView::displayAll() -{ hideAll(); proxy_.displayAll(); } - -inline QList<XmlItem *> XmlView::selectedItems() const -{ return transform(selectedIndexes()); } - -inline void XmlView::setFilterString(const QString& filterString) -{ proxy_.setFilterRegExp(QRegExp(filterString, Qt::CaseSensitive)); proxy_.invalidateFilter(); } - -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 deleted file mode 100644 index dc24193..0000000 --- a/GScribo/XmlWidget/xmlwidget.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "xmlwidget.h" - -XmlWidget::XmlWidget(QWidget *parent) : - QSplitter(Qt::Horizontal, parent) -{ - proxy_.setFilterRegExp(QRegExp("(?:Page|.Region|Line)", Qt::CaseSensitive)); - proxy_.setDynamicSortFilter(true); - proxy_.setFilterRole(Qt::UserRole); - proxy_.setSourceModel(&model_); - - view_.setModel(&proxy_); - - attributes_.setModel(&attributesModel_); - attributes_.setSelectionMode(QAbstractItemView::NoSelection); - attributes_.setItemDelegateForColumn(0, new XmlDelegate(Qt::UserRole)); - attributes_.setItemDelegateForColumn(1, new XmlDelegate(Qt::UserRole+1)); - - addWidget(&view_); - addWidget(&attributes_); - - connect(&view_, SIGNAL(resetProperty()), &attributesModel_, SLOT(reset())); - connect(&view_, SIGNAL(clicked(QModelIndex)), this, SLOT(loadAttributes(QModelIndex))); - connect(&view_, SIGNAL(loadAttributes(XmlAttributes)), &attributesModel_, SLOT(load(XmlAttributes))); -} - -void XmlWidget::changeView(XmlItem *rootItem) -{ - attributesModel_.reset(); - - model_.load(rootItem); - - view_.displayAll(); - view_.expandAll(); -} diff --git a/GScribo/XmlWidget/xmlwidget.h b/GScribo/XmlWidget/xmlwidget.h deleted file mode 100644 index 32eca37..0000000 --- a/GScribo/XmlWidget/xmlwidget.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef XMLWIDGET_H -#define XMLWIDGET_H - -#include <QSortFilterProxyModel> -#include <QTableView> -#include <QTreeWidget> -#include <QSplitter> -#include <QDomElement> -#include <QWidget> - -#include "Rendering/scene.h" -#include "selectionproxy.h" -#include "attributesmodel.h" -#include "variantpointer.h" -#include "xmldelegate.h" -#include "xmlmodel.h" -#include "xmlview.h" - -class XmlWidget : - public QSplitter -{ - Q_OBJECT - - public: - explicit XmlWidget(QWidget *parent = 0); - - inline XmlView *view(); - inline QTableView *attributes(); - - void changeView(XmlItem *rootItem); - - private: - QSortFilterProxyModel proxy_; - - XmlModel model_; - AttributesModel attributesModel_; - - XmlView view_; - QTableView attributes_; - - private slots: - inline void loadAttributes(const QModelIndex& index); -}; - -inline XmlView * XmlWidget::view() -{ return &view_; } - -inline QTableView *XmlWidget::attributes() -{ return &attributes_; } - -inline void XmlWidget::loadAttributes(const QModelIndex& index) -{ attributesModel_.load(index.data(Qt::UserRole+2).value<XmlItem *>()->attributes()); } - -#endif // XMLWIDGET_H diff --git a/GScribo/aboutdialog.h b/GScribo/aboutdialog.h deleted file mode 100644 index fa91ada..0000000 --- a/GScribo/aboutdialog.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef ABOUTDIALOG_H -#define ABOUTDIALOG_H - -#include <QDialog> - -#include "ui_aboutdialog.h" - -namespace Ui -{ - class AboutDialog; -} - -class AboutDialog : - public QDialog -{ - public: - explicit AboutDialog(QWidget *parent = 0) : QDialog(parent, Qt::Dialog) - { ui = new Ui::AboutDialog; ui->setupUi(this); } - ~AboutDialog() { delete ui; } - - private: - Ui::AboutDialog *ui; -}; - -#endif // ABOUTDIALOG_H diff --git a/GScribo/aboutdialog.ui b/GScribo/aboutdialog.ui deleted file mode 100644 index d16b076..0000000 --- a/GScribo/aboutdialog.ui +++ /dev/null @@ -1,136 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>AboutDialog</class> - <widget class="QDialog" name="AboutDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>557</width> - <height>390</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>557</width> - <height>390</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>557</width> - <height>390</height> - </size> - </property> - <property name="windowTitle"> - <string>About</string> - </property> - <property name="windowIcon"> - <iconset> - <normaloff>:/icons/shared/icons/olena_smaller.jpg</normaloff>:/icons/shared/icons/olena_smaller.jpg</iconset> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string/> - </property> - <property name="pixmap"> - <pixmap>:/icons/shared/icons/olena_smaller.jpg</pixmap> - </property> - <property name="scaledContents"> - <bool>false</bool> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="label_2"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd%22%3E; -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:12pt; font-weight:600;">Document Image Analysis Tool</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:12pt; font-weight:600;"></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans';">This project is powered by </span><span style=" font-family:'DejaVu Sans'; font-weight:600; font-style:italic;">Milena</span><span style=" font-family:'DejaVu Sans';">, a generic image processing library.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans';">It is part of </span><span style=" font-family:'DejaVu Sans'; font-weight:600; font-style:italic;">Olena</span><span style=" font-family:'DejaVu Sans';">, an Image Processing Platform and its module </span><span style=" font-family:'DejaVu Sans'; font-weight:600; font-style:italic;">Scribo</span><span style=" font-family:'DejaVu Sans';">, a set of tools for Document Image Analysis.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://olena.lrde.epita.fr%22%3E%3Cspan style=" font-family:'DejaVu Sans'; text-decoration: underline; color:#0057ae;">http://olena.lrde.epita.fr%3C/span%3E%3C/a%3E%3C/p%3E; -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:8pt;">Thanks to Arthur Crépin-Leblond, Samuel Da Mota, Loic Denuziere, Jérôme Galtier, Florent d'Halluin, Alex Hamelin, Damien Lefortier, Vincent Ordy, Guillaume Sadegh and Warren Seine for their contribution.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:8pt;"></p> -<p align="justify" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:8pt;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:7pt;">This application has been developed in the context of the SCRIBO project of the Free Software Thematic Group, part of the &quot;System@tic Paris-Région&quot; Cluster (France). This project is partially funded by the French Government, its economic development agencies, and by the Paris-Région institutions.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:7pt;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:7pt;">Copyright (C) 2012, 2013 EPITA Research and Development Laboratory (LRDE)</span></p></body></html></string> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="standardButtons"> - <set>QDialogButtonBox::Ok</set> - </property> - <property name="centerButtons"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>AboutDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>281</x> - <y>391</y> - </hint> - <hint type="destinationlabel"> - <x>240</x> - <y>203</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/GScribo/configs.h b/GScribo/configs.h deleted file mode 100644 index c6aac68..0000000 --- a/GScribo/configs.h +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef CONFIGS_H -#define CONFIGS_H - -#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> -#include <QSettings> -#include <QDir> -#include <QDebug> - -#include "region.h" - -class Configs : - public QSettings -{ - public: - inline static Configs *getInstance(); - - inline bool preprocessingSubsample(); - inline void setPreprocessingSubsample(bool b); - - inline bool preprocessingRemoveBg(); - inline void setPreprocessingRemoveBg(bool b); - - inline bool preprocessingDeskew(); - inline void setPreprocessingDeskew(bool b); - - inline bool preprocessingRemoveNoise(); - inline void setPreprocessingRemoveNoise(bool b); - - inline int preprocessingBinAlgo(); - inline void setPreprocessingBinAlgo(int algo); - - inline int segmentationFindSeps(); - inline void setSegmentationFindSeps(int seps); - - inline bool ocrEnabled(); - inline void setOcrEnabled(bool b); - - inline QString ocrLanguage(); - inline void setOcrLanguage(const QString& lang); - - inline bool generalSaveXmlEnabled(); - inline void setGeneralSaveXmlEnabled(bool b); - - inline bool generalSaveXmlSameDir(); - inline void setGeneralSaveXmlSameDir(bool b); - - inline bool generalSaveXmlCustomDir(); - inline void setGeneralSaveXmlCustomDir(bool b); - - inline QString generalSaveXmlCustomDirPath(); - inline void setGeneralSaveXmlCustomDirPath(const QString& path); - - private: - explicit Configs() : QSettings("olena-scribo", "gui") { } -}; - -inline Configs *Configs::getInstance() -{ static Configs *conf = new Configs(); return conf; } - -inline bool Configs::preprocessingSubsample() -{ return value("preprocessing/subsample", false).toBool(); } - -inline void Configs::setPreprocessingSubsample(bool b) -{ setValue("preprocessing/subsample", b); } - -inline bool Configs::preprocessingRemoveBg() -{ return value("preprocessing/remove_bg", false).toBool(); } - -inline void Configs::setPreprocessingRemoveBg(bool b) -{ setValue("preprocessing/remove_bg", b); } - -inline bool Configs::preprocessingDeskew() -{ return value("preprocessing/deskew", false).toBool(); } - -inline void Configs::setPreprocessingDeskew(bool b) -{ setValue("preprocessing/deskew", b); } - -inline bool Configs::preprocessingRemoveNoise() -{ return value("preprocessing/remove_noise", true).toBool(); } - -inline void Configs::setPreprocessingRemoveNoise(bool b) -{ setValue("preprocessing/remove_noise", b); } - -inline int Configs::preprocessingBinAlgo() -{ return value("preprocessing/bin_algo", - scribo::toolchain::internal::SauvolaMs).toInt(); } - -inline void Configs::setPreprocessingBinAlgo(int algo) -{ setValue("preprocessing/bin_algo", algo); } - -inline int Configs::segmentationFindSeps() -{ return value("segmentation/find_seps", Separator::Both).toInt(); } - -inline void Configs::setSegmentationFindSeps(int seps) -{ setValue("segmentation/find_seps", seps); } - -inline bool Configs::ocrEnabled() -{ return value("ocr/enabled", true).toBool(); } - -inline void Configs::setOcrEnabled(bool b) -{ setValue("ocr/enabled", b); } - -inline QString Configs::ocrLanguage() -{ return value("ocr/language", 0).toString(); } - -inline void Configs::setOcrLanguage(const QString& lang) -{ setValue("ocr/language", lang); } - -inline bool Configs::generalSaveXmlEnabled() -{ return value("general/save_xml/enabled", true).toBool(); } - -inline void Configs::setGeneralSaveXmlEnabled(bool b) -{ setValue("general/save_xml/enabled", b); } - -inline bool Configs::generalSaveXmlSameDir() -{ return value("general/save_xml/same_dir", true).toBool(); } - -inline void Configs::setGeneralSaveXmlSameDir(bool b) -{ setValue("general/save_xml/same_dir", b); } - -inline bool Configs::generalSaveXmlCustomDir() -{ return value("general/save_xml/custom_dir", false).toBool(); } - -inline void Configs::setGeneralSaveXmlCustomDir(bool b) -{ setValue("general/save_xml/custom_dir", b); } - -inline QString Configs::generalSaveXmlCustomDirPath() -{ return value("general/save_xml/custom_dir_path", - QDir::tempPath()).toString(); } - -inline void Configs::setGeneralSaveXmlCustomDirPath(const QString& path) -{ setValue("general/save_xml/custom_dir_path", path); } - -#endif // CONFIGS_H diff --git a/GScribo/dockwidget.h b/GScribo/dockwidget.h deleted file mode 100644 index a1a2b40..0000000 --- a/GScribo/dockwidget.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef DOCKWIDGET_H -#define DOCKWIDGET_H - -#include <QDockWidget> - -class DockWidget : - public QDockWidget -{ - Q_OBJECT - - public: - explicit DockWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QDockWidget(parent, flags) { } - explicit DockWidget(const QString& title, QWidget *parent = 0, Qt::WindowFlags flags = 0) : QDockWidget(title, parent, flags) { } - - public slots: - inline void switchVisibility(); -}; - -inline void DockWidget::switchVisibility() -{ setVisible(!isVisible()); } - -#endif // DOCKWIDGET_H diff --git a/GScribo/main.cpp b/GScribo/main.cpp deleted file mode 100644 index d47ec16..0000000 --- a/GScribo/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#undef MLN_WO_GLOBAL_VARS - -#include <scribo/make/debug_filename.hh> -#include <mln/labeling/colorize.hh> -#include <mln/io/magick/load.hh> -#include <mln/literal/colors.hh> -#include <mln/debug/filename.hh> -#include <QtGui/QApplication> -#include <mln/math/pi.hh> - -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - Magick::InitializeMagick(*argv); - // On Linux, we NEED to use the raster graphics system. - // Linux don't really support openGL graphics system (the default one on Linux). - QApplication::setGraphicsSystem("raster"); - QApplication a(argc, argv); - MainWindow w; - w.show(); - return a.exec(); -} diff --git a/GScribo/mainwindow.cpp b/GScribo/mainwindow.cpp deleted file mode 100644 index 4bb5c74..0000000 --- a/GScribo/mainwindow.cpp +++ /dev/null @@ -1,415 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - setWindowTitle(tr("GScribo")); - showMaximized(); - - initGraphicsRegion(); - initDialogsWidget(); - initXmlWidget(); - initRegionWidget(); - initPageWidget(); - initMenuBar(); - - // Told the left dock widget (here the pages widget and the region widget) to fill the bottom left corner. - setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); - // Merge the region and pages widget in one tab (pages widget over the region widget). - tabifyDockWidget(&dockRegion_, &dockPages_); - - connectWidgets(); -} - -MainWindow::~MainWindow() -{ - delete preferencesDialog_; - delete aboutDialog_; - delete progressDialog_; - delete ui; -} - -void MainWindow::changeEvent(QEvent *e) -{ - QMainWindow::changeEvent(e); - switch (e->type()) - { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - -void MainWindow::initGraphicsRegion() -{ - graphicsView_.setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); - graphicsView_.setScene(&scene_); - - setCentralWidget(&graphicsView_); -} - -void MainWindow::initDialogsWidget() -{ - preferencesDialog_ = new PreferencesDialog(this); - aboutDialog_ = new AboutDialog(this); - progressDialog_ = new ProgressDialog(this); -} - -void MainWindow::initPageWidget() -{ - dockPages_.setWindowTitle("Pages"); - dockPages_.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); - dockPages_.setWidget(&pagesWidget_); - dockPages_.setMinimumWidth(190); - - addDockWidget(Qt::LeftDockWidgetArea, &dockPages_); -} - -void MainWindow::initRegionWidget() -{ - dockRegion_.setWindowTitle("Regions"); - dockRegion_.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); - dockRegion_.setWidget(®ionWidget_); - - addDockWidget(Qt::LeftDockWidgetArea, &dockRegion_); -} - -void MainWindow::initXmlWidget() -{ - dockXml_.setWindowTitle("Xml"); - dockXml_.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); - dockXml_.setWidget(&xmlWidget_); - - addDockWidget(Qt::BottomDockWidgetArea, &dockXml_); - dockXml_.setVisible(false); -} - -void MainWindow::initMenuBar() -{ - QMenu *menuFile = ui->menuBar->addMenu(tr("File")); - - QAction *open = menuFile->addAction(tr("Open")); - connect(open, SIGNAL(triggered()), this, SLOT(onOpen())); - - segment_ = menuFile->addAction(tr("Segment")); - segment_->setEnabled(false); - connect(segment_, SIGNAL(triggered()), this, SLOT(onSegment())); - - menuFile->addSeparator(); - - previewPrinting_ = menuFile->addAction(tr("Preview Printing")); - previewPrinting_->setEnabled(false); - connect(previewPrinting_, SIGNAL(triggered()), this, SLOT(onPreviewPrint())); - - print_ = menuFile->addAction(tr("Print")); - print_->setEnabled(false); - connect(print_, SIGNAL(triggered()), this, SLOT(onPrint())); - - menuFile->addSeparator(); - - export_ = menuFile->addAction(tr("Exportation")); - export_->setEnabled(false); - connect(export_, SIGNAL(triggered()), this, SLOT(onExportation())); - - menuFile->addSeparator(); - - QAction *quit = menuFile->addAction(tr("Quit")); - connect(quit, SIGNAL(triggered()), this, SLOT(close())); - - QMenu *menuAreas = ui->menuBar->addMenu(tr("Areas")); - - QAction *page = menuAreas->addAction(tr("Page")); - page->setCheckable(true); - page->setChecked(true); - connect(page, SIGNAL(triggered()), &dockPages_, SLOT(switchVisibility())); - - QAction *region = menuAreas->addAction(tr("Region")); - region->setCheckable(true); - region->setChecked(true); - connect(region, SIGNAL(triggered()), &dockRegion_, SLOT(switchVisibility())); - - QAction *xml = menuAreas->addAction(tr("Xml")); - xml->setCheckable(true); - xml->setChecked(false); - connect(xml, SIGNAL(triggered()), &dockXml_, SLOT(switchVisibility())); - - QAction *preferences = ui->menuBar->addAction(tr("Preferences")); - connect(preferences, SIGNAL(triggered()), this, SLOT(onPreferences())); - - QAction *about = ui->menuBar->addAction(tr("About")); - connect(about, SIGNAL(triggered()), this, SLOT(onAbout())); -} - -void MainWindow::setActionsEnabled(bool isSegmented) -{ - segment_->setEnabled(!isSegmented); - print_->setEnabled(isSegmented); - previewPrinting_->setEnabled(isSegmented); -} - -void MainWindow::disableActions() -{ - segment_->setEnabled(false); - print_->setEnabled(false); - previewPrinting_->setEnabled(false); - export_->setEnabled(false); -} - -void MainWindow::connectWidgets() -{ - // Each time the scene rect change (when a new picture is loaded), we fit the scene background rectangle in the view. - connect(&scene_, SIGNAL(sceneRectChanged(QRectF)), &graphicsView_, SLOT(fitInView(QRectF))); - // When dragging with right click, disable selection. - connect(&graphicsView_, SIGNAL(beginDrag()), &scene_, SLOT(disableSelection())); - connect(&graphicsView_, SIGNAL(endDrag()), &scene_, SLOT(enableSelection())); - - // 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(newSelection(QList<RegionItem*>)), this, SLOT(onRegionSelection(QList<RegionItem*>))); - connect(xmlWidget_.view(), SIGNAL(select(QList<XmlItem*>)), this, SLOT(onXmlSelect(QList<XmlItem*>))); - connect(xmlWidget_.view(), SIGNAL(unselect(QList<XmlItem*>)), this, SLOT(onXmlUnselect(QList<XmlItem*>))); - connect(xmlWidget_.view(), SIGNAL(emptySelection()), &scene_, SLOT(selectBase())); - connect(xmlWidget_.view(), SIGNAL(resetSelection()), &scene_, SLOT(clearSelection())); - - // Connect the scene with the region widget. - connect(®ionWidget_, SIGNAL(checkStateChanged(GraphicsRegion::Id,bool)), &scene_, SLOT(setVisible(GraphicsRegion::Id,bool))); - - // Connect the xml widget with the region widget. - connect(®ionWidget_, SIGNAL(checkStateChanged(QString)), xmlWidget_.view(), SLOT(setFilterString(QString))); - - connect(&runner_, SIGNAL(progress()), progressDialog_, SLOT(run())); - connect(&runner_, SIGNAL(new_progress_max_value(int)), progressDialog_, SLOT(setMaximum(int))); - connect(&runner_, SIGNAL(new_progress_label(QString)), progressDialog_, SLOT(setLabelText(QString))); - connect(&runner_, SIGNAL(finished()), progressDialog_, SLOT(close())); - connect(&runner_, SIGNAL(xml_saved(QString)), this, SLOT(onXmlSaved(QString))); -} - -void MainWindow::onOpen() -{ - QStringList paths = QFileDialog::getOpenFileNames(this, "Open Image(s)", QDir::homePath(), - "Images (*.png *.jpg *.ppm *.bmp)"); - setWindowTitle(tr("GScribo")); - - if(paths.count() > 0) - { - QStringList filenames = pagesWidget_.filenames(); - QString path; - - int counter = 0; - bool isContained; - // Check for an image not already added to the page widget. - do - { - path = paths[counter]; - counter++; - isContained = filenames.contains(path); - } while(isContained && counter < paths.count()); - - if(!isContained) - { - pagesWidget_.addPicture(path, QPixmap(path)); - - // If more than one file, we store it in the page widget. - for(int i = counter; i < paths.count(); i++) - { - // Check if the page widget contains the image. - if(!filenames.contains(paths[i])) - { - path = paths[i]; - pagesWidget_.addPicture(path, QPixmap(path)); - } - } - - pagesWidget_.setCurrentRow(0); - pagesWidget_.scrollToTop(); - } - - // Change current scene. - onFileChanged(path); - } -} - -void MainWindow::onSegment() -{ - QStringList filenames; - - filenames << scene_.backgroundPath(); - - // Run segmentation of page(s). - progressDialog_->reset(); - runner_.start_demat(filenames); -} - -void MainWindow::onPreviewPrint() -{ - QPrinter printer(QPrinter::HighResolution); - printer.setPaperSize(QPrinter::A4); - printer.setResolution(300); - - QPrintPreviewDialog preview(&printer, this); - connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(printScene(QPrinter*))); - - preview.exec(); -} - -void MainWindow::onPrint() -{ - QPrinter printer(QPrinter::HighResolution); - printer.setPaperSize(QPrinter::A4); - printer.setResolution(300); - - QPrintDialog dialog(&printer, this); - dialog.setWindowTitle("Print Document"); - - if(dialog.exec() != QDialog::Accepted) - return; - - printScene(&printer); -} - -void MainWindow::printScene(QPrinter *printer) -{ - QPainter painter(printer); - QStyleOptionGraphicsItem options; - - scene_.backgroundPixmap()->paint(&painter, &options, 0); - - // Paint backwards items first. - printItems(&painter, scene_.root()->childsFrom(GraphicsRegion::TextRegion), &options); - printItems(&painter, scene_.root()->childsFrom(GraphicsRegion::Image), &options); - - for(int i = GraphicsRegion::Line; i < GraphicsRegion::Image; i++) - printItems(&painter, scene_.root()->childsFrom(static_castGraphicsRegion::Id(i)), &options); - - for(int i = GraphicsRegion::Noise; i <= GraphicsRegion::Meanline; i++) - printItems(&painter, scene_.root()->childsFrom(static_castGraphicsRegion::Id(i)), &options); -} - -void MainWindow::printItems(QPainter *painter, const QList<QGraphicsItem *>& items, QStyleOptionGraphicsItem *options) -{ - foreach(QGraphicsItem *child, items) - { - if(child->isVisible()) - { - QRect viewport = scene_.backgroundPixmap()->mapRectFromItem(child, child->boundingRect()).toRect(); - painter->translate(abs(child->boundingRect().x() - viewport.x()), - abs(child->boundingRect().y() - viewport.y())); - child->paint(painter, options); - painter->resetTransform(); - } - } -} - -void MainWindow::onExportation() -{ - QMessageBox messageBox(this); - messageBox.setWindowTitle("Information"); - messageBox.setText("This feature is not available yet"); - messageBox.exec(); - return; - - QFileInfo fileInfo(scene_.backgroundPath()); - QString outputSuggestion = fileInfo.baseName() + ".pdf"; - QString output = QFileDialog::getSaveFileName(0, tr("Export Document As ..."), outputSuggestion, - tr("PDF (*.pdf);; HTML (*.html *.htm")); - - if(!output.isEmpty()) - { - progressDialog_->reset(); - runner_.start_export(scene_.backgroundPath(), xml_.filename(), output); - } -} - -void MainWindow::onXmlSaved(const QString& filename) -{ - xml_.load(filename); - xmlWidget_.changeView(xml_.xmlItem()); - scene_.setRoot(xml_.graphicsItem()); - - setActionsEnabled(true); - export_->setEnabled(xml_.recognized()); -} - -void MainWindow::onFileChanged(const QString& filename) -{ - // If it's not the current scene. - if(scene_.backgroundPath() != filename) - { - QString xmlPath = Xml::getPath(filename); - - if(filename.isEmpty()) - { - xmlPath = QString(); - disableActions(); - } - // Check if the xml file already exists. - else if(!QFile(xmlPath).exists()) - { - xmlPath = QString(); - setActionsEnabled(false); - } - else - setActionsEnabled(true); - - xml_.load(xmlPath); - scene_.changeScene(filename, xml_.graphicsItem()); - xmlWidget_.changeView(xml_.xmlItem()); - export_->setEnabled(xml_.recognized()); - } -} - -void MainWindow::onRegionSelection(QList<RegionItem *> regionItems) -{ - if(!regionItems.isEmpty()) - xmlWidget_.view()->displayOnly(toXmlItems(regionItems)); - else - { - xmlWidget_.view()->reset(); - xmlWidget_.view()->displayAll(); - xmlWidget_.view()->expandAll(); - } -} - -void MainWindow::onXmlChangeSelection(QList<XmlItem *> xmlItems, bool select) -{ - QList<RegionItem *> regionItems = toRegionItems(xmlItems); - - if(!regionItems.isEmpty()) - { - if(select) - scene_.select(regionItems); - else - scene_.unselect(regionItems); - } -} - -QList<RegionItem *> MainWindow::toRegionItems(QList<XmlItem *> xmlItems) const -{ - QList<RegionItem *> regionItems; - XmlItem *child; - foreach(child, xmlItems) - { - if(child->regionItem()) - regionItems << child->regionItem(); - } - - return regionItems; -} - -QList<XmlItem *> MainWindow::toXmlItems(QList<RegionItem *> regionItems) const -{ - QList<XmlItem *> xmlItems; - RegionItem *child; - foreach(child, regionItems) - xmlItems << child->xmlItem(); - - return xmlItems; -} diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h deleted file mode 100644 index 0637f44..0000000 --- a/GScribo/mainwindow.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include <QPrintPreviewDialog> -#include <QGraphicsView> -#include <QPrintDialog> -#include <QMainWindow> -#include <QHBoxLayout> -#include <QDockWidget> -#include <QFileDialog> -#include <QGroupBox> -#include <QPrinter> - -#include "Preferences/preferencesdialog.h" -#include "Processing/progressdialog.h" -#include "PagesWidget/pageswidget.h" -#include "Rendering/graphicsview.h" -#include "XmlWidget/xmlwidget.h" -#include "Processing/runner.h" -#include "Rendering/scene.h" -#include "regionwidget.h" -#include "aboutdialog.h" -#include "dockwidget.h" -#include "xml.h" - -namespace Ui -{ - class MainWindow; -} - -class MainWindow: - public QMainWindow -{ - Q_OBJECT - - public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); - - protected: - void changeEvent(QEvent *e); - - private: - void initGraphicsRegion(); - void initDialogsWidget(); - void initPageWidget(); - void initRegionWidget(); - void initXmlWidget(); - void initMenuBar(); - void connectWidgets(); - - void setActionsEnabled(bool isSegmented); - void disableActions(); - - void printItems(QPainter *painter, const QList<QGraphicsItem *>& items, QStyleOptionGraphicsItem *options); - - Xml processTmpXml(const QString& filename) const; - QList<RegionItem *> toRegionItems(QList<XmlItem *> regionItems) const; - QList<XmlItem *> toXmlItems(QList<RegionItem *> xmlItems) const; - - Ui::MainWindow *ui; - - DockWidget dockRegion_; - DockWidget dockPages_; - DockWidget dockXml_; - - GraphicsView graphicsView_; - Scene scene_; - - PagesWidget pagesWidget_; - RegionWidget regionWidget_; - - AboutDialog *aboutDialog_; - ProgressDialog *progressDialog_; - PreferencesDialog *preferencesDialog_; - - XmlWidget xmlWidget_; - Xml xml_; - Runner runner_; - - QAction *segment_; - QAction *previewPrinting_; - QAction *print_; - QAction *export_; - - public slots: - void printScene(QPrinter *printer); - - private slots: - void onOpen(); - void onSegment(); - void onPreviewPrint(); - void onPrint(); - void onExportation(); - inline void onPreferences(); - inline void onAbout(); - - void onXmlSaved(const QString& filename); - void onFileChanged(const QString& filename); - - void onRegionSelection(QList<RegionItem *> regionItems); - - void onXmlChangeSelection(QList<XmlItem *> xmlItems, bool select); - inline void onXmlSelect(QList<XmlItem *> xmlItems); - inline void onXmlUnselect(QList<XmlItem *> xmlItems); -}; - -inline void MainWindow::onPreferences() -{ preferencesDialog_->show(); } - -inline void MainWindow::onAbout() -{ aboutDialog_->show(); } - -inline void MainWindow::onXmlSelect(QList<XmlItem *> xmlItems) -{ onXmlChangeSelection(xmlItems, true); } - -inline void MainWindow::onXmlUnselect(QList<XmlItem *> xmlItems) -{ onXmlChangeSelection(xmlItems, false); } - -#endif // MAINWINDOW_H diff --git a/GScribo/region.h b/GScribo/region.h deleted file mode 100644 index ee8d836..0000000 --- a/GScribo/region.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef REGION_H -#define REGION_H - -#include <QColor> - -namespace GraphicsRegion -{ - // WARNING : The order is important. - enum Id - { - TextRegion, - Line, - - VerticalSeparator, - HorizontalSeparator, - WhiteSpaceSeparator, - - Image, - Noise, - Table, - Maths, - Graphic, - Chart, - - Baseline, - Meanline, - - Text, - Separators, - Miscellaneous, - Typology, - - None - }; - - struct Data - { - QColor color; - QString name; - GraphicsRegion::Id region; - GraphicsRegion::Id parent; - int zValue; - }; -} - -namespace Separator -{ - enum FindSeparator - { - Lines, - Whitespaces, - Both - }; -} - -#endif // REGION_H diff --git a/GScribo/regionwidget.cpp b/GScribo/regionwidget.cpp deleted file mode 100644 index 5d1a95e..0000000 --- a/GScribo/regionwidget.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "regionwidget.h" - -RegionWidget::RegionWidget(QWidget *parent) : - QTreeWidget(parent) -{ - setHeaderHidden(true); - setSelectionMode(QAbstractItemView::NoSelection); - - addTopLevelItem(createRoot("Text", GraphicsRegion::Text, GraphicsRegion::TextRegion, GraphicsRegion::Line)); - addTopLevelItem(createRoot("Typological Lines", GraphicsRegion::Typology, GraphicsRegion::Baseline, GraphicsRegion::Meanline)); - addTopLevelItem(createRoot("Separators", GraphicsRegion::Separators, GraphicsRegion::VerticalSeparator, GraphicsRegion::WhiteSpaceSeparator)); - addTopLevelItem(createRoot("Miscellaneous", GraphicsRegion::Miscellaneous, GraphicsRegion::Image, GraphicsRegion::Chart)); - - expandAll(); - - connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(checkStateChanged(QTreeWidgetItem*))); -} - -QTreeWidgetItem *RegionWidget::createRoot(const QString& text, const GraphicsRegion::Id& region, const GraphicsRegion::Id& begin, const GraphicsRegion::Id& end) -{ - // Create root. - QTreeWidgetItem *rootItem = createItem(text, region); - - // Fill root with corresponding childs. - for(int region_ = begin; region_ <= end; region_++) - fillRoot(rootItem, static_castGraphicsRegion::Id(region_)); - - return rootItem; -} - -QTreeWidgetItem *RegionWidget::createItem(const QString& text, const GraphicsRegion::Id& region, const QColor& color) -{ - QTreeWidgetItem *item = new QTreeWidgetItem; - item->setText(0, text); - item->setCheckState(0, Qt::Checked); - item->setBackgroundColor(0, color); - // Store graphical id in the object to recognize it afterward. - item->setData(0, Qt::UserRole, static_cast<int>(region)); - - return item; -} - -void RegionWidget::checkStateChanged(QTreeWidgetItem *item) -{ - // If it's a root item, go to childs. - if(item->childCount() != 0) - { - QTreeWidgetItem *child; - for(int i = 0; i < item->childCount(); i++) - { - child = item->child(i); - child->setCheckState(0, item->checkState(0)); - } - } - else - { - if(item->checkState(0) == Qt::Checked) - { - filterString_.append('|' + item->text(0)); - emit checkStateChanged(static_castGraphicsRegion::Id(item->data(0, Qt::UserRole).toInt()), true); - } - else - { - filterString_.remove('|' + item->text(0), Qt::CaseSensitive); - emit checkStateChanged(static_castGraphicsRegion::Id(item->data(0, Qt::UserRole).toInt()), false); - } - - //emit checkStateChanged(filterString_); - } -} diff --git a/GScribo/regionwidget.h b/GScribo/regionwidget.h deleted file mode 100644 index aaa6eda..0000000 --- a/GScribo/regionwidget.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef REGIONWIDGET_H -#define REGIONWIDGET_H - -#include <QTreeWidget> -#include <QLabel> - -#include "xml.h" - -class RegionWidget : - public QTreeWidget -{ - Q_OBJECT - - public: - explicit RegionWidget(QWidget *parent = 0); - - inline QString filterString() const; - - private: - QTreeWidgetItem *createRoot(const QString& text, const GraphicsRegion::Id& region, const GraphicsRegion::Id& begin, const GraphicsRegion::Id& end); - QTreeWidgetItem *createItem(const QString& text, const GraphicsRegion::Id& region, const QColor& color = QColor::fromRgb(255, 255, 255)); - inline void fillRoot(QTreeWidgetItem *rootItem, const GraphicsRegion::Id& region); - - QString filterString_; - - private slots: - void checkStateChanged(QTreeWidgetItem *item); - - signals: - void checkStateChanged(const GraphicsRegion::Id& region, bool checked); - void checkStateChanged(const QString& filterString); -}; - -inline void RegionWidget::fillRoot(QTreeWidgetItem *rootItem, const GraphicsRegion::Id& region) -{ GraphicsRegion::Data data = Xml::dataFromRegion(region); filterString_.append('|' + data.name); rootItem->addChild(createItem(data.name, region, data.color)); } - -inline QString RegionWidget::filterString() const -{ return filterString_.right(filterString_.count()-1); } - -#endif // REGIONWIDGET_H diff --git a/GScribo/variantpointer.h b/GScribo/variantpointer.h deleted file mode 100644 index a11072c..0000000 --- a/GScribo/variantpointer.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef VARIANTPOINTER_H -#define VARIANTPOINTER_H - -#include <QVariant> - -template<typename T> class VariantPointer -{ - public: - static inline QVariant toQVariant(T *pointer) - { return QVariant::fromValue(static_cast<void *>(pointer)); } - - static inline T *fromQVariant(const QVariant& variant) - { return static_cast<T *>(variant.value<void *>()); } - - private: - VariantPointer() { } -}; - -#endif // VARIANTPOINTER_H diff --git a/GScribo/xml.cpp b/GScribo/xml.cpp deleted file mode 100644 index 9b0334d..0000000 --- a/GScribo/xml.cpp +++ /dev/null @@ -1,206 +0,0 @@ -#include "xml.h" - -Xml::Xml(const QString& filename) -{ - load(filename); -} - -QString Xml::getPath(const QString& filename) -{ - Configs *const configs = 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 configs->generalSaveXmlCustomDirPath() + "/" + xmlPath; -} - -void Xml::isRecognized(const QDomElement& textElement) -{ - QDomElement lineElement = textElement.firstChild().nextSiblingElement("Line"); - - // Check if the attributes "text" exists in the attributes of line in the xml file. - isRecognized_ = lineElement.attributeNode("text").isNull() ? false : true; -} - -void Xml::load(const QString& filename) -{ - if(filename.isEmpty()) - { - xmlItem_ = 0; - graphicsItem_ = 0; - filename_ = QString(); - isRecognized_ = false; - return; - } - - // Reset graphic and tree items; - xmlItem_ = new XmlItem; - graphicsItem_ = new RootGraphicsItem(13); - filename_ = getPath(filename); - - QFile xmlFile(filename); - xmlFile.open(QIODevice::ReadOnly); - - // Fill new xml tree. - xml_.clear(); - xml_.setContent(&xmlFile); - - xmlFile.close(); - - QDomElement root = xml_.documentElement(); - xmlItem_->load(root); - xmlItem_->show(); - - root = root.firstChild().toElement(); - XmlItem *parentTreeItem = init(root, xmlItem_); - - // Run through the xml file structure by structure. - root = root.nextSibling().firstChild().toElement(); - // Check if the xml file has been recognized by the ocr or not. - isRecognized(root); - - processNode(root, datas_[0], parentTreeItem); - for(int i = 2; i < 11; i++) - processNode(root.nextSiblingElement(datas_[i].name), datas_[i], parentTreeItem); -} - -XmlItem *Xml::init(const QDomElement& root, XmlItem *rootTreeItem) -{ - XmlItem *metadataItem = new XmlItem(root, rootTreeItem); - - XmlItem *contentItem = 0; - - // Run through "METADATA" node and subnodes. - QDomElement node = root.firstChild().toElement(); - while(!node.isNull()) - { - contentItem = new XmlItem(node, metadataItem, contentItem); - node = node.nextSibling().toElement(); - } - - // Add "PAGE" root node and return it. - metadataItem = new XmlItem(root.nextSibling().toElement(), rootTreeItem, metadataItem); - metadataItem->show(); - - return metadataItem; -} - -void Xml::processNode(const QDomElement& root, const GraphicsRegion::Data& data, XmlItem *pageItem) -{ - if(!root.isNull()) - { - // Create corresponding tree item. - XmlItem *regionItem = new XmlItem(root, pageItem); - - QDomElement node = root.firstChild().toElement(); - XmlItem *coordsItem = new XmlItem(node, regionItem); - - QPolygon polygon; - XmlItem *pointItem = 0; - QString x, y; - - // Run through all points data. - node = node.firstChild().toElement(); - while(!node.isNull()) - { - x = node.attribute("x", "null"); - y = node.attribute("y", "null"); - - pointItem = new XmlItem(node, coordsItem, pointItem); - - polygon << QPoint(x.toInt(), y.toInt()); - node = node.nextSibling().toElement(); - } - - // Create the graphics item from data structure. - RegionItem *graphicsItem = new RegionItem(polygon, graphicsItem_); - graphicsItem->loadData(data); - graphicsItem_->addItemFrom(graphicsItem, data.region); - - // Store xml item and graphics item in each object for selection. - regionItem->setRegionItem(graphicsItem); - graphicsItem->setXmlItem(regionItem); - - if(data.region == GraphicsRegion::TextRegion) - 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, XmlItem *precItem) -{ - if(!root.isNull()) - { - // Create corresponding tree item. - XmlItem *lineItem = new XmlItem(root, precItem->parent(), precItem); - - QDomElement node = root.firstChild().toElement(); - XmlItem *coordsItem = new XmlItem(node, lineItem); - - QPolygon polygon; - XmlItem *pointItem = 0; - - QString xs, ys; - int x, y; - - int xMin = INT_MAX; - int xMax = INT_MIN; - - // Run through all points data. - node = node.firstChild().toElement(); - while(!node.isNull()) - { - xs = node.attribute("x", "null"); - ys = node.attribute("y", "null"); - - pointItem = new XmlItem(node, coordsItem, pointItem); - - x = xs.toInt(); - y = ys.toInt(); - - // Get beginning and end of line. - if(xMin > x) - xMin = x; - if(xMax < x) - xMax = x; - - polygon << QPoint(x, y); - node = node.nextSibling().toElement(); - } - - // Create the graphics item from data structure. - RegionItem *graphicsItem = new RegionItem(polygon, graphicsItem_); - graphicsItem->loadData(datas_[1]); - graphicsItem_->addItemFrom(graphicsItem, datas_[1].region); - - // Store xml item and graphics item in each object for selection. - lineItem->setRegionItem(graphicsItem); - graphicsItem->setXmlItem(lineItem); - - // Get meanline and baseline. - processTypoNode(root, QPoint(xMin, xMax)); - // Run through all line nodes recursively. - processLineNode(root.nextSiblingElement(datas_[1].name), lineItem); - } -} - -void Xml::processTypoNode(const QDomElement& root, const QPoint& xPoint) -{ - int yPos = root.attribute("baseline", "null").toInt(); - QGraphicsLineItem *baselineItem = new QGraphicsLineItem(QLine(QPoint(xPoint.x(), yPos), QPoint(xPoint.y(), yPos))); - baselineItem->setZValue(datas_[11].zValue); - graphicsItem_->addItemFrom(baselineItem, datas_[11].region); - - yPos = root.attribute("meanline", "null").toInt(); - QGraphicsLineItem *meanlineItem = new QGraphicsLineItem(QLine(QPoint(xPoint.x(), yPos), QPoint(xPoint.y(), yPos))); - meanlineItem->setZValue(datas_[12].zValue); - graphicsItem_->addItemFrom(meanlineItem, datas_[12].region); -} diff --git a/GScribo/xml.h b/GScribo/xml.h deleted file mode 100644 index f9274ed..0000000 --- a/GScribo/xml.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef XML_H -#define XML_H - -#include <QTreeWidgetItem> -#include <QGraphicsItem> -#include <QStringList> -#include <QDomElement> -#include <QDomAttr> -#include <climits> -#include <QFile> - -#include "Rendering/rootgraphicsitem.h" -#include "Rendering/regionitem.h" -#include "XmlWidget/xmlitem.h" -#include "variantpointer.h" -#include "configs.h" -#include "region.h" - -// WARNING : The order is VERY IMPORTANT (depending on the enum). -static const GraphicsRegion::Data datas_[] = -{ - /* COLOR | NAME | REGION | PARENT | Z */ - { QColor::fromRgb(0, 100, 0, 110), "TextRegion", GraphicsRegion::TextRegion, GraphicsRegion::Text, 1 }, - { QColor::fromRgb(255, 0, 0, 110), "Line", GraphicsRegion::Line, GraphicsRegion::Text, 2 }, - { QColor::fromRgb(0, 0, 255, 110), "VerticalSeparatorRegion", GraphicsRegion::VerticalSeparator, GraphicsRegion::Separators, 2 }, - { QColor::fromRgb(0, 0, 255, 110), "HorizontalSeparatorRegion", GraphicsRegion::HorizontalSeparator, GraphicsRegion::Separators, 2 }, - { QColor::fromRgb(0, 0, 128, 110), "WhitespaceSeparatorRegion", GraphicsRegion::WhiteSpaceSeparator, GraphicsRegion::Separators, 2 }, - { QColor::fromRgb(255, 120, 0, 110), "ImageRegion", GraphicsRegion::Image, GraphicsRegion::Miscellaneous, 1 }, - { QColor::fromRgb(43, 39, 128, 110), "NoiseRegion", GraphicsRegion::Noise, GraphicsRegion::Miscellaneous, 2 }, - { QColor::fromRgb(220, 246, 0, 110), "TableRegion", GraphicsRegion::Table, GraphicsRegion::Miscellaneous, 2 }, - { QColor::fromRgb(170, 0, 255, 110), "MathsRegion", GraphicsRegion::Maths, GraphicsRegion::Miscellaneous, 2 }, - { QColor::fromRgb(255, 0, 144, 110), "GraphicsRegion", GraphicsRegion::Graphic, GraphicsRegion::Miscellaneous, 2 }, - { QColor::fromRgb(0, 204, 255, 110), "ChartRegion", GraphicsRegion::Chart, GraphicsRegion::Miscellaneous, 2 }, - { QColor::fromRgb(128, 0, 255), "Baseline", GraphicsRegion::Baseline, GraphicsRegion::Typology, 3 }, - { QColor::fromRgb(128, 0, 255), "Meanline", GraphicsRegion::Meanline, GraphicsRegion::Typology, 3 }, - { QColor::fromRgb(255, 255, 255), "Text", GraphicsRegion::Text, GraphicsRegion::None, 0 }, - { QColor::fromRgb(255, 255, 255), "Separators", GraphicsRegion::Separators, GraphicsRegion::None, 0 }, - { QColor::fromRgb(255, 255, 255), "Miscellaneous", GraphicsRegion::Miscellaneous, GraphicsRegion::None, 0 }, - { QColor::fromRgb(255, 255, 255), "Typological Lines", GraphicsRegion::Typology, GraphicsRegion::None, 0 } -}; - -class Xml -{ - public: - explicit Xml(const QString& filename = QString()); - - inline XmlItem *xmlItem(); - inline RootGraphicsItem *graphicsItem(); - - inline QDomDocument document() const; - inline QString filename() const; - inline bool recognized() const; - - static QString getPath(const QString& filename); - - void load(const QString& filename); - inline static GraphicsRegion::Data dataFromRegion(GraphicsRegion::Id region); - - private: - XmlItem *init(const QDomElement& root, XmlItem *rootTreeItem); - void isRecognized(const QDomElement& element); - - void processNode(const QDomElement& root, const GraphicsRegion::Data& data, XmlItem *rootTreeItem); - void processLineNode(const QDomElement& root, XmlItem *rootTreeItem); - void processTypoNode(const QDomElement& root, const QPoint& xPoint); - - RootGraphicsItem *graphicsItem_; - XmlItem *xmlItem_; - - QDomDocument xml_; - QString filename_; - bool isRecognized_; -}; - -inline XmlItem *Xml::xmlItem() -{ return xmlItem_; } - -inline RootGraphicsItem *Xml::graphicsItem() -{ return graphicsItem_; } - -inline QDomDocument Xml::document() const -{ return xml_; } - -inline QString Xml::filename() const -{ return filename_; } - -inline GraphicsRegion::Data Xml::dataFromRegion(GraphicsRegion::Id region) -{ return datas_[region]; } - -inline bool Xml::recognized() const -{ return isRecognized_; } - -#endif // XML_H diff --git a/scribo/ChangeLog b/scribo/ChangeLog index c4bdcfc..529fdf5 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,3 +1,143 @@ +2013-02-27 Guillaume Lazzara z@lrde.epita.fr + + Move new viewer to scribo/demo. + + * scribo/demo/viewer/BUGS, + * scribo/demo/viewer/GScribo.pro, + * scribo/demo/viewer/GScribo.pro.user, + * scribo/demo/viewer/GScribo.pro.user.1.3, + * scribo/demo/viewer/Makefile.am, + * scribo/demo/viewer/PagesWidget/pagesdelegate.cc, + * scribo/demo/viewer/PagesWidget/pagesdelegate.hh, + * scribo/demo/viewer/PagesWidget/pagesmodel.cc, + * scribo/demo/viewer/PagesWidget/pagesmodel.hh, + * scribo/demo/viewer/PagesWidget/pageswidget.cc, + * scribo/demo/viewer/PagesWidget/pageswidget.hh, + * scribo/demo/viewer/Preferences/generaloptions.cc, + * scribo/demo/viewer/Preferences/generaloptions.hh, + * scribo/demo/viewer/Preferences/generaloptions.ui, + * scribo/demo/viewer/Preferences/ocroptions.cc, + * scribo/demo/viewer/Preferences/ocroptions.hh, + * scribo/demo/viewer/Preferences/ocroptions.ui, + * scribo/demo/viewer/Preferences/optionwidget.hh, + * scribo/demo/viewer/Preferences/preferencesdialog.cc, + * scribo/demo/viewer/Preferences/preferencesdialog.hh, + * scribo/demo/viewer/Preferences/preferencesdialog.ui, + * scribo/demo/viewer/Preferences/preprocessingoptions.cc, + * scribo/demo/viewer/Preferences/preprocessingoptions.hh, + * scribo/demo/viewer/Preferences/preprocessingoptions.ui, + * scribo/demo/viewer/Preferences/segmentationoptions.cc, + * scribo/demo/viewer/Preferences/segmentationoptions.hh, + * scribo/demo/viewer/Preferences/segmentationoptions.ui, + * scribo/demo/viewer/Processing/preprocess.cc, + * scribo/demo/viewer/Processing/preprocess.hh, + * scribo/demo/viewer/Processing/process.cc, + * scribo/demo/viewer/Processing/process.hh, + * scribo/demo/viewer/Processing/progressdialog.cc, + * scribo/demo/viewer/Processing/progressdialog.hh, + * scribo/demo/viewer/Processing/runner.cc, + * scribo/demo/viewer/Processing/runner.hh, + * scribo/demo/viewer/Rendering/abstractregionitem.hh, + * scribo/demo/viewer/Rendering/backgroundtexture.hh, + * scribo/demo/viewer/Rendering/graphicsview.cc, + * scribo/demo/viewer/Rendering/graphicsview.hh, + * scribo/demo/viewer/Rendering/regionitem.cc, + * scribo/demo/viewer/Rendering/regionitem.hh, + * scribo/demo/viewer/Rendering/rootgraphicsitem.cc, + * scribo/demo/viewer/Rendering/rootgraphicsitem.hh, + * scribo/demo/viewer/Rendering/scene.cc, + * scribo/demo/viewer/Rendering/scene.hh, + * scribo/demo/viewer/Rendering/selection.cc, + * scribo/demo/viewer/Rendering/selection.hh, + * scribo/demo/viewer/TODO, + * scribo/demo/viewer/XmlWidget/attributesmodel.cc, + * scribo/demo/viewer/XmlWidget/attributesmodel.hh, + * scribo/demo/viewer/XmlWidget/selectionproxy.hh, + * scribo/demo/viewer/XmlWidget/xmlattributes.cc, + * scribo/demo/viewer/XmlWidget/xmlattributes.hh, + * scribo/demo/viewer/XmlWidget/xmldelegate.hh, + * scribo/demo/viewer/XmlWidget/xmlitem.cc, + * scribo/demo/viewer/XmlWidget/xmlitem.hh, + * scribo/demo/viewer/XmlWidget/xmlmodel.cc, + * scribo/demo/viewer/XmlWidget/xmlmodel.hh, + * scribo/demo/viewer/XmlWidget/xmlview.cc, + * scribo/demo/viewer/XmlWidget/xmlview.hh, + * scribo/demo/viewer/XmlWidget/xmlwidget.cc, + * scribo/demo/viewer/XmlWidget/xmlwidget.hh, + * scribo/demo/viewer/aboutdialog.cc, + * scribo/demo/viewer/aboutdialog.hh, + * scribo/demo/viewer/aboutdialog.ui, + * scribo/demo/viewer/config.cc, + * scribo/demo/viewer/configs.cc, + * scribo/demo/viewer/configs.hh, + * scribo/demo/viewer/defs.hh, + * scribo/demo/viewer/dir.hh, + * scribo/demo/viewer/dockwidget.cc, + * scribo/demo/viewer/dockwidget.hh, + * scribo/demo/viewer/general_options.hh, + * scribo/demo/viewer/help_dialog.hh, + * scribo/demo/viewer/image_scene.hh, + * scribo/demo/viewer/image_view.hh, + * scribo/demo/viewer/main.cc, + * scribo/demo/viewer/mainwindow.cc, + * scribo/demo/viewer/mainwindow.hh, + * scribo/demo/viewer/mainwindow.ui, + * scribo/demo/viewer/ocr_options.hh, + * scribo/demo/viewer/option_widget.cc, + * scribo/demo/viewer/option_widget.hh, + * scribo/demo/viewer/preprocess.cc, + * scribo/demo/viewer/preprocess.hh, + * scribo/demo/viewer/process.cc, + * scribo/demo/viewer/region.hh, + * scribo/demo/viewer/regionwidget.cc, + * scribo/demo/viewer/regionwidget.hh, + * scribo/demo/viewer/variantpointer.cc, + * scribo/demo/viewer/variantpointer.hh, + * scribo/demo/viewer/xml.cc, + * scribo/demo/viewer/xml.hh: New. + + * scribo/demo/viewer/README, + * scribo/demo/viewer/browser_widget.cc, + * scribo/demo/viewer/browser_widget.hh, + * scribo/demo/viewer/common.hh, + * scribo/demo/viewer/config.hh, + * scribo/demo/viewer/general_options.cc, + * scribo/demo/viewer/general_options.ui, + * scribo/demo/viewer/help_dialog.cc, + * scribo/demo/viewer/help_dialog.ui, + * scribo/demo/viewer/icons/olena_smaller.jpg, + * scribo/demo/viewer/image_region.cc, + * scribo/demo/viewer/image_region.hh, + * scribo/demo/viewer/image_region.hxx, + * scribo/demo/viewer/image_scene.cc, + * scribo/demo/viewer/image_view.cc, + * scribo/demo/viewer/image_widget.cc, + * scribo/demo/viewer/image_widget.hh, + * scribo/demo/viewer/key_widget.cc, + * scribo/demo/viewer/key_widget.hh, + * scribo/demo/viewer/ocr_options.cc, + * scribo/demo/viewer/ocr_options.ui, + * scribo/demo/viewer/preferences_dialog.cc, + * scribo/demo/viewer/preferences_dialog.hh, + * scribo/demo/viewer/preferences_dialog.ui, + * scribo/demo/viewer/preprocessing_options.cc, + * scribo/demo/viewer/preprocessing_options.hh, + * scribo/demo/viewer/preprocessing_options.ui, + * scribo/demo/viewer/process.hh, + * scribo/demo/viewer/runner.cc, + * scribo/demo/viewer/runner.hh, + * scribo/demo/viewer/segmentation_options.cc, + * scribo/demo/viewer/segmentation_options.hh, + * scribo/demo/viewer/segmentation_options.ui, + * scribo/demo/viewer/step_widget.cc, + * scribo/demo/viewer/step_widget.hh, + * scribo/demo/viewer/viewer.cc, + * scribo/demo/viewer/viewer.hh, + * scribo/demo/viewer/viewer.hxx, + * scribo/demo/viewer/viewer.qrc , + * scribo/demo/viewer/xml_widget.cc, + * scribo/demo/viewer/xml_widget.hh: Remove. + 2013-02-26 Guillaume Lazzara z@lrde.epita.fr
* tests/unit_test/unit-tests.mk: Update. diff --git a/GScribo/BUGS b/scribo/demo/viewer/BUGS similarity index 100% rename from GScribo/BUGS rename to scribo/demo/viewer/BUGS diff --git a/scribo/demo/viewer/GScribo.pro b/scribo/demo/viewer/GScribo.pro new file mode 100644 index 0000000..d607cc5 --- /dev/null +++ b/scribo/demo/viewer/GScribo.pro @@ -0,0 +1,83 @@ +# ------------------------------------------------- +# Project created by QtCreator 2013-01-21T09:20:54 +# ------------------------------------------------- +QT += xml +INCLUDEPATH += /lrde/home/stage/froger_a/olena/scribo/ \ + /lrde/home/stage/froger_a/olena/milena/ \ + /lrde/home/stage/froger_a/olena/_build/scribo/demo/ +QMAKE_CXXFLAGS += -DNDEBUG \ + -DMLN_WO_GLOBAL_VARS +LIBS += -I/usr/include/graphicsImage \ + -lGraphicsMagick++ \ + -ltesseract_full \ + -ltiff +TARGET = GScribo +TEMPLATE = app +SOURCES += regionwidget.cc \ + mainwindow.cc \ + main.cc \ + xml.cc \ + Rendering/scene.cc \ + Rendering/selection.cc \ + Rendering/regionitem.cc \ + Rendering/graphicsview.cc \ + PagesWidget/pageswidget.cc \ + PagesWidget/pagesmodel.cc \ + PagesWidget/pagesdelegate.cc \ + Preferences/segmentationoptions.cc \ + Preferences/preprocessingoptions.cc \ + Preferences/ocroptions.cc \ + Preferences/generaloptions.cc \ + Preferences/preferencesdialog.cc \ + Processing/progressdialog.cc \ + Processing/preprocess.cc \ + Processing/process.cc \ + Processing/runner.cc \ + XmlWidget/xmlwidget.cc \ + XmlWidget/xmlmodel.cc \ + XmlWidget/xmlitem.cc \ + XmlWidget/xmlattributes.cc \ + XmlWidget/attributesmodel.cc \ + XmlWidget/xmlview.cc +HEADERS += mainwindow.hh \ + variantpointer.hh \ + regionwidget.hh \ + aboutdialog.hh \ + configs.hh \ + region.hh \ + dir.hh \ + xml.hh \ + Rendering/scene.hh \ + Rendering/selection.hh \ + Rendering/regionitem.hh \ + Rendering/graphicsview.hh \ + PagesWidget/pageswidget.hh \ + PagesWidget/pagesmodel.hh \ + Processing/preprocess.hh \ + Processing/process.hh \ + Processing/runner.hh \ + Processing/progressdialog.hh \ + Preferences/segmentationoptions.hh \ + Preferences/preprocessingoptions.hh \ + Preferences/ocroptions.hh \ + Preferences/generaloptions.hh \ + Preferences/optionwidget.hh \ + Preferences/preferencesdialog.hh \ + XmlWidget/xmlwidget.hh \ + XmlWidget/xmlmodel.hh \ + XmlWidget/xmlitem.hh \ + XmlWidget/xmlattributes.hh \ + XmlWidget/selectionproxy.hh \ + XmlWidget/xmldelegate.hh \ + XmlWidget/attributesmodel.hh \ + PagesWidget/pagesdelegate.hh \ + Rendering/rootgraphicsitem.hh \ + XmlWidget/xmlview.hh \ + dockwidget.hh +FORMS += mainwindow.ui \ + aboutdialog.ui \ + Preferences/preferencesdialog.ui \ + Preferences/ocroptions.ui \ + Preferences/segmentationoptions.ui \ + Preferences/generaloptions.ui \ + Preferences/preprocessingoptions.ui diff --git a/GScribo/GScribo.pro.user b/scribo/demo/viewer/GScribo.pro.user similarity index 100% rename from GScribo/GScribo.pro.user rename to scribo/demo/viewer/GScribo.pro.user diff --git a/GScribo/GScribo.pro.user.1.3 b/scribo/demo/viewer/GScribo.pro.user.1.3 similarity index 100% rename from GScribo/GScribo.pro.user.1.3 rename to scribo/demo/viewer/GScribo.pro.user.1.3 diff --git a/scribo/demo/viewer/Makefile.am b/scribo/demo/viewer/Makefile.am index d79abcf..23c800b 100644 --- a/scribo/demo/viewer/Makefile.am +++ b/scribo/demo/viewer/Makefile.am @@ -19,96 +19,131 @@ include $(top_srcdir)/build-aux/autotroll.mk
bin_PROGRAMS = scribo-viewer -scribo_viewer_SOURCES = viewer.cc \ +scribo_viewer_SOURCES = mainwindow.cc \ + aboutdialog.cc \ + configs.cc \ main.cc \ - image_widget.cc \ - xml_widget.cc \ - key_widget.cc \ - browser_widget.cc \ - image_scene.cc \ - image_view.cc \ - image_region.cc \ - help_dialog.cc \ - step_widget.cc \ - preprocessing_options.cc\ - segmentation_options.cc \ - ocr_options.cc \ - runner.cc \ - preprocess.cc \ - process.cc \ - general_options.cc \ - preferences_dialog.cc \ - option_widget.cc \ - config.cc + regionwidget.cc \ + xml.cc \ + dockwidget.cc \ + PagesWidget/pagesdelegate.cc \ + PagesWidget/pagesmodel.cc \ + PagesWidget/pageswidget.cc \ + Preferences/generaloptions.cc \ + Preferences/ocroptions.cc \ + Preferences/preferencesdialog.cc \ + Preferences/preprocessingoptions.cc \ + Preferences/segmentationoptions.cc \ + Processing/preprocess.cc \ + Processing/process.cc \ + Processing/progressdialog.cc \ + Processing/runner.cc \ + Rendering/graphicsview.cc \ + Rendering/regionitem.cc \ + Rendering/scene.cc \ + Rendering/selection.cc \ + Rendering/rootgraphicsitem.cc \ + XmlWidget/attributesmodel.cc \ + XmlWidget/xmlattributes.cc \ + XmlWidget/xmlitem.cc \ + XmlWidget/xmlmodel.cc \ + XmlWidget/xmlview.cc \ + XmlWidget/xmlwidget.cc + +
nodist_scribo_viewer_SOURCES = $(BUILT_SOURCES)
+ + scribo_viewer_CPPFLAGS = $(QT_CPPFLAGS) $(AM_CPPFLAGS) -I$(srcdir) \ + -I$(builddir) \ -I$(top_srcdir)/milena \ -I$(top_srcdir)/scribo \ $(MAGICKXX_CPPFLAGS) \ $(TESSERACT_CPPFLAGS) \ $(TIFF_CPPFLAGS) \ -DNDEBUG -DMLN_WO_GLOBAL_VARS + + + scribo_viewer_CXXFLAGS = $(QT_CXXFLAGS) $(AM_CXXFLAGS) \ $(STRICT_ALIASING_CXXFLAGS) -O3 + + + scribo_viewer_LDFLAGS = $(QT_LDFLAGS) $(LDFLAGS) \ $(MAGICKXX_LDFLAGS) \ $(TESSERACT_LDFLAGS) \ $(TIFF_LDFLAGS) + + + scribo_viewer_LDADD = $(QT_LIBS) $(LDADD)
-BUILT_SOURCES = viewer.moc.cc \ - image_widget.moc.cc \ - xml_widget.moc.cc \ - key_widget.moc.cc \ - browser_widget.moc.cc \ - image_scene.moc.cc \ - image_view.moc.cc \ - image_region.moc.cc \ - help_dialog.ui.h \ - step_widget.moc.cc \ - preprocessing_options.moc.cc \ - preprocessing_options.ui.h \ - segmentation_options.moc.cc \ - segmentation_options.ui.h \ - ocr_options.moc.cc \ - ocr_options.ui.h \ - runner.moc.cc \ - preprocess.moc.cc \ - process.moc.cc \ - preferences_dialog.moc.cc \ - preferences_dialog.ui.h \ - general_options.moc.cc \ - general_options.ui.h \ - demodir.hh \ - viewer.qrc.cc - - -noinst_HEADERS = viewer.hh \ - viewer.hxx \ - image_widget.hh \ - xml_widget.hh \ - key_widget.hh \ - browser_widget.hh \ - image_scene.hh \ - image_view.hh \ - image_region.hh \ - image_region.hxx \ - common.hh \ - help_dialog.hh \ - step_widget.hh \ - preprocessing_options.hh\ - segmentation_options.hh\ - ocr_options.hh \ - runner.hh \ - preprocess.hh \ - process.hh \ - general_options.hh \ - preferences_dialog.hh \ - option_widget.hh \ - config.hh \ - defs.hh + + +BUILT_SOURCES = demodir.hh \ + dockwidget.moc.cc \ + Rendering/graphicsview.moc.cc \ + mainwindow.moc.cc \ + Preferences/ocroptions.moc.cc \ + PagesWidget/pagesmodel.moc.cc \ + PagesWidget/pageswidget.moc.cc \ + Preferences/preferencesdialog.moc.cc \ + Processing/preprocess.moc.cc \ + Preferences/preprocessingoptions.moc.cc \ + Processing/process.moc.cc \ + Processing/progressdialog.moc.cc \ + regionwidget.moc.cc \ + Processing/runner.moc.cc \ + Rendering/scene.moc.cc \ + Preferences/segmentationoptions.moc.cc \ + XmlWidget/xmlview.moc.cc \ + XmlWidget/xmlwidget.moc.cc \ + aboutdialog.ui.h \ + Preferences/generaloptions.ui.h \ + mainwindow.ui.h \ + Preferences/generaloptions.moc.cc \ + Preferences/ocroptions.ui.h \ + Preferences/preferencesdialog.ui.h \ + Preferences/preprocessingoptions.ui.h \ + Preferences/segmentationoptions.ui.h \ + XmlWidget/attributesmodel.moc.cc + + +noinst_HEADERS = mainwindow.hh \ + aboutdialog.hh \ + regionwidget.hh \ + xml.hh \ + PagesWidget/pagesdelegate.hh \ + PagesWidget/pagesmodel.hh \ + PagesWidget/pageswidget.hh \ + Preferences/generaloptions.hh \ + Preferences/ocroptions.hh \ + Preferences/optionwidget.hh \ + Preferences/preferencesdialog.hh \ + Preferences/preprocessingoptions.hh \ + Preferences/segmentationoptions.hh \ + Processing/preprocess.hh \ + Processing/process.hh \ + Processing/progressdialog.hh \ + Processing/runner.hh \ + Rendering/graphicsview.hh \ + Rendering/regionitem.hh \ + Rendering/rootgraphicsitem.hh \ + Rendering/scene.hh \ + Rendering/selection.hh \ + XmlWidget/attributesmodel.hh \ + XmlWidget/selectionproxy.hh \ + XmlWidget/xmlattributes.hh \ + XmlWidget/xmldelegate.hh \ + XmlWidget/xmlitem.hh \ + XmlWidget/xmlmodel.hh \ + XmlWidget/xmlview.hh \ + XmlWidget/xmlwidget.hh + +
# Generated files @@ -116,6 +151,8 @@ do_subst = sed \ -e 's|@libexecdir[@]|$(libexecdir)|g' \ -e 's|@abs_demodir[@]|$(abs_top_builddir)/scribo/demo|g'
+ + demodir.hh: $(srcdir)/demodir.hh.in Makefile rm -f $@ $@.tmp srcdir=''; \ @@ -124,17 +161,20 @@ demodir.hh: $(srcdir)/demodir.hh.in Makefile chmod a-w $@.tmp mv $@.tmp $@
+ + CLEANFILES = $(BUILT_SOURCES)
-EXTRA_DIST = \ - general_options.ui \ - preferences_dialog.ui \ - README \ - preprocessing_options.ui\ - segmentation_options.ui \ - ocr_options.ui \ - help_dialog.ui \ - demodir.hh.in \ - viewer.qrc \ - icons/olena_smaller.jpg + + +EXTRA_DIST = BUGS \ + README \ + aboutdialog.ui \ + mainwindow.ui \ + Preferences/generaloptions.ui \ + Preferences/ocroptions.ui \ + Preferences/preferencesdialog.ui \ + Preferences/preprocessingoptions.ui \ + Preferences/segmentationoptions.ui \ + demodir.hh.in
diff --git a/scribo/demo/viewer/PagesWidget/pagesdelegate.cc b/scribo/demo/viewer/PagesWidget/pagesdelegate.cc new file mode 100644 index 0000000..f981e1f --- /dev/null +++ b/scribo/demo/viewer/PagesWidget/pagesdelegate.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "pagesdelegate.hh" + +PagesDelegate::PagesDelegate(QObject *parent) : + QStyledItemDelegate(parent) +{ + pen_.setColor(QColor::fromRgb(255, 69, 0, 255)); + pen_.setWidth(2); +} + +void PagesDelegate::paint(QPainter *painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const +{ + QStyledItemDelegate::paint(painter, option, index); + + if(index.row() == index.data(Qt::UserRole+1).toInt()) + { + painter->setPen(pen_); + painter->drawRect(option.rect); + painter->fillRect(option.rect, QColor::fromRgb(255, 69, 0, 60)); + } +} diff --git a/scribo/demo/viewer/PagesWidget/pagesdelegate.hh b/scribo/demo/viewer/PagesWidget/pagesdelegate.hh new file mode 100644 index 0000000..02440f8 --- /dev/null +++ b/scribo/demo/viewer/PagesWidget/pagesdelegate.hh @@ -0,0 +1,36 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PAGESDELEGATE_H +# define PAGESDELEGATE_H + +#include <QStyledItemDelegate> +#include <QPainter> + +class PagesDelegate : + public QStyledItemDelegate +{ + public: + explicit PagesDelegate(QObject *parent = 0); + void paint(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + private: + QPen pen_; +}; + +#endif // PAGESDELEGATE_H diff --git a/scribo/demo/viewer/PagesWidget/pagesmodel.cc b/scribo/demo/viewer/PagesWidget/pagesmodel.cc new file mode 100644 index 0000000..6246f18 --- /dev/null +++ b/scribo/demo/viewer/PagesWidget/pagesmodel.cc @@ -0,0 +1,91 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "pagesmodel.hh" + +PagesModel::PagesModel(QObject *parent): + QAbstractListModel(parent) +{ + currentRow_ = 0; +} + +QVariant PagesModel::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + if(role == Qt::DecorationRole) + return pixmaps_[index.row()]; + + if(role == Qt::UserRole) + return filenames_[index.row()]; + + if(role == Qt::UserRole+1) + return currentRow_; + + return QVariant(); +} + +void PagesModel::addPicture(const QString& filename, const QPixmap& pixmap) +{ + beginInsertRows(QModelIndex(), 0, 0); + + pixmaps_.prepend(pixmap.scaled(QSize(200, 200), + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); + filenames_.prepend(filename); + + endInsertRows(); +} + +void PagesModel::removePixmap(const QModelIndex &parent) +{ + int row = parent.row(); + + beginRemoveRows(parent, row, row); + + pixmaps_.removeAt(row); + filenames_.removeAt(row); + + endRemoveRows(); +} + +void PagesModel::setCurrentRow(int currentRow) +{ + beginResetModel(); + + currentRow_ = currentRow; + + endResetModel(); +} + + +QStringList PagesModel::filenames() const +{ + return filenames_; +} + + +int PagesModel::rowCount(const QModelIndex&) const +{ + return filenames_.count(); +} + + +int PagesModel::currentRow() const +{ + return currentRow_; +} diff --git a/scribo/demo/viewer/PagesWidget/pagesmodel.hh b/scribo/demo/viewer/PagesWidget/pagesmodel.hh new file mode 100644 index 0000000..2a0ec4b --- /dev/null +++ b/scribo/demo/viewer/PagesWidget/pagesmodel.hh @@ -0,0 +1,51 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PAGESMODEL_HH +# define PAGESMODEL_HH + +#include <QAbstractListModel> +#include <QIcon> +#include <QList> + +class PagesModel: + public QAbstractListModel +{ + Q_OBJECT + + public: + explicit PagesModel(QObject *parent = 0); + + QStringList filenames() const; + int rowCount(const QModelIndex& parent = QModelIndex()) const; + + int currentRow() const; + void setCurrentRow(int currentRow); + + QVariant data(const QModelIndex& index, int role = Qt::DecorationRole) const; + void addPicture(const QString& filename, const QPixmap& pixmap); + + private: + QStringList filenames_; + QList<QPixmap> pixmaps_; + int currentRow_; + + public slots: + void removePixmap(const QModelIndex& parent); +}; + + +#endif // PAGESMODEL_HH diff --git a/scribo/demo/viewer/PagesWidget/pageswidget.cc b/scribo/demo/viewer/PagesWidget/pageswidget.cc new file mode 100644 index 0000000..0355419 --- /dev/null +++ b/scribo/demo/viewer/PagesWidget/pageswidget.cc @@ -0,0 +1,119 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include <QDebug> +#include "pageswidget.hh" + +PagesWidget::PagesWidget(QWidget *parent): + QListView(parent) +{ + setUniformItemSizes(true); + setSelectionMode(QAbstractItemView::ExtendedSelection); + setViewMode(QListView::IconMode); + setIconSize(QSize(200, 200)); + setMovement(QListView::Static); + setResizeMode(QListView::Adjust); + setSpacing(10); + + setModel(&model_); + setItemDelegate(new PagesDelegate()); + + QShortcut *remove = new QShortcut(Qt::Key_Delete, this); + connect(remove, SIGNAL(activated()), this, SLOT(removeSelection())); + connect(this, SIGNAL(doubleClicked(QModelIndex)), + this, SLOT(getPicture(QModelIndex))); +} + +void PagesWidget::removeSelection() +{ + QModelIndexList indexes = selectionModel()->selectedIndexes(); + if(hasFocus() && indexes.count() > 0) + { + // Sort the list because after the first removal, the second row index may not be the good one. + qSort(indexes.begin(), indexes.end()); + + // From the highest row to the smallest to be sure to remove the good index. + for(int i = indexes.count()-1; i > -1; i--) + model_.removePixmap(indexes[i]); + + // Draw new image on the scene. + getPicture(model_.index(indexes[0].row())); + clearSelection(); + + model_.setCurrentRow(indexes[0].row()); + scrollTo(indexes[0]); + } +} + +void PagesWidget::getPicture(const QModelIndex& index) +{ + QString filename = index.data(Qt::UserRole).toString(); + model_.setCurrentRow(index.row()); + + emit imageSelected(filename); +} + +QStringList PagesWidget::filenames() const +{ + return model_.filenames(); +} + +int PagesWidget::currentRow() const +{ + return model_.currentRow(); +} + +void PagesWidget::setCurrentRow(int currentRow) +{ + model_.setCurrentRow(currentRow); +} + +void PagesWidget::addPicture(const QString& filename, + const QPixmap& pixmap) +{ + model_.addPicture(filename, pixmap); +} + +void PagesWidget::focusOutEvent(QFocusEvent *event) +{ + QListView::focusOutEvent(event); clearSelection(); +} + +bool PagesWidget::haveNextRow() const +{ + return currentRow() + 1 < model_.rowCount(); +} + +bool PagesWidget::havePreviousRow() const +{ + return currentRow() - 1 >= 0; +} + +void PagesWidget::selectNextRow() +{ + Q_ASSERT(haveNextRow()); + QModelIndex index = model_.index(currentRow() + 1); + getPicture(index); + scrollTo(index); +} + +void PagesWidget::selectPreviousRow() +{ + Q_ASSERT(havePreviousRow()); + QModelIndex index = model_.index(currentRow() - 1); + getPicture(index); + scrollTo(index); +} diff --git a/scribo/demo/viewer/PagesWidget/pageswidget.hh b/scribo/demo/viewer/PagesWidget/pageswidget.hh new file mode 100644 index 0000000..d159a8e --- /dev/null +++ b/scribo/demo/viewer/PagesWidget/pageswidget.hh @@ -0,0 +1,61 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + // +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PAGESWIDGET_HH +# define PAGESWIDGET_HH + +#include <QListView> +#include <QShortcut> + +#include "pagesdelegate.hh" +#include "pagesmodel.hh" + +class PagesWidget : public QListView +{ + Q_OBJECT; + +public: + explicit PagesWidget(QWidget *parent = 0); + + QStringList filenames() const; + int currentRow() const; + void setCurrentRow(int currentRow); + + void addPicture(const QString& filename, const QPixmap& pixmap); + + bool haveNextRow() const; + bool havePreviousRow() const; + +protected: + void focusOutEvent(QFocusEvent *event); + +private: + PagesModel model_; + +public slots: + void removeSelection(); + void selectNextRow(); + void selectPreviousRow(); + +private slots: + void getPicture(const QModelIndex& index); + +signals: + void imageSelected(const QString& filename); +}; + + +#endif // PAGESWIDGET_HH diff --git a/scribo/demo/viewer/Preferences/generaloptions.cc b/scribo/demo/viewer/Preferences/generaloptions.cc new file mode 100644 index 0000000..d32ee40 --- /dev/null +++ b/scribo/demo/viewer/Preferences/generaloptions.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "generaloptions.hh" +#include "Preferences/generaloptions.ui.h" + +GeneralOptions::GeneralOptions(QWidget *parent) : + OptionWidget(parent), + ui(new Ui::GeneralOptions) +{ + ui->setupUi(this); + loadConfig(); +} + +GeneralOptions::~GeneralOptions() +{ + delete ui; +} + +void GeneralOptions::loadConfig() +{ + Configs *const conf = Configs::getInstance(); + + ui->saveXml->setChecked(conf->generalSaveXmlEnabled()); + ui->sameDir->setChecked(conf->generalSaveXmlSameDir()); + ui->customDir->setChecked(conf->generalSaveXmlCustomDir()); + ui->customDirValue->setText(conf->generalSaveXmlCustomDirPath()); +} + + +void GeneralOptions::saveConfig() +{ + Configs *const conf = Configs::getInstance(); + + conf->setGeneralSaveXmlEnabled(ui->saveXml->isChecked()); + conf->setGeneralSaveXmlSameDir(ui->sameDir->isChecked()); + conf->setGeneralSaveXmlCustomDir(ui->customDir->isChecked()); + conf->setGeneralSaveXmlCustomDirPath(ui->customDirValue->text()); +} + +void GeneralOptions::onCustomDirBrowseBtnClicked() +{ + QString dir = QFileDialog::getExistingDirectory(0, "Choose a directory"); + + if (!dir.isEmpty()) + ui->customDirValue->setText(dir); +} diff --git a/scribo/demo/viewer/Preferences/generaloptions.hh b/scribo/demo/viewer/Preferences/generaloptions.hh new file mode 100644 index 0000000..1d31d18 --- /dev/null +++ b/scribo/demo/viewer/Preferences/generaloptions.hh @@ -0,0 +1,50 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef GENERALOPTIONS_HH +# define GENERALOPTIONS_HH + +#include <QFileDialog> + +#include "optionwidget.hh" +#include "configs.hh" + +namespace Ui +{ + class GeneralOptions; +} + +class GeneralOptions : + public OptionWidget +{ + Q_OBJECT + + public: + explicit GeneralOptions(QWidget *parent = 0); + ~GeneralOptions(); + + virtual void loadConfig(); + virtual void saveConfig(); + + private: + Ui::GeneralOptions *ui; + + private slots: + void onCustomDirBrowseBtnClicked(); + +}; + +#endif // GENERAL_OPTIONS_HH diff --git a/GScribo/Preferences/generaloptions.ui b/scribo/demo/viewer/Preferences/generaloptions.ui similarity index 100% rename from GScribo/Preferences/generaloptions.ui rename to scribo/demo/viewer/Preferences/generaloptions.ui diff --git a/scribo/demo/viewer/Preferences/ocroptions.cc b/scribo/demo/viewer/Preferences/ocroptions.cc new file mode 100644 index 0000000..187a8d7 --- /dev/null +++ b/scribo/demo/viewer/Preferences/ocroptions.cc @@ -0,0 +1,69 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "ocroptions.hh" +#include "Preferences/ocroptions.ui.h" + +static const char *language[][2] = +{ + { "English", "eng" }, + { "French", "fra" }, + { 0, 0 } +}; + +OcrOptions::OcrOptions(QWidget *parent) : + OptionWidget(parent), + ui(new Ui::OcrOptions) +{ + ui->setupUi(this); + + for (unsigned i = 0; language[i][0]; ++i) + ui->ocr_language->insertItem(i, language[i][0]); + + loadConfig(); +} + +OcrOptions::~OcrOptions() +{ + delete ui; +} + +int OcrOptions::findIndex(const QString& lang) +{ + for (unsigned i = 0; language[i][0]; ++i) + if (lang == language[i][1]) + return i; + + return 0; +} + + +void OcrOptions::loadConfig() +{ + Configs *const conf = Configs::getInstance(); + + ui->enable_ocr->setChecked(conf->ocrEnabled()); + ui->ocr_language->setCurrentIndex(findIndex(conf->ocrLanguage())); +} + + +void OcrOptions::saveConfig() +{ + Configs *const conf = Configs::getInstance(); + + conf->setOcrEnabled(ui->enable_ocr->isChecked()); + conf->setOcrLanguage(language[ui->ocr_language->currentIndex()][1]); +} diff --git a/scribo/demo/viewer/Preferences/ocroptions.hh b/scribo/demo/viewer/Preferences/ocroptions.hh new file mode 100644 index 0000000..8b5b209 --- /dev/null +++ b/scribo/demo/viewer/Preferences/ocroptions.hh @@ -0,0 +1,49 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef OCR_OPTIONS_HH +# define OCR_OPTIONS_HH + +//#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> + +#include "optionwidget.hh" +#include "configs.hh" +#include "region.hh" + +namespace Ui +{ + class OcrOptions; +} + +class OcrOptions : + public OptionWidget +{ + Q_OBJECT + + public: + explicit OcrOptions(QWidget *parent = 0); + ~OcrOptions(); + + void loadConfig(); + void saveConfig(); + + private: + int findIndex(const QString& lang); + + Ui::OcrOptions *ui; +}; + +#endif // OCR_OPTIONS_HH diff --git a/GScribo/Preferences/ocroptions.ui b/scribo/demo/viewer/Preferences/ocroptions.ui similarity index 100% rename from GScribo/Preferences/ocroptions.ui rename to scribo/demo/viewer/Preferences/ocroptions.ui diff --git a/GScribo/Preferences/optionwidget.h b/scribo/demo/viewer/Preferences/optionwidget.hh similarity index 100% rename from GScribo/Preferences/optionwidget.h rename to scribo/demo/viewer/Preferences/optionwidget.hh diff --git a/scribo/demo/viewer/Preferences/preferencesdialog.cc b/scribo/demo/viewer/Preferences/preferencesdialog.cc new file mode 100644 index 0000000..ee6feda --- /dev/null +++ b/scribo/demo/viewer/Preferences/preferencesdialog.cc @@ -0,0 +1,120 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "preferencesdialog.hh" +#include "Preferences/preferencesdialog.ui.h" + +PreferencesDialog::PreferencesDialog(QWidget *parent) : + QDialog(parent, Qt::Dialog), + ui(new Ui::PreferencesDialog) +{ + ui->setupUi(this); + + // We may want to remove this useless object in the ui file. + delete ui->widget; + + connect(ui->optionList, SIGNAL(currentRowChanged(int)), this, SLOT(onOptionListCurrentRowChanged(int))); + setAttribute(Qt::WA_DeleteOnClose); + + loadOptionList(); + ui->optionList->setCurrentRow(0); +} + +PreferencesDialog::~PreferencesDialog() +{ + delete ui; +} + +void PreferencesDialog::loadOptionList() +{ + static const char *options[] = { "General", "Preprocessing", "Segmentation", "OCR", 0 }; + + int i; + for (i = 0; options[i]; ++i) + ui->optionList->insertItem(i, options[i]); + + widgets.fill(0, i); +} + +void PreferencesDialog::selectOptionWidget(int row) +{ + if(!widgets[row]) + { + QWidget *widget = 0; + + switch(row) + { + case 0: + widget = new GeneralOptions(this); + break; + + case 1: + widget = new PreprocessingOptions(this); + break; + + case 2: + widget = new SegmentationOptions(this); + break; + + case 3: + widget = new OcrOptions(this); + break; + } + + if(widget) + widgets[row] = widget; + } + + if(ui->horizontalLayout_2->count() == 2) + { + QWidget *current_widget = ui->horizontalLayout_2->itemAt(1)->widget(); + ui->horizontalLayout_2->removeWidget(current_widget); + current_widget->hide(); + } + + ui->horizontalLayout_2->insertWidget(1, widgets[row]); + widgets[row]->show(); +} + + +void PreferencesDialog::accept() +{ + for (int i = 0; i < widgets.size(); ++i) + { + if (widgets[i]) + { + static_cast<OptionWidget *>(widgets[i])->saveConfig(); + delete widgets[i]; + } + } + + QDialog::accept(); +} + + +void PreferencesDialog::reject() +{ + for (int i = 0; i < widgets.size(); ++i) + delete widgets[i]; + + QDialog::reject(); +} + + +void PreferencesDialog::onOptionListCurrentRowChanged(int row) +{ + selectOptionWidget(row); +} diff --git a/scribo/demo/viewer/Preferences/preferencesdialog.hh b/scribo/demo/viewer/Preferences/preferencesdialog.hh new file mode 100644 index 0000000..f867b26 --- /dev/null +++ b/scribo/demo/viewer/Preferences/preferencesdialog.hh @@ -0,0 +1,55 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PREFERENCESDIALOG_HH +# define PREFERENCESDIALOG_HH + +#include <QDialog> + +#include "preprocessingoptions.hh" +#include "segmentationoptions.hh" +#include "generaloptions.hh" +#include "ocroptions.hh" + +namespace Ui +{ + class PreferencesDialog; +} + +class PreferencesDialog : + public QDialog +{ + Q_OBJECT + + public: + explicit PreferencesDialog(QWidget *parent = 0); + ~PreferencesDialog(); + + private: + void loadOptionList(); + void selectOptionWidget(int row); + + Ui::PreferencesDialog *ui; + QVector<QWidget *> widgets; + + private slots: + void onOptionListCurrentRowChanged(int row); + virtual void accept(); + virtual void reject(); + +}; + +#endif // PREFERENCESDIALOG_HH diff --git a/GScribo/Preferences/preferencesdialog.ui b/scribo/demo/viewer/Preferences/preferencesdialog.ui similarity index 100% rename from GScribo/Preferences/preferencesdialog.ui rename to scribo/demo/viewer/Preferences/preferencesdialog.ui diff --git a/scribo/demo/viewer/Preferences/preprocessingoptions.cc b/scribo/demo/viewer/Preferences/preprocessingoptions.cc new file mode 100644 index 0000000..23d2538 --- /dev/null +++ b/scribo/demo/viewer/Preferences/preprocessingoptions.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "preprocessingoptions.hh" +#include "Preferences/preprocessingoptions.ui.h" + +using namespace scribo::toolchain::internal; + +PreprocessingOptions::PreprocessingOptions(QWidget *parent) : + OptionWidget(parent), + ui(new Ui::PreprocessingOptions) +{ + ui->setupUi(this); + + ui->bin_algoCbox->insertItem(Convert, "Violent convert"); + ui->bin_algoCbox->insertItem(Sauvola, "Local threshold"); + ui->bin_algoCbox->insertItem(SauvolaMs, "Local threshold multiscale"); + + loadConfig(); +} + +PreprocessingOptions::~PreprocessingOptions() +{ + delete ui; +} + +void PreprocessingOptions::loadConfig() +{ + Configs *const conf = Configs::getInstance(); + + ui->subsampleCb->setChecked(conf->preprocessingSubsample()); + ui->remove_bgCb->setChecked(conf->preprocessingRemoveBg()); + ui->deskewCb->setChecked(conf->preprocessingDeskew()); + ui->remove_noiseCb->setChecked(conf->preprocessingRemoveNoise()); + ui->bin_algoCbox->setCurrentIndex(conf->preprocessingBinAlgo()); +} + + +void PreprocessingOptions::saveConfig() +{ + Configs *const conf = Configs::getInstance(); + + conf->setPreprocessingSubsample(ui->subsampleCb->isChecked()); + conf->setPreprocessingRemoveBg(ui->remove_bgCb->isChecked()); + conf->setPreprocessingDeskew(ui->deskewCb->isChecked()); + conf->setPreprocessingRemoveNoise(ui->remove_noiseCb->isChecked()); + conf->setPreprocessingBinAlgo(ui->bin_algoCbox->currentIndex()); +} diff --git a/scribo/demo/viewer/Preferences/preprocessingoptions.hh b/scribo/demo/viewer/Preferences/preprocessingoptions.hh new file mode 100644 index 0000000..38645fa --- /dev/null +++ b/scribo/demo/viewer/Preferences/preprocessingoptions.hh @@ -0,0 +1,48 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PREPROCESSINGOPTIONS_HH +# define PREPROCESSINGOPTIONS_HH + +#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> + +#include "optionwidget.hh" +#include "region.hh" +#include "configs.hh" + +namespace Ui +{ + class PreprocessingOptions; +} + +class PreprocessingOptions : + public OptionWidget +{ + Q_OBJECT + + public: + explicit PreprocessingOptions(QWidget *parent = 0); + ~PreprocessingOptions(); + + void loadConfig(); + void saveConfig(); + + private: + Ui::PreprocessingOptions *ui; + +}; + +#endif // PREPROCESSINGOPTIONS_HH diff --git a/GScribo/Preferences/preprocessingoptions.ui b/scribo/demo/viewer/Preferences/preprocessingoptions.ui similarity index 100% rename from GScribo/Preferences/preprocessingoptions.ui rename to scribo/demo/viewer/Preferences/preprocessingoptions.ui diff --git a/scribo/demo/viewer/Preferences/segmentationoptions.cc b/scribo/demo/viewer/Preferences/segmentationoptions.cc new file mode 100644 index 0000000..867aa9a --- /dev/null +++ b/scribo/demo/viewer/Preferences/segmentationoptions.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "segmentationoptions.hh" +#include "Preferences/segmentationoptions.ui.h" + +SegmentationOptions::SegmentationOptions(QWidget *parent) : + OptionWidget(parent), + ui(new Ui::SegmentationOptions) +{ + ui->setupUi(this); + + ui->find_sepsCbox->insertItem(Separator::Lines, "Lines"); + ui->find_sepsCbox->insertItem(Separator::Whitespaces, "Whitespaces"); + ui->find_sepsCbox->insertItem(Separator::Both, "Lines and whitespaces"); + + loadConfig(); +} + +SegmentationOptions::~SegmentationOptions() +{ + delete ui; +} + +void SegmentationOptions::loadConfig() +{ + Configs *const conf = Configs::getInstance(); + ui->find_sepsCbox->setCurrentIndex(conf->segmentationFindSeps()); +} + + +void SegmentationOptions::saveConfig() +{ + Configs *const conf = Configs::getInstance(); + conf->setSegmentationFindSeps(ui->find_sepsCbox->currentIndex()); +} diff --git a/scribo/demo/viewer/Preferences/segmentationoptions.hh b/scribo/demo/viewer/Preferences/segmentationoptions.hh new file mode 100644 index 0000000..4ad282a --- /dev/null +++ b/scribo/demo/viewer/Preferences/segmentationoptions.hh @@ -0,0 +1,46 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef SEGMENTATIONOPTIONS_HH +# define SEGMENTATIONOPTIONS_HH + + +#include "optionwidget.hh" +#include "configs.hh" +#include "region.hh" + +namespace Ui +{ + class SegmentationOptions; +} + +class SegmentationOptions : + public OptionWidget +{ + Q_OBJECT + + public: + explicit SegmentationOptions(QWidget *parent = 0); + ~SegmentationOptions(); + + void loadConfig(); + void saveConfig(); + + private: + Ui::SegmentationOptions *ui; +}; + +#endif // SEGMENTATIONOPTIONS_HH diff --git a/GScribo/Preferences/segmentationoptions.ui b/scribo/demo/viewer/Preferences/segmentationoptions.ui similarity index 100% rename from GScribo/Preferences/segmentationoptions.ui rename to scribo/demo/viewer/Preferences/segmentationoptions.ui diff --git a/scribo/demo/viewer/Processing/preprocess.cc b/scribo/demo/viewer/Processing/preprocess.cc new file mode 100644 index 0000000..c913c60 --- /dev/null +++ b/scribo/demo/viewer/Processing/preprocess.cc @@ -0,0 +1,27 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "preprocess.hh" + +void Preprocess::on_progress() +{ + emit progress(); +} + +void Preprocess::on_new_progress_label(const char *label) +{ + emit newProgressLabel(QString(label)); +} diff --git a/scribo/demo/viewer/Processing/preprocess.hh b/scribo/demo/viewer/Processing/preprocess.hh new file mode 100644 index 0000000..457efde --- /dev/null +++ b/scribo/demo/viewer/Processing/preprocess.hh @@ -0,0 +1,42 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PREPROCESS_H +# define PREPROCESS_H + +#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> +#include <mln/core/image/image2d.hh> +#include <mln/value/rgb8.hh> +#include <QObject> + +using namespace scribo::toolchain::internal; + +class Preprocess : + public QObject, + public text_in_doc_preprocess_functor<mln::image2dmln::value::rgb8 > +{ + Q_OBJECT + + public: + virtual void on_progress(); + virtual void on_new_progress_label(const char *label); + + signals: + void newProgressLabel(const QString& label); + void progress(); +}; + +#endif // PREPROCESS_H diff --git a/scribo/demo/viewer/Processing/process.cc b/scribo/demo/viewer/Processing/process.cc new file mode 100644 index 0000000..0fb54a6 --- /dev/null +++ b/scribo/demo/viewer/Processing/process.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "process.hh" + +Process::Process(const char *doc_filename) + : superT(doc_filename) +{ +} + +void Process::on_progress() +{ + emit progress(); +} + +void Process::on_new_progress_label(const char *label) +{ + emit newProgressLabel(QString(label)); +} + +void Process::on_xml_saved() +{ + emit xmlSaved(QString(output_file.c_str())); +} diff --git a/scribo/demo/viewer/Processing/process.hh b/scribo/demo/viewer/Processing/process.hh new file mode 100644 index 0000000..fc3809c --- /dev/null +++ b/scribo/demo/viewer/Processing/process.hh @@ -0,0 +1,45 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PROCESS_H +# define PROCESS_H + +#include <scribo/toolchain/internal/content_in_doc_functor.hh> +#include <mln/core/image/image2d.hh> +#include <QObject> + +using namespace scribo::toolchain::internal; + +struct Process : + public QObject, + public content_in_doc_functor<mln::image2d<bool> > +{ + Q_OBJECT + typedef content_in_doc_functor<mln::image2d<bool> > superT; + + public : + explicit Process(const char *docFilename); + virtual void on_progress(); + virtual void on_new_progress_label(const char *label); + virtual void on_xml_saved(); + + signals: + void newProgressLabel(const QString& label); + void progress(); + void xmlSaved(const QString& filename); +}; + +#endif // PROCESS_H diff --git a/scribo/demo/viewer/Processing/progressdialog.cc b/scribo/demo/viewer/Processing/progressdialog.cc new file mode 100644 index 0000000..beda013 --- /dev/null +++ b/scribo/demo/viewer/Processing/progressdialog.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "progressdialog.hh" + +ProgressDialog::ProgressDialog(QWidget *parent): + QProgressDialog(parent, Qt::Dialog) +{ + setAutoClose(false); + setCancelButton(0); + hide(); +} + +void ProgressDialog::reset() +{ + setValue(0); + setLabelText("Initilization"); + show(); +} + +void ProgressDialog::run() +{ + setValue(value()+1); +} diff --git a/scribo/demo/viewer/Processing/progressdialog.hh b/scribo/demo/viewer/Processing/progressdialog.hh new file mode 100644 index 0000000..fe2ea0f --- /dev/null +++ b/scribo/demo/viewer/Processing/progressdialog.hh @@ -0,0 +1,36 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef PROGRESSDIALOG_H +#define PROGRESSDIALOG_H + +#include <QProgressDialog> + +class ProgressDialog : + public QProgressDialog +{ + Q_OBJECT + + public: + explicit ProgressDialog(QWidget *parent = 0); + void reset(); + + public slots: + void run(); +}; + + +#endif // PROGRESSDIALOG_H diff --git a/scribo/demo/viewer/Processing/runner.cc b/scribo/demo/viewer/Processing/runner.cc new file mode 100644 index 0000000..a52c6eb --- /dev/null +++ b/scribo/demo/viewer/Processing/runner.cc @@ -0,0 +1,199 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "runner.hh" + +using namespace mln; +using namespace scribo::toolchain::internal; + +static QString get_pathto(const QString& file, const QString localdirsuffix = QString()) +{ + QFile f(SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix + "/" + file); + if (f.exists()) + return SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix; + f.setFileName(SCRIBO_PREFIX_BINDIR "/" + file); + if (f.exists()) + return SCRIBO_PREFIX_BINDIR; + + return ""; +} + +Runner::Runner(QObject *parent) : + QThread(parent) +{ + moveToThread(this); +} + +void Runner::run() +{ + if(mode_ == Demat) + { + image2dvalue::rgb8 ima; + for(int i = 0; i < args_.count(); i++) + { + io::magick::load(ima, args_.at(i).toUtf8().constData()); + image2d<bool> bin_ima = preprocess(ima); + process(ima, bin_ima, i); + } + } + + else if(mode_ == Export) + export_as(); + + emit finished(); +} + +void Runner::stop() +{ + terminate(); +} + +// Demat related stuff +void Runner::start_demat(const QStringList& filenames) +{ + args_.clear(); + args_ = filenames; + mode_ = Demat; + QThread::start(); +} + + +image2d<bool> Runner::preprocess(const image2dvalue::rgb8& ima) +{ + emit new_step("Preprocessing"); + Preprocess f; + + // Load config. + Configs *const conf = Configs::getInstance(); + + connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); + connect(&f, SIGNAL(newProgressLabel(QString)), + this, SIGNAL(new_progress_label(const QString&))); + + f.enable_subsample = conf->preprocessingSubsample(); + f.enable_fg_extraction = conf->preprocessingRemoveBg(); + f.enable_deskew = conf->preprocessingDeskew(); + f.enable_denoising = conf->preprocessingRemoveNoise(); + + f.binarization_algo = static_cast<Binarization_Algo>(conf->preprocessingBinAlgo()); + + emit new_progress_max_value(f.nsteps()); + + // Perform preprocessing. + f(ima); + + return f.output; +} + + +void Runner::process(const image2dvalue::rgb8& original_ima, + const image2d<bool>& processed_ima, int arg) +{ + emit new_step("Page segmentation"); + + Process f(args_.at(arg).toUtf8().constData()); + + connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); + connect(&f, SIGNAL(newProgressLabel(QString)), + this, SIGNAL(new_progress_label(QString))); + connect(&f, SIGNAL(xmlSaved(QString)), + this, SIGNAL(xml_saved(const QString&))); + + // Load config. + Configs *const conf = Configs::getInstance(); + + Separator::FindSeparator find_seps = static_castSeparator::FindSeparator(conf->segmentationFindSeps()); + f.enable_line_seps = (find_seps == Separator::Lines + || find_seps == Separator::Both); + f.enable_whitespace_seps = (find_seps == Separator::Whitespaces + || find_seps == Separator::Both); + f.enable_ocr = conf->ocrEnabled(); + f.ocr_language = conf->ocrLanguage().toAscii().data(); + f.xml_format = scribo::io::xml::PageExtended; + + + f.save_doc_as_xml = true; + QFileInfo file(args_.at(arg)); + QString output_dir = QDir::tempPath(); + if (conf->generalSaveXmlEnabled()) + { + if (conf->generalSaveXmlSameDir()) + output_dir = file.absolutePath(); + else if (conf->generalSaveXmlCustomDir()) + output_dir = conf->generalSaveXmlCustomDirPath(); + + QDir dir(output_dir); + if (!dir.exists() && !dir.mkpath(output_dir)) + output_dir = QDir::tempPath(); + } + QString filename = (output_dir + "/" + file.baseName() + "_gui.xml"); + f.output_file = filename.toUtf8().constData(); + emit new_progress_max_value(f.nsteps()); + + // Perform text detection. + f(original_ima, processed_ima); +} + +// Export related stuff +void Runner::start_export(const QString& imgfile, + const QString& xmlfile, const QString& outfile) +{ + args_.clear(); + args_ << imgfile << xmlfile << outfile; + mode_ = Export; + + QThread::start(); +} + +void Runner::export_as() +{ + emit new_step("Exporting document"); + emit new_progress_max_value(2); + + // Checking output format + QFileInfo f(args_.at(2)); + + QString pathto_xml2doc = get_pathto("scribo-xml2doc", "xml2doc"); + + if (pathto_xml2doc.isEmpty()) + { + QMessageBox::critical(0, "Fatal error", "Cannot export! Cannot find scribo-xml2doc program!"); + return; + } + + emit progress(); + + int rvalue = 0; + if (f.suffix() == "pdf") + { + emit new_step("Exporting as PDF"); + rvalue = system(QString("%1/scribo-xml2doc --pdf %2 %3 %4") + .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) + .arg(args_.at(2)).toAscii().constData()); + } + else if (f.suffix() == "html" || f.suffix() == "htm") + { + emit new_step("Exporting as HTML"); + rvalue = system(QString("%1/scribo-xml2doc --html %2 %3 %4") + .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) + .arg(args_.at(2)).toAscii().constData()); + } + else + QMessageBox::critical(0, "Fatal error", "Cannot export! Invalid output format!"); + + if (rvalue != 0) + QMessageBox::critical(0, "Fatal error", "Cannot export! Return value is not 0!"); +} diff --git a/scribo/demo/viewer/Processing/runner.hh b/scribo/demo/viewer/Processing/runner.hh new file mode 100644 index 0000000..ab0fb79 --- /dev/null +++ b/scribo/demo/viewer/Processing/runner.hh @@ -0,0 +1,74 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef RUNNER_H +# define RUNNER_H + +#include <mln/core/image/image2d.hh> +#include <mln/io/magick/load.hh> +#include <mln/value/rgb8.hh> +#include <QStringList> +#include <QMessageBox> +#include <QThread> +#include <QFile> + +#include "preprocess.hh" +#include "process.hh" +#include "configs.hh" +#include "region.hh" +#include "dir.hh" + +using namespace mln; + +enum RunMode +{ + Demat, + Export +}; + +class Runner : + public QThread +{ + Q_OBJECT + + public: + explicit Runner(QObject *parent = 0); + void start_demat(const QStringList& filenames); + void start_export(const QString& imgfile, const QString& xmlfile, const QString& outfile); + + private: + image2d<bool> preprocess(const image2dvalue::rgb8& ima); + void process(const image2dvalue::rgb8& original_ima, const image2d<bool>& processed_ima, int arg); + void export_as(); + virtual void run(); + template <typename V> unsigned find_best_scale(const mln::image2d<V>& ima); + + QStringList args_; + RunMode mode_; + + public slots: + void stop(); + + signals: + void new_step(const QString& step_name); + void new_progress_max_value(int i); + void new_progress_label(const QString& msg); + void xml_saved(const QString& filename); + void progress(); + void finished(); +}; + +#endif // RUNNER_H diff --git a/scribo/demo/viewer/README b/scribo/demo/viewer/README deleted file mode 100644 index 31c66aa..0000000 --- a/scribo/demo/viewer/README +++ /dev/null @@ -1,32 +0,0 @@ -Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) - -This file is part of Olena. - -Olena is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation, version 2 of the License. - -Olena is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Olena. If not, see http:www.gnu.org/licenses/. - -__________________________________________________________________ - - -Document Layout Viewer - -Purpose: -- Display layout information about image documents. - -Usage: -- Get XML layout descriptions (PAGE format, ICDAR2009). -- Put XML and image files in the same directory, with the same name. -- Select an image within the application. -- Click on regions to display their attributes. - -Infos: -- Everything is read-only. diff --git a/GScribo/Rendering/abstractregionitem.h b/scribo/demo/viewer/Rendering/abstractregionitem.hh similarity index 100% rename from GScribo/Rendering/abstractregionitem.h rename to scribo/demo/viewer/Rendering/abstractregionitem.hh diff --git a/GScribo/Rendering/backgroundtexture.h b/scribo/demo/viewer/Rendering/backgroundtexture.hh similarity index 100% rename from GScribo/Rendering/backgroundtexture.h rename to scribo/demo/viewer/Rendering/backgroundtexture.hh diff --git a/scribo/demo/viewer/Rendering/graphicsview.cc b/scribo/demo/viewer/Rendering/graphicsview.cc new file mode 100644 index 0000000..10ac034 --- /dev/null +++ b/scribo/demo/viewer/Rendering/graphicsview.cc @@ -0,0 +1,165 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "graphicsview.hh" + +GraphicsView::GraphicsView(QWidget *parent) : + QGraphicsView(parent) +{ + init(); +} + +GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) : + QGraphicsView(scene, parent) +{ + init(); +} + +void GraphicsView::init() +{ + isRightClicking_ = false; + scaleRatio_ = QSizeF(1, 1); + setTransformationAnchor(GraphicsView::AnchorUnderMouse); + setBackgroundBrush(QBrush(Qt::lightGray)); + + // Important to hide scroll bars : when they appear, it triggers the resizeEvent. + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +} + +void GraphicsView::mousePressEvent(QMouseEvent *event) +{ + if(event->button() == Qt::RightButton) + { + emit beginDrag(); + setDragMode(QGraphicsView::ScrollHandDrag); + } + + QMouseEvent *mouseEvent = new QMouseEvent(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, + Qt::LeftButton, Qt::MetaModifier); + event->ignore(); + QGraphicsView::mousePressEvent(mouseEvent); +} + +void GraphicsView::mouseReleaseEvent(QMouseEvent *event) +{ + if(event->button() == Qt::RightButton) + { + setDragMode(GraphicsView::NoDrag); + emit endDrag(); + } + + QGraphicsView::mouseReleaseEvent(event); +} + +void GraphicsView::wheelEvent(QWheelEvent *event) +{ + if(event->modifiers() & Qt::ControlModifier) + { + // Current wheel have an angle of 15 degrees by steps with a delta of + or - 120. A good scale is +- 0.1 in that case. + // So we have to adapt for wheel whith better precision. + qreal degrees = 1 + static_cast<qreal>(event->delta()) / 1200; + qreal nextScaleRatio = degrees * isWidthGreater_ ? scaleRatio_.width() : + scaleRatio_.height(); + if(event->delta() > 0) + { + if(nextScaleRatio <= 20) + { + scaleRatio_ *= degrees; + scale(degrees, degrees); + } + } + else + { + if(nextScaleRatio >= 1.1) + { + scaleRatio_ *= degrees; + scale(degrees, degrees); + } + else if(isContainedInView_) + { + QGraphicsView::fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); + scaleRatio_ = QSizeF(1, 1); + } + } + } + else + QGraphicsView::wheelEvent(event); +} + +void GraphicsView::keyPressEvent(QKeyEvent* event) +{ + // Bitwise AND to check if at least CTRL is pushed. + if(event->modifiers() & Qt::ControlModifier) + { + qreal nextScaleRatio; + if(event->key() == Qt::Key_Plus) + { + nextScaleRatio = 1.2 * isWidthGreater_ ? scaleRatio_.width() : + scaleRatio_.height(); + if(nextScaleRatio <= 19) + { + scaleRatio_ *= 1.2; + scale(1.2, 1.2); + } + } + else if(event->key() == Qt::Key_Minus) + { + nextScaleRatio = 0.8 * isWidthGreater_ ? scaleRatio_.width() : + scaleRatio_.height(); + if(nextScaleRatio >= 1.2) + { + scaleRatio_ *= 0.8; + scale(0.8, 0.8); + } + else if(isContainedInView_) + { + QGraphicsView::fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); + scaleRatio_ = QSizeF(1, 1); + } + } + } + + QGraphicsView::keyPressEvent(event); +} + +void GraphicsView::fitInView(const QRectF& rect) +{ + setFocus(); + isWidthGreater_ = static_cast<qreal>(rect.width()) / static_cast<qreal>(rect.height()) > 1 ? true : + false; + qreal ratio = isWidthGreater_ ? static_cast<qreal>(width()) / static_cast<qreal>(rect.width()) : + static_cast<qreal>(height()) / static_cast<qreal>(rect.height()); + + isContainedInView_ = ratio < 1 ? true : false; + if(isContainedInView_) + { + scaleRatio_ = QSizeF(1, 1); + QGraphicsView::fitInView(rect, Qt::KeepAspectRatio); + } +} + +void GraphicsView::resizeEvent(QResizeEvent *event) +{ + if(scene()->items().count() > 1) + { + qreal ratio = isWidthGreater_ ? static_cast<qreal>(event->size().width()) / static_cast<qreal>(event->oldSize().width()) : + static_cast<qreal>(event->size().height()) / static_cast<qreal>(event->oldSize().height()); + scale(ratio, ratio); + } + + QGraphicsView::resizeEvent(event); +} diff --git a/scribo/demo/viewer/Rendering/graphicsview.hh b/scribo/demo/viewer/Rendering/graphicsview.hh new file mode 100644 index 0000000..86e1786 --- /dev/null +++ b/scribo/demo/viewer/Rendering/graphicsview.hh @@ -0,0 +1,59 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef GRAPHICSVIEW_HH +# define GRAPHICSVIEW_HH + +#include <QGraphicsView> +#include <QWheelEvent> +#include <QScrollBar> + +class GraphicsView : + public QGraphicsView +{ + Q_OBJECT + + public: + explicit GraphicsView(QWidget *parent = 0); + explicit GraphicsView(QGraphicsScene *scene, QWidget *parent = 0); + + protected: + void init(); + + void resizeEvent(QResizeEvent *event); + + void wheelEvent(QWheelEvent *event); + void keyPressEvent(QKeyEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + + private: + bool isWidthGreater_; + bool isContainedInView_; + QSizeF scaleRatio_; + + bool isRightClicking_; + QPointF prevMousePos_; + + public slots: + void fitInView(const QRectF& rect); + + signals: + void beginDrag(); + void endDrag(); +}; + +#endif // GRAPHICSVIEW_HH diff --git a/scribo/demo/viewer/Rendering/regionitem.cc b/scribo/demo/viewer/Rendering/regionitem.cc new file mode 100644 index 0000000..d845413 --- /dev/null +++ b/scribo/demo/viewer/Rendering/regionitem.cc @@ -0,0 +1,130 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "Rendering/regionitem.hh" + +RegionItem::RegionItem(QGraphicsItem *parent, QGraphicsScene *scene) + : QGraphicsPolygonItem(parent, scene) +{ + init(); +} + +RegionItem::RegionItem(const QPolygonF& polygon, QGraphicsItem *parent, QGraphicsScene *scene): + QGraphicsPolygonItem(polygon, parent, scene) +{ + init(); +} + +void RegionItem::init() +{ + xmlItem_ = 0; + + selectedPen_.setStyle(Qt::SolidLine); + unselectedPen_.setStyle(Qt::SolidLine); + + selectedPen_.setWidthF(2); + unselectedPen_.setWidth(0); + + selectedPen_.setCapStyle(Qt::SquareCap); + unselectedPen_.setCapStyle(Qt::SquareCap); + + selectedBrush_.setStyle(Qt::SolidPattern); + unselectedBrush_.setStyle(Qt::SolidPattern); +} + +void RegionItem::setColor(const QColor& color) +{ + selectedPen_.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 255)); + unselectedPen_.setColor(color); + + selectedBrush_.setColor(color); + unselectedBrush_.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 40)); + + setPen(unselectedPen_); + setBrush(unselectedBrush_); +} + +void RegionItem::setSelected(bool isSelected) +{ + if(isSelected) + { + isSelected_ = true; + setPen(selectedPen_); + setBrush(selectedBrush_); + } + + else + { + isSelected_ = false; + setPen(unselectedPen_); + setBrush(unselectedBrush_); + } +} + + +void RegionItem::setXmlItem(XmlItem *xmlItem) +{ + xmlItem_ = xmlItem; +} + +XmlItem *RegionItem::xmlItem() const +{ + return xmlItem_; +} + +QColor RegionItem::color() const +{ + return selectedBrush_.color(); +} + +int RegionItem::region() const +{ + return region_; +} + +bool RegionItem::isSelected() +{ + return isSelected_; +} + +void RegionItem::select() +{ + setSelected(true); +} + +void RegionItem::unselect() +{ + setSelected(false); +} + +void RegionItem::loadData(const GraphicsRegion::Data& data) +{ + region_ = data.region; setColor(data.color); setZValue(data.zValue); +} + +bool RegionItem::contains(const QPointF& point) +{ + return (boundingRect().width() * boundingRect().height() == 0 + || boundingRect().contains(point)) + && shape().contains(point); +} + +bool RegionItem::intersects(const QRectF& rect) +{ + return (boundingRect().width() * boundingRect().height() == 0 + || boundingRect().intersects(rect)) + && shape().intersects(rect); +} diff --git a/scribo/demo/viewer/Rendering/regionitem.hh b/scribo/demo/viewer/Rendering/regionitem.hh new file mode 100644 index 0000000..3fe03a7 --- /dev/null +++ b/scribo/demo/viewer/Rendering/regionitem.hh @@ -0,0 +1,66 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef RegionITEM_HH +# define RegionITEM_HH + +#include <QGraphicsPolygonItem> +#include <QTreeWidgetItem> +#include <QPen> + +#include "variantpointer.hh" +#include "region.hh" + +class XmlItem; + +class RegionItem : + public QGraphicsPolygonItem +{ + public: + explicit RegionItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); + explicit RegionItem(const QPolygonF& path, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); + + void setColor(const QColor& color); + QColor color() const; + + void setXmlItem(XmlItem *xmlItem); + XmlItem *xmlItem() const; + + void loadData(const GraphicsRegion::Data& data); + int region() const; + + bool intersects(const QRectF& rect); + bool contains(const QPointF& point); + + void setSelected(bool isSelected); + bool isSelected(); + void unselect(); + void select(); + + private: + void init(); + + XmlItem *xmlItem_; + int region_; + bool isSelected_; + + QPen selectedPen_; + QPen unselectedPen_; + QBrush selectedBrush_; + QBrush unselectedBrush_; +}; + +#endif // RegionITEM_HH diff --git a/scribo/demo/viewer/Rendering/rootgraphicsitem.cc b/scribo/demo/viewer/Rendering/rootgraphicsitem.cc new file mode 100644 index 0000000..166a186 --- /dev/null +++ b/scribo/demo/viewer/Rendering/rootgraphicsitem.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "Rendering/rootgraphicsitem.hh" + +RootGraphicsItem::RootGraphicsItem(int numberRegion) +{ + childsFromRegion_.fill(QList<QGraphicsItem *>(), numberRegion); +} + +RootGraphicsItem::~RootGraphicsItem() +{ + foreach(QList<QGraphicsItem *> list, childsFromRegion_) + { + foreach(QGraphicsItem *child, list) + { + delete child; + } + } +} + +QList<QGraphicsItem *> +RootGraphicsItem::childsFrom(const GraphicsRegion::Id& region) const +{ + return childsFromRegion_[region]; +} + +void +RootGraphicsItem::addItemFrom(QGraphicsItem *graphicalItem, + const GraphicsRegion::Id& region) +{ + childsFromRegion_[region] << graphicalItem; +} diff --git a/scribo/demo/viewer/Rendering/rootgraphicsitem.hh b/scribo/demo/viewer/Rendering/rootgraphicsitem.hh new file mode 100644 index 0000000..fe7f5a2 --- /dev/null +++ b/scribo/demo/viewer/Rendering/rootgraphicsitem.hh @@ -0,0 +1,39 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef ROOTGRAPHICSITEM_HH +# define ROOTGRAPHICSITEM_HH + +#include <QGraphicsItem> + +#include "region.hh" + +class RootGraphicsItem : + public QGraphicsPolygonItem +{ +public: + explicit RootGraphicsItem(int numberRegion); + ~RootGraphicsItem(); + + + void addItemFrom(QGraphicsItem *graphicalItem, const GraphicsRegion::Id& region); + QList<QGraphicsItem *> childsFrom(const GraphicsRegion::Id& region) const; + +private: + QVector<QList<QGraphicsItem *> > childsFromRegion_; +}; + +#endif // ROOTGRAPHICSITEM_HH diff --git a/scribo/demo/viewer/Rendering/scene.cc b/scribo/demo/viewer/Rendering/scene.cc new file mode 100644 index 0000000..a036ed2 --- /dev/null +++ b/scribo/demo/viewer/Rendering/scene.cc @@ -0,0 +1,289 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "scene.hh" + +Scene::Scene(QObject *parent): + QGraphicsScene(parent) +{ + init(); +} + +Scene::Scene(const QRectF &sceneRect, QObject *parent): + QGraphicsScene(sceneRect, parent) +{ + init(); +} + +Scene::Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent): + QGraphicsScene(x, y, width, height, parent) +{ + init(); +} + +void Scene::init() +{ + isPressing_ = false; + isSelectionDisabled_ = false; + backgroundPixmap_ = 0; + root_ = 0; + + selection_.hide(); + addItem(&selection_); +} + +void Scene::clearAll() +{ + if(root_) + delete root_; + + if(backgroundPixmap_) + delete backgroundPixmap_; + + selectedRegions_.clear(); + backgroundPath_ = QString(); + backgroundPixmap_ = 0; + root_ = 0; +} + +void Scene::clearRegions() +{ + if(root_) + delete root_; + + selectedRegions_.clear(); + root_ = 0; +} + +void Scene::clearSelection() +{ + QGraphicsItem *child; + RegionItem *regionItem; + + // Unselect all items. + foreach(child, selectedRegions_) + { + regionItem = static_cast<RegionItem *>(child); + regionItem->unselect(); + } + + selectedRegions_.clear(); + emit selectionCleared(); +} + +void Scene::selectAll() +{ + RegionItem *item; + foreach(QGraphicsItem *child, root_->childItems()) + { + item = static_cast<RegionItem *>(child); + item->select(); + selectedRegions_ << item; + } +} + +void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if(!backgroundPath_.isEmpty() && event->button() == Qt::LeftButton && !isSelectionDisabled_) + { + isPressing_ = true; + + baseSelection_.clear(); + pressPos_ = event->scenePos(); + selection_.show(); + } +} + +void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if(isPressing_) + { + // 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); + else + selection_.setRect(event->scenePos().x(), 0, pressPos_.x()-event->scenePos().x(), 0); + + if(pressPos_.y() < event->scenePos().y()) + selection_.setRect(selection_.rect().x(), pressPos_.y(), selection_.rect().width(), event->scenePos().y()-pressPos_.y()); + else + selection_.setRect(selection_.rect().x(), event->scenePos().y(), selection_.rect().width(), pressPos_.y()-event->scenePos().y()); + } +} + +void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if(event->button() == Qt::LeftButton) + { + isPressing_ = false; + + // Redraw all items in selection. + if(root_) + { + clearSelection(); + + // Check if it is a click. + if(selection_.rect().width() * selection_.rect().height() == 0) + select(event->scenePos()); + else + select(selection_.rect()); + + baseSelection_ = selectedRegions(); + emit newSelection(selectedRegions_); + } + + selection_.setRect(QRect()); + selection_.hide(); + } +} + +void Scene::select(QGraphicsItem *root, const QPointF& point, const QRectF& rect) +{ + QGraphicsItem *child; + RegionItem *regionItem; + + // Check if it is a click. + if(!point.isNull()) + { + foreach(child, root->childItems()) + { + regionItem = static_cast<RegionItem *>(child); + + if(regionItem->contains(point)) + { + regionItem->select(); + selectedRegions_ << regionItem; + } + } + } + else + { + foreach(child, root->childItems()) + { + regionItem = static_cast<RegionItem *>(child); + + if(regionItem->intersects(rect)) + { + regionItem->select(); + selectedRegions_ << regionItem; + } + } + } + + emit newSelection(); +} + +void Scene::select(const QList<RegionItem *>& selectedRegions) +{ + RegionItem *child; + foreach(child, selectedRegions) + { + if(!child->isSelected()) + { + child->select(); + selectedRegions_ << child; + } + } + + ensureVisible(selectedRegions_.last()); + emit newSelection(); +} + +void Scene::unselect(const QList<RegionItem *>& unselectedRegions) +{ + RegionItem *child; + foreach(child, unselectedRegions) + { + if(child->isSelected()) + { + child->unselect(); + selectedRegions_.removeOne(child); + } + } + + // Check if after the removal, the selected list isn't empty. + if(!selectedRegions_.isEmpty()) + ensureVisible(selectedRegions_.last()); + + emit newSelection(); +} + + +void Scene::ensureVisible(QGraphicsItem *graphicalItem) +{ + QGraphicsView *view; + foreach (view, views()) + view->ensureVisible(graphicalItem); +} + +void Scene::setVisible(const GraphicsRegion::Id& region, bool visible) +{ + if(root_) + { + QGraphicsItem *child; + + if(visible) + { + foreach(child, root_->childsFrom(region)) + child->setVisible(true); + } + + else + { + foreach(child, root_->childsFrom(region)) + child->setVisible(false); + } + } +} + +void Scene::setRoot(RootGraphicsItem *root) +{ + // Delete all items. + clearRegions(); + + root_ = root; + addItem(root); + + // Add typo lines separately because can't be selected. + QGraphicsItem *line; + foreach(line, root->childsFrom(GraphicsRegion::Baseline)) + addItem(line); + + foreach(line, root->childsFrom(GraphicsRegion::Meanline)) + addItem(line); +} + +void Scene::changeScene(const QString& filename, RootGraphicsItem *root) +{ + // Delete all items. + clearAll(); + backgroundPath_ = filename; + + if(!filename.isEmpty()) + { + QPixmap pixmap(filename); + setSceneRect(pixmap.rect()); + // Create the background item and dock it at the maximal depth of the scene. + backgroundPixmap_ = new QGraphicsPixmapItem(pixmap, 0, this); + backgroundPixmap_->setZValue(INT_MIN); + } + else + setSceneRect(QRectF()); + + // Add new items. + if(root) + setRoot(root); +} diff --git a/scribo/demo/viewer/Rendering/scene.hh b/scribo/demo/viewer/Rendering/scene.hh new file mode 100644 index 0000000..7d2771d --- /dev/null +++ b/scribo/demo/viewer/Rendering/scene.hh @@ -0,0 +1,118 @@ +#ifndef SCENE_H +#define SCENE_H + +#include <QGraphicsSceneMouseEvent> +#include <QGraphicsView> +#include <QGraphicsScene> +#include <QFileDialog> +#include <climits> + +#include "rootgraphicsitem.hh" +#include "regionitem.hh" +#include "selection.hh" + +class Scene : + public QGraphicsScene +{ + Q_OBJECT + + public: + explicit Scene(QObject *parent = 0); + explicit Scene(const QRectF &sceneRect, QObject *parent = 0); + explicit Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0); + + inline QString backgroundPath() const; + inline QGraphicsPixmapItem *backgroundPixmap() const; + + inline QList<RegionItem *> selectedRegions() const; + + void setRoot(RootGraphicsItem *rootItem); + inline RootGraphicsItem *root() const; + + void select(const QRectF& rect); + void select(const QPointF& point); + void selectAll(); + + inline bool selectionEnable() const; + inline void setSelectionEnable(bool enable); + + void changeScene(const QString& filename, RootGraphicsItem *root = 0); + + protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + + private: + void init(); + void select(QGraphicsItem *root, const QPointF& point, const QRectF& rect); + + QGraphicsView *mainView_; + RootGraphicsItem *root_; + + QString backgroundPath_; + QGraphicsPixmapItem *backgroundPixmap_; + + Selection selection_; + QList<RegionItem *> selectedRegions_; + QList<RegionItem *> baseSelection_; + + QPointF pressPos_; + bool isPressing_; + bool isSelectionDisabled_; + + public slots: + void clearAll(); + void clearRegions(); + void clearSelection(); + + void select(const QList<RegionItem *>& selectedRegions); + inline void selectBase(); + void unselect(const QList<RegionItem *>& unselectedItems); + + void setVisible(const GraphicsRegion::Id& region, bool visible); + void ensureVisible(QGraphicsItem *graphicsItem); + + inline void disableSelection(); + inline void enableSelection(); + + signals: + void selectionCleared(); + void newSelection(); + void newSelection(const QList<RegionItem *>& selectedRegions); +}; + +inline QString Scene::backgroundPath() const +{ return backgroundPath_; } + +inline QGraphicsPixmapItem *Scene::backgroundPixmap() const +{ return backgroundPixmap_; } + +inline RootGraphicsItem *Scene::root() const +{ return root_; } + +inline QList<RegionItem *> Scene::selectedRegions() const +{ return selectedRegions_; } + +inline void Scene::selectBase() +{ select(baseSelection_); } + +inline void Scene::select(const QPointF& point) +{ select(root_, point, QRectF()); } + +inline void Scene::select(const QRectF& rect) +{ select(root_, QPointF(), rect); } + +inline void Scene::setSelectionEnable(bool enable) +{ isSelectionDisabled_ = !enable; } + +inline bool Scene::selectionEnable() const +{ return isSelectionDisabled_; } + +inline void Scene::disableSelection() +{ setSelectionEnable(false); } + +inline void Scene::enableSelection() +{ setSelectionEnable(true); } + +#endif // SCENE_H diff --git a/scribo/demo/viewer/Rendering/selection.cc b/scribo/demo/viewer/Rendering/selection.cc new file mode 100644 index 0000000..89d2349 --- /dev/null +++ b/scribo/demo/viewer/Rendering/selection.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "selection.hh" + +Selection::Selection(QGraphicsScene *scene): + QGraphicsRectItem(0, scene) +{ + init(); +} + +Selection::Selection(const QRectF &rect, QGraphicsScene *scene): + QGraphicsRectItem(rect, 0, scene) +{ + init(); +} + +Selection::Selection(qreal x, qreal y, qreal width, qreal height, QGraphicsScene *scene): + QGraphicsRectItem(x, y, width, height, 0, scene) +{ + init(); +} + +void Selection::init() +{ + // Always drawn on top of the scene. + setZValue(INT_MAX); + + QPen pen; + pen.setStyle(Qt::SolidLine); + pen.setCapStyle(Qt::SquareCap); + pen.setCosmetic(true); + setPen(pen); + + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor(QColor::fromRgb(80, 200, 10, 60)); + setBrush(brush); +} diff --git a/GScribo/Rendering/selection.h b/scribo/demo/viewer/Rendering/selection.hh similarity index 100% rename from GScribo/Rendering/selection.h rename to scribo/demo/viewer/Rendering/selection.hh diff --git a/GScribo/TODO b/scribo/demo/viewer/TODO similarity index 100% rename from GScribo/TODO rename to scribo/demo/viewer/TODO diff --git a/scribo/demo/viewer/XmlWidget/attributesmodel.cc b/scribo/demo/viewer/XmlWidget/attributesmodel.cc new file mode 100644 index 0000000..d2e1cb0 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/attributesmodel.cc @@ -0,0 +1,108 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "attributesmodel.hh" + +AttributesModel::AttributesModel(const XmlAttributes& attributes, QObject *parent) : + QAbstractItemModel(parent) +{ + attributes_ = attributes; +} + +AttributesModel::AttributesModel(const XmlAttributes& attributes, QAbstractItemModelPrivate& dd, QObject *parent) : + QAbstractItemModel(dd, parent) +{ + attributes_ = attributes; +} + +QVariant AttributesModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section) + { + case 0: + return tr("Name"); + + case 1: + return tr("Value"); + + default: + return QVariant(); + } + } + + return QVariant(); +} + +QVariant AttributesModel::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + switch(role) + { + case Qt::UserRole: + return attributes_.names()[index.row()]; + + case Qt::UserRole+1: + return attributes_.values()[index.row()]; + + default: + return QVariant(); + } +} + +void AttributesModel::load(const XmlAttributes& attributes) +{ + beginResetModel(); + + attributes_ = attributes; + + endResetModel(); +} + +void AttributesModel::reset() +{ + beginResetModel(); + + attributes_ = XmlAttributes(); + + endResetModel(); +} + + +int AttributesModel::rowCount(const QModelIndex&) const +{ + return attributes_.names().count(); +} + +int AttributesModel::columnCount(const QModelIndex&) const +{ + return 2; +} + +QModelIndex AttributesModel::index(int row, int column, const QModelIndex& parent) const +{ + if(!hasIndex(row, column, parent)) + return QModelIndex(); + return createIndex(row, column, 0); +} + +QModelIndex AttributesModel::parent(const QModelIndex&) const +{ + return QModelIndex(); +} diff --git a/scribo/demo/viewer/XmlWidget/attributesmodel.hh b/scribo/demo/viewer/XmlWidget/attributesmodel.hh new file mode 100644 index 0000000..c99c993 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/attributesmodel.hh @@ -0,0 +1,55 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef ATTRIBUTESMODEL_HH +# define ATTRIBUTESMODEL_HH + +#include <QAbstractItemModel> + +#include "xmlattributes.hh" + +class AttributesModel : + public QAbstractItemModel +{ + Q_OBJECT + + public: + explicit AttributesModel(const XmlAttributes& attributes = XmlAttributes(), + QObject *parent = 0); + explicit AttributesModel(const XmlAttributes& attributes, + QAbstractItemModelPrivate& dd, + QObject *parent = 0); + + int rowCount(const QModelIndex& parent) const; + int columnCount(const QModelIndex& parent) const; + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex& index, int role) const; + + QModelIndex index(int row, int column, const QModelIndex &parent) const; + QModelIndex parent(const QModelIndex &child) const; + +public slots: + void reset(); + +private: + XmlAttributes attributes_; + +public slots: + void load(const XmlAttributes& attributes); +}; + +#endif // ATTRIBUTESMODEL_HH diff --git a/scribo/demo/viewer/XmlWidget/selectionproxy.hh b/scribo/demo/viewer/XmlWidget/selectionproxy.hh new file mode 100644 index 0000000..7817c72 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/selectionproxy.hh @@ -0,0 +1,47 @@ +#ifndef SELECTIONPROXY_H +#define SELECTIONPROXY_H + +#include <QSortFilterProxyModel> +#include <QDebug> + +#include "xmlitem.hh" + +class SelectionProxy : + public QSortFilterProxyModel +{ + public: + explicit SelectionProxy(QObject *parent = 0) : QSortFilterProxyModel(parent) { isAllDisplayed_ = true; } + + inline void displayAll(); + inline bool isAllDisplayed(); + + inline void beginResetModel(); + inline void endResetModel(); + inline void invalidateFilter(); + + protected: + inline bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const; + + private: + bool isAllDisplayed_; +}; + +inline bool SelectionProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const +{ return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent) && (isAllDisplayed_ || sourceModel()->index(sourceRow, 0, sourceParent).data(Qt::UserRole+2).value<XmlItem *>()->isVisible()); } + +inline void SelectionProxy::beginResetModel() +{ isAllDisplayed_ = false; QSortFilterProxyModel::beginResetModel(); } + +inline void SelectionProxy::endResetModel() +{ QSortFilterProxyModel::endResetModel(); } + +inline void SelectionProxy::displayAll() +{ isAllDisplayed_ = true; } + +inline bool SelectionProxy::isAllDisplayed() +{ return isAllDisplayed_; } + +inline void SelectionProxy::invalidateFilter() +{ QSortFilterProxyModel::invalidateFilter(); } + +#endif // SELECTIONPROXY_H diff --git a/scribo/demo/viewer/XmlWidget/xmlattributes.cc b/scribo/demo/viewer/XmlWidget/xmlattributes.cc new file mode 100644 index 0000000..0a441c3 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlattributes.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "xmlattributes.hh" + +XmlAttributes::XmlAttributes() +{ +} + +XmlAttributes::XmlAttributes(const QDomNamedNodeMap& node) +{ + load(node); +} + +void XmlAttributes::load(const QDomNamedNodeMap& node) +{ + QDomAttr attr; + + for(int i = 0; i < node.count(); i++) + { + attr = node.item(i).toAttr(); + + names_ << attr.name(); + values_ << attr.value(); + } +} + +QStringList XmlAttributes::names() const +{ + return names_; +} + +QStringList XmlAttributes::values() const +{ + return values_; +} diff --git a/scribo/demo/viewer/XmlWidget/xmlattributes.hh b/scribo/demo/viewer/XmlWidget/xmlattributes.hh new file mode 100644 index 0000000..89c546e --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlattributes.hh @@ -0,0 +1,44 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef XMLATTRIBUTES_H +# define XMLATTRIBUTES_H + +#include <QDomNamedNodeMap> +#include <QStringList> +#include <QVariant> + +class XmlAttributes +{ + public: + explicit XmlAttributes(); + explicit XmlAttributes(const QDomNamedNodeMap& node); + + void load(const QDomNamedNodeMap& node); + + QStringList names() const; + QStringList values() const; + + private: + QStringList names_; + QStringList values_; +}; + + +Q_DECLARE_METATYPE(XmlAttributes) +Q_DECLARE_METATYPE(XmlAttributes *) + +#endif // XMLATTRIBUTES_H diff --git a/GScribo/XmlWidget/xmldelegate.h b/scribo/demo/viewer/XmlWidget/xmldelegate.hh similarity index 100% rename from GScribo/XmlWidget/xmldelegate.h rename to scribo/demo/viewer/XmlWidget/xmldelegate.hh diff --git a/scribo/demo/viewer/XmlWidget/xmlitem.cc b/scribo/demo/viewer/XmlWidget/xmlitem.cc new file mode 100644 index 0000000..c12c819 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlitem.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "xmlitem.hh" + +XmlItem::XmlItem(XmlItem *parent, XmlItem *precItem) +{ + init(parent, precItem); +} + +XmlItem::XmlItem(const QDomElement& node, XmlItem *parent, XmlItem *precItem) +{ + init(parent, precItem); + load(node); +} + +XmlItem::~XmlItem() +{ + // Delete all childs. + XmlItem *child; + foreach(child, childs_) + delete child; +} + +void XmlItem::init(XmlItem *parent, XmlItem *precItem) +{ + isVisible_ = false; + regionItem_ = 0; + parent_ = parent; + + if(parent) + parent->addChild(this); + + if(precItem) + row_ = precItem->row()+1; + else + row_ = 0; +} + +void XmlItem::load(const QDomElement& node) +{ + text_ = node.tagName(); + + // Load attributes. + attributes_.load(node.attributes()); +} diff --git a/scribo/demo/viewer/XmlWidget/xmlitem.hh b/scribo/demo/viewer/XmlWidget/xmlitem.hh new file mode 100644 index 0000000..a964ea7 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlitem.hh @@ -0,0 +1,106 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef XMLITEM_H +#define XMLITEM_H + +#include <QDomElement> + +#include "xmlattributes.hh" + +class RegionItem; + +class XmlItem +{ + public: + explicit XmlItem(XmlItem *parent = 0, XmlItem *precItem = 0); + explicit XmlItem(const QDomElement& node, XmlItem *parent = 0, XmlItem *precItem = 0); + ~XmlItem(); + + void load(const QDomElement& node); + + inline QList<XmlItem *> childs() const; + inline XmlItem *child(int i) const; + inline void addChild(XmlItem *child); + inline XmlItem *parent() const; + + inline RegionItem *regionItem(); + inline void setRegionItem(RegionItem *regionItem); + + inline bool isVisible() const; + inline void setVisible(bool visible); + inline void show(); + inline void hide(); + + inline QString text() const; + inline int row() const; + inline XmlAttributes attributes() const; + + private: + void init(XmlItem *parent = 0, XmlItem *precItem = 0); + + int row_; + bool isVisible_; + QList<XmlItem *> childs_; + XmlItem *parent_; + RegionItem *regionItem_; + QString text_; + XmlAttributes attributes_; +}; + +inline QList<XmlItem *> XmlItem::childs() const +{ return childs_; } + +inline XmlItem *XmlItem::child(int i) const +{ if(i > -1 && i < childs_.count()) return childs_[i]; return 0; } + +inline void XmlItem::addChild(XmlItem *child) +{ childs_ << child; } + +inline XmlItem *XmlItem::parent() const +{ return parent_; } + +inline RegionItem *XmlItem::regionItem() +{ return regionItem_; } + +inline void XmlItem::setRegionItem(RegionItem *regionItem) +{ regionItem_ = regionItem; } + +inline bool XmlItem::isVisible() const +{ return isVisible_; } + +inline void XmlItem::setVisible(bool visible) +{ isVisible_ = visible; } + +inline void XmlItem::show() +{ isVisible_ = true; } + +inline void XmlItem::hide() +{ isVisible_ = false; } + +inline QString XmlItem::text() const +{ return text_; } + +inline int XmlItem::row() const +{ return row_; } + +inline XmlAttributes XmlItem::attributes() const +{ return attributes_; } + +Q_DECLARE_METATYPE(XmlItem) +Q_DECLARE_METATYPE(XmlItem *) + +#endif // XMLITEM_H diff --git a/scribo/demo/viewer/XmlWidget/xmlmodel.cc b/scribo/demo/viewer/XmlWidget/xmlmodel.cc new file mode 100644 index 0000000..0f51eb7 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlmodel.cc @@ -0,0 +1,123 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "xmlmodel.hh" + +XmlModel::XmlModel(XmlItem *rootItem, QObject *parent) : + QAbstractItemModel(parent) +{ + rootItem_ = rootItem; +} + +XmlModel::XmlModel(XmlItem *rootItem, + QAbstractItemModelPrivate& dd, + QObject *parent) + : QAbstractItemModel(dd, parent) +{ + rootItem_ = rootItem; +} + +XmlModel::~XmlModel() +{ + if(rootItem_) + delete rootItem_; +} + +QVariant XmlModel::headerData(int, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal && role == Qt::DisplayRole) + return tr("Tree"); + + return QVariant(); +} + +QVariant XmlModel::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + switch(role) + { + case Qt::UserRole: + return static_cast<XmlItem *>(index.internalPointer())->text(); + + case Qt::UserRole+1: + return QVariant::fromValue(static_cast<XmlItem *>(index.internalPointer())->attributes()); + + case Qt::UserRole+2: + return QVariant::fromValue(static_cast<XmlItem *>(index.internalPointer())); + + default: + return QVariant(); + } +} + +QModelIndex XmlModel::index(int row, int column, const QModelIndex& parent) const +{ + if(!hasIndex(row, column, parent)) + return QModelIndex(); + + XmlItem *childItem = toXmlItem(parent)->child(row); + + // Create the model index from the child item. + if(childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex XmlModel::parent(const QModelIndex& child) const +{ + if(!child.isValid()) + return QModelIndex(); + + XmlItem *parentItem = static_cast<XmlItem *>(child.internalPointer())->parent(); + + if(!parentItem || parentItem == rootItem_) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} + +void XmlModel::load(XmlItem *rootItem) +{ + beginResetModel(); + + if(rootItem_) + delete rootItem_; + + rootItem_ = rootItem; + + endResetModel(); +} + + +inline XmlItem *XmlModel::toXmlItem(const QModelIndex& parent) const +{ + return !parent.isValid() ? rootItem_ : static_cast<XmlItem *>(parent.internalPointer()); +} + +inline int XmlModel::rowCount(const QModelIndex& parent) const +{ + if(rootItem_) + return toXmlItem(parent)->childs().count(); + return 0; +} + +inline int XmlModel::columnCount(const QModelIndex&) const +{ + return 1; +} diff --git a/scribo/demo/viewer/XmlWidget/xmlmodel.hh b/scribo/demo/viewer/XmlWidget/xmlmodel.hh new file mode 100644 index 0000000..a781ea7 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlmodel.hh @@ -0,0 +1,51 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef XMLMODEL_H +#define XMLMODEL_H + +#include <QAbstractItemModel> + +#include "variantpointer.hh" +#include "xmlitem.hh" + +class XmlModel : + public QAbstractItemModel +{ + public: + explicit XmlModel(XmlItem *rootItem = 0, QObject *parent = 0); + explicit XmlModel(XmlItem *rootItem, QAbstractItemModelPrivate& dd, QObject *parent = 0); + ~XmlModel(); + + void load(XmlItem *rootItem); + + inline int rowCount(const QModelIndex& parent) const; + inline int columnCount(const QModelIndex& parent) const; + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + QVariant data(const QModelIndex& index, int role) const; + + QModelIndex index(int row, int column, const QModelIndex& parent) const; + QModelIndex parent(const QModelIndex& child) const; + + private: + inline XmlItem *toXmlItem(const QModelIndex& index) const; + + XmlItem *rootItem_; +}; + +#endif // XMLMODEL_H diff --git a/scribo/demo/viewer/XmlWidget/xmlview.cc b/scribo/demo/viewer/XmlWidget/xmlview.cc new file mode 100644 index 0000000..c943401 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlview.cc @@ -0,0 +1,104 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "xmlview.hh" + +XmlView::XmlView(QWidget *parent) : + QTreeView(parent) +{ + proxy_.setFilterRole(Qt::UserRole); + proxy_.setDynamicSortFilter(true); + + setUniformRowHeights(true); + setItemDelegate(new XmlDelegate(Qt::UserRole)); + setSelectionMode(QAbstractItemView::ExtendedSelection); +} + +void XmlView::hideAll() +{ + proxy_.beginResetModel(); + + XmlItem *child; + foreach(child, displayedItems_) + child->hide(); + + displayedItems_.clear(); + emit resetProperty(); + + proxy_.endResetModel(); +} + +void XmlView::display(QList<XmlItem *> displayedItems, bool addToDisplayedList) +{ + proxy_.beginResetModel(); + + if(!addToDisplayedList) + hideAll(); + + XmlItem *child; + foreach(child, displayedItems) + { + child->show(); + displayedItems_ << child; + } + + proxy_.endResetModel(); + + expandAll(); +} + +QList<XmlItem *> XmlView::transform(const QModelIndexList& modelIndexList) const +{ + QList<XmlItem *> selectedItems; + QModelIndex index; + + foreach(index, modelIndexList) + selectedItems << index.data(Qt::UserRole+2).value<XmlItem *>(); + + return selectedItems; +} + +void XmlView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) +{ + QTreeView::selectionChanged(selected, deselected); + + if(selected.indexes() == selectedIndexes()) + emit resetSelection(); + + if(!selectedIndexes().isEmpty()) + { + QList<XmlItem *> xmlItems; + if(!selected.isEmpty()) + { + xmlItems = transform(selected.indexes()); + emit select(xmlItems); + } + else + { + xmlItems = transform(deselected.indexes()); + emit unselect(xmlItems); + } + + emit loadAttributes(xmlItems.last()->attributes()); + } + else + { + emit resetProperty(); + emit emptySelection(); + } + + emit newSelection(); +} diff --git a/scribo/demo/viewer/XmlWidget/xmlview.hh b/scribo/demo/viewer/XmlWidget/xmlview.hh new file mode 100644 index 0000000..b9720dc --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlview.hh @@ -0,0 +1,95 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef XMLVIEW_H +#define XMLVIEW_H + +#include <QGraphicsItem> +#include <QTreeView> + +#include "Rendering/regionitem.hh" +#include "selectionproxy.hh" +#include "xmldelegate.hh" +#include "xmlitem.hh" + +class XmlView : + public QTreeView +{ + Q_OBJECT + + public: + explicit XmlView(QWidget *parent = 0); + + inline QList<XmlItem *> displayedItems() const; + void hideAll(); + + inline QList<XmlItem *> selectedItems() const; + + inline void setModel(QAbstractItemModel *model); + + protected: + void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); + + private: + QList<XmlItem *> transform(const QModelIndexList& modelIndexList) const; + void display(QList<XmlItem *> displayedItems, bool addToDisplayedList); + + SelectionProxy proxy_; + QList<XmlItem *> displayedItems_; + + public slots: + inline void display(QList<XmlItem *> displayedItems); + inline void displayOnly(QList<XmlItem *> displayedItems); + + inline void displayAll(); + + inline void setFilterString(const QString& filterString); + + signals: + void loadAttributes(const XmlAttributes& xmlAttributes); + + void select(const QList<XmlItem *>& selectedItems); + void unselect(const QList<XmlItem *>& unselectedItems); + + void newSelection(); + void emptySelection(); + + void resetSelection(); + void resetProperty(); +}; + +inline QList<XmlItem *> XmlView::displayedItems() const +{ return displayedItems_; } + +inline void XmlView::display(QList<XmlItem *> displayedItems) +{ display(displayedItems, true); } + +inline void XmlView::displayOnly(QList<XmlItem *> displayedItems) +{ display(displayedItems, false); } + +inline void XmlView::displayAll() +{ hideAll(); proxy_.displayAll(); } + +inline QList<XmlItem *> XmlView::selectedItems() const +{ return transform(selectedIndexes()); } + +inline void XmlView::setFilterString(const QString& filterString) +{ proxy_.setFilterRegExp(QRegExp(filterString, Qt::CaseSensitive)); proxy_.invalidateFilter(); } + +inline void XmlView::setModel(QAbstractItemModel *model) +{ proxy_.setSourceModel(model); QTreeView::setModel(&proxy_); } + +#endif // XMLVIEW_H diff --git a/scribo/demo/viewer/XmlWidget/xmlwidget.cc b/scribo/demo/viewer/XmlWidget/xmlwidget.cc new file mode 100644 index 0000000..e6bfe2a --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlwidget.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "xmlwidget.hh" + +XmlWidget::XmlWidget(QWidget *parent) : + QSplitter(Qt::Horizontal, parent) +{ + proxy_.setFilterRegExp(QRegExp("(?:Page|.Region|Line)", Qt::CaseSensitive)); + proxy_.setDynamicSortFilter(true); + proxy_.setFilterRole(Qt::UserRole); + proxy_.setSourceModel(&model_); + + view_.setModel(&proxy_); + + attributes_.setModel(&attributesModel_); + attributes_.setSelectionMode(QAbstractItemView::NoSelection); + attributes_.setItemDelegateForColumn(0, new XmlDelegate(Qt::UserRole)); + attributes_.setItemDelegateForColumn(1, new XmlDelegate(Qt::UserRole+1)); + + addWidget(&view_); + addWidget(&attributes_); + + connect(&view_, SIGNAL(resetProperty()), &attributesModel_, SLOT(reset())); + connect(&view_, SIGNAL(clicked(QModelIndex)), this, SLOT(loadAttributes(QModelIndex))); + connect(&view_, SIGNAL(loadAttributes(XmlAttributes)), &attributesModel_, SLOT(load(XmlAttributes))); +} + +void XmlWidget::changeView(XmlItem *rootItem) +{ + attributesModel_.reset(); + + model_.load(rootItem); + + view_.displayAll(); + view_.expandAll(); +} + + +XmlView * XmlWidget::view() +{ + return &view_; +} + +QTableView *XmlWidget::attributes() +{ + return &attributes_; +} + +void XmlWidget::loadAttributes(const QModelIndex& index) +{ + attributesModel_.load(index.data(Qt::UserRole+2).value<XmlItem *>()->attributes()); +} diff --git a/scribo/demo/viewer/XmlWidget/xmlwidget.hh b/scribo/demo/viewer/XmlWidget/xmlwidget.hh new file mode 100644 index 0000000..2662ae1 --- /dev/null +++ b/scribo/demo/viewer/XmlWidget/xmlwidget.hh @@ -0,0 +1,61 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef XMLWIDGET_H +# define XMLWIDGET_H + +#include <QSortFilterProxyModel> +#include <QTableView> +#include <QTreeWidget> +#include <QSplitter> +#include <QDomElement> +#include <QWidget> + +#include "Rendering/scene.hh" +#include "selectionproxy.hh" +#include "attributesmodel.hh" +#include "variantpointer.hh" +#include "xmldelegate.hh" +#include "xmlmodel.hh" +#include "xmlview.hh" + +class XmlWidget : + public QSplitter +{ + Q_OBJECT + + public: + explicit XmlWidget(QWidget *parent = 0); + + XmlView *view(); + QTableView *attributes(); + + void changeView(XmlItem *rootItem); + + private: + QSortFilterProxyModel proxy_; + + XmlModel model_; + AttributesModel attributesModel_; + + XmlView view_; + QTableView attributes_; + + private slots: + void loadAttributes(const QModelIndex& index); +}; + +#endif // XMLWIDGET_H diff --git a/scribo/demo/viewer/aboutdialog.cc b/scribo/demo/viewer/aboutdialog.cc new file mode 100644 index 0000000..c668d23 --- /dev/null +++ b/scribo/demo/viewer/aboutdialog.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include <aboutdialog.hh> + + +AboutDialog::AboutDialog(QWidget *parent) + : QDialog(parent, Qt::Dialog) +{ + ui = new Ui::AboutDialog; + ui->setupUi(this); +} + +AboutDialog::~AboutDialog() +{ + delete ui; +} + diff --git a/scribo/demo/viewer/aboutdialog.hh b/scribo/demo/viewer/aboutdialog.hh new file mode 100644 index 0000000..359489d --- /dev/null +++ b/scribo/demo/viewer/aboutdialog.hh @@ -0,0 +1,40 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef ABOUTDIALOG_HH +# define ABOUTDIALOG_HH + +#include <QDialog> + +#include "aboutdialog.ui.h" + +namespace Ui +{ + class AboutDialog; +} + +class AboutDialog : + public QDialog +{ +public: + explicit AboutDialog(QWidget *parent = 0); + ~AboutDialog(); + +private: + Ui::AboutDialog *ui; +}; + +#endif // ABOUTDIALOG_HH diff --git a/scribo/demo/viewer/aboutdialog.ui b/scribo/demo/viewer/aboutdialog.ui new file mode 100644 index 0000000..87bed94 --- /dev/null +++ b/scribo/demo/viewer/aboutdialog.ui @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>AboutDialog</class> + <widget class="QDialog" name="AboutDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>557</width> + <height>390</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>557</width> + <height>390</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>557</width> + <height>390</height> + </size> + </property> + <property name="windowTitle"> + <string>About</string> + </property> + <property name="windowIcon"> + <iconset> + <normaloff>:/icons/shared/icons/olena_smaller.jpg</normaloff>:/icons/shared/icons/olena_smaller.jpg</iconset> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string/> + </property> + <property name="pixmap"> + <pixmap>:/icons/shared/icons/olena_smaller.jpg</pixmap> + </property> + <property name="scaledContents"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="label_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd%22%3E; +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:12pt; font-weight:600;">Document Image Analysis Tool</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:12pt; font-weight:600;"></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans';">This project is powered by </span><span style=" font-family:'DejaVu Sans'; font-weight:600; font-style:italic;">Milena</span><span style=" font-family:'DejaVu Sans';">, a generic image processing library.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans';">It is part of </span><span style=" font-family:'DejaVu Sans'; font-weight:600; font-style:italic;">Olena</span><span style=" font-family:'DejaVu Sans';">, an Image Processing Platform and its module </span><span style=" font-family:'DejaVu Sans'; font-weight:600; font-style:italic;">Scribo</span><span style=" font-family:'DejaVu Sans';">, a set of tools for Document Image Analysis.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://olena.lrde.epita.fr%22%3E%3Cspan style=" font-family:'DejaVu Sans'; text-decoration: underline; color:#0057ae;">http://olena.lrde.epita.fr%3C/span%3E%3C/a%3E%3C/p%3E; +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans';"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:8pt;">Thanks to Antoine Froger, Arthur Crépin-Leblond, Samuel Da Mota, Loic Denuziere, Jérôme Galtier, Florent d'Halluin, Alex Hamelin, Damien Lefortier, Vincent Ordy, Guillaume Sadegh and Warren Seine for their contribution.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:8pt;"></p> +<p align="justify" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:8pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:7pt;">This application has been developed in the context of the SCRIBO project of the Free Software Thematic Group, part of the &quot;System@tic Paris-Région&quot; Cluster (France). This project is partially funded by the French Government, its economic development agencies, and by the Paris-Région institutions.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:7pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans'; font-size:7pt;">Copyright (C) 2012, 2013 EPITA Research and Development Laboratory (LRDE)</span></p></body></html></string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Ok</set> + </property> + <property name="centerButtons"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>AboutDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>281</x> + <y>391</y> + </hint> + <hint type="destinationlabel"> + <x>240</x> + <y>203</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/scribo/demo/viewer/browser_widget.cc b/scribo/demo/viewer/browser_widget.cc deleted file mode 100644 index 17e1c61..0000000 --- a/scribo/demo/viewer/browser_widget.cc +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "browser_widget.hh" - -BrowserWidget::BrowserWidget(QDirModel* files, QString dir) - : files_(files), - view_(new QListView()), - path_(new QLineEdit("")), - first_time_(true) -{ - QToolButton* next= new QToolButton(); - QToolButton* prev= new QToolButton(); - - prev->setIcon(style()->standardIcon(QStyle::SP_ArrowLeft)); - next->setIcon(style()->standardIcon(QStyle::SP_ArrowRight)); - next->setShortcut(QKeySequence("Ctrl+right")); - prev->setShortcut(QKeySequence("Ctrl+left")); - - QLabel* title = new QLabel(tr("Images")); - title->setAlignment(Qt::AlignHCenter); - - QVBoxLayout* layout = new QVBoxLayout; - QHBoxLayout *hlayout = new QHBoxLayout; - - hlayout->addWidget(prev); - hlayout->addWidget(title); - hlayout->addWidget(next); - layout->addLayout(hlayout); - layout->addWidget(path_); - layout->addWidget(view_); - - //setLayout(hlayout); - setLayout(layout); - - view_->setModel(files); - files->setFilter(QDir::AllDirs | QDir::Files - | QDir::Readable | QDir::Drives); - - view_->setRootIndex(files->index(QDir::currentPath())); - - QDir d(dir); - if (d.isReadable()) - view_->setRootIndex(files->index(d.absolutePath())); - - view_->setRowHidden(0, true); - - path_->setText(files->filePath(view_->rootIndex())); - - connect(view_, SIGNAL(activated(const QModelIndex&)), - this, SLOT(activate(const QModelIndex&))); - connect(next, SIGNAL(released ()), - this, SLOT(next())); - connect(prev, SIGNAL(released ()), - this, SLOT(prev())); - connect(path_, SIGNAL(returnPressed()), - this, SLOT(path_return_pressed())); - - QStringList files_filters; - files_filters << "*.png" << "*.jpg" - << "*.tif" << "*.ppm" - << "*.pgm" << "*.pbm" - << "*.pnm" << "*.xmlc"; - - files->setNameFilters(files_filters); -} - -void -BrowserWidget::path_return_pressed() -{ - QString path = path_->text(); - QDir d(path); - - if (d.isReadable()) - activate(files_->index(QString(path)), false); -} - -void -BrowserWidget::activate(const QModelIndex& index, bool b) -{ - if (files_->isDir(index)) - { - view_->setRootIndex(index); - view_->setRowHidden(0, true); - path_->setText(files_->filePath(view_->rootIndex())); - first_time_ = true; - return; - } - - first_time_ = false; - - if (files_->filePath(index).endsWith(".xmlc")) - emit activated(files_->filePath(index), b, true); - else - emit activated(files_->filePath(index), b, false); -} - -void -BrowserWidget::change_pos(bool next) -{ - QModelIndex index = view_->currentIndex(); - - if(next) - index = files_->index(index.row() + 1, index.column(), index.parent()); - else - index = files_->index(index.row() - 1, index.column(), index.parent()); - - if (index.isValid()) - { - if (!files_->isDir(index)) - if (!first_time_) - activate(index, true); - view_->setCurrentIndex(index); - } -} - -BrowserWidget::~BrowserWidget() -{ -} - -QString -BrowserWidget::current() const -{ - return files_->filePath(view_->currentIndex()); -} diff --git a/scribo/demo/viewer/browser_widget.hh b/scribo/demo/viewer/browser_widget.hh deleted file mode 100644 index 9567c11..0000000 --- a/scribo/demo/viewer/browser_widget.hh +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_BROWSER_WIDGET_HH -# define SCRIBO_DEMO_VIEWER_BROWSER_WIDGET_HH - -# include <QtGui> - -class BrowserWidget - : public QWidget -{ - Q_OBJECT - -public: - BrowserWidget(QDirModel* files, QString dir = QString()); - ~BrowserWidget(); - - QString current() const; - -public slots: - void activate(const QModelIndex& index, bool b = false); - void path_return_pressed(); - void next() { change_pos(true); } - void prev() { change_pos(false); } - -signals: - void activated(QString filename, bool b, bool x); - -private: - void change_pos(bool next); - QDirModel* files_; - QListView* view_; - QLineEdit* path_; - bool first_time_; -}; - -#endif // ! SCRIBO_DEMO_VIEWER_BROWSER_WIDGET_HH diff --git a/scribo/demo/viewer/common.hh b/scribo/demo/viewer/common.hh deleted file mode 100644 index 0072376..0000000 --- a/scribo/demo/viewer/common.hh +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_COMMON_HH -# define SCRIBO_DEMO_VIEWER_COMMON_HH - -namespace region -{ - typedef QVector<QPair<QString, QColor> > KeyMap; - - enum RegionId - { - // Text regions - // ------------- - - Text = 0, - - // Extension - Line, - - EndOfTextRegion, - - // Separators - // ---------- - - HorizontalSeparator, - VerticalSeparator, - - // Extension - WhitespaceSeparator, - - EndOfSepsRegion, - - // Misc regions. - // ------------- - Image, - Noise, - Table, - LineDrawing, - Graphic, - Chart, - Maths, - - EndOfMiscRegion, - - // Typographical lines - // ------------------- - - // Extension - Baseline, - Meanline, - - EndOfTypoRegion, - - RegionIdCount - }; -} - -#endif // ! SCRIBO_DEMO_VIEWER_COMMON_HH diff --git a/scribo/demo/viewer/config.cc b/scribo/demo/viewer/config.cc deleted file mode 100644 index 6bdcd35..0000000 --- a/scribo/demo/viewer/config.cc +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include <QDir> - -#include "config.hh" -#include "defs.hh" - -// Defines enum of binarization algorithms -# include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - - -config::config() - : QSettings("Olena-Scribo", "viewer") -{ - -} - -config* config::get_instance() -{ - static config * conf = new config(); - return conf; -} - - -// Preprocessing - -bool config::preprocessing_subsample() -{ - return value("preprocessing/subsample", false).toBool(); -} - -void config::set_preprocessing_subsample(bool b) -{ - setValue("preprocessing/subsample", b); -} - - -bool config::preprocessing_remove_bg() -{ - return value("preprocessing/remove_bg", false).toBool(); -} - -void config::set_preprocessing_remove_bg(bool b) -{ - setValue("preprocessing/remove_bg", b); -} - - -bool config::preprocessing_deskew() -{ - return value("preprocessing/deskew", false).toBool(); -} - -void config::set_preprocessing_deskew(bool b) -{ - setValue("preprocessing/deskew", b); -} - - -bool config::preprocessing_remove_noise() -{ - return value("preprocessing/remove_noise", true).toBool(); -} - -void config::set_preprocessing_remove_noise(bool b) -{ - setValue("preprocessing/remove_noise", b); -} - - -int config::preprocessing_bin_algo() -{ - return value("preprocessing/bin_algo", - scribo::toolchain::internal::SauvolaMs).toInt(); -} - -void config::set_preprocessing_bin_algo(int algo) -{ - setValue("preprocessing/bin_algo", algo); -} - - - -// Segmentation - -int config::segmentation_find_seps() -{ - return value("segmentation/find_seps", defs::LinesAndWhitespaces).toInt(); -} - -void config::set_segmentation_find_seps(int seps) -{ - setValue("segmentation/find_seps", seps); -} - - -// OCR - -bool config::ocr_enabled() -{ - return value("ocr/enabled", true).toBool(); -} - -void config::set_ocr_enabled(bool b) -{ - setValue("ocr/enabled", b); -} - - - -QString config::ocr_language() -{ - return value("ocr/language", 0).toString(); -} - -void config::set_ocr_language(const QString& lang) -{ - setValue("ocr/language", lang); -} - - - -// General options - -bool config::general_save_xml_enabled() -{ - return value("general/save_xml/enabled", true).toBool(); -} - -void config::set_general_save_xml_enabled(bool b) -{ - setValue("general/save_xml/enabled", b); -} - - -bool config::general_save_xml_same_dir() -{ - return value("general/save_xml/same_dir", true).toBool(); -} - -void config::set_general_save_xml_same_dir(bool b) -{ - setValue("general/save_xml/same_dir", b); -} - - -bool config::general_save_xml_custom_dir() -{ - return value("general/save_xml/custom_dir", false).toBool(); -} - -void config::set_general_save_xml_custom_dir(bool b) -{ - setValue("general/save_xml/custom_dir", b); -} - - -QString config::general_save_xml_custom_dir_path() -{ - return value("general/save_xml/custom_dir_path", QDir::tempPath()).toString(); -} - -void config::set_general_save_xml_custom_dir_path(const QString& path) -{ - setValue("general/save_xml/custom_dir_path", path); -} - diff --git a/scribo/demo/viewer/config.hh b/scribo/demo/viewer/config.hh deleted file mode 100644 index 74dab3b..0000000 --- a/scribo/demo/viewer/config.hh +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_CONFIG_HH -# define SCRIBO_DEMO_VIEWER_CONFIG_HH - -# include <QSettings> - -class config : public QSettings -{ -public: - - config(); - - static config* get_instance(); - - // Preprocessing - bool preprocessing_subsample(); - void set_preprocessing_subsample(bool b); - - bool preprocessing_remove_bg(); - void set_preprocessing_remove_bg(bool b); - - bool preprocessing_deskew(); - void set_preprocessing_deskew(bool b); - - bool preprocessing_remove_noise(); - void set_preprocessing_remove_noise(bool b); - - int preprocessing_bin_algo(); - void set_preprocessing_bin_algo(int algo); - - - // Segmentation - int segmentation_find_seps(); - void set_segmentation_find_seps(int seps); - - - // OCR - bool ocr_enabled(); - void set_ocr_enabled(bool b); - - QString ocr_language(); - void set_ocr_language(const QString& lang); - - - // General options - bool general_save_xml_enabled(); - void set_general_save_xml_enabled(bool b); - - bool general_save_xml_same_dir(); - void set_general_save_xml_same_dir(bool b); - - bool general_save_xml_custom_dir(); - void set_general_save_xml_custom_dir(bool b); - - QString general_save_xml_custom_dir_path(); - void set_general_save_xml_custom_dir_path(const QString& path); - - -}; - - -#endif // ! SCRIBO_DEMO_VIEWER_CONFIG_HH diff --git a/scribo/demo/viewer/configs.cc b/scribo/demo/viewer/configs.cc new file mode 100644 index 0000000..f832b5a --- /dev/null +++ b/scribo/demo/viewer/configs.cc @@ -0,0 +1,149 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "configs.hh" + +Configs::Configs() + : QSettings("olena-scribo", "gui") +{ +} + +Configs *Configs::getInstance() +{ + static Configs *conf = new Configs(); return conf; +} + +bool Configs::preprocessingSubsample() +{ + return value("preprocessing/subsample", false).toBool(); +} + +void Configs::setPreprocessingSubsample(bool b) +{ + setValue("preprocessing/subsample", b); +} + +bool Configs::preprocessingRemoveBg() +{ + return value("preprocessing/remove_bg", false).toBool(); +} + +void Configs::setPreprocessingRemoveBg(bool b) +{ + setValue("preprocessing/remove_bg", b); +} + +bool Configs::preprocessingDeskew() +{ + return value("preprocessing/deskew", false).toBool(); +} + +void Configs::setPreprocessingDeskew(bool b) +{ + setValue("preprocessing/deskew", b); +} + +bool Configs::preprocessingRemoveNoise() +{ + return value("preprocessing/remove_noise", true).toBool(); +} + +void Configs::setPreprocessingRemoveNoise(bool b) +{ + setValue("preprocessing/remove_noise", b); +} + +int Configs::preprocessingBinAlgo() +{ + return value("preprocessing/bin_algo", + scribo::toolchain::internal::SauvolaMs).toInt(); +} + +void Configs::setPreprocessingBinAlgo(int algo) +{ + setValue("preprocessing/bin_algo", algo); +} + +int Configs::segmentationFindSeps() +{ + return value("segmentation/find_seps", Separator::Both).toInt(); +} + +void Configs::setSegmentationFindSeps(int seps) +{ + setValue("segmentation/find_seps", seps); +} + +bool Configs::ocrEnabled() +{ + return value("ocr/enabled", true).toBool(); +} + +void Configs::setOcrEnabled(bool b) +{ + setValue("ocr/enabled", b); +} + +QString Configs::ocrLanguage() +{ + return value("ocr/language", 0).toString(); +} + +void Configs::setOcrLanguage(const QString& lang) +{ + setValue("ocr/language", lang); +} + +bool Configs::generalSaveXmlEnabled() +{ + return value("general/save_xml/enabled", true).toBool(); +} + +void Configs::setGeneralSaveXmlEnabled(bool b) +{ + setValue("general/save_xml/enabled", b); +} + +bool Configs::generalSaveXmlSameDir() +{ + return value("general/save_xml/same_dir", true).toBool(); +} + +void Configs::setGeneralSaveXmlSameDir(bool b) +{ + setValue("general/save_xml/same_dir", b); +} + +bool Configs::generalSaveXmlCustomDir() +{ + return value("general/save_xml/custom_dir", false).toBool(); +} + +void Configs::setGeneralSaveXmlCustomDir(bool b) +{ + setValue("general/save_xml/custom_dir", b); +} + +QString Configs::generalSaveXmlCustomDirPath() +{ + return value("general/save_xml/custom_dir_path", + QDir::tempPath()).toString(); +} + +void Configs::setGeneralSaveXmlCustomDirPath(const QString& path) +{ + setValue("general/save_xml/custom_dir_path", path); +} diff --git a/scribo/demo/viewer/configs.hh b/scribo/demo/viewer/configs.hh new file mode 100644 index 0000000..26de148 --- /dev/null +++ b/scribo/demo/viewer/configs.hh @@ -0,0 +1,74 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef CONFIGS_H +# define CONFIGS_H + +#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> +#include <QSettings> +#include <QDir> +#include <QDebug> + +#include "region.hh" + +class Configs : + public QSettings +{ +public: + static Configs *getInstance(); + + bool preprocessingSubsample(); + void setPreprocessingSubsample(bool b); + + bool preprocessingRemoveBg(); + void setPreprocessingRemoveBg(bool b); + + bool preprocessingDeskew(); + void setPreprocessingDeskew(bool b); + + bool preprocessingRemoveNoise(); + void setPreprocessingRemoveNoise(bool b); + + int preprocessingBinAlgo(); + void setPreprocessingBinAlgo(int algo); + + int segmentationFindSeps(); + void setSegmentationFindSeps(int seps); + + bool ocrEnabled(); + void setOcrEnabled(bool b); + + QString ocrLanguage(); + void setOcrLanguage(const QString& lang); + + bool generalSaveXmlEnabled(); + void setGeneralSaveXmlEnabled(bool b); + + bool generalSaveXmlSameDir(); + void setGeneralSaveXmlSameDir(bool b); + + bool generalSaveXmlCustomDir(); + void setGeneralSaveXmlCustomDir(bool b); + + QString generalSaveXmlCustomDirPath(); + void setGeneralSaveXmlCustomDirPath(const QString& path); + +private: + explicit Configs(); +}; + + +#endif // CONFIGS_H diff --git a/scribo/demo/viewer/defs.hh b/scribo/demo/viewer/defs.hh deleted file mode 100644 index ada4441..0000000 --- a/scribo/demo/viewer/defs.hh +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_DEFS_HH -# define SCRIBO_DEMO_VIEWER_DEFS_HH - -namespace defs -{ - enum FindSeparators - { - Lines, - Whitespaces, - LinesAndWhitespaces - }; - -} // end of namespace defs - -#endif // ! SCRIBO_DEMO_VIEWER_DEFS_HH diff --git a/GScribo/dir.h b/scribo/demo/viewer/dir.hh similarity index 100% rename from GScribo/dir.h rename to scribo/demo/viewer/dir.hh diff --git a/scribo/demo/viewer/dockwidget.cc b/scribo/demo/viewer/dockwidget.cc new file mode 100644 index 0000000..fc895b0 --- /dev/null +++ b/scribo/demo/viewer/dockwidget.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "dockwidget.hh" + +DockWidget::DockWidget(QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(parent, flags) +{ +} + + +DockWidget::DockWidget(const QString& title, + QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(title, parent, flags) +{ +} + +void DockWidget::switchVisibility() +{ + setVisible(!isVisible()); +} diff --git a/scribo/demo/viewer/dockwidget.hh b/scribo/demo/viewer/dockwidget.hh new file mode 100644 index 0000000..e6fb483 --- /dev/null +++ b/scribo/demo/viewer/dockwidget.hh @@ -0,0 +1,36 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef DOCKWIDGET_H +# define DOCKWIDGET_H + +#include <QDockWidget> + +class DockWidget : + public QDockWidget +{ + Q_OBJECT + + public: + explicit DockWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0); + explicit DockWidget(const QString& title, + QWidget *parent = 0, Qt::WindowFlags flags = 0); + +public slots: + void switchVisibility(); +}; + +#endif // DOCKWIDGET_H diff --git a/scribo/demo/viewer/general_options.cc b/scribo/demo/viewer/general_options.cc deleted file mode 100644 index 50201ff..0000000 --- a/scribo/demo/viewer/general_options.cc +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "general_options.hh" -#include "config.hh" - - -general_options::general_options(QWidget *parent) - : OptionWidget(parent) -{ - setupUi(this); - - load_config(); -} - -general_options::~general_options() -{ -} - - -void general_options::load_config() -{ - config * const conf = config::get_instance(); - - saveXml->setChecked(conf->general_save_xml_enabled()); - sameDir->setChecked(conf->general_save_xml_same_dir()); - customDir->setChecked(conf->general_save_xml_custom_dir()); - customDirValue->setText(conf->general_save_xml_custom_dir_path()); -} - - -void general_options::save_config() -{ - config * const conf = config::get_instance(); - - conf->set_general_save_xml_enabled(saveXml->isChecked()); - conf->set_general_save_xml_same_dir(sameDir->isChecked()); - conf->set_general_save_xml_custom_dir(customDir->isChecked()); - conf->set_general_save_xml_custom_dir_path(customDirValue->text()); -} - -void general_options::on_customDirBrowseBtn_clicked() -{ - QString dir = QFileDialog::getExistingDirectory(0, "Choose a directory"); - if (!dir.isEmpty()) - customDirValue->setText(dir); -} diff --git a/scribo/demo/viewer/general_options.hh b/scribo/demo/viewer/general_options.hh deleted file mode 100644 index e2fcaae..0000000 --- a/scribo/demo/viewer/general_options.hh +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_GENERAL_OPTIONS_HH -# define SCRIBO_DEMO_VIEWER_GENERAL_OPTIONS_HH - -# include <QtGui> -# include <general_options.ui.h> -# include "option_widget.hh" - -class general_options : public OptionWidget, private Ui::GeneralOptions -{ - Q_OBJECT; - -public: - general_options(QWidget *parent = 0); - ~general_options(); - - virtual void load_config(); - virtual void save_config(); - -private slots: - void on_customDirBrowseBtn_clicked(); - -}; - -#endif // ! SCRIBO_DEMO_VIEWER_GENERAL_OPTIONS_HH diff --git a/scribo/demo/viewer/general_options.ui b/scribo/demo/viewer/general_options.ui deleted file mode 100644 index 5839c27..0000000 --- a/scribo/demo/viewer/general_options.ui +++ /dev/null @@ -1,100 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>GeneralOptions</class> - <widget class="QWidget" name="GeneralOptions"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <widget class="QGroupBox" name="saveXml"> - <property name="title"> - <string>Save segmentation results</string> - </property> - <property name="flat"> - <bool>true</bool> - </property> - <property name="checkable"> - <bool>true</bool> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <widget class="QRadioButton" name="sameDir"> - <property name="text"> - <string>In the same directory as the input image</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QRadioButton" name="customDir"> - <property name="text"> - <string>In the following directory</string> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Maximum</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QLineEdit" name="customDirValue"/> - </item> - <item> - <widget class="QPushButton" name="customDirBrowseBtn"> - <property name="text"> - <string>Browse</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> diff --git a/scribo/demo/viewer/help_dialog.cc b/scribo/demo/viewer/help_dialog.cc deleted file mode 100644 index 2d5ce6c..0000000 --- a/scribo/demo/viewer/help_dialog.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "help_dialog.hh" - -HelpDialog::HelpDialog() -{ - setupUi(this); -} diff --git a/scribo/demo/viewer/help_dialog.hh b/scribo/demo/viewer/help_dialog.hh deleted file mode 100644 index 9f179c6..0000000 --- a/scribo/demo/viewer/help_dialog.hh +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_HELP_DIALOG_HH -# define SCRIBO_DEMO_VIEWER_HELP_DIALOG_HH - -# include <QtGui> -# include <help_dialog.ui.h> - -class HelpDialog : public QDialog, private Ui::HelpDialog -{ -public: - HelpDialog(); - -}; - -#endif // ! SCRIBO_DEMO_VIEWER_HELP_DIALOG_HH diff --git a/scribo/demo/viewer/help_dialog.ui b/scribo/demo/viewer/help_dialog.ui deleted file mode 100644 index 9ab7e58..0000000 --- a/scribo/demo/viewer/help_dialog.ui +++ /dev/null @@ -1,138 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>HelpDialog</class> - <widget class="QDialog" name="HelpDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>557</width> - <height>390</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>557</width> - <height>390</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>557</width> - <height>390</height> - </size> - </property> - <property name="windowTitle"> - <string>About</string> - </property> - <property name="windowIcon"> - <iconset resource="viewer.qrc"> - <normaloff>:/icons/shared/icons/olena_smaller.jpg</normaloff>:/icons/shared/icons/olena_smaller.jpg</iconset> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string/> - </property> - <property name="pixmap"> - <pixmap resource="viewer.qrc">:/icons/shared/icons/olena_smaller.jpg</pixmap> - </property> - <property name="scaledContents"> - <bool>false</bool> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="label_2"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd%22%3E; -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">Document Image Analysis Tool</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-weight:600;"></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This project is powered by <span style=" font-weight:600; font-style:italic;">Milena</span>, a generic image processing library.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">It is part of <span style=" font-weight:600; font-style:italic;">Olena</span>, an Image Processing Platform and its module <span style=" font-weight:600; font-style:italic;">Scribo</span>, a set of tools for Document Image Analysis.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://olena.lrde.epita.fr%22%3E%3Cspan style=" text-decoration: underline; color:#0057ae;">http://olena.lrde.epita.fr%3C/span%3E%3C/a%3E%3C/p%3E; -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Thanks to Arthur Crépin-Leblond, Samuel Da Mota, Loic Denuziere, </span><span style=" font-size:8pt;">Jérôme Galtier,</span><span style=" font-size:8pt;"> </span><span style=" font-size:8pt;">Florent d'Halluin, </span><span style=" font-size:8pt;">Alex Hamelin, </span><span style=" font-size:8pt;">Damien Lefortier, </span><span style=" font-size:8pt;">Vincent Ordy, </span><span style=" font-size:8pt;">Guillaume Sadegh and</span><span style=" font-size:8pt;"> </span><span style=" font-size:8pt;">Warren Seine </span><span style=" font-size:8pt;">for their contribution.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> -<p align="justify" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:7pt;">This application has been developed in the context of the SCRIBO project of the Free Software Thematic Group, part of the &quot;System@tic Paris-Région&quot; Cluster (France). This project is partially funded by the French Government, its economic development agencies, and by the Paris-Région institutions.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:7pt;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:7pt;">Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)</span></p></body></html></string> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="standardButtons"> - <set>QDialogButtonBox::Ok</set> - </property> - <property name="centerButtons"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> - <resources> - <include location="viewer.qrc"/> - </resources> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>HelpDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>281</x> - <y>391</y> - </hint> - <hint type="destinationlabel"> - <x>240</x> - <y>203</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/scribo/demo/viewer/icons/olena_smaller.jpg b/scribo/demo/viewer/icons/olena_smaller.jpg deleted file mode 100644 index c6b9110..0000000 Binary files a/scribo/demo/viewer/icons/olena_smaller.jpg and /dev/null differ diff --git a/scribo/demo/viewer/image_region.cc b/scribo/demo/viewer/image_region.cc deleted file mode 100644 index 93d9d79..0000000 --- a/scribo/demo/viewer/image_region.cc +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "image_region.hh" - -ImageRegion::ImageRegion(region::RegionId id, - QString name, - QColor color, - QString attr_id, - const QVector<QPoint>& points, - bool outline, - bool fill, - bool precise, - bool draw) - : QGraphicsItem(0), - id_(id), - name_(name), - color_(color), - attr_id_(attr_id), - shape_(), - rect_(), - outline_(outline), - precise_(precise), - fill_(fill), - draw_(draw), - selected_(false), - alpha_(50) -{ - setCursor(Qt::ArrowCursor); - if (id_ == region::Line) - setZValue(3); - else - setZValue(1); - - if (points.size() == 0) - return; - - for (int i = 1; i < points.size(); ++i) - shape_.lineTo(points[i] - points[0]); - shape_.lineTo(QPoint(0, 0)); - - rect_ = shape_.boundingRect(); - setPos(points[0] + QPointF(0.5, 0.5)); - - prepareGeometryChange(); -} - -ImageRegion::~ImageRegion() -{ -} - -region::RegionId ImageRegion::id() -{ - return id_; -} - -void -ImageRegion::paint(QPainter* painter, - const QStyleOptionGraphicsItem*, - QWidget*) -{ - if (!draw_ && !selected_) - return; - - int width = 0; - if (precise_) - width = 1; - - if (outline_) - painter->setPen(QPen(QBrush(color_), width, Qt::SolidLine, - Qt::SquareCap, Qt::MiterJoin)); - else - painter->setPen(QColor(0, 0, 0, 0)); - - QColor brush = color_; - if (fill_) - brush.setAlpha(alpha_); - else - brush.setAlpha(0); - painter->setBrush(brush); - - painter->drawPath(shape_); - - if (selected_) - { - QPolygonF sceneRect = mapFromScene(scene()->sceneRect()); - QPainterPath path; - path.addPolygon(sceneRect); - QColor brush(255, 255, 255); - brush.setAlpha(120); - painter->setBrush(brush); - painter->setPen(QColor(0, 0, 0, 0)); - painter->drawPath(path.subtracted(shape_)); - } -} - -void -ImageRegion::select() -{ - if (!selected_) - { - selected_ = true; - setZValue(4); - prepareGeometryChange(); - scene()->invalidate(); - update(); - } -} - -void -ImageRegion::deselect() -{ - if (selected_) - { - selected_ = false; - if (id_ == region::Line) - setZValue(3); - else - setZValue(1); - prepareGeometryChange(); - scene()->invalidate(); - update(); - } -} diff --git a/scribo/demo/viewer/image_region.hh b/scribo/demo/viewer/image_region.hh deleted file mode 100644 index 41141f7..0000000 --- a/scribo/demo/viewer/image_region.hh +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_IMAGE_REGION_HH -# define SCRIBO_DEMO_VIEWER_IMAGE_REGION_HH - -# include <QtGui> -# include "common.hh" - -class ImageRegion - : public QObject, public QGraphicsItem -{ - Q_OBJECT - -public: - ImageRegion(region::RegionId id, - QString name, - QColor color, - QString attr_id, - const QVector<QPoint>& points, - bool outline, - bool fill, - bool precise, - bool draw); - - ~ImageRegion(); - - region::RegionId id(); - void paint(QPainter* painter, - const QStyleOptionGraphicsItem* option, - QWidget* widget = 0); - - QRectF boundingRect() const; - QPainterPath shape() const; - QString name() { return name_; } - QRectF rect() { return rect_; } - QString attr_id() { return attr_id_; } - -public slots: - void setOutline(bool outline); - void setFill(bool fill); - void setFillAlpha(int alpha); - void setDraw(bool draw); - void setPrecise(bool precise); - void setDrawIfSameId(int id, bool draw); - void select(); - void deselect(); - -private: - region::RegionId id_; - QString name_; - QColor color_; - QString attr_id_; - QPainterPath shape_; - QRectF rect_; - bool outline_; - bool precise_; - bool fill_; - bool draw_; - bool selected_; - int alpha_; -}; - -#include "image_region.hxx" - -#endif // ! SCRIBO_DEMO_VIEWER_IMAGE_REGION_HH diff --git a/scribo/demo/viewer/image_region.hxx b/scribo/demo/viewer/image_region.hxx deleted file mode 100644 index 5ddd7de..0000000 --- a/scribo/demo/viewer/image_region.hxx +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef IMAGE_REGION_HXX_ -# define IMAGE_REGION_HXX_ - -# include "image_region.hh" - -inline -void -ImageRegion::setOutline(bool outline) -{ - outline_ = outline; - scene()->invalidate(); - update(); -} - -inline -void -ImageRegion::setPrecise(bool precise) -{ - precise_ = precise; - scene()->invalidate(); - update(); -} - -inline -void -ImageRegion::setFill(bool fill) -{ - fill_ = fill; - update(); -} - -inline -void -ImageRegion::setDraw(bool draw) -{ - draw_ = draw; - update(); -} - -inline -void -ImageRegion::setDrawIfSameId(int id, bool draw) -{ - if (id == id_) - { - draw_ = draw; - setVisible(draw); - if (scene()) - { - scene()->invalidate(); - update(); - } - } -} - -inline -void -ImageRegion::setFillAlpha(int alpha) -{ - alpha_ = alpha; - update(); -} - -inline -QRectF -ImageRegion::boundingRect() const -{ -// if (selected_) -// return mapFromScene(scene()->sceneRect()).boundingRect(); - return rect_; -} - -inline -QPainterPath -ImageRegion::shape() const -{ - return shape_; -} - -#endif /* !IMAGE_REGION_HXX_ */ diff --git a/scribo/demo/viewer/image_scene.cc b/scribo/demo/viewer/image_scene.cc deleted file mode 100644 index a800896..0000000 --- a/scribo/demo/viewer/image_scene.cc +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - - -#include "image_scene.hh" -#include "image_region.hh" - -ImageScene::ImageScene(QObject *parent) - : QGraphicsScene(parent), selected_(0) -{ -} - -void -ImageScene::clear() -{ - selected_ = 0; - QGraphicsScene::clear(); -} - -void -ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsScene::mousePressEvent(event); - QList<QGraphicsItem *> items_list = items(event->scenePos()); // includes both ImageRegions and the picture. - - if (items_list.isEmpty()) - { - if (selected_) - { - selected_->deselect(); - emit deselected(); - selected_ = 0; - } - } - - // Selection is under the mouse click (at event->pos()). - bool selection_is_clicked = items_list.contains(selected_); - - foreach(QGraphicsItem* elt, items_list) - { - ImageRegion* item = dynamic_cast<ImageRegion*>(elt); - if (item) - { - if (item != selected_) - { - if (selected_) - { - if ( (item->boundingRect().intersects(selected_->boundingRect()))) - { - int item_area = item->boundingRect().size().height() * item->boundingRect().size().width(); - int selected_area = selected_->boundingRect().size().height() * selected_->boundingRect().size().width(); - - if (selected_area < item_area && selection_is_clicked) - return; - else - { - selected_->deselect(); - emit deselected(); - selected_ = 0; - } - } - else - { - selected_->deselect(); - emit deselected(); - selected_ = 0; - } - } - selected_ = item; - item->select(); - emit selected(item->attr_id(), item->name()); - return; - } - } - else - { - if ( (selected_) - && (items_list.size() == 1) )// no ImageRegion, only the picture - { - selected_->deselect(); - emit deselected(); - selected_ = 0; - } - } - } -} - -ImageScene::~ImageScene() -{ -} diff --git a/scribo/demo/viewer/image_scene.hh b/scribo/demo/viewer/image_scene.hh deleted file mode 100644 index b141478..0000000 --- a/scribo/demo/viewer/image_scene.hh +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_IMAGE_SCENE_HH -# define SCRIBO_DEMO_VIEWER_IMAGE_SCENE_HH - -# include <QtGui> - -class ImageRegion; - -class ImageScene - : public QGraphicsScene -{ - Q_OBJECT - -public: - ImageScene(QObject *parent = 0); - ~ImageScene(); - - void mousePressEvent(QGraphicsSceneMouseEvent* event); - void clear(); - -signals: - void selected(QString, QString); - void deselected(); - -private: - ImageRegion* selected_; - QVector<ImageRegion*> region_vector_; -}; - -#endif // ! SCRIBO_DEMO_VIEWER_IMAGE_SCENE_HH diff --git a/scribo/demo/viewer/image_view.cc b/scribo/demo/viewer/image_view.cc deleted file mode 100644 index bb34eb7..0000000 --- a/scribo/demo/viewer/image_view.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "image_view.hh" - -ImageView::ImageView(QGraphicsScene* scene) - : QGraphicsView(scene) -{ -} - -void -ImageView::wheelEvent(QWheelEvent* event) -{ - // Basic zoom code (same as yavgui) - if (event->delta() != 0) - { - qreal degrees = ((qreal) event->delta()) / 8; - qreal sc; - if (degrees > 0) - sc = 1 + degrees / 100; - else - sc = 1 / (1 - degrees / 100); - - QPointF center = mapToScene(width() / 2, height() / 2); - QPointF mouse = mapToScene(event->pos()); - - qreal dx = (mouse.x() - center.x()); - qreal dy = (mouse.y() - center.y()); - QPointF newCenter = QPointF (mouse.x() - dx / sc, - mouse.y() - dy / sc); - scale(sc, sc); - scaleUpdate(); - } -} - -void -ImageView::keyPressEvent(QKeyEvent* event) -{ - if (event->key() == Qt::Key_PageUp) - scale(1.25, 1.25); - else if (event->key() == Qt::Key_PageDown) - scale(0.75, 0.75); - else if (event->key() == Qt::Key_Home) - resetMatrix(); - else if (event->key() == Qt::Key_End) - fitInView(sceneRect(), Qt::KeepAspectRatio); - else - { - QGraphicsView::keyPressEvent(event); - return; - } - scaleUpdate(); - event->accept(); -} - -void -ImageView::scaleUpdate() -{ - // Used to determine whether to change the main image cache mode. - QRect orig(0, 0, 10, 1); - QRectF scene = mapToScene(orig).boundingRect(); - emit scaleUpdated(10 / scene.width()); -} - -ImageView::~ImageView() -{ -} diff --git a/scribo/demo/viewer/image_view.hh b/scribo/demo/viewer/image_view.hh deleted file mode 100644 index 622999b..0000000 --- a/scribo/demo/viewer/image_view.hh +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_IMAGE_VIEW_HH -# define SCRIBO_DEMO_VIEWER_IMAGE_VIEW_HH - -# include <QtGui> - -class ImageView - : public QGraphicsView -{ - Q_OBJECT - -public: - ImageView(QGraphicsScene* scene); - ~ImageView(); - - void wheelEvent(QWheelEvent* event); - void keyPressEvent(QKeyEvent *event); - - // Call after changing the scale. - void scaleUpdate(); - -signals: - // Scale is approximate. - void scaleUpdated(qreal scale); -}; - -#endif // ! SCRIBO_DEMO_VIEWER_IMAGE_VIEW_HH diff --git a/scribo/demo/viewer/image_widget.cc b/scribo/demo/viewer/image_widget.cc deleted file mode 100644 index f86ff1d..0000000 --- a/scribo/demo/viewer/image_widget.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "image_widget.hh" -#include "image_view.hh" - -ImageWidget::ImageWidget(QGraphicsScene* scene) - : view_ (new ImageView(scene)) -{ - scene->setParent(view_); - - QLabel* title = new QLabel(tr("Layout")); - title->setAlignment(Qt::AlignHCenter); - - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget(title); - layout->addWidget(view_); - - view_->setDragMode(QGraphicsView::ScrollHandDrag); - view_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view_->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - - connect(view_, SIGNAL(scaleUpdated(qreal)), - this, SIGNAL(scaleUpdated(qreal))); - - setLayout(layout); -} - - -ImageWidget::~ImageWidget() -{ -} - - -void -ImageWidget::update() -{ - view_->fitInView(view_->sceneRect(), Qt::KeepAspectRatio); - view_->scaleUpdate(); -} - -ImageView * -ImageWidget::view() const -{ - return view_; -} diff --git a/scribo/demo/viewer/image_widget.hh b/scribo/demo/viewer/image_widget.hh deleted file mode 100644 index 79dd672..0000000 --- a/scribo/demo/viewer/image_widget.hh +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_IMAGE_WIDGET_HH -# define SCRIBO_DEMO_VIEWER_IMAGE_WIDGET_HH - -# include <QtGui> -# include "image_view.hh" - -class ImageView; - -class ImageWidget - : public QWidget -{ - Q_OBJECT - -public: - ImageWidget(QGraphicsScene* scene); - ~ImageWidget(); - - ImageView * view() const; - -public slots: - void update(); - -signals: - void scaleUpdated(qreal scale); - -private: - ImageView* view_; -}; - -#endif // ! SCRIBO_DEMO_VIEWER_IMAGE_WIDGET_HH diff --git a/scribo/demo/viewer/key_widget.cc b/scribo/demo/viewer/key_widget.cc deleted file mode 100644 index 3b07617..0000000 --- a/scribo/demo/viewer/key_widget.cc +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "key_widget.hh" -#include "common.hh" - -KeyWidget::KeyWidget(const region::KeyMap& key_map) - : items_(new QTreeWidget()) -{ - item_list_.append(new QTreeWidgetItem(QStringList("Text"))); - item_list_.append(new QTreeWidgetItem(QStringList("Separators"))); - item_list_.append(new QTreeWidgetItem(QStringList("Misc. Regions"))); - item_list_.append(new QTreeWidgetItem(QStringList("Typographical lines"))); - - QLabel* title = new QLabel(tr("Key")); - title->setAlignment(Qt::AlignHCenter); - - foreach(QTreeWidgetItem* item, item_list_) - { - items_->addTopLevelItem(item); - item->setCheckState(0, Qt::Checked); - item->setExpanded(true); - } - items_->setHeaderHidden(true); - - base_id_.append(0); - base_id_.append(region::EndOfTextRegion + 1); - base_id_.append(region::EndOfSepsRegion + 1); - base_id_.append(region::EndOfMiscRegion + 1); - base_id_.append(region::EndOfTypoRegion + 1); - - for (int j = 0; j < base_id_.size() - 1; ++j) - for (int i = base_id_.at(j); i < base_id_.at(j + 1) - 1; ++i) - add_item_(key_map.at(i).first, key_map.at(i).second, false, item_list_.at(j)); - - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget(title); - layout->addWidget(items_); - - setLayout(layout); - - connect(items_, SIGNAL(itemChanged(QTreeWidgetItem*, int)), - this, SLOT(update(QTreeWidgetItem*))); -} - -void KeyWidget::update_all() -{ - foreach(QTreeWidgetItem* item, item_list_) - for (int i = 0; i < item->childCount(); ++i) - update(item->child(i)); -} - -void KeyWidget::setAll(bool b) -{ - Qt::CheckState state; - if (b) - state = Qt::Checked; - else - state = Qt::Unchecked; - - foreach(QTreeWidgetItem* item, item_list_) - item->setCheckState(0, state); -} - -void KeyWidget::setAllCheck(QTreeWidgetItem* parent) -{ - for (int i = 0; i < parent->childCount(); ++i) - { - if (parent->checkState(0) == Qt::Checked) - parent->child(i)->setCheckState(0, Qt::Checked); - else - parent->child(i)->setCheckState(0, Qt::Unchecked); - update(parent->child(i)); - } -} - -void -KeyWidget::change_mode(bool b) -{ - item_list_.at(0)->child(region::Line)->setHidden(!b); - // FIXME: we may like to hide also typographical objects. -} - -void -KeyWidget::add_item_(QString text, QColor color, bool b, QTreeWidgetItem* parent) -{ - QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(text)); - QPixmap pixmap(10, 6); - - pixmap.fill(color); - item->setIcon(0, QIcon(pixmap)); - item->setCheckState(0, Qt::Checked); - parent->addChild(item); - item->setHidden(b); -} - -bool -KeyWidget::isChecked(region::RegionId id) -{ - QTreeWidgetItem* current_item = 0; - - foreach(QTreeWidgetItem* item, item_list_) - { - current_item = item->child(id); - if (item) - break; - else - current_item = 0; - } - - if (!current_item) - return false; - - return current_item->checkState(0) == Qt::Checked; -} - -void -KeyWidget::update(QTreeWidgetItem* item_up) -{ - int id = -1; - - foreach(QTreeWidgetItem* item, item_list_) - if (item_up == item) - { - setAllCheck(item); - return; - } - - - int i = 0; - foreach(QTreeWidgetItem* item, item_list_) - { - id = item->indexOfChild(item_up); - if (id != -1) - { - id += base_id_.at(i); - break; - } - ++i; - } - - emit updated(id, item_up->checkState(0) == Qt::Checked); -} - -KeyWidget::~KeyWidget() -{ -} - diff --git a/scribo/demo/viewer/key_widget.hh b/scribo/demo/viewer/key_widget.hh deleted file mode 100644 index 1a3518e..0000000 --- a/scribo/demo/viewer/key_widget.hh +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_KEY_WIDGET_HH -# define SCRIBO_DEMO_VIEWER_KEY_WIDGET_HH - -# include <QtGui> -# include "common.hh" - -class KeyWidget - : public QWidget -{ - Q_OBJECT - -public: - KeyWidget(const region::KeyMap& key_map); - ~KeyWidget(); - - bool isChecked(region::RegionId id); - QTreeWidget* items() { return items_; }; - void update_all(); - -signals: - void updated(int key, bool checked); - -public slots: - void setAll(bool b); - -private slots: - void change_mode(bool b); - void update(QTreeWidgetItem* item); - void setAllCheck(QTreeWidgetItem* parent); - -private: - void add_item_(QString text, QColor color, bool b, QTreeWidgetItem* parent); - - QTreeWidget* items_; - QVector<QTreeWidgetItem*> item_list_; - QVector<int> base_id_; -}; - -#endif // ! SCRIBO_DEMO_VIEWER_KEY_WIDGET_HH diff --git a/scribo/demo/viewer/main.cc b/scribo/demo/viewer/main.cc index 0c50c7b..871cd4f 100644 --- a/scribo/demo/viewer/main.cc +++ b/scribo/demo/viewer/main.cc @@ -1,5 +1,4 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -15,35 +14,26 @@ // You should have received a copy of the GNU General Public License // along with Olena. If not, see http://www.gnu.org/licenses/.
-#include <QtGui> -#include <iostream> - #undef MLN_WO_GLOBAL_VARS -#include "viewer.hh" + +#include <scribo/make/debug_filename.hh> #include <mln/labeling/colorize.hh> -#include <mln/math/pi.hh> #include <mln/io/magick/load.hh> -#include <scribo/make/debug_filename.hh> -#include <mln/debug/filename.hh> #include <mln/literal/colors.hh> +#include <mln/debug/filename.hh> +#include <QtGui/QApplication> +#include <mln/math/pi.hh>
-int main(int argc, char** argv) -{ - if (argc > 2 || - (argc == 2 && - (QString(argv[1]) == "--help" || QString(argv[1]) == "-h"))) - { - std::cout << "Usage:" << std::endl - << argv[0] << " <image dir>" << std::endl; - return 0; - } - - Magick::InitializeMagick(*argv); - - Viewer* viewer = Viewer::Instance(argc, argv); - - if (!viewer) - return -1; +#include "mainwindow.hh"
- return viewer->exec(); +int main(int argc, char *argv[]) +{ + Magick::InitializeMagick(*argv); + // On Linux, we NEED to use the raster graphics system. + // Linux don't really support openGL graphics system (the default one on Linux). + QApplication::setGraphicsSystem("raster"); + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); } diff --git a/scribo/demo/viewer/mainwindow.cc b/scribo/demo/viewer/mainwindow.cc new file mode 100644 index 0000000..97cda4e --- /dev/null +++ b/scribo/demo/viewer/mainwindow.cc @@ -0,0 +1,496 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "mainwindow.hh" +#include "mainwindow.ui.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + setWindowTitle(tr("GScribo")); + showMaximized(); + + initGraphicsRegion(); + initDialogsWidget(); + initXmlWidget(); + initRegionWidget(); + initPageWidget(); + initMenuBar(); + + // Told the left dock widget (here the pages widget and the region + // widget) to fill the bottom left corner. + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); + // Merge the region and pages widget in one tab (pages widget over + // the region widget). + tabifyDockWidget(&dockRegion_, &dockPages_); + + connectWidgets(); +} + +MainWindow::~MainWindow() +{ + delete preferencesDialog_; + delete aboutDialog_; + delete progressDialog_; + delete ui; +} + +void MainWindow::changeEvent(QEvent *e) +{ + QMainWindow::changeEvent(e); + switch (e->type()) + { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void MainWindow::initGraphicsRegion() +{ + graphicsView_.setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); + graphicsView_.setScene(&scene_); + + setCentralWidget(&graphicsView_); +} + +void MainWindow::initDialogsWidget() +{ + preferencesDialog_ = new PreferencesDialog(this); + aboutDialog_ = new AboutDialog(this); + progressDialog_ = new ProgressDialog(this); +} + +void MainWindow::initPageWidget() +{ + dockPages_.setWindowTitle("Pages"); + dockPages_.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); + dockPages_.setWidget(&pagesWidget_); + dockPages_.setMinimumWidth(190); + + addDockWidget(Qt::LeftDockWidgetArea, &dockPages_); +} + +void MainWindow::initRegionWidget() +{ + dockRegion_.setWindowTitle("Regions"); + dockRegion_.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); + dockRegion_.setWidget(®ionWidget_); + + addDockWidget(Qt::LeftDockWidgetArea, &dockRegion_); +} + +void MainWindow::initXmlWidget() +{ + dockXml_.setWindowTitle("Xml"); + dockXml_.setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); + dockXml_.setWidget(&xmlWidget_); + + addDockWidget(Qt::BottomDockWidgetArea, &dockXml_); + dockXml_.setVisible(false); +} + +void MainWindow::initMenuBar() +{ + QMenu *menuFile = ui->menuBar->addMenu(tr("File")); + + menuFile->addAction(tr("&Open"), this, SLOT(onOpen()), + QKeySequence(tr("Ctrl+O"))); + + segment_ = menuFile->addAction(tr("Segment"), this, SLOT(onSegment()), + QKeySequence(tr("Ctrl+S"))); + segment_->setEnabled(false); + + menuFile->addSeparator(); + + previewPrinting_ = menuFile->addAction(tr("Preview Printing"), + this, SLOT(onPreviewPrint()), + QKeySequence(tr("Shift+Ctrl+P"))); + previewPrinting_->setEnabled(false); + + print_ = menuFile->addAction(tr("Print"), this, SLOT(onPrint()), + QKeySequence(tr("Ctrl+P"))); + print_->setEnabled(false); + + menuFile->addSeparator(); + + export_ = menuFile->addAction(tr("&Exportation"), + this, SLOT(onExportation()), + QKeySequence(tr("Ctrl+E"))); + export_->setEnabled(false); + + menuFile->addSeparator(); + + menuFile->addAction(tr("Quit"), this, SLOT(close())); + + ui->menuBar->addAction(tr("Preferences"), + this, SLOT(onPreferences())); + + QMenu *menuAreas = ui->menuBar->addMenu(tr("Window")); + + next_ = menuAreas->addAction(tr("Next document"), + &pagesWidget_, SLOT(selectNextRow()), + QKeySequence(tr("Space"))); + next_->setEnabled(false); + + prev_ = menuAreas->addAction(tr("Previous document"), + &pagesWidget_, SLOT(selectPreviousRow()), + QKeySequence(tr("Backspace"))); + prev_->setEnabled(false); + + menuAreas->addSeparator(); + + QAction *page = menuAreas->addAction(tr("Page"), + &dockPages_, SLOT(switchVisibility())); + page->setCheckable(true); + page->setChecked(true); + + QAction *region = menuAreas->addAction(tr("Region"), + &dockRegion_, SLOT(switchVisibility())); + region->setCheckable(true); + region->setChecked(true); + + QAction *xml = menuAreas->addAction(tr("Xml"), + &dockXml_, SLOT(switchVisibility())); + xml->setCheckable(true); + xml->setChecked(false); + + ui->menuBar->addAction(tr("&About"), this, SLOT(onAbout())); +} + +void MainWindow::setActionsEnabled(bool isSegmented) +{ + segment_->setEnabled(!isSegmented); + print_->setEnabled(isSegmented); + previewPrinting_->setEnabled(isSegmented); +} + +void MainWindow::disableActions() +{ + segment_->setEnabled(false); + print_->setEnabled(false); + previewPrinting_->setEnabled(false); + export_->setEnabled(false); +} + +void MainWindow::connectWidgets() +{ + // Each time the scene rect change (when a new picture is loaded), we fit the scene background rectangle in the view. + connect(&scene_, SIGNAL(sceneRectChanged(QRectF)), + &graphicsView_, SLOT(fitInView(QRectF))); + // When dragging with right click, disable selection. + connect(&graphicsView_, SIGNAL(beginDrag()), + &scene_, SLOT(disableSelection())); + connect(&graphicsView_, SIGNAL(endDrag()), + &scene_, SLOT(enableSelection())); + + // If double click on a picture of the page widget -> draw it on background scene. + connect(&pagesWidget_, SIGNAL(imageSelected(QString)), + this, SLOT(onFileChanged(QString))); + + // Connect the scene to the xml widget and vice versa. + connect(&scene_, SIGNAL(newSelection(QList<RegionItem*>)), + this, SLOT(onRegionSelection(QList<RegionItem*>))); + connect(xmlWidget_.view(), SIGNAL(select(QList<XmlItem*>)), + this, SLOT(onXmlSelect(QList<XmlItem*>))); + connect(xmlWidget_.view(), SIGNAL(unselect(QList<XmlItem*>)), + this, SLOT(onXmlUnselect(QList<XmlItem*>))); + connect(xmlWidget_.view(), SIGNAL(emptySelection()), + &scene_, SLOT(selectBase())); + connect(xmlWidget_.view(), SIGNAL(resetSelection()), + &scene_, SLOT(clearSelection())); + + // Connect the scene with the region widget. + connect(®ionWidget_, SIGNAL(checkStateChanged(GraphicsRegion::Id,bool)), &scene_, SLOT(setVisible(GraphicsRegion::Id,bool))); + + // Connect the xml widget with the region widget. + connect(®ionWidget_, SIGNAL(checkStateChanged(QString)), xmlWidget_.view(), SLOT(setFilterString(QString))); + + connect(&runner_, SIGNAL(progress()), progressDialog_, SLOT(run())); + connect(&runner_, SIGNAL(new_progress_max_value(int)), + progressDialog_, SLOT(setMaximum(int))); + connect(&runner_, SIGNAL(new_progress_label(QString)), + progressDialog_, SLOT(setLabelText(QString))); + connect(&runner_, SIGNAL(finished()), progressDialog_, SLOT(close())); + connect(&runner_, SIGNAL(xml_saved(QString)), + this, SLOT(onXmlSaved(QString))); +} + +void MainWindow::onOpen() +{ + QStringList + paths = QFileDialog::getOpenFileNames(this, "Open Image(s)", + QDir::homePath(), + "Images (*.png *.jpg *.ppm *.bmp)"); + setWindowTitle(tr("GScribo")); + + if(paths.count() > 0) + { + QStringList filenames = pagesWidget_.filenames(); + QString path; + + int counter = 0; + bool isContained; + // Check for an image not already added to the page widget. + do + { + path = paths[counter]; + counter++; + isContained = filenames.contains(path); + } while(isContained && counter < paths.count()); + + if(!isContained) + { + pagesWidget_.addPicture(path, QPixmap(path)); + + // If more than one file, we store it in the page widget. + for(int i = counter; i < paths.count(); i++) + { + // Check if the page widget contains the image. + if(!filenames.contains(paths[i])) + { + path = paths[i]; + pagesWidget_.addPicture(path, QPixmap(path)); + } + } + + pagesWidget_.setCurrentRow(0); + pagesWidget_.scrollToTop(); + } + + // Change current scene. + onFileChanged(path); + } +} + +void MainWindow::onSegment() +{ + QStringList filenames; + + filenames << scene_.backgroundPath(); + + // Run segmentation of page(s). + progressDialog_->reset(); + runner_.start_demat(filenames); +} + +void MainWindow::onPreviewPrint() +{ + QPrinter printer(QPrinter::HighResolution); + printer.setPaperSize(QPrinter::A4); + printer.setResolution(300); + + QPrintPreviewDialog preview(&printer, this); + connect(&preview, SIGNAL(paintRequested(QPrinter*)), + this, SLOT(printScene(QPrinter*))); + + preview.exec(); +} + +void MainWindow::onPrint() +{ + QPrinter printer(QPrinter::HighResolution); + printer.setPaperSize(QPrinter::A4); + printer.setResolution(300); + + QPrintDialog dialog(&printer, this); + dialog.setWindowTitle("Print Document"); + + if(dialog.exec() != QDialog::Accepted) + return; + + printScene(&printer); +} + +void MainWindow::printScene(QPrinter *printer) +{ + QPainter painter(printer); + QStyleOptionGraphicsItem options; + + scene_.backgroundPixmap()->paint(&painter, &options, 0); + + // Paint backwards items first. + printItems(&painter, scene_.root()->childsFrom(GraphicsRegion::TextRegion), + &options); + printItems(&painter, scene_.root()->childsFrom(GraphicsRegion::Image), + &options); + + for(int i = GraphicsRegion::Line; i < GraphicsRegion::Image; i++) + printItems(&painter, + scene_.root()->childsFrom(static_castGraphicsRegion::Id(i)), + &options); + + for(int i = GraphicsRegion::Noise; i <= GraphicsRegion::Meanline; i++) + printItems(&painter, + scene_.root()->childsFrom(static_castGraphicsRegion::Id(i)), + &options); +} + +void MainWindow::printItems(QPainter *painter, + const QList<QGraphicsItem *>& items, + QStyleOptionGraphicsItem *options) +{ + foreach(QGraphicsItem *child, items) + { + if(child->isVisible()) + { + QRect + viewport = scene_.backgroundPixmap()->mapRectFromItem(child, child->boundingRect()).toRect(); + painter->translate(abs(child->boundingRect().x() - viewport.x()), + abs(child->boundingRect().y() - viewport.y())); + child->paint(painter, options); + painter->resetTransform(); + } + } +} + +void MainWindow::onExportation() +{ + QMessageBox messageBox(this); + messageBox.setWindowTitle("Information"); + messageBox.setText("This feature is not available yet"); + messageBox.exec(); + return; + + QFileInfo fileInfo(scene_.backgroundPath()); + QString outputSuggestion = fileInfo.baseName() + ".pdf"; + QString output = QFileDialog::getSaveFileName(0, tr("Export Document As ..."), outputSuggestion, + tr("PDF (*.pdf);; HTML (*.html *.htm")); + + if(!output.isEmpty()) + { + progressDialog_->reset(); + runner_.start_export(scene_.backgroundPath(), xml_.filename(), output); + } +} + +void MainWindow::onXmlSaved(const QString& filename) +{ + xml_.load(filename); + xmlWidget_.changeView(xml_.xmlItem()); + scene_.setRoot(xml_.graphicsItem()); + + setActionsEnabled(true); + export_->setEnabled(xml_.recognized()); +} + +void MainWindow::onFileChanged(const QString& filename) +{ + // If it's not the current scene. + if(scene_.backgroundPath() != filename) + { + QString xmlPath = Xml::getPath(filename); + + if(filename.isEmpty()) + { + xmlPath = QString(); + disableActions(); + } + // Check if the xml file already exists. + else if(!QFile(xmlPath).exists()) + { + xmlPath = QString(); + setActionsEnabled(false); + } + else + setActionsEnabled(true); + + xml_.load(xmlPath); + scene_.changeScene(filename, xml_.graphicsItem()); + xmlWidget_.changeView(xml_.xmlItem()); + export_->setEnabled(xml_.recognized()); + updatePageBrowsing(); + } +} + +void MainWindow::onRegionSelection(QList<RegionItem *> regionItems) +{ + if(!regionItems.isEmpty()) + xmlWidget_.view()->displayOnly(toXmlItems(regionItems)); + else + { + xmlWidget_.view()->reset(); + xmlWidget_.view()->displayAll(); + xmlWidget_.view()->expandAll(); + } +} + +void MainWindow::onXmlChangeSelection(QList<XmlItem *> xmlItems, bool select) +{ + QList<RegionItem *> regionItems = toRegionItems(xmlItems); + + if(!regionItems.isEmpty()) + { + if(select) + scene_.select(regionItems); + else + scene_.unselect(regionItems); + } +} + +QList<RegionItem *> MainWindow::toRegionItems(QList<XmlItem *> xmlItems) const +{ + QList<RegionItem *> regionItems; + XmlItem *child; + foreach(child, xmlItems) + { + if(child->regionItem()) + regionItems << child->regionItem(); + } + + return regionItems; +} + +QList<XmlItem *> MainWindow::toXmlItems(QList<RegionItem *> regionItems) const +{ + QList<XmlItem *> xmlItems; + RegionItem *child; + foreach(child, regionItems) + xmlItems << child->xmlItem(); + + return xmlItems; +} + +void MainWindow::onPreferences() +{ + preferencesDialog_->show(); +} + +void MainWindow::onAbout() +{ + aboutDialog_->show(); +} + +void MainWindow::onXmlSelect(QList<XmlItem *> xmlItems) +{ + onXmlChangeSelection(xmlItems, true); +} + +void MainWindow::onXmlUnselect(QList<XmlItem *> xmlItems) +{ + onXmlChangeSelection(xmlItems, false); +} + +void MainWindow::updatePageBrowsing() +{ + next_->setEnabled(pagesWidget_.haveNextRow()); + prev_->setEnabled(pagesWidget_.havePreviousRow()); +} diff --git a/scribo/demo/viewer/mainwindow.hh b/scribo/demo/viewer/mainwindow.hh new file mode 100644 index 0000000..527b612 --- /dev/null +++ b/scribo/demo/viewer/mainwindow.hh @@ -0,0 +1,130 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef MAINWINDOW_HH +# define MAINWINDOW_HH + +#include <QPrintPreviewDialog> +#include <QGraphicsView> +#include <QPrintDialog> +#include <QMainWindow> +#include <QHBoxLayout> +#include <QDockWidget> +#include <QFileDialog> +#include <QGroupBox> +#include <QPrinter> + +#include "Preferences/preferencesdialog.hh" +#include "Processing/progressdialog.hh" +#include "PagesWidget/pageswidget.hh" +#include "Rendering/graphicsview.hh" +#include "XmlWidget/xmlwidget.hh" +#include "Processing/runner.hh" +#include "Rendering/scene.hh" +#include "regionwidget.hh" +#include "aboutdialog.hh" +#include "dockwidget.hh" +#include "xml.hh" + +namespace Ui +{ + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT; + +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); + +protected: + void changeEvent(QEvent *e); + +private: + void initGraphicsRegion(); + void initDialogsWidget(); + void initPageWidget(); + void initRegionWidget(); + void initXmlWidget(); + void initMenuBar(); + void connectWidgets(); + + void setActionsEnabled(bool isSegmented); + void disableActions(); + + void updatePageBrowsing(); + + void printItems(QPainter *painter, const QList<QGraphicsItem *>& items, QStyleOptionGraphicsItem *options); + + Xml processTmpXml(const QString& filename) const; + QList<RegionItem *> toRegionItems(QList<XmlItem *> regionItems) const; + QList<XmlItem *> toXmlItems(QList<RegionItem *> xmlItems) const; + + Ui::MainWindow *ui; + + DockWidget dockRegion_; + DockWidget dockPages_; + DockWidget dockXml_; + + GraphicsView graphicsView_; + Scene scene_; + + PagesWidget pagesWidget_; + RegionWidget regionWidget_; + + AboutDialog *aboutDialog_; + ProgressDialog *progressDialog_; + PreferencesDialog *preferencesDialog_; + + XmlWidget xmlWidget_; + Xml xml_; + Runner runner_; + + QAction *segment_; + QAction *previewPrinting_; + QAction *print_; + QAction *export_; + + // Browse among documents. + QAction *next_; + QAction *prev_; + +public slots: + void printScene(QPrinter *printer); + +private slots: + void onOpen(); + void onSegment(); + void onPreviewPrint(); + void onPrint(); + void onExportation(); + void onPreferences(); + void onAbout(); + + void onXmlSaved(const QString& filename); + void onFileChanged(const QString& filename); + + void onRegionSelection(QList<RegionItem *> regionItems); + + void onXmlChangeSelection(QList<XmlItem *> xmlItems, bool select); + void onXmlSelect(QList<XmlItem *> xmlItems); + void onXmlUnselect(QList<XmlItem *> xmlItems); +}; + + +#endif // MAINWINDOW_HH diff --git a/GScribo/mainwindow.ui b/scribo/demo/viewer/mainwindow.ui similarity index 100% rename from GScribo/mainwindow.ui rename to scribo/demo/viewer/mainwindow.ui diff --git a/scribo/demo/viewer/ocr_options.cc b/scribo/demo/viewer/ocr_options.cc deleted file mode 100644 index 0ff09d9..0000000 --- a/scribo/demo/viewer/ocr_options.cc +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "defs.hh" -#include "ocr_options.hh" -#include "config.hh" - -// Defines enum of binarization algorithms -# include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - -using namespace scribo::toolchain::internal; - - -static const char *language[][2] = { - { "English", "eng" }, - { "French", "fra" }, - { 0, 0 } -}; - - -ocr_options::ocr_options(QWidget *parent) - : OptionWidget(parent) -{ - setupUi(this); - - for (unsigned i = 0; language[i][0]; ++i) - ocr_language->insertItem(i, language[i][0]); - - load_config(); -} - -ocr_options::~ocr_options() -{ -} - - -int ocr_options::find_index(const QString& lang) -{ - for (unsigned i = 0; language[i][0]; ++i) - if (lang == language[i][1]) - return i; - return 0; -} - - -void ocr_options::load_config() -{ - config * const conf = config::get_instance(); - - enable_ocr->setChecked(conf->ocr_enabled()); - ocr_language->setCurrentIndex(find_index(conf->ocr_language())); -} - - -void ocr_options::save_config() -{ - config * const conf = config::get_instance(); - - conf->set_ocr_enabled(enable_ocr->isChecked()); - conf->set_ocr_language(language[ocr_language->currentIndex()][1]); -} diff --git a/scribo/demo/viewer/ocr_options.hh b/scribo/demo/viewer/ocr_options.hh deleted file mode 100644 index 67ab4ef..0000000 --- a/scribo/demo/viewer/ocr_options.hh +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_OCR_OPTIONS_HH -# define SCRIBO_DEMO_VIEWER_OCR_OPTIONS_HH - -# include <QtGui> -# include <ocr_options.ui.h> -# include "option_widget.hh" - -class ocr_options : public OptionWidget, private Ui::OcrOptions -{ - Q_OBJECT; - -public: - ocr_options(QWidget *parent = 0); - ~ocr_options(); - - void load_config(); - void save_config(); - -private: - int find_index(const QString& lang); - -}; - -#endif // ! SCRIBO_DEMO_VIEWER_OCR_OPTIONS_HH diff --git a/scribo/demo/viewer/ocr_options.ui b/scribo/demo/viewer/ocr_options.ui deleted file mode 100644 index d001c64..0000000 --- a/scribo/demo/viewer/ocr_options.ui +++ /dev/null @@ -1,62 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>OcrOptions</class> - <widget class="QWidget" name="OcrOptions"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>366</width> - <height>112</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QGroupBox" name="enable_ocr"> - <property name="title"> - <string>Enable OCR</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - <property name="flat"> - <bool>true</bool> - </property> - <property name="checkable"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="1"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Language</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QComboBox" name="ocr_language"/> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> diff --git a/scribo/demo/viewer/option_widget.cc b/scribo/demo/viewer/option_widget.cc deleted file mode 100644 index 4557749..0000000 --- a/scribo/demo/viewer/option_widget.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -# include "option_widget.hh" - -OptionWidget::OptionWidget(QWidget * parent) - : QWidget(parent) -{ -} - -void OptionWidget::save_config() -{ -} - -void OptionWidget::load_config() -{ -} diff --git a/scribo/demo/viewer/option_widget.hh b/scribo/demo/viewer/option_widget.hh deleted file mode 100644 index 6b24e90..0000000 --- a/scribo/demo/viewer/option_widget.hh +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_OPTION_WIDGET_HH -# define SCRIBO_DEMO_VIEWER_OPTION_WIDGET_HH - -#include <QWidget> - -struct OptionWidget : public QWidget -{ - OptionWidget(QWidget * parent); - - virtual void load_config(); - virtual void save_config(); -}; - -#endif // ! SCRIBO_DEMO_VIEWER_OPTION_WIDGET_HH diff --git a/scribo/demo/viewer/preferences_dialog.cc b/scribo/demo/viewer/preferences_dialog.cc deleted file mode 100644 index 1eb80a7..0000000 --- a/scribo/demo/viewer/preferences_dialog.cc +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "preferences_dialog.hh" -#include "general_options.hh" -#include "ocr_options.hh" -#include "preprocessing_options.hh" -#include "segmentation_options.hh" - - - -preferences_dialog::preferences_dialog(QWidget *parent) - : QDialog(parent) -{ - setupUi(this); - - // We may want to remove this useless object in the ui file. - delete widget; - - setAttribute(Qt::WA_DeleteOnClose); - - load_option_list(); - optionList->setCurrentRow(0); -} - -preferences_dialog::~preferences_dialog() -{ -} - - -void preferences_dialog::load_option_list() -{ - static const char *options[] = { "General", "Preprocessing", "Segmentation", "OCR", 0 }; - - int i; - for (i = 0; options[i]; ++i) - optionList->insertItem(i, options[i]); - - widgets_.fill(0, i); -} - -void preferences_dialog::on_optionList_currentRowChanged(int row) -{ - select_option_widget(row); -} - - -void preferences_dialog::select_option_widget(int row) -{ - if (row >= widgets_.size()) - { - qDebug() << "select_option_widget - Hu? Something wrong... Invalid row"; - return; - } - - if (!widgets_[row]) - { - QWidget *widget = 0; - - switch (row) - { - case 0: - widget = new general_options(this); - break; - - case 1: - widget = new preprocessing_options(this); - break; - - case 2: - widget = new segmentation_options(this); - break; - - case 3: - widget = new ocr_options(this); - break; - - default: - qDebug() << "select_option_widget - Hu? Something wrong..."; - } - - if (widget) - widgets_[row] = widget; - } - - if (horizontalLayout_2->count() == 2) - { - QWidget *current_widget = horizontalLayout_2->itemAt(1)->widget(); - horizontalLayout_2->removeWidget(current_widget); - current_widget->hide(); - } - - horizontalLayout_2->insertWidget(1, widgets_[row]); - widgets_[row]->show(); -} - - -void preferences_dialog::accept() -{ - for (int i = 0; i < widgets_.size(); ++i) - if (widgets_[i]) - { - static_cast<OptionWidget *>(widgets_[i])->save_config(); - delete widgets_[i]; - } - QDialog::accept(); -} - - -void preferences_dialog::reject() -{ - for (int i = 0; i < widgets_.size(); ++i) - delete widgets_[i]; - QDialog::reject(); -} diff --git a/scribo/demo/viewer/preferences_dialog.hh b/scribo/demo/viewer/preferences_dialog.hh deleted file mode 100644 index 0368bbe..0000000 --- a/scribo/demo/viewer/preferences_dialog.hh +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_PREFERENCES_DIALOG_HH -# define SCRIBO_DEMO_VIEWER_PREFERENCES_DIALOG_HH - -# include <QtGui> -# include <preferences_dialog.ui.h> - -class preferences_dialog : public QDialog, private Ui::PreferencesDialog -{ - Q_OBJECT; - -public: - preferences_dialog(QWidget *parent = 0); - ~preferences_dialog(); - -private slots: - void on_optionList_currentRowChanged(int row); - virtual void accept(); - virtual void reject(); - -private: // Methods - void load_option_list(); - void select_option_widget(int row); - -private: // Attributes - QVector<QWidget *> widgets_; - -}; - -#endif // ! SCRIBO_DEMO_VIEWER_PREFERENCES_DIALOG_HH diff --git a/scribo/demo/viewer/preferences_dialog.ui b/scribo/demo/viewer/preferences_dialog.ui deleted file mode 100644 index 1d40563..0000000 --- a/scribo/demo/viewer/preferences_dialog.ui +++ /dev/null @@ -1,121 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>PreferencesDialog</class> - <widget class="QDialog" name="PreferencesDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>668</width> - <height>418</height> - </rect> - </property> - <property name="windowTitle"> - <string>Preferences</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd%22%3E; -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">Preferences</span></p></body></html></string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QListWidget" name="optionList"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>200</width> - <height>16777215</height> - </size> - </property> - <property name="baseSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - </widget> - </item> - <item> - <widget class="QWidget" name="widget" native="true"/> - </item> - </layout> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>PreferencesDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>PreferencesDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/scribo/demo/viewer/preprocess.cc b/scribo/demo/viewer/preprocess.cc deleted file mode 100644 index fd9a48b..0000000 --- a/scribo/demo/viewer/preprocess.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "preprocess.hh" - -void preprocess::on_progress() -{ - emit progress(); -} - - -void preprocess::on_new_progress_label(const char *label) -{ - QString lbl(label); - emit new_progress_label(label); -} diff --git a/scribo/demo/viewer/preprocess.hh b/scribo/demo/viewer/preprocess.hh deleted file mode 100644 index 4562cfb..0000000 --- a/scribo/demo/viewer/preprocess.hh +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_PREPROCESS_HH -# define SCRIBO_DEMO_VIEWER_PREPROCESS_HH - -# include <QtCore/QObject> -# include <mln/core/image/image2d.hh> -# include <mln/value/rgb8.hh> -# include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - -using namespace scribo::toolchain::internal; - -struct preprocess - : public QObject, - public text_in_doc_preprocess_functor<mln::image2dmln::value::rgb8 > -{ - Q_OBJECT; - - virtual void on_progress(); - virtual void on_new_progress_label(const char *label); - -signals: - void new_progress_label(const QString& label); - void progress(); -}; - -#endif // ! SCRIBO_DEMO_VIEWER_PREPROCESS_HH diff --git a/scribo/demo/viewer/preprocessing_options.cc b/scribo/demo/viewer/preprocessing_options.cc deleted file mode 100644 index 2d55fea..0000000 --- a/scribo/demo/viewer/preprocessing_options.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "defs.hh" -#include "preprocessing_options.hh" -#include "config.hh" - -// Defines enum of binarization algorithms -# include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - -using namespace scribo::toolchain::internal; - -preprocessing_options::preprocessing_options(QWidget *parent) - : OptionWidget(parent) -{ - setupUi(this); - - bin_algoCbox->insertItem(Convert, "Violent convert"); - bin_algoCbox->insertItem(Sauvola, "Local threshold"); - bin_algoCbox->insertItem(SauvolaMs, - "Local threshold multiscale"); - - load_config(); -} - -preprocessing_options::~preprocessing_options() -{ -} - - -void preprocessing_options::load_config() -{ - config * const conf = config::get_instance(); - - subsampleCb->setChecked(conf->preprocessing_subsample()); - remove_bgCb->setChecked(conf->preprocessing_remove_bg()); - deskewCb->setChecked(conf->preprocessing_deskew()); - remove_noiseCb->setChecked(conf->preprocessing_remove_noise()); - bin_algoCbox->setCurrentIndex(conf->preprocessing_bin_algo()); -} - - -void preprocessing_options::save_config() -{ - config * const conf = config::get_instance(); - - conf->set_preprocessing_subsample(subsampleCb->isChecked()); - conf->set_preprocessing_remove_bg(remove_bgCb->isChecked()); - conf->set_preprocessing_deskew(deskewCb->isChecked()); - conf->set_preprocessing_remove_noise(remove_noiseCb->isChecked()); - conf->set_preprocessing_bin_algo(bin_algoCbox->currentIndex()); -} diff --git a/scribo/demo/viewer/preprocessing_options.hh b/scribo/demo/viewer/preprocessing_options.hh deleted file mode 100644 index c676880..0000000 --- a/scribo/demo/viewer/preprocessing_options.hh +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_PREPROCESSING_OPTIONS_HH -# define SCRIBO_DEMO_VIEWER_PREPROCESSING_OPTIONS_HH - -# include <QtGui> -# include <preprocessing_options.ui.h> -# include "option_widget.hh" - -class preprocessing_options : public OptionWidget, private Ui::PreprocessingOptions -{ - Q_OBJECT; - -public: - preprocessing_options(QWidget *parent = 0); - ~preprocessing_options(); - - void load_config(); - void save_config(); - -}; - -#endif // ! SCRIBO_DEMO_VIEWER_PREPROCESSING_OPTIONS_HH diff --git a/scribo/demo/viewer/preprocessing_options.ui b/scribo/demo/viewer/preprocessing_options.ui deleted file mode 100644 index 962cf49..0000000 --- a/scribo/demo/viewer/preprocessing_options.ui +++ /dev/null @@ -1,76 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>PreprocessingOptions</class> - <widget class="QWidget" name="PreprocessingOptions"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>466</width> - <height>198</height> - </rect> - </property> - <property name="windowTitle"> - <string>Configure toolchain</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Binarization method:</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="bin_algoCbox"/> - </item> - </layout> - </item> - <item row="1" column="0"> - <widget class="QCheckBox" name="subsampleCb"> - <property name="text"> - <string>Run on subsampled image</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QCheckBox" name="remove_bgCb"> - <property name="text"> - <string>Remove background (slow)</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QCheckBox" name="deskewCb"> - <property name="text"> - <string>Deskew</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QCheckBox" name="remove_noiseCb"> - <property name="text"> - <string>Remove noise</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>48</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> diff --git a/scribo/demo/viewer/process.cc b/scribo/demo/viewer/process.cc deleted file mode 100644 index 8fa5b9f..0000000 --- a/scribo/demo/viewer/process.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "process.hh" - -process::process(const char *doc_filename) - : super_t(doc_filename) -{ - -} - -void process::on_progress() -{ - emit progress(); -} - - -void process::on_new_progress_label(const char *label) -{ - QString lbl(label); - emit new_progress_label(label); -} - - -void process::on_xml_saved() -{ - QString filename(output_file.c_str()); - emit xml_saved(filename); -} diff --git a/scribo/demo/viewer/process.hh b/scribo/demo/viewer/process.hh deleted file mode 100644 index 09ace43..0000000 --- a/scribo/demo/viewer/process.hh +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_PROCESS_HH -# define SCRIBO_DEMO_VIEWER_PROCESS_HH - -# include <QtCore/QObject> -# include <mln/core/image/image2d.hh> -# include <scribo/toolchain/internal/content_in_doc_functor.hh> - -using namespace scribo::toolchain::internal; - -struct process - : public QObject, - public content_in_doc_functor<mln::image2d<bool> > -{ - Q_OBJECT; - typedef content_in_doc_functor<mln::image2d<bool> > super_t; - -public: - process(const char *doc_filename); - - virtual void on_progress(); - virtual void on_new_progress_label(const char *label); - virtual void on_xml_saved(); - -signals: - void new_progress_label(const QString& label); - void progress(); - void xml_saved(const QString& filename); -}; - -#endif // ! SCRIBO_DEMO_VIEWER_PROCESS_HH diff --git a/scribo/demo/viewer/region.hh b/scribo/demo/viewer/region.hh new file mode 100644 index 0000000..806d8b4 --- /dev/null +++ b/scribo/demo/viewer/region.hh @@ -0,0 +1,72 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef REGION_HH +# define REGION_HH + +#include <QColor> + +namespace GraphicsRegion +{ + // WARNING : The order is important. + enum Id + { + TextRegion, + Line, + + VerticalSeparator, + HorizontalSeparator, + WhiteSpaceSeparator, + + Image, + Noise, + Table, + Maths, + Graphic, + Chart, + + Baseline, + Meanline, + + Text, + Separators, + Miscellaneous, + Typology, + + None + }; + + struct Data + { + QColor color; + QString name; + GraphicsRegion::Id region; + GraphicsRegion::Id parent; + int zValue; + }; +} + +namespace Separator +{ + enum FindSeparator + { + Lines, + Whitespaces, + Both + }; +} + +#endif // REGION_HH diff --git a/scribo/demo/viewer/regionwidget.cc b/scribo/demo/viewer/regionwidget.cc new file mode 100644 index 0000000..a9553ca --- /dev/null +++ b/scribo/demo/viewer/regionwidget.cc @@ -0,0 +1,114 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "regionwidget.hh" + +RegionWidget::RegionWidget(QWidget *parent) : + QTreeWidget(parent) +{ + setHeaderHidden(true); + setSelectionMode(QAbstractItemView::NoSelection); + + addTopLevelItem(createRoot("Text", GraphicsRegion::Text, + GraphicsRegion::TextRegion, + GraphicsRegion::Line)); + addTopLevelItem(createRoot("Typological Lines", GraphicsRegion::Typology, + GraphicsRegion::Baseline, + GraphicsRegion::Meanline)); + addTopLevelItem(createRoot("Separators", GraphicsRegion::Separators, + GraphicsRegion::VerticalSeparator, + GraphicsRegion::WhiteSpaceSeparator)); + addTopLevelItem(createRoot("Miscellaneous", GraphicsRegion::Miscellaneous, + GraphicsRegion::Image, GraphicsRegion::Chart)); + + expandAll(); + + connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), + this, SLOT(checkStateChanged(QTreeWidgetItem*))); +} + +QTreeWidgetItem *RegionWidget::createRoot(const QString& text, + const GraphicsRegion::Id& region, + const GraphicsRegion::Id& begin, + const GraphicsRegion::Id& end) +{ + // Create root. + QTreeWidgetItem *rootItem = createItem(text, region); + + // Fill root with corresponding childs. + for(int region_ = begin; region_ <= end; region_++) + fillRoot(rootItem, static_castGraphicsRegion::Id(region_)); + + return rootItem; +} + +QTreeWidgetItem *RegionWidget::createItem(const QString& text, + const GraphicsRegion::Id& region, + const QColor& color) +{ + QTreeWidgetItem *item = new QTreeWidgetItem; + item->setText(0, text); + item->setCheckState(0, Qt::Checked); + item->setBackgroundColor(0, color); + // Store graphical id in the object to recognize it afterward. + item->setData(0, Qt::UserRole, static_cast<int>(region)); + + return item; +} + +void RegionWidget::checkStateChanged(QTreeWidgetItem *item) +{ + // If it's a root item, go to childs. + if(item->childCount() != 0) + { + QTreeWidgetItem *child; + for(int i = 0; i < item->childCount(); i++) + { + child = item->child(i); + child->setCheckState(0, item->checkState(0)); + } + } + else + { + if(item->checkState(0) == Qt::Checked) + { + filterString_.append('|' + item->text(0)); + emit checkStateChanged(static_castGraphicsRegion::Id(item->data(0, Qt::UserRole).toInt()), true); + } + else + { + filterString_.remove('|' + item->text(0), Qt::CaseSensitive); + emit checkStateChanged(static_castGraphicsRegion::Id(item->data(0, Qt::UserRole).toInt()), false); + } + + //emit checkStateChanged(filterString_); + } +} + + +inline void RegionWidget::fillRoot(QTreeWidgetItem *rootItem, + const GraphicsRegion::Id& region) +{ + GraphicsRegion::Data data = Xml::dataFromRegion(region); + filterString_.append('|' + data.name); + rootItem->addChild(createItem(data.name, region, data.color)); +} + + +inline QString RegionWidget::filterString() const +{ + return filterString_.right(filterString_.count()-1); +} diff --git a/scribo/demo/viewer/regionwidget.hh b/scribo/demo/viewer/regionwidget.hh new file mode 100644 index 0000000..3899ffc --- /dev/null +++ b/scribo/demo/viewer/regionwidget.hh @@ -0,0 +1,58 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef REGIONWIDGET_HH +# define REGIONWIDGET_HH + +#include <QTreeWidget> +#include <QLabel> + +#include "xml.hh" + +class RegionWidget : + public QTreeWidget +{ + Q_OBJECT; + +public: + explicit RegionWidget(QWidget *parent = 0); + + QString filterString() const; + +private: + QTreeWidgetItem *createRoot(const QString& text, + const GraphicsRegion::Id& region, + const GraphicsRegion::Id& begin, + const GraphicsRegion::Id& end); + QTreeWidgetItem *createItem(const QString& text, + const GraphicsRegion::Id& region, + const QColor& color = QColor::fromRgb(255, 255, 255)); + void fillRoot(QTreeWidgetItem *rootItem, + const GraphicsRegion::Id& region); + + QString filterString_; + +private slots: + void checkStateChanged(QTreeWidgetItem *item); + +signals: + void checkStateChanged(const GraphicsRegion::Id& region, + bool checked); + void checkStateChanged(const QString& filterString); +}; + + +#endif // REGIONWIDGET_HH diff --git a/scribo/demo/viewer/runner.cc b/scribo/demo/viewer/runner.cc deleted file mode 100644 index da2f3bf..0000000 --- a/scribo/demo/viewer/runner.cc +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "runner.hh" - -#include <mln/core/image/image2d.hh> -#include <mln/value/rgb8.hh> -#include <mln/io/magick/load.hh> - -#include "demodir.hh" - -#include "process.hh" -#include "preprocess.hh" -#include "config.hh" -#include "defs.hh" - - - -using namespace mln; -using namespace scribo::toolchain::internal; - -static -QString get_pathto(const QString& file, - const QString localdirsuffix = QString()) -{ - QFile f(SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix + "/" + file); - if (f.exists()) - return SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix; - - f.setFileName(SCRIBO_PREFIX_LIBEXECDIR "/" + file); - if (f.exists()) - return SCRIBO_PREFIX_LIBEXECDIR; - - qDebug() << "FATAL ERROR: Can't locate file: " + file; - - return ""; -} - - -runner::runner(QObject *parent) - : QThread(parent) -{ - moveToThread(this); -} - - -void runner::run() -{ - - switch(mode_) - { - default: - case Demat: - { - image2dvalue::rgb8 ima; - io::magick::load(ima, args_.at(0).toUtf8().constData()); - - image2d<bool> bin_ima = preprocess(ima); - process(ima, bin_ima); - } - break; - - case Export: - export_as(); - break; - } - - emit finished(); - qDebug() << "Done."; -} - - -void runner::stop() -{ - terminate(); -} - - - -// Demat related stuff - -void runner::start_demat(const QString& filename) -{ - args_.clear(); - args_ << filename; - mode_ = Demat; - - QThread::start(); -} - - -image2d<bool> -runner::preprocess(const image2dvalue::rgb8& ima) -{ - emit new_step("Preprocessing"); - - ::preprocess f; - - // Load config. - config * const conf = config::get_instance(); - - connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); - connect(&f, SIGNAL(new_progress_label(const QString&)), - this, SIGNAL(new_progress_label(const QString&))); - - f.enable_subsample = conf->preprocessing_subsample(); - f.enable_fg_extraction = conf->preprocessing_remove_bg(); - f.enable_deskew = conf->preprocessing_deskew(); - f.enable_denoising = conf->preprocessing_remove_noise(); - - f.binarization_algo = static_cast<Binarization_Algo>(conf->preprocessing_bin_algo()); - - emit new_progress_max_value(f.nsteps()); - - // Perform preprocessing. - f(ima); - - qDebug() << "Preprocess Done."; - return f.output; -} - - -void runner::process(const image2dvalue::rgb8& original_ima, - const image2d<bool>& processed_ima) -{ - emit new_step("Page segmentation"); - - ::process f(args_.at(0).toUtf8().constData()); - - connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); - connect(&f, SIGNAL(new_progress_label(const QString&)), - this, SIGNAL(new_progress_label(const QString&))); - connect(&f, SIGNAL(xml_saved(const QString&)), - this, SIGNAL(xml_saved(const QString&))); - - // Load config. - config * const conf = config::get_instance(); - - defs::FindSeparators - find_seps = static_castdefs::FindSeparators(conf->segmentation_find_seps()); - f.enable_line_seps = (find_seps == defs::Lines - || find_seps == defs::LinesAndWhitespaces); - f.enable_whitespace_seps = (find_seps == defs::Whitespaces - || find_seps == defs::LinesAndWhitespaces); - f.enable_ocr = conf->ocr_enabled(); - f.ocr_language = conf->ocr_language().toAscii().data(); - f.xml_format = scribo::io::xml::PageExtended; - - - f.save_doc_as_xml = true; - QFileInfo file(args_.at(0)); - QString output_dir = QDir::tempPath(); - if (conf->general_save_xml_enabled()) - { - if (conf->general_save_xml_same_dir()) - output_dir = file.absolutePath(); - else if (conf->general_save_xml_custom_dir()) - output_dir = conf->general_save_xml_custom_dir_path(); - else - qDebug() << "runner::progress - Invalid xml saving option!"; - - QDir dir(output_dir); - if (!dir.exists() && !dir.mkpath(output_dir)) - output_dir = QDir::tempPath(); - } - f.output_file = (output_dir + "/" + file.baseName() + "_gui.xml").toUtf8().constData(); - - emit new_progress_max_value(f.nsteps()); - - // Perform text detection. - f(original_ima, processed_ima); - - qDebug() << "Process Done."; -} - - - -// Export related stuff - -void runner::start_export(const QString& imgfile, - const QString& xmlfile, const QString& outfile) -{ - args_.clear(); - args_ << imgfile << xmlfile << outfile; - mode_ = Export; - - QThread::start(); -} - - -void runner::export_as() -{ - emit new_step("Exporting document..."); - emit new_progress_max_value(2); - - // Checking output format - QFileInfo f(args_.at(2)); - - QString pathto_xml2doc = get_pathto("scribo-xml2doc", "xml2doc"); - - if (pathto_xml2doc.isEmpty()) - { - QMessageBox::critical(0, "Fatal error", "Cannot export! Cannot find scribo-xml2doc program!"); - return; - } - - emit progress(); - - int rvalue = 0; - if (f.suffix() == "pdf") - { - emit new_step("Exporting as PDF..."); - rvalue = system(QString("%1/scribo-xml2doc --pdf %2 %3 %4") - .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) - .arg(args_.at(2)).toAscii().constData()); - } - else if (f.suffix() == "html" || f.suffix() == "htm") - { - emit new_step("Exporting as HTML..."); - rvalue = system(QString("%1/scribo-xml2doc --html %2 %3 %4") - .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) - .arg(args_.at(2)).toAscii().constData()); - } - else - QMessageBox::critical(0, "Fatal error", "Cannot export! Invalid output format!"); - - if (rvalue != 0) - QMessageBox::critical(0, "Fatal error", "Cannot export! Return value is not 0!"); -} diff --git a/scribo/demo/viewer/runner.hh b/scribo/demo/viewer/runner.hh deleted file mode 100644 index 176dcd8..0000000 --- a/scribo/demo/viewer/runner.hh +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_RUNNER_HH -# define SCRIBO_DEMO_VIEWER_RUNNER_HH - -# include <QtGui> - -# include <mln/core/image/image2d.hh> -# include <mln/value/rgb8.hh> - -using namespace mln; - -enum RunMode -{ - Demat, - Export -}; - -class runner : public QThread -{ - Q_OBJECT; - -public: - runner(QObject *parent = 0); - - void start_demat(const QString& filename); - void start_export(const QString& imgfile, - const QString& xmlfile, const QString& outfile); - -public slots: - void stop(); - -signals: - void new_step(const QString& step_name); - void new_progress_max_value(int i); - void new_progress_label(const QString& msg); - void xml_saved(const QString& filename); - void progress(); - void finished(); - -private: // members - image2d<bool> preprocess(const image2dvalue::rgb8& ima); - void process(const image2dvalue::rgb8& original_ima, - const image2d<bool>& processed_ima); - - void export_as(); - - virtual void run(); - - template <typename V> - unsigned find_best_scale(const mln::image2d<V>& ima); - -private: // attributes - QStringList args_; - RunMode mode_; -}; - - -#endif // ! SCRIBO_DEMO_VIEWER_RUNNER_HH diff --git a/scribo/demo/viewer/segmentation_options.cc b/scribo/demo/viewer/segmentation_options.cc deleted file mode 100644 index c120879..0000000 --- a/scribo/demo/viewer/segmentation_options.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "defs.hh" -#include "segmentation_options.hh" -#include "config.hh" - -// Defines enum of binarization algorithms -# include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> - -using namespace scribo::toolchain::internal; - -segmentation_options::segmentation_options(QWidget *parent) - : OptionWidget(parent) -{ - setupUi(this); - - find_sepsCbox->insertItem(defs::Lines, "Lines"); - find_sepsCbox->insertItem(defs::Whitespaces, "Whitespaces"); - find_sepsCbox->insertItem(defs::LinesAndWhitespaces, "Lines and whitespaces"); - - load_config(); -} - -segmentation_options::~segmentation_options() -{ -} - - -void segmentation_options::load_config() -{ - config * const conf = config::get_instance(); - - find_sepsCbox->setCurrentIndex(conf->segmentation_find_seps()); -} - - -void segmentation_options::save_config() -{ - config * const conf = config::get_instance(); - - conf->set_segmentation_find_seps(find_sepsCbox->currentIndex()); -} diff --git a/scribo/demo/viewer/segmentation_options.hh b/scribo/demo/viewer/segmentation_options.hh deleted file mode 100644 index bdf65f9..0000000 --- a/scribo/demo/viewer/segmentation_options.hh +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_SEGMENTATION_OPTIONS_HH -# define SCRIBO_DEMO_VIEWER_SEGMENTATION_OPTIONS_HH - -# include <QtGui> -# include <segmentation_options.ui.h> -# include "option_widget.hh" - -class segmentation_options : public OptionWidget, private Ui::SegmentationOptions -{ - Q_OBJECT; - -public: - segmentation_options(QWidget *parent = 0); - ~segmentation_options(); - - void load_config(); - void save_config(); - -}; - -#endif // ! SCRIBO_DEMO_VIEWER_SEGMENTATION_OPTIONS_HH diff --git a/scribo/demo/viewer/segmentation_options.ui b/scribo/demo/viewer/segmentation_options.ui deleted file mode 100644 index 485e448..0000000 --- a/scribo/demo/viewer/segmentation_options.ui +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SegmentationOptions</class> - <widget class="QWidget" name="SegmentationOptions"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Find separators</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="find_sepsCbox"> - <property name="editable"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </item> - <item row="1" column="0"> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>258</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> diff --git a/scribo/demo/viewer/step_widget.cc b/scribo/demo/viewer/step_widget.cc deleted file mode 100644 index 19b5d0f..0000000 --- a/scribo/demo/viewer/step_widget.cc +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -# include "step_widget.hh" -# include "config.hh" - -StepWidget::StepWidget() - : view_(new QListWidget()), - step_(QString::Null()) -{ - QLabel* title = new QLabel(tr("Steps")); - title->setAlignment(Qt::AlignHCenter); - - QVBoxLayout* layout = new QVBoxLayout; - - layout->addWidget(title); - layout->addWidget(view_); - - view_->setSortingEnabled(true); - - setLayout(layout); - - connect(view_, SIGNAL(itemActivated(QListWidgetItem*)), - this, SLOT(activate(QListWidgetItem*))); - - connect(this, SIGNAL(activated(QListWidgetItem*)), - this, SLOT(activate(QListWidgetItem*))); - -} - -StepWidget::~StepWidget() -{ -} - - -void StepWidget::activate(QListWidgetItem* item) -{ - QString key, value; - - StepQMap::iterator iter = map_.find(item->text()); - - if (iter != map_.end()) - { - view_->setCurrentItem(item); - step_ = item->text(); - key = iter.key(); - value = iter.value(); - - qDebug() << "Loading " << value; - emit load_xml(value); - } - else - qDebug() << "Step not found!"; - - emit step_selected(view_->count()); -} - - -void StepWidget::fill_steps(QString file, bool step, bool container) -{ - view_->clear(); - map_.clear(); - - if (container) - { - emit change_base(true); - // emit load_image(file, true); - emit load_xml(file); - } - else - { - emit change_base(false); - // image is loaded once - emit load_image(file, false); - - - QFileInfo f(file); - file_with_no_ext_ = f.baseName(); - - QStringList dirlist; - dirlist << f.absolutePath() << QDir::tempPath(); - - // Set directories to look at according to settings. - config * const conf = config::get_instance(); - if (conf->general_save_xml_custom_dir()) - dirlist << conf->general_save_xml_custom_dir_path(); - - foreach(QString path, dirlist) - { - QDir dir(path); - - if (dir.isReadable()) - { - QStringList filter; - filter << "*.xml"; - QFileInfoList xml_list = dir.entryInfoList(filter); - for (int i = 0; i < xml_list.size(); ++i) - insert_new_entry(xml_list.at(i)); - } - } - - if ( (step && step_ != QString::Null())) - { - QList<QListWidgetItem*> list = view_->findItems(step_, Qt::MatchContains); - - if (!list.isEmpty()) - emit activated(list.first()); - } - else - { - step_ = QString::Null(); - if (view_->count()) - emit activated(view_->item(0)); - } - } -} - - -QListWidgetItem* StepWidget::insert_new_entry(const QFileInfo& file) -{ - QListWidgetItem *item = 0; - - if (file.fileName().startsWith(file_with_no_ext_)) - { - QString key = file.baseName(); - key.replace(file_with_no_ext_ + QString("_"), QString("")); - key.replace(QRegExp("^step([0-9])"), "Step \1"); - key.replace(QRegExp("^Step ([0-9])_"), "Step \1 : "); - key.replace("_", " "); - - bool exists = (map_.find(key) != map_.end()); - - map_.insertMulti(key, file.absoluteFilePath()); - - if (!exists) - { - item = new QListWidgetItem(key); - view_->addItem(item); - } - else - item = view_->findItems(key, Qt::MatchCaseSensitive).at(0); - } - - return item; -} - - -QListWidgetItem* StepWidget::add_element(const QString& element) -{ - QListWidgetItem *item = new QListWidgetItem(element); - view_->addItem(item); - - return item; -} - -QString StepWidget::current() const -{ - return map_.value(step_); -} - - - - - - diff --git a/scribo/demo/viewer/step_widget.hh b/scribo/demo/viewer/step_widget.hh deleted file mode 100644 index f648ede..0000000 --- a/scribo/demo/viewer/step_widget.hh +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - - -#ifndef SCRIBO_DEMO_VIEWER_STEP_WIDGET_HH_ -# define SCRIBO_DEMO_VIEWER_STEP_WIDGET_HH_ - -# include <QtGui> - -typedef QMap<QString, QString> StepQMap; - -class StepWidget - : public QWidget -{ - Q_OBJECT - -public: - StepWidget(); - ~StepWidget(); - QListWidgetItem* add_element(const QString& element); - - QString current() const; - -signals: - void load_image(QString, bool); - void load_xml(QString); - void activated(QListWidgetItem*); - void change_base(bool); - void step_selected(bool); - -public slots: - void fill_steps(QString file, bool step = false, bool container = false); - void activate(QListWidgetItem* item); - QListWidgetItem* insert_new_entry(const QFileInfo& file); - -private: - QListWidget* view_; - StepQMap map_; - QString step_; - QString file_with_no_ext_; -}; - -#endif // ! SCRIBO_DEMO_VIEWER_STEP_WIDGET_HH_ diff --git a/scribo/demo/viewer/variantpointer.cc b/scribo/demo/viewer/variantpointer.cc new file mode 100644 index 0000000..07213aa --- /dev/null +++ b/scribo/demo/viewer/variantpointer.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +# include <variantpointer.hh> + + +template<typename T> +VariantPointer<T>::VariantPointer() +{ +} + + +template<typename T> +QVariant +VariantPointer<T>::toQVariant(T *pointer) +{ + return QVariant::fromValue(static_cast<void *>(pointer)); +} + + +template<typename T> +T * +VariantPointer<T>::fromQVariant(const QVariant& variant) +{ + return static_cast<T *>(variant.value<void *>()); +} diff --git a/scribo/demo/viewer/variantpointer.hh b/scribo/demo/viewer/variantpointer.hh new file mode 100644 index 0000000..e8aab4b --- /dev/null +++ b/scribo/demo/viewer/variantpointer.hh @@ -0,0 +1,33 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef VARIANTPOINTER_HH +# define VARIANTPOINTER_HH + +#include <QVariant> + +template<typename T> +class VariantPointer +{ +public: + static QVariant toQVariant(T *pointer); + static T *fromQVariant(const QVariant& variant); + +private: + VariantPointer(); +}; + +#endif // VARIANTPOINTER_HH diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc deleted file mode 100644 index 866761d..0000000 --- a/scribo/demo/viewer/viewer.cc +++ /dev/null @@ -1,1021 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - - -#include <iostream> -#include <limits.h> - -#include "viewer.hh" -#include "key_widget.hh" -#include "browser_widget.hh" -#include "xml_widget.hh" -#include "step_widget.hh" -#include "image_scene.hh" -#include "image_view.hh" -#include "image_region.hh" -#include "help_dialog.hh" -#include "preferences_dialog.hh" -#include "runner.hh" -#include "config.hh" - -#include "common.hh" - -Viewer::Viewer(int &argc, char** argv) - : app_ (new QApplication(argc, argv)), - win_ (new QMainWindow()), - image_(0), - scene_(new ImageScene()), - files_(new QDirModel()), - doc_layout_(0), - key_map_(region::RegionIdCount), - no_cache_(false), - extended_mode_(false), - xml_file_(QString::Null()), - base64_(false), - text_(true), - use_image_(true), - pdialog_(win_) -{ - // Key map - // -------- - - key_map_[region::Text] = qMakePair(tr("Text Region"), QColor(0, 200, 0)); - - // Extension - key_map_[region::Line] = qMakePair(tr("Text line"), QColor(255, 0, 0)); - - key_map_[region::Image] = qMakePair(tr("Image"), QColor(255, 120, 0)); - key_map_[region::Noise] = qMakePair(tr("Noise"), QColor(43, 39, 128)); - key_map_[region::Table] = qMakePair(tr("Table"), QColor(220, 246, 0)); - key_map_[region::LineDrawing] = qMakePair(tr("LineDrawing"), - QColor(255, 198, 0)); - key_map_[region::Graphic] = qMakePair(tr("Graphic"), QColor(255, 0, 144)); - key_map_[region::Chart] = qMakePair(tr("Chart"), QColor(0, 204, 255)); - key_map_[region::Maths] = qMakePair(tr("Maths"), QColor(170, 0, 255)); - - // Extension - key_map_[region::HorizontalSeparator] = qMakePair(tr("HorizontalSeparator"), QColor(0, 0, 255)); - key_map_[region::VerticalSeparator] = qMakePair(tr("VerticalSeparator"), QColor(0, 0, 255)); - key_map_[region::WhitespaceSeparator] = qMakePair(tr("Whitespace Separator"), QColor(0, 0, 128)); - - // Extension - key_map_[region::Baseline] = qMakePair(tr("Baseline"), QColor(128, 0, 255)); - key_map_[region::Meanline] = qMakePair(tr("Meanline"), QColor(128, 0, 255)); - - - - // Region ids - // ---------- - - region_ids_["TextRegion"] = region::Text; - - // Extension - region_ids_["Line"] = region::Line; - - region_ids_["ImageRegion"] = region::Image; - region_ids_["NoiseRegion"] = region::Noise; - region_ids_["TableRegion"] = region::Table; - region_ids_["Line_drawingRegion"] = region::LineDrawing; - region_ids_["GraphicRegion"] = region::Graphic; - region_ids_["ChartRegion"] = region::Chart; - region_ids_["MathsRegion"] = region::Maths; - - // Extension - region_ids_["VerticalSeparatorRegion"] = region::VerticalSeparator; - region_ids_["HorizontalSeparatorRegion"] = region::HorizontalSeparator; - region_ids_["WhitespaceSeparatorRegion"] = region::WhitespaceSeparator; - - - - win_->resize(1152, 864); - win_->statusBar(); - - QMenu* file_menu = win_->menuBar()->addMenu(tr("File")); - QMenu* option_menu = win_->menuBar()->addMenu(tr("Options")); - QMenu* view_menu = win_->menuBar()->addMenu(tr("View")); - QMenu* help_menu = win_->menuBar()->addMenu(tr("Help")); - - - // File menu - - QAction *doc_seg_action = create_action("Segment document", file_menu, - "Segment document", "Ctrl+S"); - connect(doc_seg_action, SIGNAL(triggered()), - this, SLOT(run_process())); - file_menu->addAction(doc_seg_action); - - file_menu->addSeparator(); - - export_action_ = create_action("Export as...", file_menu, - "Export as...", "Shift+Ctrl+S"); - connect(export_action_, SIGNAL(triggered()), - this, SLOT(export_as())); - file_menu->addAction(export_action_); - export_action_->setEnabled(false); - - file_menu->addSeparator(); - - QAction *preview_print_action = create_action("Printing preview", file_menu, - "Printint preview", "Ctrl+P"); - connect(preview_print_action, SIGNAL(triggered()), - this, SLOT(preview_print())); - file_menu->addAction(preview_print_action); - preview_print_action->setEnabled(false); - - - QAction *print_action = create_action("Print", file_menu, - "Print", "Ctrl+P"); - connect(print_action, SIGNAL(triggered()), - this, SLOT(print())); - file_menu->addAction(print_action); - print_action->setEnabled(false); - - file_menu->addSeparator(); - - - QAction* quit_action = create_action("Quit", file_menu, - "Exit the program.", "Ctrl+q"); - connect(quit_action, SIGNAL(triggered()), - app_, SLOT(quit())); - file_menu->addAction(quit_action); - - // Option menu - - QAction* preferences_action_ = create_action("Preferences", option_menu, - "Preferences", "Ctrl+Alt+P"); - preferences_action_->setCheckable(false); - connect(preferences_action_, SIGNAL(triggered(bool)), - this, SLOT(on_preferences())); - option_menu->addAction(preferences_action_); - - - // View menu - - outline_action_ = create_action("Draw outline", view_menu, - "Draw region outlines.", "Ctrl+o"); - outline_action_->setCheckable(true); - outline_action_->setChecked(true); - connect(outline_action_, SIGNAL(toggled(bool)), - this, SIGNAL(setOutline(bool))); - view_menu->addAction(outline_action_); - - precise_action_ = create_action("Precise outline", view_menu, - "1px outline relative to the image " - "(1px relative to the view if off).", - "Shift+Ctrl+p"); - precise_action_->setCheckable(true); - precise_action_->setChecked(false); - connect(precise_action_, SIGNAL(toggled(bool)), - this, SIGNAL(setPrecise(bool))); - view_menu->addAction(precise_action_); - - fill_action_ = create_action("Fill regions", view_menu, - "Color the inside of regions.", "Ctrl+f"); - fill_action_->setCheckable(true); - fill_action_->setChecked(true); - connect(fill_action_, SIGNAL(toggled(bool)), - this, SIGNAL(setFill(bool))); - view_menu->addAction(fill_action_); - - QAction* cache_action = create_action("Disable cache", view_menu, - "Disable the image cache (useful for" - " large images).", "Ctrl+c"); - cache_action->setCheckable(true); - cache_action->setChecked(false); - connect(cache_action, SIGNAL(toggled(bool)), - this, SLOT(useCache(bool))); - view_menu->addAction(cache_action); - - - QAction* extended_action = create_action("Extended mode", view_menu, - "If enabled, some features " - "not supported by ICDAR" - " are added such as text regions" - "or text lines", "Ctrl+e"); - extended_action->setCheckable(true); - extended_action->setChecked(false); - connect(extended_action, SIGNAL(toggled(bool)), - this, SLOT(useExtended(bool))); - view_menu->addAction(extended_action); - - QAction* show_image_action = create_action("Show pictures", view_menu, - "Display pictures on the scene or not", - "Ctrl+i"); - show_image_action->setCheckable(true); - show_image_action->setChecked(true); - connect(show_image_action, SIGNAL(toggled(bool)), - this, SLOT(useImage(bool))); - view_menu->addAction(show_image_action); - - QAction* show_text_action = create_action("Show text", view_menu, - "Show detected text inside boxes.", - "Ctrl+t"); - show_text_action->setCheckable(true); - show_text_action->setChecked(true); - connect(show_text_action, SIGNAL(toggled(bool)), - this, SLOT(useText(bool))); - view_menu->addAction(show_text_action); - - key_wgt_ = new KeyWidget(key_map_); - QAction *show_region_action = create_action("Show regions", view_menu, - "Display regions that are present in" - " the XML file.", - "Ctrl+r"); - show_region_action->setCheckable(true); - show_region_action->setChecked(true); - connect(show_region_action, SIGNAL(toggled(bool)), - key_wgt_, SLOT(setAll(bool))); - view_menu->addAction(show_region_action); - - // Help menu - - QAction* about_action = create_action("About", help_menu, - "About this program", - "Ctrl+h"); - connect(about_action, SIGNAL(triggered()), - this, SLOT(help())); - help_menu->addAction(about_action); - - // Layout - - QSplitter* h_splitter = new QSplitter(); - QSplitter* v_splitter = new QSplitter(Qt::Vertical); - QSplitter* v_splitter2 = new QSplitter(Qt::Vertical); - - step_widget_ = new StepWidget(); - XmlWidget* xml_wgt = new XmlWidget(); - browser_wgt_ = new BrowserWidget(files_, argc != 2 ? QString() : argv[1]); - image_wgt_ = new ImageWidget(scene_); - - connect(step_widget_, SIGNAL(step_selected(bool)), - export_action_, SLOT(setEnabled(bool))); - connect(step_widget_, SIGNAL(step_selected(bool)), - print_action, SLOT(setEnabled(bool))); - connect(step_widget_, SIGNAL(step_selected(bool)), - preview_print_action, SLOT(setEnabled(bool))); - - scene_->setBackgroundBrush(scene_->palette().window()); - - v_splitter->addWidget(step_widget_); - v_splitter->addWidget(key_wgt_); - v_splitter->addWidget(browser_wgt_); - - v_splitter2->addWidget(image_wgt_); - v_splitter2->addWidget(xml_wgt); - - h_splitter->addWidget(v_splitter); - h_splitter->addWidget(v_splitter2); - - win_->setCentralWidget(h_splitter); - - QList<int> v_sizes; - v_sizes << 200 << 250 << 350; - v_splitter->setSizes(v_sizes); - - QList<int> v_sizes2; - v_sizes2 << 725 << 175; - v_splitter2->setSizes(v_sizes2); - - QList<int> h_sizes; - h_sizes << 200 << 900; - h_splitter->setSizes(h_sizes); - - connect(browser_wgt_, SIGNAL(activated(QString, bool, bool)), - step_widget_, SLOT(fill_steps(QString, bool, bool))); - - connect(step_widget_, SIGNAL(change_base(bool)), - this, SLOT(change_base(bool))); - connect(step_widget_, SIGNAL(load_image(QString, bool)), - this, SLOT(load(QString, bool))); - connect(step_widget_, SIGNAL(load_xml(QString)), - this, SLOT(load_xml(QString))); - - connect(this, SIGNAL(mode_changed(bool)), - key_wgt_, SLOT(change_mode(bool))); - connect(this, SIGNAL(updated()), - image_wgt_, SLOT(update())); - connect(this, SIGNAL(fill_xml(QString)), - xml_wgt, SLOT(fill_widget(QString))); - - connect(key_wgt_, SIGNAL(updated(int, bool)), - this, SIGNAL(key_updated(int, bool))); - - connect(scene_, SIGNAL(selected(QString, QString)), - xml_wgt, SLOT(select(QString, QString))); - connect(scene_, SIGNAL(deselected()), - xml_wgt, SLOT(deselect())); - - connect(image_wgt_, SIGNAL(scaleUpdated(qreal)), - this, SLOT(maybeChangeCacheMode(qreal))); - - - // Progress dialog and process runner. - pdialog_.setModal(true); - pdialog_.setAutoClose(false); - pdialog_.setCancelButton(0); - connect(&runner_, SIGNAL(finished()), &pdialog_, SLOT(close())); - - connect(&runner_, SIGNAL(new_step(const QString&)), - &pdialog_, SLOT(setWindowTitle(const QString&))); - connect(&runner_, SIGNAL(new_progress_max_value(int)), - &pdialog_, SLOT(setMaximum(int))); - connect(&runner_, SIGNAL(new_progress_label(const QString&)), - &pdialog_, SLOT(setLabelText(const QString&))); - connect(&runner_, SIGNAL(progress()), - this, SLOT(run_progress())); - connect(&runner_, SIGNAL(xml_saved(const QString&)), - this, SLOT(on_xml_saved(const QString&))); - - extended_action->setChecked(true); -} - - -Viewer::~Viewer() -{ - // Remove temporary xml files. - foreach(QString file, tmp_files_to_remove_) - QFile::remove(file); -} - -void -Viewer::add_text(QDomNode line) -{ - - int a_height = line.toElement().attribute("aHeight", "0").toInt(); - int d_height = line.toElement().attribute("dHeight", "0").toInt(); - int x_height = line.toElement().attribute("xHeight", "0").toInt(); - - if (d_height < 0) - d_height = -d_height; - - if ( (a_height - x_height) < (d_height)) - a_height = x_height + d_height; - - if ( (a_height - x_height) > (d_height)) - d_height = a_height - x_height; - - QDomNode coords = line.firstChild(); - - while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) - coords = coords.nextSibling(); - - if (coords.isNull()) - { - qDebug() << "Warning : textline without coordinates..."; - return; - } - - QDomNode point = coords.firstChild(); - - int x_min = INT_MAX; - int y_min = INT_MAX; - - while (!point.isNull()) - { - int x = point.toElement().attribute("x", "0").toInt(); - int y = point.toElement().attribute("y", "0").toInt(); - - if (x < x_min) - x_min = x; - - if (y < y_min) - y_min = y; - - point = point.nextSibling(); - } - - QString text = line.toElement().attribute("text", ""); - QFont font("Times"); - font.setPixelSize(a_height + d_height); - QGraphicsTextItem* text_item = scene_->addText(text, font); - text_item->setPos(x_min, y_min); - text_item->setTextInteractionFlags(Qt::TextSelectableByMouse); - text_item->setZValue(5); - text_vector_ << text_item; - if (!text_) - scene_->removeItem(text_item); - -} - -void -Viewer::add_region(QDomNode father, QString attr_id) -{ - QDomNode coords = father.firstChild(); - QString name = father.toElement().tagName(); - region::RegionId id = static_castregion::RegionId(region_ids_[name]); - - while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) - coords = coords.nextSibling(); - - if (coords.isNull()) - { - qDebug() << "Warning : add_region - region without coordinates"; - return; - } - - QDomNode point = coords.firstChild(); - QVector<QPoint> points; - - while (!point.isNull()) - { - int x = point.toElement().attribute("x", "0").toInt(); - int y = point.toElement().attribute("y", "0").toInt(); - - points << QPoint(x, y); - point = point.nextSibling(); - } - - ImageRegion* r = new ImageRegion(id, - key_map_[id].first, - key_map_[id].second, - attr_id, points, - outline_action_->isChecked(), - fill_action_->isChecked(), - precise_action_->isChecked(), - key_wgt_->isChecked(id)); - - connect(this, SIGNAL(key_updated(int, bool)), - r, SLOT(setDrawIfSameId(int, bool))); - connect(this, SIGNAL(setOutline(bool)), - r, SLOT(setOutline(bool))); - connect(this, SIGNAL(setPrecise(bool)), - r, SLOT(setPrecise(bool))); - connect(this, SIGNAL(setFill(bool)), - r, SLOT(setFill(bool))); - - scene_->addItem(r); -} - - -void -Viewer::add_typo_lines(QDomNode father, QString attr_id) -{ - // Retrieve typographical information - int baseline = father.toElement().attribute("baseline").toInt(); - int meanline = father.toElement().attribute("meanline").toInt(); - - QRect bbox; - - // Looking for bbox coordinates. - { - QDomNode coords = father.firstChild(); - while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) - coords = coords.nextSibling(); - - if (coords.isNull()) - return; - - - QDomNode point = coords.firstChild(); - QVector<QPoint> points; - - while (!point.isNull()) - { - int x = point.toElement().attribute("x", "0").toInt(); - int y = point.toElement().attribute("y", "0").toInt(); - - points << QPoint(x, y); - point = point.nextSibling(); - } - - QPolygon polygon(points); - bbox = polygon.boundingRect(); - } - - // Creating blocks - - // Baseline - { - QVector<QPoint> points; - points.append(QPoint(bbox.topLeft().x(), baseline)); - points.append(QPoint(bbox.topRight().x(), baseline)); - - ImageRegion* r = new ImageRegion(region::Baseline, - key_map_[region::Baseline].first, - key_map_[region::Baseline].second, - attr_id, points, - outline_action_->isChecked(), - fill_action_->isChecked(), - precise_action_->isChecked(), - key_wgt_->isChecked(region::Baseline)); - - connect(this, SIGNAL(key_updated(int, bool)), - r, SLOT(setDrawIfSameId(int, bool))); - connect(this, SIGNAL(setOutline(bool)), - r, SLOT(setOutline(bool))); - connect(this, SIGNAL(setPrecise(bool)), - r, SLOT(setPrecise(bool))); - connect(this, SIGNAL(setFill(bool)), - r, SLOT(setFill(bool))); - - scene_->addItem(r); - } - - // Meanline - { - QVector<QPoint> points; - points.append(QPoint(bbox.topLeft().x(), meanline)); - points.append(QPoint(bbox.topRight().x(), meanline)); - - ImageRegion* r = new ImageRegion(region::Meanline, - key_map_[region::Meanline].first, - key_map_[region::Meanline].second, - attr_id, points, - outline_action_->isChecked(), - fill_action_->isChecked(), - precise_action_->isChecked(), - key_wgt_->isChecked(region::Meanline)); - - connect(this, SIGNAL(key_updated(int, bool)), - r, SLOT(setDrawIfSameId(int, bool))); - connect(this, SIGNAL(setOutline(bool)), - r, SLOT(setOutline(bool))); - connect(this, SIGNAL(setPrecise(bool)), - r, SLOT(setPrecise(bool))); - connect(this, SIGNAL(setFill(bool)), - r, SLOT(setFill(bool))); - - scene_->addItem(r); - } -} - - -void -Viewer::load_xml(QString filename) -{ - app_->setOverrideCursor(QCursor(Qt::WaitCursor)); - emit fill_xml(filename); - - if (image_ && image_->scene() && image_->scene() == scene_) - scene_->removeItem(image_); - - text_vector_.clear(); - image_vector_.clear(); - scene_->clear(); - - if (!base64_ && use_image_ && image_) - scene_->addItem(image_); - - scene_->update(); - - xml_file_ = filename; - QFile f_in(xml_file_); - f_in.open(QIODevice::ReadOnly); - - QDomDocument doc; - doc.setContent(&f_in); - f_in.close(); - - QDomElement root = doc.documentElement(); - QDomNode page = root.firstChild(); - - while (!page.isNull() && !page.toElement().tagName().contains("Page")) - page = page.nextSibling(); - - if (page.isNull()) - return; - - int width = page.toElement().attribute("imageWidth", "none").toInt(); - int height = page.toElement().attribute("imageHeight", "none").toInt(); - - scene_->setSceneRect(0, 0, width, height); - - QDomNode region = page.firstChild(); - - while (!region.isNull()) - { - if (region.toElement().tagName().contains(QRegExp("(WhitespaceSeparator|Image|Graphic|Chart|Separator|Table|Text)Region"))) - { - QString attr_id = region.toElement().attribute("id", "none"); - add_region(region, attr_id); - - if ( base64_ && - region.toElement().tagName().contains(QRegExp("(Image|Graphic|Chart|Separator|Table)Region"))) - { - QDomNode container = region.firstChild(); - - while (!container.isNull() && !container.toElement().tagName().contains("container")) - container = container.nextSibling(); - - QDomNode coords = region.firstChild(); - - while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) - coords = coords.nextSibling(); - - if (!container.isNull() && !coords.isNull()) - { - QDomNode child = container.firstChild(); - - while (!child.isNull() && !child.toElement().tagName().contains("data")) - child = child.nextSibling(); - - QPixmap pix; - QString data = child.toElement().text(); - QByteArray ba; - ba = ba.append(data); - QByteArray out_ba = QByteArray::fromBase64(ba); - pix.loadFromData(out_ba); - - QGraphicsPixmapItem* image = new QGraphicsPixmapItem(pix); - - QDomNode point = coords.firstChild(); - - int x_min = INT_MAX; - int y_min = INT_MAX; - - while (!point.isNull()) - { - int x = point.toElement().attribute("x", "0").toInt(); - int y = point.toElement().attribute("y", "0").toInt(); - - if (x < x_min) - x_min = x; - - if (y < y_min) - y_min = y; - - point = point.nextSibling(); - } - - image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); - image->setZValue(0); - image->setOffset(x_min, y_min); - if (use_image_) - scene_->addItem(image); - image_vector_ << image; - - if (no_cache_) - image->setCacheMode(QGraphicsItem::NoCache); - else - image->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - - child = child.nextSibling(); - } - } - - if (region.toElement().tagName().contains("TextRegion")) - { - QDomNode line = region.firstChild(); - - do - { - while (!line.isNull() && !line.toElement().tagName().contains("Line")) - line = line.nextSibling(); - - if (!line.isNull()) - { - if (extended_mode_) - { - QString line_id = line.toElement().attribute("id", "none"); - add_region(line, line_id); - add_typo_lines(line, line_id); - } - add_text(line); - } - } - while (!(line = line.nextSiblingElement("Line")).isNull()); - } - } - - region = region.nextSibling(); - } - - //emit updated(); - scene_->update(); - key_wgt_->update_all(); - - app_->restoreOverrideCursor(); -} - -void -Viewer::load(QString filename, bool b) -{ - app_->setOverrideCursor(QCursor(Qt::WaitCursor)); - - scene_->clear(); - text_vector_.clear(); - image_vector_.clear(); - scene_->update(); - image_ = 0; - xml_file_ = QString::Null(); - - // Load the image in a pixmap that is directly shown on screen. - // This is very slow when used with the normal rendering system. - // OpenGL might speed up things a bit. - if (b) - image_ = new QGraphicsPixmapItem(load_base64(filename)); - else - image_ = new QGraphicsPixmapItem(QPixmap(filename)); - - current_image_ = filename; - - image_->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); - image_->setZValue(0); - if (use_image_) - scene_->addItem(image_); - - if (no_cache_) - image_->setCacheMode(QGraphicsItem::NoCache); - else - image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - - app_->restoreOverrideCursor(); - emit updated(); - - app_->restoreOverrideCursor(); -} - -int -Viewer::exec() -{ - win_->show(); - return app_->exec(); -} - -void -Viewer::help() -{ - HelpDialog dlg; - dlg.exec(); -} - -void -Viewer::maybeChangeCacheMode(qreal scale) -{ - if (image_) - { - if (scale >= 0.7) - image_->setCacheMode(QGraphicsItem::NoCache); - else if (!no_cache_) - image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - } -} - -void Viewer::useExtended(bool b) -{ - extended_mode_ = b; - key_wgt_->update_all(); - - if (xml_file_ != QString::Null()) - load_xml(xml_file_); - - emit mode_changed(b); -} - -void -Viewer::useCache(bool b) -{ - no_cache_ = b; - if (b) - { - if (image_) - image_->setCacheMode(QGraphicsItem::NoCache); - } - else - if (image_) - image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache); -} - -QPixmap Viewer::load_base64(QString xml) -{ - QPixmap pix; - QFile f_in(xml); - f_in.open(QIODevice::ReadOnly); - - QDomDocument doc; - doc.setContent(&f_in); - f_in.close(); - - QDomElement root = doc.documentElement(); - QDomNode child = root.firstChild(); - - while (!child.isNull() && !child.toElement().tagName().contains("Page")) - child = child.nextSibling(); - - child = child.firstChild(); - while (!child.isNull()) - { - if (child.toElement().tagName().contains(QRegExp("ImageRegion"))) - { - QDomNode node = child.firstChild(); - QString id = child.toElement().attribute("id", "none"); - - while (!node.isNull() && !node.toElement().tagName().contains("container")) - node = node.nextSibling(); - - if (!node.isNull()) - { - QString data = node.firstChildElement("data").text(); - QByteArray ba; - ba = ba.append(data); - QByteArray out_ba = QByteArray::fromBase64(ba); - pix.loadFromData(out_ba); - - return pix; - } - } - child = child.nextSibling(); - } - - return pix; -} - -void -Viewer::useText(bool b) -{ - text_ = b; - if (!b) - { - for (int i = 0; i < text_vector_.size(); ++i) - scene_->removeItem(text_vector_[i]); - } - else - { - for (int i = 0; i < text_vector_.size(); ++i) - scene_->addItem(text_vector_[i]); - } - - scene_->update(); -} - -void -Viewer::useImage(bool b) -{ - use_image_ = b; - if (!b) - { - if (image_ && image_->scene() && image_->scene() == scene_) - scene_->removeItem(image_); - - for (int i = 0; i < image_vector_.size(); ++i) - scene_->removeItem(image_vector_[i]); - } - else - { - if (image_ && image_->scene() == 0) - scene_->addItem(image_); - - for (int i = 0; i < image_vector_.size(); ++i) - scene_->addItem(image_vector_[i]); - } - - scene_->update(); -} - -void -Viewer::change_base(bool b) -{ - base64_ = b; -} - - -QAction -*Viewer::create_action(QString name, QMenu *menu, QString status, QString shortcut) -{ - QAction* action = new QAction(name, menu); - action->setStatusTip(status); - action->setShortcut(QKeySequence(shortcut)); - - return (action); -} - -void -Viewer::on_preferences() -{ - preferences_dialog *win = new preferences_dialog(win_); - win->show(); -} - - -void -Viewer::run_process() -{ - if (!current_image_.isEmpty()) - { - reset_progress_dialog(); - runner_.start_demat(current_image_); - } -} - - -void -Viewer::run_progress() -{ - pdialog_.setValue(pdialog_.value() + 1); -} - - -void -Viewer::on_xml_saved(const QString& filename) -{ - config * const conf = config::get_instance(); - - if (!conf->general_save_xml_enabled()) - tmp_files_to_remove_.insert(filename); - - QListWidgetItem *item = step_widget_->insert_new_entry(filename); - step_widget_->activate(item); -} - - -void -Viewer::export_as() -{ - QFileInfo f(browser_wgt_->current()); - QString output_suggestion = f.baseName() + ".pdf"; - QString output = QFileDialog::getSaveFileName(0, "Export document as...", output_suggestion, tr("PDF (*.pdf);; HTML (*.html *.htm)")); - - if (!output.isEmpty()) - { - reset_progress_dialog(); - runner_.start_export(browser_wgt_->current(), step_widget_->current(), output); - qDebug() << "Saving to " << output << " - " << browser_wgt_->current() << " - " << step_widget_->current(); - } -} - - -void -Viewer::reset_progress_dialog() -{ - pdialog_.setValue(0); - pdialog_.setLabelText(""); - pdialog_.show(); -} - - -void -Viewer::print() -{ - QPrinter printer(QPrinter::HighResolution); - configure_printer(printer); - - QPrintDialog dialog(&printer); - dialog.setWindowTitle(tr("Print Document")); - if (dialog.exec() != QDialog::Accepted) - return; - - do_print(&printer); -} - -void -Viewer::preview_print() -{ - QPrinter printer(QPrinter::HighResolution); - configure_printer(printer); - - QPrintPreviewDialog preview(&printer); - connect(&preview, SIGNAL(paintRequested(QPrinter *)), - this, SLOT(do_print(QPrinter *))); - - preview.exec(); -} - -void Viewer::do_print(QPrinter * printer) -{ - QList<QGraphicsItem *> items = image_wgt_->view()->items(); - - QPainter painter(printer); - - QGraphicsItem *item; - QStyleOptionGraphicsItem options; - - // Painting backward objects first. - for (int i = items.size() - 1; i >= 0; --i) - { - item = items.at(i); - - if (item != image_) - { - QRect vport = image_->mapRectFromItem(item, - item->boundingRect()).toRect(); - - painter.translate(std::abs(item->boundingRect().x() - vport.x()), - std::abs(item->boundingRect().y() - vport.y())); - } - - - item->paint(&painter, &options); - painter.resetTransform(); - } -} - -void -Viewer::configure_printer(QPrinter& printer) -{ - printer.setPageSize(QPrinter::A4); - printer.setResolution(300); -} diff --git a/scribo/demo/viewer/viewer.hh b/scribo/demo/viewer/viewer.hh deleted file mode 100644 index c68dd02..0000000 --- a/scribo/demo/viewer/viewer.hh +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_VIEWER_HH -# define SCRIBO_DEMO_VIEWER_VIEWER_HH - -# include <QtGui> -# include <QDomNode> -# include "common.hh" -# include "runner.hh" -# include "image_widget.hh" - -class ImageScene; -class DomModel; -class KeyWidget; -class ImageRegion; -class StepWidget; -class BrowserWidget; - - -class Viewer - : public QObject -{ - Q_OBJECT - -public: - ~Viewer(); - - static Viewer* Instance(int &argc, char** argv); - - int exec(); - -public slots: - // Load the file as an image, load the layout if xml with the same - // name is found. - void load(QString filename, bool b); - void help(); - void load_xml(QString filename); - void maybeChangeCacheMode(qreal scale); - void useCache(bool b); - void useExtended(bool b); - void useText(bool b); - void useImage(bool b); - void change_base(bool b); - -private slots: - void on_preferences(); - void run_process(); - void run_progress(); - void on_xml_saved(const QString& filename); - void export_as(); - void print(); - void preview_print(); - void do_print(QPrinter * printer); - -signals: - void updated(); - void key_updated(int key, bool checked); - void setOutline(bool b); - void setPrecise(bool b); - void setFill(bool b); - void mode_changed(bool b); - void fill_xml(QString); - -private: - Viewer(int &argc, char** argv); - Viewer(); - - void xml_to_layout(); - QPixmap load_base64(QString xml); - void add_region(QDomNode father, QString attr_id); - void add_text(QDomNode line); - void add_typo_lines(QDomNode father, QString attr_id); - QAction *create_action(QString name, QMenu* menu, QString status, QString shortcut); - void reset_progress_dialog(); - void configure_printer(QPrinter& printer); - - QApplication* app_; - QMainWindow* win_; - StepWidget* step_widget_; - BrowserWidget* browser_wgt_; - - QGraphicsPixmapItem* image_; - - ImageScene* scene_; - ImageWidget* image_wgt_; - QDirModel* files_; - DomModel* doc_layout_; - - QAction* outline_action_; - QAction* fill_action_; - QAction* precise_action_; - QAction *export_action_; - - KeyWidget* key_wgt_; - - QMap<QString, int> region_ids_; - region::KeyMap key_map_; - - bool no_cache_; - bool extended_mode_; - QString xml_file_; - bool base64_; - bool text_; - bool use_image_; - QVector<QGraphicsTextItem *> text_vector_; - QVector<QGraphicsPixmapItem*> image_vector_; - QString current_image_; - - QProgressDialog pdialog_; - runner runner_; - - QSet<QString> tmp_files_to_remove_; -}; - -#include "viewer.hxx" - -#endif // ! SCRIBO_DEMO_VIEWER_VIEWER_HH diff --git a/scribo/demo/viewer/viewer.hxx b/scribo/demo/viewer/viewer.hxx deleted file mode 100644 index cba59f3..0000000 --- a/scribo/demo/viewer/viewer.hxx +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef VIEWER_HXX_ -# define VIEWER_HXX_ - -# include "viewer.hh" - -inline Viewer* Viewer::Instance(int &argc, char** argv) -{ - static Viewer viewer(argc, argv); - - return &viewer; -} - -#endif /* !VIEWER_HXX_ */ diff --git a/scribo/demo/viewer/viewer.qrc b/scribo/demo/viewer/viewer.qrc deleted file mode 100644 index c64fdcc..0000000 --- a/scribo/demo/viewer/viewer.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="icons"> - <file>icons/olena_smaller.jpg</file> - </qresource> -</RCC> diff --git a/scribo/demo/viewer/xml.cc b/scribo/demo/viewer/xml.cc new file mode 100644 index 0000000..74c9112 --- /dev/null +++ b/scribo/demo/viewer/xml.cc @@ -0,0 +1,253 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#include "xml.hh" + +Xml::Xml(const QString& filename) +{ + load(filename); +} + +QString Xml::getPath(const QString& filename) +{ + Configs *const configs = 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 configs->generalSaveXmlCustomDirPath() + "/" + xmlPath; +} + +void Xml::isRecognized(const QDomElement& textElement) +{ + QDomElement lineElement = textElement.firstChild().nextSiblingElement("Line"); + + // Check if the attributes "text" exists in the attributes of line in the xml file. + isRecognized_ = lineElement.attributeNode("text").isNull() ? false : true; +} + +void Xml::load(const QString& filename) +{ + if(filename.isEmpty()) + { + xmlItem_ = 0; + graphicsItem_ = 0; + filename_ = QString(); + isRecognized_ = false; + return; + } + + // Reset graphic and tree items; + xmlItem_ = new XmlItem; + graphicsItem_ = new RootGraphicsItem(13); + filename_ = getPath(filename); + + QFile xmlFile(filename); + xmlFile.open(QIODevice::ReadOnly); + + // Fill new xml tree. + xml_.clear(); + xml_.setContent(&xmlFile); + + xmlFile.close(); + + QDomElement root = xml_.documentElement(); + xmlItem_->load(root); + xmlItem_->show(); + + root = root.firstChild().toElement(); + XmlItem *parentTreeItem = init(root, xmlItem_); + + // Run through the xml file structure by structure. + root = root.nextSibling().firstChild().toElement(); + // Check if the xml file has been recognized by the ocr or not. + isRecognized(root); + + processNode(root, datas_[0], parentTreeItem); + for(int i = 2; i < 11; i++) + processNode(root.nextSiblingElement(datas_[i].name), datas_[i], parentTreeItem); +} + +XmlItem *Xml::init(const QDomElement& root, XmlItem *rootTreeItem) +{ + XmlItem *metadataItem = new XmlItem(root, rootTreeItem); + + XmlItem *contentItem = 0; + + // Run through "METADATA" node and subnodes. + QDomElement node = root.firstChild().toElement(); + while(!node.isNull()) + { + contentItem = new XmlItem(node, metadataItem, contentItem); + node = node.nextSibling().toElement(); + } + + // Add "PAGE" root node and return it. + metadataItem = new XmlItem(root.nextSibling().toElement(), rootTreeItem, metadataItem); + metadataItem->show(); + + return metadataItem; +} + +void Xml::processNode(const QDomElement& root, const GraphicsRegion::Data& data, XmlItem *pageItem) +{ + if(!root.isNull()) + { + // Create corresponding tree item. + XmlItem *regionItem = new XmlItem(root, pageItem); + + QDomElement node = root.firstChild().toElement(); + XmlItem *coordsItem = new XmlItem(node, regionItem); + + QPolygon polygon; + XmlItem *pointItem = 0; + QString x, y; + + // Run through all points data. + node = node.firstChild().toElement(); + while(!node.isNull()) + { + x = node.attribute("x", "null"); + y = node.attribute("y", "null"); + + pointItem = new XmlItem(node, coordsItem, pointItem); + + polygon << QPoint(x.toInt(), y.toInt()); + node = node.nextSibling().toElement(); + } + + // Create the graphics item from data structure. + RegionItem *graphicsItem = new RegionItem(polygon, graphicsItem_); + graphicsItem->loadData(data); + graphicsItem_->addItemFrom(graphicsItem, data.region); + + // Store xml item and graphics item in each object for selection. + regionItem->setRegionItem(graphicsItem); + graphicsItem->setXmlItem(regionItem); + + if(data.region == GraphicsRegion::TextRegion) + 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, XmlItem *precItem) +{ + if(!root.isNull()) + { + // Create corresponding tree item. + XmlItem *lineItem = new XmlItem(root, precItem->parent(), precItem); + + QDomElement node = root.firstChild().toElement(); + XmlItem *coordsItem = new XmlItem(node, lineItem); + + QPolygon polygon; + XmlItem *pointItem = 0; + + QString xs, ys; + int x, y; + + int xMin = INT_MAX; + int xMax = INT_MIN; + + // Run through all points data. + node = node.firstChild().toElement(); + while(!node.isNull()) + { + xs = node.attribute("x", "null"); + ys = node.attribute("y", "null"); + + pointItem = new XmlItem(node, coordsItem, pointItem); + + x = xs.toInt(); + y = ys.toInt(); + + // Get beginning and end of line. + if(xMin > x) + xMin = x; + if(xMax < x) + xMax = x; + + polygon << QPoint(x, y); + node = node.nextSibling().toElement(); + } + + // Create the graphics item from data structure. + RegionItem *graphicsItem = new RegionItem(polygon, graphicsItem_); + graphicsItem->loadData(datas_[1]); + graphicsItem_->addItemFrom(graphicsItem, datas_[1].region); + + // Store xml item and graphics item in each object for selection. + lineItem->setRegionItem(graphicsItem); + graphicsItem->setXmlItem(lineItem); + + // Get meanline and baseline. + processTypoNode(root, QPoint(xMin, xMax)); + // Run through all line nodes recursively. + processLineNode(root.nextSiblingElement(datas_[1].name), lineItem); + } +} + +void Xml::processTypoNode(const QDomElement& root, const QPoint& xPoint) +{ + int yPos = root.attribute("baseline", "null").toInt(); + QGraphicsLineItem *baselineItem = new QGraphicsLineItem(QLine(QPoint(xPoint.x(), yPos), QPoint(xPoint.y(), yPos))); + baselineItem->setZValue(datas_[11].zValue); + graphicsItem_->addItemFrom(baselineItem, datas_[11].region); + + yPos = root.attribute("meanline", "null").toInt(); + QGraphicsLineItem *meanlineItem = new QGraphicsLineItem(QLine(QPoint(xPoint.x(), yPos), QPoint(xPoint.y(), yPos))); + meanlineItem->setZValue(datas_[12].zValue); + graphicsItem_->addItemFrom(meanlineItem, datas_[12].region); +} + + +XmlItem *Xml::xmlItem() +{ + return xmlItem_; +} + +RootGraphicsItem *Xml::graphicsItem() +{ + return graphicsItem_; +} + +QDomDocument Xml::document() const +{ + return xml_; +} + +QString Xml::filename() const +{ + return filename_; +} + +GraphicsRegion::Data Xml::dataFromRegion(GraphicsRegion::Id region) +{ + return datas_[region]; +} + +bool Xml::recognized() const +{ + return isRecognized_; +} diff --git a/scribo/demo/viewer/xml.hh b/scribo/demo/viewer/xml.hh new file mode 100644 index 0000000..c5f59d4 --- /dev/null +++ b/scribo/demo/viewer/xml.hh @@ -0,0 +1,91 @@ +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. + +#ifndef XML_HH +# define XML_HH + +#include <QTreeWidgetItem> +#include <QGraphicsItem> +#include <QStringList> +#include <QDomElement> +#include <QDomAttr> +#include <climits> +#include <QFile> + +#include "Rendering/rootgraphicsitem.hh" +#include "Rendering/regionitem.hh" +#include "XmlWidget/xmlitem.hh" +#include "variantpointer.hh" +#include "configs.hh" +#include "region.hh" + +// WARNING : The order is VERY IMPORTANT (depending on the enum). +static const GraphicsRegion::Data datas_[] = +{ + /* COLOR | NAME | REGION | PARENT | Z */ + { QColor::fromRgb(0, 100, 0, 110), "TextRegion", GraphicsRegion::TextRegion, GraphicsRegion::Text, 1 }, + { QColor::fromRgb(255, 0, 0, 110), "Line", GraphicsRegion::Line, GraphicsRegion::Text, 2 }, + { QColor::fromRgb(0, 0, 255, 110), "VerticalSeparatorRegion", GraphicsRegion::VerticalSeparator, GraphicsRegion::Separators, 2 }, + { QColor::fromRgb(0, 0, 255, 110), "HorizontalSeparatorRegion", GraphicsRegion::HorizontalSeparator, GraphicsRegion::Separators, 2 }, + { QColor::fromRgb(0, 0, 128, 110), "WhitespaceSeparatorRegion", GraphicsRegion::WhiteSpaceSeparator, GraphicsRegion::Separators, 2 }, + { QColor::fromRgb(255, 120, 0, 110), "ImageRegion", GraphicsRegion::Image, GraphicsRegion::Miscellaneous, 1 }, + { QColor::fromRgb(43, 39, 128, 110), "NoiseRegion", GraphicsRegion::Noise, GraphicsRegion::Miscellaneous, 2 }, + { QColor::fromRgb(220, 246, 0, 110), "TableRegion", GraphicsRegion::Table, GraphicsRegion::Miscellaneous, 2 }, + { QColor::fromRgb(170, 0, 255, 110), "MathsRegion", GraphicsRegion::Maths, GraphicsRegion::Miscellaneous, 2 }, + { QColor::fromRgb(255, 0, 144, 110), "GraphicsRegion", GraphicsRegion::Graphic, GraphicsRegion::Miscellaneous, 2 }, + { QColor::fromRgb(0, 204, 255, 110), "ChartRegion", GraphicsRegion::Chart, GraphicsRegion::Miscellaneous, 2 }, + { QColor::fromRgb(128, 0, 255), "Baseline", GraphicsRegion::Baseline, GraphicsRegion::Typology, 3 }, + { QColor::fromRgb(128, 0, 255), "Meanline", GraphicsRegion::Meanline, GraphicsRegion::Typology, 3 }, + { QColor::fromRgb(255, 255, 255), "Text", GraphicsRegion::Text, GraphicsRegion::None, 0 }, + { QColor::fromRgb(255, 255, 255), "Separators", GraphicsRegion::Separators, GraphicsRegion::None, 0 }, + { QColor::fromRgb(255, 255, 255), "Miscellaneous", GraphicsRegion::Miscellaneous, GraphicsRegion::None, 0 }, + { QColor::fromRgb(255, 255, 255), "Typological Lines", GraphicsRegion::Typology, GraphicsRegion::None, 0 } +}; + +class Xml +{ +public: + explicit Xml(const QString& filename = QString()); + + XmlItem *xmlItem(); + RootGraphicsItem *graphicsItem(); + + QDomDocument document() const; + QString filename() const; + bool recognized() const; + + static QString getPath(const QString& filename); + + void load(const QString& filename); + static GraphicsRegion::Data dataFromRegion(GraphicsRegion::Id region); + +private: + XmlItem *init(const QDomElement& root, XmlItem *rootTreeItem); + void isRecognized(const QDomElement& element); + + void processNode(const QDomElement& root, const GraphicsRegion::Data& data, XmlItem *rootTreeItem); + void processLineNode(const QDomElement& root, XmlItem *rootTreeItem); + void processTypoNode(const QDomElement& root, const QPoint& xPoint); + + RootGraphicsItem *graphicsItem_; + XmlItem *xmlItem_; + + QDomDocument xml_; + QString filename_; + bool isRecognized_; +}; + +#endif // XML_HH diff --git a/scribo/demo/viewer/xml_widget.cc b/scribo/demo/viewer/xml_widget.cc deleted file mode 100644 index 642cf9a..0000000 --- a/scribo/demo/viewer/xml_widget.cc +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#include "xml_widget.hh" - -XmlWidget::XmlWidget() - : tree_(new QTreeWidget()), - property_(new QTreeWidget()) -{ - QLabel* title = new QLabel(tr("XML")); - title->setAlignment(Qt::AlignHCenter); - - tree_->setHeaderHidden(true); - - QVBoxLayout* layout = new QVBoxLayout; - QHBoxLayout *hlayout = new QHBoxLayout; - - QStringList header_names; - header_names << tr("Name") << tr("Value"); - property_->setHeaderItem(new QTreeWidgetItem(header_names)); - - hlayout->addWidget(tree_); - hlayout->addWidget(property_); - - layout->addWidget(title); - layout->addLayout(hlayout); - - setLayout(layout); - - connect(tree_, SIGNAL(itemDoubleClicked (QTreeWidgetItem*, int)), - this, SLOT(check_item (QTreeWidgetItem*) ) ); -} - -void -XmlWidget::select(QString id, QString /*name*/) -{ - QDomNode n = node_map_[item_map_[id]]; - - if (!n.isNull()) - { - QTreeWidgetItem* item = node_map_.key(n); - - tree_->setCurrentItem(item, 0); - item->setExpanded(true); - check_item(item); - } -} - -void -XmlWidget::check_item (QTreeWidgetItem* item) -{ - QDomNode node = node_map_[item]; - - if (node.hasAttributes()) - { - property_->clear(); - QDomNamedNodeMap attributes = node.toElement().attributes(); - - for (int i = 0; i < attributes.count(); ++i) - { - QStringList values; - values << attributes.item(i).toAttr().name() << attributes.item(i).toAttr().value(); - property_->addTopLevelItem(new QTreeWidgetItem(values)); - } - } - - property_->resizeColumnToContents(0); -} - -void XmlWidget::NFS(QDomNode node, QTreeWidgetItem* item) -{ - if (!node.isNull()) - { - QString append; - if (node.toElement().tagName().contains("Point")) - { - QString x = node.toElement().attribute("x", "0"); - QString y = node.toElement().attribute("y", "0"); - append.append(" = (" + x + ", " + y + ")"); - } - - QTreeWidgetItem* child = - new QTreeWidgetItem(QStringList(node.toElement().tagName() + node.nodeValue() + append)); - - if (node.hasAttributes()) - { - QString id = node.toElement().attribute("id", "none"); - item_map_[id] = child; - } - - node_map_[child] = node; - item->addChild(child); - - QDomNode sibling = node.firstChild(); - while (!sibling.isNull()) - { - if (!sibling.toElement().tagName().contains("data")) - NFS(sibling, child); - else - { - QTreeWidgetItem* child_son = - new QTreeWidgetItem(QStringList("data = base64-encoded")); - - child->addChild(child_son); - } - sibling = sibling.nextSibling(); - } - } -} - -void XmlWidget::fill_widget(QString xml) -{ - node_map_.clear(); - item_map_.clear(); - - tree_->clear(); - property_->clear(); - QFile f_in(xml); - f_in.open(QIODevice::ReadOnly); - - QDomDocument doc; - doc.setContent(&f_in); - f_in.close(); - - int i = 0; - - QDomElement root = doc.documentElement(); - QTreeWidgetItem* root_item= - new QTreeWidgetItem(QStringList(root.tagName())); - - tree_->addTopLevelItem(root_item); - root = root.firstChild().toElement(); - - while (!root.isNull()) - { - ++i; - NFS(root, root_item); - root = root.nextSibling().toElement(); - } -} - -void -XmlWidget::deselect() -{ - property_->clear(); -} - -XmlWidget::~XmlWidget() -{ -} diff --git a/scribo/demo/viewer/xml_widget.hh b/scribo/demo/viewer/xml_widget.hh deleted file mode 100644 index b7cd868..0000000 --- a/scribo/demo/viewer/xml_widget.hh +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see http://www.gnu.org/licenses/. - -#ifndef SCRIBO_DEMO_VIEWER_XML_WIDGET_HH -# define SCRIBO_DEMO_VIEWER_XML_WIDGET_HH - -# include <QtGui> -# include <QDomNode> - -class DomModel; - -class XmlWidget - : public QWidget -{ - Q_OBJECT - -public: - XmlWidget(); - ~XmlWidget(); - -public slots: - void select(QString id, QString name); - void deselect(); - void fill_widget(QString xml); - void check_item (QTreeWidgetItem* item); - -private: - void NFS(QDomNode node, QTreeWidgetItem* item); - QTreeWidget* tree_; - QTreeWidget* property_; - QMap<QString, QTreeWidgetItem*> item_map_; - QMap<QTreeWidgetItem*, QDomNode> node_map_; -}; - -#endif // ! SCRIBO_DEMO_VIEWER_XML_WIDGET_HH