Merge pull request #5487 from ligfx/removetabledelegate

DolphinQt2: don't use custom delegate for GameList
This commit is contained in:
Leo Lam 2017-05-27 10:23:40 +02:00 committed by GitHub
commit 6a7c3fcac1
9 changed files with 30 additions and 124 deletions

View File

@ -39,7 +39,6 @@ set(SRCS
GameList/GameListModel.cpp
GameList/GameTracker.cpp
GameList/ListProxyModel.cpp
GameList/TableDelegate.cpp
Settings/GeneralPane.cpp
Settings/InterfacePane.cpp
)

View File

@ -94,7 +94,6 @@
<QtMoc Include="GameList\GameListModel.h" />
<QtMoc Include="GameList\GameTracker.h" />
<QtMoc Include="GameList\ListProxyModel.h" />
<QtMoc Include="GameList\TableDelegate.h" />
<QtMoc Include="Host.h" />
<QtMoc Include="InDevelopmentWarning.h" />
<QtMoc Include="Settings\InterfacePane.h" />
@ -129,7 +128,6 @@
<ClCompile Include="$(QtMocOutPrefix)RenderWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)Settings.cpp" />
<ClCompile Include="$(QtMocOutPrefix)SettingsWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)TableDelegate.cpp" />
<ClCompile Include="$(QtMocOutPrefix)ToolBar.cpp" />
<ClCompile Include="AboutDialog.cpp" />
<ClCompile Include="Config\ControllersWindow.cpp" />
@ -154,7 +152,6 @@
<ClCompile Include="GameList\GameListModel.cpp" />
<ClCompile Include="GameList\GameTracker.cpp" />
<ClCompile Include="GameList\ListProxyModel.cpp" />
<ClCompile Include="GameList\TableDelegate.cpp" />
<ClCompile Include="Host.cpp" />
<ClCompile Include="InDevelopmentWarning.cpp" />
<ClCompile Include="Main.cpp" />

View File

@ -63,14 +63,10 @@
<ClCompile Include="Config\PathDialog.cpp">
<Filter>Config</Filter>
</ClCompile>
<ClCompile Include="GameList\TableDelegate.cpp" />
<ClCompile Include="AboutDialog.cpp" />
<ClCompile Include="$(QtMocOutPrefix)AboutDialog.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="$(QtMocOutPrefix)TableDelegate.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="Config\SettingsWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)SettingsWindow.cpp">
<Filter>Generated Files</Filter>
@ -146,7 +142,6 @@
<QtMoc Include="Config\PathDialog.h">
<Filter>Config</Filter>
</QtMoc>
<QtMoc Include="GameList\TableDelegate.h" />
<QtMoc Include="AboutDialog.h" />
<QtMoc Include="Config\SettingsWindow.h" />
<QtMoc Include="Config\PropertiesDialog.h" />

View File

@ -22,7 +22,6 @@
#include "DolphinQt2/Config/PropertiesDialog.h"
#include "DolphinQt2/GameList/GameList.h"
#include "DolphinQt2/GameList/ListProxyModel.h"
#include "DolphinQt2/GameList/TableDelegate.h"
#include "DolphinQt2/Settings.h"
static bool CompressCB(const std::string&, float, void*);
@ -35,8 +34,6 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent)
m_list_proxy = new ListProxyModel(this);
m_list_proxy->setSourceModel(m_model);
m_delegate = new TableDelegate(this);
MakeTableView();
MakeListView();
MakeEmptyView();
@ -59,7 +56,7 @@ void GameList::MakeTableView()
{
m_table = new QTableView(this);
m_table->setModel(m_table_proxy);
m_table->setItemDelegate(m_delegate);
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
m_table->setAlternatingRowColors(true);
@ -67,6 +64,7 @@ void GameList::MakeTableView()
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);

View File

@ -13,8 +13,6 @@
#include "DolphinQt2/GameList/GameFile.h"
#include "DolphinQt2/GameList/GameListModel.h"
class TableDelegate;
class GameList final : public QStackedWidget
{
Q_OBJECT
@ -56,7 +54,6 @@ private:
void ConsiderViewChange();
GameListModel* m_model;
TableDelegate* m_delegate;
QSortFilterProxyModel* m_table_proxy;
QSortFilterProxyModel* m_list_proxy;

View File

@ -5,6 +5,8 @@
#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/Resources.h"
const QSize GAMECUBE_BANNER_SIZE(96, 32);
GameListModel::GameListModel(QObject* parent) : QAbstractTableModel(parent)
{
connect(&m_tracker, &GameTracker::GameLoaded, this, &GameListModel::UpdateGame);
@ -19,14 +21,29 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
return QVariant();
QSharedPointer<GameFile> game = m_games[index.row()];
if (role == Qt::DisplayRole)
if (role == Qt::DecorationRole)
{
switch (index.column())
{
case COL_PLATFORM:
return static_cast<int>(game->GetPlatformID());
return Resources::GetPlatform(static_cast<int>(game->GetPlatformID()));
case COL_COUNTRY:
return Resources::GetCountry(static_cast<int>(game->GetCountryID()));
case COL_RATING:
return Resources::GetRating(game->GetRating());
case COL_BANNER:
return game->GetBanner();
// GameCube banners are 96x32, but Wii banners are 192x64.
// TODO: use custom banners from rom directory like DolphinWX?
QPixmap banner = game->GetBanner();
banner.setDevicePixelRatio(std::max(banner.width() / GAMECUBE_BANNER_SIZE.width(),
banner.height() / GAMECUBE_BANNER_SIZE.height()));
return banner;
}
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case COL_TITLE:
return game->GetLongName();
case COL_ID:
@ -36,11 +53,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
case COL_MAKER:
return game->GetMaker();
case COL_SIZE:
return game->GetFileSize();
case COL_COUNTRY:
return static_cast<int>(game->GetCountryID());
case COL_RATING:
return game->GetRating();
return FormatSize(game->GetFileSize());
}
}
return QVariant();

View File

@ -7,7 +7,7 @@
#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/GameList/ListProxyModel.h"
static QSize LARGE_BANNER_SIZE(144, 48);
const QSize LARGE_BANNER_SIZE(144, 48);
ListProxyModel::ListProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
{
@ -25,10 +25,12 @@ QVariant ListProxyModel::data(const QModelIndex& i, int role) const
}
else if (role == Qt::DecorationRole)
{
return sourceModel()
->data(sourceModel()->index(source_index.row(), GameListModel::COL_BANNER), Qt::DisplayRole)
.value<QPixmap>()
.scaled(LARGE_BANNER_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
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();
}

View File

@ -1,75 +0,0 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <QPainter>
#include "DolphinQt2/GameList/GameFile.h"
#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/GameList/TableDelegate.h"
#include "DolphinQt2/Resources.h"
static QSize NORMAL_BANNER_SIZE(96, 32);
TableDelegate::TableDelegate(QWidget* parent) : QStyledItemDelegate(parent)
{
}
void TableDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QVariant data = index.data(Qt::DisplayRole);
switch (index.column())
{
case GameListModel::COL_PLATFORM:
DrawPixmap(painter, option.rect, Resources::GetPlatform(data.toInt()));
break;
case GameListModel::COL_COUNTRY:
DrawPixmap(painter, option.rect, Resources::GetCountry(data.toInt()));
break;
case GameListModel::COL_RATING:
DrawPixmap(painter, option.rect, Resources::GetRating(data.toInt()));
break;
case GameListModel::COL_BANNER:
DrawPixmap(painter, option.rect,
data.value<QPixmap>().scaled(NORMAL_BANNER_SIZE, Qt::KeepAspectRatio,
Qt::SmoothTransformation));
break;
case GameListModel::COL_SIZE:
painter->drawText(option.rect, Qt::AlignCenter, FormatSize(data.toULongLong()));
break;
// Fall through.
case GameListModel::COL_ID:
case GameListModel::COL_TITLE:
case GameListModel::COL_DESCRIPTION:
case GameListModel::COL_MAKER:
painter->drawText(option.rect, Qt::AlignVCenter, data.toString());
break;
default:
break;
}
}
QSize TableDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
switch (index.column())
{
case GameListModel::COL_PLATFORM:
return Resources::GetPlatform(0).size();
case GameListModel::COL_COUNTRY:
return Resources::GetCountry(0).size();
case GameListModel::COL_RATING:
return Resources::GetRating(0).size();
case GameListModel::COL_BANNER:
return NORMAL_BANNER_SIZE;
default:
return QSize(0, 0);
}
}
void TableDelegate::DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap) const
{
// We don't want to stretch the pixmap out, so center it in the rect.
painter->drawPixmap(rect.left() + (rect.width() - pixmap.width()) / 2,
rect.top() + (rect.height() - pixmap.height()) / 2, pixmap);
}

View File

@ -1,20 +0,0 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QStyledItemDelegate>
class TableDelegate final : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit TableDelegate(QWidget* parent = nullptr);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
void DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap) const;
};