summaryrefslogtreecommitdiffstats
path: root/qt-ui/profilegraphics.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-09 19:59:55 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-09 17:50:06 -0700
commitacdb5d97ebe88a75933089a80b1ce844c4375851 (patch)
tree3f2e57f4ea7f2944357832e83d1e60dad7bf0855 /qt-ui/profilegraphics.cpp
parent9cc089f9f61a876057799e540c56178d4449fdce (diff)
downloadsubsurface-acdb5d97ebe88a75933089a80b1ce844c4375851.tar.gz
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>
Diffstat (limited to 'qt-ui/profilegraphics.cpp')
-rw-r--r--qt-ui/profilegraphics.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index ad6cbb172..44af49e7c 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -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()