Skip to content

Commit

Permalink
GUI: Minimal Qt window
Browse files Browse the repository at this point in the history
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent 16c2a0a commit 7b64f37
Show file tree
Hide file tree
Showing 9 changed files with 974 additions and 550 deletions.
428 changes: 61 additions & 367 deletions src/gui/mainwindow.cpp

Large diffs are not rendered by default.

104 changes: 30 additions & 74 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,96 +25,52 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <map>
#include <QMainWindow>
#include <QFileSystemModel>
#include <QLabel>
#include <QProgressBar>

#include <wx/frame.h>
#include "verdigris/wobjectdefs.h"

#include "src/common/ptrmap.h"
#include "src/common/ustring.h"
#include "src/common/filetree.h"

#include "src/aurora/types.h"
#include "src/aurora/archive.h"

namespace Aurora {
class KEYFile;
class KEYDataFile;
namespace Ui {
class MainWindow;
}

class wxPanel;
class wxSplitterWindow;
class wxGenericStaticText;
class wxBoxSizer;
class wxButton;

namespace GUI {

class ResourceTree;
class ResourceTreeItem;

class PanelResourceInfo;

class PanelPreviewEmpty;
class PanelPreviewSound;
class PanelPreviewImage;
class MainWindow : public QMainWindow {
W_OBJECT(MainWindow)

class MainWindow : public wxFrame {
public:
MainWindow(const wxString &title, const wxPoint &pos, const wxSize &size);
~MainWindow();
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

bool open(Common::UString path);
// signals:
void open(const QString &path)
W_SIGNAL(open, path)

void forceRedraw();
void pushStatus(const Common::UString &text);
void popStatus();

void resourceSelect(const ResourceTreeItem *item);
void resourceActivate(const ResourceTreeItem &item);

Aurora::Archive *getArchive(const boost::filesystem::path &path);

private:
typedef Common::PtrMap<Common::UString, Aurora::Archive> ArchiveMap;
typedef Common::PtrMap<Common::UString, Aurora::KEYDataFile> KEYDataFileMap;
// public slots:
void setTreeViewModel(const QString &path);

Common::UString _path;
Common::FileTree _files;
// private slots:
void on_actionOpen_directory_triggered();
void on_actionOpen_file_triggered();
void on_actionClose_triggered();
void on_actionQuit_triggered();

ResourceTree *_resourceTree;
void on_pushButton_clicked();

wxSplitterWindow *_splitterInfoPreview;
void on_pushButton_2_clicked();

PanelResourceInfo *_panelResourceInfo;
void on_pushButton_3_clicked();

PanelPreviewEmpty *_panelPreviewEmpty;
PanelPreviewSound *_panelPreviewSound;
PanelPreviewImage *_panelPreviewImage;
void on_filesTabWidget_tabCloseRequested(int index);

ArchiveMap _archives;
KEYDataFileMap _keyDataFiles;

void onOpenDir(wxCommandEvent &event);
void onOpenFile(wxCommandEvent &event);
void onClose(wxCommandEvent &event);
void onQuit(wxCommandEvent &event);
void onAbout(wxCommandEvent &event);

void createLayout();

void close();

void showPreviewPanel(wxPanel *panel);
void showPreviewPanel(Aurora::ResourceType type);
void showPreviewPanel(const ResourceTreeItem *item);

Common::UString dialogOpenDir(const Common::UString &title);
Common::UString dialogOpenFile(const Common::UString &title, const Common::UString &mask);

void loadKEYDataFiles(Aurora::KEYFile &key);
Aurora::KEYDataFile *getKEYDataFile(const Common::UString &file);

wxDECLARE_EVENT_TABLE();
private:
Ui::MainWindow *ui;
QFileSystemModel fsModel;
QLabel *statusLabel;
QProgressBar *statusProgressBar;
};

} // End of namespace GUI
Expand Down
22 changes: 11 additions & 11 deletions src/gui/panelresourceinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

#include "src/gui/panelresourceinfo.h"
#include "src/gui/eventid.h"
#include "src/gui/mainwindow.h"
// #include "src/gui/mainwindow.h"
#include "src/gui/resourcetree.h"

namespace GUI {
Expand All @@ -60,8 +60,8 @@ wxBEGIN_EVENT_TABLE(PanelResourceInfo, wxPanel)
EVT_BUTTON(kEventButtonExportTGA , PanelResourceInfo::onExportTGA)
wxEND_EVENT_TABLE()

PanelResourceInfo::PanelResourceInfo(wxWindow *parent, MainWindow &mainWindow, const Common::UString &title) :
wxPanel(parent, wxID_ANY), _mainWindow(&mainWindow), _currentItem(0) {
PanelResourceInfo::PanelResourceInfo(wxWindow *parent/*, MainWindow &mainWindow*/, const Common::UString &title) :
wxPanel(parent, wxID_ANY), /*_mainWindow(&mainWindow),*/ _currentItem(0) {

createLayout(title);
}
Expand Down Expand Up @@ -220,10 +220,10 @@ bool PanelResourceInfo::exportRaw(const Common::UString &path) {
if (!_currentItem || path.empty())
return false;

_mainWindow->pushStatus(constructStatus("Saving", _currentItem->getName(), path));
/*_mainWindow->pushStatus(constructStatus("Saving", _currentItem->getName(), path));
BOOST_SCOPE_EXIT( (&_mainWindow) ) {
_mainWindow->popStatus();
} BOOST_SCOPE_EXIT_END
} BOOST_SCOPE_EXIT_END*/

try {
Common::ScopedPtr<Common::SeekableReadStream> res(_currentItem->getResourceData());
Expand All @@ -245,10 +245,10 @@ bool PanelResourceInfo::exportBMUMP3(const Common::UString &path) {
if (!_currentItem || path.empty())
return false;

_mainWindow->pushStatus(constructStatus("Exporting", _currentItem->getName(), path));
/*_mainWindow->pushStatus(constructStatus("Exporting", _currentItem->getName(), path));
BOOST_SCOPE_EXIT( (&_mainWindow) ) {
_mainWindow->popStatus();
} BOOST_SCOPE_EXIT_END
} BOOST_SCOPE_EXIT_END*/

try {
Common::ScopedPtr<Common::SeekableReadStream> res(_currentItem->getResourceData());
Expand All @@ -270,10 +270,10 @@ bool PanelResourceInfo::exportWAV(const Common::UString &path) {
if (!_currentItem || path.empty())
return false;

_mainWindow->pushStatus(constructStatus("Exporting", _currentItem->getName(), path));
/*_mainWindow->pushStatus(constructStatus("Exporting", _currentItem->getName(), path));
BOOST_SCOPE_EXIT( (&_mainWindow) ) {
_mainWindow->popStatus();
} BOOST_SCOPE_EXIT_END
} BOOST_SCOPE_EXIT_END*/

try {
Common::ScopedPtr<Sound::AudioStream> sound(_currentItem->getAudioStream());
Expand All @@ -295,10 +295,10 @@ bool PanelResourceInfo::exportTGA(const Common::UString &path) {
if (!_currentItem || path.empty())
return false;

_mainWindow->pushStatus(constructStatus("Exporting", _currentItem->getName(), path));
/*_mainWindow->pushStatus(constructStatus("Exporting", _currentItem->getName(), path));
BOOST_SCOPE_EXIT( (&_mainWindow) ) {
_mainWindow->popStatus();
} BOOST_SCOPE_EXIT_END
} BOOST_SCOPE_EXIT_END*/

try {
Common::ScopedPtr<Images::Decoder> image(_currentItem->getImage());
Expand Down
6 changes: 3 additions & 3 deletions src/gui/panelresourceinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ class wxCommandEvent;

namespace GUI {

class MainWindow;
// class MainWindow;
class ResourceTreeItem;

class PanelResourceInfo : public wxPanel {
public:
PanelResourceInfo(wxWindow *parent, MainWindow &mainWindow, const Common::UString &title);
PanelResourceInfo(wxWindow *parent/*, MainWindow &mainWindow*/, const Common::UString &title);
~PanelResourceInfo();

void setCurrentItem(const ResourceTreeItem *item);

private:
MainWindow *_mainWindow;
// MainWindow *_mainWindow;

const ResourceTreeItem *_currentItem;

Expand Down
28 changes: 14 additions & 14 deletions src/gui/resourcetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

#include "src/gui/resourcetree.h"
#include "src/gui/eventid.h"
#include "src/gui/mainwindow.h"
// #include "src/gui/mainwindow.h"

namespace GUI {

Expand Down Expand Up @@ -246,12 +246,12 @@ wxBEGIN_EVENT_TABLE(ResourceTree, wxTreeCtrl)
wxEND_EVENT_TABLE()

wxIMPLEMENT_DYNAMIC_CLASS(ResourceTree, wxTreeCtrl);
ResourceTree::ResourceTree() : _mainWindow(0) {
ResourceTree::ResourceTree() /*: _mainWindow(0)*/ {
}

ResourceTree::ResourceTree(wxWindow *parent, MainWindow &mainWindow) :
wxTreeCtrl(parent, kEventResourceTree, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_SINGLE),
_mainWindow(&mainWindow) {
ResourceTree::ResourceTree(wxWindow *parent/*, MainWindow &mainWindow*/) :
wxTreeCtrl(parent, kEventResourceTree, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_SINGLE)/*,
_mainWindow(&mainWindow)*/ {

wxIcon icon[kImageMAX];

Expand All @@ -275,7 +275,7 @@ void ResourceTree::populate(const Common::FileTree::Entry &root) {
populate(root, treeRoot);
Expand(treeRoot);

_mainWindow->resourceSelect(getItemData(treeRoot));
// _mainWindow->resourceSelect(getItemData(treeRoot));
}

void ResourceTree::populate(const Common::FileTree::Entry &e, wxTreeItemId t) {
Expand Down Expand Up @@ -310,9 +310,9 @@ int ResourceTree::OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &
}

void ResourceTree::onSelChanged(wxTreeEvent &event) {
assert(_mainWindow);
// assert(_mainWindow);

_mainWindow->resourceSelect(getItemData(event.GetItem()));
// _mainWindow->resourceSelect(getItemData(event.GetItem()));
}

void ResourceTree::onItemExpanding(wxTreeEvent &event) {
Expand All @@ -336,16 +336,16 @@ void ResourceTree::onItemExpanding(wxTreeEvent &event) {
if (data.addedArchiveMembers)
return;

_mainWindow->pushStatus(Common::UString("Loading archive ") + item->getName() + "...");
// _mainWindow->pushStatus(Common::UString("Loading archive ") + item->getName() + "...");

// Load the archive, if necessary
if (!data.archive) {
try {
data.archive = _mainWindow->getArchive(data.path);
// data.archive = _mainWindow->getArchive(data.path);
} catch (Common::Exception &e) {
// If that fails, print the error and treat this archive as empty

_mainWindow->popStatus();
// _mainWindow->popStatus();

e.add("Failed to load archive \"%s\"", item->getName().c_str());
Common::printException(e, "WARNING: ");
Expand All @@ -360,18 +360,18 @@ void ResourceTree::onItemExpanding(wxTreeEvent &event) {
for (Aurora::Archive::ResourceList::const_iterator r = resources.begin(); r != resources.end(); ++r)
appendItem(event.GetItem(), new ResourceTreeItem(data.archive, *r));

_mainWindow->popStatus();
// _mainWindow->popStatus();
data.addedArchiveMembers = true;
}

void ResourceTree::onItemActivated(wxTreeEvent &event) {
assert(_mainWindow);
// assert(_mainWindow);

const ResourceTreeItem *item = getItemData(event.GetItem());
if (!item)
return;

_mainWindow->resourceActivate(*item);
// _mainWindow->resourceActivate(*item);
}

ResourceTree::Image ResourceTree::getImage(const ResourceTreeItem &item) {
Expand Down
6 changes: 3 additions & 3 deletions src/gui/resourcetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Images {

namespace GUI {

class MainWindow;
// class MainWindow;

class ResourceTreeItem : public wxTreeItemData {
public:
Expand Down Expand Up @@ -129,7 +129,7 @@ wxDECLARE_DYNAMIC_CLASS(ResourceTree);

public:
ResourceTree();
ResourceTree(wxWindow *parent, MainWindow &mainWindow);
ResourceTree(wxWindow *parent/*, MainWindow &mainWindow*/);
~ResourceTree();

void populate(const Common::FileTree::Entry &root);
Expand All @@ -153,7 +153,7 @@ wxDECLARE_DYNAMIC_CLASS(ResourceTree);
kImageMAX
};

MainWindow *_mainWindow;
// MainWindow *_mainWindow;

static Image getImage(const ResourceTreeItem &item);

Expand Down
3 changes: 2 additions & 1 deletion src/gui/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
noinst_LTLIBRARIES += src/gui/libgui.la

QT_UI_FORMS_BUILT = \
ui/ui_mainwindow.h
$(EMPTY)

BUILT_SOURCES += $(QT_UI_FORMS_BUILT)
Expand Down Expand Up @@ -54,5 +55,5 @@ EXTRA_src_gui_libgui_la_DEPENDENCIES = \
$(QT_UI_FORMS_BUILT) \
$(EMPTY)

ui_%.h: ui/%.ui
ui/ui_%.h: ui/%.ui
@UIC@ -o $@ $<

0 comments on commit 7b64f37

Please sign in to comment.