Commits

jsvcycling committed 0b94632

Initial commit.

  • Participants

Comments (0)

Files changed (5)

ProgrammingProj.pro

+#-------------------------------------------------
+#
+# Project created by QtCreator 2013-08-10T18:01:55
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = ProgrammingProj
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+        mainwindow.cpp
+
+HEADERS  += mainwindow.h

ProgrammingProj.pro.user

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE QtCreatorProject>
+<!-- Written by QtCreator 2.8.1, 2013-09-20T13:44:58. -->
+<qtcreator>
+ <data>
+  <variable>ProjectExplorer.Project.ActiveTarget</variable>
+  <value type="int">0</value>
+ </data>
+ <data>
+  <variable>ProjectExplorer.Project.EditorSettings</variable>
+  <valuemap type="QVariantMap">
+   <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
+   <value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
+   <value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
+   <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
+    <value type="QString" key="language">Cpp</value>
+    <valuemap type="QVariantMap" key="value">
+     <value type="QString" key="CurrentPreferences">CppGlobal</value>
+    </valuemap>
+   </valuemap>
+   <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
+    <value type="QString" key="language">QmlJS</value>
+    <valuemap type="QVariantMap" key="value">
+     <value type="QString" key="CurrentPreferences">QmlJSGlobal</value>
+    </valuemap>
+   </valuemap>
+   <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
+   <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
+   <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
+   <value type="int" key="EditorConfiguration.IndentSize">4</value>
+   <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
+   <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
+   <value type="int" key="EditorConfiguration.PaddingMode">1</value>
+   <value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
+   <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
+   <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
+   <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
+   <value type="int" key="EditorConfiguration.TabSize">8</value>
+   <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
+   <value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
+   <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
+   <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
+   <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
+   <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
+  </valuemap>
+ </data>
+ <data>
+  <variable>ProjectExplorer.Project.PluginSettings</variable>
+  <valuemap type="QVariantMap"/>
+ </data>
+ <data>
+  <variable>ProjectExplorer.Project.Target.0</variable>
+  <valuemap type="QVariantMap">
+   <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
+   <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
+   <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{3ba33723-d18e-40e9-b2ff-74c84b681473}</value>
+   <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
+   <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
+   <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
+   <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
+    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
+     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
+      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
+      <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
+      <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
+      <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
+      <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
+     </valuemap>
+     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
+      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
+      <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
+      <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
+     </valuemap>
+     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
+    </valuemap>
+    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
+     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
+      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
+      <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
+      <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
+     </valuemap>
+     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
+    </valuemap>
+    <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
+    <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
+    <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
+    <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
+    <value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">D:/Qt/ProgrammingProj/build-ProgrammingProj-Desktop-Debug</value>
+    <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
+   </valuemap>
+   <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
+    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
+     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
+      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
+      <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
+      <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
+      <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
+      <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
+     </valuemap>
+     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
+      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
+      <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
+      <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
+     </valuemap>
+     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
+    </valuemap>
+    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
+     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
+      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
+      <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
+      <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
+     </valuemap>
+     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
+    </valuemap>
+    <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
+    <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
+    <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
+    <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
+    <value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">D:/Qt/ProgrammingProj/build-ProgrammingProj-Desktop-Release</value>
+    <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
+   </valuemap>
+   <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
+   <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
+    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
+     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
+    </valuemap>
+    <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
+   </valuemap>
+   <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
+   <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
+   <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
+    <value type="bool" key="Analyzer.Project.UseGlobal">true</value>
+    <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
+    <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
+    <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
+    <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
+    <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
+    <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
+    <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
+    <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
+    <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
+    <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
+    <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
+    <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
+    <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
+    <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
+     <value type="int">0</value>
+     <value type="int">1</value>
+     <value type="int">2</value>
+     <value type="int">3</value>
+     <value type="int">4</value>
+     <value type="int">5</value>
+     <value type="int">6</value>
+     <value type="int">7</value>
+     <value type="int">8</value>
+     <value type="int">9</value>
+     <value type="int">10</value>
+     <value type="int">11</value>
+     <value type="int">12</value>
+     <value type="int">13</value>
+     <value type="int">14</value>
+    </valuelist>
+    <value type="int" key="PE.EnvironmentAspect.Base">2</value>
+    <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">ProgrammingProj</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Qt/ProgrammingProj/ProgrammingProj/ProgrammingProj.pro</value>
+    <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
+    <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">ProgrammingProj.pro</value>
+    <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
+    <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
+    <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
+    <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
+    <value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
+    <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">false</value>
+    <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
+    <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
+    <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
+   </valuemap>
+   <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
+  </valuemap>
+ </data>
+ <data>
+  <variable>ProjectExplorer.Project.TargetCount</variable>
+  <value type="int">1</value>
+ </data>
+ <data>
+  <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
+  <value type="QByteArray">{2215fe50-704d-4360-9a28-4fe96e56f22c}</value>
+ </data>
+ <data>
+  <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
+  <value type="int">14</value>
+ </data>
+</qtcreator>
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+    
+    return a.exec();
+}
+#include <QtWidgets>
+
+#include <sstream>
+#include <fstream>
+#include <vector>
+#include <iterator>
+
+#include <cstdlib>
+
+#ifndef QT_NO_PRINTER
+    #include <QtPrintSupport/QPrintDialog>
+#endif /* !QT_NO_PRINTER */
+
+#include "mainwindow.h"
+
+#define IMAGE_SIZE_X	97
+#define IMAGE_SIZE_Y	56
+
+/*
+std::vector<std::string> SplitString(const std::string &str)
+{
+    std::istringstream buf(str);
+    std::vector<std::string> out;
+
+    std::copy(std::istream_iterator<std::string>(buf),
+              std::istream_iterator<std::string>(),
+              std::back_inserter<std::vector<std::string>>(out));
+
+    return out;
+}
+
+QImage LoadScan(const std::string filename)
+{
+    QImage img;
+    QVector<Pixel> data;
+
+    FILE *file = fopen(filename.c_str(), "r");
+
+    if (file)
+    {
+        QTextStream strm(file);
+
+        strm.readLine();
+
+        while (!strm.atEnd())
+        {
+            Pixel pxl;
+            QString line = strm.readLine();
+            std::vector<std::string> strs;
+
+            strs = SplitString(line.toStdString());
+
+            if (strs.size() == 0)
+            {
+                QMessageBox msgbox;
+
+                msgbox.setText("String std::vector is empty.");
+                msgbox.exec();
+            }
+
+            pxl.x = std::atoi(strs[0].c_str());
+            pxl.y = std::atoi(strs[1].c_str());
+            pxl.data = std::atof(strs[2].c_str());
+
+            data.push_back(pxl);
+        }
+    }
+
+    fclose(file);
+
+    img = QImage(data.last().x, data.last().y, QImage::Format_RGB16);
+
+    int id = 0;
+    for (int i = 0; i < data.last().x; i++)
+    {
+        for (int j = 0; j < data.last().y; j++)
+        {
+            int colour = ((data[id].data * 255) / 20);
+
+            img.setPixel(data[id].x, data[id].y, QRgb(colour));
+
+            id++;
+        }
+    }
+
+    return img;
+}
+*/
+
+QImage LoadScan(const std::string filename)
+{
+    float **data;
+    QImage img = QImage(IMAGE_SIZE_X, IMAGE_SIZE_Y, QImage::Format_RGB444);
+    char buf[32];
+    char buf3[32];
+    int cont;
+    QColor color;
+
+    data = (float **)malloc(sizeof(float) * IMAGE_SIZE_X);
+
+    for (int i = 0; i <= (IMAGE_SIZE_X - 1); i++)
+    {
+        data[i] = (float *)malloc(sizeof(float) * IMAGE_SIZE_Y);
+    }
+
+    // float temp;
+
+    std::ifstream filebuf(filename);
+
+    filebuf.getline(buf, 32);
+
+    printf("Image Data\n");
+
+    // Reiterate over each pixel, very inefficient, needs to be fixed.
+    for (int x = 1; x <= IMAGE_SIZE_X; x++)
+    {
+        for (int y = 1; y <= IMAGE_SIZE_Y; y++)
+        {
+            filebuf.getline(buf, 32);
+
+            // Only copy the values.
+            cont = 0;
+            for (int i = 8; i < 32; i++)
+            {
+                if (buf[i] != '\t' && buf[i] != ' ')
+                {
+                    buf3[cont] = buf[i];
+                    cont += 1;
+                }
+            }
+
+            // Set the pixel's value.
+            // data[x - 1][y - 1] = (float)atof(buf3);
+
+            int colour = (((float)atof(buf3) * 255) / 20);
+
+            color = QColor(colour, colour, colour);
+
+            img.setPixel(x - 1, y - 1, color.rgb());
+
+            printf("%d %d = %f = %d\n", x - 1, y - 1, atof(buf3), colour);
+        }
+    }
+
+    filebuf.close();
+
+    return img;
+}
+
+MainWindow::MainWindow()
+{
+    mImageLabel = new QLabel;
+    mImageLabel->setBackgroundRole(QPalette::Base);
+    mImageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+    mImageLabel->setScaledContents(true);
+
+    mScrollArea = new QScrollArea;
+    mScrollArea->setBackgroundRole(QPalette::Dark);
+    mScrollArea->setWidget(mImageLabel);
+
+    setCentralWidget(mScrollArea);
+
+    CreateActions();
+    CreateMenus();
+
+    setWindowTitle((tr("MRI Viewer")));
+
+    resize(1280, 720);
+}
+
+void MainWindow::Open()
+{
+    QString filename = QFileDialog::getOpenFileName(this, tr("Open Scan"), QDir::currentPath(), tr("MRI Scans (*.dat)"));
+
+    if (!filename.isEmpty())
+    {
+        QImage image = LoadScan(filename.toStdString());
+
+        if (image.isNull())
+        {
+            QMessageBox::information(this, tr("Error"), tr("Cannot load %1.").arg(filename));
+
+            return;
+        }
+
+        mImageLabel->setPixmap(QPixmap::fromImage(image));
+        mScaleFactor = 1.0;
+
+//        mPrintAction->setEnabled(true);
+        mFitToWindowAction->setEnabled(true);
+
+        UpdateActions();
+
+        if (!mFitToWindowAction->isChecked())
+        {
+            mImageLabel->adjustSize();
+        }
+    }
+}
+
+//void MainWindow::PrintScan()
+//{
+//    Q_ASSERT(mImageLabel->pixmap());
+
+//#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
+//    QPrintDialog dialog(&mPrinter, this);
+
+//    if (dialog.exec())
+//    {
+//        QPainter painter(&mPrinter);
+//        QRect rect = painter.viewport();
+//        QSize size = mImageLabel->pixmap()->size();
+//        size.scale(rect.size(), Qt::KeepAspectRatio);
+
+//        painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
+//        painter.setWindow(mImageLabel->pixmap()->rect());
+//        painter.drawPixmap(0, 0, *mImageLabel->pixmap());
+//    }
+//#endif /* !QT_NO_PRINTER && ... */
+//}
+
+void MainWindow::Exit()
+{
+
+}
+
+void MainWindow::ZoomIn()
+{
+    ScaleImage(1.25);
+}
+
+void MainWindow::ZoomOut()
+{
+    ScaleImage(0.8);
+}
+
+void MainWindow::NormalSize()
+{
+    mImageLabel->adjustSize();
+    mScaleFactor = 1.0;
+}
+
+void MainWindow::FitToWindow()
+{
+    bool fit = mFitToWindowAction->isChecked();
+
+    mScrollArea->setWidgetResizable(fit);
+
+    if (!fit)
+    {
+        NormalSize();
+    }
+
+    UpdateActions();
+}
+
+
+void MainWindow::About()
+{
+
+}
+
+void MainWindow::AboutQt()
+{
+
+}
+
+void MainWindow::CreateActions()
+{
+    // Open Scan
+    mOpenAction = new QAction(tr("&Open Scan..."), this);
+    mOpenAction->setShortcut(tr("Ctrl+O"));
+    connect(mOpenAction, SIGNAL(triggered()), this, SLOT(Open()));
+
+//    // Print Image
+//    mPrintAction = new QAction(tr("&Print Scan..."), this);
+//    mPrintAction->setShortcut(tr("Ctrl+P"));
+//    mPrintAction->setEnabled(false);
+//    connect(mPrintAction, SIGNAL(triggered()), this, SLOT(PrintScan()));
+
+    // Quit
+    mQuitAction = new QAction(tr("E&xit"), this);
+    mQuitAction->setShortcut(tr("Ctrl+Q"));
+    connect(mQuitAction, SIGNAL(triggered()), this, SLOT(Exit()));
+
+    // Zoom-In
+    mZoomInAction = new QAction(tr("Zoom-&In (25%)"), this);
+    mZoomInAction->setShortcut(tr("Ctrl++"));
+    mZoomInAction->setEnabled(false);
+    connect(mZoomInAction, SIGNAL(triggered()), this, SLOT(ZoomIn()));
+
+    // Zoom-Out
+    mZoomOutAction = new QAction(tr("Zoom-&Out (25%)"), this);
+    mZoomOutAction->setShortcut(tr("Ctrl+-"));
+    mZoomOutAction->setEnabled(false);
+    connect(mZoomOutAction, SIGNAL(triggered()), this, SLOT(ZoomOut()));
+
+    // Normal-Size
+    mNormalSizeAction = new QAction(tr("&Normal Size"), this);
+    mNormalSizeAction->setShortcut(tr("Ctrl+S"));
+    mNormalSizeAction->setEnabled(false);
+    connect(mNormalSizeAction, SIGNAL(triggered()), this, SLOT(NormalSize()));
+
+    // Fit To Window
+    mFitToWindowAction = new QAction(tr("&Fit to Window"), this);
+    mFitToWindowAction->setShortcut(tr("Ctrl+F"));
+    mFitToWindowAction->setEnabled(false);
+    mFitToWindowAction->setCheckable(true);
+    connect(mFitToWindowAction, SIGNAL(triggered()), this, SLOT(FitToWindow()));
+
+    // About
+    mAboutAction = new QAction(tr("&About MRI Viewer"), this);
+    connect(mAboutAction, SIGNAL(triggered()), this, SLOT(About()));
+
+    // AboutQt
+    mAboutQtAction = new QAction(tr("About &Qt"), this);
+    connect(mAboutQtAction, SIGNAL(triggered()), this, SLOT(AboutQt()));
+}
+
+void MainWindow::CreateMenus()
+{
+    // File Menu
+    mFileMenu = new QMenu(tr("&File"), this);
+    mFileMenu->addAction(mOpenAction);
+//    mFileMenu->addAction(mPrintAction);
+    mFileMenu->addSeparator();
+    mFileMenu->addAction(mQuitAction);
+
+    // View Menu
+    mViewMenu = new QMenu(tr("&View"), this);
+    mViewMenu->addAction(mZoomInAction);
+    mViewMenu->addAction(mZoomOutAction);
+    mViewMenu->addAction(mNormalSizeAction);
+    mViewMenu->addSeparator();
+    mViewMenu->addAction(mFitToWindowAction);
+
+    // Help Menu
+    mHelpMenu = new QMenu(tr("&Help"), this);
+    mHelpMenu->addAction(mAboutAction);
+    mHelpMenu->addAction(mAboutQtAction);
+
+    menuBar()->addMenu(mFileMenu);
+    menuBar()->addMenu(mViewMenu);
+    menuBar()->addMenu(mHelpMenu);
+}
+
+void MainWindow::UpdateActions()
+{
+    mZoomInAction->setEnabled(!mFitToWindowAction->isChecked());
+    mZoomOutAction->setEnabled(!mFitToWindowAction->isChecked());
+    mNormalSizeAction->setEnabled(!mFitToWindowAction->isChecked());
+}
+
+void MainWindow::ScaleImage(double factor)
+{
+    Q_ASSERT(mImageLabel->pixmap());
+
+    mScaleFactor *= factor;
+
+    mImageLabel->resize(mScaleFactor * mImageLabel->pixmap()->size());
+
+    AdjustScrollbar(mScrollArea->horizontalScrollBar(), factor);
+    AdjustScrollbar(mScrollArea->verticalScrollBar(), factor);
+
+    mZoomInAction->setEnabled(mScaleFactor < 3.0);
+    mZoomOutAction->setEnabled(mScaleFactor > 0.333);
+}
+
+void MainWindow::AdjustScrollbar(QScrollBar *scrollbar, double factor)
+{
+    scrollbar->setValue(int(factor * scrollbar->value() + ((factor - 1) * scrollbar->pageStep() /2 )));
+}
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+//#ifndef QT_NO_PRINTER
+//    #include <QtPrintSupport/QPrinter>
+//#endif /* !QT_NO_PRINTER */
+
+class QAction;
+class QLabel;
+class QScrollArea;
+class QMenu;
+class QScrollBar;
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+    
+public:
+    MainWindow();
+
+private slots:
+    void Open();
+//    void PrintScan();
+    void Exit();
+    void ZoomIn();
+    void ZoomOut();
+    void NormalSize();
+    void FitToWindow();
+    void About();
+    void AboutQt();
+
+private:
+    void CreateActions();
+    void CreateMenus();
+    void UpdateActions();
+    void ScaleImage(double factor);
+
+    void AdjustScrollbar(QScrollBar *scrollbar, double factor);
+
+    QLabel *mImageLabel;
+    QScrollArea *mScrollArea;
+    double mScaleFactor;
+
+//#if !defined(QT_NO_PRINTER)
+//    QPrinter mPrinter;
+//#endif /* !QT_NO_PRINTER */
+
+    QAction *mOpenAction;
+//    QAction *mPrintAction;
+    QAction *mQuitAction;
+    QAction *mZoomInAction;
+    QAction *mZoomOutAction;
+    QAction *mNormalSizeAction;
+    QAction *mFitToWindowAction;
+    QAction *mAboutAction;
+    QAction *mAboutQtAction;
+
+    QMenu *mFileMenu;
+    QMenu *mViewMenu;
+    QMenu *mHelpMenu;
+};
+
+QImage LoadScan(const QString filename);
+
+struct Pixel
+{
+    int x;
+    int y;
+
+    float data;
+};
+
+#endif // MAINWINDOW_H