mirror of
https://github.com/obhq/obliteration.git
synced 2024-11-27 05:00:24 +00:00
Adds menu/toolbar to open games directory
This commit is contained in:
parent
cdec8fa5b4
commit
9b713f0e69
@ -29,9 +29,9 @@ add_executable(obliteration WIN32
|
||||
game_models.cpp
|
||||
game_settings.cpp
|
||||
game_settings_dialog.cpp
|
||||
initialize_dialog.cpp
|
||||
main.cpp
|
||||
main_window.cpp
|
||||
resources.qrc
|
||||
settings.cpp)
|
||||
|
||||
add_dependencies(obliteration emulator)
|
||||
|
@ -21,7 +21,10 @@ GameListModel::~GameListModel()
|
||||
void GameListModel::add(Game *game)
|
||||
{
|
||||
game->setParent(this);
|
||||
|
||||
beginInsertRows(QModelIndex(), m_items.size(), m_items.size());
|
||||
m_items.append(game);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void GameListModel::clear()
|
||||
|
@ -1,86 +0,0 @@
|
||||
#include "initialize_dialog.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
InitializeDialog::InitializeDialog() :
|
||||
m_gamesDirectory(nullptr)
|
||||
{
|
||||
auto layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(setupGamesDirectory());
|
||||
layout->addStretch();
|
||||
layout->addWidget(setupDialogActions());
|
||||
|
||||
setWindowTitle("Initialize Obliteration");
|
||||
}
|
||||
|
||||
InitializeDialog::~InitializeDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void InitializeDialog::browse()
|
||||
{
|
||||
auto path = QFileDialog::getExistingDirectory(this, "Location for PKG files");
|
||||
|
||||
if (!path.isEmpty()) {
|
||||
m_gamesDirectory->setText(QDir::toNativeSeparators(path));
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *InitializeDialog::setupGamesDirectory()
|
||||
{
|
||||
auto group = new QGroupBox("Location for PKG files");
|
||||
auto layout = new QHBoxLayout(group);
|
||||
|
||||
// Input.
|
||||
m_gamesDirectory = new QLineEdit();
|
||||
m_gamesDirectory->setText(readGamesDirectorySetting());
|
||||
m_gamesDirectory->setMinimumWidth(static_cast<int>(400.0 * devicePixelRatioF()));
|
||||
|
||||
layout->addWidget(m_gamesDirectory);
|
||||
|
||||
// Browse button.
|
||||
auto browse = new QPushButton("...");
|
||||
|
||||
connect(browse, &QPushButton::clicked, this, &InitializeDialog::browse);
|
||||
|
||||
layout->addWidget(browse);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
QWidget *InitializeDialog::setupDialogActions()
|
||||
{
|
||||
auto actions = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
connect(actions, &QDialogButtonBox::accepted, this, &InitializeDialog::save);
|
||||
connect(actions, &QDialogButtonBox::rejected, this, &InitializeDialog::reject);
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
void InitializeDialog::save()
|
||||
{
|
||||
// Check games directory.
|
||||
auto gamesDirectory = m_gamesDirectory->text();
|
||||
|
||||
if (gamesDirectory.isEmpty() || !QDir(gamesDirectory).exists() || !QDir::isAbsolutePath(gamesDirectory)) {
|
||||
QMessageBox::critical(this, "Error", "The value for directory to store games is not valid.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Write settings and close dialog.
|
||||
writeGamesDirectorySetting(QDir::toNativeSeparators(gamesDirectory));
|
||||
|
||||
accept();
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QLineEdit;
|
||||
|
||||
class InitializeDialog final : public QDialog {
|
||||
public:
|
||||
InitializeDialog();
|
||||
~InitializeDialog();
|
||||
|
||||
private slots:
|
||||
void browse();
|
||||
|
||||
private:
|
||||
QWidget *setupGamesDirectory();
|
||||
QWidget *setupDialogActions();
|
||||
void save();
|
||||
|
||||
private:
|
||||
QLineEdit *m_gamesDirectory;
|
||||
};
|
@ -8,12 +8,15 @@
|
||||
#include <QCloseEvent>
|
||||
#include <QGuiApplication>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QIcon>
|
||||
#include <QListView>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
#include <QTabWidget>
|
||||
#include <QToolBar>
|
||||
#include <QSettings>
|
||||
|
||||
#include <cstring>
|
||||
@ -22,15 +25,27 @@ MainWindow::MainWindow(void *emulator) :
|
||||
m_emulator(emulator),
|
||||
m_games(nullptr)
|
||||
{
|
||||
setWindowTitle("Obliteration");
|
||||
restoreGeometry();
|
||||
|
||||
// Setup File menu.
|
||||
auto file = menuBar()->addMenu("&File");
|
||||
auto fileMenu = menuBar()->addMenu("&File");
|
||||
auto openGames = new QAction(QIcon(":/resources/folder-open-outline.svg"), "&Open Games Folder", this);
|
||||
auto quit = new QAction("&Quit", this);
|
||||
|
||||
connect(openGames, &QAction::triggered, this, &MainWindow::openGamesFolder);
|
||||
connect(quit, &QAction::triggered, this, &MainWindow::close);
|
||||
|
||||
file->addAction(quit);
|
||||
fileMenu->addAction(openGames);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(quit);
|
||||
|
||||
// Setup File toolbar.
|
||||
auto fileBar = addToolBar("&File");
|
||||
|
||||
fileBar->setMovable(false);
|
||||
|
||||
fileBar->addAction(openGames);
|
||||
|
||||
// Setup game list.
|
||||
m_games = new QListView();
|
||||
@ -131,6 +146,26 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::openGamesFolder()
|
||||
{
|
||||
if (!requireEmulatorStopped()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Browse folder.
|
||||
auto path = QFileDialog::getExistingDirectory(this, "Location for PKG files");
|
||||
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
path = QDir::toNativeSeparators(path);
|
||||
|
||||
// Write setting and reload game list.
|
||||
writeGamesDirectorySetting(path);
|
||||
reloadGames();
|
||||
}
|
||||
|
||||
void MainWindow::startGame(const QModelIndex &index)
|
||||
{
|
||||
// Get target game.
|
||||
|
@ -16,6 +16,7 @@ protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void openGamesFolder();
|
||||
void startGame(const QModelIndex &index);
|
||||
void requestGamesContextMenu(const QPoint &pos);
|
||||
|
||||
|
6
src/resources.qrc
Normal file
6
src/resources.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0">
|
||||
<qresource>
|
||||
<file>resources/folder-open-outline.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
1
src/resources/folder-open-outline.svg
Normal file
1
src/resources/folder-open-outline.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6.1,10L4,18V8H21A2,2 0 0,0 19,6H12L10,4H4A2,2 0 0,0 2,6V18A2,2 0 0,0 4,20H19C19.9,20 20.7,19.4 20.9,18.5L23.2,10H6.1M19,18H6L7.6,12H20.6L19,18Z" /></svg>
|
After Width: | Height: | Size: 223 B |
Loading…
Reference in New Issue
Block a user