From 678fc5b437ca573d94156dba6a6c1a032caf412e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 19 Oct 2016 17:34:15 +0200 Subject: [PATCH] [apps/graph/values] Enable function title cell to draw a derivative function title Change-Id: I20f207bb73bf1459029601fb5900fbbd12ec3b77 --- apps/graph/values/function_title_cell.cpp | 11 ++++++++++- apps/graph/values/function_title_cell.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/graph/values/function_title_cell.cpp b/apps/graph/values/function_title_cell.cpp index fe38b0c7d..abba84da2 100644 --- a/apps/graph/values/function_title_cell.cpp +++ b/apps/graph/values/function_title_cell.cpp @@ -7,13 +7,22 @@ void FunctionTitleCell::setColor(KDColor color) { m_functionColor = color; } +void FunctionTitleCell::setDerivative(bool derivative) { + m_derivative = derivative; +} + void FunctionTitleCell::drawRect(KDContext * ctx, KDRect rect) const { EvenOddCell::drawRect(ctx, rect); // Write the "(x)" KDColor background = backgroundColor(); KDSize textSize = KDText::stringSize("f"); KDPoint origin(0.5f*(m_frame.width() - textSize.width()), 0.5f*(m_frame.height() - textSize.height())); - ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), m_functionColor , background); + if (m_derivative) { + ctx->drawString("'", origin.translatedBy(KDPoint(textSize.width(), 0)), m_functionColor , background); + ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(2*textSize.width(), 0)), m_functionColor , background); + } else { + ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), m_functionColor , background); + } // Color the color indicator ctx->fillRect(KDRect(0, 0, bounds().width(), k_colorIndicatorThickness), m_functionColor); } diff --git a/apps/graph/values/function_title_cell.h b/apps/graph/values/function_title_cell.h index 8df2424b9..59abe61c3 100644 --- a/apps/graph/values/function_title_cell.h +++ b/apps/graph/values/function_title_cell.h @@ -9,9 +9,11 @@ class FunctionTitleCell : public TitleCell { public: void setColor(KDColor color); void drawRect(KDContext * ctx, KDRect rect) const override; + void setDerivative(bool derivative); private: constexpr static KDCoordinate k_colorIndicatorThickness = 2; KDColor m_functionColor; + bool m_derivative; }; }