Skip to content

Commit

Permalink
Qt: fix bug when grid item width > grid width
Browse files Browse the repository at this point in the history
  • Loading branch information
CozmoP committed Jan 15, 2019
1 parent 2052e15 commit e4bc578
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions ui/drivers/qt/gridview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,66 +94,80 @@ void GridView::calculateRectsIfNecessary() const

const int maxWidth = viewport()->width();

switch (m_viewMode)
if (m_size + m_spacing * 2 > maxWidth)
{
case Anchored:
m_rectForRow[0] = QRectF(x, y, m_size, m_size);

for (row = 1; row < model()->rowCount(); ++row)
{
int columns = (maxWidth - m_spacing) / (m_size + m_spacing);
if (columns > 0)
y += m_size + m_spacing;
m_rectForRow[row] = QRectF(x, y, m_size, m_size);
}
}
else
{
switch (m_viewMode)
{
case Anchored:
{
const int actualSpacing = (maxWidth - m_spacing - m_size - (columns - 1) * m_size) / columns;
for (row = 0; row < model()->rowCount(); ++row)
int columns = (maxWidth - m_spacing) / (m_size + m_spacing);
if (columns > 0)
{
nextX = x + m_size + actualSpacing;
if (nextX > maxWidth)
const int actualSpacing = (maxWidth - m_spacing - m_size - (columns - 1) * m_size) / columns;
for (row = 0; row < model()->rowCount(); ++row)
{
x = m_spacing;
y += m_size + m_spacing;
nextX = x + m_size + actualSpacing;
if (nextX > maxWidth)
{
x = m_spacing;
y += m_size + m_spacing;
nextX = x + m_size + actualSpacing;
}
m_rectForRow[row] = QRectF(x, y, m_size, m_size);
x = nextX;
}
m_rectForRow[row] = QRectF(x, y, m_size, m_size);
x = nextX;
}
break;
}
break;
}
case Centered:
{
int columns = (maxWidth - m_spacing) / (m_size + m_spacing);
if (columns > 0)
case Centered:
{
const int actualSpacing = (maxWidth - columns * m_size) / (columns + 1);
x = actualSpacing;
for (row = 0; row < model()->rowCount(); ++row)
int columns = (maxWidth - m_spacing) / (m_size + m_spacing);
if (columns > 0)
{
nextX = x + m_size + actualSpacing;
if (nextX > maxWidth)
const int actualSpacing = (maxWidth - columns * m_size) / (columns + 1);
x = actualSpacing;
for (row = 0; row < model()->rowCount(); ++row)
{
x = actualSpacing;
y += m_size + m_spacing;
nextX = x + m_size + actualSpacing;
if (nextX > maxWidth)
{
x = actualSpacing;
y += m_size + m_spacing;
nextX = x + m_size + actualSpacing;
}
m_rectForRow[row] = QRectF(x, y, m_size, m_size);
x = nextX;
}
m_rectForRow[row] = QRectF(x, y, m_size, m_size);
x = nextX;
}
break;
}
break;
}
case Simple:
for (row = 0; row < model()->rowCount(); ++row)
{
nextX = x + m_size + m_spacing;
if (nextX > maxWidth)
case Simple:
for (row = 0; row < model()->rowCount(); ++row)
{
x = m_spacing;
y += m_size + m_spacing;
nextX = x + m_size + m_spacing;
if (nextX > maxWidth)
{
x = m_spacing;
y += m_size + m_spacing;
nextX = x + m_size + m_spacing;
}
m_rectForRow[row] = QRectF(x, y, m_size, m_size);
x = nextX;
}
m_rectForRow[row] = QRectF(x, y, m_size, m_size);
x = nextX;
break;
}
break;
}

m_idealHeight = y + m_size + m_spacing;
m_hashIsDirty = false;
viewport()->update();
Expand Down

0 comments on commit e4bc578

Please sign in to comment.