Skip to content

Commit

Permalink
Merge pull request #5886 from JosJuice/rename-list-table
Browse files Browse the repository at this point in the history
DolphinQt2: Rename "Table"/"List" to "List View"/"Grid View"
  • Loading branch information
Helios747 committed Aug 6, 2017
2 parents 84ecc0e + fa4723f commit 7a74e8a
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt2/CMakeLists.txt
Expand Up @@ -63,8 +63,8 @@ set(SRCS
GameList/GameList.cpp
GameList/GameListModel.cpp
GameList/GameTracker.cpp
GameList/GridProxyModel.cpp
GameList/ListProxyModel.cpp
GameList/TableProxyModel.cpp
QtUtils/BlockUserInputFilter.cpp
QtUtils/DoubleClickEventFilter.cpp
QtUtils/ElidedButton.cpp
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/DolphinQt2/DolphinQt2.vcxproj
Expand Up @@ -84,8 +84,8 @@
<QtMoc Include="GameList\GameList.h" />
<QtMoc Include="GameList\GameListModel.h" />
<QtMoc Include="GameList\GameTracker.h" />
<QtMoc Include="GameList\GridProxyModel.h" />
<QtMoc Include="GameList\ListProxyModel.h" />
<QtMoc Include="GameList\TableProxyModel.h" />
<QtMoc Include="Host.h" />
<QtMoc Include="HotkeyScheduler.h" />
<QtMoc Include="InDevelopmentWarning.h" />
Expand Down Expand Up @@ -126,8 +126,8 @@
<ClCompile Include="$(QtMocOutPrefix)InfoWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)InterfacePane.cpp" />
<ClCompile Include="$(QtMocOutPrefix)IOWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)GridProxyModel.cpp" />
<ClCompile Include="$(QtMocOutPrefix)ListProxyModel.cpp" />
<ClCompile Include="$(QtMocOutPrefix)TableProxyModel.cpp" />
<ClCompile Include="$(QtMocOutPrefix)LoggerWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)MainWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)MappingButton.cpp" />
Expand Down Expand Up @@ -181,8 +181,8 @@
<ClCompile Include="GameList\GameList.cpp" />
<ClCompile Include="GameList\GameListModel.cpp" />
<ClCompile Include="GameList\GameTracker.cpp" />
<ClCompile Include="GameList\GridProxyModel.cpp" />
<ClCompile Include="GameList\ListProxyModel.cpp" />
<ClCompile Include="GameList\TableProxyModel.cpp" />
<ClCompile Include="HotkeyScheduler.cpp" />
<ClCompile Include="Host.cpp" />
<ClCompile Include="InDevelopmentWarning.cpp" />
Expand Down
124 changes: 62 additions & 62 deletions Source/Core/DolphinQt2/GameList/GameList.cpp
Expand Up @@ -25,8 +25,8 @@

#include "DolphinQt2/Config/PropertiesDialog.h"
#include "DolphinQt2/GameList/GameList.h"
#include "DolphinQt2/GameList/GridProxyModel.h"
#include "DolphinQt2/GameList/ListProxyModel.h"
#include "DolphinQt2/GameList/TableProxyModel.h"
#include "DolphinQt2/QtUtils/DoubleClickEventFilter.h"
#include "DolphinQt2/Settings.h"

Expand All @@ -35,59 +35,59 @@ static bool CompressCB(const std::string&, float, void*);
GameList::GameList(QWidget* parent) : QStackedWidget(parent)
{
m_model = new GameListModel(this);
m_table_proxy = new TableProxyModel(this);
m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_table_proxy->setSortRole(Qt::InitialSortOrderRole);
m_table_proxy->setSourceModel(m_model);
m_list_proxy = new ListProxyModel(this);
m_list_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_list_proxy->setSortRole(Qt::InitialSortOrderRole);
m_list_proxy->setSourceModel(m_model);
m_grid_proxy = new GridProxyModel(this);
m_grid_proxy->setSourceModel(m_model);

MakeTableView();
MakeListView();
MakeGridView();
MakeEmptyView();

connect(m_table, &QTableView::doubleClicked, this, &GameList::GameSelected);
connect(m_list, &QListView::doubleClicked, this, &GameList::GameSelected);
connect(m_list, &QTableView::doubleClicked, this, &GameList::GameSelected);
connect(m_grid, &QListView::doubleClicked, this, &GameList::GameSelected);
connect(&Settings::Instance(), &Settings::PathAdded, m_model, &GameListModel::DirectoryAdded);
connect(&Settings::Instance(), &Settings::PathRemoved, m_model, &GameListModel::DirectoryRemoved);
connect(m_model, &QAbstractItemModel::rowsInserted, this, &GameList::ConsiderViewChange);
connect(m_model, &QAbstractItemModel::rowsRemoved, this, &GameList::ConsiderViewChange);

addWidget(m_table);
addWidget(m_list);
addWidget(m_grid);
addWidget(m_empty);
m_prefer_table = Settings::Instance().GetPreferredView();
m_prefer_list = Settings::Instance().GetPreferredView();
ConsiderViewChange();
}

void GameList::MakeTableView()
void GameList::MakeListView()
{
m_table = new QTableView(this);
m_table->setModel(m_table_proxy);

m_table->setSelectionMode(QAbstractItemView::SingleSelection);
m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
m_table->setAlternatingRowColors(true);
m_table->setShowGrid(false);
m_table->setSortingEnabled(true);
m_table->setCurrentIndex(QModelIndex());
m_table->setContextMenuPolicy(Qt::CustomContextMenu);
m_table->setWordWrap(false);

connect(m_table, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu);

m_table->setColumnHidden(GameListModel::COL_PLATFORM, !SConfig::GetInstance().m_showSystemColumn);
m_table->setColumnHidden(GameListModel::COL_ID, !SConfig::GetInstance().m_showIDColumn);
m_table->setColumnHidden(GameListModel::COL_BANNER, !SConfig::GetInstance().m_showBannerColumn);
m_table->setColumnHidden(GameListModel::COL_TITLE, !SConfig::GetInstance().m_showTitleColumn);
m_table->setColumnHidden(GameListModel::COL_DESCRIPTION,
!SConfig::GetInstance().m_showDescriptionColumn);
m_table->setColumnHidden(GameListModel::COL_MAKER, !SConfig::GetInstance().m_showMakerColumn);
m_table->setColumnHidden(GameListModel::COL_SIZE, !SConfig::GetInstance().m_showSizeColumn);
m_table->setColumnHidden(GameListModel::COL_COUNTRY, !SConfig::GetInstance().m_showRegionColumn);
m_table->setColumnHidden(GameListModel::COL_RATING, !SConfig::GetInstance().m_showStateColumn);

QHeaderView* hor_header = m_table->horizontalHeader();
m_list = new QTableView(this);
m_list->setModel(m_list_proxy);

m_list->setSelectionMode(QAbstractItemView::SingleSelection);
m_list->setSelectionBehavior(QAbstractItemView::SelectRows);
m_list->setAlternatingRowColors(true);
m_list->setShowGrid(false);
m_list->setSortingEnabled(true);
m_list->setCurrentIndex(QModelIndex());
m_list->setContextMenuPolicy(Qt::CustomContextMenu);
m_list->setWordWrap(false);

connect(m_list, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu);

m_list->setColumnHidden(GameListModel::COL_PLATFORM, !SConfig::GetInstance().m_showSystemColumn);
m_list->setColumnHidden(GameListModel::COL_ID, !SConfig::GetInstance().m_showIDColumn);
m_list->setColumnHidden(GameListModel::COL_BANNER, !SConfig::GetInstance().m_showBannerColumn);
m_list->setColumnHidden(GameListModel::COL_TITLE, !SConfig::GetInstance().m_showTitleColumn);
m_list->setColumnHidden(GameListModel::COL_DESCRIPTION,
!SConfig::GetInstance().m_showDescriptionColumn);
m_list->setColumnHidden(GameListModel::COL_MAKER, !SConfig::GetInstance().m_showMakerColumn);
m_list->setColumnHidden(GameListModel::COL_SIZE, !SConfig::GetInstance().m_showSizeColumn);
m_list->setColumnHidden(GameListModel::COL_COUNTRY, !SConfig::GetInstance().m_showRegionColumn);
m_list->setColumnHidden(GameListModel::COL_RATING, !SConfig::GetInstance().m_showStateColumn);

QHeaderView* hor_header = m_list->horizontalHeader();

connect(hor_header, &QHeaderView::sortIndicatorChanged, this, &GameList::OnHeaderViewChanged);
connect(hor_header, &QHeaderView::sectionResized, this, &GameList::OnHeaderViewChanged);
Expand All @@ -107,8 +107,8 @@ void GameList::MakeTableView()
hor_header->setSectionResizeMode(GameListModel::COL_DESCRIPTION, QHeaderView::Stretch);
hor_header->setSectionResizeMode(GameListModel::COL_RATING, QHeaderView::ResizeToContents);

m_table->verticalHeader()->hide();
m_table->setFrameStyle(QFrame::NoFrame);
m_list->verticalHeader()->hide();
m_list->setFrameStyle(QFrame::NoFrame);
}

void GameList::MakeEmptyView()
Expand All @@ -128,16 +128,16 @@ void GameList::MakeEmptyView()
});
}

void GameList::MakeListView()
void GameList::MakeGridView()
{
m_list = new QListView(this);
m_list->setModel(m_list_proxy);
m_list->setViewMode(QListView::IconMode);
m_list->setResizeMode(QListView::Adjust);
m_list->setUniformItemSizes(true);
m_list->setContextMenuPolicy(Qt::CustomContextMenu);
m_list->setFrameStyle(QFrame::NoFrame);
connect(m_list, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu);
m_grid = new QListView(this);
m_grid->setModel(m_grid_proxy);
m_grid->setViewMode(QListView::IconMode);
m_grid->setResizeMode(QListView::Adjust);
m_grid->setUniformItemSizes(true);
m_grid->setContextMenuPolicy(Qt::CustomContextMenu);
m_grid->setFrameStyle(QFrame::NoFrame);
connect(m_grid, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu);
}

void GameList::ShowContextMenu(const QPoint&)
Expand Down Expand Up @@ -383,15 +383,15 @@ QString GameList::GetSelectedGame() const
{
QAbstractItemView* view;
QSortFilterProxyModel* proxy;
if (currentWidget() == m_table)
if (currentWidget() == m_list)
{
view = m_table;
proxy = m_table_proxy;
view = m_list;
proxy = m_list_proxy;
}
else
{
view = m_list;
proxy = m_list_proxy;
view = m_grid;
proxy = m_grid_proxy;
}
QItemSelectionModel* sel_model = view->selectionModel();
if (sel_model->hasSelection())
Expand All @@ -402,21 +402,21 @@ QString GameList::GetSelectedGame() const
return QStringLiteral("");
}

void GameList::SetPreferredView(bool table)
void GameList::SetPreferredView(bool list)
{
m_prefer_table = table;
Settings::Instance().SetPreferredView(table);
m_prefer_list = list;
Settings::Instance().SetPreferredView(list);
ConsiderViewChange();
}

void GameList::ConsiderViewChange()
{
if (m_model->rowCount(QModelIndex()) > 0)
{
if (m_prefer_table)
setCurrentWidget(m_table);
else
if (m_prefer_list)
setCurrentWidget(m_list);
else
setCurrentWidget(m_grid);
}
else
{
Expand Down Expand Up @@ -444,13 +444,13 @@ void GameList::OnColumnVisibilityToggled(const QString& row, bool visible)
{tr("Title"), GameListModel::COL_TITLE},
{tr("State"), GameListModel::COL_RATING}};

m_table->setColumnHidden(rowname_to_col_index[row], !visible);
m_list->setColumnHidden(rowname_to_col_index[row], !visible);
}

void GameList::OnGameListVisibilityChanged()
{
m_table_proxy->invalidate();
m_list_proxy->invalidate();
m_grid_proxy->invalidate();
}

static bool CompressCB(const std::string& text, float percent, void* ptr)
Expand All @@ -466,5 +466,5 @@ static bool CompressCB(const std::string& text, float percent, void* ptr)
void GameList::OnHeaderViewChanged()
{
QSettings().setValue(QStringLiteral("tableheader/state"),
m_table->horizontalHeader()->saveState());
m_list->horizontalHeader()->saveState());
}
18 changes: 9 additions & 9 deletions Source/Core/DolphinQt2/GameList/GameList.h
Expand Up @@ -21,9 +21,9 @@ class GameList final : public QStackedWidget
explicit GameList(QWidget* parent = nullptr);
QString GetSelectedGame() const;

void SetTableView() { SetPreferredView(true); }
void SetListView() { SetPreferredView(false); }
void SetViewColumn(int col, bool view) { m_table->setColumnHidden(col, !view); }
void SetListView() { SetPreferredView(true); }
void SetGridView() { SetPreferredView(false); }
void SetViewColumn(int col, bool view) { m_list->setColumnHidden(col, !view); }
void OnColumnVisibilityToggled(const QString& row, bool visible);
void OnGameListVisibilityChanged();

Expand All @@ -46,21 +46,21 @@ class GameList final : public QStackedWidget
void CompressISO();
void OnHeaderViewChanged();

void MakeTableView();
void MakeListView();
void MakeGridView();
void MakeEmptyView();
// We only have two views, just use a bool to distinguish.
void SetPreferredView(bool table);
void SetPreferredView(bool list);
void ConsiderViewChange();

GameListModel* m_model;
QSortFilterProxyModel* m_table_proxy;
QSortFilterProxyModel* m_list_proxy;
QSortFilterProxyModel* m_grid_proxy;

QListView* m_list;
QTableView* m_table;
QListView* m_grid;
QTableView* m_list;
QLabel* m_empty;
bool m_prefer_table;
bool m_prefer_list;

protected:
void keyReleaseEvent(QKeyEvent* event) override;
Expand Down
42 changes: 42 additions & 0 deletions Source/Core/DolphinQt2/GameList/GridProxyModel.cpp
@@ -0,0 +1,42 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <QSize>

#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/GameList/GridProxyModel.h"

const QSize LARGE_BANNER_SIZE(144, 48);

GridProxyModel::GridProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
{
setSortCaseSensitivity(Qt::CaseInsensitive);
sort(GameListModel::COL_TITLE);
}

QVariant GridProxyModel::data(const QModelIndex& i, int role) const
{
QModelIndex source_index = mapToSource(i);
if (role == Qt::DisplayRole)
{
return sourceModel()->data(sourceModel()->index(source_index.row(), GameListModel::COL_TITLE),
Qt::DisplayRole);
}
else if (role == Qt::DecorationRole)
{
auto pixmap = sourceModel()
->data(sourceModel()->index(source_index.row(), GameListModel::COL_BANNER),
Qt::DecorationRole)
.value<QPixmap>();
return pixmap.scaled(LARGE_BANNER_SIZE * pixmap.devicePixelRatio(), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
}
return QVariant();
}

bool GridProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
GameListModel* glm = qobject_cast<GameListModel*>(sourceModel());
return glm->ShouldDisplayGameListItem(source_row);
}
19 changes: 19 additions & 0 deletions Source/Core/DolphinQt2/GameList/GridProxyModel.h
@@ -0,0 +1,19 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QSortFilterProxyModel>

// This subclass of QSortFilterProxyModel transforms the raw data into a
// single-column large icon + name to be displayed in a QListView.
class GridProxyModel final : public QSortFilterProxyModel
{
Q_OBJECT

public:
explicit GridProxyModel(QObject* parent = nullptr);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
};
30 changes: 2 additions & 28 deletions Source/Core/DolphinQt2/GameList/ListProxyModel.cpp
@@ -1,38 +1,12 @@
// Copyright 2015 Dolphin Emulator Project
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <QSize>

#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/GameList/ListProxyModel.h"

const QSize LARGE_BANNER_SIZE(144, 48);
#include "DolphinQt2/GameList/GameListModel.h"

ListProxyModel::ListProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
{
setSortCaseSensitivity(Qt::CaseInsensitive);
sort(GameListModel::COL_TITLE);
}

QVariant ListProxyModel::data(const QModelIndex& i, int role) const
{
QModelIndex source_index = mapToSource(i);
if (role == Qt::DisplayRole)
{
return sourceModel()->data(sourceModel()->index(source_index.row(), GameListModel::COL_TITLE),
Qt::DisplayRole);
}
else if (role == Qt::DecorationRole)
{
auto pixmap = sourceModel()
->data(sourceModel()->index(source_index.row(), GameListModel::COL_BANNER),
Qt::DecorationRole)
.value<QPixmap>();
return pixmap.scaled(LARGE_BANNER_SIZE * pixmap.devicePixelRatio(), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
}
return QVariant();
}

bool ListProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
Expand Down

0 comments on commit 7a74e8a

Please sign in to comment.