Skip to content

Commit

Permalink
bugfixes and added preferences dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Jan 6, 2012
1 parent a88699d commit ec1b509
Show file tree
Hide file tree
Showing 15 changed files with 395 additions and 56 deletions.
12 changes: 9 additions & 3 deletions TuringEditor.pro
Expand Up @@ -223,7 +223,8 @@ HEADERS = \
./QScintilla/src/XPM.h \
TuringEditor/turingeditorwidget.h \
TuringEditor/aboutbox.h \
TuringEditor/turingrunner.h
TuringEditor/turingrunner.h \
TuringEditor/settingsdialog.h

SOURCES = \
./TuringEditor/turinglexer.cpp \
Expand Down Expand Up @@ -395,7 +396,8 @@ SOURCES = \
./QScintilla/src/XPM.cpp \
TuringEditor/turingeditorwidget.cpp \
TuringEditor/aboutbox.cpp \
TuringEditor/turingrunner.cpp
TuringEditor/turingrunner.cpp \
TuringEditor/settingsdialog.cpp

TRANSLATIONS = \
./QScintilla/Qt4/qscintilla_cs.ts \
Expand All @@ -407,7 +409,8 @@ TRANSLATIONS = \

FORMS += \
./TuringEditor/findreplacedialog.ui \
TuringEditor/aboutbox.ui
TuringEditor/aboutbox.ui \
TuringEditor/settingsdialog.ui

CONFIG(test_editor) {
CONFIG += qtestlib
Expand All @@ -423,3 +426,6 @@ CONFIG(test_editor) {






8 changes: 4 additions & 4 deletions TuringEditor/aboutbox.ui
Expand Up @@ -83,10 +83,10 @@
<widget class="QLabel" name="versionLabel">
<property name="geometry">
<rect>
<x>270</x>
<y>290</y>
<width>221</width>
<height>20</height>
<x>240</x>
<y>280</y>
<width>251</width>
<height>31</height>
</rect>
</property>
<property name="font">
Expand Down
2 changes: 1 addition & 1 deletion TuringEditor/findreplacedialog.ui
Expand Up @@ -208,7 +208,7 @@
<x>10</x>
<y>240</y>
<width>361</width>
<height>16</height>
<height>21</height>
</rect>
</property>
<property name="font">
Expand Down
5 changes: 3 additions & 2 deletions TuringEditor/main.cpp
Expand Up @@ -29,8 +29,9 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(turing);
QApplication app(argc, argv);

QFontDatabase fontDB;
fontDB.addApplicationFont(":/GraphicsView/fonts");
QCoreApplication::setOrganizationName("The Open Turing Project");
QCoreApplication::setOrganizationDomain("compsci.ca");
QCoreApplication::setApplicationName("Open Turing Editor");

MainWindow mainWin;
mainWin.show();
Expand Down
52 changes: 23 additions & 29 deletions TuringEditor/mainwindow.cpp
Expand Up @@ -33,6 +33,7 @@
#include "turinglexer.h"
#include "findreplacedialog.h"
#include "aboutbox.h"
#include "settingsdialog.h"

#include "turingrunner.h"

Expand All @@ -57,21 +58,22 @@ MainWindow::MainWindow()
createToolBars();
createStatusBar();

readSettings();

connect(textEdit, SIGNAL(textChanged()),
this, SLOT(documentWasModified()));

setCurrentFile("");

currentRunner = NULL;

readSettings();
}

QSize MainWindow::sizeHint() const {
return QSize(660,630);
}

void MainWindow::runProgram() {
if (saveOnRun) save();
if(currentRunner != NULL) {
statusBar()->showMessage(tr("Already running a program."));
return;
Expand Down Expand Up @@ -128,7 +130,6 @@ void MainWindow::completeStruct() {
void MainWindow::closeEvent(QCloseEvent *event)
{
if (maybeSave()) {
writeSettings();
event->accept();
} else {
event->ignore();
Expand Down Expand Up @@ -192,6 +193,14 @@ void MainWindow::showHelp()
QDesktopServices::openUrl(QString("file:///") + HELP_FILE_PATH);
}

void MainWindow::showSettings()
{
SettingsDialog settings;
if(settings.exec()) {
readSettings();
}
}

void MainWindow::documentWasModified()
{
setWindowModified(textEdit->isModified());
Expand All @@ -200,6 +209,10 @@ void MainWindow::documentWasModified()
void MainWindow::createActions()
{

settingsAct = new QAction(tr("&Preferences"), this);
settingsAct->setStatusTip(tr("Change settings/preferences."));
connect(settingsAct, SIGNAL(triggered()), this, SLOT(showSettings()));

helpAct = new QAction(QIcon(":/images/help.png"),tr("Turing &Help"), this);
helpAct->setShortcut(Qt::Key_F10);
helpAct->setStatusTip(tr("Open Turing help."));
Expand All @@ -221,14 +234,6 @@ void MainWindow::createActions()
autoCompleteAct->setStatusTip(tr("Insert an ending for a structure."));
connect(autoCompleteAct, SIGNAL(triggered()), textEdit, SLOT(autoCompleteFromAll()));

lightThemeAct = new QAction(tr("&Light theme"), this);
lightThemeAct->setStatusTip(tr("Change to a light theme."));
connect(lightThemeAct, SIGNAL(triggered()), textEdit, SLOT(lightTheme()));

darkThemeAct = new QAction(tr("&Dark theme"), this);
darkThemeAct->setStatusTip(tr("Change to a dark theme."));
connect(darkThemeAct, SIGNAL(triggered()), textEdit, SLOT(darkTheme()));

findAct = new QAction(QIcon(":/images/magnifier.png"),tr("&Find"), this);
findAct->setShortcut(tr("Ctrl+F"));
findAct->setStatusTip(tr("Find text in file."));
Expand Down Expand Up @@ -306,6 +311,7 @@ void MainWindow::createMenus()
fileMenu->addAction(saveAsAct);
fileMenu->addAction(runAct);
fileMenu->addSeparator();
fileMenu->addAction(settingsAct);
fileMenu->addAction(exitAct);

editMenu = menuBar()->addMenu(tr("&Edit"));
Expand All @@ -318,9 +324,6 @@ void MainWindow::createMenus()

viewMenu = menuBar()->addMenu(tr("&View"));
viewMenu->addAction(clearAct);
viewMenu->addSeparator();
viewMenu->addAction(lightThemeAct);
viewMenu->addAction(darkThemeAct);

menuBar()->addSeparator();

Expand Down Expand Up @@ -358,26 +361,17 @@ void MainWindow::createStatusBar()

void MainWindow::readSettings()
{
QSettings settings("The Open Turing Project", "Open Turing Editor");
QString theme = settings.value("theme", "Default").toString();
qDebug() << "Loading settings. Theme: " << theme;
if(theme == "Dark") {
textEdit->darkTheme();
} else {
textEdit->lightTheme();
}
}
QSettings settings;

void MainWindow::writeSettings()
{
qDebug() << "Saving settings. Theme: " << textEdit->lex->getTheme();
QSettings settings("The Open Turing Project", "Open Turing Editor");
settings.setValue("theme", textEdit->lex->getTheme());
saveOnRun = settings.value("saveOnRun",true).toBool();
confirmSave = settings.value("confirmSave",true).toBool();

textEdit->readSettings();
}

bool MainWindow::maybeSave()
{
if (textEdit->isModified()) {
if (textEdit->isModified() && confirmSave) {
int ret = QMessageBox::warning(this, tr("Open Turing Editor"),
tr("The document has been modified.\n"
"Do you want to save your changes?"),
Expand Down
14 changes: 9 additions & 5 deletions TuringEditor/mainwindow.h
Expand Up @@ -47,6 +47,9 @@ class MainWindow : public QMainWindow

friend class TestEditor;

public slots:
void readSettings();

protected:
void closeEvent(QCloseEvent *event);

Expand All @@ -59,6 +62,7 @@ private slots:
void documentWasModified();
void completeStruct();
void showHelp();
void showSettings();

void runProgram();
void compileComplete(bool success);
Expand All @@ -71,14 +75,16 @@ private slots:
void createMenus();
void createToolBars();
void createStatusBar();
void readSettings();
void writeSettings();
bool maybeSave();

bool saveFile(const QString &fileName);
void setCurrentFile(const QString &fileName);
QString strippedName(const QString &fullFileName);

// prefs
bool saveOnRun;
bool confirmSave;

TuringEditorWidget *textEdit;
QString curFile;

Expand All @@ -95,9 +101,6 @@ private slots:
//! completion
QAction *structCompleteAct;
QAction *autoCompleteAct;
//! theme switch
QAction *darkThemeAct;
QAction *lightThemeAct;
//! find and replace
QAction *findAct;
//! file actions
Expand All @@ -115,6 +118,7 @@ private slots:
QAction *runAct;
QAction *clearAct;
QAction *helpAct;
QAction *settingsAct;
};

#endif
52 changes: 52 additions & 0 deletions TuringEditor/settingsdialog.cpp
@@ -0,0 +1,52 @@
#include "settingsdialog.h"
#include "ui_settingsdialog.h"

#include <QSettings>

SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog)
{
ui->setupUi(this);

// populate themese
ui->theme->addItem("Default");
ui->theme->addItem("Dark");

// load settings
QSettings settings;

QString theme = settings.value("theme", "Default").toString();
ui->theme->setCurrentIndex(theme == "Default" ? 0 : 1);
// ints
ui->fontSize->setValue(settings.value("fontSize", 10).toInt());
ui->indentSize->setValue(settings.value("indentSize", 4).toInt());
ui->autoCompThresh->setValue(settings.value("autoCompleteThreshold", 5).toInt());
// bools
ui->autoComp->setChecked(settings.value("autoCompleteEnabled", true).toBool());
ui->saveOnRun->setChecked(settings.value("saveOnRun", true).toBool());
ui->confirmSave->setChecked(settings.value("confirmSave", true).toBool());
ui->stringEOLHighlight->setChecked(settings.value("stringEOLHighlight", false).toBool());
}

void SettingsDialog::accept() {
QSettings settings;

settings.setValue("theme",ui->theme->currentText());
// ints
settings.setValue("fontSize",ui->fontSize->value());
settings.setValue("indentSize",ui->indentSize->value());
settings.setValue("autoCompleteThreshold",ui->autoCompThresh->value());
// bools
settings.setValue("autoCompleteEnabled",(ui->autoComp->checkState() == Qt::Checked));
settings.setValue("saveOnRun",(ui->saveOnRun->checkState() == Qt::Checked));
settings.setValue("confirmSave",(ui->confirmSave->checkState() == Qt::Checked));
settings.setValue("stringEOLHighlight",(ui->stringEOLHighlight->checkState() == Qt::Checked));

done(QDialog::Accepted);
}

SettingsDialog::~SettingsDialog()
{
delete ui;
}
24 changes: 24 additions & 0 deletions TuringEditor/settingsdialog.h
@@ -0,0 +1,24 @@
#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H

#include <QDialog>

namespace Ui {
class SettingsDialog;
}

class SettingsDialog : public QDialog
{
Q_OBJECT

public:
explicit SettingsDialog(QWidget *parent = 0);
~SettingsDialog();

virtual void accept();

private:
Ui::SettingsDialog *ui;
};

#endif // SETTINGSDIALOG_H

0 comments on commit ec1b509

Please sign in to comment.