diff --git a/core/pref.c b/core/pref.c index 75dedcbeb..85a5ec243 100644 --- a/core/pref.c +++ b/core/pref.c @@ -92,6 +92,7 @@ struct preferences default_prefs = { .auto_recalculate_thumbnails = true, .extract_video_thumbnails = true, .extract_video_thumbnails_position = 20, // The first fifth seems like a reasonable place + .three_m_based_grid = false, }; /* copy a preferences block, including making copies of all included strings */ diff --git a/core/pref.h b/core/pref.h index a3f9c2b3b..71255c605 100644 --- a/core/pref.h +++ b/core/pref.h @@ -103,6 +103,7 @@ struct preferences { double font_size; double mobile_scale; bool show_developer; + bool three_m_based_grid; // ********** Equipment tab ******* const char *default_cylinder; diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp index c733b0c6b..6e71d0d40 100644 --- a/core/settings/qPrefDisplay.cpp +++ b/core/settings/qPrefDisplay.cpp @@ -67,6 +67,7 @@ void qPrefDisplay::loadSync(bool doSync) load_lastState(); load_singleColumnPortrait(); } + disk_three_m_based_grid(doSync); } void qPrefDisplay::set_divelist_font(const QString &value) @@ -148,6 +149,8 @@ HANDLE_PREFERENCE_BOOL(Display, "displayinvalid", display_invalid_dives); HANDLE_PREFERENCE_BOOL(Display, "show_developer", show_developer); +HANDLE_PREFERENCE_BOOL(Display, "three_m_based_grid", three_m_based_grid); + void qPrefDisplay::setCorrectFont() { // get the font from the settings or our defaults diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h index 61fa5dbaf..ffcf4c7cc 100644 --- a/core/settings/qPrefDisplay.h +++ b/core/settings/qPrefDisplay.h @@ -25,6 +25,7 @@ class qPrefDisplay : public QObject { Q_PROPERTY(QByteArray windowState READ windowState WRITE set_windowState NOTIFY windowStateChanged) Q_PROPERTY(int lastState READ lastState WRITE set_lastState NOTIFY lastStateChanged) Q_PROPERTY(bool singleColumnPortrait READ singleColumnPortrait WRITE set_singleColumnPortrait NOTIFY singleColumnPortraitChanged) + Q_PROPERTY(bool three_m_based_grid READ three_m_based_grid WRITE set_three_m_based_grid NOTIFY three_m_based_gridChanged) public: static qPrefDisplay *instance(); @@ -52,6 +53,7 @@ public: static QByteArray windowState() { return st_windowState; } static int lastState() { return st_lastState; } static bool singleColumnPortrait() { return st_singleColumnPortrait; } + static bool three_m_based_grid() { return prefs.three_m_based_grid; } public slots: static void set_animation_speed(int value); @@ -71,6 +73,7 @@ public slots: static void set_windowState(const QByteArray& value); static void set_lastState(int value); static void set_singleColumnPortrait(bool value); + static void set_three_m_based_grid(bool value); signals: void animation_speedChanged(int value); @@ -90,6 +93,7 @@ signals: void windowStateChanged(const QByteArray& value); void lastStateChanged(int value); void singleColumnPortraitChanged(bool value); + void three_m_based_gridChanged(bool value); private: qPrefDisplay() {} @@ -101,6 +105,7 @@ private: static void disk_mobile_scale(bool doSync); static void disk_display_invalid_dives(bool doSync); static void disk_show_developer(bool doSync); + static void disk_three_m_based_grid(bool doSync); // functions to handle class variables static void load_lastDir(); diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index ca1b51acb..b30b25fd1 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -28,6 +28,10 @@ void PreferencesDefaults::refreshSettings() ui->fontsize->setValue(qPrefDisplay::font_size()); ui->velocitySlider->setValue(qPrefDisplay::animation_speed()); + if (qPrefDisplay::three_m_based_grid()) + ui->grid3MBased->setChecked(true); + else + ui->gridGeneric->setChecked(true); } void PreferencesDefaults::syncSettings() @@ -35,4 +39,5 @@ void PreferencesDefaults::syncSettings() qPrefDisplay::set_divelist_font(ui->font->currentFont().toString()); qPrefDisplay::set_font_size(ui->fontsize->value()); qPrefDisplay::set_animation_speed(ui->velocitySlider->value()); + qPrefDisplay::set_three_m_based_grid(ui->grid3MBased->isChecked()); } diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui index 030bb77d6..5a32e276c 100644 --- a/desktop-widgets/preferences/preferences_defaults.ui +++ b/desktop-widgets/preferences/preferences_defaults.ui @@ -118,7 +118,37 @@ - + + + + Dive profile depth grid + + + + + + Depth line intevals. + + + + + + + generic ( 1, 2, 4, 5, 10 ) + + + + + + + based on ×3 intervals ( 1, 3, 6, 15 ) + + + + + + + diff --git a/mobile-widgets/qml/Settings.qml b/mobile-widgets/qml/Settings.qml index 1792d9865..0137fcac1 100644 --- a/mobile-widgets/qml/Settings.qml +++ b/mobile-widgets/qml/Settings.qml @@ -576,6 +576,16 @@ TemplatePage { PrefDisplay.singleColumnPortrait = checked } } + TemplateLabel { + text: qsTr("Depth line based on ×3 intervals") + } + SsrfSwitch { + checked: PrefDisplay.three_m_based_grid + onClicked: { + PrefDisplay.three_m_based_grid = checked + rootItem.settingsChanged() + } + } TemplateLine { visible: sectionAdvanced.isExpanded Layout.columnSpan: 2 diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 43e32722a..541d4fbf3 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -30,6 +30,7 @@ DiveCartesianAxis::DiveCartesianAxis(Position position, bool inverted, int integ max(0), textVisibility(textVisible), lineVisibility(linesVisible), + gridIsMultipleOfThree(false), labelScale(labelScale), dpr(dpr), transform({1.0, 0.0}) @@ -101,7 +102,7 @@ int DiveCartesianAxis::getMinLabelDistance(const DiveCartesianAxis &timeAxis) co return int(ceil(interval)); } -static double sensibleInterval(double inc, int decimals, bool is_time_axis) +static double sensibleInterval(double inc, int decimals, bool is_time_axis, bool is_multiple_of_three) { if (is_time_axis && inc < 60.0) { // for time axes and less than one hour increments, round to @@ -130,11 +131,22 @@ static double sensibleInterval(double inc, int decimals, bool is_time_axis) double digits_factor = pow(10.0, digits); int inc_int = std::max((int)ceil(inc / digits_factor), 1); - // Do "nice" increments of the leading digit. In general: 1, 2, 4, 5. - if (inc_int > 5) - inc_int = 10; - if (inc_int == 3) - inc_int = 4; + if (is_multiple_of_three) + { + // Do increments quantized to 3. In general: 1, 3, 6, 15 + if (inc_int > 6) + inc_int = 15; + else if (inc_int > 3) + inc_int = 6; + else if (inc_int == 2) + inc_int = 3; + } else { + // Do "nice" increments of the leading digit. In general: 1, 2, 4, 5. + if (inc_int > 5) + inc_int = 10; + if (inc_int == 3) + inc_int = 4; + } inc = inc_int * digits_factor; return inc; @@ -165,7 +177,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed) // Round the interval to a sensible size in display units double intervalDisplay = stepValue * transform.a; - intervalDisplay = sensibleInterval(intervalDisplay, fractionalDigits, position == Position::Bottom); + intervalDisplay = sensibleInterval(intervalDisplay, fractionalDigits, position == Position::Bottom, gridIsMultipleOfThree); // Choose full multiples of the interval as minumum and maximum values double minDisplay = transform.to(dataMin); @@ -478,6 +490,11 @@ double DiveCartesianAxis::minimum() const return min; } +void DiveCartesianAxis::setGridIsMultipleOfThree(bool arg1) +{ + gridIsMultipleOfThree = arg1; +} + std::pair DiveCartesianAxis::screenMinMax() const { return position == Position::Bottom ? std::make_pair(rect.left(), rect.right()) diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index 8b9db59e9..580ded8a1 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -36,6 +36,7 @@ public: double pointInRange(double pos) const; // Point on screen is in range of axis void setTextVisible(bool arg1); void setLinesVisible(bool arg1); + void setGridIsMultipleOfThree(bool arg1); void updateTicks(int animSpeed); double width() const; // only for vertical axes double height() const; // only for horizontal axes @@ -75,6 +76,7 @@ private: double min, max; bool textVisibility; bool lineVisibility; + bool gridIsMultipleOfThree; double labelScale; double dpr; double labelWidth, labelHeight; // maximum expected sizes of label width and height diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 04a431380..eb799f6cb 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -164,6 +164,7 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) : addTissueItems<0,16>(dpr); percentageItem->setZValue(1.0); + profileYAxis->setGridIsMultipleOfThree( qPrefDisplay::three_m_based_grid() ); // Add items to scene addItem(diveComputerText); @@ -304,6 +305,8 @@ void ProfileScene::updateAxes(bool diveHasHeartBeat, bool simplified) if (width <= 10.0 * dpr) return clear(); + profileYAxis->setGridIsMultipleOfThree( qPrefDisplay::three_m_based_grid() ); + // Place the fixed dive computer text at the bottom double bottomBorder = sceneRect().height() - diveComputerText->height() - 2.0 * dpr * diveComputerTextBorder; diveComputerText->setPos(0.0, bottomBorder + dpr * diveComputerTextBorder);