2014-01-14 16:30:13 +00:00
|
|
|
#include "profilewidget2.h"
|
2014-01-15 14:00:23 +00:00
|
|
|
#include "diveplotdatamodel.h"
|
|
|
|
#include "divepixmapitem.h"
|
|
|
|
#include "diverectitem.h"
|
|
|
|
#include "divecartesianaxis.h"
|
|
|
|
#include "diveprofileitem.h"
|
2014-01-15 14:23:40 +00:00
|
|
|
#include "helpers.h"
|
2014-01-15 15:34:55 +00:00
|
|
|
#include "profile.h"
|
2014-01-16 17:02:32 +00:00
|
|
|
#include "diveeventitem.h"
|
2014-01-21 12:48:26 +00:00
|
|
|
#include "divetextitem.h"
|
2014-02-05 16:34:45 +00:00
|
|
|
#include "divetooltipitem.h"
|
2014-02-07 18:34:42 +00:00
|
|
|
#include "animationfunctions.h"
|
2014-01-15 14:00:23 +00:00
|
|
|
#include <QStateMachine>
|
2014-01-15 14:34:42 +00:00
|
|
|
#include <QSignalTransition>
|
2014-01-15 15:01:29 +00:00
|
|
|
#include <QPropertyAnimation>
|
2014-01-15 15:04:01 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QContextMenuEvent>
|
2014-01-16 20:39:13 +00:00
|
|
|
#include <QDebug>
|
2014-02-04 23:47:50 +00:00
|
|
|
#include <QScrollBar>
|
2014-01-16 17:02:32 +00:00
|
|
|
|
2014-01-15 15:20:05 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
#include <QTableView>
|
|
|
|
#endif
|
2014-01-16 05:28:33 +00:00
|
|
|
#include "mainwindow.h"
|
2014-01-15 15:20:05 +00:00
|
|
|
|
2014-02-07 17:32:39 +00:00
|
|
|
/* This is the global 'Item position' variable.
|
|
|
|
* it should tell you where to position things up
|
|
|
|
* on the canvas.
|
|
|
|
*
|
|
|
|
* please, please, please, use this instead of
|
|
|
|
* hard coding the item on the scene with a random
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
static struct _ItemPos{
|
|
|
|
struct _Pos{
|
|
|
|
QPointF on;
|
|
|
|
QPointF off;
|
|
|
|
};
|
|
|
|
struct _Axis{
|
|
|
|
_Pos pos;
|
|
|
|
QLineF shrinked;
|
|
|
|
QLineF expanded;
|
|
|
|
};
|
|
|
|
_Pos background;
|
|
|
|
_Axis depth;
|
|
|
|
_Axis partialgas;
|
|
|
|
_Axis time;
|
|
|
|
_Axis cylinder;
|
|
|
|
_Axis temperature;
|
|
|
|
} itemPos;
|
2014-02-07 16:59:58 +00:00
|
|
|
|
2014-01-15 14:00:23 +00:00
|
|
|
ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
|
|
|
QGraphicsView(parent),
|
|
|
|
dataModel(new DivePlotDataModel(this)),
|
|
|
|
currentState(INVALID),
|
2014-02-04 23:47:50 +00:00
|
|
|
zoomLevel(0),
|
2014-01-15 14:00:23 +00:00
|
|
|
background (new DivePixmapItem()),
|
2014-02-05 16:34:45 +00:00
|
|
|
toolTipItem(new ToolTipItem()),
|
2014-01-15 14:00:23 +00:00
|
|
|
profileYAxis(new DepthAxis()),
|
2014-01-27 17:14:42 +00:00
|
|
|
gasYAxis(new PartialGasPressureAxis()),
|
2014-01-16 23:30:47 +00:00
|
|
|
temperatureAxis(new TemperatureAxis()),
|
2014-01-15 14:00:23 +00:00
|
|
|
timeAxis(new TimeAxis()),
|
2014-02-07 16:14:36 +00:00
|
|
|
diveProfileItem(new DiveProfileItem()),
|
2014-01-17 16:28:59 +00:00
|
|
|
cylinderPressureAxis(new DiveCartesianAxis()),
|
2014-02-07 16:14:36 +00:00
|
|
|
temperatureItem(new DiveTemperatureItem()),
|
|
|
|
gasPressureItem(new DiveGasPressureItem()),
|
2014-01-18 22:38:21 +00:00
|
|
|
cartesianPlane(new DiveCartesianPlane()),
|
2014-01-22 17:08:19 +00:00
|
|
|
meanDepth(new MeanDepthLine()),
|
2014-01-21 16:59:19 +00:00
|
|
|
diveComputerText(new DiveTextItem()),
|
2014-02-07 16:14:36 +00:00
|
|
|
diveCeiling(new DiveCalculatedCeiling()),
|
2014-02-07 16:59:58 +00:00
|
|
|
reportedCeiling(new DiveReportedCeiling()),
|
|
|
|
pn2GasItem( new PartialPressureGasItem()),
|
|
|
|
pheGasItem( new PartialPressureGasItem()),
|
|
|
|
po2GasItem( new PartialPressureGasItem())
|
2014-01-14 16:30:13 +00:00
|
|
|
{
|
2014-02-07 16:59:58 +00:00
|
|
|
setupSceneAndFlags();
|
|
|
|
setupItemSizes();
|
|
|
|
setupItemOnScene();
|
|
|
|
addItemsToScene();
|
|
|
|
scene()->installEventFilter(this);
|
2014-02-07 18:34:42 +00:00
|
|
|
setEmptyState();
|
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
QTableView *diveDepthTableView = new QTableView();
|
|
|
|
diveDepthTableView->setModel(dataModel);
|
|
|
|
mainWindow()->tabWidget()->addTab(diveDepthTableView, "Depth Model");
|
|
|
|
#endif
|
|
|
|
}
|
2014-01-15 14:23:40 +00:00
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
void ProfileWidget2::addItemsToScene()
|
|
|
|
{
|
|
|
|
scene()->addItem(background);
|
|
|
|
scene()->addItem(toolTipItem);
|
|
|
|
scene()->addItem(profileYAxis);
|
|
|
|
scene()->addItem(gasYAxis);
|
|
|
|
scene()->addItem(temperatureAxis);
|
|
|
|
scene()->addItem(timeAxis);
|
|
|
|
scene()->addItem(diveProfileItem);
|
|
|
|
scene()->addItem(cylinderPressureAxis);
|
|
|
|
scene()->addItem(temperatureItem);
|
|
|
|
scene()->addItem(gasPressureItem);
|
|
|
|
scene()->addItem(cartesianPlane);
|
|
|
|
scene()->addItem(meanDepth);
|
|
|
|
scene()->addItem(diveComputerText);
|
|
|
|
scene()->addItem(diveCeiling);
|
|
|
|
scene()->addItem(reportedCeiling);
|
|
|
|
scene()->addItem(pn2GasItem);
|
|
|
|
scene()->addItem(pheGasItem);
|
|
|
|
scene()->addItem(po2GasItem);
|
|
|
|
Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
|
|
|
|
scene()->addItem(tissue);
|
|
|
|
}
|
|
|
|
}
|
2014-01-15 14:23:40 +00:00
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
void ProfileWidget2::setupItemOnScene()
|
|
|
|
{
|
2014-02-07 18:34:42 +00:00
|
|
|
background->setZValue(9999);
|
2014-02-07 16:59:58 +00:00
|
|
|
toolTipItem->setTimeAxis(timeAxis);
|
2014-01-23 19:54:34 +00:00
|
|
|
|
|
|
|
gasYAxis->setOrientation(DiveCartesianAxis::BottomToTop);
|
|
|
|
gasYAxis->setX(3);
|
|
|
|
gasYAxis->setTickInterval(1);
|
|
|
|
gasYAxis->setTickSize(2);
|
|
|
|
gasYAxis->setY(70);
|
2014-01-27 17:14:42 +00:00
|
|
|
gasYAxis->setMinimum(0);
|
|
|
|
gasYAxis->setModel(dataModel);
|
2014-01-16 20:39:13 +00:00
|
|
|
|
2014-01-16 21:28:33 +00:00
|
|
|
temperatureAxis->setOrientation(DiveCartesianAxis::BottomToTop);
|
2014-01-16 20:39:13 +00:00
|
|
|
temperatureAxis->setX(3);
|
|
|
|
temperatureAxis->setTickSize(2);
|
|
|
|
temperatureAxis->setTickInterval(300);
|
|
|
|
|
2014-01-17 17:34:15 +00:00
|
|
|
cylinderPressureAxis->setOrientation(DiveCartesianAxis::BottomToTop);
|
2014-01-17 16:28:59 +00:00
|
|
|
cylinderPressureAxis->setX(3);
|
|
|
|
cylinderPressureAxis->setTickSize(2);
|
|
|
|
cylinderPressureAxis->setTickInterval(30000);
|
|
|
|
|
2014-01-18 22:38:21 +00:00
|
|
|
meanDepth->setLine(0,0,96,0);
|
|
|
|
meanDepth->setX(3);
|
|
|
|
meanDepth->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
|
2014-01-22 17:29:25 +00:00
|
|
|
meanDepth->setZValue(1);
|
2014-01-15 14:23:40 +00:00
|
|
|
|
2014-01-16 14:32:45 +00:00
|
|
|
cartesianPlane->setBottomAxis(timeAxis);
|
|
|
|
cartesianPlane->setLeftAxis(profileYAxis);
|
|
|
|
|
2014-01-21 12:48:26 +00:00
|
|
|
diveComputerText->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
diveComputerText->setBrush(getColor(TIME_TEXT));
|
|
|
|
|
2014-02-07 16:14:36 +00:00
|
|
|
setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
|
|
|
|
setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
|
2014-01-23 17:02:12 +00:00
|
|
|
for(int i = 0; i < 16; i++){
|
|
|
|
DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue();
|
2014-02-07 16:14:36 +00:00
|
|
|
setupItem(tissueItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::TISSUE_1 + i, DivePlotDataModel::TIME, 1+i);
|
2014-01-23 17:02:12 +00:00
|
|
|
allTissues.append(tissueItem);
|
|
|
|
}
|
2014-02-07 16:14:36 +00:00
|
|
|
setupItem(gasPressureItem, timeAxis, cylinderPressureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1);
|
|
|
|
setupItem(temperatureItem, timeAxis, temperatureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1);
|
|
|
|
setupItem(diveProfileItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::DEPTH, DivePlotDataModel::TIME, 0);
|
2014-01-23 18:03:19 +00:00
|
|
|
|
2014-01-27 17:14:42 +00:00
|
|
|
#define CREATE_PP_GAS( ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS ) \
|
|
|
|
ITEM = new PartialPressureGasItem(); \
|
2014-02-07 16:14:36 +00:00
|
|
|
setupItem(ITEM, timeAxis, gasYAxis, dataModel, DivePlotDataModel::VERTICAL_COLUMN, DivePlotDataModel::TIME, 0); \
|
2014-01-27 17:14:42 +00:00
|
|
|
ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \
|
|
|
|
ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \
|
|
|
|
ITEM->setColors(getColor(COLOR), getColor(COLOR_ALERT)); \
|
2014-02-07 16:14:36 +00:00
|
|
|
ITEM->preferencesChanged();
|
2014-01-27 17:14:42 +00:00
|
|
|
|
|
|
|
CREATE_PP_GAS( pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph");
|
|
|
|
CREATE_PP_GAS( pheGasItem, PHE, PHE, PHE_ALERT, "phethreshold", "phegraph");
|
|
|
|
CREATE_PP_GAS( po2GasItem, PO2, PO2, PO2_ALERT, "po2threshold", "po2graph");
|
|
|
|
#undef CREATE_PP_GAS
|
2014-01-23 20:03:28 +00:00
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
}
|
2014-01-15 15:01:29 +00:00
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
void ProfileWidget2::setupItemSizes()
|
|
|
|
{
|
2014-02-07 19:38:00 +00:00
|
|
|
// Scene is *always* (double) 100 / 100.
|
|
|
|
// Background Config
|
|
|
|
/* Much probably a better math is needed here.
|
|
|
|
* good thing is that we only need to change the
|
|
|
|
* Axis and everything else is auto-adjusted.*
|
|
|
|
*/
|
|
|
|
|
2014-02-07 17:32:39 +00:00
|
|
|
itemPos.background.on.setX(0);
|
|
|
|
itemPos.background.on.setY(0);
|
|
|
|
itemPos.background.off.setX(0);
|
|
|
|
itemPos.background.off.setY(110);
|
2014-02-07 19:38:00 +00:00
|
|
|
|
|
|
|
//Depth Axis Config
|
|
|
|
itemPos.depth.pos.on.setX(3);
|
|
|
|
itemPos.depth.pos.on.setY(3);
|
|
|
|
itemPos.depth.pos.off.setX(-2);
|
|
|
|
itemPos.depth.pos.off.setY(3);
|
|
|
|
itemPos.depth.expanded.setP1(QPointF(0,0));
|
|
|
|
itemPos.depth.expanded.setP2(QPointF(0,94));
|
|
|
|
itemPos.depth.shrinked.setP1(QPointF(0,0));
|
|
|
|
itemPos.depth.shrinked.setP2(QPointF(0,60));
|
|
|
|
|
|
|
|
// Time Axis Config
|
|
|
|
itemPos.time.pos.on.setX(3);
|
|
|
|
itemPos.time.pos.on.setY(97);
|
|
|
|
itemPos.time.pos.off.setX(3);
|
|
|
|
itemPos.time.pos.off.setY(110);
|
|
|
|
itemPos.time.expanded.setP1(QPointF(0,0));
|
|
|
|
itemPos.time.expanded.setP2(QPointF(94,0));
|
2014-01-14 16:30:13 +00:00
|
|
|
}
|
2014-02-07 16:59:58 +00:00
|
|
|
|
2014-02-07 16:14:36 +00:00
|
|
|
void ProfileWidget2::setupItem(AbstractProfilePolygonItem* item, DiveCartesianAxis* hAxis, DiveCartesianAxis* vAxis, DivePlotDataModel* model, int vData, int hData, int zValue)
|
|
|
|
{
|
2014-02-07 16:59:58 +00:00
|
|
|
item->setHorizontalAxis(hAxis);
|
|
|
|
item->setVerticalAxis(vAxis);
|
|
|
|
item->setModel(model);
|
|
|
|
item->setVerticalDataColumn(vData);
|
|
|
|
item->setHorizontalDataColumn(hData);
|
|
|
|
item->setZValue(zValue);
|
2014-02-07 16:14:36 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
void ProfileWidget2::setupSceneAndFlags()
|
|
|
|
{
|
|
|
|
setScene(new QGraphicsScene());
|
|
|
|
scene()->setSceneRect(0, 0, 100, 100);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
|
|
|
|
setOptimizationFlags(QGraphicsView::DontSavePainterState);
|
|
|
|
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
|
|
|
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
|
|
|
|
setMouseTracking(true);
|
|
|
|
background->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
|
|
|
}
|
2014-01-14 16:30:13 +00:00
|
|
|
|
|
|
|
// Currently just one dive, but the plan is to enable All of the selected dives.
|
|
|
|
void ProfileWidget2::plotDives(QList<dive*> dives)
|
|
|
|
{
|
2014-01-15 15:34:55 +00:00
|
|
|
// I Know that it's a list, but currently we are
|
|
|
|
// using just the first.
|
|
|
|
struct dive *d = dives.first();
|
2014-01-16 04:50:56 +00:00
|
|
|
if (!d)
|
2014-01-15 15:34:55 +00:00
|
|
|
return;
|
|
|
|
|
2014-02-07 18:54:12 +00:00
|
|
|
setProfileState();
|
2014-01-15 15:34:55 +00:00
|
|
|
// Here we need to probe for the limits of the dive.
|
|
|
|
// There's already a function that does exactly that,
|
|
|
|
// but it's using the graphics context, and I need to
|
|
|
|
// replace that.
|
|
|
|
struct divecomputer *currentdc = select_dc(&d->dc);
|
|
|
|
Q_ASSERT(currentdc);
|
|
|
|
|
|
|
|
/* This struct holds all the data that's about to be plotted.
|
|
|
|
* I'm not sure this is the best approach ( but since we are
|
|
|
|
* interpolating some points of the Dive, maybe it is... )
|
|
|
|
* The Calculation of the points should be done per graph,
|
|
|
|
* so I'll *not* calculate everything if something is not being
|
|
|
|
* shown.
|
|
|
|
*/
|
|
|
|
struct plot_info pInfo = calculate_max_limits_new(d, currentdc);
|
2014-01-17 16:43:25 +00:00
|
|
|
create_plot_info_new(d, currentdc, &pInfo);
|
2014-01-15 20:03:58 +00:00
|
|
|
int maxtime = get_maxtime(&pInfo);
|
|
|
|
int maxdepth = get_maxdepth(&pInfo);
|
2014-01-15 15:34:55 +00:00
|
|
|
|
2014-01-27 17:14:42 +00:00
|
|
|
dataModel->setDive(current_dive, pInfo);
|
2014-02-05 16:53:57 +00:00
|
|
|
toolTipItem->setPlotInfo(pInfo);
|
|
|
|
|
2014-01-16 17:02:32 +00:00
|
|
|
// It seems that I'll have a lot of boilerplate setting the model / axis for
|
|
|
|
// each item, I'll mostly like to fix this in the future, but I'll keep at this for now.
|
2014-01-18 22:33:12 +00:00
|
|
|
profileYAxis->setMaximum(maxdepth);
|
2014-01-15 15:34:55 +00:00
|
|
|
profileYAxis->updateTicks();
|
2014-01-16 20:39:13 +00:00
|
|
|
temperatureAxis->setMinimum(pInfo.mintemp);
|
|
|
|
temperatureAxis->setMaximum(pInfo.maxtemp);
|
2014-01-15 20:03:58 +00:00
|
|
|
timeAxis->setMaximum(maxtime);
|
2014-01-27 19:09:08 +00:00
|
|
|
|
|
|
|
int i, incr;
|
|
|
|
static int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 };
|
|
|
|
/* Time markers: at most every 10 seconds, but no more than 12 markers.
|
|
|
|
* We start out with 10 seconds and increment up to 30 minutes,
|
|
|
|
* depending on the dive time.
|
|
|
|
* This allows for 6h dives - enough (I hope) for even the craziest
|
|
|
|
* divers - but just in case, for those 8h depth-record-breaking dives,
|
|
|
|
* we double the interval if this still doesn't get us to 12 or fewer
|
|
|
|
* time markers */
|
|
|
|
i = 0;
|
|
|
|
while (i < 7 && maxtime / increments[i] > 12)
|
|
|
|
i++;
|
|
|
|
incr = increments[i];
|
|
|
|
while (maxtime / incr > 12)
|
|
|
|
incr *= 2;
|
|
|
|
timeAxis->setTickInterval(incr);
|
2014-01-15 15:34:55 +00:00
|
|
|
timeAxis->updateTicks();
|
2014-01-17 16:28:59 +00:00
|
|
|
cylinderPressureAxis->setMinimum(pInfo.minpressure);
|
|
|
|
cylinderPressureAxis->setMaximum(pInfo.maxpressure);
|
2014-01-22 17:08:19 +00:00
|
|
|
meanDepth->setMeanDepth(pInfo.meandepth);
|
2014-01-18 22:38:21 +00:00
|
|
|
meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth));
|
2014-01-23 19:54:34 +00:00
|
|
|
|
2014-01-27 17:14:42 +00:00
|
|
|
dataModel->emitDataChanged();
|
2014-01-23 18:12:18 +00:00
|
|
|
// The event items are a bit special since we don't know how many events are going to
|
|
|
|
// exist on a dive, so I cant create cache items for that. that's why they are here
|
|
|
|
// while all other items are up there on the constructor.
|
2014-01-16 17:02:32 +00:00
|
|
|
qDeleteAll(eventItems);
|
|
|
|
eventItems.clear();
|
|
|
|
struct event *event = currentdc->events;
|
|
|
|
while (event) {
|
|
|
|
DiveEventItem *item = new DiveEventItem();
|
|
|
|
item->setHorizontalAxis(timeAxis);
|
|
|
|
item->setVerticalAxis(profileYAxis);
|
|
|
|
item->setModel(dataModel);
|
|
|
|
item->setEvent(event);
|
2014-01-19 22:16:08 +00:00
|
|
|
item->setZValue(2);
|
2014-01-16 17:02:32 +00:00
|
|
|
scene()->addItem(item);
|
|
|
|
eventItems.push_back(item);
|
|
|
|
event = event->next;
|
|
|
|
}
|
2014-01-16 20:39:13 +00:00
|
|
|
|
2014-01-21 12:48:26 +00:00
|
|
|
diveComputerText->setText(currentdc->model);
|
2014-01-21 15:27:08 +00:00
|
|
|
diveComputerText->animateMoveTo(1 , sceneRect().height());
|
2014-01-14 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::settingsChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
2014-02-07 17:32:39 +00:00
|
|
|
QGraphicsView::resizeEvent(event); DiveRectItem *depthController;
|
2014-01-15 14:55:33 +00:00
|
|
|
fitInView(sceneRect(), Qt::IgnoreAspectRatio);
|
2014-02-07 18:34:42 +00:00
|
|
|
fixBackgroundPos();
|
2014-01-15 14:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::fixBackgroundPos()
|
|
|
|
{
|
2014-02-07 18:34:42 +00:00
|
|
|
QPixmap toBeScaled;
|
|
|
|
if (!backgrounds.keys().contains(backgroundFile)){
|
|
|
|
backgrounds[backgroundFile] = QPixmap(backgroundFile);
|
|
|
|
}
|
|
|
|
toBeScaled = backgrounds[backgroundFile];
|
2014-01-17 12:18:03 +00:00
|
|
|
QPixmap p = toBeScaled.scaledToHeight(viewport()->height());
|
2014-01-16 04:50:56 +00:00
|
|
|
int x = viewport()->width() / 2 - p.width() / 2;
|
2014-02-07 17:32:39 +00:00
|
|
|
background->setPixmap(p);
|
|
|
|
background->setX(mapToScene(x, 0).x());
|
2014-01-14 16:30:13 +00:00
|
|
|
}
|
2014-02-04 23:47:50 +00:00
|
|
|
|
|
|
|
void ProfileWidget2::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
2014-02-05 16:34:45 +00:00
|
|
|
QPoint toolTipPos = mapFromScene(toolTipItem->pos());
|
2014-02-04 23:47:50 +00:00
|
|
|
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());
|
2014-02-05 16:34:45 +00:00
|
|
|
toolTipItem->setPos(mapToScene(toolTipPos));
|
2014-02-04 23:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2014-02-05 16:57:02 +00:00
|
|
|
const qreal yRat = (qreal)pos.y() / viewport()->height();
|
|
|
|
const qreal xRat = (qreal)pos.x() / viewport()->width();
|
|
|
|
vs->setValue(yRat * vs->maximum());
|
|
|
|
hs->setValue(xRat * hs->maximum());
|
2014-02-04 23:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
{
|
2014-02-05 17:25:24 +00:00
|
|
|
toolTipItem->refresh(mapToScene(event->pos()));
|
2014-02-05 16:34:45 +00:00
|
|
|
QPoint toolTipPos = mapFromScene(toolTipItem->pos());
|
2014-02-04 23:47:50 +00:00
|
|
|
if (zoomLevel == 0) {
|
|
|
|
QGraphicsView::mouseMoveEvent(event);
|
2014-02-05 16:34:45 +00:00
|
|
|
} else {
|
|
|
|
toolTipItem->setPos(mapToScene(toolTipPos));
|
2014-02-04 23:47:50 +00:00
|
|
|
scrollViewTo(event->pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 18:15:59 +00:00
|
|
|
bool ProfileWidget2::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsScene *s = qobject_cast<QGraphicsScene*>(object);
|
|
|
|
if (s && event->type() == QEvent::GraphicsSceneHelp){
|
|
|
|
event->ignore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QGraphicsView::eventFilter(object, event);
|
|
|
|
}
|
2014-02-07 18:34:42 +00:00
|
|
|
|
|
|
|
void ProfileWidget2::setEmptyState()
|
|
|
|
{
|
|
|
|
// Then starting Empty State, move the background up.
|
|
|
|
if (currentState == EMPTY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
backgroundFile = QString(":poster%1").arg( rand()%3 +1);
|
|
|
|
currentState = EMPTY;
|
|
|
|
fixBackgroundPos();
|
2014-02-07 18:54:12 +00:00
|
|
|
Animations::moveTo(background, background->x(), itemPos.background.on.y());
|
2014-02-07 19:38:00 +00:00
|
|
|
profileYAxis->setPos(itemPos.depth.pos.off);
|
2014-02-07 18:34:42 +00:00
|
|
|
toolTipItem->setVisible(false);
|
|
|
|
gasYAxis->setVisible(false);
|
|
|
|
temperatureAxis->setVisible(false);
|
2014-02-07 19:38:00 +00:00
|
|
|
timeAxis->setPos(itemPos.time.pos.off);
|
2014-02-07 18:34:42 +00:00
|
|
|
diveProfileItem->setVisible(false);
|
|
|
|
cylinderPressureAxis->setVisible(false);
|
|
|
|
temperatureItem->setVisible(false);
|
|
|
|
gasPressureItem->setVisible(false);
|
|
|
|
cartesianPlane->setVisible(false);
|
|
|
|
meanDepth->setVisible(false);
|
|
|
|
diveComputerText->setVisible(false);
|
|
|
|
diveCeiling->setVisible(false);
|
|
|
|
reportedCeiling->setVisible(false);
|
|
|
|
pn2GasItem->setVisible(false);
|
|
|
|
pheGasItem->setVisible(false);
|
|
|
|
po2GasItem->setVisible(false);
|
|
|
|
Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
|
|
|
|
tissue->setVisible(false);
|
|
|
|
}
|
|
|
|
Q_FOREACH(DiveEventItem *event, eventItems){
|
|
|
|
event->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::setProfileState()
|
|
|
|
{
|
2014-02-07 18:54:12 +00:00
|
|
|
// Then starting Empty State, move the background up.
|
|
|
|
if (currentState == PROFILE)
|
|
|
|
return;
|
2014-02-07 18:34:42 +00:00
|
|
|
|
2014-02-07 18:54:12 +00:00
|
|
|
currentState = PROFILE;
|
2014-02-07 19:38:00 +00:00
|
|
|
setBackgroundBrush(getColor(::BACKGROUND));
|
|
|
|
|
2014-02-07 18:54:12 +00:00
|
|
|
Animations::moveTo(background, background->x(), itemPos.background.off.y(), 1500);
|
|
|
|
toolTipItem->setVisible(true);
|
2014-02-07 19:38:00 +00:00
|
|
|
|
|
|
|
profileYAxis->setPos(itemPos.depth.pos.on);
|
|
|
|
profileYAxis->setLine(itemPos.depth.expanded);
|
|
|
|
|
|
|
|
qDebug() << "ProfileAxisPos" << profileYAxis->pos() << "Line" << profileYAxis->line() << scene()->items().indexOf(profileYAxis);
|
|
|
|
// gasYAxis->setVisible(true);
|
|
|
|
// temperatureAxis->setVisible(true);
|
|
|
|
timeAxis->setPos(itemPos.time.pos.on);
|
|
|
|
timeAxis->setLine(itemPos.time.expanded);
|
|
|
|
qDebug() << "timeAxisPos" << timeAxis->pos() << "Line" << timeAxis->line() << scene()->items().indexOf(timeAxis);
|
|
|
|
// diveProfileItem->setVisible(true);
|
|
|
|
// cylinderPressureAxis->setVisible(true);
|
|
|
|
// temperatureItem->setVisible(true);
|
|
|
|
// gasPressureItem->setVisible(true);
|
|
|
|
// cartesianPlane->setVisible(true);
|
|
|
|
// meanDepth->setVisible(true);
|
|
|
|
// diveComputerText->setVisible(true);
|
|
|
|
// diveCeiling->setVisible(true);
|
|
|
|
// reportedCeiling->setVisible(true);
|
|
|
|
// pn2GasItem->setVisible(true);
|
|
|
|
// pheGasItem->setVisible(true);
|
|
|
|
// po2GasItem->setVisible(true);
|
|
|
|
// Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
|
|
|
|
// tissue->setVisible(true);
|
|
|
|
// }
|
|
|
|
// Q_FOREACH(DiveEventItem *event, eventItems){
|
|
|
|
// event->setVisible(true);
|
|
|
|
// }
|
2014-02-07 18:34:42 +00:00
|
|
|
}
|