mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Improved slider handling
This commit is contained in:
parent
2df5dd0d88
commit
7e2b27acf1
@ -1,6 +1,6 @@
|
||||
#include <float.h>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QEvent>
|
||||
#include "slideritem.h"
|
||||
#include "infoitem.h"
|
||||
@ -10,10 +10,20 @@
|
||||
|
||||
#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)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
_scene = new QGraphicsScene(this);
|
||||
_scene = new Scene(this);
|
||||
setScene(_scene);
|
||||
|
||||
_xAxis = new AxisItem(AxisItem::X);
|
||||
@ -21,8 +31,11 @@ Graph::Graph(QWidget *parent)
|
||||
|
||||
_slider = new SliderItem();
|
||||
_slider->setZValue(2.0);
|
||||
|
||||
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
||||
SLOT(emitSliderPositionChanged(const QPointF&)));
|
||||
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
|
||||
SLOT(newSliderPosition(const QPointF&)));
|
||||
|
||||
_info = new InfoItem();
|
||||
|
||||
@ -239,6 +252,14 @@ void Graph::setSliderPosition(qreal pos)
|
||||
_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)
|
||||
{
|
||||
_info->insert(key, value);
|
||||
|
17
src/graph.h
17
src/graph.h
@ -2,6 +2,7 @@
|
||||
#define GRAPH_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <QPointF>
|
||||
@ -12,6 +13,18 @@
|
||||
class SliderItem;
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -48,6 +61,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
void emitSliderPositionChanged(const QPointF &pos);
|
||||
void newSliderPosition(const QPointF &pos);
|
||||
|
||||
private:
|
||||
void createXLabel();
|
||||
@ -55,8 +69,7 @@ private:
|
||||
void updateBounds(const QPointF &point);
|
||||
void resize(const QSizeF &size);
|
||||
|
||||
|
||||
QGraphicsScene *_scene;
|
||||
Scene *_scene;
|
||||
AxisItem *_xAxis, *_yAxis;
|
||||
SliderItem *_slider;
|
||||
InfoItem *_info;
|
||||
|
Loading…
Reference in New Issue
Block a user