Oliver Eichler wrote:
Hi Andrey
I want help to qlandkarte.
may be you have any todo list?
Now I want add "zoom in/out" (separate for vertical and horizontal) to a
track profile. It unusable practically without this feature. any
objection?
Yes, that is a good idea
Hi, Oliver.
I send patch in attach.
pls, comment it.
>From f689b3a6b8684e0be44fd0a2e11454a757a76a08 Mon Sep 17 00:00:00 2001
From: Adnrew <[EMAIL PROTECTED]>
Date: Sun, 21 Sep 2008 16:54:03 +0400
Subject: [PATCH] add "zoom in/out" (separate for vertical and horizontal) to a
track profile.
---
src/CPlot.cpp | 76 +++++++++++++++++++++++++++++++++++++-
src/CPlot.h | 16 ++++++++
src/CPlotAxis.cpp | 21 ++++++++++-
src/CPlotAxis.h | 4 ++
src/CTrackStatProfileWidget.cpp | 2 +-
src/CTrackStatSpeedWidget.cpp | 1 +
src/ITrackStat.cpp | 41 +++++++++------------
src/ITrackStat.h | 4 +-
8 files changed, 136 insertions(+), 29 deletions(-)
diff --git a/src/CPlot.cpp b/src/CPlot.cpp
index 2795bca..8f2c3f2 100644
--- a/src/CPlot.cpp
+++ b/src/CPlot.cpp
@@ -37,6 +37,7 @@ CPlot::CPlot(QWidget * parent)
{
setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
m_pData = new CPlotData(this);
+ createActions();
}
@@ -72,6 +73,10 @@ void CPlot::setXLabel(const QString& str)
update();
}
+void CPlot::setLimits()
+{
+ m_pData->setLimits();
+}
void CPlot::newLine(const QPolygonF& line, const QPointF& focus, const QString& label)
{
@@ -84,7 +89,6 @@ void CPlot::newLine(const QPolygonF& line, const QPointF& focus, const QString&
l.label = label;
m_pData->lines << l;
- m_pData->setLimits();
setSizes();
m_pData->x().setScale( rectGraphArea.width() );
m_pData->y().setScale( rectGraphArea.height() );
@@ -99,7 +103,6 @@ void CPlot::addLine(const QPolygonF& line, const QString& label)
l.label = label;
m_pData->lines << l;
- m_pData->setLimits();
setSizes();
m_pData->x().setScale( rectGraphArea.width() );
m_pData->y().setScale( rectGraphArea.height() );
@@ -549,3 +552,72 @@ void CPlot::drawTags(QPainter& p)
++tag;
}
}
+
+void CPlot::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu menu(this);
+ menu.addAction(hZoomAct);
+ menu.addAction(vZoomAct);
+
+ menu.exec(event->globalPos());
+}
+
+void CPlot::createActions()
+{
+ hZoomAct = new QAction("horizontal zoom", this);
+ hZoomAct->setCheckable(true);
+ hZoomAct->setChecked(true);
+
+ vZoomAct = new QAction(tr("vertical zoom"), this);
+ vZoomAct->setCheckable(true);
+ vZoomAct->setChecked(true);
+}
+
+void CPlot::zoom(CPlotAxis &axis, double factor, int curInt)
+{
+ axis.zoom(factor, curInt);
+ setSizes();
+ update();
+}
+
+void CPlot::wheelEvent ( QWheelEvent * e )
+{
+ if (hZoomAct->isChecked())
+ zoom(m_pData->x(), (1 + e->delta() / 1200.0), e->pos().x() - left);
+ if (vZoomAct->isChecked())
+ zoom(m_pData->y(), (1 + e->delta() / 1200.0), - e->pos().y() + bottom);
+}
+
+void CPlot::mouseMoveEvent(QMouseEvent * e)
+{
+ double p;
+ checkClick = false;
+
+ CPlotAxis &xaxis = m_pData->x();
+ p = xaxis.pt2val(e->pos().x()) - xaxis.pt2val(startMovePos.x());
+ xaxis.setMinMax(xaxis.getMin() - p , xaxis.getMax() - p);
+
+ CPlotAxis &yaxis = m_pData->y();
+ p = yaxis.pt2val(e->pos().y()) - yaxis.pt2val(startMovePos.y());
+ yaxis.setMinMax(yaxis.getMin() + p , yaxis.getMax() + p);
+
+ startMovePos = e->pos();
+ update();
+}
+
+void CPlot::mouseReleaseEvent(QMouseEvent * e)
+{
+ if (checkClick && e->button() == Qt::LeftButton) {
+ QPoint pos = e->pos();
+ double dist = getXValByPixel(pos.x());
+ emit activePointSignal(dist);
+ }
+}
+
+void CPlot::mousePressEvent(QMouseEvent * e)
+{
+ qDebug() << "press" << endl;
+ startMovePos = e->pos();
+ checkClick = true;
+}
+
diff --git a/src/CPlot.h b/src/CPlot.h
index e1bc63d..8ddc0cb 100644
--- a/src/CPlot.h
+++ b/src/CPlot.h
@@ -38,12 +38,21 @@ class CPlot : public QWidget
void addLine(const QPolygonF& line, const QString& label);
void newMarks(const QPolygonF& line);
void addTag(CPlotData::point_t& tag);
+ void setLimits();
void clear();
double getXValByPixel(int px);
+ signals:
+ void activePointSignal(double dist);
+
protected:
+ void contextMenuEvent(QContextMenuEvent *event);
+ void mousePressEvent(QMouseEvent * e);
+ void mouseMoveEvent(QMouseEvent * e);
+ void mouseReleaseEvent(QMouseEvent * e);
+ void wheelEvent ( QWheelEvent * e );
void paintEvent(QPaintEvent * e);
void resizeEvent(QResizeEvent * e);
@@ -66,6 +75,11 @@ class CPlot : public QWidget
void setSizeXLabel();
void setSizeYLabel();
void setSizeDrawArea();
+ void zoom(CPlotAxis &axis, double factor, int cur = 0);
+
+ void createActions();
+ QAction *hZoomAct;
+ QAction *vZoomAct;
CPlotData * m_pData;
@@ -93,5 +107,7 @@ class CPlot : public QWidget
QFontMetrics fm;
+ QPoint startMovePos;
+ int checkClick;
};
#endif //CPLOT_H
diff --git a/src/CPlotAxis.cpp b/src/CPlotAxis.cpp
index 6a4736a..2eacc7f 100644
--- a/src/CPlotAxis.cpp
+++ b/src/CPlotAxis.cpp
@@ -26,7 +26,7 @@
CPlotAxis::CPlotAxis( QObject * parent )
: QObject( parent )
, initialized( false )
-, autoscale( true )
+, autoscale( false )
, scale( 1.0 )
, given_min( 0.0 )
, given_max( 0.0 )
@@ -44,6 +44,16 @@ CPlotAxis::CPlotAxis( QObject * parent )
CPlotAxis::~CPlotAxis()
{}
+double CPlotAxis::getMin()
+{
+ return used_min;
+}
+
+double CPlotAxis::getMax()
+{
+ return used_max;
+}
+
void CPlotAxis::setMinMax( double min, double max )
{
double tmp;
@@ -302,3 +312,12 @@ void CPlotAxis::setScale( const unsigned int pts )
points = pts;
scale = pts / ( used_max - used_min );
}
+
+void CPlotAxis::zoom(double factor, int fixedPoint)
+{
+ double min, p, d;
+ p = pt2val(fixedPoint);
+ min = (p - getMin()) * (1 - factor) + getMin();
+ d = min - getMin() * factor;
+ setMinMax(min, getMax() * factor + d);
+}
diff --git a/src/CPlotAxis.h b/src/CPlotAxis.h
index 9c05da3..913ed66 100644
--- a/src/CPlotAxis.h
+++ b/src/CPlotAxis.h
@@ -47,6 +47,10 @@ class CPlotAxis : public QObject
full /**< minmax && norm*/
};
+ virtual double getMin();
+ virtual double getMax();
+
+ virtual void zoom(double factor, int fixedPoint);
///set the desired minimum and maximum value
virtual void setMinMax(double min, double max);
///set the scale factor for a given size in points
diff --git a/src/CTrackStatProfileWidget.cpp b/src/CTrackStatProfileWidget.cpp
index 483c079..ed29a25 100644
--- a/src/CTrackStatProfileWidget.cpp
+++ b/src/CTrackStatProfileWidget.cpp
@@ -39,7 +39,7 @@ CTrackStatProfileWidget::CTrackStatProfileWidget(QWidget * parent)
connect(&CWptDB::self(),SIGNAL(sigChanged()),this,SLOT(slotChanged()));
slotChanged();
-
+ plot->setLimits();
}
CTrackStatProfileWidget::~CTrackStatProfileWidget()
diff --git a/src/CTrackStatSpeedWidget.cpp b/src/CTrackStatSpeedWidget.cpp
index 0db3481..0aee0f5 100644
--- a/src/CTrackStatSpeedWidget.cpp
+++ b/src/CTrackStatSpeedWidget.cpp
@@ -34,6 +34,7 @@ CTrackStatSpeedWidget::CTrackStatSpeedWidget(QWidget * parent)
connect(&CTrackDB::self(),SIGNAL(sigChanged()),this,SLOT(slotChanged()));
slotChanged();
+ plot->setLimits();
}
diff --git a/src/ITrackStat.cpp b/src/ITrackStat.cpp
index 79a93e5..33774a5 100644
--- a/src/ITrackStat.cpp
+++ b/src/ITrackStat.cpp
@@ -39,7 +39,8 @@ ITrackStat::ITrackStat(QWidget * parent)
plot = new CPlot(this);
layout()->addWidget(plot);
-
+ QObject::connect(plot, SIGNAL(activePointSignal(double)),
+ this, SLOT(activePointEvent(double)));
}
@@ -48,32 +49,26 @@ ITrackStat::~ITrackStat()
}
-void ITrackStat::mousePressEvent(QMouseEvent * e)
+void ITrackStat::activePointEvent(double dist)
{
+ qDebug() << "ITrackStat::activePointEvent" << endl;
if(track.isNull()) return;
+ if(plot == 0) return;
+ QList<CTrack::pt_t>& trkpts = track->getTrackPoints();
+ QList<CTrack::pt_t>::const_iterator trkpt = trkpts.begin();
+ quint32 idx = 0;
+ while(trkpt != trkpts.end()) {
+ if(trkpt->flags & CTrack::pt_t::eDeleted) {
+ ++trkpt; continue;
+ }
- if(e->button() == Qt::LeftButton) {
- QPoint pos = e->pos();
-
- if(plot == 0) return;
-
- double dist = plot->getXValByPixel(pos.x() - SPACING);
- QList<CTrack::pt_t>& trkpts = track->getTrackPoints();
- QList<CTrack::pt_t>::const_iterator trkpt = trkpts.begin();
- quint32 idx = 0;
- while(trkpt != trkpts.end()) {
- if(trkpt->flags & CTrack::pt_t::eDeleted) {
- ++trkpt; continue;
- }
-
- if(dist < trkpt->distance) {
- track->setPointOfFocus(idx);
- break;
- }
- idx = trkpt->idx;
-
- ++trkpt;
+ if(dist < trkpt->distance) {
+ track->setPointOfFocus(idx);
+ break;
}
+ idx = trkpt->idx;
+
+ ++trkpt;
}
}
diff --git a/src/ITrackStat.h b/src/ITrackStat.h
index ce1710d..ce08f48 100644
--- a/src/ITrackStat.h
+++ b/src/ITrackStat.h
@@ -46,12 +46,12 @@ class ITrackStat : public QWidget, private Ui::ITrackStatWidget
CTrack::pt_t trkpt;
};
- void mousePressEvent(QMouseEvent * e);
-
void addWptTags(QVector<wpt_t>& wpts);
CPlot * plot;
QPointer<CTrack> track;
+ protected slots:
+ void activePointEvent(double x);
};
#endif //ITRACKSTAT_H
--
1.5.5.2
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
QLandkarte-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qlandkarte-users