From b5dc7f738eb77fdf41c9d508c96a3ca7719ee466 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Mon, 18 Feb 2019 15:10:38 +0100 Subject: [PATCH] [escher/table_view] scrollToCell includes CellOverlap In passing, factorize duplicate code. --- escher/include/escher/table_view.h | 2 +- escher/src/table_view.cpp | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h index 7fde8754c..ca2db0d32 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/table_view.h @@ -56,7 +56,7 @@ protected: /* realCellWidth enables to handle list view for which * TableViewDataSource->cellWidht = 0 */ - KDCoordinate columnWidth(int x) const; + KDRect cellFrame(int i, int j) const; /* These two methods transform an index (of subview for instance) into * coordinates that refer to the data source entire table */ int absoluteColumnNumberFromSubviewIndex(int index) const; diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp index adb859b8d..08b2859da 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/table_view.cpp @@ -73,10 +73,14 @@ TableViewDataSource * TableView::ContentView::dataSource() { return m_dataSource; } -KDCoordinate TableView::ContentView::columnWidth(int i) const { - int columnWidth = m_dataSource->columnWidth(i); +KDRect TableView::ContentView::cellFrame(int i, int j) const { + KDCoordinate columnWidth = m_dataSource->columnWidth(i); columnWidth = columnWidth ? columnWidth : m_tableView->maxContentWidthDisplayableWithoutScrolling(); - return columnWidth; + return KDRect( + m_dataSource->cumulatedWidthFromIndex(i), m_dataSource->cumulatedHeightFromIndex(j), + columnWidth + m_horizontalCellOverlap, + m_dataSource->rowHeight(j) + m_verticalCellOverlap + ); } KDCoordinate TableView::ContentView::height() const { @@ -90,8 +94,7 @@ KDCoordinate TableView::ContentView::width() const { } void TableView::ContentView::scrollToCell(int x, int y) const { - KDRect cellRect = KDRect(m_dataSource->cumulatedWidthFromIndex(x), m_dataSource->cumulatedHeightFromIndex(y), columnWidth(x), m_dataSource->rowHeight(y)); - m_tableView->scrollToContentRect(cellRect, true); + m_tableView->scrollToContentRect(cellFrame(x, y), true); } void TableView::ContentView::reloadCellAtLocation(int i, int j) { @@ -172,14 +175,7 @@ void TableView::ContentView::layoutSubviews() { int i = absoluteColumnNumberFromSubviewIndex(index); int j = absoluteRowNumberFromSubviewIndex(index); m_dataSource->willDisplayCellAtLocation((HighlightCell *)cell, i, j); - - KDCoordinate rowHeight = m_dataSource->rowHeight(j); - KDCoordinate columnWidth = this->columnWidth(i); - KDCoordinate verticalOffset = m_dataSource->cumulatedHeightFromIndex(j); - KDCoordinate horizontalOffset = m_dataSource->cumulatedWidthFromIndex(i); - KDRect cellFrame(horizontalOffset, verticalOffset, - columnWidth+m_horizontalCellOverlap, rowHeight+m_verticalCellOverlap); - cell->setFrame(cellFrame); + cell->setFrame(cellFrame(i,j)); } }