Skip to content

Commit

Permalink
Add help dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bvschaik committed Jan 12, 2020
1 parent ce15551 commit 5609988
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 3 deletions.
77 changes: 77 additions & 0 deletions sgreader/helpdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Citybuilding Mappers - create minimaps from citybuilding game files
* Copyright (C) 2007, 2008 Bianca van Schaik
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "helpdialog.h"

#include <QTextEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFont>

HelpDialog::HelpDialog(QWidget *parent, const QString &appname)
: QDialog(parent) {

this->appname = appname;

setWindowTitle(appname + tr(" Help"));

// Create textedit
QTextEdit *textEdit = new QTextEdit();
textEdit->setReadOnly(true);
textEdit->setWordWrapMode(QTextOption::WordWrap);
textEdit->setPlainText(getHelpText());
textEdit->setMinimumSize(480, 300);

// Create ok button
QPushButton *okButton = new QPushButton(tr("OK"), this);
okButton->setDefault(true);
connect(okButton, SIGNAL(clicked()), this, SLOT(close()));

QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->addStretch();
buttonLayout->addWidget(okButton);
buttonLayout->addStretch();

QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(textEdit);
layout->addLayout(buttonLayout);

setLayout(layout);
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}

QString HelpDialog::getHelpText() {
QString text = tr(
"This program can open the .sg2 and .sg3 files that were used in "
"the citybuilding games from Impressions Games.\n\n"
"Loading a single SG file:\n"
"Open a .sg2/.sg3 file and a tree of images will appear to the left. "
"Click any image to show it on the right. Use the File menu to save the "
"image as PNG.\n\n"
"Batch-extraction:\n"
"To extract all images in one go, use File -> Batch Extract. "
"Select a directory where SG files are stored, select a destination, "
"and all images will be extracted.\n\n"
"SG files contain multiple images, usually thousands. The SG file itself acts as a "
"dictionary for all the images, the actual pixels are stored in "
"the .555 files that are also present in the games.\n\n");

return text;
}
40 changes: 40 additions & 0 deletions sgreader/helpdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Citybuilding Mappers - create minimaps from citybuilding game files
* Copyright (C) 2007, 2008 Bianca van Schaik
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef HELPDIALOG_H
#define HELPDIALOG_H

#include <QDialog>
#include <QString>

class HelpDialog : public QDialog {
public:
/**
* Constructor, constructs a new help dialog
* @param parent Parent widget
* @param appname Name of the application, used in the title bar
*/
HelpDialog(QWidget *parent, const QString & appname);

private:
QString getHelpText();

QString appname;
};

#endif /* HELPDIALOG_H */
9 changes: 7 additions & 2 deletions sgreader/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "imagetreeitem.h"
#include "aboutdialog.h"
#include "helpdialog.h"
#include "licencedialog.h"
#include "gui/extractwizard.h"

Expand Down Expand Up @@ -59,6 +60,11 @@ void MainWindow::licence() {
dialog.exec();
}

void MainWindow::help() {
HelpDialog dialog(this, appname);
dialog.exec();
}

void MainWindow::about() {
AboutDialog dialog(this, appname, QString("1.1 (2019-01-12)"),
tr("Copyright (C) 2007-2020 Bianca van Schaik &lt;[email protected]&gt;"),
Expand Down Expand Up @@ -112,8 +118,7 @@ void MainWindow::loadFile(const QString &filename) {
// Just have a long list of images
int numImages = sgFile->totalImageCount();
for (int i = 0; i < numImages; i++) {
QTreeWidgetItem *item = new ImageTreeItem(treeWidget, i,
sgFile->image(i));
new ImageTreeItem(treeWidget, i, sgFile->image(i));
}
} else {
// Split up by file
Expand Down
2 changes: 1 addition & 1 deletion sgreader/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MainWindow : public QMainWindow {
void saveFile();
void extractAll();
void treeSelectionChanged();
//void help();
void help();
void licence();
void about();

Expand Down
2 changes: 2 additions & 0 deletions sgreader/sgreader.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RCC_DIR = build/rcc
HEADERS += aboutdialog.h \
imagetreeitem.h \
licencedialog.h \
helpdialog.h \
mainwindow.h \
sgbitmap.h \
sgfile.h \
Expand All @@ -23,6 +24,7 @@ HEADERS += aboutdialog.h \
SOURCES += aboutdialog.cpp \
imagetreeitem.cpp \
licencedialog.cpp \
helpdialog.cpp \
main.cpp \
mainwindow.cpp \
sgbitmap.cpp \
Expand Down

0 comments on commit 5609988

Please sign in to comment.