From 243016633d31f8225fc4d1475463cd0477cf9505 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 4 May 2013 16:12:43 -0300 Subject: Started the code for the Profile Plotting This small patch adds a new class - ProfileGraphicsView it's a QGraphicsView based class that will holds all graphics-items for the plotting. The setup is simple, just call ui->ListView->plot( dive ) ( that's already a ProfileGraphicsView and magic will happen. Since Im using a QGraphicsView , the size of the canvas doesn't matter and I'm fixing it at 0,0,100,100. when a resize is done, the resizeEvent will be called, fitting the scene's rectangle on the view. Signed-off-by: Tomaz Canabrava --- qt-ui/mainwindow.cpp | 2 ++ qt-ui/mainwindow.ui | 9 +++++++-- qt-ui/profilegraphics.cpp | 26 ++++++++++++++++++++++++++ qt-ui/profilegraphics.h | 17 +++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 qt-ui/profilegraphics.cpp create mode 100644 qt-ui/profilegraphics.h (limited to 'qt-ui') diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 3f545171e..e8134a5f6 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -94,6 +94,8 @@ void MainWindow::dive_selection_changed(const QItemSelection& newSelection, cons continue; select_dive(get_divenr(d)); } + + ui->ProfileWidget->plot( get_dive(selected_dive) ); } void MainWindow::on_actionSave_triggered() diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index fe97d98b4..7dfbae746 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -25,7 +25,7 @@ Qt::Horizontal - + @@ -88,7 +88,7 @@ 0 0 763 - 19 + 25 @@ -339,6 +339,11 @@ QTreeView
divelistview.h
+ + ProfileGraphicsView + QGraphicsView +
profilegraphics.h
+
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp new file mode 100644 index 000000000..59a47826f --- /dev/null +++ b/qt-ui/profilegraphics.cpp @@ -0,0 +1,26 @@ +#include "profilegraphics.h" + +#include +#include + +#include + +ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent) +{ + setScene(new QGraphicsScene()); + scene()->setSceneRect(0,0,100,100); +} + +void ProfileGraphicsView::plot(struct dive *d) +{ + qDebug() << "Start the plotting of the dive here."; +} + +void ProfileGraphicsView::resizeEvent(QResizeEvent *event) +{ + // Fits the scene's rectangle on the view. + // I can pass some parameters to this - + // like Qt::IgnoreAspectRatio or Qt::KeepAspectRatio + QRectF r = scene()->sceneRect(); + fitInView ( r.x() - 2, r.y() -2, r.width() + 4, r.height() + 4); // do a little bit of spacing; +} diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h new file mode 100644 index 000000000..e3380abcd --- /dev/null +++ b/qt-ui/profilegraphics.h @@ -0,0 +1,17 @@ +#ifndef PROFILEGRAPHICS_H +#define PROFILEGRAPHICS_H + +#include + +class ProfileGraphicsView : public QGraphicsView { +Q_OBJECT +public: + ProfileGraphicsView(QWidget* parent = 0); + void plot(struct dive *d); + +protected: + void resizeEvent(QResizeEvent *event); + +}; + +#endif -- cgit v1.2.3-70-g09d2 From a58412cb3114160c6dadb849582f2ea57ddb2125 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 4 May 2013 16:41:49 -0300 Subject: Converted the Colors.h code to Qt The colors on colors.h were done to fill a special struct by Subsurface - I removed that structure and replaced the code that generated the map of colors to a QMap. I know that this changes are not very 'welcomed', but C++ has issues on creating & initializing complex static members, this was the best way that I could think of. Signed-off-by: Tomaz Canabrava --- color.h | 80 ++++++++++++++++++++++--------------------- profile.c | 86 ++--------------------------------------------- qt-ui/profilegraphics.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 122 deletions(-) (limited to 'qt-ui') diff --git a/color.h b/color.h index 5d88fb5f7..f2013bcc9 100644 --- a/color.h +++ b/color.h @@ -4,54 +4,56 @@ /* The colors are named by picking the closest match from http://chir.ag/projects/name-that-color */ +#include + // Greens -#define CAMARONE1 { 0.0, 0.4, 0.0, 1 } -#define FUNGREEN1 { 0.0, 0.4, 0.2, 1 } -#define FUNGREEN1_HIGH_TRANS { 0.0, 0.4, 0.2, 0.25 } -#define KILLARNEY1 { 0.2, 0.4, 0.2, 1 } -#define APPLE1 { 0.2, 0.6, 0.2, 1 } -#define APPLE1_MED_TRANS { 0.2, 0.6, 0.2, 0.5 } -#define APPLE1_HIGH_TRANS { 0.2, 0.6, 0.2, 0.25 } -#define LIMENADE1 { 0.4, 0.8, 0.0, 1 } -#define ATLANTIS1 { 0.4, 0.8, 0.2, 1 } -#define ATLANTIS2 { 0.6, 0.8, 0.2, 1 } -#define RIOGRANDE1 { 0.8, 0.8, 0.0, 1 } -#define EARLSGREEN1 { 0.8, 0.8, 0.2, 1 } -#define FORESTGREEN1 { 0.1, 0.5, 0.1, 1 } +#define CAMARONE1 QColor::fromRgbF( 0.0, 0.4, 0.0, 1 ) +#define FUNGREEN1 QColor::fromRgbF( 0.0, 0.4, 0.2, 1 ) +#define FUNGREEN1_HIGH_TRANS QColor::fromRgbF( 0.0, 0.4, 0.2, 0.25 ) +#define KILLARNEY1 QColor::fromRgbF( 0.2, 0.4, 0.2, 1 ) +#define APPLE1 QColor::fromRgbF( 0.2, 0.6, 0.2, 1 ) +#define APPLE1_MED_TRANS QColor::fromRgbF( 0.2, 0.6, 0.2, 0.5 ) +#define APPLE1_HIGH_TRANS QColor::fromRgbF( 0.2, 0.6, 0.2, 0.25 ) +#define LIMENADE1 QColor::fromRgbF( 0.4, 0.8, 0.0, 1 ) +#define ATLANTIS1 QColor::fromRgbF( 0.4, 0.8, 0.2, 1 ) +#define ATLANTIS2 QColor::fromRgbF( 0.6, 0.8, 0.2, 1 ) +#define RIOGRANDE1 QColor::fromRgbF( 0.8, 0.8, 0.0, 1 ) +#define EARLSGREEN1 QColor::fromRgbF( 0.8, 0.8, 0.2, 1 ) +#define FORESTGREEN1 QColor::fromRgbF( 0.1, 0.5, 0.1, 1 ) // Reds -#define PERSIANRED1 { 0.8, 0.2, 0.2, 1 } -#define TUSCANY1 { 0.8, 0.4, 0.2, 1 } -#define PIRATEGOLD1 { 0.8, 0.5, 0.0, 1 } -#define HOKEYPOKEY1 { 0.8, 0.6, 0.2, 1 } -#define CINNABAR1 { 0.9, 0.3, 0.2, 1 } -#define REDORANGE1 { 1.0, 0.2, 0.2, 1 } -#define REDORANGE1_HIGH_TRANS { 1.0, 0.2, 0.2, 0.25 } -#define REDORANGE1_MED_TRANS { 1.0, 0.2, 0.2, 0.5 } -#define RED1_MED_TRANS { 1.0, 0.0, 0.0, 0.5 } -#define RED1 { 1.0, 0.0, 0.0, 1 } +#define PERSIANRED1 QColor::fromRgbF( 0.8, 0.2, 0.2, 1 ) +#define TUSCANY1 QColor::fromRgbF( 0.8, 0.4, 0.2, 1 ) +#define PIRATEGOLD1 QColor::fromRgbF( 0.8, 0.5, 0.0, 1 ) +#define HOKEYPOKEY1 QColor::fromRgbF( 0.8, 0.6, 0.2, 1 ) +#define CINNABAR1 QColor::fromRgbF( 0.9, 0.3, 0.2, 1 ) +#define REDORANGE1 QColor::fromRgbF( 1.0, 0.2, 0.2, 1 ) +#define REDORANGE1_HIGH_TRANS QColor::fromRgbF( 1.0, 0.2, 0.2, 0.25 ) +#define REDORANGE1_MED_TRANS QColor::fromRgbF( 1.0, 0.2, 0.2, 0.5 ) +#define RED1_MED_TRANS QColor::fromRgbF( 1.0, 0.0, 0.0, 0.5 ) +#define RED1 QColor::fromRgbF( 1.0, 0.0, 0.0, 1 ) // Monochromes -#define BLACK1_LOW_TRANS { 0.0, 0.0, 0.0, 0.75 } -#define BLACK1_HIGH_TRANS { 0.0, 0.0, 0.0, 0.25 } -#define TUNDORA1_MED_TRANS { 0.3, 0.3, 0.3, 0.5 } -#define MERCURY1_MED_TRANS { 0.9, 0.9, 0.9, 0.5 } -#define CONCRETE1_LOWER_TRANS { 0.95, 0.95, 0.95, 0.9 } -#define WHITE1_MED_TRANS { 1.0, 1.0, 1.0, 0.5 } -#define WHITE1 { 1.0, 1.0, 1.0, 1 } +#define BLACK1_LOW_TRANS QColor::fromRgbF( 0.0, 0.0, 0.0, 0.75 ) +#define BLACK1_HIGH_TRANS QColor::fromRgbF( 0.0, 0.0, 0.0, 0.25 ) +#define TUNDORA1_MED_TRANS QColor::fromRgbF( 0.3, 0.3, 0.3, 0.5 ) +#define MERCURY1_MED_TRANS QColor::fromRgbF( 0.9, 0.9, 0.9, 0.5 ) +#define CONCRETE1_LOWER_TRANS QColor::fromRgbF( 0.95, 0.95, 0.95, 0.9 ) +#define WHITE1_MED_TRANS QColor::fromRgbF( 1.0, 1.0, 1.0, 0.5 ) +#define WHITE1 QColor::fromRgbF( 1.0, 1.0, 1.0, 1 ) // Blues -#define GOVERNORBAY2 { 0.2, 0.2, 0.7, 1 } -#define GOVERNORBAY1_MED_TRANS { 0.2, 0.2, 0.8, 0.5 } -#define ROYALBLUE2 { 0.2, 0.2, 0.9, 1 } -#define ROYALBLUE2_LOW_TRANS { 0.2, 0.2, 0.9, 0.75 } +#define GOVERNORBAY2 QColor::fromRgbF( 0.2, 0.2, 0.7, 1 ) +#define GOVERNORBAY1_MED_TRANS QColor::fromRgbF( 0.2, 0.2, 0.8, 0.5 ) +#define ROYALBLUE2 QColor::fromRgbF( 0.2, 0.2, 0.9, 1 ) +#define ROYALBLUE2_LOW_TRANS QColor::fromRgbF( 0.2, 0.2, 0.9, 0.75 ) // Yellows / BROWNS -#define SPRINGWOOD1 { 0.95, 0.95, 0.9, 1 } -#define BROOM1_LOWER_TRANS { 1.0, 1.0, 0.1, 0.9 } -#define PEANUT { 0.5, 0.2, 0.1, 1.0 } -#define PEANUT_MED_TRANS { 0.5, 0.2, 0.1, 0.5 } +#define SPRINGWOOD1 QColor::fromRgbF( 0.95, 0.95, 0.9, 1 ) +#define BROOM1_LOWER_TRANS QColor::fromRgbF( 1.0, 1.0, 0.1, 0.9 ) +#define PEANUT QColor::fromRgbF( 0.5, 0.2, 0.1, 1.0 ) +#define PEANUT_MED_TRANS QColor::fromRgbF( 0.5, 0.2, 0.1, 0.5 ) // Magentas -#define MEDIUMREDVIOLET1_HIGHER_TRANS { 0.7, 0.2, 0.7, 0.1 } +#define MEDIUMREDVIOLET1_HIGHER_TRANS QColor::fromRgbF( 0.7, 0.2, 0.7, 0.1 ) #endif diff --git a/profile.c b/profile.c index b9a633cf6..fa0a24a06 100644 --- a/profile.c +++ b/profile.c @@ -10,7 +10,7 @@ #include "display-gtk.h" #endif #include "divelist.h" -#include "color.h" + #include "libdivecomputer/parser.h" #include "libdivecomputer/version.h" @@ -59,88 +59,6 @@ struct plot_data { #define INTERPOLATED_PRESSURE(_entry) (_entry)->pressure[INTERPOLATED_PR] #define GET_PRESSURE(_entry) (SENSOR_PRESSURE(_entry) ? : INTERPOLATED_PRESSURE(_entry)) -#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; - -typedef struct { - /* media[0] is screen, media[1] is b/w printer media[2] is color printer */ - struct rgba { - double r,g,b,a; - } media[3]; -} color_t; - -/* [color indice] = {{screen color, b/w printer color, color printer}} printer & screen colours could be different */ -static const color_t profile_color[] = { - [SAC_1] = {{FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1}}, - [SAC_2] = {{APPLE1, BLACK1_LOW_TRANS, APPLE1}}, - [SAC_3] = {{ATLANTIS1, BLACK1_LOW_TRANS, ATLANTIS1}}, - [SAC_4] = {{ATLANTIS2, BLACK1_LOW_TRANS, ATLANTIS2}}, - [SAC_5] = {{EARLSGREEN1, BLACK1_LOW_TRANS, EARLSGREEN1}}, - [SAC_6] = {{HOKEYPOKEY1, BLACK1_LOW_TRANS, HOKEYPOKEY1}}, - [SAC_7] = {{TUSCANY1, BLACK1_LOW_TRANS, TUSCANY1}}, - [SAC_8] = {{CINNABAR1, BLACK1_LOW_TRANS, CINNABAR1}}, - [SAC_9] = {{REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1}}, - - [VELO_STABLE] = {{CAMARONE1, BLACK1_LOW_TRANS, CAMARONE1}}, - [VELO_SLOW] = {{LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1}}, - [VELO_MODERATE] = {{RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1}}, - [VELO_FAST] = {{PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1}}, - [VELO_CRAZY] = {{RED1, BLACK1_LOW_TRANS, RED1}}, - - [PO2] = {{APPLE1, BLACK1_LOW_TRANS, APPLE1}}, - [PO2_ALERT] = {{RED1, BLACK1_LOW_TRANS, RED1}}, - [PN2] = {{BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS}}, - [PN2_ALERT] = {{RED1, BLACK1_LOW_TRANS, RED1}}, - [PHE] = {{PEANUT, BLACK1_LOW_TRANS, PEANUT}}, - [PHE_ALERT] = {{RED1, BLACK1_LOW_TRANS, RED1}}, - [PP_LINES] = {{BLACK1_HIGH_TRANS, BLACK1_HIGH_TRANS, BLACK1_HIGH_TRANS}}, - - [TEXT_BACKGROUND] = {{CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS}}, - [ALERT_BG] = {{BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS}}, - [ALERT_FG] = {{BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS}}, - [EVENTS] = {{REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1}}, - [SAMPLE_DEEP] = {{PERSIANRED1, BLACK1_LOW_TRANS, PERSIANRED1}}, - [SAMPLE_SHALLOW] = {{PERSIANRED1, BLACK1_LOW_TRANS, PERSIANRED1}}, - [SMOOTHED] = {{REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS}}, - [MINUTE] = {{MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS}}, - [TIME_GRID] = {{WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS}}, - [TIME_TEXT] = {{FORESTGREEN1, BLACK1_LOW_TRANS, FORESTGREEN1}}, - [DEPTH_GRID] = {{WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS}}, - [MEAN_DEPTH] = {{REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS}}, - [DEPTH_BOTTOM] = {{GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS, GOVERNORBAY1_MED_TRANS}}, - [DEPTH_TOP] = {{MERCURY1_MED_TRANS, WHITE1_MED_TRANS, MERCURY1_MED_TRANS}}, - [TEMP_TEXT] = {{GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2}}, - [TEMP_PLOT] = {{ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS}}, - [SAC_DEFAULT] = {{WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1}}, - [BOUNDING_BOX] = {{WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS}}, - [PRESSURE_TEXT] = {{KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1}}, - [BACKGROUND] = {{SPRINGWOOD1, BLACK1_LOW_TRANS, SPRINGWOOD1}}, - [CEILING_SHALLOW] = {{REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS, REDORANGE1_HIGH_TRANS}}, - [CEILING_DEEP] = {{RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS}}, - [CALC_CEILING_SHALLOW] = {{FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS, FUNGREEN1_HIGH_TRANS}}, - [CALC_CEILING_DEEP] = {{APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS}}, - -}; - #if USE_GTK_UI /* Scale to 0,0 -> maxx,maxy */ @@ -270,11 +188,13 @@ int get_maxdepth(struct plot_info *pi) return md; } +#if 0 typedef struct { double size; color_indice_t color; double hpos, vpos; } text_render_options_t; +#endif #define RIGHT (-1.0) #define CENTER (-0.5) diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 59a47826f..fab17beb7 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -5,10 +5,91 @@ #include +#include "../color.h" + +#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 */ +QMap > profile_color; +void fill_profile_color() +{ +#define COLOR(x, y, z) QVector() << 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(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 +} + ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent) { setScene(new QGraphicsScene()); scene()->setSceneRect(0,0,100,100); + fill_profile_color(); } void ProfileGraphicsView::plot(struct dive *d) -- cgit v1.2.3-70-g09d2 From c74dc111675980ddd1a1b256b38a41304c792d89 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 4 May 2013 17:24:23 -0300 Subject: Moved the plot from the cairo version to the Qt version Started working on the Qt version of the Plot, initially nothing is printed - but this is not a bad thing, the program doesn't explodes too. :) some work had to be done about the 'bool/gboolean' stuff so I removed all gbooleans in the code that I'v encountered. A new file was created ( profile.h ) so I could put the signatures of helper methods that cairo used to call. till now the code computes the max limits. Next patch the first drawing will be made. Signed-off-by: Tomaz Canabrava --- display.h | 27 ++++++--- profile.c | 123 ---------------------------------------- profile.h | 25 +++++++++ qt-ui/profilegraphics.cpp | 140 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 182 insertions(+), 133 deletions(-) create mode 100644 profile.h (limited to 'qt-ui') diff --git a/display.h b/display.h index b1a034e88..bc60c059f 100644 --- a/display.h +++ b/display.h @@ -1,18 +1,26 @@ #ifndef DISPLAY_H #define DISPLAY_H -#include - #ifdef __cplusplus extern "C" { +#else +#if __STDC_VERSION__ >= 199901L +#include +#else +typedef int bool; +#endif #endif #define SCALE_SCREEN 1.0 -#define SCALE_PRINT (1.0 / get_screen_dpi()) +#warning "PORT THE get_screen_dpi to Qt" +#define SCALE_PRINT 1.0 +//#define SCALE_PRINT (1.0 / get_screen_dpi()) extern void repaint_dive(void); extern void do_print(void); -extern gdouble get_screen_dpi(void); + +// Commented out because I don't know how to get the dpi on a paint device yet. +// extern gdouble get_screen_dpi(void); /* Plot info with smoothing, velocity indication * and one-, two- and three-minute minimums and maximums */ @@ -24,10 +32,15 @@ struct plot_info { int mintemp, maxtemp; double endtempcoord; double maxpp; - gboolean has_ndl; + bool has_ndl; struct plot_data *entry; }; +/* +// I'm not sure if this is needed anymore - but keeping this here +// so I wont break stuff trying to redo the well. +*/ + /* * Cairo scaling really is horribly horribly mis-designed. * @@ -38,8 +51,6 @@ struct plot_info { */ struct graphics_context { int printer; - cairo_t *cr; - cairo_rectangle_t drawing_area; double maxx, maxy; double leftx, rightx; double topy, bottomy; @@ -61,7 +72,7 @@ struct options { enum { PRETTY, TABLE, TWOPERPAGE } type; int print_selected; int color_selected; - gboolean notes_up; + bool notes_up; int profile_height, notes_height, tanks_height; }; diff --git a/profile.c b/profile.c index fa0a24a06..3f413f4ed 100644 --- a/profile.c +++ b/profile.c @@ -18,9 +18,6 @@ int selected_dive = 0; char zoomed_plot = 0; char dc_number = 0; -#if USE_GTK_UI -static double plot_scale = SCALE_SCREEN; -#endif static struct plot_data *last_pi_entry = NULL; @@ -1951,126 +1948,6 @@ struct divecomputer *select_dc(struct divecomputer *main) return main; } -#if USE_GTK_UI -void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) -{ - struct plot_info *pi; - struct divecomputer *dc = &dive->dc; - cairo_rectangle_t *drawing_area = &gc->drawing_area; - const char *nickname; - - plot_set_scale(scale); - - if (!dc->samples) { - static struct sample fake[4]; - static struct divecomputer fakedc; - fakedc = dive->dc; - fakedc.sample = fake; - fakedc.samples = 4; - - /* The dive has no samples, so create a few fake ones. This assumes an - ascent/descent rate of 9 m/min, which is just below the limit for FAST. */ - int duration = dive->dc.duration.seconds; - int maxdepth = dive->dc.maxdepth.mm; - int asc_desc_time = dive->dc.maxdepth.mm*60/9000; - if (asc_desc_time * 2 >= duration) - asc_desc_time = duration / 2; - fake[1].time.seconds = asc_desc_time; - fake[1].depth.mm = maxdepth; - fake[2].time.seconds = duration - asc_desc_time; - fake[2].depth.mm = maxdepth; - fake[3].time.seconds = duration * 1.00; - fakedc.events = dc->events; - dc = &fakedc; - } - - /* - * Set up limits that are independent of - * the dive computer - */ - calculate_max_limits(dive, dc, gc); - - /* shift the drawing area so we have a nice margin around it */ - cairo_translate(gc->cr, drawing_area->x, drawing_area->y); - cairo_set_line_width_scaled(gc->cr, 1); - cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND); - cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND); - - /* - * We don't use "cairo_translate()" because that doesn't - * scale line width etc. But the actual scaling we need - * do set up ourselves.. - * - * Snif. What a pity. - */ - gc->maxx = (drawing_area->width - 2*drawing_area->x); - gc->maxy = (drawing_area->height - 2*drawing_area->y); - - dc = select_dc(dc); - - /* This is per-dive-computer. Right now we just do the first one */ - pi = create_plot_info(dive, dc, gc); - - /* Depth profile */ - plot_depth_profile(gc, pi); - plot_events(gc, pi, dc); - - /* Temperature profile */ - plot_temperature_profile(gc, pi); - - /* Cylinder pressure plot */ - plot_cylinder_pressure(gc, pi, dive, dc); - - /* Text on top of all graphs.. */ - plot_temperature_text(gc, pi); - plot_depth_text(gc, pi); - plot_cylinder_pressure_text(gc, pi); - plot_deco_text(gc, pi); - - /* Bounding box last */ - gc->leftx = 0; gc->rightx = 1.0; - gc->topy = 0; gc->bottomy = 1.0; - - set_source_rgba(gc, BOUNDING_BOX); - cairo_set_line_width_scaled(gc->cr, 1); - move_to(gc, 0, 0); - line_to(gc, 0, 1); - line_to(gc, 1, 1); - line_to(gc, 1, 0); - cairo_close_path(gc->cr); - cairo_stroke(gc->cr); - - /* Put the dive computer name in the lower left corner */ - nickname = get_dc_nickname(dc->model, dc->deviceid); - if (!nickname || *nickname == '\0') - nickname = dc->model; - if (nickname) { - static const text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, MIDDLE}; - plot_text(gc, &computer, 0, 1, "%s", nickname); - } - - if (PP_GRAPHS_ENABLED) { - plot_pp_gas_profile(gc, pi); - plot_pp_text(gc, pi); - } - - /* now shift the translation back by half the margin; - * this way we can draw the vertical scales on both sides */ - cairo_translate(gc->cr, -drawing_area->x / 2.0, 0); - gc->maxx += drawing_area->x; - gc->leftx = -(drawing_area->x / drawing_area->width) / 2.0; - gc->rightx = 1.0 - gc->leftx; - - plot_depth_scale(gc, pi); - - if (gc->printer) { - free(pi->entry); - last_pi_entry = pi->entry = NULL; - pi->nr = 0; - } -} -#endif /* USE_GTK_UI */ - static void plot_string(struct plot_data *entry, char *buf, size_t bufsize, int depth, int pressure, int temp, gboolean has_ndl) { diff --git a/profile.h b/profile.h new file mode 100644 index 000000000..66d1ee190 --- /dev/null +++ b/profile.h @@ -0,0 +1,25 @@ +#ifndef PROFILE_H +#define PROFILE_H + +#ifdef __cplusplus +extern "C" { +#else +#if __STDC_VERSION__ >= 199901L +#include +#else +typedef int bool; +#endif +#endif + +struct dive; +struct divecomputer; +struct graphics_context; +struct plot_info; + +void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc); +struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index fab17beb7..004c78a47 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -6,12 +6,17 @@ #include #include "../color.h" +#include "../display.h" +#include "../dive.h" +#include "../profile.h" #define SAC_COLORS_START_IDX SAC_1 #define SAC_COLORS 9 #define VELOCITY_COLORS_START_IDX VELO_STABLE #define VELOCITY_COLORS 5 +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, @@ -92,9 +97,140 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent fill_profile_color(); } -void ProfileGraphicsView::plot(struct dive *d) +static void plot_set_scale(scale_mode_t scale) +{ + switch (scale) { + default: + case SC_SCREEN: + plot_scale = SCALE_SCREEN; + break; + case SC_PRINT: + plot_scale = SCALE_PRINT; + break; + } +} + +void ProfileGraphicsView::plot(struct dive *dive) { - qDebug() << "Start the plotting of the dive here."; + struct plot_info *pi; + struct divecomputer *dc = &dive->dc; + + // This was passed around in the Cairo version / needed? + graphics_context gc; + const char *nickname; + + // Fix this for printing / screen later. + // plot_set_scale( scale_mode_t); + + if (!dc->samples) { + static struct sample fake[4]; + static struct divecomputer fakedc; + fakedc = dive->dc; + fakedc.sample = fake; + fakedc.samples = 4; + + /* The dive has no samples, so create a few fake ones. This assumes an + ascent/descent rate of 9 m/min, which is just below the limit for FAST. */ + int duration = dive->dc.duration.seconds; + int maxdepth = dive->dc.maxdepth.mm; + int asc_desc_time = dive->dc.maxdepth.mm*60/9000; + if (asc_desc_time * 2 >= duration) + asc_desc_time = duration / 2; + fake[1].time.seconds = asc_desc_time; + fake[1].depth.mm = maxdepth; + fake[2].time.seconds = duration - asc_desc_time; + fake[2].depth.mm = maxdepth; + fake[3].time.seconds = duration * 1.00; + fakedc.events = dc->events; + dc = &fakedc; + } + + /* + * Set up limits that are independent of + * the dive computer + */ + calculate_max_limits(dive, dc, &gc); + +#if 0 + /* shift the drawing area so we have a nice margin around it */ + cairo_translate(gc->cr, drawing_area->x, drawing_area->y); + cairo_set_line_width_scaled(gc->cr, 1); + cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND); + + /* + * We don't use "cairo_translate()" because that doesn't + * scale line width etc. But the actual scaling we need + * do set up ourselves.. + * + * Snif. What a pity. + */ + gc->maxx = (drawing_area->width - 2*drawing_area->x); + gc->maxy = (drawing_area->height - 2*drawing_area->y); + + dc = select_dc(dc); + + /* This is per-dive-computer. Right now we just do the first one */ + pi = create_plot_info(dive, dc, gc); + + /* Depth profile */ + plot_depth_profile(gc, pi); + plot_events(gc, pi, dc); + + /* Temperature profile */ + plot_temperature_profile(gc, pi); + + /* Cylinder pressure plot */ + plot_cylinder_pressure(gc, pi, dive, dc); + + /* Text on top of all graphs.. */ + plot_temperature_text(gc, pi); + plot_depth_text(gc, pi); + plot_cylinder_pressure_text(gc, pi); + plot_deco_text(gc, pi); + + /* Bounding box last */ + gc->leftx = 0; gc->rightx = 1.0; + gc->topy = 0; gc->bottomy = 1.0; + + set_source_rgba(gc, BOUNDING_BOX); + cairo_set_line_width_scaled(gc->cr, 1); + move_to(gc, 0, 0); + line_to(gc, 0, 1); + line_to(gc, 1, 1); + line_to(gc, 1, 0); + cairo_close_path(gc->cr); + cairo_stroke(gc->cr); + + /* Put the dive computer name in the lower left corner */ + nickname = get_dc_nickname(dc->model, dc->deviceid); + if (!nickname || *nickname == '\0') + nickname = dc->model; + if (nickname) { + static const text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, MIDDLE}; + plot_text(gc, &computer, 0, 1, "%s", nickname); + } + + if (PP_GRAPHS_ENABLED) { + plot_pp_gas_profile(gc, pi); + plot_pp_text(gc, pi); + } + + /* now shift the translation back by half the margin; + * this way we can draw the vertical scales on both sides */ + cairo_translate(gc->cr, -drawing_area->x / 2.0, 0); + gc->maxx += drawing_area->x; + gc->leftx = -(drawing_area->x / drawing_area->width) / 2.0; + gc->rightx = 1.0 - gc->leftx; + + plot_depth_scale(gc, pi); + + if (gc->printer) { + free(pi->entry); + last_pi_entry = pi->entry = NULL; + pi->nr = 0; + } +#endif } void ProfileGraphicsView::resizeEvent(QResizeEvent *event) -- cgit v1.2.3-70-g09d2 From 1b1ea35fac63ef7a6909f28e92bc2b4c24c2b7f4 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 4 May 2013 19:20:49 -0300 Subject: Start plotting something. The first plotting method was removed from profile.c to profilegraphics.cpp and some conversion ( almost 1 to 1 ) was made so that the code could work. Since the code is big - this commit has just a part of it working - it plots the grid. but already works for testing the resizing of the window and Zooming ( unimplemented ) Signed-off-by: Tomaz Canabrava --- profile.c | 204 -------------------------------------- profile.h | 15 +++ qt-ui/profilegraphics.cpp | 242 +++++++++++++++++++++++++++++++++++++++++++--- qt-ui/profilegraphics.h | 2 + 4 files changed, 247 insertions(+), 216 deletions(-) (limited to 'qt-ui') diff --git a/profile.c b/profile.c index 3f413f4ed..be6efa1e6 100644 --- a/profile.c +++ b/profile.c @@ -58,11 +58,6 @@ struct plot_data { #if USE_GTK_UI -/* Scale to 0,0 -> maxx,maxy */ -#define SCALEX(gc,x) (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx) -#define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy) -#define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y) - /* keep the last used gc around so we can invert the SCALEX calculation in * order to calculate a time value for an x coordinate */ static struct graphics_context last_gc; @@ -611,205 +606,6 @@ static void plot_pp_gas_profile(struct graphics_context *gc, struct plot_info *p } } -static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi) -{ - int i, incr; - cairo_t *cr = gc->cr; - int sec, depth; - struct plot_data *entry; - int maxtime, maxdepth, marker, maxline; - int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 }; - - /* Get plot scaling limits */ - maxtime = get_maxtime(pi); - maxdepth = get_maxdepth(pi); - - gc->maxtime = maxtime; - - /* 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 (maxtime / increments[i] > 12 && i < 7) - i++; - incr = increments[i]; - while (maxtime / incr > 12) - incr *= 2; - - gc->leftx = 0; gc->rightx = maxtime; - gc->topy = 0; gc->bottomy = 1.0; - - last_gc = *gc; - - set_source_rgba(gc, TIME_GRID); - cairo_set_line_width_scaled(gc->cr, 2); - - for (i = incr; i < maxtime; i += incr) { - move_to(gc, i, 0); - line_to(gc, i, 1); - } - cairo_stroke(cr); - - /* now the text on the time markers */ - text_render_options_t tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, TOP}; - if (maxtime < 600) { - /* Be a bit more verbose with shorter dives */ - for (i = incr; i < maxtime; i += incr) - plot_text(gc, &tro, i, 1, "%02d:%02d", i/60, i%60); - } else { - /* Only render the time on every second marker for normal dives */ - for (i = incr; i < maxtime; i += 2 * incr) - plot_text(gc, &tro, i, 1, "%d", i/60); - } - /* Depth markers: every 30 ft or 10 m*/ - gc->leftx = 0; gc->rightx = 1.0; - gc->topy = 0; gc->bottomy = maxdepth; - switch (prefs.units.length) { - case METERS: marker = 10000; break; - case FEET: marker = 9144; break; /* 30 ft */ - } - maxline = MAX(pi->maxdepth + marker, maxdepth * 2 / 3); - set_source_rgba(gc, DEPTH_GRID); - for (i = marker; i < maxline; i += marker) { - move_to(gc, 0, i); - line_to(gc, 1, i); - } - cairo_stroke(cr); - - gc->leftx = 0; gc->rightx = maxtime; - - /* Show mean depth */ - if (! gc->printer) { - set_source_rgba(gc, MEAN_DEPTH); - move_to(gc, 0, pi->meandepth); - line_to(gc, pi->entry[pi->nr - 1].sec, pi->meandepth); - cairo_stroke(cr); - } - - /* - * These are good for debugging text placement etc, - * but not for actual display.. - */ - if (0) { - plot_smoothed_profile(gc, pi); - plot_minmax_profile(gc, pi); - } - - /* Do the depth profile for the neat fill */ - gc->topy = 0; gc->bottomy = maxdepth; - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 1, DEPTH_BOTTOM); - pattern_add_color_stop_rgba (gc, pat, 0, DEPTH_TOP); - - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); - cairo_set_line_width_scaled(gc->cr, 2); - - entry = pi->entry; - move_to(gc, 0, 0); - for (i = 0; i < pi->nr; i++, entry++) - line_to(gc, entry->sec, entry->depth); - - /* Show any ceiling we may have encountered */ - for (i = pi->nr - 1; i >= 0; i--, entry--) { - if (entry->ndl) { - /* non-zero NDL implies this is a safety stop, no ceiling */ - line_to(gc, entry->sec, 0); - } else if (entry->stopdepth < entry->depth) { - line_to(gc, entry->sec, entry->stopdepth); - } else { - line_to(gc, entry->sec, entry->depth); - } - } - cairo_close_path(gc->cr); - cairo_fill(gc->cr); - - /* if the user wants the deco ceiling more visible, do that here (this - * basically draws over the background that we had allowed to shine - * through so far) */ - if (prefs.profile_red_ceiling) { - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); - pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); - entry = pi->entry; - move_to(gc, 0, 0); - for (i = 0; i < pi->nr; i++, entry++) { - if (entry->ndl == 0 && entry->stopdepth) { - if (entry->ndl == 0 && entry->stopdepth < entry->depth) { - line_to(gc, entry->sec, entry->stopdepth); - } else { - line_to(gc, entry->sec, entry->depth); - } - } else { - line_to(gc, entry->sec, 0); - } - } - cairo_close_path(gc->cr); - cairo_fill(gc->cr); - } - /* finally, plot the calculated ceiling over all this */ - if (prefs.profile_calc_ceiling) { - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 0, CALC_CEILING_SHALLOW); - pattern_add_color_stop_rgba (gc, pat, 1, CALC_CEILING_DEEP); - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); - entry = pi->entry; - move_to(gc, 0, 0); - for (i = 0; i < pi->nr; i++, entry++) { - if (entry->ceiling) - line_to(gc, entry->sec, entry->ceiling); - else - line_to(gc, entry->sec, 0); - } - line_to(gc, (entry-1)->sec, 0); /* make sure we end at 0 */ - cairo_close_path(gc->cr); - cairo_fill(gc->cr); - } - /* next show where we have been bad and crossed the dc's ceiling */ - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); - pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); - entry = pi->entry; - move_to(gc, 0, 0); - for (i = 0; i < pi->nr; i++, entry++) - line_to(gc, entry->sec, entry->depth); - - for (i = pi->nr - 1; i >= 0; i--, entry--) { - if (entry->ndl == 0 && entry->stopdepth > entry->depth) { - line_to(gc, entry->sec, entry->stopdepth); - } else { - line_to(gc, entry->sec, entry->depth); - } - } - cairo_close_path(gc->cr); - cairo_fill(gc->cr); - - /* Now do it again for the velocity colors */ - entry = pi->entry; - for (i = 1; i < pi->nr; i++) { - entry++; - sec = entry->sec; - /* we want to draw the segments in different colors - * representing the vertical velocity, so we need to - * chop this into short segments */ - depth = entry->depth; - set_source_rgba(gc, VELOCITY_COLORS_START_IDX + entry->velocity); - move_to(gc, entry[-1].sec, entry[-1].depth); - line_to(gc, sec, depth); - cairo_stroke(cr); - } -} static int setup_temperature_limits(struct graphics_context *gc, struct plot_info *pi) { diff --git a/profile.h b/profile.h index 66d1ee190..1ad6625db 100644 --- a/profile.h +++ b/profile.h @@ -19,6 +19,21 @@ struct plot_info; void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc); struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc); +/* + * When showing dive profiles, we scale things to the + * current dive. However, we don't scale past less than + * 30 minutes or 90 ft, just so that small dives show + * up as such unless zoom is enabled. + * We also need to add 180 seconds at the end so the min/max + * plots correctly + */ +int get_maxtime(struct plot_info *pi); + +/* get the maximum depth to which we want to plot + * take into account the additional verical space needed to plot + * partial pressure graphs */ +int get_maxdepth(struct plot_info *pi); + #ifdef __cplusplus } #endif diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 004c78a47..01ad5ab45 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -2,7 +2,9 @@ #include #include - +#include +#include +#include #include #include "../color.h" @@ -15,6 +17,12 @@ #define VELOCITY_COLORS_START_IDX VELO_STABLE #define VELOCITY_COLORS 5 +/* Scale to 0,0 -> maxx,maxy */ +#define SCALEX(gc,x) (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx) +#define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy) +#define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y) + +static struct graphics_context last_gc; static double plot_scale = SCALE_SCREEN; typedef enum { @@ -93,6 +101,7 @@ void fill_profile_color() ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent) { setScene(new QGraphicsScene()); + setBackgroundBrush(QColor("#F3F3E6")); scene()->setSceneRect(0,0,100,100); fill_profile_color(); } @@ -112,6 +121,13 @@ static void plot_set_scale(scale_mode_t scale) void ProfileGraphicsView::plot(struct dive *dive) { + // Clear the items before drawing this dive. + qDeleteAll(scene()->items()); + scene()->clear(); + + if(!dive) + return; + struct plot_info *pi; struct divecomputer *dc = &dive->dc; @@ -151,13 +167,6 @@ void ProfileGraphicsView::plot(struct dive *dive) */ calculate_max_limits(dive, dc, &gc); -#if 0 - /* shift the drawing area so we have a nice margin around it */ - cairo_translate(gc->cr, drawing_area->x, drawing_area->y); - cairo_set_line_width_scaled(gc->cr, 1); - cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND); - cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND); - /* * We don't use "cairo_translate()" because that doesn't * scale line width etc. But the actual scaling we need @@ -165,16 +174,18 @@ void ProfileGraphicsView::plot(struct dive *dive) * * Snif. What a pity. */ - gc->maxx = (drawing_area->width - 2*drawing_area->x); - gc->maxy = (drawing_area->height - 2*drawing_area->y); + QRectF drawing_area = scene()->sceneRect(); + gc.maxx = (drawing_area.width() - 2*drawing_area.x()); + gc.maxy = (drawing_area.height() - 2*drawing_area.y()); dc = select_dc(dc); /* This is per-dive-computer. Right now we just do the first one */ - pi = create_plot_info(dive, dc, gc); + pi = create_plot_info(dive, dc, &gc); /* Depth profile */ - plot_depth_profile(gc, pi); + plot_depth_profile(&gc, pi); +#if 0 plot_events(gc, pi, dc); /* Temperature profile */ @@ -233,6 +244,213 @@ void ProfileGraphicsView::plot(struct dive *dive) #endif } + +void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct plot_info *pi) +{ + int i, incr; + int sec, depth; + struct plot_data *entry; + int maxtime, maxdepth, marker, maxline; + int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 }; + + /* Get plot scaling limits */ + maxtime = get_maxtime(pi); + maxdepth = get_maxdepth(pi); + + gc->maxtime = maxtime; + + /* 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 (maxtime / increments[i] > 12 && i < 7) + i++; + incr = increments[i]; + while (maxtime / incr > 12) + incr *= 2; + + gc->leftx = 0; gc->rightx = maxtime; + gc->topy = 0; gc->bottomy = 1.0; + + last_gc = *gc; + + QColor color; + color = profile_color[TIME_GRID].at(0); + for (i = incr; i < maxtime; i += incr) { + QGraphicsLineItem *line = new QGraphicsLineItem(SCALE(gc, i, 0), SCALE(gc, i, 1)); + line->setPen(QPen(color)); + scene()->addItem(line); + } + +#if 0 + /* now the text on the time markers */ + text_render_options_t tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, TOP}; + if (maxtime < 600) { + /* Be a bit more verbose with shorter dives */ + for (i = incr; i < maxtime; i += incr) + plot_text(gc, &tro, i, 1, "%02d:%02d", i/60, i%60); + } else { + /* Only render the time on every second marker for normal dives */ + for (i = incr; i < maxtime; i += 2 * incr) + plot_text(gc, &tro, i, 1, "%d", i/60); + } +#endif + + /* Depth markers: every 30 ft or 10 m*/ + gc->leftx = 0; gc->rightx = 1.0; + gc->topy = 0; gc->bottomy = maxdepth; + switch (prefs.units.length) { + case units::METERS: marker = 10000; break; + case units::FEET: marker = 9144; break; /* 30 ft */ + } + maxline = MAX(pi->maxdepth + marker, maxdepth * 2 / 3); + + color = profile_color[TIME_GRID].at(0); + + for (i = marker; i < maxline; i += marker) { + QGraphicsLineItem *line = new QGraphicsLineItem(SCALE(gc, 0, i), SCALE(gc, 1, i)); + line->setPen(QPen(color)); + scene()->addItem(line); + } + +#if 0 + gc->leftx = 0; gc->rightx = maxtime; + + /* Show mean depth */ + if (! gc->printer) { + set_source_rgba(gc, MEAN_DEPTH); + move_to(gc, 0, pi->meandepth); + line_to(gc, pi->entry[pi->nr - 1].sec, pi->meandepth); + cairo_stroke(cr); + } + + /* + * These are good for debugging text placement etc, + * but not for actual display.. + */ + if (0) { + plot_smoothed_profile(gc, pi); + plot_minmax_profile(gc, pi); + } + + /* Do the depth profile for the neat fill */ + gc->topy = 0; gc->bottomy = maxdepth; + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); + pattern_add_color_stop_rgba (gc, pat, 1, DEPTH_BOTTOM); + pattern_add_color_stop_rgba (gc, pat, 0, DEPTH_TOP); + + cairo_set_source(gc->cr, pat); + cairo_pattern_destroy(pat); + cairo_set_line_width_scaled(gc->cr, 2); + + entry = pi->entry; + move_to(gc, 0, 0); + for (i = 0; i < pi->nr; i++, entry++) + line_to(gc, entry->sec, entry->depth); + + /* Show any ceiling we may have encountered */ + for (i = pi->nr - 1; i >= 0; i--, entry--) { + if (entry->ndl) { + /* non-zero NDL implies this is a safety stop, no ceiling */ + line_to(gc, entry->sec, 0); + } else if (entry->stopdepth < entry->depth) { + line_to(gc, entry->sec, entry->stopdepth); + } else { + line_to(gc, entry->sec, entry->depth); + } + } + cairo_close_path(gc->cr); + cairo_fill(gc->cr); + + /* if the user wants the deco ceiling more visible, do that here (this + * basically draws over the background that we had allowed to shine + * through so far) */ + if (prefs.profile_red_ceiling) { + pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); + pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); + pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); + cairo_set_source(gc->cr, pat); + cairo_pattern_destroy(pat); + entry = pi->entry; + move_to(gc, 0, 0); + for (i = 0; i < pi->nr; i++, entry++) { + if (entry->ndl == 0 && entry->stopdepth) { + if (entry->ndl == 0 && entry->stopdepth < entry->depth) { + line_to(gc, entry->sec, entry->stopdepth); + } else { + line_to(gc, entry->sec, entry->depth); + } + } else { + line_to(gc, entry->sec, 0); + } + } + cairo_close_path(gc->cr); + cairo_fill(gc->cr); + } + /* finally, plot the calculated ceiling over all this */ + if (prefs.profile_calc_ceiling) { + pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); + pattern_add_color_stop_rgba (gc, pat, 0, CALC_CEILING_SHALLOW); + pattern_add_color_stop_rgba (gc, pat, 1, CALC_CEILING_DEEP); + cairo_set_source(gc->cr, pat); + cairo_pattern_destroy(pat); + entry = pi->entry; + move_to(gc, 0, 0); + for (i = 0; i < pi->nr; i++, entry++) { + if (entry->ceiling) + line_to(gc, entry->sec, entry->ceiling); + else + line_to(gc, entry->sec, 0); + } + line_to(gc, (entry-1)->sec, 0); /* make sure we end at 0 */ + cairo_close_path(gc->cr); + cairo_fill(gc->cr); + } + /* next show where we have been bad and crossed the dc's ceiling */ + pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); + pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); + pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); + cairo_set_source(gc->cr, pat); + cairo_pattern_destroy(pat); + entry = pi->entry; + move_to(gc, 0, 0); + for (i = 0; i < pi->nr; i++, entry++) + line_to(gc, entry->sec, entry->depth); + + for (i = pi->nr - 1; i >= 0; i--, entry--) { + if (entry->ndl == 0 && entry->stopdepth > entry->depth) { + line_to(gc, entry->sec, entry->stopdepth); + } else { + line_to(gc, entry->sec, entry->depth); + } + } + cairo_close_path(gc->cr); + cairo_fill(gc->cr); + + /* Now do it again for the velocity colors */ + entry = pi->entry; + for (i = 1; i < pi->nr; i++) { + entry++; + sec = entry->sec; + /* we want to draw the segments in different colors + * representing the vertical velocity, so we need to + * chop this into short segments */ + depth = entry->depth; + set_source_rgba(gc, VELOCITY_COLORS_START_IDX + entry->velocity); + move_to(gc, entry[-1].sec, entry[-1].depth); + line_to(gc, sec, depth); + cairo_stroke(cr); + } +#endif +} + + void ProfileGraphicsView::resizeEvent(QResizeEvent *event) { // Fits the scene's rectangle on the view. diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h index e3380abcd..633409b23 100644 --- a/qt-ui/profilegraphics.h +++ b/qt-ui/profilegraphics.h @@ -12,6 +12,8 @@ public: protected: void resizeEvent(QResizeEvent *event); +private: + void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi); }; #endif -- cgit v1.2.3-70-g09d2 From 09597cd2d8729ab368f2e423dbb1ef5235745f58 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 4 May 2013 19:36:40 -0300 Subject: Plot of the Mean Deph The mean depth now is plotted correctly. I wanted to do more stuff on this commit, but since it required that a few things on profile.c got moved to profile.h, commited to not have a huge blob for review. Signed-off-by: Tomaz Canabrava --- profile.c | 27 ++------------------------- profile.h | 28 +++++++++++++++++++++++++++- qt-ui/profilegraphics.cpp | 13 +++++++------ 3 files changed, 36 insertions(+), 32 deletions(-) (limited to 'qt-ui') diff --git a/profile.c b/profile.c index be6efa1e6..161415e88 100644 --- a/profile.c +++ b/profile.c @@ -11,6 +11,7 @@ #endif #include "divelist.h" +#include "profile.h" #include "libdivecomputer/parser.h" #include "libdivecomputer/version.h" @@ -24,31 +25,7 @@ static struct plot_data *last_pi_entry = NULL; #define cairo_set_line_width_scaled(cr, w) \ cairo_set_line_width((cr), (w) * plot_scale); -typedef enum { STABLE, SLOW, MODERATE, FAST, CRAZY } velocity_t; - -struct plot_data { - unsigned int in_deco:1; - unsigned int cylinderindex; - int sec; - /* pressure[0] is sensor pressure - * pressure[1] is interpolated pressure */ - int pressure[2]; - int temperature; - /* Depth info */ - int depth; - int ceiling; - int ndl; - int stoptime; - int stopdepth; - int cns; - int smoothed; - double po2, pn2, phe; - double mod, ead, end, eadd; - velocity_t velocity; - struct plot_data *min[3]; - struct plot_data *max[3]; - int avg[3]; -}; + #define SENSOR_PR 0 #define INTERPOLATED_PR 1 diff --git a/profile.h b/profile.h index 1ad6625db..2c293fa7d 100644 --- a/profile.h +++ b/profile.h @@ -11,10 +11,36 @@ typedef int bool; #endif #endif -struct dive; +#include "dive.h" + +typedef enum { STABLE, SLOW, MODERATE, FAST, CRAZY } velocity_t; + struct divecomputer; struct graphics_context; struct plot_info; +struct plot_data { + unsigned int in_deco:1; + unsigned int cylinderindex; + int sec; + /* pressure[0] is sensor pressure + * pressure[1] is interpolated pressure */ + int pressure[2]; + int temperature; + /* Depth info */ + int depth; + int ceiling; + int ndl; + int stoptime; + int stopdepth; + int cns; + int smoothed; + double po2, pn2, phe; + double mod, ead, end, eadd; + velocity_t velocity; + struct plot_data *min[3]; + struct plot_data *max[3]; + int avg[3]; +}; void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc); struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc); diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 01ad5ab45..891cd81bf 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -309,7 +309,7 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct } maxline = MAX(pi->maxdepth + marker, maxdepth * 2 / 3); - color = profile_color[TIME_GRID].at(0); + color = profile_color[DEPTH_GRID].at(0); for (i = marker; i < maxline; i += marker) { QGraphicsLineItem *line = new QGraphicsLineItem(SCALE(gc, 0, i), SCALE(gc, 1, i)); @@ -317,17 +317,18 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct scene()->addItem(line); } -#if 0 + gc->leftx = 0; gc->rightx = maxtime; + color = profile_color[MEAN_DEPTH].at(0); /* Show mean depth */ if (! gc->printer) { - set_source_rgba(gc, MEAN_DEPTH); - move_to(gc, 0, pi->meandepth); - line_to(gc, pi->entry[pi->nr - 1].sec, pi->meandepth); - cairo_stroke(cr); + QGraphicsLineItem *line = new QGraphicsLineItem(SCALE(gc, 0, pi->meandepth), SCALE(gc, pi->entry[pi->nr - 1].sec, pi->meandepth)); + line->setPen(QPen(color)); + scene()->addItem(line); } +#if 0 /* * These are good for debugging text placement etc, * but not for actual display.. -- cgit v1.2.3-70-g09d2 From 926224122ebc4cf6a53e3a63eb455293bcfb455d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 4 May 2013 20:18:16 -0300 Subject: Added the code to plot the actual Graph. This version already plots the dive-graph, with the gradient and all that jazz. One thing that will be easily spotted is that the size of the line is very thick - easily changed, I'm just using the default. As soon as everything is plotted correctly I'll fix the lines. Signed-off-by: Tomaz Canabrava --- qt-ui/profilegraphics.cpp | 32 ++++++++++++++++---------------- qt-ui/profilegraphics.h | 3 +++ 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 891cd81bf..761ef262b 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -337,38 +337,38 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct plot_smoothed_profile(gc, pi); plot_minmax_profile(gc, pi); } +#endif /* Do the depth profile for the neat fill */ gc->topy = 0; gc->bottomy = maxdepth; - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 1, DEPTH_BOTTOM); - pattern_add_color_stop_rgba (gc, pat, 0, DEPTH_TOP); - - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); - cairo_set_line_width_scaled(gc->cr, 2); - entry = pi->entry; - move_to(gc, 0, 0); + + QGraphicsPolygonItem *neatFill = new QGraphicsPolygonItem(); + QPolygonF p; for (i = 0; i < pi->nr; i++, entry++) - line_to(gc, entry->sec, entry->depth); + p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); /* Show any ceiling we may have encountered */ for (i = pi->nr - 1; i >= 0; i--, entry--) { if (entry->ndl) { /* non-zero NDL implies this is a safety stop, no ceiling */ - line_to(gc, entry->sec, 0); + p.append( QPointF( SCALE(gc, entry->sec, 0) )); } else if (entry->stopdepth < entry->depth) { - line_to(gc, entry->sec, entry->stopdepth); + p.append( QPointF( SCALE(gc, entry->sec, entry->stopdepth) )); } else { - line_to(gc, entry->sec, entry->depth); + p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); } } - cairo_close_path(gc->cr); - cairo_fill(gc->cr); + neatFill->setPolygon(p); + QLinearGradient pat(0.0,0.0,0.0,p.boundingRect().height()); + pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first()); + pat.setColorAt(0, profile_color[DEPTH_TOP].first()); + + neatFill->setBrush(QBrush(pat)); + scene()->addItem(neatFill); +#if 0 /* if the user wants the deco ceiling more visible, do that here (this * basically draws over the background that we had allowed to shine * through so far) */ diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h index 633409b23..a62e55c4d 100644 --- a/qt-ui/profilegraphics.h +++ b/qt-ui/profilegraphics.h @@ -14,6 +14,9 @@ protected: private: void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi); + + QPen defaultPen; + QBrush defaultBrush; }; #endif -- cgit v1.2.3-70-g09d2 From c72609046adcaff2ca5af475113e583cbb943a04 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 5 May 2013 13:42:33 -0300 Subject: Finished the port of the plot_profile code. There are a few regressions, mostly because the text is not being plotted yet and the background of some of the curves are not being applied. This is because QGrapdien is based on the coordinates of the items that I wanna paint, but I'v setted a QGradient that's global and doesn't take this into consideration. all curves are being plotted. in Small resolutions they plot bad. but it's just a matter of redrawing in the correct resolution. the Line widths are being hardcoded now, on the cairo version they weren't, this will need a bit of porting too. Signed-off-by: Tomaz Canabrava --- qt-ui/profilegraphics.cpp | 110 ++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 48 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 761ef262b..c5421659c 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -102,7 +102,7 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent { setScene(new QGraphicsScene()); setBackgroundBrush(QColor("#F3F3E6")); - scene()->setSceneRect(0,0,100,100); + scene()->setSceneRect(0,0,1000,1000); fill_profile_color(); } @@ -344,8 +344,11 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct entry = pi->entry; - QGraphicsPolygonItem *neatFill = new QGraphicsPolygonItem(); + QPolygonF p; + QLinearGradient pat(0.0,0.0,0.0,scene()->height()); + QGraphicsPolygonItem *neatFill = 0; + for (i = 0; i < pi->nr; i++, entry++) p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); @@ -353,86 +356,98 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct for (i = pi->nr - 1; i >= 0; i--, entry--) { if (entry->ndl) { /* non-zero NDL implies this is a safety stop, no ceiling */ - p.append( QPointF( SCALE(gc, entry->sec, 0) )); + p.append( QPointF( SCALE(gc, entry->sec, 0) )); } else if (entry->stopdepth < entry->depth) { p.append( QPointF( SCALE(gc, entry->sec, entry->stopdepth) )); } else { p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); } } - neatFill->setPolygon(p); - QLinearGradient pat(0.0,0.0,0.0,p.boundingRect().height()); + +; pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first()); pat.setColorAt(0, profile_color[DEPTH_TOP].first()); + neatFill = new QGraphicsPolygonItem(); + neatFill->setPolygon(p); neatFill->setBrush(QBrush(pat)); + neatFill->setPen(QPen()); scene()->addItem(neatFill); -#if 0 /* if the user wants the deco ceiling more visible, do that here (this * basically draws over the background that we had allowed to shine * through so far) */ - if (prefs.profile_red_ceiling) { - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); - pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); + // TODO: port the prefs.profile_red_ceiling to QSettings + //if (prefs.profile_red_ceiling) { + p.clear(); + pat.setColorAt(0, profile_color[CEILING_SHALLOW].first()); + pat.setColorAt(1, profile_color[CEILING_DEEP].first()); + entry = pi->entry; - move_to(gc, 0, 0); for (i = 0; i < pi->nr; i++, entry++) { if (entry->ndl == 0 && entry->stopdepth) { if (entry->ndl == 0 && entry->stopdepth < entry->depth) { - line_to(gc, entry->sec, entry->stopdepth); + p.append( QPointF( SCALE(gc, entry->sec, entry->stopdepth) )); } else { - line_to(gc, entry->sec, entry->depth); + p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); } } else { - line_to(gc, entry->sec, 0); + p.append( QPointF( SCALE(gc, entry->sec, 0) )); } } - cairo_close_path(gc->cr); - cairo_fill(gc->cr); - } + + neatFill = new QGraphicsPolygonItem(); + neatFill->setBrush(QBrush(pat)); + neatFill->setPolygon(p); + neatFill->setPen(QPen()); + scene()->addItem(neatFill); + //} + /* finally, plot the calculated ceiling over all this */ - if (prefs.profile_calc_ceiling) { - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 0, CALC_CEILING_SHALLOW); - pattern_add_color_stop_rgba (gc, pat, 1, CALC_CEILING_DEEP); - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); + // TODO: Port the profile_calc_ceiling to QSettings + // if (prefs.profile_calc_ceiling) { + pat.setColorAt(0, profile_color[CALC_CEILING_SHALLOW].first()); + pat.setColorAt(1, profile_color[CALC_CEILING_DEEP].first()); + entry = pi->entry; - move_to(gc, 0, 0); + p.clear(); + p.append( QPointF(0,0)); for (i = 0; i < pi->nr; i++, entry++) { if (entry->ceiling) - line_to(gc, entry->sec, entry->ceiling); + p.append( QPointF( SCALE(gc, entry->sec, entry->ceiling) )); else - line_to(gc, entry->sec, 0); + p.append( QPointF( SCALE(gc, entry->sec, 0) )); } - line_to(gc, (entry-1)->sec, 0); /* make sure we end at 0 */ - cairo_close_path(gc->cr); - cairo_fill(gc->cr); - } + p.append( QPointF( SCALE(gc, (entry-1)->sec, 0) )); + neatFill = new QGraphicsPolygonItem(); + neatFill->setPolygon(p); + neatFill->setPen(QPen()); + scene()->addItem(neatFill); + //} + /* next show where we have been bad and crossed the dc's ceiling */ - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); - pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); - pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); - cairo_set_source(gc->cr, pat); - cairo_pattern_destroy(pat); + pat.setColorAt(0, profile_color[CEILING_SHALLOW].first()); + pat.setColorAt(1, profile_color[CEILING_DEEP].first()); + entry = pi->entry; - move_to(gc, 0, 0); + p.clear(); + p.append( QPointF(0,0)); for (i = 0; i < pi->nr; i++, entry++) - line_to(gc, entry->sec, entry->depth); + p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); for (i = pi->nr - 1; i >= 0; i--, entry--) { if (entry->ndl == 0 && entry->stopdepth > entry->depth) { - line_to(gc, entry->sec, entry->stopdepth); + p.append( QPointF( SCALE(gc, entry->sec, entry->stopdepth) )); } else { - line_to(gc, entry->sec, entry->depth); + p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); } } - cairo_close_path(gc->cr); - cairo_fill(gc->cr); + + neatFill = new QGraphicsPolygonItem(); + neatFill->setPolygon(p); + neatFill->setPen(QPen()); + neatFill->setBrush(QBrush(pat)); + scene()->addItem(neatFill); /* Now do it again for the velocity colors */ entry = pi->entry; @@ -442,13 +457,12 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct /* we want to draw the segments in different colors * representing the vertical velocity, so we need to * chop this into short segments */ + depth = entry->depth; - set_source_rgba(gc, VELOCITY_COLORS_START_IDX + entry->velocity); - move_to(gc, entry[-1].sec, entry[-1].depth); - line_to(gc, sec, depth); - cairo_stroke(cr); + QGraphicsLineItem *colorLine = new QGraphicsLineItem( SCALE(gc, entry[-1].sec, entry[-1].depth), SCALE(gc, sec, depth)); + colorLine->setPen(QPen(QBrush(profile_color[ (color_indice_t) (VELOCITY_COLORS_START_IDX + entry->velocity)].first()), 2 )); + scene()->addItem(colorLine); } -#endif } -- cgit v1.2.3-70-g09d2