Qt: resize game list columns by default with slight spacing

This commit is contained in:
Megamouse 2018-05-22 14:13:21 +02:00 committed by Ani
parent f1670a9ea0
commit 40d2341ef1
2 changed files with 34 additions and 2 deletions

View File

@ -183,8 +183,7 @@ void game_list_frame::LoadSettings()
if (!m_gameList->horizontalHeader()->restoreState(state) && m_gameList->rowCount())
{
// If no settings exist, resize to contents.
m_gameList->verticalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
m_gameList->horizontalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
ResizeColumnsToContents();
}
for (int col = 0; col < m_columnActs.count(); ++col)
@ -226,6 +225,29 @@ void game_list_frame::FixNarrowColumns()
}
}
void game_list_frame::ResizeColumnsToContents(int spacing)
{
if (!m_gameList)
{
return;
}
m_gameList->verticalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
m_gameList->horizontalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
// Make non-icon columns slighty bigger for better visuals
for (int i = 1; i < m_gameList->columnCount(); i++)
{
if (m_gameList->isColumnHidden(i))
{
continue;
}
int size = m_gameList->horizontalHeader()->sectionSize(i) + spacing;
m_gameList->horizontalHeader()->resizeSection(i, size);
}
}
void game_list_frame::OnColClicked(int col)
{
if (col == 0) return; // Don't "sort" icons.
@ -418,10 +440,17 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
if (m_isListLayout)
{
int scroll_position = m_gameList->verticalScrollBar()->value();
int rows = m_gameList->rowCount();
int row = PopulateGameList();
m_gameList->selectRow(row);
SortGameList();
// Resize columns if the game list was empty before
if (!rows)
{
ResizeColumnsToContents();
}
if (scrollAfter)
{
m_gameList->scrollTo(m_gameList->currentIndex(), QAbstractItemView::PositionAtCenter);

View File

@ -183,6 +183,9 @@ public:
/** Fix columns with width smaller than the minimal section size */
void FixNarrowColumns();
/** Resizes the columns to their contents and adds a small spacing */
void ResizeColumnsToContents(int spacing = 20);
/** Refresh the gamelist with/without loading game data from files. Public so that main frame can refresh after vfs or install */
void Refresh(const bool fromDrive = false, const bool scrollAfter = true);