mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
dc077e7bff
commit
a649bcc7bc
2 changed files with 76 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QScrollBar>
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG
|
#ifndef QT_NO_DEBUG
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
@ -24,6 +25,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||||
QGraphicsView(parent),
|
QGraphicsView(parent),
|
||||||
dataModel(new DivePlotDataModel(this)),
|
dataModel(new DivePlotDataModel(this)),
|
||||||
currentState(INVALID),
|
currentState(INVALID),
|
||||||
|
zoomLevel(0),
|
||||||
stateMachine(new QStateMachine(this)),
|
stateMachine(new QStateMachine(this)),
|
||||||
background (new DivePixmapItem()),
|
background (new DivePixmapItem()),
|
||||||
profileYAxis(new DepthAxis()),
|
profileYAxis(new DepthAxis()),
|
||||||
|
@ -50,7 +52,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||||
setOptimizationFlags(QGraphicsView::DontSavePainterState);
|
setOptimizationFlags(QGraphicsView::DontSavePainterState);
|
||||||
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
||||||
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
|
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
|
||||||
|
setMouseTracking(true);
|
||||||
// Creating the needed items.
|
// Creating the needed items.
|
||||||
// ORDER: {BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
|
// ORDER: {BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
|
||||||
profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom);
|
profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom);
|
||||||
|
@ -476,3 +478,72 @@ void ProfileWidget2::fixBackgroundPos()
|
||||||
bg->setPixmap(p);
|
bg->setPixmap(p);
|
||||||
bg->setX(mapToScene(x, 0).x());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ struct PartialGasPressureAxis;
|
||||||
class ProfileWidget2 : public QGraphicsView {
|
class ProfileWidget2 : public QGraphicsView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
void fixBackgroundPos();
|
void fixBackgroundPos();
|
||||||
|
void scrollViewTo(const QPoint& pos);
|
||||||
public:
|
public:
|
||||||
enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID };
|
enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID };
|
||||||
enum Items{BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
|
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:
|
protected:
|
||||||
virtual void contextMenuEvent(QContextMenuEvent* event);
|
virtual void contextMenuEvent(QContextMenuEvent* event);
|
||||||
virtual void resizeEvent(QResizeEvent* event);
|
virtual void resizeEvent(QResizeEvent* event);
|
||||||
|
virtual void wheelEvent(QWheelEvent* event);
|
||||||
|
virtual void mouseMoveEvent(QMouseEvent* event);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void startProfileState();
|
void startProfileState();
|
||||||
|
@ -70,7 +73,7 @@ private:
|
||||||
DivePlotDataModel *dataModel;
|
DivePlotDataModel *dataModel;
|
||||||
State currentState;
|
State currentState;
|
||||||
QStateMachine *stateMachine;
|
QStateMachine *stateMachine;
|
||||||
|
int zoomLevel;
|
||||||
DivePixmapItem *background ;
|
DivePixmapItem *background ;
|
||||||
// All those here should probably be merged into one structure,
|
// All those here should probably be merged into one structure,
|
||||||
// So it's esyer to replicate for more dives later.
|
// So it's esyer to replicate for more dives later.
|
||||||
|
|
Loading…
Add table
Reference in a new issue