* demo/viewer/image_scene.cc,
* demo/viewer/image_scene.hh: Accept a parent widget.
* demo/viewer/image_widget.cc,
* demo/viewer/image_widget.hh: Add an accessor to the underlying
view.
* demo/viewer/viewer.cc,
* demo/viewer/viewer.hh: Add print and print preview menu entries
---
scribo/ChangeLog | 14 +++++
scribo/demo/viewer/image_scene.cc | 7 ++-
scribo/demo/viewer/image_scene.hh | 2 +-
scribo/demo/viewer/image_widget.cc | 15 +++++-
scribo/demo/viewer/image_widget.hh | 6 ++-
scribo/demo/viewer/viewer.cc | 95 ++++++++++++++++++++++++++++++++++--
scribo/demo/viewer/viewer.hh | 9 +++-
7 files changed, 135 insertions(+), 13 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 620dcfb..52006a7 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,17 @@
+2011-02-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add printing support in Scribo viewer.
+
+ * demo/viewer/image_scene.cc,
+ * demo/viewer/image_scene.hh: Accept a parent widget.
+
+ * demo/viewer/image_widget.cc,
+ * demo/viewer/image_widget.hh: Add an accessor to the underlying
+ view.
+
+ * demo/viewer/viewer.cc,
+ * demo/viewer/viewer.hh: Add print and print preview menu entries.
+
2011-02-18 Guillaume Lazzara <z(a)lrde.epita.fr>
Improve about dialog in scribo viewer.
diff --git a/scribo/demo/viewer/image_scene.cc b/scribo/demo/viewer/image_scene.cc
index 2c56113..a800896 100644
--- a/scribo/demo/viewer/image_scene.cc
+++ b/scribo/demo/viewer/image_scene.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -18,8 +19,8 @@
#include "image_scene.hh"
#include "image_region.hh"
-ImageScene::ImageScene()
- : selected_(0)
+ImageScene::ImageScene(QObject *parent)
+ : QGraphicsScene(parent), selected_(0)
{
}
diff --git a/scribo/demo/viewer/image_scene.hh b/scribo/demo/viewer/image_scene.hh
index 136f1a2..b141478 100644
--- a/scribo/demo/viewer/image_scene.hh
+++ b/scribo/demo/viewer/image_scene.hh
@@ -27,7 +27,7 @@ class ImageScene
Q_OBJECT
public:
- ImageScene();
+ ImageScene(QObject *parent = 0);
~ImageScene();
void mousePressEvent(QGraphicsSceneMouseEvent* event);
diff --git a/scribo/demo/viewer/image_widget.cc b/scribo/demo/viewer/image_widget.cc
index e9e5e79..f86ff1d 100644
--- a/scribo/demo/viewer/image_widget.cc
+++ b/scribo/demo/viewer/image_widget.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -20,6 +21,8 @@
ImageWidget::ImageWidget(QGraphicsScene* scene)
: view_ (new ImageView(scene))
{
+ scene->setParent(view_);
+
QLabel* title = new QLabel(tr("Layout"));
title->setAlignment(Qt::AlignHCenter);
@@ -38,6 +41,12 @@ ImageWidget::ImageWidget(QGraphicsScene* scene)
setLayout(layout);
}
+
+ImageWidget::~ImageWidget()
+{
+}
+
+
void
ImageWidget::update()
{
@@ -45,6 +54,8 @@ ImageWidget::update()
view_->scaleUpdate();
}
-ImageWidget::~ImageWidget()
+ImageView *
+ImageWidget::view() const
{
+ return view_;
}
diff --git a/scribo/demo/viewer/image_widget.hh b/scribo/demo/viewer/image_widget.hh
index 826b873..79dd672 100644
--- a/scribo/demo/viewer/image_widget.hh
+++ b/scribo/demo/viewer/image_widget.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -18,6 +19,7 @@
# define SCRIBO_DEMO_VIEWER_IMAGE_WIDGET_HH
# include <QtGui>
+# include "image_view.hh"
class ImageView;
@@ -30,6 +32,8 @@ public:
ImageWidget(QGraphicsScene* scene);
~ImageWidget();
+ ImageView * view() const;
+
public slots:
void update();
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index 46172ce..57a67c2 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -22,10 +22,10 @@
#include "viewer.hh"
#include "key_widget.hh"
#include "browser_widget.hh"
-#include "image_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"
@@ -107,6 +107,23 @@ Viewer::Viewer(int &argc, char** argv)
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");
@@ -220,10 +237,14 @@ Viewer::Viewer(int &argc, char** argv)
step_widget_ = new StepWidget();
XmlWidget* xml_wgt = new XmlWidget();
browser_wgt_ = new BrowserWidget(files_, argc != 2 ? QString() : argv[1]);
- ImageWidget* image_wgt = new ImageWidget(scene_);
+ 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());
@@ -231,7 +252,7 @@ Viewer::Viewer(int &argc, char** argv)
v_splitter->addWidget(key_wgt_);
v_splitter->addWidget(browser_wgt_);
- v_splitter2->addWidget(image_wgt);
+ v_splitter2->addWidget(image_wgt_);
v_splitter2->addWidget(xml_wgt);
h_splitter->addWidget(v_splitter);
@@ -264,7 +285,7 @@ Viewer::Viewer(int &argc, char** argv)
connect(this, SIGNAL(mode_changed(bool)),
key_wgt_, SLOT(change_mode(bool)));
connect(this, SIGNAL(updated()),
- image_wgt, SLOT(update()));
+ image_wgt_, SLOT(update()));
connect(this, SIGNAL(fill_xml(QString)),
xml_wgt, SLOT(fill_widget(QString)));
@@ -276,7 +297,7 @@ Viewer::Viewer(int &argc, char** argv)
connect(scene_, SIGNAL(deselected()),
xml_wgt, SLOT(deselect()));
- connect(image_wgt, SIGNAL(scaleUpdated(qreal)),
+ connect(image_wgt_, SIGNAL(scaleUpdated(qreal)),
this, SLOT(maybeChangeCacheMode(qreal)));
@@ -808,3 +829,67 @@ Viewer::reset_progress_dialog()
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
index 3aefaf6..c4b99e8 100644
--- a/scribo/demo/viewer/viewer.hh
+++ b/scribo/demo/viewer/viewer.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -21,6 +22,7 @@
# include <QDomNode>
# include "common.hh"
# include "runner.hh"
+# include "image_widget.hh"
class ImageScene;
class DomModel;
@@ -61,6 +63,9 @@ private slots:
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();
@@ -81,6 +86,7 @@ private:
void add_text(QDomNode line);
QAction *create_action(QString name, QMenu* menu, QString status, QString shortcut);
void reset_progress_dialog();
+ void configure_printer(QPrinter& printer);
QApplication* app_;
QMainWindow* win_;
@@ -90,6 +96,7 @@ private:
QGraphicsPixmapItem* image_;
ImageScene* scene_;
+ ImageWidget* image_wgt_;
QDirModel* files_;
DomModel* doc_layout_;
--
1.5.6.5