on xenial help sign in
introduce aux itemsPerRow
a9b898cAlbert Astals
plugins/DashViews/organicgrid.cpp+6−4
@@ -67,8 +67,9 @@ QPointF OrganicGrid::positionForIndex(int modelIndex) const
67{
67{
68 const qreal moduleHeight = m_smallDelegateSize.height() + rowSpacing() + m_bigDelegateSize.height();
68 const qreal moduleHeight = m_smallDelegateSize.height() + rowSpacing() + m_bigDelegateSize.height();
69 const qreal moduleWidth = m_smallDelegateSize.width() * 2 + columnSpacing() * 2 + m_bigDelegateSize.width();
69 const qreal moduleWidth = m_smallDelegateSize.width() * 2 + columnSpacing() * 2 + m_bigDelegateSize.width();
70+ const int itemsPerRow = m_numberOfModulesPerRow * 6;
70− const int rowIndex = floor(modelIndex / (m_numberOfModulesPerRow * 6));
71+ const int rowIndex = floor(modelIndex / itemsPerRow);
71− const int columnIndex = floor((modelIndex - rowIndex * m_numberOfModulesPerRow * 6) / 6);
72+ const int columnIndex = floor((modelIndex - rowIndex * itemsPerRow) / 6);
72
73
73 qreal yPos = (moduleHeight + rowSpacing()) * rowIndex;
74 qreal yPos = (moduleHeight + rowSpacing()) * rowIndex;
74 const int moduleIndex = modelIndex % 6;
75 const int moduleIndex = modelIndex % 6;
@@ -223,10 +224,11 @@ void OrganicGrid::calculateImplicitHeight()
223{
224{
224 const qreal moduleHeight = m_smallDelegateSize.height() + rowSpacing() + m_bigDelegateSize.height();
225 const qreal moduleHeight = m_smallDelegateSize.height() + rowSpacing() + m_bigDelegateSize.height();
225 const int itemCount = !model() ? 0 : model()->rowCount();
226 const int itemCount = !model() ? 0 : model()->rowCount();
227+ const int itemsPerRow = m_numberOfModulesPerRow * 6;
226− const int fullRows = floor(itemCount / (m_numberOfModulesPerRow * 6));
228+ const int fullRows = floor(itemCount / itemsPerRow);
227 const qreal fullRowsHeight = fullRows == 0 ? 0 : fullRows * moduleHeight + rowSpacing() * (fullRows - 1);
229 const qreal fullRowsHeight = fullRows == 0 ? 0 : fullRows * moduleHeight + rowSpacing() * (fullRows - 1);
228
230
229− const int remainingItems = itemCount - fullRows * m_numberOfModulesPerRow * 6;
231+ const int remainingItems = itemCount - fullRows * itemsPerRow;
230 if (remainingItems == 0) {
232 if (remainingItems == 0) {
231 setImplicitHeight(fullRowsHeight);
233 setImplicitHeight(fullRowsHeight);
232 } else if (remainingItems <= 2) {
234 } else if (remainingItems <= 2) {