diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index 7bf55f141..34b6cbb9c 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -54,16 +54,30 @@ void CurveView::setCurveViewRange(CurveViewRange * curveViewRange) { m_curveViewRange = curveViewRange; } +/* When setting cursor, banner or ok view we first dirty the former element + * frame (in case we set the new element to be nullptr or the new element frame + * does not recover the former element frame) and then we dirty the new element + * frame (most of the time it is automatically done by the layout but the frame + * might be identical to the previous one and in that case layoutSubviews will + * do nothing). */ + void CurveView::setCursorView(View * cursorView) { + markRectAsDirty(cursorFrame()); m_cursorView = cursorView; + markRectAsDirty(cursorFrame()); + layoutSubviews(); } void CurveView::setBannerView(View * bannerView) { + markRectAsDirty(bannerFrame()); m_bannerView = bannerView; + layoutSubviews(); } void CurveView::setOkView(View * okView) { + markRectAsDirty(okFrame()); m_okView = okView; + layoutSubviews(); } float CurveView::resolution() const { @@ -477,39 +491,50 @@ void CurveView::stampAtLocation(KDContext * ctx, KDRect rect, float pxf, float p void CurveView::layoutSubviews() { if (m_curveViewCursor != nullptr && m_cursorView != nullptr) { + m_cursorView->setFrame(cursorFrame()); + } + if (m_bannerView != nullptr) { + m_bannerView->setFrame(bannerFrame()); + } + if (m_okView != nullptr) { + m_okView->setFrame(okFrame()); + } +} + +KDRect CurveView::cursorFrame() { + KDRect cursorFrame = KDRectZero; + if (m_cursorView && m_mainViewSelected && !std::isnan(m_curveViewCursor->x()) && !std::isnan(m_curveViewCursor->y())) { KDCoordinate xCursorPixelPosition = std::round(floatToPixel(Axis::Horizontal, m_curveViewCursor->x())); KDCoordinate yCursorPixelPosition = std::round(floatToPixel(Axis::Vertical, m_curveViewCursor->y())); - KDRect cursorFrame(xCursorPixelPosition - cursorSize().width()/2, yCursorPixelPosition - cursorSize().height()/2, cursorSize().width(), cursorSize().height()); + cursorFrame = KDRect(xCursorPixelPosition - cursorSize().width()/2, yCursorPixelPosition - cursorSize().height()/2, cursorSize().width(), cursorSize().height()); if (cursorSize().height() == 0) { KDCoordinate bannerHeight = m_bannerView != nullptr ? m_bannerView->minimalSizeForOptimalDisplay().height() : 0; cursorFrame = KDRect(xCursorPixelPosition - cursorSize().width()/2, 0, cursorSize().width(),bounds().height()-bannerHeight); } - if (!m_mainViewSelected || std::isnan(m_curveViewCursor->x()) || std::isnan(m_curveViewCursor->y()) - || std::isinf(m_curveViewCursor->x()) || std::isinf(m_curveViewCursor->y())) { - cursorFrame = KDRectZero; - } - m_cursorView->setFrame(cursorFrame); } - if (m_bannerView != nullptr) { + return cursorFrame; +} + +KDRect CurveView::bannerFrame() { + KDRect bannerFrame = KDRectZero; + if (m_bannerView && m_mainViewSelected) { KDCoordinate bannerHeight = m_bannerView->minimalSizeForOptimalDisplay().height(); - KDRect bannerFrame(KDRect(0, bounds().height()- bannerHeight, bounds().width(), bannerHeight)); - if (!m_mainViewSelected) { - bannerFrame = KDRectZero; - } - m_bannerView->setFrame(bannerFrame); + bannerFrame = KDRect(0, bounds().height()- bannerHeight, bounds().width(), bannerHeight); } - if (m_okView != nullptr) { + return bannerFrame; +} + +KDRect CurveView::okFrame() { + KDRect okFrame = KDRectZero; + if (m_okView && m_mainViewSelected) { KDCoordinate bannerHeight = 0; if (m_bannerView != nullptr) { bannerHeight = m_bannerView->minimalSizeForOptimalDisplay().height(); } KDSize okSize = m_okView->minimalSizeForOptimalDisplay(); - KDRect okFrame(KDRect(bounds().width()- okSize.width()-k_okMargin, bounds().height()- bannerHeight-okSize.height()-k_okMargin, okSize)); - if (!m_mainViewSelected) { - okFrame = KDRectZero; - } - m_okView->setFrame(okFrame); + okFrame = KDRect(bounds().width()- okSize.width()-k_okMargin, bounds().height()- bannerHeight-okSize.height()-k_okMargin, okSize); } + return okFrame; } int CurveView::numberOfSubviews() const { diff --git a/apps/shared/curve_view.h b/apps/shared/curve_view.h index 590a8d29f..c8c907a12 100644 --- a/apps/shared/curve_view.h +++ b/apps/shared/curve_view.h @@ -76,6 +76,9 @@ private: * anti alising. */ void stampAtLocation(KDContext * ctx, KDRect rect, float pxf, float pyf, KDColor color) const; void layoutSubviews() override; + KDRect cursorFrame(); + KDRect bannerFrame(); + KDRect okFrame(); int numberOfSubviews() const override; View * subviewAtIndex(int index) override; /* m_curveViewRange has to be non null but the cursor model, the banner and diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index f4b1a5c50..660b400d2 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -83,7 +83,6 @@ bool SumGraphController::handleEvent(Ion::Events::Event event) { app()->setFirstResponder(m_legendView.textField()); m_graphView->setAreaHighlightColor(false); m_graphView->setCursorView(&m_cursorView); - m_graphView->reload(); m_endSum = m_cursor->x(); m_legendView.setEditableZone(m_endSum); m_legendView.setSumSymbol(m_step, m_startSum); @@ -197,7 +196,6 @@ bool SumGraphController::handleEnter() { m_legendView.setLegendMessage(I18n::Message::Default, m_step); m_graphView->setAreaHighlightColor(true); m_graphView->setCursorView(nullptr); - m_graphView->reload(); myApp->setFirstResponder(this); return true; }