Commit 06903f85 authored by Florent D'Halluin's avatar Florent D'Halluin Committed by Guillaume Lazzara
Browse files

Update viewer.

* 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).
parent ed6a220e
......@@ -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@lrde.epita.fr\n"
"\n"
......
......@@ -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()
{
}
......@@ -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_ */
......@@ -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()
......
......@@ -31,6 +31,9 @@ public:
public slots:
void update();
signals:
void scaleUpdated(qreal scale);
private:
ImageView* view_;
};
......
......@@ -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);
}
......@@ -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"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment