Merge branch 'nitpicks' of github.com:tcanabrava/subsurface

This commit is contained in:
Dirk Hohndel 2013-07-02 13:43:48 -07:00
commit be6e6638de
6 changed files with 269 additions and 123 deletions

View file

@ -52,6 +52,7 @@ HEADERS = \
qt-ui/divecomputermanagementdialog.h \
qt-ui/diveplanner.h \
qt-ui/about.h \
qt-ui/graphicsview-common.h \
SOURCES = \
@ -92,6 +93,7 @@ SOURCES = \
qt-ui/divecomputermanagementdialog.cpp \
qt-ui/diveplanner.cpp \
qt-ui/about.cpp \
qt-ui/graphicsview-common.cpp \
$(RESFILE)

View file

@ -1,4 +1,6 @@
#include "diveplanner.h"
#include "graphicsview-common.h"
#include "../dive.h"
#include <cmath>
#include <QMouseEvent>
@ -6,24 +8,43 @@
#include <QGraphicsWidget>
#include <QGraphicsProxyWidget>
#include <QPushButton>
#include <QGraphicsSceneMouseEvent>
#include "ui_diveplanner.h"
#include "mainwindow.h"
#define TIME_INITIAL_MAX 30
#define MAX_DEEPNESS 150
#define MIN_DEEPNESS 40
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0),
lastValidPos(0.0, 0.0)
{
fill_profile_color();
setBackgroundBrush(profile_color[BACKGROUND].at(0));
setMouseTracking(true);
setScene(new QGraphicsScene());
scene()->setSceneRect(0,0,200,200);
scene()->setSceneRect(0,0,1920,1080);
QRectF r = scene()->sceneRect();
verticalLine = new QGraphicsLineItem(
fromPercent(0, Qt::Horizontal),
fromPercent(0, Qt::Vertical),
fromPercent(0, Qt::Horizontal),
fromPercent(100, Qt::Vertical)
);
verticalLine = new QGraphicsLineItem(0,0,0, 200);
verticalLine->setPen(QPen(Qt::DotLine));
scene()->addItem(verticalLine);
horizontalLine = new QGraphicsLineItem(0,0,200,0);
horizontalLine = new QGraphicsLineItem(
fromPercent(0, Qt::Horizontal),
fromPercent(0, Qt::Vertical),
fromPercent(100, Qt::Horizontal),
fromPercent(0, Qt::Vertical)
);
horizontalLine->setPen(QPen(Qt::DotLine));
scene()->addItem(horizontalLine);
@ -31,8 +52,15 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
timeLine->setMinimum(0);
timeLine->setMaximum(TIME_INITIAL_MAX);
timeLine->setTickInterval(10);
timeLine->setLine(10, 190, 190, 190);
timeLine->setLine(
fromPercent(10, Qt::Horizontal),
fromPercent(90, Qt::Vertical),
fromPercent(90, Qt::Horizontal),
fromPercent(90, Qt::Vertical)
);
timeLine->setOrientation(Qt::Horizontal);
timeLine->setTickSize(fromPercent(1, Qt::Vertical));
timeLine->setColor(profile_color[TIME_GRID].at(0));
timeLine->updateTicks();
scene()->addItem(timeLine);
@ -40,32 +68,43 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
depthLine->setMinimum(0);
depthLine->setMaximum(40);
depthLine->setTickInterval(10);
depthLine->setLine(10, 1, 10, 190);
depthLine->setLine(
fromPercent(10, Qt::Horizontal),
fromPercent(10, Qt::Vertical),
fromPercent(10, Qt::Horizontal),
fromPercent(90, Qt::Vertical)
);
depthLine->setOrientation(Qt::Vertical);
depthLine->setTickSize(fromPercent(1, Qt::Horizontal));
depthLine->setColor(profile_color[DEPTH_GRID].at(0));
depthLine->updateTicks();
scene()->addItem(depthLine);
timeString = new QGraphicsSimpleTextItem();
timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
timeString->setBrush(profile_color[TIME_TEXT].at(0));
scene()->addItem(timeString);
depthString = new QGraphicsSimpleTextItem();
depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
depthString->setBrush(profile_color[SAMPLE_DEEP].at(0));
scene()->addItem(depthString);
diveBg = new QGraphicsPolygonItem();
diveBg->setBrush(QBrush(Qt::green));
diveBg->setPen(QPen(QBrush(),0));
scene()->addItem(diveBg);
plusDepth = new Button();
plusDepth->setPixmap(QPixmap(":plus"));
plusDepth->setPos(0, 1);
plusDepth->setPos(fromPercent(5, Qt::Horizontal), fromPercent(5, Qt::Vertical));
plusDepth->setToolTip("Increase maximum depth by 10m");
scene()->addItem(plusDepth);
connect(plusDepth, SIGNAL(clicked()), this, SLOT(increaseDepth()));
plusTime = new Button();
plusTime->setPixmap(QPixmap(":plus"));
plusTime->setPos(180, 190);
plusTime->setPos(fromPercent(90, Qt::Horizontal), fromPercent(95, Qt::Vertical));
plusTime->setToolTip("Increase minimum dive time by 10m");
scene()->addItem(plusTime);
connect(plusTime, SIGNAL(clicked()), this, SLOT(increaseTime()));
@ -81,9 +120,17 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
scene()->addItem(cancelBtn);
connect(cancelBtn, SIGNAL(clicked()), this, SLOT(cancelClicked()));
minMinutes = TIME_INITIAL_MAX;
setRenderHint(QPainter::Antialiasing);
}
qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation)
{
qreal total = orientation == Qt::Horizontal ? sceneRect().width() : sceneRect().height();
qreal result = (total * percent) / 100;
return result;
}
void DivePlannerGraphics::cancelClicked()
{
qDebug() << "clicked";
@ -97,12 +144,19 @@ void DivePlannerGraphics::okClicked()
void DivePlannerGraphics::increaseDepth()
{
qDebug() << "Increase Depth Clicked";
if (depthLine->maximum() + 10 > MAX_DEEPNESS)
return;
depthLine->setMaximum( depthLine->maximum() + 10);
depthLine->updateTicks();
createDecoStops();
}
void DivePlannerGraphics::increaseTime()
{
qDebug() << "Increase Time Clicked";
minMinutes += 10;
timeLine->setMaximum( minMinutes );
timeLine->updateTicks();
createDecoStops();
}
void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
@ -129,10 +183,6 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
createDecoStops();
}
void DivePlannerGraphics::clearGeneratedDeco()
{
}
void DivePlannerGraphics::createDecoStops()
{
qDeleteAll(lines);
@ -177,14 +227,14 @@ void DivePlannerGraphics::createDecoStops()
if (timeLine->maximum() < dp->time / 60.0 + 5 ||
dp->time / 60.0 + 15 < timeLine->maximum()) {
double newMax = fmax(dp->time / 60.0 + 5, TIME_INITIAL_MAX);
double newMax = fmax(dp->time / 60.0 + 5, minMinutes);
timeLine->setMaximum(newMax);
timeLine->updateTicks();
}
// Re-position the user generated dive handlers
Q_FOREACH(DiveHandler *h, handles){
h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm) / 1000);
h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm / 1000));
}
// (re-) create the profile with different colors for segments that were
@ -197,27 +247,29 @@ void DivePlannerGraphics::createDecoStops()
for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
double xpos = timeLine->posAtValue(dp->time / 60.0);
double ypos = depthLine->posAtValue(dp->depth / 1000.0);
QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos);
item->setPen(QPen(QBrush(dp->entered ? Qt::black : Qt::red),0));
if(!dp->entered){
QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos);
item->setPen(QPen(QBrush(Qt::red),0));
scene()->addItem(item);
lines << item;
}
lastx = xpos;
lasty = ypos;
scene()->addItem(item);
lines << item;
poly.append(QPointF(lastx, lasty));
}
diveBg->setPolygon(poly);
QRectF b = poly.boundingRect();
QLinearGradient linearGrad(
QLinearGradient pat(
b.x(),
b.y(),
b.x(),
b.height() + b.y()
);
linearGrad.setColorAt(0, Qt::green);
linearGrad.setColorAt(1, Qt::white);
diveBg->setBrush(linearGrad);
pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first());
pat.setColorAt(0, profile_color[DEPTH_TOP].first());
diveBg->setBrush(pat);
deleteTemporaryDivePlan(diveplan.dp);
}
@ -248,12 +300,23 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
if (isPointOutOfBoundaries(mappedPos))
return;
verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 200);
horizontalLine->setLine(0, mappedPos.y(), 200, mappedPos.y());
verticalLine->setPos(mappedPos.x(), fromPercent(0, Qt::Vertical));
horizontalLine->setPos(fromPercent(0, Qt::Horizontal), mappedPos.y());
depthString->setText(QString::number(rint(depthLine->valueAt(mappedPos))) + "m" );
depthString->setPos(0, mappedPos.y());
depthString->setPos(fromPercent(5, Qt::Horizontal), mappedPos.y());
timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min");
timeString->setPos(mappedPos.x()+1, 180);
timeString->setPos(mappedPos.x()+1, fromPercent(95, Qt::Vertical));
// calculate the correct color for the depthString.
// QGradient doesn't returns it's interpolation, meh.
double percent = depthLine->percentAt(mappedPos);
QColor& startColor = profile_color[SAMPLE_SHALLOW].first();
QColor& endColor = profile_color[SAMPLE_DEEP].first();
short redDelta = (endColor.red() - startColor.red()) * percent + startColor.red();
short greenDelta = (endColor.green() - startColor.green()) * percent + startColor.green();
short blueDelta = (endColor.blue() - startColor.blue()) * percent + startColor.blue();
depthString->setBrush( QColor(redDelta, greenDelta, blueDelta));
if (activeDraggedHandler)
moveActiveHandler(mappedPos);
@ -370,21 +433,41 @@ void Ruler::updateTicks()
qDeleteAll(ticks);
ticks.clear();
QLineF m = line();
QGraphicsLineItem *item = NULL;
if (orientation == Qt::Horizontal) {
double steps = (max - min) / interval;
double stepSize = (m.x2() - m.x1()) / steps;
qreal pos;
for (qreal pos = m.x1(); pos < m.x2(); pos += stepSize) {
ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + 1, this));
item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
item->setPen(pen());
ticks.push_back(item);
}
item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
item->setPen(pen());
ticks.push_back(item);
} else {
double steps = (max - min) / interval;
double stepSize = (m.y2() - m.y1()) / steps;
for (qreal pos = m.y1(); pos < m.y2(); pos += stepSize) {
ticks.push_back(new QGraphicsLineItem(m.x1(), pos, m.x1() - 1, pos, this));
qreal pos;
for (pos = m.y1(); pos < m.y2(); pos += stepSize) {
item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
item->setPen(pen());
ticks.push_back(item);
}
item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
item->setPen(pen());
ticks.push_back(item);
}
}
void Ruler::setTickSize(qreal size)
{
tickSize = size;
}
void Ruler::setTickInterval(double i)
{
interval = i;
@ -414,6 +497,16 @@ qreal Ruler::posAtValue(qreal value)
return retValue;
}
qreal Ruler::percentAt(const QPointF& p)
{
qreal value = valueAt(p);
QLineF m = line();
double size = max - min;
double percent = value / size;
return percent;
}
double Ruler::maximum() const
{
return max;
@ -424,6 +517,11 @@ double Ruler::minimum() const
return min;
}
void Ruler::setColor(const QColor& color)
{
setPen(QPen(color));
}
Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem()
{
icon = new QGraphicsPixmapItem(this);
@ -431,12 +529,12 @@ Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem()
icon->setPos(0,0);
text->setPos(0,0);
setFlag(ItemIgnoresTransformations);
setPen(QPen(QBrush(Qt::white), 0));
setPen(QPen(QBrush(), 0));
}
void Button::setPixmap(const QPixmap& pixmap)
{
icon->setPixmap(pixmap.scaled(20,20));
icon->setPixmap(pixmap.scaled(20,20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
if(pixmap.isNull()){
icon->hide();
}else{
@ -460,5 +558,6 @@ void Button::setText(const QString& t)
void Button::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
event->ignore();
emit clicked();
}

View file

@ -37,11 +37,14 @@ public:
void setMaximum(double maximum);
void setTickInterval(double interval);
void setOrientation(Qt::Orientation orientation);
void setTickSize(qreal size);
void updateTicks();
double minimum() const;
double maximum() const;
qreal valueAt(const QPointF& p);
qreal percentAt(const QPointF& p);
qreal posAtValue(qreal value);
void setColor(const QColor& color);
private:
Qt::Orientation orientation;
@ -51,6 +54,7 @@ private:
double interval;
double posBegin;
double posEnd;
double tickSize;
};
class DivePlannerGraphics : public QGraphicsView {
@ -65,10 +69,11 @@ protected:
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
void clearGeneratedDeco();
void createDecoStops();
bool isPointOutOfBoundaries(const QPointF& point);
void deleteTemporaryDivePlan(struct divedatapoint* dp);
qreal fromPercent(qreal percent, Qt::Orientation orientation);
private slots:
void increaseTime();
void increaseDepth();
@ -77,25 +82,43 @@ private slots:
private:
void moveActiveHandler(const QPointF& pos);
/* This are the lines of the plotted dive. */
QList<QGraphicsLineItem*> lines;
/* This is the user-entered handles. */
QList<DiveHandler *> handles;
/* those are the lines that follows the mouse. */
QGraphicsLineItem *verticalLine;
QGraphicsLineItem *horizontalLine;
/* This is the handler that's being dragged. */
DiveHandler *activeDraggedHandler;
// helper to save the positions where the drag-handler is valid.
QPointF lastValidPos;
/* this is the background of the dive, the blue-gradient. */
QGraphicsPolygonItem *diveBg;
/* This is the bottom ruler - the x axis, and it's associated text */
Ruler *timeLine;
QGraphicsSimpleTextItem *timeString;
/* this is the left ruler, the y axis, and it's associated text. */
Ruler *depthLine;
QGraphicsSimpleTextItem *depthString;
Button *plusTime;
Button *plusDepth;
Button *lessTime;
Button *lessDepth;
Button *okBtn;
Button *cancelBtn;
QPointF lastValidPos;
/* 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.
Button *okBtn; // accepts, and creates a new dive based on the plan.
Button *cancelBtn; // rejects, and clears the dive plan.
int minMinutes; // this holds the minimum duration of the dive.
};
#endif

View file

@ -0,0 +1,58 @@
#include "graphicsview-common.h"
QMap<color_indice_t, QVector<QColor> > profile_color;
void fill_profile_color()
{
#define COLOR(x, y, z) QVector<QColor>() << x << y << z;
profile_color[SAC_1] = COLOR(FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1);
profile_color[SAC_2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
profile_color[SAC_3] = COLOR(ATLANTIS1, BLACK1_LOW_TRANS, ATLANTIS1);
profile_color[SAC_4] = COLOR(ATLANTIS2, BLACK1_LOW_TRANS, ATLANTIS2);
profile_color[SAC_5] = COLOR(EARLSGREEN1, BLACK1_LOW_TRANS, EARLSGREEN1);
profile_color[SAC_6] = COLOR(HOKEYPOKEY1, BLACK1_LOW_TRANS, HOKEYPOKEY1);
profile_color[SAC_7] = COLOR(TUSCANY1, BLACK1_LOW_TRANS, TUSCANY1);
profile_color[SAC_8] = COLOR(CINNABAR1, BLACK1_LOW_TRANS, CINNABAR1);
profile_color[SAC_9] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
profile_color[VELO_STABLE] = COLOR(CAMARONE1, BLACK1_LOW_TRANS, CAMARONE1);
profile_color[VELO_SLOW] = COLOR(LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1);
profile_color[VELO_MODERATE] = COLOR(RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1);
profile_color[VELO_FAST] = COLOR(PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1);
profile_color[VELO_CRAZY] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PO2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
profile_color[PO2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PN2] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
profile_color[PN2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
profile_color[PHE_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_HIGH_TRANS, BLACK1_HIGH_TRANS);
profile_color[TEXT_BACKGROUND] = COLOR(CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS);
profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS);
profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1_LOW_TRANS, PERSIANRED1);
profile_color[SAMPLE_SHALLOW] = COLOR(QColor(Qt::red).lighter(), BLACK1_LOW_TRANS, PERSIANRED1);
profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS);
profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS);
profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS);
profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1_LOW_TRANS, 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[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);
profile_color[TEMP_PLOT] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS);
profile_color[SAC_DEFAULT] = COLOR(WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1);
profile_color[BOUNDING_BOX] = COLOR(WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS);
profile_color[PRESSURE_TEXT] = COLOR(KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1);
profile_color[BACKGROUND] = COLOR(SPRINGWOOD1, BLACK1_LOW_TRANS, SPRINGWOOD1);
profile_color[CEILING_SHALLOW] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS, REDORANGE1_HIGH_TRANS);
profile_color[CEILING_DEEP] = COLOR(RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS);
profile_color[CALC_CEILING_SHALLOW] = COLOR(FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS, FUNGREEN1_HIGH_TRANS);
profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS);
#undef COLOR
}

View file

@ -0,0 +1,41 @@
#ifndef GRAPHICSVIEW_COMMON_H
#define GRAPHICSVIEW_COMMON_H
#include "../color.h"
#include <QMap>
#include <QVector>
#include <QColor>
#define SAC_COLORS_START_IDX SAC_1
#define SAC_COLORS 9
#define VELOCITY_COLORS_START_IDX VELO_STABLE
#define VELOCITY_COLORS 5
typedef enum {
/* SAC colors. Order is important, the SAC_COLORS_START_IDX define above. */
SAC_1, SAC_2, SAC_3, SAC_4, SAC_5, SAC_6, SAC_7, SAC_8, SAC_9,
/* Velocity colors. Order is still important, ref VELOCITY_COLORS_START_IDX. */
VELO_STABLE, VELO_SLOW, VELO_MODERATE, VELO_FAST, VELO_CRAZY,
/* gas colors */
PO2, PO2_ALERT, PN2, PN2_ALERT, PHE, PHE_ALERT, PP_LINES,
/* 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,
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;
/* profile_color[color indice] = COLOR(screen color, b/w printer color, color printer}} printer & screen colours could be different */
extern QMap<color_indice_t, QVector<QColor> > profile_color;
void fill_profile_color();
#endif

View file

@ -1,6 +1,7 @@
#include "profilegraphics.h"
#include "mainwindow.h"
#include "divelistview.h"
#include "graphicsview-common.h"
#include <QGraphicsScene>
#include <QResizeEvent>
@ -26,89 +27,9 @@
#include <libdivecomputer/parser.h>
#include <libdivecomputer/version.h>
#define SAC_COLORS_START_IDX SAC_1
#define SAC_COLORS 9
#define VELOCITY_COLORS_START_IDX VELO_STABLE
#define VELOCITY_COLORS 5
static struct graphics_context last_gc;
static double plot_scale = SCALE_SCREEN;
typedef enum {
/* SAC colors. Order is important, the SAC_COLORS_START_IDX define above. */
SAC_1, SAC_2, SAC_3, SAC_4, SAC_5, SAC_6, SAC_7, SAC_8, SAC_9,
/* Velocity colors. Order is still important, ref VELOCITY_COLORS_START_IDX. */
VELO_STABLE, VELO_SLOW, VELO_MODERATE, VELO_FAST, VELO_CRAZY,
/* gas colors */
PO2, PO2_ALERT, PN2, PN2_ALERT, PHE, PHE_ALERT, PP_LINES,
/* 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,
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;
#define COLOR(x, y, z) QVector<QColor>() << x << y << z;
/* profile_color[color indice] = COLOR(screen color, b/w printer color, color printer}} printer & screen colours could be different */
QMap<color_indice_t, QVector<QColor> > profile_color;
void fill_profile_color()
{
profile_color[SAC_1] = COLOR(FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1);
profile_color[SAC_2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
profile_color[SAC_3] = COLOR(ATLANTIS1, BLACK1_LOW_TRANS, ATLANTIS1);
profile_color[SAC_4] = COLOR(ATLANTIS2, BLACK1_LOW_TRANS, ATLANTIS2);
profile_color[SAC_5] = COLOR(EARLSGREEN1, BLACK1_LOW_TRANS, EARLSGREEN1);
profile_color[SAC_6] = COLOR(HOKEYPOKEY1, BLACK1_LOW_TRANS, HOKEYPOKEY1);
profile_color[SAC_7] = COLOR(TUSCANY1, BLACK1_LOW_TRANS, TUSCANY1);
profile_color[SAC_8] = COLOR(CINNABAR1, BLACK1_LOW_TRANS, CINNABAR1);
profile_color[SAC_9] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
profile_color[VELO_STABLE] = COLOR(CAMARONE1, BLACK1_LOW_TRANS, CAMARONE1);
profile_color[VELO_SLOW] = COLOR(LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1);
profile_color[VELO_MODERATE] = COLOR(RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1);
profile_color[VELO_FAST] = COLOR(PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1);
profile_color[VELO_CRAZY] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PO2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1);
profile_color[PO2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PN2] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
profile_color[PN2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
profile_color[PHE_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_HIGH_TRANS, BLACK1_HIGH_TRANS);
profile_color[TEXT_BACKGROUND] = COLOR(CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS);
profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS);
profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
profile_color[SAMPLE_DEEP] = COLOR(PERSIANRED1, BLACK1_LOW_TRANS, PERSIANRED1);
profile_color[SAMPLE_SHALLOW] = COLOR(PERSIANRED1, BLACK1_LOW_TRANS, PERSIANRED1);
profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS);
profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS);
profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS);
profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1_LOW_TRANS, 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[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);
profile_color[TEMP_PLOT] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS);
profile_color[SAC_DEFAULT] = COLOR(WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1);
profile_color[BOUNDING_BOX] = COLOR(WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS);
profile_color[PRESSURE_TEXT] = COLOR(KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1);
profile_color[BACKGROUND] = COLOR(SPRINGWOOD1, BLACK1_LOW_TRANS, SPRINGWOOD1);
profile_color[CEILING_SHALLOW] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS, REDORANGE1_HIGH_TRANS);
profile_color[CEILING_DEEP] = COLOR(RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS);
profile_color[CALC_CEILING_SHALLOW] = COLOR(FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS, FUNGREEN1_HIGH_TRANS);
profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS);
}
#undef COLOR
struct text_render_options{
double size;
color_indice_t color;
@ -122,8 +43,10 @@ extern int evn_used;
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0), diveDC(0)
{
gc.printer = false;
fill_profile_color();
setScene(new QGraphicsScene());
setBackgroundBrush(QColor("#F3F3E6"));
setBackgroundBrush(profile_color[BACKGROUND].at(0));
scene()->installEventFilter(this);
setRenderHint(QPainter::Antialiasing);
@ -138,7 +61,7 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
fill_profile_color();
}
void ProfileGraphicsView::wheelEvent(QWheelEvent* event)