Qt: Add UI for playlist disc switching

This commit is contained in:
Connor McLaughlin 2020-08-15 20:39:11 +10:00
parent d9893bb127
commit 86799775ce
10 changed files with 67 additions and 1 deletions

View File

@ -124,6 +124,8 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
{
case GameListEntryType::Disc:
return m_type_disc_pixmap;
case GameListEntryType::Playlist:
return m_type_playlist_pixmap;
case GameListEntryType::PSExe:
default:
return m_type_exe_pixmap;
@ -275,6 +277,7 @@ void GameListModel::loadCommonImages()
// TODO: Use svg instead of png
m_type_disc_pixmap.load(QStringLiteral(":/icons/media-optical-24.png"));
m_type_exe_pixmap.load(QStringLiteral(":/icons/applications-system-24.png"));
m_type_playlist_pixmap.load(QStringLiteral(":/icons/address-book-new-22.png"));
m_region_eu_pixmap.load(QStringLiteral(":/icons/flag-eu.png"));
m_region_jp_pixmap.load(QStringLiteral(":/icons/flag-jp.png"));
m_region_us_pixmap.load(QStringLiteral(":/icons/flag-us.png"));

View File

@ -53,6 +53,7 @@ private:
QPixmap m_type_disc_pixmap;
QPixmap m_type_exe_pixmap;
QPixmap m_type_playlist_pixmap;
QPixmap m_region_jp_pixmap;
QPixmap m_region_eu_pixmap;

View File

@ -29,7 +29,8 @@
static constexpr char DISC_IMAGE_FILTER[] =
"All File Types (*.bin *.img *.cue *.chd *.exe *.psexe *.psf);;Single-Track Raw Images (*.bin *.img);;Cue Sheets "
"(*.cue);;MAME CHD Images (*.chd);;PlayStation Executables (*.exe *.psexe);;Portable Sound Format Files (*.psf)";
"(*.cue);;MAME CHD Images (*.chd);;PlayStation Executables (*.exe *.psexe);;Portable Sound Format Files "
"(*.psf);;Playlists (*.m3u)";
ALWAYS_INLINE static QString getWindowTitle()
{
@ -294,6 +295,16 @@ void MainWindow::onChangeDiscFromGameListActionTriggered()
switchToGameListView();
}
void MainWindow::onChangeDiscFromPlaylistMenuAboutToShow()
{
m_host_interface->populatePlaylistEntryMenu(m_ui.menuChangeDiscFromPlaylist);
}
void MainWindow::onChangeDiscFromPlaylistMenuAboutToHide()
{
m_ui.menuChangeDiscFromPlaylist->clear();
}
void MainWindow::onRemoveDiscActionTriggered()
{
m_host_interface->changeDisc(QString());
@ -567,6 +578,10 @@ void MainWindow::connectSignals()
connect(m_ui.actionChangeDiscFromFile, &QAction::triggered, this, &MainWindow::onChangeDiscFromFileActionTriggered);
connect(m_ui.actionChangeDiscFromGameList, &QAction::triggered, this,
&MainWindow::onChangeDiscFromGameListActionTriggered);
connect(m_ui.menuChangeDiscFromPlaylist, &QMenu::aboutToShow, this,
&MainWindow::onChangeDiscFromPlaylistMenuAboutToShow);
connect(m_ui.menuChangeDiscFromPlaylist, &QMenu::aboutToHide, this,
&MainWindow::onChangeDiscFromPlaylistMenuAboutToHide);
connect(m_ui.actionRemoveDisc, &QAction::triggered, this, &MainWindow::onRemoveDiscActionTriggered);
connect(m_ui.actionAddGameDirectory, &QAction::triggered,
[this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); });

View File

@ -55,6 +55,8 @@ private Q_SLOTS:
void onStartBIOSActionTriggered();
void onChangeDiscFromFileActionTriggered();
void onChangeDiscFromGameListActionTriggered();
void onChangeDiscFromPlaylistMenuAboutToShow();
void onChangeDiscFromPlaylistMenuAboutToHide();
void onRemoveDiscActionTriggered();
void onGitHubRepositoryActionTriggered();
void onIssueTrackerActionTriggered();

View File

@ -45,8 +45,14 @@
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/media-optical.png</normaloff>:/icons/media-optical.png</iconset>
</property>
<widget class="QMenu" name="menuChangeDiscFromPlaylist">
<property name="title">
<string>From Playlist...</string>
</property>
</widget>
<addaction name="actionChangeDiscFromFile"/>
<addaction name="actionChangeDiscFromGameList"/>
<addaction name="menuChangeDiscFromPlaylist"/>
<addaction name="actionRemoveDisc"/>
</widget>
<widget class="QMenu" name="menuLoadState">

View File

@ -808,6 +808,21 @@ void QtHostInterface::changeDisc(const QString& new_disc_filename)
System::RemoveMedia();
}
void QtHostInterface::changeDiscFromPlaylist(quint32 index)
{
if (!isOnWorkerThread())
{
QMetaObject::invokeMethod(this, "changeDiscFromPlaylist", Qt::QueuedConnection, Q_ARG(quint32, index));
return;
}
if (System::IsShutdown())
return;
if (!System::SwitchMediaFromPlaylist(index))
ReportFormattedError("Failed to switch to playlist index %u", index);
}
static QString FormatTimestampForSaveStateMenu(u64 timestamp)
{
const QDateTime qtime(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(timestamp)));
@ -909,6 +924,24 @@ void QtHostInterface::populateGameListContextMenu(const char* game_code, QWidget
}
}
void QtHostInterface::populatePlaylistEntryMenu(QMenu* menu)
{
if (!System::IsValid())
return;
QActionGroup* ag = new QActionGroup(menu);
const u32 count = System::GetMediaPlaylistCount();
const u32 current = System::GetMediaPlaylistIndex();
for (u32 i = 0; i < count; i++)
{
QAction* action = ag->addAction(QString::fromStdString(System::GetMediaPlaylistPath(i)));
action->setCheckable(true);
action->setChecked(i == current);
connect(action, &QAction::triggered, [this, i]() { changeDiscFromPlaylist(i); });
menu->addAction(action);
}
}
void QtHostInterface::loadState(const QString& filename)
{
if (!isOnWorkerThread())

View File

@ -84,6 +84,9 @@ public:
/// Fills menu with save state info and handlers.
void populateGameListContextMenu(const char* game_code, QWidget* parent_window, QMenu* menu);
/// Fills menu with the current playlist entries. The disc index is marked as checked.
void populatePlaylistEntryMenu(QMenu* menu);
ALWAYS_INLINE QString getSavePathForInputProfile(const QString& name) const
{
return QString::fromStdString(GetSavePathForInputProfile(name.toUtf8().constData()));
@ -140,6 +143,7 @@ public Q_SLOTS:
void resetSystem();
void pauseSystem(bool paused);
void changeDisc(const QString& new_disc_filename);
void changeDiscFromPlaylist(quint32 index);
void loadState(const QString& filename);
void loadState(bool global, qint32 slot);
void saveState(bool global, qint32 slot, bool block_until_done = false);

View File

@ -12,6 +12,7 @@
<file>icons/star-3.png</file>
<file>icons/star-4.png</file>
<file>icons/star-5.png</file>
<file>icons/address-book-new-22.png</file>
<file>icons/applications-internet.png</file>
<file>icons/system-search.png</file>
<file>icons/list-add.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

View File

@ -12,6 +12,7 @@
<file>icons/star-3.png</file>
<file>icons/star-4.png</file>
<file>icons/star-5.png</file>
<file>icons/address-book-new-22.png</file>
<file>icons/applications-internet.png</file>
<file>icons/system-search.png</file>
<file>icons/list-add.png</file>