2013-06-20 15:33:26 +00:00
|
|
|
#ifndef DIVEPLANNER_H
|
|
|
|
#define DIVEPLANNER_H
|
|
|
|
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QGraphicsPathItem>
|
2013-06-20 21:40:59 +00:00
|
|
|
#include <QDialog>
|
2013-08-26 12:14:19 +00:00
|
|
|
#include <QAbstractTableModel>
|
2013-08-26 16:18:21 +00:00
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
#include "dive.h"
|
2013-06-20 15:33:26 +00:00
|
|
|
|
2013-08-26 11:43:37 +00:00
|
|
|
namespace Ui{
|
|
|
|
class DivePlanner;
|
|
|
|
};
|
|
|
|
|
2013-07-21 16:54:21 +00:00
|
|
|
class QListView;
|
|
|
|
class QStringListModel;
|
|
|
|
class QModelIndex;
|
|
|
|
|
2013-08-30 10:14:30 +00:00
|
|
|
// Return a Model containing the air types.
|
|
|
|
QStringListModel *airTypes();
|
|
|
|
|
2013-08-26 12:14:19 +00:00
|
|
|
class DivePlannerPointsModel : public QAbstractTableModel{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static DivePlannerPointsModel* instance();
|
2013-08-28 10:27:59 +00:00
|
|
|
enum Sections{REMOVE, DEPTH, DURATION, GAS, CCSETPOINT, COLUMNS};
|
2013-08-26 16:18:21 +00:00
|
|
|
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
2013-09-19 02:33:53 +00:00
|
|
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
2013-08-30 18:53:10 +00:00
|
|
|
void removeSelectedPoints(const QVector<int>& rows);
|
2013-09-19 02:33:53 +00:00
|
|
|
enum Modes { PLAN, ADD };
|
|
|
|
void setPlanMode(bool);
|
|
|
|
bool isPlanner();
|
2013-09-20 12:36:14 +00:00
|
|
|
void createSimpleDive();
|
2013-08-30 19:08:55 +00:00
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
/**
|
|
|
|
* @return the row number.
|
|
|
|
*/
|
2013-08-26 17:54:07 +00:00
|
|
|
void editStop(int row, divedatapoint newData );
|
2013-08-26 17:17:39 +00:00
|
|
|
divedatapoint at(int row);
|
2013-09-22 18:01:18 +00:00
|
|
|
int size();
|
2013-09-09 10:18:22 +00:00
|
|
|
struct diveplan getDiveplan();
|
2013-08-26 16:18:21 +00:00
|
|
|
public slots:
|
2013-09-09 22:57:22 +00:00
|
|
|
int addStop(int meters = 0, int minutes = 0,const QString& gas = QString(), int ccpoint = 0 );
|
2013-08-26 16:18:21 +00:00
|
|
|
void setGFHigh(short gfhigh);
|
|
|
|
void setGFLow(short ghflow);
|
|
|
|
void setSurfacePressure(int pressure);
|
|
|
|
void setBottomSac(int sac);
|
|
|
|
void setDecoSac(int sac);
|
|
|
|
void setStartTime(const QTime& t);
|
|
|
|
void setLastStop6m(bool value);
|
|
|
|
void createPlan();
|
2013-09-02 19:21:08 +00:00
|
|
|
void remove(const QModelIndex& index);
|
2013-09-19 02:33:53 +00:00
|
|
|
void cancelPlan();
|
|
|
|
void createTemporaryPlan();
|
|
|
|
void deleteTemporaryPlan();
|
2013-09-16 14:38:41 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void planCreated();
|
|
|
|
void planCanceled();
|
2013-08-26 16:18:21 +00:00
|
|
|
|
2013-08-26 12:14:19 +00:00
|
|
|
private:
|
2013-08-26 16:18:21 +00:00
|
|
|
explicit DivePlannerPointsModel(QObject* parent = 0);
|
|
|
|
struct diveplan diveplan;
|
2013-09-19 02:33:53 +00:00
|
|
|
Modes mode;
|
2013-08-26 16:18:21 +00:00
|
|
|
QVector<divedatapoint> divepoints;
|
2013-09-16 15:11:06 +00:00
|
|
|
struct dive *tempDive;
|
|
|
|
void deleteTemporaryPlan(struct divedatapoint *dp);
|
2013-08-26 12:14:19 +00:00
|
|
|
};
|
|
|
|
|
2013-06-27 19:45:58 +00:00
|
|
|
class Button : public QObject, public QGraphicsRectItem {
|
2013-06-21 19:44:38 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit Button(QObject* parent = 0);
|
2013-06-27 19:45:58 +00:00
|
|
|
void setText(const QString& text);
|
|
|
|
void setPixmap(const QPixmap& pixmap);
|
|
|
|
|
2013-06-21 19:44:38 +00:00
|
|
|
protected:
|
2013-06-23 20:09:29 +00:00
|
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
2013-06-21 19:44:38 +00:00
|
|
|
signals:
|
|
|
|
void clicked();
|
2013-06-27 19:45:58 +00:00
|
|
|
private:
|
|
|
|
QGraphicsPixmapItem *icon;
|
|
|
|
QGraphicsSimpleTextItem *text;
|
2013-06-21 19:44:38 +00:00
|
|
|
};
|
|
|
|
|
2013-06-20 17:29:32 +00:00
|
|
|
class DiveHandler : public QGraphicsEllipseItem{
|
|
|
|
public:
|
2013-06-23 20:09:29 +00:00
|
|
|
DiveHandler();
|
2013-07-04 14:01:59 +00:00
|
|
|
protected:
|
2013-08-26 16:18:21 +00:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
2013-06-20 17:29:32 +00:00
|
|
|
};
|
2013-06-20 18:52:27 +00:00
|
|
|
|
2013-06-20 19:48:24 +00:00
|
|
|
class Ruler : public QGraphicsLineItem{
|
2013-06-20 18:52:27 +00:00
|
|
|
public:
|
2013-06-23 20:09:29 +00:00
|
|
|
Ruler();
|
2013-06-20 18:52:27 +00:00
|
|
|
void setMinimum(double minimum);
|
|
|
|
void setMaximum(double maximum);
|
|
|
|
void setTickInterval(double interval);
|
|
|
|
void setOrientation(Qt::Orientation orientation);
|
2013-07-02 14:12:15 +00:00
|
|
|
void setTickSize(qreal size);
|
2013-06-20 19:48:24 +00:00
|
|
|
void updateTicks();
|
2013-06-21 19:07:44 +00:00
|
|
|
double minimum() const;
|
|
|
|
double maximum() const;
|
2013-06-20 20:34:42 +00:00
|
|
|
qreal valueAt(const QPointF& p);
|
2013-07-02 16:31:25 +00:00
|
|
|
qreal percentAt(const QPointF& p);
|
2013-06-20 21:25:03 +00:00
|
|
|
qreal posAtValue(qreal value);
|
2013-07-02 15:01:47 +00:00
|
|
|
void setColor(const QColor& color);
|
2013-09-16 23:10:12 +00:00
|
|
|
void setTextColor(const QColor& color);
|
2013-06-20 18:52:27 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Qt::Orientation orientation;
|
|
|
|
QList<QGraphicsLineItem*> ticks;
|
2013-09-16 23:10:12 +00:00
|
|
|
QList<QGraphicsSimpleTextItem*> labels;
|
2013-06-20 18:52:27 +00:00
|
|
|
double min;
|
|
|
|
double max;
|
2013-06-20 19:48:24 +00:00
|
|
|
double interval;
|
2013-06-20 18:52:27 +00:00
|
|
|
double posBegin;
|
|
|
|
double posEnd;
|
2013-07-02 14:12:15 +00:00
|
|
|
double tickSize;
|
2013-09-16 23:10:12 +00:00
|
|
|
QColor textColor;
|
2013-06-20 18:52:27 +00:00
|
|
|
};
|
|
|
|
|
2013-06-20 21:40:59 +00:00
|
|
|
class DivePlannerGraphics : public QGraphicsView {
|
2013-06-20 15:33:26 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-06-20 21:40:59 +00:00
|
|
|
DivePlannerGraphics(QWidget* parent = 0);
|
2013-06-20 15:37:41 +00:00
|
|
|
protected:
|
2013-06-23 20:09:29 +00:00
|
|
|
virtual void mouseDoubleClickEvent(QMouseEvent* event);
|
|
|
|
virtual void showEvent(QShowEvent* event);
|
|
|
|
virtual void resizeEvent(QResizeEvent* event);
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent* event);
|
|
|
|
virtual void mousePressEvent(QMouseEvent* event);
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent* event);
|
2013-06-21 19:28:17 +00:00
|
|
|
bool isPointOutOfBoundaries(const QPointF& point);
|
2013-07-02 13:53:08 +00:00
|
|
|
qreal fromPercent(qreal percent, Qt::Orientation orientation);
|
2013-06-21 19:51:13 +00:00
|
|
|
private slots:
|
2013-07-04 14:06:28 +00:00
|
|
|
void keyEscAction();
|
2013-07-04 14:16:42 +00:00
|
|
|
void keyDeleteAction();
|
2013-07-04 14:28:39 +00:00
|
|
|
void keyUpAction();
|
|
|
|
void keyDownAction();
|
2013-07-04 15:30:05 +00:00
|
|
|
void keyLeftAction();
|
|
|
|
void keyRightAction();
|
2013-06-21 19:51:13 +00:00
|
|
|
void increaseTime();
|
|
|
|
void increaseDepth();
|
2013-07-21 12:27:04 +00:00
|
|
|
void decreaseTime();
|
|
|
|
void decreaseDepth();;
|
2013-09-19 03:19:49 +00:00
|
|
|
void drawProfile();
|
2013-07-21 16:54:21 +00:00
|
|
|
void prepareSelectGas();
|
|
|
|
void selectGas(const QModelIndex& index);
|
2013-08-26 17:17:39 +00:00
|
|
|
void pointInserted(const QModelIndex&, int start, int end);
|
2013-08-30 18:53:10 +00:00
|
|
|
void pointsRemoved(const QModelIndex&, int start, int end);
|
2013-09-21 15:50:09 +00:00
|
|
|
bool eventFilter(QObject *object, QEvent* event);
|
2013-06-20 15:33:26 +00:00
|
|
|
private:
|
2013-09-19 14:13:53 +00:00
|
|
|
void moveActiveHandler(const QPointF& MappedPos, const int pos);
|
2013-07-02 13:53:08 +00:00
|
|
|
|
|
|
|
/* This are the lines of the plotted dive. */
|
2013-06-20 16:20:41 +00:00
|
|
|
QList<QGraphicsLineItem*> lines;
|
2013-07-02 13:53:08 +00:00
|
|
|
|
|
|
|
/* This is the user-entered handles. */
|
2013-06-20 17:29:32 +00:00
|
|
|
QList<DiveHandler *> handles;
|
2013-07-02 13:53:08 +00:00
|
|
|
|
2013-07-21 15:12:31 +00:00
|
|
|
/* this is the user-entered gases.
|
|
|
|
This must be a button, so the
|
|
|
|
user cna click to choose a new gas.
|
|
|
|
*/
|
|
|
|
QList<Button*> gases;
|
2013-07-21 16:54:21 +00:00
|
|
|
QListView *gasListView;
|
|
|
|
QStringListModel *gasChoices;
|
|
|
|
Button *currentGasChoice;
|
2013-07-21 15:12:31 +00:00
|
|
|
|
2013-07-02 13:53:08 +00:00
|
|
|
/* those are the lines that follows the mouse. */
|
2013-06-20 16:53:12 +00:00
|
|
|
QGraphicsLineItem *verticalLine;
|
|
|
|
QGraphicsLineItem *horizontalLine;
|
2013-07-02 13:53:08 +00:00
|
|
|
|
|
|
|
/* This is the handler that's being dragged. */
|
2013-06-20 17:46:40 +00:00
|
|
|
DiveHandler *activeDraggedHandler;
|
2013-07-02 13:53:08 +00:00
|
|
|
|
2013-07-04 13:29:28 +00:00
|
|
|
// When we start to move the handler, this pos is saved.
|
|
|
|
// so we can revert it later.
|
|
|
|
QPointF originalHandlerPos;
|
2013-07-02 13:53:08 +00:00
|
|
|
|
|
|
|
/* this is the background of the dive, the blue-gradient. */
|
2013-06-27 22:52:58 +00:00
|
|
|
QGraphicsPolygonItem *diveBg;
|
2013-07-02 13:53:08 +00:00
|
|
|
|
|
|
|
/* This is the bottom ruler - the x axis, and it's associated text */
|
2013-06-20 19:48:24 +00:00
|
|
|
Ruler *timeLine;
|
2013-06-20 20:54:36 +00:00
|
|
|
QGraphicsSimpleTextItem *timeString;
|
|
|
|
|
2013-07-02 13:53:08 +00:00
|
|
|
/* this is the left ruler, the y axis, and it's associated text. */
|
2013-06-20 19:48:24 +00:00
|
|
|
Ruler *depthLine;
|
2013-06-20 20:54:36 +00:00
|
|
|
QGraphicsSimpleTextItem *depthString;
|
2013-06-20 19:48:24 +00:00
|
|
|
|
2013-07-02 13:53:08 +00:00
|
|
|
/* Buttons */
|
|
|
|
Button *plusTime; // adds 10 minutes to the time ruler.
|
|
|
|
Button *plusDepth; // adds 10 meters to the depth ruler.
|
|
|
|
Button *lessTime; // remove 10 minutes to the time ruler.
|
|
|
|
Button *lessDepth; // remove 10 meters to the depth ruler.
|
2013-07-02 17:36:52 +00:00
|
|
|
|
|
|
|
int minMinutes; // this holds the minimum duration of the dive.
|
2013-07-21 12:44:52 +00:00
|
|
|
int dpMaxTime; // this is the time of the dive calculated by the deco.
|
2013-06-20 15:33:26 +00:00
|
|
|
};
|
2013-06-20 21:40:59 +00:00
|
|
|
|
2013-08-26 11:43:37 +00:00
|
|
|
class DivePlannerWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit DivePlannerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
2013-08-26 16:18:21 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void startTimeChanged(const QTime& time);
|
|
|
|
void atmPressureChanged(const QString& pressure);
|
|
|
|
void bottomSacChanged(const QString& bottomSac);
|
|
|
|
void decoSacChanged(const QString& decosac);
|
|
|
|
void gflowChanged(const QString& gflow);
|
|
|
|
void gfhighChanged(const QString& gfhigh);
|
|
|
|
void lastStopChanged(bool checked);
|
2013-08-26 11:43:37 +00:00
|
|
|
private:
|
|
|
|
Ui::DivePlanner *ui;
|
|
|
|
};
|
|
|
|
|
2013-06-20 15:33:26 +00:00
|
|
|
#endif
|