Skip to content

Commit

Permalink
GUI: Replace QFileSystemModel with QAbstractItemModel
Browse files Browse the repository at this point in the history
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent ed1fcf7 commit eaabcf7
Show file tree
Hide file tree
Showing 13 changed files with 739 additions and 855 deletions.
103 changes: 46 additions & 57 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,81 +35,70 @@
#include "src/common/strutil.h"
#include "src/gui/mainwindow.h"
#include "src/aurora/util.h"
#include "src/gui/resourcetree.h"
#include "src/gui/resourcetreeitem.h"

namespace GUI {

W_OBJECT_IMPL(MainWindow)

MainWindow::MainWindow(QWidget *parent, const char *version, QSize size, QString path) :
QMainWindow(parent),
ui(new Ui::MainWindow)
_ui(new Ui::MainWindow)
{
ui->setupUi(this);
_ui->setupUi(this);

connect(this, &MainWindow::openDir, this, &MainWindow::setTreeViewModel);
connect(ui->actionOpen_directory, &QAction::triggered, this, &MainWindow::on_actionOpen_directory_triggered);
connect(ui->actionClose, &QAction::triggered, this, &MainWindow::on_actionClose_triggered);
connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::on_actionQuit_triggered);
connect(ui->pushButton_1, &QPushButton::clicked, this, &MainWindow::on_pushButton_1_clicked);
connect(ui->pushButton_2, &QPushButton::clicked, this, &MainWindow::on_pushButton_2_clicked);
connect(ui->pushButton_3, &QPushButton::clicked, this, &MainWindow::on_pushButton_3_clicked);
connect(ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::on_pushButton_4_clicked);
connect(_ui->actionOpen_directory, &QAction::triggered, this, &MainWindow::on_actionOpen_directory_triggered);
connect(_ui->actionClose, &QAction::triggered, this, &MainWindow::on_actionClose_triggered);
connect(_ui->actionQuit, &QAction::triggered, this, &MainWindow::on_actionQuit_triggered);
connect(_ui->pushButton_1, &QPushButton::clicked, this, &MainWindow::on_pushButton_1_clicked);
connect(_ui->pushButton_2, &QPushButton::clicked, this, &MainWindow::on_pushButton_2_clicked);
connect(_ui->pushButton_3, &QPushButton::clicked, this, &MainWindow::on_pushButton_3_clicked);
connect(_ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::on_pushButton_4_clicked);

if (size != QSize())
resize(size);

connect(this, &MainWindow::openDir, this, &MainWindow::setTreeViewModel);

statusLabel = new QLabel(this);
statusLabel->setText("None");
statusLabel->setAlignment(Qt::AlignLeft);
statusProgressBar = new QProgressBar(this);
statusProgressBar->setVisible(false);
_statusLabel = new QLabel(this);
_statusLabel->setText("None");
_statusLabel->setAlignment(Qt::AlignLeft);

ui->statusBar->addWidget(statusLabel, 2);
ui->statusBar->addWidget(statusProgressBar, 1);
_ui->statusBar->addWidget(_statusLabel, 2);

ui->treeView->setHeaderHidden(true);
_ui->treeView->setHeaderHidden(true);

// remove close button from Files tab
ui->filesTabWidget->tabBar()->tabButton(0, QTabBar::RightSide)->resize(0,0);

resLabels << ui->resLabel1;
resLabels << ui->resLabel2;
resLabels << ui->resLabel3;
resLabels << ui->resLabel4;
resLabels[0]->setText("Resource name:");
resLabels[1]->setText("Size:");
resLabels[2]->setText("File type:");
resLabels[3]->setText("Resource type:");
_resLabels << _ui->resLabel1;
_resLabels << _ui->resLabel2;
_resLabels << _ui->resLabel3;
_resLabels << _ui->resLabel4;
_resLabels[0]->setText("Resource name:");
_resLabels[1]->setText("Size:");
_resLabels[2]->setText("File type:");
_resLabels[3]->setText("Resource type:");

if (!path.isEmpty())
emit openDir(path);
}

MainWindow::~MainWindow() {
delete ui;
delete _ui;
}

void MainWindow::setTreeViewModel(const QString &path) {
QString cPath = QDir(path).canonicalPath();
fsModel.setRootPath(cPath);

ui->treeView->setModel(&fsModel);

connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::selection);
_treeModel = new ResourceTree(path, _ui->treeView);
_ui->treeView->setModel(_treeModel);

for (int i = 1; i < fsModel.columnCount(); i++)
ui->treeView->hideColumn(i);
connect(_ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::selection);

if (!path.isEmpty()) {
const QModelIndex rootIndex = fsModel.index(QDir::cleanPath(cPath));
if (rootIndex.isValid())
ui->treeView->setRootIndex(rootIndex);
}
_statusLabel->setText(tr("Root: %1").arg(cPath));
_ui->treeView->show();

statusLabel->setText(tr("Root: %1").arg(cPath));
ui->treeView->show();
_ui->actionClose->setEnabled(true);
}

void MainWindow::on_actionOpen_directory_triggered() {
Expand All @@ -122,14 +111,14 @@ void MainWindow::on_actionOpen_directory_triggered() {
}

void MainWindow::on_actionClose_triggered() {
ui->treeView->setModel(nullptr);
_ui->treeView->setModel(nullptr);

resLabels[0]->setText("Resource name:");
resLabels[1]->setText("Size:");
resLabels[2]->setText("File type:");
resLabels[3]->setText("Resource type:");
_resLabels[0]->setText("Resource name:");
_resLabels[1]->setText("Size:");
_resLabels[2]->setText("File type:");
_resLabels[3]->setText("Resource type:");

statusLabel->setText("None");
_statusLabel->setText("None");

clearLabels();
}
Expand Down Expand Up @@ -215,23 +204,23 @@ void MainWindow::setLabels() {
labelResType += getResTypeLabel(resType);
}

resLabels[0]->setText(labelName);
resLabels[1]->setText(labelSize);
resLabels[2]->setText(labelFileType);
resLabels[3]->setText(labelResType);
_resLabels[0]->setText(labelName);
_resLabels[1]->setText(labelSize);
_resLabels[2]->setText(labelFileType);
_resLabels[3]->setText(labelResType);
}


void MainWindow::clearLabels() {
resLabels[0]->setText("Resource name:");
resLabels[1]->setText("Size:");
resLabels[2]->setText("File type:");
resLabels[3]->setText("Resource type:");
_resLabels[0]->setText("Resource name:");
_resLabels[1]->setText("Size:");
_resLabels[2]->setText("File type:");
_resLabels[3]->setText("Resource type:");
}

void MainWindow::selection(const QItemSelection &selected) {
const QModelIndex index = selected.indexes().at(0);
_currentSelection = Selection(fsModel.fileInfo(index));
_currentSelection = Selection(_treeModel->getNode(index)->getFileInfo());
setLabels();
}

Expand Down
11 changes: 6 additions & 5 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace Ui {

namespace GUI {

class ResourceTree;

class MainWindow : public QMainWindow {
W_OBJECT(MainWindow)

Expand Down Expand Up @@ -71,11 +73,10 @@ class MainWindow : public QMainWindow {
void clearLabels();

private:
Ui::MainWindow *ui;
QFileSystemModel fsModel;
QLabel *statusLabel;
QProgressBar *statusProgressBar;
QList<QLabel*> resLabels;
Ui::MainWindow *_ui;
ResourceTree *_treeModel;
QLabel *_statusLabel;
QList<QLabel*> _resLabels;
Selection _currentSelection;
};

Expand Down
4 changes: 2 additions & 2 deletions src/gui/panelpreviewimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void ImageCanvas::loadImage() {
_image.reset();
_bitmap.reset();

if (!_currentItem || (_currentItem->getResourceType() != Aurora::kResourceImage)) {
/* if (!_currentItem || (_currentItem->getResourceType() != Aurora::kResourceImage)) {
SetVirtualSize(0, 0);
SetScrollRate(0, 0);
return;
Expand Down Expand Up @@ -166,7 +166,7 @@ void ImageCanvas::loadImage() {
_bitmap.reset(new wxBitmap(*_image));
SetVirtualSize(width, height);
SetScrollRate(1, 1);
SetScrollRate(1, 1);*/
}

void ImageCanvas::writePixel(const byte *&data, Images::PixelFormat format,
Expand Down
6 changes: 3 additions & 3 deletions src/gui/panelpreviewsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void PanelPreviewSound::setCurrentItem(const ResourceTreeItem *item) {
return;
}

_duration = item->getSoundDuration();
// _duration = item->getSoundDuration();
}

void PanelPreviewSound::setButtons(bool enablePlay, bool enablePause, bool enableStop) {
Expand Down Expand Up @@ -209,7 +209,7 @@ void PanelPreviewSound::setVolume() {
}

bool PanelPreviewSound::play() {
if (!_currentItem || (_currentItem->getResourceType() != Aurora::kResourceSound))
/* if (!_currentItem || (_currentItem->getResourceType() != Aurora::kResourceSound))
return false;
if (SoundMan.isPlaying(_sound)) {
Expand All @@ -232,7 +232,7 @@ bool PanelPreviewSound::play() {
return false;
}
SoundMan.startChannel(_sound);
SoundMan.startChannel(_sound);*/
return true;
}

Expand Down
44 changes: 23 additions & 21 deletions src/gui/panelresourceinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,48 +172,48 @@ void PanelResourceInfo::onExportRaw(wxCommandEvent &UNUSED(event)) {

const Common::UString title = "Save Aurora game resource file";
const Common::UString mask = "Aurora game resource (*.*)|*.*";
const Common::UString def = _currentItem->getName();
// const Common::UString def = _currentItem->getName();

exportRaw(dialogSaveFile(title, mask, def));
// exportRaw(dialogSaveFile(title, mask, def));
}

void PanelResourceInfo::onExportBMUMP3(wxCommandEvent &UNUSED(event)) {
if (!_currentItem)
return;

assert(_currentItem->getFileType() == Aurora::kFileTypeBMU);
// assert(_currentItem->getFileType() == Aurora::kFileTypeBMU);

const Common::UString title = "Save MP3 file";
const Common::UString mask = "MP3 file (*.mp3)|*.mp3";
const Common::UString def = TypeMan.setFileType(_currentItem->getName(), Aurora::kFileTypeMP3);
// const Common::UString def = TypeMan.setFileType(_currentItem->getName(), Aurora::kFileTypeMP3);

exportBMUMP3(dialogSaveFile(title, mask, def));
// exportBMUMP3(dialogSaveFile(title, mask, def));
}

void PanelResourceInfo::onExportWAV(wxCommandEvent &UNUSED(event)) {
if (!_currentItem)
return;

assert(_currentItem->getResourceType() == Aurora::kResourceSound);
// assert(_currentItem->getResourceType() == Aurora::kResourceSound);

const Common::UString title = "Save PCM WAV file";
const Common::UString mask = "WAV file (*.wav)|*.wav";
const Common::UString def = TypeMan.setFileType(_currentItem->getName(), Aurora::kFileTypeWAV);
// const Common::UString def = TypeMan.setFileType(_currentItem->getName(), Aurora::kFileTypeWAV);

exportWAV(dialogSaveFile(title, mask, def));
// exportWAV(dialogSaveFile(title, mask, def));
}

void PanelResourceInfo::onExportTGA(wxCommandEvent &UNUSED(event)) {
if (!_currentItem)
return;

assert(_currentItem->getResourceType() == Aurora::kResourceImage);
// assert(_currentItem->getResourceType() == Aurora::kResourceImage);

const Common::UString title = "Save TGA file";
const Common::UString mask = "TGA file (*.tga)|*.tga";
const Common::UString def = TypeMan.setFileType(_currentItem->getName(), Aurora::kFileTypeTGA);
// const Common::UString def = TypeMan.setFileType(_currentItem->getName(), Aurora::kFileTypeTGA);

exportTGA(dialogSaveFile(title, mask, def));
// exportTGA(dialogSaveFile(title, mask, def));
}

bool PanelResourceInfo::exportRaw(const Common::UString &path) {
Expand All @@ -223,7 +223,7 @@ bool PanelResourceInfo::exportRaw(const Common::UString &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 @@ -236,7 +236,7 @@ bool PanelResourceInfo::exportRaw(const Common::UString &path) {
} catch (Common::Exception &e) {
Common::printException(e, "WARNING: ");
return false;
}
}*/

return true;
}
Expand All @@ -248,7 +248,7 @@ bool PanelResourceInfo::exportBMUMP3(const Common::UString &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 @@ -261,7 +261,7 @@ bool PanelResourceInfo::exportBMUMP3(const Common::UString &path) {
} catch (Common::Exception &e) {
Common::printException(e, "WARNING: ");
return false;
}
}*/

return true;
}
Expand All @@ -273,7 +273,7 @@ bool PanelResourceInfo::exportWAV(const Common::UString &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 @@ -286,7 +286,7 @@ bool PanelResourceInfo::exportWAV(const Common::UString &path) {
} catch (Common::Exception &e) {
Common::printException(e, "WARNING: ");
return false;
}
}*/

return true;
}
Expand All @@ -298,7 +298,7 @@ bool PanelResourceInfo::exportTGA(const Common::UString &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 All @@ -308,7 +308,7 @@ bool PanelResourceInfo::exportTGA(const Common::UString &path) {
} catch (Common::Exception &e) {
Common::printException(e, "WARNING: ");
return false;
}
}*/

return true;
}
Expand Down Expand Up @@ -397,7 +397,7 @@ void PanelResourceInfo::showExportButtons(bool enableRaw, bool showMP3, bool sho
}

void PanelResourceInfo::showExportButtons() {
if (!_currentItem || _currentItem->getSource() == ResourceTreeItem::kSourceDirectory) {
/*if (!_currentItem || _currentItem->getSource() == ResourceTreeItem::kSourceDirectory) {
showExportButtons(false, false, false, false);
return;
}
Expand All @@ -406,10 +406,11 @@ void PanelResourceInfo::showExportButtons() {
bool isSound = _currentItem->getResourceType() == Aurora::kResourceSound;
bool isImage = _currentItem->getResourceType() == Aurora::kResourceImage;
showExportButtons(true, isBMU, isSound, isImage);
showExportButtons(true, isBMU, isSound, isImage);*/
}

void PanelResourceInfo::setLabels() {
/*
Common::UString labelName = "Resource name: ";
Common::UString labelSize = "Size: ";
Common::UString labelFileType = "File type: ";
Expand Down Expand Up @@ -440,6 +441,7 @@ void PanelResourceInfo::setLabels() {
_textSize->SetLabel(labelSize);
_textFileType->SetLabel(labelFileType);
_textResType->SetLabel(labelResType);
*/
}

void PanelResourceInfo::update() {
Expand Down

0 comments on commit eaabcf7

Please sign in to comment.