Add project explorer dock and tab bar
This commit is contained in:
parent
3901493274
commit
c548d200b6
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,3 +3,7 @@ build/gba
|
|||||||
build/*-release
|
build/*-release
|
||||||
build/*-debug
|
build/*-debug
|
||||||
tags
|
tags
|
||||||
|
nostalgia.gba
|
||||||
|
nostalgia.sav
|
||||||
|
nostalgia_media.oxfs
|
||||||
|
media_header.txt
|
||||||
|
@ -8,6 +8,7 @@ set(CMAKE_AUTOMOC ON)
|
|||||||
add_library(
|
add_library(
|
||||||
NostalgiaStudioStatic
|
NostalgiaStudioStatic
|
||||||
newwizard.cpp
|
newwizard.cpp
|
||||||
|
oxfstreeview.cpp
|
||||||
project.cpp
|
project.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,13 +30,15 @@ target_link_libraries(
|
|||||||
add_library(
|
add_library(
|
||||||
NostalgiaStudio
|
NostalgiaStudio
|
||||||
SHARED
|
SHARED
|
||||||
|
newwizard.cpp
|
||||||
|
oxfstreeview.cpp
|
||||||
|
project.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaStudio
|
NostalgiaStudio
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
Qt5::Widgets
|
Qt5::Widgets
|
||||||
NostalgiaStudioStatic
|
|
||||||
OxFS
|
OxFS
|
||||||
OxStd
|
OxStd
|
||||||
)
|
)
|
||||||
@ -43,6 +46,7 @@ target_link_libraries(
|
|||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
newwizard.hpp
|
newwizard.hpp
|
||||||
|
oxfstreeview.hpp
|
||||||
project.hpp
|
project.hpp
|
||||||
DESTINATION
|
DESTINATION
|
||||||
include/nostalgia/studio/lib
|
include/nostalgia/studio/lib
|
||||||
|
17
src/studio/lib/oxfstreeview.cpp
Normal file
17
src/studio/lib/oxfstreeview.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2017 gtalent2@gmail.com
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "oxfstreeview.hpp"
|
||||||
|
|
||||||
|
namespace nostalgia {
|
||||||
|
namespace studio {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
39
src/studio/lib/oxfstreeview.hpp
Normal file
39
src/studio/lib/oxfstreeview.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2017 gtalent2@gmail.com
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
namespace nostalgia {
|
||||||
|
namespace studio {
|
||||||
|
|
||||||
|
class OxFSFile {
|
||||||
|
private:
|
||||||
|
QList<OxFSFile*> m_childItems;
|
||||||
|
QList<QVariant> m_itemData;
|
||||||
|
OxFSFile *m_parentItem;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit OxFSFile(const QList<QVariant> &data, OxFSFile *parentItem = 0);
|
||||||
|
~OxFSFile();
|
||||||
|
|
||||||
|
void appendChild(OxFSFile *child);
|
||||||
|
|
||||||
|
OxFSFile *child(int row);
|
||||||
|
int childCount() const;
|
||||||
|
int columnCount() const;
|
||||||
|
QVariant data(int column) const;
|
||||||
|
int row() const;
|
||||||
|
OxFSFile *parentItem();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -22,22 +22,14 @@ Project::Project(QString path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Project::~Project() {
|
Project::~Project() {
|
||||||
if (m_fs) {
|
|
||||||
delete m_fs;
|
|
||||||
m_fs = nullptr;
|
|
||||||
}
|
|
||||||
if (m_romBuff) {
|
|
||||||
delete m_romBuff;
|
|
||||||
m_romBuff = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::create() {
|
void Project::create() {
|
||||||
QDir().mkpath(m_path);
|
QDir().mkpath(m_path);
|
||||||
|
|
||||||
m_romBuff = new QByteArray(1024, 0);
|
m_romBuff = QSharedPointer<QByteArray>(new QByteArray(1024, 0));
|
||||||
FileSystem32::format(m_romBuff->data(), m_romBuff->size(), true);
|
FileSystem32::format(m_romBuff->data(), m_romBuff->size(), true);
|
||||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
m_fs = QSharedPointer<FileSystem>(createFileSystem(m_romBuff->data(), m_romBuff->size()));
|
||||||
|
|
||||||
m_fs->mkdir("/Tilesets");
|
m_fs->mkdir("/Tilesets");
|
||||||
|
|
||||||
@ -49,13 +41,17 @@ void Project::create() {
|
|||||||
|
|
||||||
int Project::open() {
|
int Project::open() {
|
||||||
QFile file(m_path + ROM_FILE);
|
QFile file(m_path + ROM_FILE);
|
||||||
m_romBuff = new QByteArray(file.size(), 0);
|
m_romBuff = QSharedPointer<QByteArray>(new QByteArray(file.size(), 0));
|
||||||
file.open(QIODevice::ReadOnly);
|
if (file.exists()) {
|
||||||
if (file.read(m_romBuff->data(), file.size()) > 0) {
|
file.open(QIODevice::ReadOnly);
|
||||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
if (file.read(m_romBuff->data(), file.size()) > 0) {
|
||||||
return 0;
|
m_fs = QSharedPointer<FileSystem>(createFileSystem(m_romBuff->data(), m_romBuff->size()));
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include <ox/fs/filesystem.hpp>
|
#include <ox/fs/filesystem.hpp>
|
||||||
|
|
||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
@ -20,8 +22,8 @@ class Project: public QObject {
|
|||||||
static QString ROM_FILE;
|
static QString ROM_FILE;
|
||||||
|
|
||||||
QString m_path = "";
|
QString m_path = "";
|
||||||
QByteArray *m_romBuff = nullptr;
|
QSharedPointer<QByteArray> m_romBuff;
|
||||||
ox::fs::FileSystem *m_fs = nullptr;
|
QSharedPointer<ox::fs::FileSystem> m_fs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Project(QString path);
|
Project(QString path);
|
||||||
|
@ -31,7 +31,7 @@ int run(int argc, char **args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QApplication app(argc, args);
|
QApplication app(argc, args);
|
||||||
app.setApplicationName(config.app_name);
|
app.setApplicationName(config.appName);
|
||||||
|
|
||||||
MainWindow w(config);
|
MainWindow w(config);
|
||||||
w.show();
|
w.show();
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
#include <QTabBar>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include "lib/newwizard.hpp"
|
#include "lib/newwizard.hpp"
|
||||||
#include "lib/project.hpp"
|
#include "lib/project.hpp"
|
||||||
#include "mainwindow.hpp"
|
#include "mainwindow.hpp"
|
||||||
@ -31,9 +33,13 @@ MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
|
|||||||
move(-x(), -y());
|
move(-x(), -y());
|
||||||
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
|
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
|
||||||
|
|
||||||
setWindowTitle(config.app_name);
|
setWindowTitle(config.appName);
|
||||||
|
|
||||||
|
auto tabbar = new QTabBar(this);
|
||||||
|
setCentralWidget(tabbar);
|
||||||
|
|
||||||
setupMenu();
|
setupMenu();
|
||||||
|
setupProjectExplorer();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
@ -45,6 +51,7 @@ MainWindow::~MainWindow() {
|
|||||||
void MainWindow::setupMenu() {
|
void MainWindow::setupMenu() {
|
||||||
auto menu = menuBar();
|
auto menu = menuBar();
|
||||||
auto fileMenu = menu->addMenu(tr("&File"));
|
auto fileMenu = menu->addMenu(tr("&File"));
|
||||||
|
m_viewMenu = menu->addMenu(tr("&View"));
|
||||||
|
|
||||||
// New...
|
// New...
|
||||||
addAction(
|
addAction(
|
||||||
@ -56,6 +63,16 @@ void MainWindow::setupMenu() {
|
|||||||
SLOT(showNewWizard())
|
SLOT(showNewWizard())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Open Project
|
||||||
|
addAction(
|
||||||
|
fileMenu,
|
||||||
|
tr("&Open Project"),
|
||||||
|
tr(""),
|
||||||
|
QKeySequence::Open,
|
||||||
|
this,
|
||||||
|
SLOT(openProject())
|
||||||
|
);
|
||||||
|
|
||||||
// Exit
|
// Exit
|
||||||
addAction(
|
addAction(
|
||||||
fileMenu,
|
fileMenu,
|
||||||
@ -64,16 +81,22 @@ void MainWindow::setupMenu() {
|
|||||||
QKeySequence::Quit,
|
QKeySequence::Quit,
|
||||||
QApplication::quit
|
QApplication::quit
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupProjectExplorer() {
|
||||||
|
// setup dock
|
||||||
|
auto dock = new QDockWidget(tr("&Project"), this);
|
||||||
|
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
|
addDockWidget(Qt::LeftDockWidgetArea, dock);
|
||||||
|
resizeDocks({dock}, {(int) (width() * 0.25)}, Qt::Horizontal);
|
||||||
|
|
||||||
addAction(
|
// setup tree view
|
||||||
fileMenu,
|
}
|
||||||
tr("Open &Project"),
|
|
||||||
tr(""),
|
void MainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockWidget) {
|
||||||
QKeySequence::Open,
|
QMainWindow::addDockWidget(area, dockWidget);
|
||||||
this,
|
m_viewMenu->addAction(dockWidget->toggleViewAction());
|
||||||
SLOT(openProject())
|
m_dockWidgets.push_back(dockWidget);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
||||||
@ -100,9 +123,11 @@ void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
|||||||
|
|
||||||
void MainWindow::openProject() {
|
void MainWindow::openProject() {
|
||||||
auto p = QFileDialog::getExistingDirectory(this, tr("Select Project Directory..."), QDir::homePath());
|
auto p = QFileDialog::getExistingDirectory(this, tr("Select Project Directory..."), QDir::homePath());
|
||||||
auto project = new Project(p);
|
auto project = QSharedPointer<Project>(new Project(p));
|
||||||
project->open();
|
auto err = project->open();
|
||||||
m_project = project;
|
if (err == 0) {
|
||||||
|
m_project = project;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showNewWizard() {
|
void MainWindow::showNewWizard() {
|
||||||
|
@ -8,9 +8,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QModelIndex>
|
#include <QDockWidget>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QModelIndex>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
|
#include <QPointer>
|
||||||
|
#include <QSharedPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -22,14 +25,26 @@
|
|||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
|
struct NostalgiaStudioState {
|
||||||
|
QString currentProjectPath;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
int ioOp(T *io, NostalgiaStudioState *obj) {
|
||||||
|
ox::Error err = 0;
|
||||||
|
err |= io->op("current_project_path", &obj->currentProjectPath);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct NostalgiaStudioProfile {
|
struct NostalgiaStudioProfile {
|
||||||
QString app_name;
|
QString appName;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int ioOp(T *io, NostalgiaStudioProfile *obj) {
|
int ioOp(T *io, NostalgiaStudioProfile *obj) {
|
||||||
ox::Error err = 0;
|
ox::Error err = 0;
|
||||||
err |= io->op("app_name", &obj->app_name);
|
err |= io->op("app_name", &obj->appName);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,11 +56,14 @@ class MainWindow: public QMainWindow {
|
|||||||
static const QString AppTitle;
|
static const QString AppTitle;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Project *m_project = nullptr;
|
QSharedPointer<Project> m_project;
|
||||||
|
QPointer<QMenu> m_viewMenu;
|
||||||
QVector<std::function<void()>> m_cleanupTasks;
|
QVector<std::function<void()>> m_cleanupTasks;
|
||||||
|
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0);
|
MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0);
|
||||||
|
|
||||||
virtual ~MainWindow();
|
virtual ~MainWindow();
|
||||||
|
|
||||||
void openProject(QString);
|
void openProject(QString);
|
||||||
@ -55,6 +73,10 @@ class MainWindow: public QMainWindow {
|
|||||||
|
|
||||||
void setupMenu();
|
void setupMenu();
|
||||||
|
|
||||||
|
void setupProjectExplorer();
|
||||||
|
|
||||||
|
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget);
|
||||||
|
|
||||||
void addAction(QMenu *menu, QString text, QString toolTip,
|
void addAction(QMenu *menu, QString text, QString toolTip,
|
||||||
QKeySequence::StandardKey key, const QObject *tgt, const char *cb);
|
QKeySequence::StandardKey key, const QObject *tgt, const char *cb);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user