summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-02-04 21:47:50 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-05 06:30:33 -0800
commita649bcc7bc0006cc78ac547716d8bebf8b63267c (patch)
tree6cf8274a85e6210c26a20a3e743819824f95a81d /qt-ui
parentdc077e7bffa6a5236a5b6437ef64237e30980d9d (diff)
downloadsubsurface-a649bcc7bc0006cc78ac547716d8bebf8b63267c.tar.gz
Added Mouse based Zoom / Movement.
This patch uses the same code that lubomir used on the old profile. It strangely didn't worked - most probably because the scene has a fixed width() and height() of 100. the zoom works, and the movement works, but only on the 100 first pixels of the profile. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/profile/profilewidget2.cpp73
-rw-r--r--qt-ui/profile/profilewidget2.h5
2 files changed, 76 insertions, 2 deletions
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 3a65fdd66..0de11966c 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -14,6 +14,7 @@
#include <QMenu>
#include <QContextMenuEvent>
#include <QDebug>
+#include <QScrollBar>
#ifndef QT_NO_DEBUG
#include <QTableView>
@@ -24,6 +25,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
QGraphicsView(parent),
dataModel(new DivePlotDataModel(this)),
currentState(INVALID),
+ zoomLevel(0),
stateMachine(new QStateMachine(this)),
background (new DivePixmapItem()),
profileYAxis(new DepthAxis()),
@@ -50,7 +52,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
setOptimizationFlags(QGraphicsView::DontSavePainterState);
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
-
+ setMouseTracking(true);
// Creating the needed items.
// ORDER: {BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom);
@@ -476,3 +478,72 @@ void ProfileWidget2::fixBackgroundPos()
bg->setPixmap(p);
bg->setX(mapToScene(x, 0).x());
}
+
+void ProfileWidget2::wheelEvent(QWheelEvent* event)
+{
+// if (!toolTip)
+// return;
+
+ // doesn't seem to work for Qt 4.8.1
+ // setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
+
+ // Scale the view / do the zoom
+// QPoint toolTipPos = mapFromScene(toolTip->pos());
+
+ double scaleFactor = 1.15;
+ if (event->delta() > 0 && zoomLevel < 20) {
+ scale(scaleFactor, scaleFactor);
+ zoomLevel++;
+ } else if (event->delta() < 0 && zoomLevel > 0) {
+ // Zooming out
+ scale(1.0 / scaleFactor, 1.0 / scaleFactor);
+ zoomLevel--;
+ }
+
+ scrollViewTo(event->pos());
+// toolTip->setPos(mapToScene(toolTipPos));
+// toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
+// if (zoomLevel != 0) {
+// toolBarProxy->hide();
+// } else {
+// toolBarProxy->show();
+// }
+}
+
+void ProfileWidget2::scrollViewTo(const QPoint& pos)
+{
+/* since we cannot use translate() directly on the scene we hack on
+ * the scroll bars (hidden) functionality */
+ if (!zoomLevel)
+ return;
+ QScrollBar *vs = verticalScrollBar();
+ QScrollBar *hs = horizontalScrollBar();
+ const qreal yRat = pos.y() / sceneRect().height();
+ const qreal xRat = pos.x() / sceneRect().width();
+ const int vMax = vs->maximum();
+ const int hMax = hs->maximum();
+ const int vMin = vs->minimum();
+ const int hMin = hs->minimum();
+ /* QScrollBar receives crazy negative values for minimum */
+ vs->setValue(yRat * (vMax - vMin) + vMin * 0.9);
+ hs->setValue(xRat * (hMax - hMin) + hMin * 0.9);
+}
+
+void ProfileWidget2::mouseMoveEvent(QMouseEvent* event)
+{
+// if (!toolTip)
+// return;
+//
+// toolTip->refresh(&gc, mapToScene(event->pos()));
+// QPoint toolTipPos = mapFromScene(toolTip->pos());
+
+
+ if (zoomLevel == 0) {
+ QGraphicsView::mouseMoveEvent(event);
+ } else {/*
+ toolTip->setPos(mapToScene(toolTipPos));
+ toolBarProxy->setPos(mapToScene(TOOLBAR_POS));*/
+ scrollViewTo(event->pos());
+ }
+}
+
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index df4a844bd..a89cef786 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -43,6 +43,7 @@ struct PartialGasPressureAxis;
class ProfileWidget2 : public QGraphicsView {
Q_OBJECT
void fixBackgroundPos();
+ void scrollViewTo(const QPoint& pos);
public:
enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID };
enum Items{BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
@@ -55,6 +56,8 @@ public slots: // Necessary to call from QAction's signals.
protected:
virtual void contextMenuEvent(QContextMenuEvent* event);
virtual void resizeEvent(QResizeEvent* event);
+ virtual void wheelEvent(QWheelEvent* event);
+ virtual void mouseMoveEvent(QMouseEvent* event);
signals:
void startProfileState();
@@ -70,7 +73,7 @@ private:
DivePlotDataModel *dataModel;
State currentState;
QStateMachine *stateMachine;
-
+ int zoomLevel;
DivePixmapItem *background ;
// All those here should probably be merged into one structure,
// So it's esyer to replicate for more dives later.