From b7e150cb8ff4a4a00b98f61ec85166b8e4b1eeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 19 Oct 2016 17:54:24 +0200 Subject: [PATCH] [apps/graph/values] Adjust the title of functions and derivatives in the center of cells Change-Id: Ib09e0d22b4f5389d59e37f77f4ee069e5148c0a7 --- apps/graph/values/function_title_cell.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/graph/values/function_title_cell.cpp b/apps/graph/values/function_title_cell.cpp index abba84da2..0fdbdf3d5 100644 --- a/apps/graph/values/function_title_cell.cpp +++ b/apps/graph/values/function_title_cell.cpp @@ -9,6 +9,14 @@ void FunctionTitleCell::setColor(KDColor color) { void FunctionTitleCell::setDerivative(bool derivative) { m_derivative = derivative; + PointerTextView * pointerTextView = (PointerTextView *)subviewAtIndex(0); + int textwidth = KDText::stringSize("f").width(); + // Here we compute the right horizontal alignment to center "f(x)" or "f'(x)" + if (derivative) { + pointerTextView->setAlignment(0.5f*(m_frame.width() - 5*textwidth)/(m_frame.width() - textwidth), 0.5f); + } else { + pointerTextView->setAlignment(0.5f*(m_frame.width() - 4*textwidth)/(m_frame.width() - textwidth), 0.5f); + } } void FunctionTitleCell::drawRect(KDContext * ctx, KDRect rect) const { @@ -16,8 +24,9 @@ void FunctionTitleCell::drawRect(KDContext * ctx, KDRect rect) const { // 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())); + KDPoint origin(0.5f*(m_frame.width() - 4*textSize.width()), 0.5f*(m_frame.height() - textSize.height())); if (m_derivative) { + origin = KDPoint(0.5f*(m_frame.width() - 5*textSize.width()), 0.5f*(m_frame.height() - textSize.height())); 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 {