Skip to content

Commit

Permalink
GUI: Main window code
Browse files Browse the repository at this point in the history
Removes remaining forms code from source and build system, which means no more UIC required.
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent b391368 commit c95e0e1
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 366 deletions.
4 changes: 0 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ AX_CHECK_LZMA(5, 0, 3, 2, , AC_MSG_ERROR([liblzma(>= 5.0.5) is required and coul

dnl Graphic libraries
AX_CHECK_QT5(5.7.1, , AC_MSG_ERROR([Qt5 (>= 5.7.1, modules Core, Gui, Multimedia, Widgets) is required and could not be found!]))
AC_CHECK_PROGS(UIC, [uic-qt5 uic])
if test -z "$UIC"; then
AC_MSG_ERROR([Qt utility program uic is required.])
fi

dnl Sound libraries
AX_CHECK_AL( , AC_MSG_ERROR([OpenAL or OpenAL Soft (>= 1.12) is required and could not be found!]))
Expand Down
2 changes: 1 addition & 1 deletion m4/ax_check_qt5.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dnl @synopsis AX_CHECK_QT5(version, action-if, action-if-not)
dnl
dnl @summary check for Qt5 of sufficient version.
dnl
dnl Defines QT5_LIBS, QT5_CFLAGS, QT5_UIC
dnl Defines QT5_LIBS, QT5_CFLAGS
dnl
dnl @category InstalledPackages
dnl @author Sven Hesse <drmccoy@drmccoy.de>
Expand Down
230 changes: 184 additions & 46 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <QGroupBox>
#include <QFileDialog>
#include <QMessageBox>
#include <QStandardPaths>
Expand Down Expand Up @@ -28,39 +29,165 @@ namespace GUI {
W_OBJECT_IMPL(MainWindow)

MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, const Common::UString &path)
: QMainWindow(parent)
{
_ui.setupUi(this);
: QMainWindow(parent) {
_centralWidget = new QWidget(this);
_centralLayout = new QGridLayout(_centralWidget);

setWindowTitle(title);
resize(size);
_layoutVertical = new QVBoxLayout();

_splitterTopBottom = new QSplitter(_centralWidget);
_splitterLeftRight = new QSplitter(_splitterTopBottom);

_actionOpenDirectory = new QAction(this);
_actionClose = new QAction(this);
_actionQuit = new QAction(this);
_actionAbout = new QAction(this);
_actionOpenFile = new QAction(this);

_menuBar = new QMenuBar(this);
_menuFile = new QMenu(_menuBar);
_menuHelp = new QMenu(_menuBar);

// preview
_panelPreviewEmpty = new PanelPreviewEmpty();
_panelPreviewImage = new PanelPreviewImage();
_panelPreviewSound = new PanelPreviewSound();
_panelPreviewText = new PanelPreviewText();
_resInfo = new PanelResourceInfo();
_panelResourceInfo = new PanelResourceInfo();

_treeView = new QTreeView(_splitterLeftRight);
// 1:8 ratio, 8 being the (res info + preview) wrapper widget
{
QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Preferred);
sp.setHorizontalStretch(1);
_treeView->setSizePolicy(sp);
}

QGroupBox *logBox = new QGroupBox(_splitterTopBottom);
logBox->setTitle(tr("Log"));
_log = new QTextEdit(logBox);
{
QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred);
sp.setVerticalStretch(1);
logBox->setSizePolicy(sp);

QHBoxLayout *hl = new QHBoxLayout(logBox);
hl->addWidget(_log);
hl->setContentsMargins(0, 0, 0, 0);
}

_centralLayout->addWidget(_splitterTopBottom);

// left/right splitter
// 8:1 ratio, 1 being the log box
{
QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Preferred);
sp.setVerticalStretch(5);
_splitterLeftRight->setSizePolicy(sp);
}

_splitterTopBottom->setOrientation(Qt::Vertical);

/*
_______
| |
|_______|
|_______|
*/

_splitterTopBottom->addWidget(_splitterLeftRight);
_splitterTopBottom->addWidget(logBox);

/*
_______
| | |
|_|_____|
|_______|
*/

// can't add a layout directly to a splitter
QWidget *wrapperWidget = new QWidget(_splitterTopBottom);
wrapperWidget->setContentsMargins(0, 0, 0, 0);
{
QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Preferred);
sp.setHorizontalStretch(6);
wrapperWidget->setSizePolicy(sp);
}

_ui.resBox->addWidget(_resInfo);
_ui.resLayout->addWidget(_panelPreviewEmpty);
_splitterLeftRight->addWidget(_treeView);
_splitterLeftRight->addWidget(wrapperWidget);

wrapperWidget->setLayout(_layoutVertical);
_layoutVertical->setParent(wrapperWidget);
_layoutVertical->setMargin(0);

QFrame *resInfoFrame = new QFrame(wrapperWidget);
{
QHBoxLayout *hl = new QHBoxLayout(resInfoFrame);
hl->addWidget(_panelResourceInfo);
}
resInfoFrame->setFrameShape(QFrame::StyledPanel);
resInfoFrame->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
resInfoFrame->setFixedHeight(140);

_resPreviewFrame = new QFrame(wrapperWidget);
{
QHBoxLayout *hl = new QHBoxLayout(_resPreviewFrame);
hl->setMargin(0);
hl->addWidget(_panelPreviewEmpty);
}
_resPreviewFrame->setFrameShape(QFrame::StyledPanel);

_layoutVertical->addWidget(resInfoFrame);
_layoutVertical->addWidget(_resPreviewFrame);

/*
_______
| |-----|
|_|_____|
|_______|
*/

_menuBar->addAction(_menuFile->menuAction());
_menuBar->addAction(_menuHelp->menuAction());
_menuFile->addAction(_actionOpenDirectory);
_menuFile->addAction(_actionOpenFile);
_menuFile->addSeparator();
_menuFile->addAction(_actionClose);
_menuFile->addSeparator();
_menuFile->addAction(_actionQuit);
_menuFile->setTitle("&File");
_menuHelp->addAction(_actionAbout);
_menuHelp->setTitle("&Help");

this->setMenuBar(_menuBar);

_actionOpenDirectory->setText(tr("&Open directory"));
_actionClose->setText(tr("&Close"));
_actionQuit->setText(tr("MainWindow"));
_actionAbout->setText(tr("About"));
_actionOpenFile->setText(tr("&Open file"));

this->setCentralWidget(_centralWidget);

setWindowTitle(title);
resize(size);

// signals/slots
QObject::connect(_ui.actionOpenDirectory, &QAction::triggered, this, &MainWindow::slotOpenDir);
QObject::connect(_ui.actionOpenFile, &QAction::triggered, this, &MainWindow::slotOpenFile);
QObject::connect(_ui.actionClose, &QAction::triggered, this, &MainWindow::slotCloseDir);
QObject::connect(_ui.actionQuit, &QAction::triggered, this, &MainWindow::slotQuit);
QObject::connect(_resInfo, &PanelResourceInfo::loadModel, this, &MainWindow::setTreeViewModel);
QObject::connect(_resInfo, &PanelResourceInfo::log, this, &MainWindow::slotLog);
QObject::connect(_resInfo, &PanelResourceInfo::closeDirClicked, this, &MainWindow::slotCloseDir);
QObject::connect(_resInfo, &PanelResourceInfo::saveClicked, this, &MainWindow::saveItem);
QObject::connect(_resInfo, &PanelResourceInfo::exportTGAClicked, this, &MainWindow::exportTGA);
QObject::connect(_resInfo, &PanelResourceInfo::exportBMUMP3Clicked, this, &MainWindow::exportBMUMP3);
QObject::connect(_resInfo, &PanelResourceInfo::exportWAVClicked, this, &MainWindow::exportWAV);
QObject::connect(_ui.actionAbout, &QAction::triggered, this, &MainWindow::slotAbout);
QObject::connect(_actionOpenDirectory, &QAction::triggered, this, &MainWindow::slotOpenDir);
QObject::connect(_actionOpenFile, &QAction::triggered, this, &MainWindow::slotOpenFile);
QObject::connect(_actionClose, &QAction::triggered, this, &MainWindow::slotCloseDir);
QObject::connect(_actionQuit, &QAction::triggered, this, &MainWindow::slotQuit);
QObject::connect(_panelResourceInfo, &PanelResourceInfo::loadModel, this, &MainWindow::setTreeViewModel);
QObject::connect(_panelResourceInfo, &PanelResourceInfo::log, this, &MainWindow::slotLog);
QObject::connect(_panelResourceInfo, &PanelResourceInfo::closeDirClicked, this, &MainWindow::slotCloseDir);
QObject::connect(_panelResourceInfo, &PanelResourceInfo::saveClicked, this, &MainWindow::saveItem);
QObject::connect(_panelResourceInfo, &PanelResourceInfo::exportTGAClicked, this, &MainWindow::exportTGA);
QObject::connect(_panelResourceInfo, &PanelResourceInfo::exportBMUMP3Clicked, this, &MainWindow::exportBMUMP3);
QObject::connect(_panelResourceInfo, &PanelResourceInfo::exportWAVClicked, this, &MainWindow::exportWAV);
QObject::connect(_actionAbout, &QAction::triggered, this, &MainWindow::slotAbout);
QObject::connect(_panelPreviewText, &PanelPreviewText::log, this, &MainWindow::slotLog);

_ui.actionAbout->setShortcut(QKeySequence(tr("F1")));
_actionAbout->setShortcut(QKeySequence(tr("F1")));

// status bar
_status = std::make_shared<StatusBar>(this->statusBar());
Expand All @@ -69,7 +196,7 @@ MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, co
// open the path given in command line if any
if (path.empty()) {
// nothing is open yet
_ui.actionClose->setEnabled(false);
_actionClose->setEnabled(false);
}
else {
_rootPath = path.toQString();
Expand All @@ -78,10 +205,21 @@ MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, co
}

MainWindow::~MainWindow() {
if (_panelPreviewEmpty)
delete _panelPreviewEmpty;

if (_panelPreviewText)
delete _panelPreviewText;

if (_panelPreviewSound)
delete _panelPreviewSound;

if (_panelPreviewImage)
delete _panelPreviewImage;
}

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

void MainWindow::setTreeViewModel(const QString &path) {
Expand All @@ -95,23 +233,23 @@ void MainWindow::setTreeViewModel(const QString &path) {
} BOOST_SCOPE_EXIT_END

_treeModel.reset();
_ui.treeView->setModel(nullptr);
_treeView->setModel(nullptr);

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

_ui.treeView->resizeColumnToContents(0);
_treeView->resizeColumnToContents(0);


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


_ui.log->append(tr("Set root: %1").arg(path));
_log->append(tr("Set root: %1").arg(path));

_ui.actionClose->setEnabled(true);
_actionClose->setEnabled(true);
}

void MainWindow::slotOpenDir() {
Expand All @@ -131,34 +269,34 @@ void MainWindow::slotOpenFile() {
void MainWindow::slotCloseDir() {
showPreviewPanel(_panelPreviewEmpty);

_resInfo->setButtonsForClosedDir();
_panelResourceInfo->setButtonsForClosedDir();

_ui.treeView->setModel(nullptr);
_treeView->setModel(nullptr);

_ui.log->append(tr("Closed directory: %1").arg(_rootPath));
_log->append(tr("Closed directory: %1").arg(_rootPath));

_rootPath = "";

_currentItem = nullptr;

_resInfo->clearLabels();
_panelResourceInfo->clearLabels();

_ui.actionClose->setEnabled(false);
_actionClose->setEnabled(false);
}

void MainWindow::slotQuit() {
QCoreApplication::quit();
}

void MainWindow::showPreviewPanel(QFrame *panel) {
if (_ui.resLayout->count()) {
QFrame *old = static_cast<QFrame*>(_ui.resLayout->itemAt(0)->widget());
if (_resPreviewFrame->layout()->count()) {
QFrame *old = static_cast<QFrame*>(_resPreviewFrame->layout()->itemAt(0)->widget());
if (old != panel) {
_ui.resLayout->removeWidget(old);
_resPreviewFrame->layout()->removeWidget(old);
old->setParent(0);
if (old == _panelPreviewSound)
_panelPreviewSound->stop();
_ui.resLayout->addWidget(panel);
_resPreviewFrame->layout()->addWidget(panel);
}
}
}
Expand Down Expand Up @@ -187,25 +325,25 @@ void MainWindow::showPreviewPanel() {

default:
showPreviewPanel(_panelPreviewEmpty);
break;
}
break;
}
}
}

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

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

QString constructStatus(const QString &action, const QString &name, const QString &destination) {
return action + " \"" + name + "\" to \"" + destination + "\"...";
QString constructStatus(const QString &_action, const QString &name, const QString &destination) {
return _action + " \"" + name + "\" to \"" + destination + "\"...";
}

void MainWindow::saveItem() {
Expand Down
Loading

0 comments on commit c95e0e1

Please sign in to comment.