Skip to content

Commit

Permalink
GUI: Updates:
Browse files Browse the repository at this point in the history
- Add some const.
- Implement image zoom functions.
- Some refactoring.
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent e7e60ad commit 16daf6b
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 249 deletions.
35 changes: 21 additions & 14 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
#include "src/common/strutil.h"
#include "src/common/writefile.h"
#include "src/gui/mainwindow.h"
#include "src/gui/panelpreviewempty.h"
#include "src/gui/panelpreviewimage.h"
#include "src/gui/panelpreviewsound.h"
#include "src/gui/panelpreviewtext.h"
#include "src/gui/resourceinfopanel.h"
#include "src/gui/resourcetree.h"
#include "src/gui/resourcetreeitem.h"
#include "src/images/dumptga.h"
#include "src/sound/sound.h"
#include "src/sound/audiostream.h"
Expand Down Expand Up @@ -69,14 +76,13 @@ MainWindow::MainWindow(QWidget *parent, const char *version, const QSize &size,
}

MainWindow::~MainWindow() {
// delete _status;
}

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

void MainWindow::setTreeViewModel(QString path) {
void MainWindow::setTreeViewModel(const QString &path) {
if (_rootPath == path)
return;
_rootPath = path;
Expand All @@ -89,15 +95,16 @@ void MainWindow::setTreeViewModel(QString path) {
_treeModel.reset();
_ui.treeView->setModel(nullptr);

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

_ui.treeView->resizeColumnToContents(0);


QObject::connect(_ui.treeView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &MainWindow::selection);
this, &MainWindow::resourceSelect);


_ui.log->append(tr("Set root: %1").arg(path));
Expand Down Expand Up @@ -185,9 +192,9 @@ void MainWindow::showPreviewPanel() {
}
}

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

Expand All @@ -211,7 +218,7 @@ void MainWindow::saveItem() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Saving", _currentItem->getName(), fileName));
_status->push(constructStatus("Saving", _currentItem->getData(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand Down Expand Up @@ -242,7 +249,7 @@ void MainWindow::exportTGA() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Exporting", _currentItem->getName(), fileName));
_status->push(constructStatus("Exporting", _currentItem->getData(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand Down Expand Up @@ -277,7 +284,7 @@ void MainWindow::exportBMUMP3() {

const QString title = "Save MP3 file";
const QString mask = "MP3 file (*.mp3)|*.mp3";
const QString def = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeMP3).toQString();
const QString def = TypeMan.setFileType(USTR(_currentItem->getData()), Aurora::kFileTypeMP3).toQString();

QString fileName = QFileDialog::getSaveFileName(this,
title, def,
Expand All @@ -286,7 +293,7 @@ void MainWindow::exportBMUMP3() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Exporting", _currentItem->getName(), fileName));
_status->push(constructStatus("Exporting", _currentItem->getData(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand Down Expand Up @@ -388,7 +395,7 @@ void MainWindow::exportWAV() {

const QString title = "Save PCM WAV file";
const QString mask = "WAV file (*.wav)|*.wav";
const QString def = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeWAV).toQString();
const QString def = TypeMan.setFileType(USTR(_currentItem->getData()), Aurora::kFileTypeWAV).toQString();

QString fileName = QFileDialog::getSaveFileName(this,
title, def,
Expand All @@ -397,7 +404,7 @@ void MainWindow::exportWAV() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Exporting", _currentItem->getName(), fileName));
_status->push(constructStatus("Exporting", _currentItem->getData(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand All @@ -423,7 +430,7 @@ void MainWindow::slotAbout() {
QMessageBox::about(this, "About", msg);
}

std::shared_ptr<StatusBar> MainWindow::getStatusBar() {
std::shared_ptr<StatusBar> MainWindow::status() {
return _status;
}

Expand Down
50 changes: 16 additions & 34 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define MAINWINDOW_H

#include <memory>

#include <QMainWindow>
#include <QFileSystemModel>
#include <QGraphicsView>
Expand All @@ -13,15 +12,11 @@

#include "verdigris/wobjectdefs.h"

#include "src/common/readstream.h"
#include "src/common/ustring.h"
#include "src/gui/panelpreviewempty.h"
#include "src/gui/panelpreviewimage.h"
#include "src/gui/panelpreviewsound.h"
#include "src/gui/panelpreviewtext.h"
#include "src/gui/panelresourceinfo.h"
#include "src/common/writestream.h"
#include "src/gui/statusbar.h"
#include "src/gui/resourcetree.h"
#include "src/gui/resourcetreeitem.h"
#include "src/sound/sound.h"

#include "ui/ui_mainwindow.h"

Expand All @@ -31,49 +26,36 @@ namespace Ui {

namespace GUI {

class PanelPreviewEmpty;
class PanelPreviewImage;
class PanelPreviewSound;
class PanelPreviewText;
class ResourceInfoPanel;
class ResourceTreeItem;
class ResourceTree;

class MainWindow : public QMainWindow {
W_OBJECT(MainWindow)

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

private /*slots*/:
void setTreeViewModel(QString path);
W_SLOT(setTreeViewModel)
std::shared_ptr<StatusBar> status();

private /*slots*/:
void setTreeViewModel(const QString &path);
void slotOpenDir();
W_SLOT(slotOpenDir, W_Access::Private)

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

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

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

void slotLogAppend(QString text);
W_SLOT(slotLogAppend, W_Access::Private)

void slotLogAppend(const QString &text);
void saveItem();
W_SLOT(saveItem, W_Access::Private)

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

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

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

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

std::shared_ptr<StatusBar> getStatusBar();
void selection(const QItemSelection &selected, const QItemSelection &deselected);
void resourceSelect(const QItemSelection &selected, const QItemSelection &deselected);

private:
void setLabels();
Expand Down
8 changes: 6 additions & 2 deletions src/gui/panelpreviewempty.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "panelpreviewempty.h"

#include "verdigris/wobjectimpl.h"

#include "src/gui/panelpreviewempty.h"

namespace GUI {

W_OBJECT_IMPL(PanelPreviewEmpty)

PanelPreviewEmpty::PanelPreviewEmpty(QWidget *parent)
{
_ui.setupUi(this);
}

} // End of namespace GUI
12 changes: 8 additions & 4 deletions src/gui/panelpreviewempty.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#ifndef PANELPREVIEWEMPTY_H
#define PANELPREVIEWEMPTY_H

#include "ui/ui_previewempty.h"

#include "verdigris/wobjectdefs.h"

#include <QFrame>
#include <QHBoxLayout>
#include <QSpacerItem>
#include <QWidget>

#include "verdigris/wobjectdefs.h"

#include "ui/ui_previewempty.h"

namespace GUI {

class PanelPreviewEmpty : public QFrame
{
W_OBJECT(PanelPreviewEmpty)
Expand All @@ -21,4 +23,6 @@ class PanelPreviewEmpty : public QFrame
PanelPreviewEmpty(QWidget *parent = 0);
};

} // End of namespace GUI

#endif // PANELPREVIEWEMPTY_H

0 comments on commit 16daf6b

Please sign in to comment.