Add project explorer dock and tab bar

This commit is contained in:
Gary Talent 2017-05-11 15:20:24 -05:00
parent 3901493274
commit c548d200b6
9 changed files with 145 additions and 36 deletions

4
.gitignore vendored
View File

@ -3,3 +3,7 @@ build/gba
build/*-release
build/*-debug
tags
nostalgia.gba
nostalgia.sav
nostalgia_media.oxfs
media_header.txt

View File

@ -8,6 +8,7 @@ set(CMAKE_AUTOMOC ON)
add_library(
NostalgiaStudioStatic
newwizard.cpp
oxfstreeview.cpp
project.cpp
)
@ -29,13 +30,15 @@ target_link_libraries(
add_library(
NostalgiaStudio
SHARED
newwizard.cpp
oxfstreeview.cpp
project.cpp
)
target_link_libraries(
NostalgiaStudio
Qt5::Core
Qt5::Widgets
NostalgiaStudioStatic
OxFS
OxStd
)
@ -43,6 +46,7 @@ target_link_libraries(
install(
FILES
newwizard.hpp
oxfstreeview.hpp
project.hpp
DESTINATION
include/nostalgia/studio/lib

View 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 {
}
}

View 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();
};
}
}

View File

@ -22,22 +22,14 @@ Project::Project(QString path) {
}
Project::~Project() {
if (m_fs) {
delete m_fs;
m_fs = nullptr;
}
if (m_romBuff) {
delete m_romBuff;
m_romBuff = nullptr;
}
}
void Project::create() {
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);
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
m_fs = QSharedPointer<FileSystem>(createFileSystem(m_romBuff->data(), m_romBuff->size()));
m_fs->mkdir("/Tilesets");
@ -49,13 +41,17 @@ void Project::create() {
int Project::open() {
QFile file(m_path + ROM_FILE);
m_romBuff = new QByteArray(file.size(), 0);
file.open(QIODevice::ReadOnly);
if (file.read(m_romBuff->data(), file.size()) > 0) {
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
return 0;
m_romBuff = QSharedPointer<QByteArray>(new QByteArray(file.size(), 0));
if (file.exists()) {
file.open(QIODevice::ReadOnly);
if (file.read(m_romBuff->data(), file.size()) > 0) {
m_fs = QSharedPointer<FileSystem>(createFileSystem(m_romBuff->data(), m_romBuff->size()));
return 0;
} else {
return 1;
}
} else {
return 1;
return 2;
}
}

View File

@ -8,6 +8,8 @@
#pragma once
#include <QSharedPointer>
#include <ox/fs/filesystem.hpp>
namespace nostalgia {
@ -20,8 +22,8 @@ class Project: public QObject {
static QString ROM_FILE;
QString m_path = "";
QByteArray *m_romBuff = nullptr;
ox::fs::FileSystem *m_fs = nullptr;
QSharedPointer<QByteArray> m_romBuff;
QSharedPointer<ox::fs::FileSystem> m_fs;
public:
Project(QString path);

View File

@ -31,7 +31,7 @@ int run(int argc, char **args) {
}
QApplication app(argc, args);
app.setApplicationName(config.app_name);
app.setApplicationName(config.appName);
MainWindow w(config);
w.show();

View File

@ -14,7 +14,9 @@
#include <QLabel>
#include <QLineEdit>
#include <QMenuBar>
#include <QTabBar>
#include <QVector>
#include "lib/newwizard.hpp"
#include "lib/project.hpp"
#include "mainwindow.hpp"
@ -31,9 +33,13 @@ MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
move(-x(), -y());
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();
setupProjectExplorer();
}
MainWindow::~MainWindow() {
@ -45,6 +51,7 @@ MainWindow::~MainWindow() {
void MainWindow::setupMenu() {
auto menu = menuBar();
auto fileMenu = menu->addMenu(tr("&File"));
m_viewMenu = menu->addMenu(tr("&View"));
// New...
addAction(
@ -56,6 +63,16 @@ void MainWindow::setupMenu() {
SLOT(showNewWizard())
);
// Open Project
addAction(
fileMenu,
tr("&Open Project"),
tr(""),
QKeySequence::Open,
this,
SLOT(openProject())
);
// Exit
addAction(
fileMenu,
@ -64,16 +81,22 @@ void MainWindow::setupMenu() {
QKeySequence::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(
fileMenu,
tr("Open &Project"),
tr(""),
QKeySequence::Open,
this,
SLOT(openProject())
);
// setup tree view
}
void MainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockWidget) {
QMainWindow::addDockWidget(area, dockWidget);
m_viewMenu->addAction(dockWidget->toggleViewAction());
m_dockWidgets.push_back(dockWidget);
}
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() {
auto p = QFileDialog::getExistingDirectory(this, tr("Select Project Directory..."), QDir::homePath());
auto project = new Project(p);
project->open();
m_project = project;
auto project = QSharedPointer<Project>(new Project(p));
auto err = project->open();
if (err == 0) {
m_project = project;
}
}
void MainWindow::showNewWizard() {

View File

@ -8,9 +8,12 @@
#pragma once
#include <QModelIndex>
#include <QDockWidget>
#include <QMainWindow>
#include <QModelIndex>
#include <QPoint>
#include <QPointer>
#include <QSharedPointer>
#include <QString>
#include <QVector>
#include <functional>
@ -22,14 +25,26 @@
namespace nostalgia {
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 {
QString app_name;
QString appName;
};
template<typename T>
int ioOp(T *io, NostalgiaStudioProfile *obj) {
ox::Error err = 0;
err |= io->op("app_name", &obj->app_name);
err |= io->op("app_name", &obj->appName);
return err;
}
@ -41,11 +56,14 @@ class MainWindow: public QMainWindow {
static const QString AppTitle;
private:
Project *m_project = nullptr;
QSharedPointer<Project> m_project;
QPointer<QMenu> m_viewMenu;
QVector<std::function<void()>> m_cleanupTasks;
QVector<QPointer<QDockWidget>> m_dockWidgets;
public:
MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0);
virtual ~MainWindow();
void openProject(QString);
@ -55,6 +73,10 @@ class MainWindow: public QMainWindow {
void setupMenu();
void setupProjectExplorer();
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget);
void addAction(QMenu *menu, QString text, QString toolTip,
QKeySequence::StandardKey key, const QObject *tgt, const char *cb);