From f7fc8da94df5d9596af2c291ba455279dcbb4803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 4 Oct 2019 14:21:17 +0200 Subject: [PATCH] [apps/settings] Use a MessageTableCellWithGaugeWithSeparator in the main controller to mimic two tables --- apps/settings/main_controller.cpp | 22 ++++++++++++++----- apps/settings/main_controller.h | 3 ++- ...age_table_cell_with_gauge_with_separator.h | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 apps/settings/message_table_cell_with_gauge_with_separator.h diff --git a/apps/settings/main_controller.cpp b/apps/settings/main_controller.cpp index dd8d5e9cb..73293c6b7 100644 --- a/apps/settings/main_controller.cpp +++ b/apps/settings/main_controller.cpp @@ -90,15 +90,25 @@ int MainController::numberOfRows() const { }; KDCoordinate MainController::rowHeight(int j) { + if (j == k_indexOfBrightnessCell) { + return Metric::ParameterCellHeight + CellWithSeparator::k_margin; + } return Metric::ParameterCellHeight; } KDCoordinate MainController::cumulatedHeightFromIndex(int j) { - return j*rowHeight(0); + KDCoordinate height = j * rowHeight(0); + if (j > k_indexOfBrightnessCell) { + height += CellWithSeparator::k_margin; + } + return height; } int MainController::indexFromCumulatedHeight(KDCoordinate offsetY) { - return offsetY/rowHeight(0); + if (offsetY < rowHeight(0)*k_indexOfBrightnessCell + CellWithSeparator::k_margin) { + return offsetY/rowHeight(0); + } + return (offsetY - CellWithSeparator::k_margin)/rowHeight(0); } HighlightCell * MainController::reusableCell(int index, int type) { @@ -135,14 +145,16 @@ int MainController::typeAtLocation(int i, int j) { void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) { GlobalPreferences * globalPreferences = GlobalPreferences::sharedGlobalPreferences(); Preferences * preferences = Preferences::sharedPreferences(); - MessageTableCell * myCell = (MessageTableCell *)cell; - myCell->setMessage(model()->children(index)->label()); + I18n::Message title = model()->children(index)->label(); if (index == k_indexOfBrightnessCell) { - MessageTableCellWithGauge * myGaugeCell = (MessageTableCellWithGauge *)cell; + MessageTableCellWithGaugeWithSeparator * myGaugeCell = (MessageTableCellWithGaugeWithSeparator *)cell; + myGaugeCell->setMessage(title); GaugeView * myGauge = (GaugeView *)myGaugeCell->accessoryView(); myGauge->setLevel((float)globalPreferences->brightnessLevel()/(float)Ion::Backlight::MaxBrightness); return; } + MessageTableCell * myCell = (MessageTableCell *)cell; + myCell->setMessage(title); if (index == k_indexOfLanguageCell) { int index = (int)globalPreferences->language()-1; static_cast(cell)->setSubtitle(I18n::LanguageNames[index]); diff --git a/apps/settings/main_controller.h b/apps/settings/main_controller.h index 28a8283da..cd7df0b0e 100644 --- a/apps/settings/main_controller.h +++ b/apps/settings/main_controller.h @@ -3,6 +3,7 @@ #include #include "settings_message_tree.h" +#include "message_table_cell_with_gauge_with_separator.h" #include "sub_menu/about_controller.h" #include "sub_menu/display_mode_controller.h" #include "sub_menu/exam_mode_controller.h" @@ -47,7 +48,7 @@ private: bool hasPrompt() const { return promptMessage() != I18n::Message::Default; } constexpr static int k_numberOfSimpleChevronCells = 7; MessageTableCellWithChevronAndMessage m_cells[k_numberOfSimpleChevronCells]; - MessageTableCellWithGauge m_brightnessCell; + MessageTableCellWithGaugeWithSeparator m_brightnessCell; MessageTableCellWithSwitch m_popUpCell; SelectableTableView m_selectableTableView; PreferencesController m_preferencesController; diff --git a/apps/settings/message_table_cell_with_gauge_with_separator.h b/apps/settings/message_table_cell_with_gauge_with_separator.h new file mode 100644 index 000000000..c3d30d7fc --- /dev/null +++ b/apps/settings/message_table_cell_with_gauge_with_separator.h @@ -0,0 +1,22 @@ +#ifndef SETTINGS_MESSAGE_TABLE_WITH_GAUGE_WITH_SEPARATOR_H +#define SETTINGS_MESSAGE_TABLE_WITH_GAUGE_WITH_SEPARATOR_H + +#include "cell_with_separator.h" + +namespace Settings { + +class MessageTableCellWithGaugeWithSeparator : public CellWithSeparator { +public: + MessageTableCellWithGaugeWithSeparator(I18n::Message message, const KDFont * font) : + CellWithSeparator(true), + m_cell(message, font) {} + View * accessoryView() const { return m_cell.accessoryView(); } + void setMessage(I18n::Message message) { return m_cell.setMessage(message); } +private: + HighlightCell * cell() override { return &m_cell; } + MessageTableCellWithGauge m_cell; +}; + +} + +#endif