game list frame work
This commit is contained in:
parent
e95f542e34
commit
8f51bd2fa0
|
@ -1,5 +1,5 @@
|
|||
#include "game_list_frame.h"
|
||||
|
||||
#include "gui_settings.h"
|
||||
|
||||
|
||||
void game_list_frame::FixNarrowColumns() const
|
||||
|
@ -43,3 +43,70 @@ void game_list_frame::ResizeColumnsToContents(int spacing) const
|
|||
m_game_list->horizontalHeader()->resizeSection(i, size);
|
||||
}
|
||||
}
|
||||
|
||||
void game_list_frame::SortGameList() const
|
||||
{
|
||||
// Back-up old header sizes to handle unwanted column resize in case of zero search results
|
||||
QList<int> column_widths;
|
||||
const int old_row_count = m_game_list->rowCount();
|
||||
const int old_game_count = m_game_data.count();
|
||||
|
||||
for (int i = 0; i < m_game_list->columnCount(); i++)
|
||||
{
|
||||
column_widths.append(m_game_list->columnWidth(i));
|
||||
}
|
||||
|
||||
// Sorting resizes hidden columns, so unhide them as a workaround
|
||||
QList<int> columns_to_hide;
|
||||
|
||||
for (int i = 0; i < m_game_list->columnCount(); i++)
|
||||
{
|
||||
if (m_game_list->isColumnHidden(i))
|
||||
{
|
||||
m_game_list->setColumnHidden(i, false);
|
||||
columns_to_hide << i;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the list by column and sort order
|
||||
m_game_list->sortByColumn(m_sort_column, m_col_sort_order);
|
||||
|
||||
// Hide columns again
|
||||
for (auto i : columns_to_hide)
|
||||
{
|
||||
m_game_list->setColumnHidden(i, true);
|
||||
}
|
||||
|
||||
// Don't resize the columns if no game is shown to preserve the header settings
|
||||
if (!m_game_list->rowCount())
|
||||
{
|
||||
for (int i = 0; i < m_game_list->columnCount(); i++)
|
||||
{
|
||||
m_game_list->setColumnWidth(i, column_widths[i]);
|
||||
}
|
||||
|
||||
m_game_list->horizontalHeader()->setSectionResizeMode(gui::column_icon, QHeaderView::Fixed);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fixate vertical header and row height
|
||||
m_game_list->verticalHeader()->setMinimumSectionSize(m_icon_size.height());
|
||||
m_game_list->verticalHeader()->setMaximumSectionSize(m_icon_size.height());
|
||||
m_game_list->resizeRowsToContents();
|
||||
|
||||
// Resize columns if the game list was empty before
|
||||
if (!old_row_count && !old_game_count)
|
||||
{
|
||||
ResizeColumnsToContents();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_game_list->resizeColumnToContents(gui::column_icon);
|
||||
}
|
||||
|
||||
// Fixate icon column
|
||||
m_game_list->horizontalHeader()->setSectionResizeMode(gui::column_icon, QHeaderView::Fixed);
|
||||
|
||||
// Shorten the last section to remove horizontal scrollbar if possible
|
||||
m_game_list->resizeColumnToContents(gui::column_count - 1);
|
||||
}
|
|
@ -15,9 +15,19 @@ public :
|
|||
void ResizeColumnsToContents(int spacing = 20) const;
|
||||
|
||||
private:
|
||||
void SortGameList() const;
|
||||
|
||||
// Game List
|
||||
game_list_table* m_game_list = nullptr;
|
||||
QList<QAction*> m_columnActs;
|
||||
Qt::SortOrder m_col_sort_order;
|
||||
int m_sort_column;
|
||||
|
||||
// data
|
||||
QList<game_info> m_game_data;
|
||||
|
||||
// Icons
|
||||
QSize m_icon_size;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,23 @@
|
|||
|
||||
#include <QSettings>
|
||||
|
||||
namespace gui
|
||||
{
|
||||
enum game_list_columns
|
||||
{
|
||||
column_icon,
|
||||
column_name,
|
||||
column_serial,
|
||||
column_firmware,
|
||||
column_version,
|
||||
column_category,
|
||||
column_path,
|
||||
|
||||
column_count
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class gui_settings
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue