mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
New profile: create new class for DiveHeartrateItem
This allows us to give it a different color (red) and make it a smaller size. While implementing this I also fixed the size of the temperature text in the new profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
76393a2f53
commit
b5a02e50aa
7 changed files with 86 additions and 4 deletions
|
@ -98,6 +98,8 @@ void setup_pp_limits(struct graphics_context *gc);
|
|||
#define PP_TEXT_SIZE (12 * TEXT_SCALE)
|
||||
#define TEMP_TEXT_SIZE (12 * TEXT_SCALE)
|
||||
|
||||
#define TEMP_TEXT_SCALE 0.8
|
||||
#define HR_TEXT_CALE 0.7
|
||||
#define RIGHT (-1.0)
|
||||
#define CENTER (-0.5)
|
||||
#define LEFT (0.0)
|
||||
|
|
|
@ -41,6 +41,8 @@ void fill_profile_color()
|
|||
profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1, FORESTGREEN1);
|
||||
profile_color[DEPTH_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS);
|
||||
profile_color[MEAN_DEPTH] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[HR_PLOT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[HR_TEXT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS);
|
||||
profile_color[DEPTH_BOTTOM] = COLOR(GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS, GOVERNORBAY1_MED_TRANS);
|
||||
profile_color[DEPTH_TOP] = COLOR(MERCURY1_MED_TRANS, WHITE1_MED_TRANS, MERCURY1_MED_TRANS);
|
||||
profile_color[TEMP_TEXT] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2);
|
||||
|
|
|
@ -23,7 +23,7 @@ typedef enum {
|
|||
|
||||
/* Other colors */
|
||||
TEXT_BACKGROUND, ALERT_BG, ALERT_FG, EVENTS, SAMPLE_DEEP, SAMPLE_SHALLOW,
|
||||
SMOOTHED, MINUTE, TIME_GRID, TIME_TEXT, DEPTH_GRID, MEAN_DEPTH, DEPTH_TOP,
|
||||
SMOOTHED, MINUTE, TIME_GRID, TIME_TEXT, DEPTH_GRID, MEAN_DEPTH, HR_TEXT, HR_PLOT, DEPTH_TOP,
|
||||
DEPTH_BOTTOM, TEMP_TEXT, TEMP_PLOT, SAC_DEFAULT, BOUNDING_BOX, PRESSURE_TEXT, BACKGROUND,
|
||||
CEILING_SHALLOW, CEILING_DEEP, CALC_CEILING_SHALLOW, CALC_CEILING_DEEP
|
||||
} color_indice_t;
|
||||
|
|
|
@ -216,6 +216,73 @@ void DiveProfileItem::plot_depth_sample(struct plot_data *entry,QFlags<Qt::Align
|
|||
texts.append(item);
|
||||
}
|
||||
|
||||
DiveHeartrateItem::DiveHeartrateItem()
|
||||
{
|
||||
QPen pen;
|
||||
pen.setBrush(QBrush(getColor(::HR_PLOT)));
|
||||
pen.setCosmetic(true);
|
||||
pen.setWidth(1);
|
||||
setPen(pen);
|
||||
}
|
||||
|
||||
void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
int last = -300, last_printed_hr = 0, sec = 0, last_valid_hr = 0;
|
||||
// We don't have enougth data to calculate things, quit.
|
||||
if (!shouldCalculateStuff(topLeft, bottomRight))
|
||||
return;
|
||||
|
||||
qDeleteAll(texts);
|
||||
texts.clear();
|
||||
// Ignore empty values. things do not look good with '0' as temperature in kelvin...
|
||||
QPolygonF poly;
|
||||
for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) {
|
||||
int hr = dataModel->index(i, vDataColumn).data().toInt();
|
||||
if (!hr)
|
||||
continue;
|
||||
last_valid_hr = hr;
|
||||
sec = dataModel->index(i, hDataColumn).data().toInt();
|
||||
QPointF point( hAxis->posAtValue(sec), vAxis->posAtValue(hr));
|
||||
poly.append(point);
|
||||
|
||||
/* don't print a HR
|
||||
* if it's been less than 5min and less than a 20 beats change OR
|
||||
* if it's been less than 2min OR if the change from the
|
||||
* last print is less than 10 beats */
|
||||
if (((sec < last + 300) && (abs(hr - last_printed_hr) < 20)) ||
|
||||
(sec < last + 120) ||
|
||||
(abs(hr - last_printed_hr) < 10))
|
||||
continue;
|
||||
last = sec;
|
||||
if (hr > 0)
|
||||
createTextItem(sec, hr);
|
||||
last_printed_hr = hr;
|
||||
}
|
||||
setPolygon(poly);
|
||||
|
||||
if( texts.count())
|
||||
texts.last()->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
||||
}
|
||||
|
||||
void DiveHeartrateItem::createTextItem(int sec, int hr)
|
||||
{
|
||||
DiveTextItem *text = new DiveTextItem(this);
|
||||
text->setAlignment(Qt::AlignRight | Qt::AlignBottom);
|
||||
text->setBrush(getColor(HR_TEXT));
|
||||
text->setPos(QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(hr)));
|
||||
text->setScale(0.7); // need to call this BEFORE setText()
|
||||
text->setText(QString("%1").arg(hr));
|
||||
texts.append(text);
|
||||
}
|
||||
|
||||
void DiveHeartrateItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
{
|
||||
if(polygon().isEmpty())
|
||||
return;
|
||||
painter->setPen(pen());
|
||||
painter->drawPolyline(polygon());
|
||||
}
|
||||
|
||||
DiveTemperatureItem::DiveTemperatureItem()
|
||||
{
|
||||
QPen pen;
|
||||
|
@ -281,8 +348,8 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin)
|
|||
text->setAlignment(Qt::AlignRight | Qt::AlignBottom);
|
||||
text->setBrush(getColor(TEMP_TEXT));
|
||||
text->setPos(QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin)));
|
||||
text->setScale(0.8); // need to call this BEFORE setText()
|
||||
text->setText(QString("%1%2").arg(deg, 0, 'f', 1).arg(unit));
|
||||
// text->setSize(TEMP_TEXT_SIZE); //TODO: TEXT SIZE!
|
||||
texts.append(text);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,16 @@ private:
|
|||
void createTextItem(int seconds, int mkelvin);
|
||||
};
|
||||
|
||||
class DiveHeartrateItem : public AbstractProfilePolygonItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveHeartrateItem();
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
private:
|
||||
void createTextItem(int seconds, int hr);
|
||||
};
|
||||
|
||||
class DiveGasPressureItem : public AbstractProfilePolygonItem{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
|||
pheGasItem( new PartialPressureGasItem()),
|
||||
po2GasItem( new PartialPressureGasItem()),
|
||||
heartBeatAxis(new DiveCartesianAxis()),
|
||||
heartBeatItem(new DiveTemperatureItem()) // FIXME: making this a DiveTemperatureItem is a hack
|
||||
heartBeatItem(new DiveHeartrateItem())
|
||||
{
|
||||
memset(&plotInfo, 0, sizeof(plotInfo));
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ class DiveCartesianAxis;
|
|||
class DiveProfileItem;
|
||||
class TimeAxis;
|
||||
class DiveTemperatureItem;
|
||||
class DiveHeartrateItem;
|
||||
class DiveGasPressureItem;
|
||||
class DiveCalculatedCeiling;
|
||||
class DiveCalculatedTissue;
|
||||
|
@ -98,7 +99,7 @@ private:
|
|||
PartialPressureGasItem *pheGasItem;
|
||||
PartialPressureGasItem *po2GasItem;
|
||||
DiveCartesianAxis *heartBeatAxis;
|
||||
DiveTemperatureItem *heartBeatItem;
|
||||
DiveHeartrateItem *heartBeatItem;
|
||||
};
|
||||
|
||||
#endif // PROFILEWIDGET2_H
|
||||
|
|
Loading…
Add table
Reference in a new issue