Skip to content

Commit

Permalink
GUI: Add about dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent d08040c commit fd1ec32
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 129 deletions.
50 changes: 25 additions & 25 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QMessageBox>
#include <QStandardPaths>

#include "src/cline.h"
#include "src/aurora/util.h"
#include "src/common/filepath.h"
#include "src/common/strutil.h"
Expand Down Expand Up @@ -41,6 +42,7 @@ MainWindow::MainWindow(QWidget *parent, const char *version, const QSize &size,
QObject::connect(_resInfo, &ResourceInfoPanel::closeDirClicked, this, &MainWindow::slotCloseDir);
QObject::connect(_resInfo, &ResourceInfoPanel::saveClicked, this, &MainWindow::saveItem);
QObject::connect(_resInfo, &ResourceInfoPanel::exportTGAClicked, this, &MainWindow::exportTGA);
QObject::connect(_ui.actionAbout, &QAction::triggered, this, &MainWindow::slotAbout);

// status bar
_statusLabel = new QLabel(this);
Expand All @@ -63,30 +65,23 @@ MainWindow::MainWindow(QWidget *parent, const char *version, const QSize &size,
}
}

MainWindow::~MainWindow() {
delete _treeModel;
}

void MainWindow::slotLogAppend(const QString& text) {
_ui.log->append(text);
}

void MainWindow::setTreeViewModel(const QString &path) {
if (_rootPath == path)
return;

_rootPath = path;

_statusLabel->setText("Loading...");
_statusLabel->repaint();

if (_treeModel) {
delete _treeModel;
_ui.treeView->setModel(nullptr);
}
_treeModel.reset();
_ui.treeView->setModel(nullptr);

_treeModel = new ResourceTree(path, _ui.treeView);
_ui.treeView->setModel(_treeModel);
_treeModel = std::make_unique<ResourceTree>(path, _ui.treeView);
_ui.treeView->setModel(_treeModel.get());
_ui.treeView->show();

_statusLabel->setText(tr("Root: %1").arg(path));
Expand Down Expand Up @@ -122,8 +117,7 @@ void MainWindow::slotCloseDir() {

_rootPath = "";

if (_currentSelection)
_currentSelection = nullptr;
_currentItem = nullptr;

_resInfo->clearLabels();

Expand All @@ -150,7 +144,7 @@ void MainWindow::showPreviewPanel(QFrame *panel) {
}

void MainWindow::showPreviewPanel() {
switch (_currentSelection->getResourceType()) {
switch (_currentItem->getResourceType()) {
case Aurora::kResourceImage:
showPreviewPanel(_panelPreviewImage);
break;
Expand All @@ -161,7 +155,7 @@ void MainWindow::showPreviewPanel() {

default:
{
switch (_currentSelection->getFileType()) {
switch (_currentItem->getFileType()) {
case Aurora::FileType::kFileTypeICO:
showPreviewPanel(_panelPreviewImage);
break;
Expand All @@ -181,17 +175,17 @@ void MainWindow::showPreviewPanel() {

void MainWindow::selection(const QItemSelection &selected, const QItemSelection &deselected) {
const QModelIndex index = selected.indexes().at(0);
_currentSelection = _treeModel->getNode(index);
_resInfo->update(_currentSelection);
_currentItem = _treeModel->getNode(index);
_resInfo->update(_currentItem);
showPreviewPanel();

_panelPreviewImage->setItem(_currentSelection);
_panelPreviewText->setItem(_currentSelection);
_panelPreviewSound->setItem(_currentSelection);
_panelPreviewImage->setItem(_currentItem);
_panelPreviewText->setItem(_currentItem);
_panelPreviewSound->setItem(_currentItem);
}

void MainWindow::saveItem() {
if (!_currentSelection)
if (!_currentItem)
return;

QString fileName = QFileDialog::getSaveFileName(this,
Expand All @@ -202,7 +196,7 @@ void MainWindow::saveItem() {
return;

try {
QScopedPointer<Common::SeekableReadStream> res(_currentSelection->getResourceData());
QScopedPointer<Common::SeekableReadStream> res(_currentItem->getResourceData());

Common::WriteFile file(Common::UString(fileName.toStdString().c_str()));

Expand All @@ -215,10 +209,10 @@ void MainWindow::saveItem() {
}

void MainWindow::exportTGA() {
if (!_currentSelection)
if (!_currentItem)
return;

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

QString fileName = QFileDialog::getSaveFileName(this,
tr("Save TGA file"), "",
Expand All @@ -228,7 +222,7 @@ void MainWindow::exportTGA() {
return;

try {
QScopedPointer<Images::Decoder> image(_currentSelection->getImage());
QScopedPointer<Images::Decoder> image(_currentItem->getImage());

image->dumpTGA(Common::UString(fileName.toStdString().c_str()));

Expand All @@ -237,4 +231,10 @@ void MainWindow::exportTGA() {
}
}

void MainWindow::slotAbout() {
QString msg = createVersionText().toQString();

QMessageBox::about(this, "About", msg);
}

} // namespace GUI
12 changes: 8 additions & 4 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "verdigris/wobjectdefs.h"
#include <memory>

#include <QMainWindow>
#include <QFileSystemModel>
Expand All @@ -11,6 +11,8 @@
#include <QItemSelection>
#include <QPlainTextEdit>

#include "verdigris/wobjectdefs.h"

#include "src/common/ustring.h"
#include "src/gui/panelpreviewempty.h"
#include "src/gui/panelpreviewimage.h"
Expand All @@ -33,7 +35,6 @@ class MainWindow : public QMainWindow {

public:
MainWindow(QWidget *parent = 0, const char *version = "", const QSize &size = QSize(800, 600), const Common::UString &path = "");
~MainWindow();

private /*slots*/:
void setTreeViewModel(const QString &path);
Expand All @@ -57,6 +58,9 @@ private /*slots*/:
void exportTGA();
W_SLOT(exportTGA, W_Access::Private)

void slotAbout();
W_SLOT(slotAbout, W_Access::Private)

void selection(const QItemSelection &selected, const QItemSelection &deselected);

private:
Expand All @@ -68,8 +72,8 @@ private /*slots*/:

Ui::MainWindow _ui;
QLabel *_statusLabel;
ResourceTreeItem *_currentSelection;
ResourceTree *_treeModel;
const ResourceTreeItem *_currentItem;
std::unique_ptr<ResourceTree> _treeModel;
QString _rootPath;

// resource preview
Expand Down
2 changes: 1 addition & 1 deletion src/gui/panelpreviewimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PanelPreviewImage::PanelPreviewImage(QWidget *parent)
_ui.fitShrinkWidth->setEnabled(false);
}

void PanelPreviewImage::setItem(ResourceTreeItem *item) {
void PanelPreviewImage::setItem(const ResourceTreeItem *item) {
_scaleFactor = 1.0;
_originalPixmap = QPixmap();
_imageLabel->setPixmap(_originalPixmap);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/panelpreviewimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PanelPreviewImage : public QFrame
W_OBJECT(PanelPreviewImage)

private:
ResourceTreeItem *_currentItem;
const ResourceTreeItem *_currentItem;
uint8 _color;
QLabel *_imageLabel;
QPixmap _originalPixmap;
Expand All @@ -28,7 +28,7 @@ class PanelPreviewImage : public QFrame
public:
PanelPreviewImage(QWidget *parent = 0);

void setItem(ResourceTreeItem *node);
void setItem(const ResourceTreeItem *node);
void loadImage();
void convertImage(const Images::Decoder &image, byte *data, QImage::Format &format);
void writePixel(const byte *&data, Images::PixelFormat format, byte *&data_out, QImage::Format &format_out);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/panelpreviewsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PanelPreviewSound::PanelPreviewSound(QWidget *parent)
_timer->start(50);
}

void PanelPreviewSound::setItem(ResourceTreeItem *item) {
void PanelPreviewSound::setItem(const ResourceTreeItem *item) {
if (item == _currentItem)
return;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/panelpreviewsound.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PanelPreviewSound : public QFrame
W_OBJECT(PanelPreviewSound)

private:
ResourceTreeItem *_currentItem = nullptr;
const ResourceTreeItem *_currentItem;

Sound::ChannelHandle _sound;
uint64 _duration;
Expand All @@ -33,7 +33,7 @@ class PanelPreviewSound : public QFrame
public:
PanelPreviewSound(QWidget *parent = 0);

void setItem(ResourceTreeItem *node);
void setItem(const ResourceTreeItem *node);

bool play();
W_SLOT(play, W_Access::Private);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/panelpreviewtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void PanelPreviewText::setText(QString text)
_ui.textEdit->setText(text);
}

void PanelPreviewText::setItem(ResourceTreeItem *item) {
void PanelPreviewText::setItem(const ResourceTreeItem *item) {
if (item == _currentItem)
return;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/panelpreviewtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class PanelPreviewText : public QFrame
W_OBJECT(PanelPreviewText)

private:
ResourceTreeItem *_currentItem;
const ResourceTreeItem *_currentItem;
Ui::PreviewText _ui;

public:
PanelPreviewText(QWidget *parent = 0);

void setText(QString text);
void setItem(ResourceTreeItem *node);
void setItem(const ResourceTreeItem *node);
};

#endif // PANELPREVIEWTEXT_H
6 changes: 3 additions & 3 deletions src/gui/panelresourceinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void ResourceInfoPanel::slotExportTGA() {
emit exportTGAClicked();
}

void ResourceInfoPanel::update(ResourceTreeItem *item) {
void ResourceInfoPanel::update(const ResourceTreeItem *item) {
setLabels(item);
showExportButtons(item);
}

void ResourceInfoPanel::showExportButtons(ResourceTreeItem *item) {
void ResourceInfoPanel::showExportButtons(const ResourceTreeItem *item) {
if (!item || item->getSource() == ResourceTreeItem::Source::kSourceDirectory) {
showExportButtons(false, false, false, false);
return;
Expand Down Expand Up @@ -113,7 +113,7 @@ const QString getResTypeLabel(Aurora::ResourceType type) {
return label;
}

void ResourceInfoPanel::setLabels(ResourceTreeItem *item) {
void ResourceInfoPanel::setLabels(const ResourceTreeItem *item) {
QString labelName = "Resource name: ";
QString labelSize = "Size: ";
QString labelFileType = "File type: ";
Expand Down
8 changes: 4 additions & 4 deletions src/gui/panelresourceinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define RESOURCEINFOPANEL_H

#include <QWidget>
#include "src/gui/resourcetreeitem.h"
#include "verdigris/wobjectdefs.h"
#include "src/gui/resourcetreeitem.h"
#include "ui/ui_resourceinfopanel.h"

class ResourceInfoPanel : public QFrame
Expand All @@ -14,10 +14,10 @@ class ResourceInfoPanel : public QFrame
ResourceInfoPanel(QWidget *parent = 0);

Ui::ResourceInfoPanel &getUi();
void showExportButtons(ResourceTreeItem *item);
void showExportButtons(const ResourceTreeItem *item);
void showExportButtons(bool enableRaw, bool showMP3, bool showWAV, bool showTGA);
void setLabels(ResourceTreeItem *item);
void update(ResourceTreeItem *item);
void setLabels(const ResourceTreeItem *item);
void update(const ResourceTreeItem *item);
void clearLabels();
void setButtonsForClosedDir();

Expand Down
12 changes: 6 additions & 6 deletions src/gui/resourcetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int ResourceTree::columnCount(const QModelIndex &parent) const {
}

QModelIndex ResourceTree::parent(const QModelIndex &index) const {
ResourceTreeItem *parent = getNode(index)->parent();
ResourceTreeItem *parent = getNode(index)->getParent();
if (parent == _root)
return QModelIndex();

Expand Down Expand Up @@ -237,7 +237,7 @@ void ResourceTree::insertNodes(int position, QList<ResourceTreeItem*> &nodes, co
}

Aurora::Archive *ResourceTree::getArchive(const QString &path) {
ArchiveMap::iterator a = _archives.find(path.toStdString().c_str());
ArchiveMap::iterator a = _archives.find(path);
if (a != _archives.end())
return a->second;

Expand Down Expand Up @@ -277,14 +277,14 @@ Aurora::Archive *ResourceTree::getArchive(const QString &path) {

#define USTR(x) (Common::UString((x).toStdString()))

Aurora::KEYDataFile *ResourceTree::getKEYDataFile(const Common::UString &file) {
Aurora::KEYDataFile *ResourceTree::getKEYDataFile(const QString &file) {
KEYDataFileMap::iterator d = _keyDataFiles.find(file);
if (d != _keyDataFiles.end())
return d->second;

Common::UString path = Common::FilePath::normalize(USTR(_root->getPath() + "/" + file.toQString()));
Common::UString path = Common::FilePath::normalize(USTR(_root->getPath() + "/" + file));
if (path.empty())
throw Common::Exception("No such file or directory \"%s\"", (_root->getPath() + "/" + file.toQString()));
throw Common::Exception("No such file or directory \"%s\"", (_root->getPath() + "/" + file));

Aurora::FileType type = TypeMan.getFileType(file);

Expand Down Expand Up @@ -313,7 +313,7 @@ void ResourceTree::loadKEYDataFiles(Aurora::KEYFile &key) {

//GetStatusBar()->PushStatusText(Common::UString("Loading data file") + dataFiles[i] + "..."); // fixme

Aurora::KEYDataFile *dataFile = getKEYDataFile(dataFiles[i]);
Aurora::KEYDataFile *dataFile = getKEYDataFile(dataFiles[i].toQString());
key.addDataFile(i, dataFile);

//GetStatusBar()->PopStatusText(); // fixme
Expand Down

0 comments on commit fd1ec32

Please sign in to comment.