* viewer/help_dialog.cc:
Update help message.
* viewer/image_view.cc,
* viewer/image_view.hh,
* viewer/image_widget.cc,
* viewer/image_widget.hh,
* viewer/viewer.cc,
* viewer/viewer.hh:
Update colors. Improve cache usage (disabled when zoomed in).
---
viewer/help_dialog.cc | 2 ++
viewer/image_view.cc | 30 ++++++++++++++++++++++++++++++
viewer/image_view.hh | 8 ++++++++
viewer/image_widget.cc | 6 +++++-
viewer/image_widget.hh | 3 +++
viewer/viewer.cc | 38 +++++++++++++++++++++++---------------
viewer/viewer.hh | 5 +++--
7 files changed, 74 insertions(+), 18 deletions(-)
diff --git a/viewer/help_dialog.cc b/viewer/help_dialog.cc
index ebdfdaa..fe59d93 100644
--- a/viewer/help_dialog.cc
+++ b/viewer/help_dialog.cc
@@ -33,6 +33,8 @@ HelpDialog::HelpDialog()
" - If the document layout is present\n"
" (XML file with the same name),\n"
" select regions to display their properties.\n"
+ " - Use the mouse or keyboard to move and zoom\n"
+ " (Arrows, PageUp, PageDown, Home, End).\n"
"\n"
"Contact: d-halluin(a)lrde.epita.fr\n"
"\n"
diff --git a/viewer/image_view.cc b/viewer/image_view.cc
index f017fe9..9182c1b 100644
--- a/viewer/image_view.cc
+++ b/viewer/image_view.cc
@@ -40,9 +40,39 @@ ImageView::wheelEvent(QWheelEvent* event)
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/viewer/image_view.hh b/viewer/image_view.hh
index d2e0058..84f722f 100644
--- a/viewer/image_view.hh
+++ b/viewer/image_view.hh
@@ -27,6 +27,14 @@ public:
~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 /* !IMAGE_VIEW_HH_ */
diff --git a/viewer/image_widget.cc b/viewer/image_widget.cc
index b8ac8c2..b4bee72 100644
--- a/viewer/image_widget.cc
+++ b/viewer/image_widget.cc
@@ -25,11 +25,14 @@ ImageWidget::ImageWidget(QGraphicsScene* scene)
layout->addWidget(title);
layout->addWidget(view_);
- view_->setDragMode (QGraphicsView::ScrollHandDrag);
+ 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);
}
@@ -37,6 +40,7 @@ void
ImageWidget::update()
{
view_->fitInView(view_->sceneRect(), Qt::KeepAspectRatio);
+ view_->scaleUpdate();
}
ImageWidget::~ImageWidget()
diff --git a/viewer/image_widget.hh b/viewer/image_widget.hh
index 25a41a0..87259b0 100644
--- a/viewer/image_widget.hh
+++ b/viewer/image_widget.hh
@@ -31,6 +31,9 @@ public:
public slots:
void update();
+signals:
+ void scaleUpdated(qreal scale);
+
private:
ImageView* view_;
};
diff --git a/viewer/viewer.cc b/viewer/viewer.cc
index 88d0525..ce9f850 100644
--- a/viewer/viewer.cc
+++ b/viewer/viewer.cc
@@ -34,15 +34,15 @@ Viewer::Viewer(int &argc, char** argv)
files_(new QDirModel()),
doc_layout_(0),
key_map_(9),
- alt_cache_(false)
+ no_cache_(false)
{
// Key map
key_map_[region::Text] = qMakePair(tr("Text"), QColor(0, 200, 0));
key_map_[region::Image] = qMakePair(tr("Image"), QColor(255, 120, 0));
- key_map_[region::Noise] = qMakePair(tr("Noise"), QColor(114, 188, 144));
- key_map_[region::Separator] = qMakePair(tr("Separator"), QColor(200, 222,
0));
- key_map_[region::Table] = qMakePair(tr("Table"), QColor(0, 0, 255));
+ key_map_[region::Noise] = qMakePair(tr("Noise"), QColor(43, 39, 128));
+ key_map_[region::Separator] = qMakePair(tr("Separator"), QColor(0, 0, 255));
+ 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));
@@ -96,14 +96,13 @@ Viewer::Viewer(int &argc, char** argv)
connect(fill_action_, SIGNAL(toggled(bool)),
this, SIGNAL(setFill(bool)));
option_menu->addAction(fill_action_);
- QAction* cache_action = new QAction(tr("Alternative cache mode"),
- option_menu);
- cache_action->setStatusTip(tr("Much faster at low zoom, "
- "but unstable at high zoom."));
+ QAction* cache_action = new QAction(tr("Disable cache"), file_menu);
+ cache_action->setStatusTip(tr("Disable the image cache (useful for"
+ " large images)."));
cache_action->setCheckable(true);
cache_action->setChecked(false);
connect(cache_action, SIGNAL(toggled(bool)),
- this, SLOT(setAltCache(bool)));
+ this, SLOT(useCache(bool)));
option_menu->addAction(cache_action);
QMenu* help_menu = win_->menuBar()->addMenu(tr("Help"));
@@ -168,6 +167,8 @@ Viewer::Viewer(int &argc, char** argv)
xml_wgt, SLOT(select(QModelIndex)));
connect(scene_, SIGNAL(deselected(QModelIndex)),
xml_wgt, SLOT(deselect(QModelIndex)));
+ connect(image_wgt, SIGNAL(scaleUpdated(qreal)),
+ this, SLOT(maybeChangeCacheMode(qreal)));
}
void
@@ -182,7 +183,6 @@ Viewer::load(QString filename)
// OpenGL might speed up things a bit.
image_ = new QGraphicsPixmapItem(QPixmap(filename));
image_->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
- image_->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize());
image_->setZValue(0);
scene_->addItem(image_);
@@ -288,14 +288,22 @@ Viewer::help()
}
void
-Viewer::setAltCache(bool b)
+Viewer::maybeChangeCacheMode(qreal scale)
{
- alt_cache_ = b;
+ qDebug() << scale;
if (image_)
{
- if (b)
+ if (scale >= 0.7)
+ image_->setCacheMode(QGraphicsItem::NoCache);
+ else if (!no_cache_)
image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
- else
- image_->setCacheMode(QGraphicsItem::ItemCoordinateCache);
}
}
+
+void
+Viewer::useCache(bool b)
+{
+ no_cache_ = b;
+ if (b)
+ image_->setCacheMode(QGraphicsItem::NoCache);
+}
diff --git a/viewer/viewer.hh b/viewer/viewer.hh
index 0a76afd..d579847 100644
--- a/viewer/viewer.hh
+++ b/viewer/viewer.hh
@@ -40,7 +40,8 @@ public slots:
void load(QString filename);
void help();
- void setAltCache(bool b);
+ void maybeChangeCacheMode(qreal scale);
+ void useCache(bool b);
signals:
void updated(DomModel* model);
@@ -71,7 +72,7 @@ private:
QMap<QString, int> region_ids_;
region::KeyMap key_map_;
- bool alt_cache_;
+ bool no_cache_;
};
#include "viewer.hxx"
--
1.5.6.5