The Zoom is working just like the GTK Version.

This code enables Zoom in / Out with the Wheel,
and it also enables panning by moving the mouse around.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-05-09 19:59:55 -03:00 committed by Dirk Hohndel
parent 9cc089f9f6
commit acdb5d97eb
2 changed files with 33 additions and 7 deletions

View file

@ -114,7 +114,7 @@ extern struct ev_select *ev_namelist;
extern int evn_allocated;
extern int evn_used;
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent)
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent) , dive(0)
{
gc.printer = false;
setScene(new QGraphicsScene());
@ -131,9 +131,27 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent
defaultPen.setWidth(2);
defaultPen.setCosmetic(true);
setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
fill_profile_color();
}
void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
{
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
// Scale the view / do the zoom
double scaleFactor = 1.15;
if(event->delta() > 0) {
// Zoom in
scale(scaleFactor, scaleFactor);
} else {
// Zooming out
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
}
}
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
{
toolTip->clear();
@ -146,6 +164,10 @@ void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
if (!item->toolTip().isEmpty())
toolTip->addToolTip(item->toolTip());
}
// Pan on mouseMove code.
ensureVisible(event->pos().x(), event->pos().y(), 10, 10, 100, 100);
QGraphicsView::mouseMoveEvent(event);
}
@ -172,13 +194,16 @@ static void plot_set_scale(scale_mode_t scale)
}
}
void ProfileGraphicsView::plot(struct dive *dive)
void ProfileGraphicsView::plot(struct dive *d)
{
scene()->clear();
dive = d;
if(!dive)
return;
scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50);
QSettings s;
s.beginGroup("ProfileMap");
QPointF toolTipPos = s.value("tooltip_position", QPointF(0,0)).toPointF();
@ -294,6 +319,9 @@ void ProfileGraphicsView::plot(struct dive *dive)
pi->nr = 0;
}
#endif
QRectF curerntRect = scene()->itemsBoundingRect();
scene()->setSceneRect( -10, -10, curerntRect.width() + 10, curerntRect.height() +10 );
}
void ProfileGraphicsView::plot_depth_scale()
@ -1061,11 +1089,7 @@ void ProfileGraphicsView::plot_text(text_render_options_t *tro, double x, double
void ProfileGraphicsView::resizeEvent(QResizeEvent *event)
{
// Fits the scene's rectangle on the view.
// I can pass some parameters to this -
// like Qt::IgnoreAspectRatio or Qt::KeepAspectRatio
QRectF r = scene()->sceneRect();
fitInView (r.x() - 50, r.y() -50, r.width() + 100, r.height() + 100); // do a little bit of spacing;
plot(dive);
}
void ProfileGraphicsView::plot_temperature_profile()

View file

@ -67,6 +67,7 @@ public:
protected:
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
private:
void plot_depth_profile();
@ -93,6 +94,7 @@ private:
QBrush defaultBrush;
ToolTipItem *toolTip;
graphics_context gc;
struct dive *dive;
};
#endif