diff --git a/apps/graph/even_odd_cell.cpp b/apps/graph/even_odd_cell.cpp index e20976bea..6c46c4c0a 100644 --- a/apps/graph/even_odd_cell.cpp +++ b/apps/graph/even_odd_cell.cpp @@ -4,10 +4,8 @@ constexpr KDColor EvenOddCell::k_evenLineBackgroundColor; constexpr KDColor EvenOddCell::k_oddLineBackgroundColor; constexpr KDColor EvenOddCell::k_selectedLineBackgroundColor; -EvenOddCell::EvenOddCell(float horizontalAlignment, float verticalAlignement) : +EvenOddCell::EvenOddCell() : ChildlessView(), - m_horizontalAlignment(horizontalAlignment), - m_verticalAlignment(verticalAlignement), m_highlighted(false), m_even(false) { @@ -36,7 +34,6 @@ KDColor EvenOddCell::backgroundColor() const { void EvenOddCell::drawRect(KDContext * ctx, KDRect rect) const { - // Select the background color according to the even line and the cursor selection KDColor background = backgroundColor(); ctx->fillRect(rect, background); } diff --git a/apps/graph/even_odd_cell.h b/apps/graph/even_odd_cell.h index db46ff5b0..bef02c8de 100644 --- a/apps/graph/even_odd_cell.h +++ b/apps/graph/even_odd_cell.h @@ -5,7 +5,7 @@ class EvenOddCell : public ChildlessView { public: - EvenOddCell(float horizontalAlignment, float verticalAlignment); + EvenOddCell(); void setEven(bool even); void setHighlighted(bool highlight); void reloadCell(); @@ -16,9 +16,7 @@ public: static constexpr KDColor k_oddLineBackgroundColor = KDColorWhite; static constexpr KDColor k_selectedLineBackgroundColor = KDColor(0xC0D3EA); -protected: - float m_horizontalAlignment; - float m_verticalAlignment; +private: bool m_highlighted; bool m_even; }; diff --git a/apps/graph/list/function_cell.cpp b/apps/graph/list/function_cell.cpp index 8777b1152..a53b241d2 100644 --- a/apps/graph/list/function_cell.cpp +++ b/apps/graph/list/function_cell.cpp @@ -1,38 +1,18 @@ #include "function_cell.h" -constexpr KDColor FunctionCell::k_evenLineBackgroundColor; -constexpr KDColor FunctionCell::k_oddLineBackgroundColor; -constexpr KDColor FunctionCell::k_selectedLineBackgroundColor; constexpr KDColor FunctionCell::k_desactiveTextColor; FunctionCell::FunctionCell() : - ChildlessView(), - m_highlighted(false), - m_even(false), + EvenOddCell(), m_function(nullptr) { } -void FunctionCell::setEven(bool even) { - m_even = even; - markRectAsDirty(bounds()); -} - void FunctionCell::setFunction(Graph::Function * f) { m_function = f; markRectAsDirty(bounds()); } -void FunctionCell::setHighlighted(bool highlight) { - m_highlighted = highlight; - markRectAsDirty(bounds()); -} - Graph::Function * FunctionCell::function() { return m_function; } - -void FunctionCell::reloadCell() { - //TODO: optimize for function_name_view (make it virtual) - markRectAsDirty(bounds()); -} diff --git a/apps/graph/list/function_cell.h b/apps/graph/list/function_cell.h index a234ce88f..a0eaa4b56 100644 --- a/apps/graph/list/function_cell.h +++ b/apps/graph/list/function_cell.h @@ -3,24 +3,17 @@ #include #include "../function.h" +#include "../even_odd_cell.h" -class FunctionCell : public ChildlessView { +class FunctionCell : public EvenOddCell { public: FunctionCell(); void setFunction(Graph::Function * f); - void setEven(bool even); - void setHighlighted(bool highlight); Graph::Function * function(); - void reloadCell(); - static constexpr KDColor k_evenLineBackgroundColor = KDColor(0xF9F9F9); - static constexpr KDColor k_oddLineBackgroundColor = KDColor(0xEEEEF2); - static constexpr KDColor k_selectedLineBackgroundColor = KDColor(0x8582DB); static constexpr KDColor k_desactiveTextColor = KDColor(0x646464); protected: - bool m_highlighted; - bool m_even; Graph::Function * m_function; }; diff --git a/apps/graph/list/function_expression_view.cpp b/apps/graph/list/function_expression_view.cpp index cf52f868c..c6e8cb12a 100644 --- a/apps/graph/list/function_expression_view.cpp +++ b/apps/graph/list/function_expression_view.cpp @@ -6,10 +6,9 @@ FunctionExpressionView::FunctionExpressionView() : } void FunctionExpressionView::drawRect(KDContext * ctx, KDRect rect) const { + EvenOddCell::drawRect(ctx, rect); // Select the background color according to the even line and the cursor selection - KDColor background = m_even ? FunctionCell::k_evenLineBackgroundColor : FunctionCell::k_oddLineBackgroundColor; - background = m_highlighted ? FunctionCell::k_selectedLineBackgroundColor : background; - ctx->fillRect(rect, background); + KDColor background = backgroundColor(); // Select text color according to the state of the function bool active = m_function->isActive(); KDColor text = active ? KDColorBlack : FunctionCell::k_desactiveTextColor; diff --git a/apps/graph/list/function_name_view.cpp b/apps/graph/list/function_name_view.cpp index d5864baea..d207327da 100644 --- a/apps/graph/list/function_name_view.cpp +++ b/apps/graph/list/function_name_view.cpp @@ -6,24 +6,21 @@ FunctionNameView::FunctionNameView() : } void FunctionNameView::drawRect(KDContext * ctx, KDRect rect) const { - KDCoordinate width = bounds().width(); - KDCoordinate height = bounds().height(); + EvenOddCell::drawRect(ctx, rect); // First color the color indicator + KDCoordinate height = bounds().height(); KDColor functionColor = m_function->color(); ctx->fillRect(KDRect(0, 0, k_colorIndicatorThickness, height), functionColor); - // Select the background color according to the even line and the cursor selection - bool evenLine = m_even; - KDColor backgroundColor = evenLine ? FunctionCell::k_evenLineBackgroundColor : FunctionCell::k_oddLineBackgroundColor; - backgroundColor = m_highlighted ? FunctionCell::k_selectedLineBackgroundColor : backgroundColor; - ctx->fillRect(KDRect(k_colorIndicatorThickness, 0, width-k_colorIndicatorThickness, height), backgroundColor); - // Select function name color and the tex color according to the state of the function + // Select function name color and the text color according to the state of the function bool active = m_function->isActive(); KDColor textColor = active ? KDColorBlack : FunctionCell::k_desactiveTextColor; KDColor functionNameColor = active ? functionColor : FunctionCell::k_desactiveTextColor; + // Select the background color according to the even line and the cursor selection + KDColor background = backgroundColor(); // Position the name of the function const char * functionName = m_function->name(); KDCoordinate baseline = m_function->layout()->baseline(); KDSize nameSize = KDText::stringSize(functionName); - ctx->drawString(functionName, KDPoint(k_colorIndicatorThickness, baseline-nameSize.height()), functionNameColor, backgroundColor); - ctx->drawString("(x)", KDPoint(k_colorIndicatorThickness+nameSize.width(), baseline-nameSize.height()), textColor, backgroundColor); + ctx->drawString(functionName, KDPoint(k_colorIndicatorThickness, baseline-nameSize.height()), functionNameColor, background); + ctx->drawString("(x)", KDPoint(k_colorIndicatorThickness+nameSize.width(), baseline-nameSize.height()), textColor, background); }