mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Improved slider handling
This commit is contained in:
parent
2df5dd0d88
commit
7e2b27acf1
@ -1,6 +1,6 @@
|
|||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include "slideritem.h"
|
#include "slideritem.h"
|
||||||
#include "infoitem.h"
|
#include "infoitem.h"
|
||||||
@ -10,10 +10,20 @@
|
|||||||
|
|
||||||
#define MARGIN 10.0
|
#define MARGIN 10.0
|
||||||
|
|
||||||
|
|
||||||
|
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
||||||
|
{
|
||||||
|
if (e->button() == Qt::LeftButton)
|
||||||
|
emit mouseClicked(e->scenePos());
|
||||||
|
|
||||||
|
QGraphicsScene::mousePressEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Graph::Graph(QWidget *parent)
|
Graph::Graph(QWidget *parent)
|
||||||
: QGraphicsView(parent)
|
: QGraphicsView(parent)
|
||||||
{
|
{
|
||||||
_scene = new QGraphicsScene(this);
|
_scene = new Scene(this);
|
||||||
setScene(_scene);
|
setScene(_scene);
|
||||||
|
|
||||||
_xAxis = new AxisItem(AxisItem::X);
|
_xAxis = new AxisItem(AxisItem::X);
|
||||||
@ -21,8 +31,11 @@ Graph::Graph(QWidget *parent)
|
|||||||
|
|
||||||
_slider = new SliderItem();
|
_slider = new SliderItem();
|
||||||
_slider->setZValue(2.0);
|
_slider->setZValue(2.0);
|
||||||
|
|
||||||
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
||||||
SLOT(emitSliderPositionChanged(const QPointF&)));
|
SLOT(emitSliderPositionChanged(const QPointF&)));
|
||||||
|
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
|
||||||
|
SLOT(newSliderPosition(const QPointF&)));
|
||||||
|
|
||||||
_info = new InfoItem();
|
_info = new InfoItem();
|
||||||
|
|
||||||
@ -239,6 +252,14 @@ void Graph::setSliderPosition(qreal pos)
|
|||||||
_slider->setPos(pos * _slider->area().width(), 0);
|
_slider->setPos(pos * _slider->area().width(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Graph::newSliderPosition(const QPointF &pos)
|
||||||
|
{
|
||||||
|
if (_slider->area().contains(pos)) {
|
||||||
|
_slider->setPos(pos);
|
||||||
|
emitSliderPositionChanged(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Graph::addInfo(const QString &key, const QString &value)
|
void Graph::addInfo(const QString &key, const QString &value)
|
||||||
{
|
{
|
||||||
_info->insert(key, value);
|
_info->insert(key, value);
|
||||||
|
17
src/graph.h
17
src/graph.h
@ -2,6 +2,7 @@
|
|||||||
#define GRAPH_H
|
#define GRAPH_H
|
||||||
|
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsScene>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
@ -12,6 +13,18 @@
|
|||||||
class SliderItem;
|
class SliderItem;
|
||||||
class InfoItem;
|
class InfoItem;
|
||||||
|
|
||||||
|
class Scene : public QGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Scene(QObject *parent = 0) : QGraphicsScene(parent) {}
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *e);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void mouseClicked(const QPointF &pos);
|
||||||
|
};
|
||||||
|
|
||||||
class Graph : public QGraphicsView
|
class Graph : public QGraphicsView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -48,6 +61,7 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void emitSliderPositionChanged(const QPointF &pos);
|
void emitSliderPositionChanged(const QPointF &pos);
|
||||||
|
void newSliderPosition(const QPointF &pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createXLabel();
|
void createXLabel();
|
||||||
@ -55,8 +69,7 @@ private:
|
|||||||
void updateBounds(const QPointF &point);
|
void updateBounds(const QPointF &point);
|
||||||
void resize(const QSizeF &size);
|
void resize(const QSizeF &size);
|
||||||
|
|
||||||
|
Scene *_scene;
|
||||||
QGraphicsScene *_scene;
|
|
||||||
AxisItem *_xAxis, *_yAxis;
|
AxisItem *_xAxis, *_yAxis;
|
||||||
SliderItem *_slider;
|
SliderItem *_slider;
|
||||||
InfoItem *_info;
|
InfoItem *_info;
|
||||||
|
Loading…
Reference in New Issue
Block a user