diff options
Diffstat (limited to 'subsurface-core')
-rw-r--r-- | subsurface-core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | subsurface-core/color.cpp | 88 | ||||
-rw-r--r-- | subsurface-core/color.h | 85 | ||||
-rw-r--r-- | subsurface-core/metrics.cpp | 50 | ||||
-rw-r--r-- | subsurface-core/metrics.h | 32 |
5 files changed, 257 insertions, 0 deletions
diff --git a/subsurface-core/CMakeLists.txt b/subsurface-core/CMakeLists.txt index e7f531527..60efb7d92 100644 --- a/subsurface-core/CMakeLists.txt +++ b/subsurface-core/CMakeLists.txt @@ -70,6 +70,8 @@ set(SUBSURFACE_CORE_LIB_SRCS divelogexportlogic.cpp qt-init.cpp qtserialbluetooth.cpp + metrics.cpp + color.cpp ${SERIAL_FTDI} ${PLATFORM_SRC} ${BT_CORE_SRC_FILES} diff --git a/subsurface-core/color.cpp b/subsurface-core/color.cpp new file mode 100644 index 000000000..cf6f43916 --- /dev/null +++ b/subsurface-core/color.cpp @@ -0,0 +1,88 @@ +#include "color.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[O2SETPOINT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1); + profile_color[CCRSENSOR1] = COLOR(TUNDORA1_MED_TRANS, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS); + profile_color[CCRSENSOR2] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS); + profile_color[CCRSENSOR3] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT); + profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_LOW_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, WHITE1, BLACK1_LOW_TRANS); + profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1); + profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1, 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, 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[HR_AXIS] = COLOR(MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_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, WHITE1, SPRINGWOOD1); + profile_color[BACKGROUND_TRANS] = COLOR(SPRINGWOOD1_MED_TRANS, WHITE1_MED_TRANS, SPRINGWOOD1_MED_TRANS); + 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); + profile_color[TISSUE_PERCENTAGE] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2); + profile_color[GF_LINE] = COLOR(BLACK1, BLACK1_LOW_TRANS, BLACK1); + profile_color[AMB_PRESSURE_LINE] = COLOR(TUNDORA1_MED_TRANS, BLACK1_LOW_TRANS, ATLANTIS1); +#undef COLOR +} + +QColor getColor(const color_indice_t i, bool isGrayscale) +{ + if (profile_color.count() > i && i >= 0) + return profile_color[i].at((isGrayscale) ? 1 : 0); + return QColor(Qt::black); +} + +QColor getSacColor(int sac, int avg_sac) +{ + int sac_index = 0; + int delta = sac - avg_sac + 7000; + + sac_index = delta / 2000; + if (sac_index < 0) + sac_index = 0; + if (sac_index > SAC_COLORS - 1) + sac_index = SAC_COLORS - 1; + return getColor((color_indice_t)(SAC_COLORS_START_IDX + sac_index), false); +} diff --git a/subsurface-core/color.h b/subsurface-core/color.h index 7938e59a6..57ad77242 100644 --- a/subsurface-core/color.h +++ b/subsurface-core/color.h @@ -5,6 +5,8 @@ from http://chir.ag/projects/name-that-color */ #include <QColor> +#include <QMap> +#include <QVector> // Greens #define CAMARONE1 QColor::fromRgbF(0.0, 0.4, 0.0, 1) @@ -64,4 +66,87 @@ // Magentas #define MEDIUMREDVIOLET1_HIGHER_TRANS QColor::fromRgbF(0.7, 0.2, 0.7, 0.1) +#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, + O2SETPOINT, + CCRSENSOR1, + CCRSENSOR2, + CCRSENSOR3, + 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, + HR_TEXT, + HR_PLOT, + HR_AXIS, + DEPTH_TOP, + DEPTH_BOTTOM, + TEMP_TEXT, + TEMP_PLOT, + SAC_DEFAULT, + BOUNDING_BOX, + PRESSURE_TEXT, + BACKGROUND, + BACKGROUND_TRANS, + CEILING_SHALLOW, + CEILING_DEEP, + CALC_CEILING_SHALLOW, + CALC_CEILING_DEEP, + TISSUE_PERCENTAGE, + GF_LINE, + AMB_PRESSURE_LINE +} color_indice_t; + +extern QMap<color_indice_t, QVector<QColor> > profile_color; +void fill_profile_color(); +QColor getColor(const color_indice_t i, bool isGrayscale = false); +QColor getSacColor(int sac, int diveSac); +struct text_render_options { + double size; + color_indice_t color; + double hpos, vpos; +}; + +typedef text_render_options text_render_options_t; + #endif // COLOR_H diff --git a/subsurface-core/metrics.cpp b/subsurface-core/metrics.cpp new file mode 100644 index 000000000..203c2e5e2 --- /dev/null +++ b/subsurface-core/metrics.cpp @@ -0,0 +1,50 @@ +/* + * metrics.cpp + * + * methods to find/compute essential UI metrics + * (font properties, icon sizes, etc) + * + */ + +#include "metrics.h" + +static IconMetrics dfltIconMetrics = { -1 }; + +QFont defaultModelFont() +{ + QFont font; +// font.setPointSizeF(font.pointSizeF() * 0.8); + return font; +} + +QFontMetrics defaultModelFontMetrics() +{ + return QFontMetrics(defaultModelFont()); +} + +// return the default icon size, computed as the multiple of 16 closest to +// the given height +static int defaultIconSize(int height) +{ + int ret = (height + 8)/16; + ret *= 16; + if (ret < 16) + ret = 16; + return ret; +} + +const IconMetrics & defaultIconMetrics() +{ + if (dfltIconMetrics.sz_small == -1) { + int small = defaultIconSize(defaultModelFontMetrics().height()); + dfltIconMetrics.sz_small = small; + dfltIconMetrics.sz_med = small + small/2; + dfltIconMetrics.sz_big = 2*small; + + dfltIconMetrics.sz_pic = 8*small; + + dfltIconMetrics.spacing = small/8; + } + + return dfltIconMetrics; +} diff --git a/subsurface-core/metrics.h b/subsurface-core/metrics.h new file mode 100644 index 000000000..30295a3d8 --- /dev/null +++ b/subsurface-core/metrics.h @@ -0,0 +1,32 @@ +/* + * metrics.h + * + * header file for common function to find/compute essential UI metrics + * (font properties, icon sizes, etc) + * + */ +#ifndef METRICS_H +#define METRICS_H + +#include <QFont> +#include <QFontMetrics> +#include <QSize> + +QFont defaultModelFont(); +QFontMetrics defaultModelFontMetrics(); + +// Collection of icon/picture sizes and other metrics, resolution independent +struct IconMetrics { + // icon sizes + int sz_small; // ex 16px + int sz_med; // ex 24px + int sz_big; // ex 32px + // picture size + int sz_pic; // ex 128px + // icon spacing + int spacing; // ex 2px +}; + +const IconMetrics & defaultIconMetrics(); + +#endif // METRICS_H |