From bdd8b981edd53b8bda851008321b71f291361aaf Mon Sep 17 00:00:00 2001 From: Illya Kovalevskyy Date: Sun, 12 May 2013 12:48:45 +0300 Subject: [PATCH 1/7] Refactoring step #1: Project cleanup --- .gitignore | 22 ++++++++++ LifeTime.pro | 49 +++++++++++++++++++++ {src/res => shared/img}/help.ico | Bin {src/res => shared/img}/jump.ico | Bin {src/res => shared/img}/on.ico | Bin {src/res => shared/img}/pause.ico | Bin {src/res => shared/img}/play.ico | Bin {src/res => shared/img}/restart.ico | Bin {src/res => shared/img}/settings.ico | Bin shared/ui.qrc | 11 +++++ src/LifeTime.pro | 51 ---------------------- src/mainwindow.ui | 26 ++++++------ src/ui.qrc | 11 ----- src/ui_settingswindow.h | 61 --------------------------- 14 files changed, 95 insertions(+), 136 deletions(-) create mode 100644 .gitignore create mode 100644 LifeTime.pro rename {src/res => shared/img}/help.ico (100%) rename {src/res => shared/img}/jump.ico (100%) rename {src/res => shared/img}/on.ico (100%) rename {src/res => shared/img}/pause.ico (100%) rename {src/res => shared/img}/play.ico (100%) rename {src/res => shared/img}/restart.ico (100%) rename {src/res => shared/img}/settings.ico (100%) create mode 100644 shared/ui.qrc delete mode 100644 src/LifeTime.pro delete mode 100644 src/ui.qrc delete mode 100644 src/ui_settingswindow.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..06065c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# C++ objects and libs + +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.dll +*.dylib + +# Qt-es + +*.pro.user +*.pro.user.* +moc_*.cpp +qrc_*.cpp +Makefile +*-build-* + +.DS_Store diff --git a/LifeTime.pro b/LifeTime.pro new file mode 100644 index 0000000..df75663 --- /dev/null +++ b/LifeTime.pro @@ -0,0 +1,49 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-01-08T00:14:36 +# +#------------------------------------------------- + +QT += core gui opengl + +TARGET = LifeTime +TEMPLATE = app +DESTDIR = bin + +SOURCES += src/world.cpp \ + src/timeview.cpp \ + src/timemodel.cpp \ + src/timeflow.cpp \ + src/settingsui.cpp \ + src/settings.cpp \ + src/readingsui.cpp \ + src/readings.cpp \ + src/mainwindow.cpp \ + src/main.cpp \ + src/lifeview.cpp \ + src/lifemodel.cpp \ + src/infoui.cpp + +HEADERS += src/world.h \ + src/ui_settingswindow.h \ + src/timeview.h \ + src/timemodel.h \ + src/timeflow.h \ + src/settingsui.h \ + src/settings.h \ + src/readingsui.h \ + src/readings.h \ + src/mainwindow.h \ + src/lifeview.h \ + src/lifemodel.h \ + src/infoui.h + +FORMS += src/settingsui.ui \ + src/mainwindow.ui \ + src/infoui.ui + +RESOURCES += shared/ui.qrc + +unix:LIBS += -lGLU +unix:DEFINES += __LINUX + diff --git a/src/res/help.ico b/shared/img/help.ico similarity index 100% rename from src/res/help.ico rename to shared/img/help.ico diff --git a/src/res/jump.ico b/shared/img/jump.ico similarity index 100% rename from src/res/jump.ico rename to shared/img/jump.ico diff --git a/src/res/on.ico b/shared/img/on.ico similarity index 100% rename from src/res/on.ico rename to shared/img/on.ico diff --git a/src/res/pause.ico b/shared/img/pause.ico similarity index 100% rename from src/res/pause.ico rename to shared/img/pause.ico diff --git a/src/res/play.ico b/shared/img/play.ico similarity index 100% rename from src/res/play.ico rename to shared/img/play.ico diff --git a/src/res/restart.ico b/shared/img/restart.ico similarity index 100% rename from src/res/restart.ico rename to shared/img/restart.ico diff --git a/src/res/settings.ico b/shared/img/settings.ico similarity index 100% rename from src/res/settings.ico rename to shared/img/settings.ico diff --git a/shared/ui.qrc b/shared/ui.qrc new file mode 100644 index 0000000..1bc941d --- /dev/null +++ b/shared/ui.qrc @@ -0,0 +1,11 @@ + + + img/help.ico + img/jump.ico + img/on.ico + img/pause.ico + img/play.ico + img/restart.ico + img/settings.ico + + diff --git a/src/LifeTime.pro b/src/LifeTime.pro deleted file mode 100644 index c73f302..0000000 --- a/src/LifeTime.pro +++ /dev/null @@ -1,51 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2013-01-08T00:14:36 -# -#------------------------------------------------- - -QT += core gui opengl - -TARGET = LifeTime -TEMPLATE = app - - -SOURCES += main.cpp\ - mainwindow.cpp \ - lifeview.cpp \ - timeview.cpp \ - timemodel.cpp \ - world.cpp \ - lifemodel.cpp \ - timeflow.cpp \ - settings.cpp \ - readings.cpp \ - readingsui.cpp \ - settingsui.cpp \ - infoui.cpp - -HEADERS += mainwindow.h \ - lifeview.h \ - timeview.h \ - timemodel.h \ - world.h \ - lifemodel.h \ - timeflow.h \ - settings.h \ - readings.h \ - readingsui.h \ - settingsui.h \ - infoui.h - -FORMS += mainwindow.ui \ - settingsui.ui \ - infoui.ui - -OTHER_FILES += - -RESOURCES += \ - ui.qrc - -unix:LIBS += -lGLU -unix:DEFINES += __LINUX - diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 50dc4ac..e000313 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -274,7 +274,7 @@ Leap - + :/new/prefix1/res/jump.ico:/new/prefix1/res/jump.ico @@ -294,7 +294,7 @@ Begin - + :/new/prefix1/res/on.ico:/new/prefix1/res/on.ico @@ -432,8 +432,8 @@ - - :/new/prefix1/res/settings.ico:/new/prefix1/res/settings.ico + + :/img/settings.ico:/img/settings.ico Settings @@ -444,8 +444,8 @@ - - :/new/prefix1/res/restart.ico:/new/prefix1/res/restart.ico + + :/img/restart.ico:/img/restart.ico Restart @@ -459,8 +459,8 @@ false - - :/new/prefix1/res/play.ico:/new/prefix1/res/play.ico + + :/img/play.ico:/img/play.ico Play @@ -471,8 +471,8 @@ - - :/new/prefix1/res/pause.ico:/new/prefix1/res/pause.ico + + :/img/pause.ico:/img/pause.ico Pause @@ -483,8 +483,8 @@ - - :/new/prefix1/res/help.ico:/new/prefix1/res/help.ico + + :/img/help.ico:/img/help.ico Info @@ -493,7 +493,7 @@ - + diff --git a/src/ui.qrc b/src/ui.qrc deleted file mode 100644 index e0d0f10..0000000 --- a/src/ui.qrc +++ /dev/null @@ -1,11 +0,0 @@ - - - res/help.ico - res/jump.ico - res/on.ico - res/pause.ico - res/play.ico - res/restart.ico - res/settings.ico - - diff --git a/src/ui_settingswindow.h b/src/ui_settingswindow.h deleted file mode 100644 index eb08a50..0000000 --- a/src/ui_settingswindow.h +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************** -** Form generated from reading UI file 'settingswindow.ui' -** -** Created: Fri 22. Mar 20:45:23 2013 -** by: Qt User Interface Compiler version 4.7.4 -** -** WARNING! All changes made in this file will be lost when recompiling UI file! -********************************************************************************/ - -#ifndef UI_SETTINGSWINDOW_H -#define UI_SETTINGSWINDOW_H - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Ui_SettingsWindow -{ -public: - QSpinBox *spinBox; - QLabel *label; - - void setupUi(QWidget *SettingsWindow) - { - if (SettingsWindow->objectName().isEmpty()) - SettingsWindow->setObjectName(QString::fromUtf8("SettingsWindow")); - SettingsWindow->resize(640, 480); - spinBox = new QSpinBox(SettingsWindow); - spinBox->setObjectName(QString::fromUtf8("spinBox")); - spinBox->setGeometry(QRect(130, 50, 42, 22)); - label = new QLabel(SettingsWindow); - label->setObjectName(QString::fromUtf8("label")); - label->setGeometry(QRect(50, 40, 46, 13)); - - retranslateUi(SettingsWindow); - - QMetaObject::connectSlotsByName(SettingsWindow); - } // setupUi - - void retranslateUi(QWidget *SettingsWindow) - { - SettingsWindow->setWindowTitle(QApplication::translate("SettingsWindow", "Form", 0, QApplication::UnicodeUTF8)); - label->setText(QApplication::translate("SettingsWindow", "TextLabel", 0, QApplication::UnicodeUTF8)); - } // retranslateUi - -}; - -namespace Ui { - class SettingsWindow: public Ui_SettingsWindow {}; -} // namespace Ui - -QT_END_NAMESPACE - -#endif // UI_SETTINGSWINDOW_H From 8c15462254b6f1072c7d43446b06fa3cd9f43328 Mon Sep 17 00:00:00 2001 From: Illya Kovalevskyy Date: Sun, 12 May 2013 13:16:00 +0300 Subject: [PATCH 2/7] Fix CRLF --- src/infoui.cpp | 38 +- src/infoui.h | 62 +-- src/infoui.ui | 128 +++--- src/lifemodel.cpp | 194 ++++----- src/lifemodel.h | 78 ++-- src/lifeview.cpp | 258 ++++++------ src/lifeview.h | 86 ++-- src/main.cpp | 22 +- src/mainwindow.cpp | 484 +++++++++++----------- src/mainwindow.h | 152 +++---- src/mainwindow.ui | 998 ++++++++++++++++++++++----------------------- src/readings.cpp | 58 +-- src/readings.h | 96 ++--- src/readingsui.cpp | 130 +++--- src/readingsui.h | 72 ++-- src/settings.cpp | 72 ++-- src/settings.h | 72 ++-- src/settingsui.cpp | 62 +-- src/settingsui.h | 64 +-- src/settingsui.ui | 326 +++++++-------- src/timeflow.cpp | 334 +++++++-------- src/timeflow.h | 164 ++++---- src/timemodel.cpp | 302 +++++++------- src/timemodel.h | 132 +++--- src/timeview.cpp | 202 ++++----- src/timeview.h | 60 +-- src/world.cpp | 308 +++++++------- src/world.h | 90 ++-- 28 files changed, 2522 insertions(+), 2522 deletions(-) diff --git a/src/infoui.cpp b/src/infoui.cpp index ee5d86d..c68479c 100644 --- a/src/infoui.cpp +++ b/src/infoui.cpp @@ -1,19 +1,19 @@ -#include "infoui.h" -#include "ui_infoui.h" - -InfoUI::InfoUI(QWidget *parent) : - QDialog(parent), - ui(new Ui::InfoUI) -{ - ui->setupUi(this); -} - -InfoUI::~InfoUI() -{ - delete ui; -} - -void InfoUI::on_pushButton_clicked() -{ - close(); -} +#include "infoui.h" +#include "ui_infoui.h" + +InfoUI::InfoUI(QWidget *parent) : + QDialog(parent), + ui(new Ui::InfoUI) +{ + ui->setupUi(this); +} + +InfoUI::~InfoUI() +{ + delete ui; +} + +void InfoUI::on_pushButton_clicked() +{ + close(); +} diff --git a/src/infoui.h b/src/infoui.h index 9abd4ad..d1e220f 100644 --- a/src/infoui.h +++ b/src/infoui.h @@ -1,31 +1,31 @@ -/////////////////////////////////////////////////////////////////////////////// -// InfoUI - help and about window -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef INFOUI_H -#define INFOUI_H - -#include - -namespace Ui { - class InfoUI; -} - -class InfoUI : public QDialog -{ - Q_OBJECT - -public: - explicit InfoUI(QWidget *parent = 0); - ~InfoUI(); - -private slots: - void on_pushButton_clicked(); - -private: - Ui::InfoUI *ui; -}; - -#endif // INFOUI_H +/////////////////////////////////////////////////////////////////////////////// +// InfoUI - help and about window +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef INFOUI_H +#define INFOUI_H + +#include + +namespace Ui { + class InfoUI; +} + +class InfoUI : public QDialog +{ + Q_OBJECT + +public: + explicit InfoUI(QWidget *parent = 0); + ~InfoUI(); + +private slots: + void on_pushButton_clicked(); + +private: + Ui::InfoUI *ui; +}; + +#endif // INFOUI_H diff --git a/src/infoui.ui b/src/infoui.ui index e85daf1..1ab6fea 100644 --- a/src/infoui.ui +++ b/src/infoui.ui @@ -1,64 +1,64 @@ - - - InfoUI - - - - 0 - 0 - 468 - 215 - - - - Help and About - - - - - 10 - 10 - 461 - 161 - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">LifeTime - it is a model of the time travels based on Conway's Life algorythm. Here you can see how the past responds to intervention (grandfather paradox).</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">How it works?</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">1. Push &quot;Begin&quot; (switch on virtual time machine).</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">2. Choose the object to move it in the timeline (mouse left click on any object of world).</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">3. Choose the destination point in the past (use slider).</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">4. Send the object into the past (push &quot;Leap&quot;).</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">5. See the alternative reality, its deviation, and final of time loop.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Questions, comments and suggestions: i.zimaev@timeacademy.ru</span></p></body></html> - - - Qt::AutoText - - - true - - - - - - 200 - 180 - 75 - 23 - - - - OK - - - - - - + + + InfoUI + + + + 0 + 0 + 468 + 215 + + + + Help and About + + + + + 10 + 10 + 461 + 161 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">LifeTime - it is a model of the time travels based on Conway's Life algorythm. Here you can see how the past responds to intervention (grandfather paradox).</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">How it works?</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">1. Push &quot;Begin&quot; (switch on virtual time machine).</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">2. Choose the object to move it in the timeline (mouse left click on any object of world).</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">3. Choose the destination point in the past (use slider).</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">4. Send the object into the past (push &quot;Leap&quot;).</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">5. See the alternative reality, its deviation, and final of time loop.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Questions, comments and suggestions: i.zimaev@timeacademy.ru</span></p></body></html> + + + Qt::AutoText + + + true + + + + + + 200 + 180 + 75 + 23 + + + + OK + + + + + + diff --git a/src/lifemodel.cpp b/src/lifemodel.cpp index da5e45e..8c8b18d 100644 --- a/src/lifemodel.cpp +++ b/src/lifemodel.cpp @@ -1,97 +1,97 @@ -#include -#include -#include "lifemodel.h" -#include "world.h" - -LifeModel::LifeModel() : - m_worldCur(new World()), - m_worldPrev(new World()), - m_filling(0.f) -{ -} - - -LifeModel::~LifeModel() -{ - delete m_worldPrev; - delete m_worldCur; -} - - -void LifeModel::start(int rows, int cols, int count) -{ - m_worldPrev->init(rows, cols); - m_worldCur->init(rows, cols); - - qsrand(QTime::currentTime().msec()); - - for (int n=0; ncell(qrand()%rows, qrand()%cols) = true; - } -} - - -void LifeModel::setWorld(const World& world) -{ - *m_worldPrev = world; - m_worldCur->init(world.rows(), world.cols()); -} - - -const World& LifeModel::next() -{ - int lifeCount = 0; - - for (int row=0; rowrows(); ++row) - { - for (int col=0; colcols(); ++col) - { - int lifeAround = 0; - World::TCells cells = m_worldPrev->nearest(row, col); - foreach(const World::TCell& c, cells) - { - if (m_worldPrev->cell(c.first, c.second)) lifeAround++; - } - - // empty cell, near 3 life - born life - if (!m_worldPrev->cell(row, col) && lifeAround == 3) - m_worldCur->cell(row, col) = true; - else - // dead of cell, if near less 2 or over 3 life - if (m_worldPrev->cell(row, col) && (lifeAround < 2 || lifeAround > 3)) - m_worldCur->cell(row, col) = false; - else - m_worldCur->cell(row, col) = m_worldPrev->cell(row, col); - // - if (m_worldCur->cell(row, col)) lifeCount++; - } - } - - // - World* tmp = m_worldPrev; - m_worldPrev = m_worldCur; - m_worldCur = tmp; - - m_filling = float(lifeCount) / (m_worldCur->rows() * m_worldCur->cols()); - - return (*m_worldPrev); -} - - -float LifeModel::filling() const -{ - return m_filling; -} - - -float LifeModel::crossObject(const World::TCells& object) const -{ - int countMatch = 0; - foreach(const World::TCell& c, object) - { - if (m_worldPrev->cell(c.first, c.second)) countMatch++; - } - - return float(countMatch) / object.size(); -} +#include +#include +#include "lifemodel.h" +#include "world.h" + +LifeModel::LifeModel() : + m_worldCur(new World()), + m_worldPrev(new World()), + m_filling(0.f) +{ +} + + +LifeModel::~LifeModel() +{ + delete m_worldPrev; + delete m_worldCur; +} + + +void LifeModel::start(int rows, int cols, int count) +{ + m_worldPrev->init(rows, cols); + m_worldCur->init(rows, cols); + + qsrand(QTime::currentTime().msec()); + + for (int n=0; ncell(qrand()%rows, qrand()%cols) = true; + } +} + + +void LifeModel::setWorld(const World& world) +{ + *m_worldPrev = world; + m_worldCur->init(world.rows(), world.cols()); +} + + +const World& LifeModel::next() +{ + int lifeCount = 0; + + for (int row=0; rowrows(); ++row) + { + for (int col=0; colcols(); ++col) + { + int lifeAround = 0; + World::TCells cells = m_worldPrev->nearest(row, col); + foreach(const World::TCell& c, cells) + { + if (m_worldPrev->cell(c.first, c.second)) lifeAround++; + } + + // empty cell, near 3 life - born life + if (!m_worldPrev->cell(row, col) && lifeAround == 3) + m_worldCur->cell(row, col) = true; + else + // dead of cell, if near less 2 or over 3 life + if (m_worldPrev->cell(row, col) && (lifeAround < 2 || lifeAround > 3)) + m_worldCur->cell(row, col) = false; + else + m_worldCur->cell(row, col) = m_worldPrev->cell(row, col); + // + if (m_worldCur->cell(row, col)) lifeCount++; + } + } + + // + World* tmp = m_worldPrev; + m_worldPrev = m_worldCur; + m_worldCur = tmp; + + m_filling = float(lifeCount) / (m_worldCur->rows() * m_worldCur->cols()); + + return (*m_worldPrev); +} + + +float LifeModel::filling() const +{ + return m_filling; +} + + +float LifeModel::crossObject(const World::TCells& object) const +{ + int countMatch = 0; + foreach(const World::TCell& c, object) + { + if (m_worldPrev->cell(c.first, c.second)) countMatch++; + } + + return float(countMatch) / object.size(); +} diff --git a/src/lifemodel.h b/src/lifemodel.h index 1982939..f367f1d 100644 --- a/src/lifemodel.h +++ b/src/lifemodel.h @@ -1,39 +1,39 @@ -/////////////////////////////////////////////////////////////////////////////// -// LifeModel - world's life calculation, implementation of Conway algorythm -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef LIFEMODEL_H -#define LIFEMODEL_H -#include -#include "world.h" - -class LifeModel: public QObject -{ - Q_OBJECT -public: - LifeModel(); - ~LifeModel(); - - // 1st way of life start: random - void start(int rows, int cols, int count); - // 2nd way of life start: exist world - void setWorld(const World& world); - - // Next life frame - const World& next(); - - // world filling coef. - float filling() const; - - // world and object intercross coef. - float crossObject(const World::TCells&) const; - -private: - World* m_worldCur; - World* m_worldPrev; - float m_filling; -}; - -#endif // LIFEMODEL_H +/////////////////////////////////////////////////////////////////////////////// +// LifeModel - world's life calculation, implementation of Conway algorythm +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef LIFEMODEL_H +#define LIFEMODEL_H +#include +#include "world.h" + +class LifeModel: public QObject +{ + Q_OBJECT +public: + LifeModel(); + ~LifeModel(); + + // 1st way of life start: random + void start(int rows, int cols, int count); + // 2nd way of life start: exist world + void setWorld(const World& world); + + // Next life frame + const World& next(); + + // world filling coef. + float filling() const; + + // world and object intercross coef. + float crossObject(const World::TCells&) const; + +private: + World* m_worldCur; + World* m_worldPrev; + float m_filling; +}; + +#endif // LIFEMODEL_H diff --git a/src/lifeview.cpp b/src/lifeview.cpp index a35eccb..c24e356 100644 --- a/src/lifeview.cpp +++ b/src/lifeview.cpp @@ -1,129 +1,129 @@ -#include -#include "lifeview.h" -#include "world.h" -#include "settings.h" -#ifdef __LINUX -#include -#include -#endif - -LifeView::LifeView(QWidget *parent) : - QGLWidget(QGLFormat(QGL::SampleBuffers), parent), - m_world(NULL), - m_object(NULL), - m_fixObject(false), - m_state(Readings::showPast) -{ - -} - - -void LifeView::initializeGL() -{ - glDisable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glDisable(GL_COLOR_MATERIAL); - glEnable(GL_BLEND); - glEnable(GL_POLYGON_SMOOTH); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor(0, 0, 0, 0); -} - - -void LifeView::resizeGL(int nWidth, int nHeight) -{ - glViewport(0, 0, nWidth, nHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluOrtho2D(0, nWidth, 0, nHeight); // set origin to bottom left corner - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - - -void LifeView::on_changeWorld(const World& world, const World::TCells& object, Readings::eStates state) -{ - m_world = &world; - m_object = &object; - m_state = state; - updateGL(); -} - - -void LifeView::paintGL() -{ - glClear(GL_COLOR_BUFFER_BIT); - - if (!m_world) return; - - float cellW = (float)width() / m_world->cols(); - float cellH = (float)height() / m_world->rows(); - - // - const QColor& color = Settings::instance().colorWorld; - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - - float y; - float x; - for (int row=0; row < m_world->rows(); ++row) - { - for (int col=0; col < m_world->cols(); ++col) - { - if (m_world->cell(row, col)) - { - glBegin(GL_POLYGON); - - y = cellH*((float)(m_world->rows()-row)); - x = cellW*((float)(col+1)); - - glVertex2f(x, y); - glVertex2f(x, y-cellH); - glVertex2f(x-cellW, y-cellH); - glVertex2f(x-cellW, y); - - glEnd(); - } - } - } - - // - if (m_object) - { - const QColor& color = (m_state == Readings::showPast ? Settings::instance().colorObjectChoose : - (m_state == Readings::inLoop ? Settings::instance().colorObjectGhost : Settings::instance().colorObjectFinal)); - - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - - foreach(const World::TCell& cell, (*m_object)) - { - glBegin(GL_POLYGON); - - y = cellH*((float)(m_world->rows()-cell.first)); - x = cellW*((float)(cell.second+1)); - - glVertex2f(x, y); - glVertex2f(x, y-cellH); - glVertex2f(x-cellW, y-cellH); - glVertex2f(x-cellW, y); - - glEnd(); - } - } -} - - -void LifeView::mousePressEvent(QMouseEvent* event) -{ - if (m_fixObject) return; - - int row = int( event->posF().y() / height() * m_world->rows() ); - int col = int( event->posF().x() / width() * m_world->cols() ); - - emit chooseObjectEvent(row, col); -} - - -void LifeView::fixObject(bool fix) -{ - m_fixObject = fix; -} +#include +#include "lifeview.h" +#include "world.h" +#include "settings.h" +#ifdef __LINUX +#include +#include +#endif + +LifeView::LifeView(QWidget *parent) : + QGLWidget(QGLFormat(QGL::SampleBuffers), parent), + m_world(NULL), + m_object(NULL), + m_fixObject(false), + m_state(Readings::showPast) +{ + +} + + +void LifeView::initializeGL() +{ + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_COLOR_MATERIAL); + glEnable(GL_BLEND); + glEnable(GL_POLYGON_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(0, 0, 0, 0); +} + + +void LifeView::resizeGL(int nWidth, int nHeight) +{ + glViewport(0, 0, nWidth, nHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, nWidth, 0, nHeight); // set origin to bottom left corner + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +void LifeView::on_changeWorld(const World& world, const World::TCells& object, Readings::eStates state) +{ + m_world = &world; + m_object = &object; + m_state = state; + updateGL(); +} + + +void LifeView::paintGL() +{ + glClear(GL_COLOR_BUFFER_BIT); + + if (!m_world) return; + + float cellW = (float)width() / m_world->cols(); + float cellH = (float)height() / m_world->rows(); + + // + const QColor& color = Settings::instance().colorWorld; + glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + + float y; + float x; + for (int row=0; row < m_world->rows(); ++row) + { + for (int col=0; col < m_world->cols(); ++col) + { + if (m_world->cell(row, col)) + { + glBegin(GL_POLYGON); + + y = cellH*((float)(m_world->rows()-row)); + x = cellW*((float)(col+1)); + + glVertex2f(x, y); + glVertex2f(x, y-cellH); + glVertex2f(x-cellW, y-cellH); + glVertex2f(x-cellW, y); + + glEnd(); + } + } + } + + // + if (m_object) + { + const QColor& color = (m_state == Readings::showPast ? Settings::instance().colorObjectChoose : + (m_state == Readings::inLoop ? Settings::instance().colorObjectGhost : Settings::instance().colorObjectFinal)); + + glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + + foreach(const World::TCell& cell, (*m_object)) + { + glBegin(GL_POLYGON); + + y = cellH*((float)(m_world->rows()-cell.first)); + x = cellW*((float)(cell.second+1)); + + glVertex2f(x, y); + glVertex2f(x, y-cellH); + glVertex2f(x-cellW, y-cellH); + glVertex2f(x-cellW, y); + + glEnd(); + } + } +} + + +void LifeView::mousePressEvent(QMouseEvent* event) +{ + if (m_fixObject) return; + + int row = int( event->posF().y() / height() * m_world->rows() ); + int col = int( event->posF().x() / width() * m_world->cols() ); + + emit chooseObjectEvent(row, col); +} + + +void LifeView::fixObject(bool fix) +{ + m_fixObject = fix; +} diff --git a/src/lifeview.h b/src/lifeview.h index df725c4..7000652 100644 --- a/src/lifeview.h +++ b/src/lifeview.h @@ -1,43 +1,43 @@ -/////////////////////////////////////////////////////////////////////////////// -// LifeView - view of world (use OpenGL) -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// - -#ifndef LIFEVIEW_H -#define LIFEVIEW_H -#include -#include "world.h" -#include "readings.h" - -class QMouseEvent; - -class LifeView : public QGLWidget -{ - Q_OBJECT -public: - explicit LifeView(QWidget* parent); - - // Freeze object choose - void fixObject(bool fix); - -public slots: - void on_changeWorld(const World& world, const World::TCells& object, Readings::eStates state); - -signals: - void chooseObjectEvent(int col, int row); - -private: - void initializeGL(); - void resizeGL(int nWidth, int nHeight); - void paintGL(); - void mousePressEvent(QMouseEvent* event); - - const World* m_world; - const World::TCells* m_object; - bool m_fixObject; - Readings::eStates m_state; -}; - -#endif // LIFEVIEW_H +/////////////////////////////////////////////////////////////////////////////// +// LifeView - view of world (use OpenGL) +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// + +#ifndef LIFEVIEW_H +#define LIFEVIEW_H +#include +#include "world.h" +#include "readings.h" + +class QMouseEvent; + +class LifeView : public QGLWidget +{ + Q_OBJECT +public: + explicit LifeView(QWidget* parent); + + // Freeze object choose + void fixObject(bool fix); + +public slots: + void on_changeWorld(const World& world, const World::TCells& object, Readings::eStates state); + +signals: + void chooseObjectEvent(int col, int row); + +private: + void initializeGL(); + void resizeGL(int nWidth, int nHeight); + void paintGL(); + void mousePressEvent(QMouseEvent* event); + + const World* m_world; + const World::TCells* m_object; + bool m_fixObject; + Readings::eStates m_state; +}; + +#endif // LIFEVIEW_H diff --git a/src/main.cpp b/src/main.cpp index d1378ad..d951345 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,11 @@ -#include -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0c9368e..b528c28 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,242 +1,242 @@ -#include -#include -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "timemodel.h" -#include "lifeview.h" -#include "timeview.h" -#include "settings.h" -#include "settingsui.h" -#include "infoui.h" - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow), - m_pause(false), - m_tmOn(false), - m_tmBlocked(false), - m_choosedObject(false), - m_choosedTime(false) -{ - m_timeModel = new TimeModel(); - m_timeView = new TimeView(this); - m_lifeView = new LifeView(this); - - // - // setup UI - // - ui->setupUi(this); - ui->verticalLayout_1->addWidget(m_timeView); - ui->verticalLayout_2->addWidget(m_lifeView); - - m_readingsUI.init(ui->treeWidget); - - ui->comboFlow->addItem("r0 - trunk"); - ui->comboFlow->addItem("r1 - branch"); - ui->comboFlow->setCurrentIndex(0); - - // - // Setup timer - // - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(on_render())); - - // - // bind models and views - // - connect(m_timeModel, SIGNAL(worldChangeEvent(const World&, const World::TCells&, Readings::eStates)), - m_lifeView, SLOT(on_changeWorld(const World&, const World::TCells&, Readings::eStates)) ); - - connect(m_timeModel, SIGNAL(timeChangeEvent(const TimeModel::TimeFlows&, const TimeModel::Bounds&)), - m_timeView, SLOT(on_changeTime(const TimeModel::TimeFlows&, const TimeModel::Bounds&)) ); - - connect(m_timeModel, SIGNAL(updateReadingsEvent(const Readings&)), - this, SLOT(on_updateReadings(const Readings&)) ); - - connect(m_timeModel, SIGNAL(loopEndEvent()), - this, SLOT(on_loopEnd()) ); - - connect(m_lifeView, SIGNAL(chooseObjectEvent(int, int)), - m_timeModel, SLOT(on_chooseObject(int, int)) ); - - connect(ui->comboFlow, SIGNAL(currentIndexChanged(int)), - m_timeModel, SLOT(on_switchFlow(int)) ); - - // run - start(); -} - - -MainWindow::~MainWindow() -{ - delete ui; - delete m_lifeView; - delete m_timeView; - delete m_timeModel; -} - - -void MainWindow::resizeEvent(QResizeEvent* e) -{ - m_timeView->setMaximumHeight(e->size().height() * 0.2); - m_lifeView->setMaximumHeight(e->size().height() * 0.8); -} - - -void MainWindow::start() -{ - m_timeModel->bigBan(Settings::instance().worldRows, - Settings::instance().worldCols, - Settings::instance().worldRows * - Settings::instance().worldCols * - (float)Settings::instance().initFilling/100.f); - - if (m_timer->isActive()) m_timer->stop(); - m_timer->start(1.0 / Settings::instance().desiredFPS * 1000); - - m_pause = false; - m_tmOn = false; - m_tmBlocked = false; - m_choosedObject = false; - m_choosedTime = false; - - enableControls(); -} - - -bool MainWindow::pause() const -{ - return m_pause; -} - - -void MainWindow::setPause(const bool pause) -{ - m_pause = pause; -} - - -void MainWindow::on_render() -{ - if (!m_pause && !m_tmOn) - { - m_timeModel->next(); - - ui->lcd1->display(m_timeModel->curTime()); - ui->lcd2->display(m_timeModel->maxTime()); - } -} - - -void MainWindow::enableControls() -{ - ui->sliderTime->setEnabled(m_tmOn && m_choosedObject); - ui->labelChooseObject->setEnabled(m_tmOn && !m_choosedObject); - ui->labelChooseDate->setEnabled(m_tmOn && m_choosedObject && !m_choosedTime); - - m_lifeView->fixObject(!m_tmOn); - - ui->btnOn->setEnabled(!m_tmOn && !m_tmBlocked && !m_choosedTime); - ui->btnLeap->setEnabled(m_tmOn && m_choosedTime); - - ui->labelFlow->setEnabled(m_tmBlocked); - ui->comboFlow->setEnabled(m_tmBlocked); -} - - -void MainWindow::on_btnOn_clicked() -{ - ui->sliderTime->setMaximum(m_timeModel->curTime()); - ui->sliderTime->setValue(m_timeModel->curTime()); - m_tmOn = true; - - enableControls(); -} - - -void MainWindow::on_sliderTime_sliderPressed() -{ - enableControls(); -} - - -void MainWindow::on_sliderTime_valueChanged(int value) -{ - m_timeModel->showPast(value); - ui->lcd1->display(value); -} - - -void MainWindow::on_sliderTime_sliderReleased() -{ - m_choosedTime = true; - enableControls(); -} - - -void MainWindow::on_btnLeap_clicked() -{ - m_timeModel->gotoPast(ui->sliderTime->value()); - m_tmOn = false; - enableControls(); -} - - -void MainWindow::on_updateReadings(const Readings& readings) -{ - m_choosedObject = (readings.objectSizeAbs > 0); - m_readingsUI.update(readings); - enableControls(); -} - - -void MainWindow::on_loopEnd() -{ - // only one travel in the past! - m_tmBlocked = true; - on_actionPause_triggered(); -} - - -void MainWindow::on_actionSettings_triggered() -{ - bool wasPause = m_pause; - if (!m_pause) on_actionPause_triggered(); - SettingsUI dlg; - dlg.exec(); - if (!wasPause) on_actionPlay_triggered(); -} - - -void MainWindow::on_actionRestart_triggered() -{ - start(); -} - - -void MainWindow::on_actionPlay_triggered() -{ - m_pause = false; - ui->actionPlay->setEnabled(false); - ui->actionPause->setEnabled(true); -} - - -void MainWindow::on_actionPause_triggered() -{ - m_pause = true; - ui->actionPause->setEnabled(false); - ui->actionPlay->setEnabled(true); -} - - -void MainWindow::on_actionInfo_triggered() -{ - bool wasPause = m_pause; - if (!m_pause) on_actionPause_triggered(); - InfoUI dlg; - dlg.exec(); - if (!wasPause) on_actionPlay_triggered(); -} - - +#include +#include +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "timemodel.h" +#include "lifeview.h" +#include "timeview.h" +#include "settings.h" +#include "settingsui.h" +#include "infoui.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow), + m_pause(false), + m_tmOn(false), + m_tmBlocked(false), + m_choosedObject(false), + m_choosedTime(false) +{ + m_timeModel = new TimeModel(); + m_timeView = new TimeView(this); + m_lifeView = new LifeView(this); + + // + // setup UI + // + ui->setupUi(this); + ui->verticalLayout_1->addWidget(m_timeView); + ui->verticalLayout_2->addWidget(m_lifeView); + + m_readingsUI.init(ui->treeWidget); + + ui->comboFlow->addItem("r0 - trunk"); + ui->comboFlow->addItem("r1 - branch"); + ui->comboFlow->setCurrentIndex(0); + + // + // Setup timer + // + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(on_render())); + + // + // bind models and views + // + connect(m_timeModel, SIGNAL(worldChangeEvent(const World&, const World::TCells&, Readings::eStates)), + m_lifeView, SLOT(on_changeWorld(const World&, const World::TCells&, Readings::eStates)) ); + + connect(m_timeModel, SIGNAL(timeChangeEvent(const TimeModel::TimeFlows&, const TimeModel::Bounds&)), + m_timeView, SLOT(on_changeTime(const TimeModel::TimeFlows&, const TimeModel::Bounds&)) ); + + connect(m_timeModel, SIGNAL(updateReadingsEvent(const Readings&)), + this, SLOT(on_updateReadings(const Readings&)) ); + + connect(m_timeModel, SIGNAL(loopEndEvent()), + this, SLOT(on_loopEnd()) ); + + connect(m_lifeView, SIGNAL(chooseObjectEvent(int, int)), + m_timeModel, SLOT(on_chooseObject(int, int)) ); + + connect(ui->comboFlow, SIGNAL(currentIndexChanged(int)), + m_timeModel, SLOT(on_switchFlow(int)) ); + + // run + start(); +} + + +MainWindow::~MainWindow() +{ + delete ui; + delete m_lifeView; + delete m_timeView; + delete m_timeModel; +} + + +void MainWindow::resizeEvent(QResizeEvent* e) +{ + m_timeView->setMaximumHeight(e->size().height() * 0.2); + m_lifeView->setMaximumHeight(e->size().height() * 0.8); +} + + +void MainWindow::start() +{ + m_timeModel->bigBan(Settings::instance().worldRows, + Settings::instance().worldCols, + Settings::instance().worldRows * + Settings::instance().worldCols * + (float)Settings::instance().initFilling/100.f); + + if (m_timer->isActive()) m_timer->stop(); + m_timer->start(1.0 / Settings::instance().desiredFPS * 1000); + + m_pause = false; + m_tmOn = false; + m_tmBlocked = false; + m_choosedObject = false; + m_choosedTime = false; + + enableControls(); +} + + +bool MainWindow::pause() const +{ + return m_pause; +} + + +void MainWindow::setPause(const bool pause) +{ + m_pause = pause; +} + + +void MainWindow::on_render() +{ + if (!m_pause && !m_tmOn) + { + m_timeModel->next(); + + ui->lcd1->display(m_timeModel->curTime()); + ui->lcd2->display(m_timeModel->maxTime()); + } +} + + +void MainWindow::enableControls() +{ + ui->sliderTime->setEnabled(m_tmOn && m_choosedObject); + ui->labelChooseObject->setEnabled(m_tmOn && !m_choosedObject); + ui->labelChooseDate->setEnabled(m_tmOn && m_choosedObject && !m_choosedTime); + + m_lifeView->fixObject(!m_tmOn); + + ui->btnOn->setEnabled(!m_tmOn && !m_tmBlocked && !m_choosedTime); + ui->btnLeap->setEnabled(m_tmOn && m_choosedTime); + + ui->labelFlow->setEnabled(m_tmBlocked); + ui->comboFlow->setEnabled(m_tmBlocked); +} + + +void MainWindow::on_btnOn_clicked() +{ + ui->sliderTime->setMaximum(m_timeModel->curTime()); + ui->sliderTime->setValue(m_timeModel->curTime()); + m_tmOn = true; + + enableControls(); +} + + +void MainWindow::on_sliderTime_sliderPressed() +{ + enableControls(); +} + + +void MainWindow::on_sliderTime_valueChanged(int value) +{ + m_timeModel->showPast(value); + ui->lcd1->display(value); +} + + +void MainWindow::on_sliderTime_sliderReleased() +{ + m_choosedTime = true; + enableControls(); +} + + +void MainWindow::on_btnLeap_clicked() +{ + m_timeModel->gotoPast(ui->sliderTime->value()); + m_tmOn = false; + enableControls(); +} + + +void MainWindow::on_updateReadings(const Readings& readings) +{ + m_choosedObject = (readings.objectSizeAbs > 0); + m_readingsUI.update(readings); + enableControls(); +} + + +void MainWindow::on_loopEnd() +{ + // only one travel in the past! + m_tmBlocked = true; + on_actionPause_triggered(); +} + + +void MainWindow::on_actionSettings_triggered() +{ + bool wasPause = m_pause; + if (!m_pause) on_actionPause_triggered(); + SettingsUI dlg; + dlg.exec(); + if (!wasPause) on_actionPlay_triggered(); +} + + +void MainWindow::on_actionRestart_triggered() +{ + start(); +} + + +void MainWindow::on_actionPlay_triggered() +{ + m_pause = false; + ui->actionPlay->setEnabled(false); + ui->actionPause->setEnabled(true); +} + + +void MainWindow::on_actionPause_triggered() +{ + m_pause = true; + ui->actionPause->setEnabled(false); + ui->actionPlay->setEnabled(true); +} + + +void MainWindow::on_actionInfo_triggered() +{ + bool wasPause = m_pause; + if (!m_pause) on_actionPause_triggered(); + InfoUI dlg; + dlg.exec(); + if (!wasPause) on_actionPlay_triggered(); +} + + diff --git a/src/mainwindow.h b/src/mainwindow.h index 23bc11a..e803740 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,76 +1,76 @@ -/////////////////////////////////////////////////////////////////////////////// -// MainWindow - main app window -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef MAINWINDOW_H -#define MAINWINDOW_H -#include -#include "world.h" -#include "readingsui.h" - -namespace Ui { -class MainWindow; -} - -class TimeModel; -class LifeView; -class TimeView; -class QTreeWidgetItem; -class Readings; -class QTimer; - -// -class MainWindow : public QMainWindow -{ - Q_OBJECT - Q_PROPERTY(bool pause READ pause WRITE setPause) - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - -private slots: - void on_render(); - void on_sliderTime_sliderPressed(); - void on_sliderTime_valueChanged(int value); - void on_sliderTime_sliderReleased(); - void on_btnLeap_clicked(); - void on_btnOn_clicked(); - void on_updateReadings(const Readings&); - void on_loopEnd(); - - void on_actionSettings_triggered(); - void on_actionRestart_triggered(); - void on_actionPlay_triggered(); - void on_actionPause_triggered(); - - - void on_actionInfo_triggered(); - -private: - Ui::MainWindow* ui; - TimeModel* m_timeModel; - LifeView* m_lifeView; - TimeView* m_timeView; - bool m_pause; - bool m_tmOn; - bool m_tmBlocked; - bool m_choosedObject; - bool m_choosedTime; - QTimer* m_timer; - - ReadingsUI m_readingsUI; - -private: - void start(); - void resizeEvent(QResizeEvent* e); - - bool pause() const; - void setPause(const bool pause); - - void enableControls(); -}; - -#endif // MAINWINDOW_H +/////////////////////////////////////////////////////////////////////////////// +// MainWindow - main app window +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef MAINWINDOW_H +#define MAINWINDOW_H +#include +#include "world.h" +#include "readingsui.h" + +namespace Ui { +class MainWindow; +} + +class TimeModel; +class LifeView; +class TimeView; +class QTreeWidgetItem; +class Readings; +class QTimer; + +// +class MainWindow : public QMainWindow +{ + Q_OBJECT + Q_PROPERTY(bool pause READ pause WRITE setPause) + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void on_render(); + void on_sliderTime_sliderPressed(); + void on_sliderTime_valueChanged(int value); + void on_sliderTime_sliderReleased(); + void on_btnLeap_clicked(); + void on_btnOn_clicked(); + void on_updateReadings(const Readings&); + void on_loopEnd(); + + void on_actionSettings_triggered(); + void on_actionRestart_triggered(); + void on_actionPlay_triggered(); + void on_actionPause_triggered(); + + + void on_actionInfo_triggered(); + +private: + Ui::MainWindow* ui; + TimeModel* m_timeModel; + LifeView* m_lifeView; + TimeView* m_timeView; + bool m_pause; + bool m_tmOn; + bool m_tmBlocked; + bool m_choosedObject; + bool m_choosedTime; + QTimer* m_timer; + + ReadingsUI m_readingsUI; + +private: + void start(); + void resizeEvent(QResizeEvent* e); + + bool pause() const; + void setPause(const bool pause); + + void enableControls(); +}; + +#endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index e000313..54665d8 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1,499 +1,499 @@ - - - MainWindow - - - Qt::NonModal - - - - 0 - 0 - 800 - 600 - - - - - 0 - 0 - - - - - 800 - 600 - - - - LifeTime 1.0 - - - QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks - - - false - - - - - - - - - Qt::Horizontal - - - - 40 - 0 - - - - - - - - - - - 0 - 0 - - - - - 30 - 25 - - - - QFrame::NoFrame - - - 1 - - - QLCDNumber::Flat - - - - - - - - 0 - 0 - - - - - 16777215 - 30 - - - - - - - - - 0 - 0 - 106 - - - - - - - - - 0 - 0 - 106 - - - - - - - - - 120 - 120 - 120 - - - - - - - - QFrame::NoFrame - - - 5 - - - QLCDNumber::Flat - - - - - - - - 0 - 0 - - - - - 16777215 - 30 - - - - QFrame::NoFrame - - - 5 - - - QLCDNumber::Flat - - - - - - - - - false - - - - 0 - 0 - - - - 1 - - - 99 - - - Qt::Horizontal - - - - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 0 - - - - - - - - - - - - - - 180 - 0 - - - - - 180 - 16777215 - - - - false - - - - 1 - - - - - - - - - 180 - 150 - - - - - 16777215 - 150 - - - - - - - - false - - - - 10 - 98 - 161 - 40 - - - - Leap - - - - :/new/prefix1/res/jump.ico:/new/prefix1/res/jump.ico - - - - - true - - - - 10 - 10 - 161 - 40 - - - - Begin - - - - :/new/prefix1/res/on.ico:/new/prefix1/res/on.ico - - - - 20 - 20 - - - - false - - - false - - - - - false - - - - 44 - 47 - 91 - 16 - - - - - 50 - false - - - - - choose object - - - - - false - - - - 44 - 63 - 91 - 16 - - - - - choose time - - - - - - - - - 0 - 40 - - - - - - - - false - - - - 16 - 4 - 31 - 31 - - - - - 0 - 0 - - - - - 40 - 16777215 - - - - Flow: - - - - - true - - - - 50 - 10 - 150 - 20 - - - - - 150 - 16777215 - - - - - - - - - - toolBar - - - TopToolBarArea - - - false - - - - - - - - - - - - - :/img/settings.ico:/img/settings.ico - - - Settings - - - Settings - - - - - - :/img/restart.ico:/img/restart.ico - - - Restart - - - Restart - - - - - false - - - - :/img/play.ico:/img/play.ico - - - Play - - - Play - - - - - - :/img/pause.ico:/img/pause.ico - - - Pause - - - Pause - - - - - - :/img/help.ico:/img/help.ico - - - Info - - - - - - - - - + + + MainWindow + + + Qt::NonModal + + + + 0 + 0 + 800 + 600 + + + + + 0 + 0 + + + + + 800 + 600 + + + + LifeTime 1.0 + + + QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks + + + false + + + + + + + + + Qt::Horizontal + + + + 40 + 0 + + + + + + + + + + + 0 + 0 + + + + + 30 + 25 + + + + QFrame::NoFrame + + + 1 + + + QLCDNumber::Flat + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + + + + + + 0 + 0 + 106 + + + + + + + + + 0 + 0 + 106 + + + + + + + + + 120 + 120 + 120 + + + + + + + + QFrame::NoFrame + + + 5 + + + QLCDNumber::Flat + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + QFrame::NoFrame + + + 5 + + + QLCDNumber::Flat + + + + + + + + + false + + + + 0 + 0 + + + + 1 + + + 99 + + + Qt::Horizontal + + + + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 0 + + + + + + + + + + + + + + 180 + 0 + + + + + 180 + 16777215 + + + + false + + + + 1 + + + + + + + + + 180 + 150 + + + + + 16777215 + 150 + + + + + + + + false + + + + 10 + 98 + 161 + 40 + + + + Leap + + + + :/new/prefix1/res/jump.ico:/new/prefix1/res/jump.ico + + + + + true + + + + 10 + 10 + 161 + 40 + + + + Begin + + + + :/new/prefix1/res/on.ico:/new/prefix1/res/on.ico + + + + 20 + 20 + + + + false + + + false + + + + + false + + + + 44 + 47 + 91 + 16 + + + + + 50 + false + + + + - choose object + + + + + false + + + + 44 + 63 + 91 + 16 + + + + - choose time + + + + + + + + + 0 + 40 + + + + + + + + false + + + + 16 + 4 + 31 + 31 + + + + + 0 + 0 + + + + + 40 + 16777215 + + + + Flow: + + + + + true + + + + 50 + 10 + 150 + 20 + + + + + 150 + 16777215 + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + + + + + + + :/img/settings.ico:/img/settings.ico + + + Settings + + + Settings + + + + + + :/img/restart.ico:/img/restart.ico + + + Restart + + + Restart + + + + + false + + + + :/img/play.ico:/img/play.ico + + + Play + + + Play + + + + + + :/img/pause.ico:/img/pause.ico + + + Pause + + + Pause + + + + + + :/img/help.ico:/img/help.ico + + + Info + + + + + + + + + diff --git a/src/readings.cpp b/src/readings.cpp index d5239d5..cdf51c8 100644 --- a/src/readings.cpp +++ b/src/readings.cpp @@ -1,29 +1,29 @@ -#include "readings.h" - - -Readings::Readings() -{ - clear(); -} - -void Readings::clear() -{ - worldWidth = 0; - worldHeight = 0; - worldFill = 0.f; - - objectSizeAbs = 0; - objectSizeRel = 0.f; - - state = Readings::showPast; - leapFrom = 0; - leapTo = 0; - leapDistance = 0; - - leapDifMax = 0.f; - leapDifRoot = 0.f; - leapDifK = 0.f; - leapRootInvar = 0.f; - leapType = 0; -} - +#include "readings.h" + + +Readings::Readings() +{ + clear(); +} + +void Readings::clear() +{ + worldWidth = 0; + worldHeight = 0; + worldFill = 0.f; + + objectSizeAbs = 0; + objectSizeRel = 0.f; + + state = Readings::showPast; + leapFrom = 0; + leapTo = 0; + leapDistance = 0; + + leapDifMax = 0.f; + leapDifRoot = 0.f; + leapDifK = 0.f; + leapRootInvar = 0.f; + leapType = 0; +} + diff --git a/src/readings.h b/src/readings.h index 25a82c5..535c148 100644 --- a/src/readings.h +++ b/src/readings.h @@ -1,48 +1,48 @@ -/////////////////////////////////////////////////////////////////////////////// -// Readings - data of time machine -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef READINGS_H -#define READINGS_H - -struct Readings -{ - int worldWidth; - int worldHeight; - float worldFill; - - int objectSizeAbs; - float objectSizeRel; - - // TM state - enum eStates - { - showPast, - inLoop, - afterLoop - }; - - eStates state; - - int leapFrom; - int leapTo; - int leapDistance; - - // Reality max dif - float leapDifMax; - // Reality dif at loop end - float leapDifRoot; - // Coef. of dif stable in root of loop (0 - total fade) - float leapDifK; - // Invar of object after leap - float leapRootInvar; - // Degree of history change - int leapType; - - Readings(); - void clear(); -}; - -#endif // READINGS_H +/////////////////////////////////////////////////////////////////////////////// +// Readings - data of time machine +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef READINGS_H +#define READINGS_H + +struct Readings +{ + int worldWidth; + int worldHeight; + float worldFill; + + int objectSizeAbs; + float objectSizeRel; + + // TM state + enum eStates + { + showPast, + inLoop, + afterLoop + }; + + eStates state; + + int leapFrom; + int leapTo; + int leapDistance; + + // Reality max dif + float leapDifMax; + // Reality dif at loop end + float leapDifRoot; + // Coef. of dif stable in root of loop (0 - total fade) + float leapDifK; + // Invar of object after leap + float leapRootInvar; + // Degree of history change + int leapType; + + Readings(); + void clear(); +}; + +#endif // READINGS_H diff --git a/src/readingsui.cpp b/src/readingsui.cpp index 1a21907..68aa743 100644 --- a/src/readingsui.cpp +++ b/src/readingsui.cpp @@ -1,65 +1,65 @@ -#include -#include "readingsui.h" -#include "readings.h" - -void ReadingsUI::init(QTreeWidget* treeWidget) -{ - treeWidget->setColumnCount(2); - - treeWidget->setColumnWidth(0, treeWidget->width() * 0.6); - treeWidget->setColumnWidth(1, treeWidget->width() * 0.35); - - QTreeWidgetItem* world = new QTreeWidgetItem((QTreeWidget*)NULL, QStringList("World") ); - QTreeWidgetItem* object = new QTreeWidgetItem((QTreeWidget*)NULL, QStringList("Object") ); - QTreeWidgetItem* leap = new QTreeWidgetItem((QTreeWidget*)NULL, QStringList("Leap") ); - - treeWidget->insertTopLevelItem(0, leap); - treeWidget->insertTopLevelItem(0, object); - treeWidget->insertTopLevelItem(0, world); - - itemWorldSize = new QTreeWidgetItem(world, QStringList("Size:")); - itemWorldFill = new QTreeWidgetItem(world, QStringList("Fill:")); - - itemObjectSizeAbs = new QTreeWidgetItem(object, QStringList("Size(abs):")); - itemObjectSizeRel = new QTreeWidgetItem(object, QStringList("Size(rel):")); - - itemLeapFrom = new QTreeWidgetItem(leap, QStringList("From:")); - itemLeapTo = new QTreeWidgetItem(leap, QStringList("To:")); - itemLeapDistance = new QTreeWidgetItem(leap, QStringList("Distance:")); - itemLeapDifMax = new QTreeWidgetItem(leap, QStringList("Dif max.:")); - itemLeapDifRoot = new QTreeWidgetItem(leap, QStringList("Dif root:")); - itemLeapDifK = new QTreeWidgetItem(leap, QStringList("Dif coef.:")); - itemLeapRootInvar = new QTreeWidgetItem(leap, QStringList("Root invar:")); - itemLeapType = new QTreeWidgetItem(leap, QStringList("Leap type:")); - - treeWidget->expandAll(); -} - - -void ReadingsUI::update(const Readings& readings) -{ - itemWorldSize->setText(1, QString("%1 x %2").arg(readings.worldWidth).arg(readings.worldHeight)); - itemWorldFill->setText(1, QString::number(readings.worldFill)); - - itemObjectSizeAbs->setText(1, QString::number(readings.objectSizeAbs)); - itemObjectSizeRel->setText(1, QString("%1%").arg(readings.objectSizeRel)); - - itemLeapFrom->setText(1, QString::number(readings.leapFrom)); - itemLeapTo->setText(1, QString::number(readings.leapTo)); - itemLeapDistance->setText(1, QString::number(readings.leapDistance)); - - itemLeapDifMax->setText(1, QString::number(readings.leapDifMax)); - itemLeapDifRoot->setText(1, QString::number(readings.leapDifRoot)); - itemLeapDifK->setText(1, QString::number(readings.leapDifK)); - itemLeapRootInvar->setText(1, QString::number(readings.leapRootInvar)); - - QString leapType; - switch(readings.leapType) - { - case 0: leapType = "-"; break; - case 1: leapType = "(1) observe"; break; - case 2: leapType = "(2) change"; break; - case 3: leapType = "(3) paradox"; break; - }; - itemLeapType->setText(1, leapType); -} +#include +#include "readingsui.h" +#include "readings.h" + +void ReadingsUI::init(QTreeWidget* treeWidget) +{ + treeWidget->setColumnCount(2); + + treeWidget->setColumnWidth(0, treeWidget->width() * 0.6); + treeWidget->setColumnWidth(1, treeWidget->width() * 0.35); + + QTreeWidgetItem* world = new QTreeWidgetItem((QTreeWidget*)NULL, QStringList("World") ); + QTreeWidgetItem* object = new QTreeWidgetItem((QTreeWidget*)NULL, QStringList("Object") ); + QTreeWidgetItem* leap = new QTreeWidgetItem((QTreeWidget*)NULL, QStringList("Leap") ); + + treeWidget->insertTopLevelItem(0, leap); + treeWidget->insertTopLevelItem(0, object); + treeWidget->insertTopLevelItem(0, world); + + itemWorldSize = new QTreeWidgetItem(world, QStringList("Size:")); + itemWorldFill = new QTreeWidgetItem(world, QStringList("Fill:")); + + itemObjectSizeAbs = new QTreeWidgetItem(object, QStringList("Size(abs):")); + itemObjectSizeRel = new QTreeWidgetItem(object, QStringList("Size(rel):")); + + itemLeapFrom = new QTreeWidgetItem(leap, QStringList("From:")); + itemLeapTo = new QTreeWidgetItem(leap, QStringList("To:")); + itemLeapDistance = new QTreeWidgetItem(leap, QStringList("Distance:")); + itemLeapDifMax = new QTreeWidgetItem(leap, QStringList("Dif max.:")); + itemLeapDifRoot = new QTreeWidgetItem(leap, QStringList("Dif root:")); + itemLeapDifK = new QTreeWidgetItem(leap, QStringList("Dif coef.:")); + itemLeapRootInvar = new QTreeWidgetItem(leap, QStringList("Root invar:")); + itemLeapType = new QTreeWidgetItem(leap, QStringList("Leap type:")); + + treeWidget->expandAll(); +} + + +void ReadingsUI::update(const Readings& readings) +{ + itemWorldSize->setText(1, QString("%1 x %2").arg(readings.worldWidth).arg(readings.worldHeight)); + itemWorldFill->setText(1, QString::number(readings.worldFill)); + + itemObjectSizeAbs->setText(1, QString::number(readings.objectSizeAbs)); + itemObjectSizeRel->setText(1, QString("%1%").arg(readings.objectSizeRel)); + + itemLeapFrom->setText(1, QString::number(readings.leapFrom)); + itemLeapTo->setText(1, QString::number(readings.leapTo)); + itemLeapDistance->setText(1, QString::number(readings.leapDistance)); + + itemLeapDifMax->setText(1, QString::number(readings.leapDifMax)); + itemLeapDifRoot->setText(1, QString::number(readings.leapDifRoot)); + itemLeapDifK->setText(1, QString::number(readings.leapDifK)); + itemLeapRootInvar->setText(1, QString::number(readings.leapRootInvar)); + + QString leapType; + switch(readings.leapType) + { + case 0: leapType = "-"; break; + case 1: leapType = "(1) observe"; break; + case 2: leapType = "(2) change"; break; + case 3: leapType = "(3) paradox"; break; + }; + itemLeapType->setText(1, leapType); +} diff --git a/src/readingsui.h b/src/readingsui.h index 98cb9f8..aa63119 100644 --- a/src/readingsui.h +++ b/src/readingsui.h @@ -1,36 +1,36 @@ -/////////////////////////////////////////////////////////////////////////////// -// ReadingsUI - view of time machine data -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef READINGSUI_H -#define READINGSUI_H - -class Readings; -class QTreeWidget; -class QTreeWidgetItem; - -struct ReadingsUI -{ - QTreeWidgetItem* itemWorldSize; - QTreeWidgetItem* itemWorldFill; - - QTreeWidgetItem* itemObjectSizeAbs; - QTreeWidgetItem* itemObjectSizeRel; - - QTreeWidgetItem* itemLeapFrom; - QTreeWidgetItem* itemLeapTo; - QTreeWidgetItem* itemLeapDistance; - - QTreeWidgetItem* itemLeapDifMax; - QTreeWidgetItem* itemLeapDifRoot; - QTreeWidgetItem* itemLeapDifK; - QTreeWidgetItem* itemLeapRootInvar; - QTreeWidgetItem* itemLeapType; - - void init(QTreeWidget* treeWidget); - void update(const Readings& readings); -}; - -#endif // READINGSUI_H +/////////////////////////////////////////////////////////////////////////////// +// ReadingsUI - view of time machine data +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef READINGSUI_H +#define READINGSUI_H + +class Readings; +class QTreeWidget; +class QTreeWidgetItem; + +struct ReadingsUI +{ + QTreeWidgetItem* itemWorldSize; + QTreeWidgetItem* itemWorldFill; + + QTreeWidgetItem* itemObjectSizeAbs; + QTreeWidgetItem* itemObjectSizeRel; + + QTreeWidgetItem* itemLeapFrom; + QTreeWidgetItem* itemLeapTo; + QTreeWidgetItem* itemLeapDistance; + + QTreeWidgetItem* itemLeapDifMax; + QTreeWidgetItem* itemLeapDifRoot; + QTreeWidgetItem* itemLeapDifK; + QTreeWidgetItem* itemLeapRootInvar; + QTreeWidgetItem* itemLeapType; + + void init(QTreeWidget* treeWidget); + void update(const Readings& readings); +}; + +#endif // READINGSUI_H diff --git a/src/settings.cpp b/src/settings.cpp index e828c65..64baf20 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,36 +1,36 @@ -#include "settings.h" -#include - -Settings::Settings() - : m_settings("TimeAcademy", "LifeTime") -{ - worldRows = m_settings.value("worldCols", 100).toInt(); - worldCols = m_settings.value("worldRows", 100).toInt(); - desiredFPS = m_settings.value("desiredFPS", 20).toInt(); - initFilling = m_settings.value("initFilling", 30).toInt(); - - colorWorld = QColor::fromRgb(92, 208, 7); - colorGate = QColor::fromRgb(94, 146, 251); - - colorObjectChoose = QColor::fromRgb(202, 208, 7); - colorObjectGhost = QColor::fromRgb(92, 208, 7, 100); - colorObjectFinal = QColor::fromRgb(32, 248, 7, 100); -} - - -Settings::~Settings() -{ - m_settings.setValue("worldRows", worldCols); - m_settings.setValue("worldCols", worldRows); - m_settings.setValue("desiredFPS", desiredFPS); - m_settings.setValue("initFilling", initFilling); -} - - -Settings& Settings::instance() -{ - static Settings _instance; - return _instance; -} - - +#include "settings.h" +#include + +Settings::Settings() + : m_settings("TimeAcademy", "LifeTime") +{ + worldRows = m_settings.value("worldCols", 100).toInt(); + worldCols = m_settings.value("worldRows", 100).toInt(); + desiredFPS = m_settings.value("desiredFPS", 20).toInt(); + initFilling = m_settings.value("initFilling", 30).toInt(); + + colorWorld = QColor::fromRgb(92, 208, 7); + colorGate = QColor::fromRgb(94, 146, 251); + + colorObjectChoose = QColor::fromRgb(202, 208, 7); + colorObjectGhost = QColor::fromRgb(92, 208, 7, 100); + colorObjectFinal = QColor::fromRgb(32, 248, 7, 100); +} + + +Settings::~Settings() +{ + m_settings.setValue("worldRows", worldCols); + m_settings.setValue("worldCols", worldRows); + m_settings.setValue("desiredFPS", desiredFPS); + m_settings.setValue("initFilling", initFilling); +} + + +Settings& Settings::instance() +{ + static Settings _instance; + return _instance; +} + + diff --git a/src/settings.h b/src/settings.h index 3a150bf..b3404ae 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,36 +1,36 @@ -/////////////////////////////////////////////////////////////////////////////// -// Settings - app global settings -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef SETTINGS_H -#define SETTINGS_H -#include -#include - -class Settings -{ -public: - int worldRows; - int worldCols; - int desiredFPS; - int initFilling; - QColor colorWorld; - QColor colorGate; - QColor colorObjectChoose; - QColor colorObjectGhost; - QColor colorObjectFinal; - - static Settings& instance(); - -private: - Settings(); - Settings(const Settings&); - ~Settings(); - void operator=(const Settings&); - - QSettings m_settings; -}; - -#endif // SETTINGS_H +/////////////////////////////////////////////////////////////////////////////// +// Settings - app global settings +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef SETTINGS_H +#define SETTINGS_H +#include +#include + +class Settings +{ +public: + int worldRows; + int worldCols; + int desiredFPS; + int initFilling; + QColor colorWorld; + QColor colorGate; + QColor colorObjectChoose; + QColor colorObjectGhost; + QColor colorObjectFinal; + + static Settings& instance(); + +private: + Settings(); + Settings(const Settings&); + ~Settings(); + void operator=(const Settings&); + + QSettings m_settings; +}; + +#endif // SETTINGS_H diff --git a/src/settingsui.cpp b/src/settingsui.cpp index 748697f..5075019 100644 --- a/src/settingsui.cpp +++ b/src/settingsui.cpp @@ -1,31 +1,31 @@ -#include -#include "settingsui.h" -#include "ui_settingsui.h" -#include "settings.h" - -SettingsUI::SettingsUI(QWidget *parent) : - QDialog(parent), - ui(new Ui::SettingsUI) -{ - ui->setupUi(this); - - ui->spinWorldCols->setValue(Settings::instance().worldCols); - ui->spinWorldRows->setValue(Settings::instance().worldRows); - ui->spinDesiredFPS->setValue(Settings::instance().desiredFPS); - ui->spinInitFilling->setValue(Settings::instance().initFilling); -} - -SettingsUI::~SettingsUI() -{ - delete ui; -} - -void SettingsUI::on_pushOK_clicked() -{ - Settings::instance().worldCols = ui->spinWorldCols->value(); - Settings::instance().worldRows = ui->spinWorldRows->value(); - Settings::instance().desiredFPS = ui->spinDesiredFPS->value(); - Settings::instance().initFilling = ui->spinInitFilling->value(); - - close(); -} +#include +#include "settingsui.h" +#include "ui_settingsui.h" +#include "settings.h" + +SettingsUI::SettingsUI(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsUI) +{ + ui->setupUi(this); + + ui->spinWorldCols->setValue(Settings::instance().worldCols); + ui->spinWorldRows->setValue(Settings::instance().worldRows); + ui->spinDesiredFPS->setValue(Settings::instance().desiredFPS); + ui->spinInitFilling->setValue(Settings::instance().initFilling); +} + +SettingsUI::~SettingsUI() +{ + delete ui; +} + +void SettingsUI::on_pushOK_clicked() +{ + Settings::instance().worldCols = ui->spinWorldCols->value(); + Settings::instance().worldRows = ui->spinWorldRows->value(); + Settings::instance().desiredFPS = ui->spinDesiredFPS->value(); + Settings::instance().initFilling = ui->spinInitFilling->value(); + + close(); +} diff --git a/src/settingsui.h b/src/settingsui.h index fc38c4b..f08cca9 100644 --- a/src/settingsui.h +++ b/src/settingsui.h @@ -1,32 +1,32 @@ -/////////////////////////////////////////////////////////////////////////////// -// SettingsUI - view of global app settings -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef SETTINGSUI_H -#define SETTINGSUI_H -#include - -namespace Ui { - class SettingsUI; -} - - -class SettingsUI : public QDialog -{ - Q_OBJECT - -public: - explicit SettingsUI(QWidget *parent = 0); - ~SettingsUI(); - -private slots: - void on_pushOK_clicked(); - -private: - Ui::SettingsUI *ui; - -}; - -#endif // SETTINGSUI_H +/////////////////////////////////////////////////////////////////////////////// +// SettingsUI - view of global app settings +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef SETTINGSUI_H +#define SETTINGSUI_H +#include + +namespace Ui { + class SettingsUI; +} + + +class SettingsUI : public QDialog +{ + Q_OBJECT + +public: + explicit SettingsUI(QWidget *parent = 0); + ~SettingsUI(); + +private slots: + void on_pushOK_clicked(); + +private: + Ui::SettingsUI *ui; + +}; + +#endif // SETTINGSUI_H diff --git a/src/settingsui.ui b/src/settingsui.ui index ab200b7..e60a201 100644 --- a/src/settingsui.ui +++ b/src/settingsui.ui @@ -1,163 +1,163 @@ - - - SettingsUI - - - - 0 - 0 - 273 - 166 - - - - Settings - - - - - 90 - 10 - 71 - 22 - - - - 50 - - - 1000 - - - 50 - - - - - - 30 - 14 - 61 - 16 - - - - World size: - - - - - - 167 - 16 - 16 - 16 - - - - x - - - - - - 180 - 10 - 71 - 22 - - - - 50 - - - 1000 - - - 50 - - - - - - 22 - 53 - 61 - 16 - - - - Desired FPS: - - - - - - 90 - 50 - 71 - 22 - - - - 10 - - - 100 - - - 10 - - - - - - 90 - 90 - 71 - 22 - - - - 10 - - - 100 - - - 10 - - - 30 - - - - - - 14 - 93 - 71 - 16 - - - - Init filling (%): - - - - - - 187 - 131 - 75 - 23 - - - - OK - - - - - - + + + SettingsUI + + + + 0 + 0 + 273 + 166 + + + + Settings + + + + + 90 + 10 + 71 + 22 + + + + 50 + + + 1000 + + + 50 + + + + + + 30 + 14 + 61 + 16 + + + + World size: + + + + + + 167 + 16 + 16 + 16 + + + + x + + + + + + 180 + 10 + 71 + 22 + + + + 50 + + + 1000 + + + 50 + + + + + + 22 + 53 + 61 + 16 + + + + Desired FPS: + + + + + + 90 + 50 + 71 + 22 + + + + 10 + + + 100 + + + 10 + + + + + + 90 + 90 + 71 + 22 + + + + 10 + + + 100 + + + 10 + + + 30 + + + + + + 14 + 93 + 71 + 16 + + + + Init filling (%): + + + + + + 187 + 131 + 75 + 23 + + + + OK + + + + + + diff --git a/src/timeflow.cpp b/src/timeflow.cpp index e983c87..9172c4d 100644 --- a/src/timeflow.cpp +++ b/src/timeflow.cpp @@ -1,167 +1,167 @@ -#include "timeflow.h" -#include "lifemodel.h" - -TimeFlow::TimeFlow() -{ - m_parent = NULL; - m_birthday = 0; - m_life = NULL; - m_bMax = 0.f; -} - - -TimeFlow::TimeFlow(int rows, int cols, int count) -{ - // Start of root flow - m_parent = NULL; - m_birthday = 0; - m_life = new LifeModel(); - m_life->start(rows, cols, count); - m_bMax = 0.f; -} - - -TimeFlow::TimeFlow(const TimeFlow* parent, World::TCells* object, int birthday) - : m_parent(parent), m_birthday(birthday) -{ - // Start of child flow - m_life = new LifeModel(); - m_past = parent->m_past.mid(0, birthday); - m_fillings = parent->m_fillings.mid(0, birthday); - m_bMax = 0.f; - - World* w = m_past.last(); - foreach(const World::TCell& cell, (*object)) - { - w->cell(cell.first, cell.second) = 1; - } - - m_life->setWorld(*w); - - m_branch.push_back(Point5D(birthday, parent->m_branch[birthday].b)); -} - - -TimeFlow::TimeFlow(const TimeFlow& rhs) - : m_parent(rhs.m_parent), - m_birthday(rhs.m_birthday), - m_past(rhs.m_past), - m_fillings(rhs.m_fillings), - m_life(rhs.m_life), - m_branch(rhs.m_branch), - m_bMax(rhs.m_bMax) -{ - -} - - -TimeFlow::~TimeFlow() -{ - -} - - -TimeFlow& TimeFlow::operator =(const TimeFlow& rhs) -{ - m_parent = rhs.m_parent; - m_birthday = rhs.m_birthday; - m_past = rhs.m_past; - m_fillings = rhs.m_fillings; - m_life = rhs.m_life; - m_branch = rhs.m_branch; - m_bMax = rhs.m_bMax; - - return *this; -} - - -void TimeFlow::next() -{ - // First, calc next world "frame" - m_past << new World(m_life->next()); - m_fillings << m_life->filling(); - - // Second, calc his 5D coords - int t = m_past.size()-1; - float b = m_parent ? - (worldDif(world(t), m_parent->world(t))) : 0; - - // Dif between flow and its parent, and b-coord parent - b += m_parent ? m_parent->b(t) : 0; - - if (m_bMax < b) - m_bMax = b; - - m_branch.push_back(Point5D(t, b)); -} - - -float TimeFlow::b(int t) const -{ - if (t > m_birthday) return m_branch[t - m_birthday].b; - return m_parent->b(t); -} - - -float TimeFlow::filling(int t) const -{ - Q_ASSERT(t >=0 && t < m_fillings.size()); - return m_fillings[t]; -} - - -const TimeFlow::TBranch& TimeFlow::branch() const -{ - return m_branch; -} - - -const World& TimeFlow::world(int time) const -{ - Q_ASSERT(time >=0 && time < m_past.size()); - return *m_past[time]; -} - - -const LifeModel* TimeFlow::life() const -{ - return m_life; -} - - -int TimeFlow::tMax() const -{ - return m_past.size() - 1; -} - - -float TimeFlow::bMax() const -{ - return m_bMax; -} - - -void TimeFlow::addLeap(int from, int to) -{ - m_branch.push_back(Point5D(from, b(from), Point5D::leapIn)); - m_branch.push_back(Point5D(to, b(to), Point5D::leapOut)); -} - - -float TimeFlow::worldDif(const World& world1, const World& world2) -{ - Q_ASSERT(world1.rows() == world2.rows()); - Q_ASSERT(world1.cols() == world2.cols()); - - float dif = 0; - - for (int row=0; rowstart(rows, cols, count); + m_bMax = 0.f; +} + + +TimeFlow::TimeFlow(const TimeFlow* parent, World::TCells* object, int birthday) + : m_parent(parent), m_birthday(birthday) +{ + // Start of child flow + m_life = new LifeModel(); + m_past = parent->m_past.mid(0, birthday); + m_fillings = parent->m_fillings.mid(0, birthday); + m_bMax = 0.f; + + World* w = m_past.last(); + foreach(const World::TCell& cell, (*object)) + { + w->cell(cell.first, cell.second) = 1; + } + + m_life->setWorld(*w); + + m_branch.push_back(Point5D(birthday, parent->m_branch[birthday].b)); +} + + +TimeFlow::TimeFlow(const TimeFlow& rhs) + : m_parent(rhs.m_parent), + m_birthday(rhs.m_birthday), + m_past(rhs.m_past), + m_fillings(rhs.m_fillings), + m_life(rhs.m_life), + m_branch(rhs.m_branch), + m_bMax(rhs.m_bMax) +{ + +} + + +TimeFlow::~TimeFlow() +{ + +} + + +TimeFlow& TimeFlow::operator =(const TimeFlow& rhs) +{ + m_parent = rhs.m_parent; + m_birthday = rhs.m_birthday; + m_past = rhs.m_past; + m_fillings = rhs.m_fillings; + m_life = rhs.m_life; + m_branch = rhs.m_branch; + m_bMax = rhs.m_bMax; + + return *this; +} + + +void TimeFlow::next() +{ + // First, calc next world "frame" + m_past << new World(m_life->next()); + m_fillings << m_life->filling(); + + // Second, calc his 5D coords + int t = m_past.size()-1; + float b = m_parent ? + (worldDif(world(t), m_parent->world(t))) : 0; + + // Dif between flow and its parent, and b-coord parent + b += m_parent ? m_parent->b(t) : 0; + + if (m_bMax < b) + m_bMax = b; + + m_branch.push_back(Point5D(t, b)); +} + + +float TimeFlow::b(int t) const +{ + if (t > m_birthday) return m_branch[t - m_birthday].b; + return m_parent->b(t); +} + + +float TimeFlow::filling(int t) const +{ + Q_ASSERT(t >=0 && t < m_fillings.size()); + return m_fillings[t]; +} + + +const TimeFlow::TBranch& TimeFlow::branch() const +{ + return m_branch; +} + + +const World& TimeFlow::world(int time) const +{ + Q_ASSERT(time >=0 && time < m_past.size()); + return *m_past[time]; +} + + +const LifeModel* TimeFlow::life() const +{ + return m_life; +} + + +int TimeFlow::tMax() const +{ + return m_past.size() - 1; +} + + +float TimeFlow::bMax() const +{ + return m_bMax; +} + + +void TimeFlow::addLeap(int from, int to) +{ + m_branch.push_back(Point5D(from, b(from), Point5D::leapIn)); + m_branch.push_back(Point5D(to, b(to), Point5D::leapOut)); +} + + +float TimeFlow::worldDif(const World& world1, const World& world2) +{ + Q_ASSERT(world1.rows() == world2.rows()); + Q_ASSERT(world1.cols() == world2.cols()); + + float dif = 0; + + for (int row=0; row -#include "world.h" - -class LifeModel; - - -class TimeFlow -{ -public: - - // Point of multiversum, t - time axis, b - axis of alternate realities - struct Point5D - { - enum Kind { track, normal, leapIn, leapOut }; - - int t; - float b; - Kind k; - Point5D(){} - Point5D(int time, float branch, Kind kind = normal) - : t(time), b(branch), k(kind) - { - } - }; - typedef QVector TBranch; - - TimeFlow(); - TimeFlow(int rows, int cols, int count); - TimeFlow(const TimeFlow* parent, World::TCells* object, int birthday); - TimeFlow(const TimeFlow&); - ~TimeFlow(); - - TimeFlow& operator =(const TimeFlow&); - - // Calcs step - void next(); - - // Add tonnel in past - void addLeap(int from, int to); - - const TBranch& branch() const; - const World& world(int time) const; - const LifeModel* life() const; - - int tMax() const; - float bMax() const; - - float b(int t) const; - float filling(int t) const; - -private: - // Parent flow - const TimeFlow* m_parent; - int m_birthday; - - // Copy of history - QVector m_past; - - // FIXME: parallel arrays is bad - QVector m_fillings; - - // - LifeModel* m_life; - - // - TBranch m_branch; - float m_bMax; - -private: - // The quantitative difference between the worlds - static float worldDif(const World& world1, const World& world2); -}; - -#endif // FLOW_H +/////////////////////////////////////////////////////////////////////////////// +// TimeFlow - flow of time, contains world's history and branch curve +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef FLOW_H +#define FLOW_H +#include +#include "world.h" + +class LifeModel; + + +class TimeFlow +{ +public: + + // Point of multiversum, t - time axis, b - axis of alternate realities + struct Point5D + { + enum Kind { track, normal, leapIn, leapOut }; + + int t; + float b; + Kind k; + Point5D(){} + Point5D(int time, float branch, Kind kind = normal) + : t(time), b(branch), k(kind) + { + } + }; + typedef QVector TBranch; + + TimeFlow(); + TimeFlow(int rows, int cols, int count); + TimeFlow(const TimeFlow* parent, World::TCells* object, int birthday); + TimeFlow(const TimeFlow&); + ~TimeFlow(); + + TimeFlow& operator =(const TimeFlow&); + + // Calcs step + void next(); + + // Add tonnel in past + void addLeap(int from, int to); + + const TBranch& branch() const; + const World& world(int time) const; + const LifeModel* life() const; + + int tMax() const; + float bMax() const; + + float b(int t) const; + float filling(int t) const; + +private: + // Parent flow + const TimeFlow* m_parent; + int m_birthday; + + // Copy of history + QVector m_past; + + // FIXME: parallel arrays is bad + QVector m_fillings; + + // + LifeModel* m_life; + + // + TBranch m_branch; + float m_bMax; + +private: + // The quantitative difference between the worlds + static float worldDif(const World& world1, const World& world2); +}; + +#endif // FLOW_H diff --git a/src/timemodel.cpp b/src/timemodel.cpp index 530088c..d18c0be 100644 --- a/src/timemodel.cpp +++ b/src/timemodel.cpp @@ -1,151 +1,151 @@ -#include "timemodel.h" -#include "world.h" -#include "lifemodel.h" - - -TimeModel::TimeModel() -{ - m_bounds.tMin = 0; - m_bounds.tMax = 0; - m_bounds.bMin = 0; - m_bounds.bMax = 0; - - m_curFlow = -1; - m_curTime = -1; -} - - -int TimeModel::curTime() const -{ - return m_curTime; -} - - -int TimeModel::maxTime() const -{ - return m_bounds.tMax; -} - - -void TimeModel::bigBan(int rows, int cols, int count) -{ - m_readings.clear(); - m_object.clear(); - m_flows.clear(); - m_flows.push_back(new TimeFlow(rows, cols, count)); - m_curTime = -1; - m_curFlow = 0; - m_readings.worldWidth = rows; - m_readings.worldHeight = cols; -} - - -void TimeModel::next() -{ - m_curTime++; - - int tMax = 0; - float bSum = 0; - - // Calc time flows - for (int i=0; itMax() <= m_curTime) flow->next(); - - if (tMax < flow->tMax()) - tMax = flow->tMax(); - - bSum += flow->bMax(); - } - - // Calc tree ranges - m_bounds.tMax = tMax; - m_bounds.bMax = bSum; - - // - // Calc data for control panel - // - m_readings.worldFill = m_flows[m_curFlow]->life()->filling(); - m_readings.leapDifMax = m_flows[m_curFlow]->bMax(); - - // End of loop? - if (m_curTime >= m_readings.leapFrom && m_readings.leapFrom != 0) - { - if (m_readings.state == Readings::inLoop) - { - m_readings.leapDifRoot = m_flows[m_curFlow]->b(m_curTime); - m_readings.leapDifK = m_readings.leapDifRoot / m_readings.leapDifMax; - m_readings.leapRootInvar = m_flows[m_curFlow]->life()->crossObject(m_object); - - // TODO: hardcode to settings - if (m_readings.leapRootInvar > 0.99f) - m_readings.leapType = 1; - else - if (m_readings.leapRootInvar > 0.50f) - m_readings.leapType = 2; - else - m_readings.leapType = 3; - - m_readings.state = Readings::afterLoop; - - emit loopEndEvent(); - } - } - - emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); - emit timeChangeEvent(m_flows, m_bounds); - emit updateReadingsEvent(m_readings); -} - - -void TimeModel::on_chooseObject(int row, int col) -{ - m_flows[m_curFlow]->world(m_curTime).selectObject(row, col, m_object); - - m_readings.objectSizeAbs = m_object.size(); - m_readings.objectSizeRel = float(m_object.size()) / (m_readings.worldWidth * m_readings.worldHeight) * 100.f; - - emit updateReadingsEvent(m_readings); - emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); -} - - -void TimeModel::showPast(int destTime) -{ - m_readings.state = Readings::showPast; - emit worldChangeEvent(m_flows[m_curFlow]->world(destTime), m_object, m_readings.state); - - m_readings.worldFill = m_flows[m_curFlow]->filling(destTime); - m_readings.leapFrom = m_curTime; - m_readings.leapTo = destTime; - m_readings.leapDistance = m_curTime - destTime; - emit updateReadingsEvent(m_readings); -} - - -void TimeModel::gotoPast(int destTime) -{ - m_readings.state = Readings::inLoop; - m_readings.leapDifMax = 0.f; - m_readings.leapDifRoot = 0.f; - emit updateReadingsEvent(m_readings); - - m_flows[m_curFlow]->addLeap(m_curTime, destTime); - m_flows.push_back(new TimeFlow(m_flows[m_curFlow], &m_object, destTime)); - m_curFlow++; - m_curTime = destTime-1; -} - - -float TimeModel::objectSize() const -{ - const World& world = m_flows[m_curFlow]->world(m_curTime); - return (float)m_object.size() / (world.rows() * world.cols()); -} - -void TimeModel::on_switchFlow(int flow) -{ - m_curFlow = flow; - emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); -} +#include "timemodel.h" +#include "world.h" +#include "lifemodel.h" + + +TimeModel::TimeModel() +{ + m_bounds.tMin = 0; + m_bounds.tMax = 0; + m_bounds.bMin = 0; + m_bounds.bMax = 0; + + m_curFlow = -1; + m_curTime = -1; +} + + +int TimeModel::curTime() const +{ + return m_curTime; +} + + +int TimeModel::maxTime() const +{ + return m_bounds.tMax; +} + + +void TimeModel::bigBan(int rows, int cols, int count) +{ + m_readings.clear(); + m_object.clear(); + m_flows.clear(); + m_flows.push_back(new TimeFlow(rows, cols, count)); + m_curTime = -1; + m_curFlow = 0; + m_readings.worldWidth = rows; + m_readings.worldHeight = cols; +} + + +void TimeModel::next() +{ + m_curTime++; + + int tMax = 0; + float bSum = 0; + + // Calc time flows + for (int i=0; itMax() <= m_curTime) flow->next(); + + if (tMax < flow->tMax()) + tMax = flow->tMax(); + + bSum += flow->bMax(); + } + + // Calc tree ranges + m_bounds.tMax = tMax; + m_bounds.bMax = bSum; + + // + // Calc data for control panel + // + m_readings.worldFill = m_flows[m_curFlow]->life()->filling(); + m_readings.leapDifMax = m_flows[m_curFlow]->bMax(); + + // End of loop? + if (m_curTime >= m_readings.leapFrom && m_readings.leapFrom != 0) + { + if (m_readings.state == Readings::inLoop) + { + m_readings.leapDifRoot = m_flows[m_curFlow]->b(m_curTime); + m_readings.leapDifK = m_readings.leapDifRoot / m_readings.leapDifMax; + m_readings.leapRootInvar = m_flows[m_curFlow]->life()->crossObject(m_object); + + // TODO: hardcode to settings + if (m_readings.leapRootInvar > 0.99f) + m_readings.leapType = 1; + else + if (m_readings.leapRootInvar > 0.50f) + m_readings.leapType = 2; + else + m_readings.leapType = 3; + + m_readings.state = Readings::afterLoop; + + emit loopEndEvent(); + } + } + + emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); + emit timeChangeEvent(m_flows, m_bounds); + emit updateReadingsEvent(m_readings); +} + + +void TimeModel::on_chooseObject(int row, int col) +{ + m_flows[m_curFlow]->world(m_curTime).selectObject(row, col, m_object); + + m_readings.objectSizeAbs = m_object.size(); + m_readings.objectSizeRel = float(m_object.size()) / (m_readings.worldWidth * m_readings.worldHeight) * 100.f; + + emit updateReadingsEvent(m_readings); + emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); +} + + +void TimeModel::showPast(int destTime) +{ + m_readings.state = Readings::showPast; + emit worldChangeEvent(m_flows[m_curFlow]->world(destTime), m_object, m_readings.state); + + m_readings.worldFill = m_flows[m_curFlow]->filling(destTime); + m_readings.leapFrom = m_curTime; + m_readings.leapTo = destTime; + m_readings.leapDistance = m_curTime - destTime; + emit updateReadingsEvent(m_readings); +} + + +void TimeModel::gotoPast(int destTime) +{ + m_readings.state = Readings::inLoop; + m_readings.leapDifMax = 0.f; + m_readings.leapDifRoot = 0.f; + emit updateReadingsEvent(m_readings); + + m_flows[m_curFlow]->addLeap(m_curTime, destTime); + m_flows.push_back(new TimeFlow(m_flows[m_curFlow], &m_object, destTime)); + m_curFlow++; + m_curTime = destTime-1; +} + + +float TimeModel::objectSize() const +{ + const World& world = m_flows[m_curFlow]->world(m_curTime); + return (float)m_object.size() / (world.rows() * world.cols()); +} + +void TimeModel::on_switchFlow(int flow) +{ + m_curFlow = flow; + emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); +} diff --git a/src/timemodel.h b/src/timemodel.h index dc4ad54..1d38241 100644 --- a/src/timemodel.h +++ b/src/timemodel.h @@ -1,66 +1,66 @@ -/////////////////////////////////////////////////////////////////////////////// -// TimeModel - multiversum, contains all time flows (time tree) -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef TIMEMODEL_H -#define TIMEMODEL_H -#include -#include -#include "timeflow.h" -#include "world.h" -#include "readings.h" - -class TimeModel : public QObject -{ - Q_OBJECT -public: - typedef QVector TimeFlows; //TODO: smart_ptr - - struct Bounds - { - float tMin; - float tMax; - float bMin; - float bMax; - }; - - TimeModel(); - - // Begin of space and time - void bigBan(int rows, int cols, int count); - // Next step of evolution - void next(); - - void showPast(int destTime); - void gotoPast(int destTime); - - int curTime() const; - int maxTime() const; - - float objectSize() const; - - -signals: - void worldChangeEvent(const World& world, const World::TCells& object, Readings::eStates); - void timeChangeEvent(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); - void loopEndEvent(); - void updateReadingsEvent(const Readings& readings); - -public slots: - void on_chooseObject(int col, int row); - void on_switchFlow(int flow); - -private: - TimeFlows m_flows; - Bounds m_bounds; - int m_curFlow; - int m_curTime; - World::TCells m_object; - Readings m_readings; - -private: - void calcReadings(); -}; -#endif // TIMEMODEL_H +/////////////////////////////////////////////////////////////////////////////// +// TimeModel - multiversum, contains all time flows (time tree) +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef TIMEMODEL_H +#define TIMEMODEL_H +#include +#include +#include "timeflow.h" +#include "world.h" +#include "readings.h" + +class TimeModel : public QObject +{ + Q_OBJECT +public: + typedef QVector TimeFlows; //TODO: smart_ptr + + struct Bounds + { + float tMin; + float tMax; + float bMin; + float bMax; + }; + + TimeModel(); + + // Begin of space and time + void bigBan(int rows, int cols, int count); + // Next step of evolution + void next(); + + void showPast(int destTime); + void gotoPast(int destTime); + + int curTime() const; + int maxTime() const; + + float objectSize() const; + + +signals: + void worldChangeEvent(const World& world, const World::TCells& object, Readings::eStates); + void timeChangeEvent(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); + void loopEndEvent(); + void updateReadingsEvent(const Readings& readings); + +public slots: + void on_chooseObject(int col, int row); + void on_switchFlow(int flow); + +private: + TimeFlows m_flows; + Bounds m_bounds; + int m_curFlow; + int m_curTime; + World::TCells m_object; + Readings m_readings; + +private: + void calcReadings(); +}; +#endif // TIMEMODEL_H diff --git a/src/timeview.cpp b/src/timeview.cpp index e8bb38a..a433510 100644 --- a/src/timeview.cpp +++ b/src/timeview.cpp @@ -1,101 +1,101 @@ -#include "timeview.h" -#include "timemodel.h" -#include "timeflow.h" -#include "settings.h" -#ifdef __LINUX -#include -#include -#endif - -TimeView::TimeView(QWidget *parent) : - QGLWidget(QGLFormat(QGL::SampleBuffers), parent), - m_flows(NULL) -{ -} - - -void TimeView::on_changeTime(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds) -{ - m_flows = &flows; - m_bounds = &bounds; - updateGL(); -} - - -void TimeView::initializeGL() -{ - glDisable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glDisable(GL_COLOR_MATERIAL); - glEnable(GL_BLEND); - glEnable(GL_POLYGON_SMOOTH); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor(0, 0, 0, 0); -} - - -void TimeView::resizeGL(int nWidth, int nHeight) -{ - glViewport(0, 0, nWidth, nHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluOrtho2D(0, nWidth, 0, nHeight); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - - -void TimeView::paintGL() -{ - glClear(GL_COLOR_BUFFER_BIT); - - if (!m_flows || !m_bounds) return; - - float midY = height() * 0.8; - float x_scale = width() / (m_bounds->tMax - m_bounds->tMin); - float yRange = (m_bounds->bMax - m_bounds->bMin); - float y_scale = 0.45 * height() / (yRange > 0 ? yRange : 1); - - int flowNum = 0; - bool inGate = false; - - foreach (const TimeFlow* flow, (*m_flows)) - { - float x, y; - glBegin(GL_LINE_STRIP); - foreach (const TimeFlow::Point5D& point, flow->branch()) - { - if (point.k == TimeFlow::Point5D::leapIn) - { - inGate = true; - x = float(point.t - m_bounds->tMin) * x_scale; - y = float((point.b - yRange*0.3) * -y_scale + midY); - } - else - if (point.k == TimeFlow::Point5D::leapOut) - { - x = float(point.t - m_bounds->tMin) * x_scale; - y = float((point.b - yRange*0.3) * -y_scale + midY); - glVertex2f(x, y); - y = float((point.b - yRange*0.0) * -y_scale + midY); - } - else - { - inGate = false; - x = float(point.t - m_bounds->tMin) * x_scale; - y = float(point.b * -y_scale + midY); - } - - const QColor& color = inGate ? Settings::instance().colorGate : - (flowNum == 0 ? Settings::instance().colorWorld : Settings::instance().colorObjectChoose); - - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glVertex2f(x, y); - } - glEnd(); - - flowNum++; - } - -} - +#include "timeview.h" +#include "timemodel.h" +#include "timeflow.h" +#include "settings.h" +#ifdef __LINUX +#include +#include +#endif + +TimeView::TimeView(QWidget *parent) : + QGLWidget(QGLFormat(QGL::SampleBuffers), parent), + m_flows(NULL) +{ +} + + +void TimeView::on_changeTime(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds) +{ + m_flows = &flows; + m_bounds = &bounds; + updateGL(); +} + + +void TimeView::initializeGL() +{ + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_COLOR_MATERIAL); + glEnable(GL_BLEND); + glEnable(GL_POLYGON_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(0, 0, 0, 0); +} + + +void TimeView::resizeGL(int nWidth, int nHeight) +{ + glViewport(0, 0, nWidth, nHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, nWidth, 0, nHeight); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +void TimeView::paintGL() +{ + glClear(GL_COLOR_BUFFER_BIT); + + if (!m_flows || !m_bounds) return; + + float midY = height() * 0.8; + float x_scale = width() / (m_bounds->tMax - m_bounds->tMin); + float yRange = (m_bounds->bMax - m_bounds->bMin); + float y_scale = 0.45 * height() / (yRange > 0 ? yRange : 1); + + int flowNum = 0; + bool inGate = false; + + foreach (const TimeFlow* flow, (*m_flows)) + { + float x, y; + glBegin(GL_LINE_STRIP); + foreach (const TimeFlow::Point5D& point, flow->branch()) + { + if (point.k == TimeFlow::Point5D::leapIn) + { + inGate = true; + x = float(point.t - m_bounds->tMin) * x_scale; + y = float((point.b - yRange*0.3) * -y_scale + midY); + } + else + if (point.k == TimeFlow::Point5D::leapOut) + { + x = float(point.t - m_bounds->tMin) * x_scale; + y = float((point.b - yRange*0.3) * -y_scale + midY); + glVertex2f(x, y); + y = float((point.b - yRange*0.0) * -y_scale + midY); + } + else + { + inGate = false; + x = float(point.t - m_bounds->tMin) * x_scale; + y = float(point.b * -y_scale + midY); + } + + const QColor& color = inGate ? Settings::instance().colorGate : + (flowNum == 0 ? Settings::instance().colorWorld : Settings::instance().colorObjectChoose); + + glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glVertex2f(x, y); + } + glEnd(); + + flowNum++; + } + +} + diff --git a/src/timeview.h b/src/timeview.h index d188d92..c68f8bf 100644 --- a/src/timeview.h +++ b/src/timeview.h @@ -1,30 +1,30 @@ -/////////////////////////////////////////////////////////////////////////////// -// TimeView - view of time tree (use OpenGL) -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef TIMEVIEW_H -#define TIMEVIEW_H -#include -#include "timemodel.h" - -class TimeView : public QGLWidget -{ - Q_OBJECT -public: - explicit TimeView(QWidget* parent); - -public slots: - void on_changeTime(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); - -private: - void initializeGL(); - void resizeGL(int nWidth, int nHeight); - void paintGL(); - - const TimeModel::TimeFlows* m_flows; - const TimeModel::Bounds* m_bounds; -}; - -#endif // TIMEVIEW_H +/////////////////////////////////////////////////////////////////////////////// +// TimeView - view of time tree (use OpenGL) +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef TIMEVIEW_H +#define TIMEVIEW_H +#include +#include "timemodel.h" + +class TimeView : public QGLWidget +{ + Q_OBJECT +public: + explicit TimeView(QWidget* parent); + +public slots: + void on_changeTime(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); + +private: + void initializeGL(); + void resizeGL(int nWidth, int nHeight); + void paintGL(); + + const TimeModel::TimeFlows* m_flows; + const TimeModel::Bounds* m_bounds; +}; + +#endif // TIMEVIEW_H diff --git a/src/world.cpp b/src/world.cpp index 4eacb37..d7d394e 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,154 +1,154 @@ -#include "world.h" - -World::World() : m_cells(0), m_rows(0), m_cols(0) -{ -} - - -World::World(const World& obj) : m_cells(0), m_rows(0), m_cols(0) -{ - (*this) = obj; -} - - -World::~World() -{ - destroy(); -} - - -const World& World::operator = (const World& rhs) -{ - if (this == &rhs) return (*this); - destroy(); - - init(rhs.m_rows, rhs.m_cols); - - for (int i=0; i= 0 && row < m_rows); - Q_ASSERT(col >= 0 && col < m_cols); - return m_cells[row][col]; -} - - -bool World::cell(int row, int col) const -{ - Q_ASSERT(row >= 0 && row < m_rows); - Q_ASSERT(col >= 0 && col < m_cols); - return m_cells[row][col]; -} - - -World::TCells World::nearest(int row, int col) const -{ - World::TCells cells; - int prevRow = row - 1; if (prevRow < 0) prevRow += rows(); - int prevCol = col - 1; if (prevCol < 0) prevCol += cols(); - - int nextRow = row + 1; if (nextRow >= rows()) nextRow -= rows(); - int nextCol = col + 1; if (nextCol >= cols()) nextCol -= cols(); - - cells << qMakePair(prevRow, prevCol); - cells << qMakePair(prevRow, col); - cells << qMakePair(prevRow, nextCol); - cells << qMakePair(row, prevCol); - cells << qMakePair(row, nextCol); - cells << qMakePair(nextRow, prevCol); - cells << qMakePair(nextRow, col); - cells << qMakePair(nextRow, nextCol); - - return cells; -} - - -void World::selectObject(int row, int col, TCells& object, bool begin) const -{ - if (begin) object.clear(); - - if (object.contains(qMakePair(row, col))) return; - - if (cell(row, col)) - { - object << qMakePair(row, col); - } - else - { - return; - } - - foreach(const TCell& cell, nearest(row, col)) - { - selectObject(cell.first, cell.second, object, false); - } -} - +#include "world.h" + +World::World() : m_cells(0), m_rows(0), m_cols(0) +{ +} + + +World::World(const World& obj) : m_cells(0), m_rows(0), m_cols(0) +{ + (*this) = obj; +} + + +World::~World() +{ + destroy(); +} + + +const World& World::operator = (const World& rhs) +{ + if (this == &rhs) return (*this); + destroy(); + + init(rhs.m_rows, rhs.m_cols); + + for (int i=0; i= 0 && row < m_rows); + Q_ASSERT(col >= 0 && col < m_cols); + return m_cells[row][col]; +} + + +bool World::cell(int row, int col) const +{ + Q_ASSERT(row >= 0 && row < m_rows); + Q_ASSERT(col >= 0 && col < m_cols); + return m_cells[row][col]; +} + + +World::TCells World::nearest(int row, int col) const +{ + World::TCells cells; + int prevRow = row - 1; if (prevRow < 0) prevRow += rows(); + int prevCol = col - 1; if (prevCol < 0) prevCol += cols(); + + int nextRow = row + 1; if (nextRow >= rows()) nextRow -= rows(); + int nextCol = col + 1; if (nextCol >= cols()) nextCol -= cols(); + + cells << qMakePair(prevRow, prevCol); + cells << qMakePair(prevRow, col); + cells << qMakePair(prevRow, nextCol); + cells << qMakePair(row, prevCol); + cells << qMakePair(row, nextCol); + cells << qMakePair(nextRow, prevCol); + cells << qMakePair(nextRow, col); + cells << qMakePair(nextRow, nextCol); + + return cells; +} + + +void World::selectObject(int row, int col, TCells& object, bool begin) const +{ + if (begin) object.clear(); + + if (object.contains(qMakePair(row, col))) return; + + if (cell(row, col)) + { + object << qMakePair(row, col); + } + else + { + return; + } + + foreach(const TCell& cell, nearest(row, col)) + { + selectObject(cell.first, cell.second, object, false); + } +} + diff --git a/src/world.h b/src/world.h index 7d43697..7794416 100644 --- a/src/world.h +++ b/src/world.h @@ -1,45 +1,45 @@ -/////////////////////////////////////////////////////////////////////////////// -// World - cellular 2D world -// -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// -#ifndef WORLD_H -#define WORLD_H -#include -#include - -class World -{ -public: - World(); - World(const World& obj); - ~World(); - - typedef QPair TCell; - typedef QSet TCells; - - const World& operator = (const World& rhs); - - void init(int rows, int cols); - void clear(); - void destroy(); - - int rows() const; - int cols() const; - - bool& cell(int row, int col) ; - bool cell(int row, int col) const; - - // Get 8 neighborhood - TCells nearest(int row, int col) const; - - void selectObject(int row, int col, TCells& object, bool begin=true) const; - -private: - bool** m_cells; - int m_rows; - int m_cols; -}; - -#endif // WORLD_H +/////////////////////////////////////////////////////////////////////////////// +// World - cellular 2D world +// +// Project: "LifeTime" +// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) +/////////////////////////////////////////////////////////////////////////////// +#ifndef WORLD_H +#define WORLD_H +#include +#include + +class World +{ +public: + World(); + World(const World& obj); + ~World(); + + typedef QPair TCell; + typedef QSet TCells; + + const World& operator = (const World& rhs); + + void init(int rows, int cols); + void clear(); + void destroy(); + + int rows() const; + int cols() const; + + bool& cell(int row, int col) ; + bool cell(int row, int col) const; + + // Get 8 neighborhood + TCells nearest(int row, int col) const; + + void selectObject(int row, int col, TCells& object, bool begin=true) const; + +private: + bool** m_cells; + int m_rows; + int m_cols; +}; + +#endif // WORLD_H From 4af3cc3139e1c5b3c3cf862f2dff50576416e2ed Mon Sep 17 00:00:00 2001 From: Illya Kovalevskyy Date: Sun, 12 May 2013 14:03:17 +0300 Subject: [PATCH 3/7] Qt 5 (not full now) and Mac OS X support --- LifeTime.pro | 6 +----- src/lifeview.cpp | 11 ++++++++--- src/main.cpp | 2 +- src/timeview.cpp | 7 ++++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/LifeTime.pro b/LifeTime.pro index df75663..086388c 100644 --- a/LifeTime.pro +++ b/LifeTime.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui opengl +QT += core widgets opengl TARGET = LifeTime TEMPLATE = app @@ -43,7 +43,3 @@ FORMS += src/settingsui.ui \ src/infoui.ui RESOURCES += shared/ui.qrc - -unix:LIBS += -lGLU -unix:DEFINES += __LINUX - diff --git a/src/lifeview.cpp b/src/lifeview.cpp index c24e356..533f10c 100644 --- a/src/lifeview.cpp +++ b/src/lifeview.cpp @@ -2,11 +2,16 @@ #include "lifeview.h" #include "world.h" #include "settings.h" -#ifdef __LINUX + +#ifdef Q_OS_LINUX #include #include #endif +#ifdef Q_OS_MAC +#include +#endif + LifeView::LifeView(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), m_world(NULL), @@ -116,8 +121,8 @@ void LifeView::mousePressEvent(QMouseEvent* event) { if (m_fixObject) return; - int row = int( event->posF().y() / height() * m_world->rows() ); - int col = int( event->posF().x() / width() * m_world->cols() ); + int row = int( event->pos().y() / height() * m_world->rows() ); + int col = int( event->pos().x() / width() * m_world->cols() ); emit chooseObjectEvent(row, col); } diff --git a/src/main.cpp b/src/main.cpp index d951345..597b902 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/src/timeview.cpp b/src/timeview.cpp index a433510..1ae60be 100644 --- a/src/timeview.cpp +++ b/src/timeview.cpp @@ -2,11 +2,16 @@ #include "timemodel.h" #include "timeflow.h" #include "settings.h" -#ifdef __LINUX + +#ifdef Q_OS_LINUX #include #include #endif +#ifdef Q_OS_MAC +#include +#endif + TimeView::TimeView(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), m_flows(NULL) From 48b7b7ae6db533853e142057bb093af17ccc6043 Mon Sep 17 00:00:00 2001 From: Illya Kovalevskyy Date: Thu, 16 May 2013 16:00:38 +0300 Subject: [PATCH 4/7] Visual code changes (Qt Coding Conventions) and Qt 5 porting --- LifeTime.pro | 10 +++++++--- src/infoui.cpp | 8 +++++--- src/infoui.h | 21 ++++++++++++------- src/infoui.ui | 4 ++-- src/lifemodel.cpp | 9 ++++----- src/lifemodel.h | 28 ++++++++++++++++---------- src/lifeview.cpp | 20 +++++++++---------- src/lifeview.h | 30 +++++++++++++++++----------- src/mainwindow.cpp | 50 +++++++++++++++++++++++----------------------- src/mainwindow.h | 41 +++++++++++++++++++------------------ src/readings.h | 12 +++++------ src/settingsui.cpp | 10 +++++++--- src/settingsui.h | 5 ++--- src/timeflow.cpp | 12 +++++------ src/timeflow.h | 21 ++++++++++--------- src/timemodel.cpp | 28 +++++++++++++------------- src/timemodel.h | 19 +++++++++--------- src/timeview.cpp | 26 ++++++++++++------------ src/timeview.h | 7 +++---- src/world.h | 2 +- 20 files changed, 195 insertions(+), 168 deletions(-) diff --git a/LifeTime.pro b/LifeTime.pro index 086388c..ce2358c 100644 --- a/LifeTime.pro +++ b/LifeTime.pro @@ -1,8 +1,12 @@ -#------------------------------------------------- # -# Project created by QtCreator 2013-01-08T00:14:36 +# This file is part of the Supernova IDE +# +# This program is free software licensed under the GNU LGPL. You can +# find a copy of this license in LICENSE in the top directory of +# the source code. +# +# Copyright 2013 Igor Zimaev # -#------------------------------------------------- QT += core widgets opengl diff --git a/src/infoui.cpp b/src/infoui.cpp index c68479c..ca857db 100644 --- a/src/infoui.cpp +++ b/src/infoui.cpp @@ -5,15 +5,17 @@ InfoUI::InfoUI(QWidget *parent) : QDialog(parent), ui(new Ui::InfoUI) { - ui->setupUi(this); + ui->setupUi(this); + connect(ui->closeButton, &QPushButton::clicked, + this, &InfoUI::closeWindow); } InfoUI::~InfoUI() { - delete ui; + delete ui; } -void InfoUI::on_pushButton_clicked() +void InfoUI::closeWindow() { close(); } diff --git a/src/infoui.h b/src/infoui.h index d1e220f..e2388c9 100644 --- a/src/infoui.h +++ b/src/infoui.h @@ -1,9 +1,16 @@ -/////////////////////////////////////////////////////////////////////////////// -// InfoUI - help and about window // -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// +// This file is part of the LifeTime project +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE in the top directory of +// the source code. +// +// Copyright 2013 Igor Zimaev +// Copyright 2013 Illya Kovalevskyy +// + +// InfoUI - help and about window + #ifndef INFOUI_H #define INFOUI_H @@ -21,8 +28,8 @@ class InfoUI : public QDialog explicit InfoUI(QWidget *parent = 0); ~InfoUI(); -private slots: - void on_pushButton_clicked(); +private: + void closeWindow(); private: Ui::InfoUI *ui; diff --git a/src/infoui.ui b/src/infoui.ui index 1ab6fea..ea62cc8 100644 --- a/src/infoui.ui +++ b/src/infoui.ui @@ -13,7 +13,7 @@ Help and About - + 10 @@ -45,7 +45,7 @@ p, li { white-space: pre-wrap; } true - + 200 diff --git a/src/lifemodel.cpp b/src/lifemodel.cpp index 8c8b18d..a6fc9d7 100644 --- a/src/lifemodel.cpp +++ b/src/lifemodel.cpp @@ -31,7 +31,6 @@ void LifeModel::start(int rows, int cols, int count) } } - void LifeModel::setWorld(const World& world) { *m_worldPrev = world; @@ -73,19 +72,19 @@ const World& LifeModel::next() m_worldPrev = m_worldCur; m_worldCur = tmp; - m_filling = float(lifeCount) / (m_worldCur->rows() * m_worldCur->cols()); + m_filling = double(lifeCount) / (m_worldCur->rows() * m_worldCur->cols()); return (*m_worldPrev); } -float LifeModel::filling() const +double LifeModel::filling() const { return m_filling; } -float LifeModel::crossObject(const World::TCells& object) const +double LifeModel::crossObject(const World::TCells& object) const { int countMatch = 0; foreach(const World::TCell& c, object) @@ -93,5 +92,5 @@ float LifeModel::crossObject(const World::TCells& object) const if (m_worldPrev->cell(c.first, c.second)) countMatch++; } - return float(countMatch) / object.size(); + return double(countMatch) / object.size(); } diff --git a/src/lifemodel.h b/src/lifemodel.h index f367f1d..388e603 100644 --- a/src/lifemodel.h +++ b/src/lifemodel.h @@ -1,17 +1,23 @@ -/////////////////////////////////////////////////////////////////////////////// -// LifeModel - world's life calculation, implementation of Conway algorythm // -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// +// This file is part of the LifeTime project +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE in the top directory of +// the source code. +// +// Copyright 2013 Igor Zimaev +// Copyright 2013 Illya Kovalevskyy +// + +// LifeModel - world's life calculation, implementation of Conway algorythm + #ifndef LIFEMODEL_H #define LIFEMODEL_H -#include + #include "world.h" -class LifeModel: public QObject +class LifeModel { - Q_OBJECT public: LifeModel(); ~LifeModel(); @@ -25,15 +31,15 @@ class LifeModel: public QObject const World& next(); // world filling coef. - float filling() const; + double filling() const; // world and object intercross coef. - float crossObject(const World::TCells&) const; + double crossObject(const World::TCells&) const; private: World* m_worldCur; World* m_worldPrev; - float m_filling; + double m_filling; }; #endif // LIFEMODEL_H diff --git a/src/lifeview.cpp b/src/lifeview.cpp index 533f10c..2cc004e 100644 --- a/src/lifeview.cpp +++ b/src/lifeview.cpp @@ -46,7 +46,7 @@ void LifeView::resizeGL(int nWidth, int nHeight) } -void LifeView::on_changeWorld(const World& world, const World::TCells& object, Readings::eStates state) +void LifeView::renderNewWorld(const World& world, const World::TCells& object, Readings::eStates state) { m_world = &world; m_object = &object; @@ -61,15 +61,15 @@ void LifeView::paintGL() if (!m_world) return; - float cellW = (float)width() / m_world->cols(); - float cellH = (float)height() / m_world->rows(); + double cellW = (double)width() / m_world->cols(); + double cellH = (double)height() / m_world->rows(); // const QColor& color = Settings::instance().colorWorld; glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - float y; - float x; + double y; + double x; for (int row=0; row < m_world->rows(); ++row) { for (int col=0; col < m_world->cols(); ++col) @@ -78,8 +78,8 @@ void LifeView::paintGL() { glBegin(GL_POLYGON); - y = cellH*((float)(m_world->rows()-row)); - x = cellW*((float)(col+1)); + y = cellH*((double)(m_world->rows()-row)); + x = cellW*((double)(col+1)); glVertex2f(x, y); glVertex2f(x, y-cellH); @@ -103,8 +103,8 @@ void LifeView::paintGL() { glBegin(GL_POLYGON); - y = cellH*((float)(m_world->rows()-cell.first)); - x = cellW*((float)(cell.second+1)); + y = cellH*((double)(m_world->rows()-cell.first)); + x = cellW*((double)(cell.second+1)); glVertex2f(x, y); glVertex2f(x, y-cellH); @@ -124,7 +124,7 @@ void LifeView::mousePressEvent(QMouseEvent* event) int row = int( event->pos().y() / height() * m_world->rows() ); int col = int( event->pos().x() / width() * m_world->cols() ); - emit chooseObjectEvent(row, col); + emit objectChosen(row, col); } diff --git a/src/lifeview.h b/src/lifeview.h index 7000652..9bf8c0d 100644 --- a/src/lifeview.h +++ b/src/lifeview.h @@ -1,12 +1,19 @@ -/////////////////////////////////////////////////////////////////////////////// -// LifeView - view of world (use OpenGL) // -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// +// This file is part of the LifeTime project +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE in the top directory of +// the source code. +// +// Copyright 2013 Igor Zimaev +// Copyright 2013 Illya Kovalevskyy +// + +// LifeView - view of world #ifndef LIFEVIEW_H #define LIFEVIEW_H + #include #include "world.h" #include "readings.h" @@ -21,21 +28,20 @@ class LifeView : public QGLWidget // Freeze object choose void fixObject(bool fix); - -public slots: - void on_changeWorld(const World& world, const World::TCells& object, Readings::eStates state); + void renderNewWorld(const World& world, const World::TCells& object, Readings::eStates state); signals: - void chooseObjectEvent(int col, int row); + void objectChosen(int col, int row); -private: +protected: void initializeGL(); void resizeGL(int nWidth, int nHeight); void paintGL(); void mousePressEvent(QMouseEvent* event); - const World* m_world; - const World::TCells* m_object; +private: + const World *m_world; + const World::TCells *m_object; bool m_fixObject; Readings::eStates m_state; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b528c28..d15f579 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -39,28 +39,28 @@ MainWindow::MainWindow(QWidget *parent) : // Setup timer // m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(on_render())); + connect(m_timer, &QTimer::timeout, this, &MainWindow::on_render); // // bind models and views // - connect(m_timeModel, SIGNAL(worldChangeEvent(const World&, const World::TCells&, Readings::eStates)), - m_lifeView, SLOT(on_changeWorld(const World&, const World::TCells&, Readings::eStates)) ); + connect(m_timeModel, &TimeModel::worldChanged, + m_lifeView, &LifeView::renderNewWorld); - connect(m_timeModel, SIGNAL(timeChangeEvent(const TimeModel::TimeFlows&, const TimeModel::Bounds&)), - m_timeView, SLOT(on_changeTime(const TimeModel::TimeFlows&, const TimeModel::Bounds&)) ); + connect(m_timeModel, &TimeModel::timeChanged, + m_timeView, &TimeView::renderNewFlow); - connect(m_timeModel, SIGNAL(updateReadingsEvent(const Readings&)), - this, SLOT(on_updateReadings(const Readings&)) ); + connect(m_timeModel, &TimeModel::readingsUpdated, + this, &MainWindow::on_updateReadings); - connect(m_timeModel, SIGNAL(loopEndEvent()), - this, SLOT(on_loopEnd()) ); + connect(m_timeModel, &TimeModel::loopFinished, + this, &MainWindow::on_loopEnd); - connect(m_lifeView, SIGNAL(chooseObjectEvent(int, int)), - m_timeModel, SLOT(on_chooseObject(int, int)) ); + connect(m_lifeView, &LifeView::objectChosen, + m_timeModel, &TimeModel::on_chooseObject); - connect(ui->comboFlow, SIGNAL(currentIndexChanged(int)), - m_timeModel, SLOT(on_switchFlow(int)) ); + connect(ui->comboFlow, static_cast(&QComboBox::currentIndexChanged), + m_timeModel, &TimeModel::on_switchFlow); // run start(); @@ -89,7 +89,7 @@ void MainWindow::start() Settings::instance().worldCols, Settings::instance().worldRows * Settings::instance().worldCols * - (float)Settings::instance().initFilling/100.f); + (double)Settings::instance().initFilling/100.f); if (m_timer->isActive()) m_timer->stop(); m_timer->start(1.0 / Settings::instance().desiredFPS * 1000); @@ -192,29 +192,29 @@ void MainWindow::on_updateReadings(const Readings& readings) void MainWindow::on_loopEnd() { - // only one travel in the past! + // only one travel in past! m_tmBlocked = true; - on_actionPause_triggered(); + pauseSimulation(); } -void MainWindow::on_actionSettings_triggered() +void MainWindow::showSettingsDialog() { bool wasPause = m_pause; - if (!m_pause) on_actionPause_triggered(); + if (!m_pause) pauseSimulation(); SettingsUI dlg; dlg.exec(); - if (!wasPause) on_actionPlay_triggered(); + if (!wasPause) playSimulation(); } -void MainWindow::on_actionRestart_triggered() +void MainWindow::restartSimulation() { start(); } -void MainWindow::on_actionPlay_triggered() +void MainWindow::playSimulation() { m_pause = false; ui->actionPlay->setEnabled(false); @@ -222,7 +222,7 @@ void MainWindow::on_actionPlay_triggered() } -void MainWindow::on_actionPause_triggered() +void MainWindow::pauseSimulation() { m_pause = true; ui->actionPause->setEnabled(false); @@ -230,13 +230,13 @@ void MainWindow::on_actionPause_triggered() } -void MainWindow::on_actionInfo_triggered() +void MainWindow::showInfoDialog() { bool wasPause = m_pause; - if (!m_pause) on_actionPause_triggered(); + if (!m_pause) pauseSimulation(); InfoUI dlg; dlg.exec(); - if (!wasPause) on_actionPlay_triggered(); + if (!wasPause) playSimulation(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index e803740..503c082 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,9 +1,13 @@ -/////////////////////////////////////////////////////////////////////////////// -// MainWindow - main app window // -// Project: "LifeTime" -// Autor: Igor Zimaev (i.zimaev@timeacademy.ru) -/////////////////////////////////////////////////////////////////////////////// +// This file is part of the LifeTime project +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE in the top directory of +// the source code. +// +// Copyright 2013 Igor Zimaev +// + #ifndef MAINWINDOW_H #define MAINWINDOW_H #include @@ -31,7 +35,7 @@ class MainWindow : public QMainWindow explicit MainWindow(QWidget *parent = 0); ~MainWindow(); -private slots: +public: void on_render(); void on_sliderTime_sliderPressed(); void on_sliderTime_valueChanged(int value); @@ -41,13 +45,20 @@ private slots: void on_updateReadings(const Readings&); void on_loopEnd(); - void on_actionSettings_triggered(); - void on_actionRestart_triggered(); - void on_actionPlay_triggered(); - void on_actionPause_triggered(); + void showSettingsDialog(); + void showInfoDialog(); + void restartSimulation(); + void playSimulation(); + void pauseSimulation(); +protected: + void resizeEvent(QResizeEvent* e); - void on_actionInfo_triggered(); +private: + void start(); + bool pause() const; + void setPause(const bool pause); + void enableControls(); private: Ui::MainWindow* ui; @@ -63,14 +74,6 @@ private slots: ReadingsUI m_readingsUI; -private: - void start(); - void resizeEvent(QResizeEvent* e); - - bool pause() const; - void setPause(const bool pause); - - void enableControls(); }; #endif // MAINWINDOW_H diff --git a/src/readings.h b/src/readings.h index 535c148..a2efe0e 100644 --- a/src/readings.h +++ b/src/readings.h @@ -11,10 +11,10 @@ struct Readings { int worldWidth; int worldHeight; - float worldFill; + double worldFill; int objectSizeAbs; - float objectSizeRel; + double objectSizeRel; // TM state enum eStates @@ -31,13 +31,13 @@ struct Readings int leapDistance; // Reality max dif - float leapDifMax; + double leapDifMax; // Reality dif at loop end - float leapDifRoot; + double leapDifRoot; // Coef. of dif stable in root of loop (0 - total fade) - float leapDifK; + double leapDifK; // Invar of object after leap - float leapRootInvar; + double leapRootInvar; // Degree of history change int leapType; diff --git a/src/settingsui.cpp b/src/settingsui.cpp index 5075019..fde4c4a 100644 --- a/src/settingsui.cpp +++ b/src/settingsui.cpp @@ -13,6 +13,12 @@ SettingsUI::SettingsUI(QWidget *parent) : ui->spinWorldRows->setValue(Settings::instance().worldRows); ui->spinDesiredFPS->setValue(Settings::instance().desiredFPS); ui->spinInitFilling->setValue(Settings::instance().initFilling); + + connect(ui->pushOK, &QPushButton::clicked, + this, &SettingsUI::saveSettings); + + connect(ui->pushOK, &QPushButton::clicked, + this, &SettingsUI::close); } SettingsUI::~SettingsUI() @@ -20,12 +26,10 @@ SettingsUI::~SettingsUI() delete ui; } -void SettingsUI::on_pushOK_clicked() +void SettingsUI::saveSettings() { Settings::instance().worldCols = ui->spinWorldCols->value(); Settings::instance().worldRows = ui->spinWorldRows->value(); Settings::instance().desiredFPS = ui->spinDesiredFPS->value(); Settings::instance().initFilling = ui->spinInitFilling->value(); - - close(); } diff --git a/src/settingsui.h b/src/settingsui.h index f08cca9..f4aca4c 100644 --- a/src/settingsui.h +++ b/src/settingsui.h @@ -20,9 +20,8 @@ class SettingsUI : public QDialog public: explicit SettingsUI(QWidget *parent = 0); ~SettingsUI(); - -private slots: - void on_pushOK_clicked(); + + void saveSettings(); private: Ui::SettingsUI *ui; diff --git a/src/timeflow.cpp b/src/timeflow.cpp index 9172c4d..ca04256 100644 --- a/src/timeflow.cpp +++ b/src/timeflow.cpp @@ -83,7 +83,7 @@ void TimeFlow::next() // Second, calc his 5D coords int t = m_past.size()-1; - float b = m_parent ? + double b = m_parent ? (worldDif(world(t), m_parent->world(t))) : 0; // Dif between flow and its parent, and b-coord parent @@ -96,14 +96,14 @@ void TimeFlow::next() } -float TimeFlow::b(int t) const +double TimeFlow::b(int t) const { if (t > m_birthday) return m_branch[t - m_birthday].b; return m_parent->b(t); } -float TimeFlow::filling(int t) const +double TimeFlow::filling(int t) const { Q_ASSERT(t >=0 && t < m_fillings.size()); return m_fillings[t]; @@ -135,7 +135,7 @@ int TimeFlow::tMax() const } -float TimeFlow::bMax() const +double TimeFlow::bMax() const { return m_bMax; } @@ -148,12 +148,12 @@ void TimeFlow::addLeap(int from, int to) } -float TimeFlow::worldDif(const World& world1, const World& world2) +double TimeFlow::worldDif(const World& world1, const World& world2) { Q_ASSERT(world1.rows() == world2.rows()); Q_ASSERT(world1.cols() == world2.cols()); - float dif = 0; + double dif = 0; for (int row=0; row #include "world.h" class LifeModel; - class TimeFlow { public: - // Point of multiversum, t - time axis, b - axis of alternate realities struct Point5D { enum Kind { track, normal, leapIn, leapOut }; int t; - float b; + double b; Kind k; Point5D(){} - Point5D(int time, float branch, Kind kind = normal) + Point5D(int time, double branch, Kind kind = normal) : t(time), b(branch), k(kind) { } @@ -36,7 +35,7 @@ class TimeFlow TimeFlow(int rows, int cols, int count); TimeFlow(const TimeFlow* parent, World::TCells* object, int birthday); TimeFlow(const TimeFlow&); - ~TimeFlow(); + ~TimeFlow(); TimeFlow& operator =(const TimeFlow&); @@ -51,10 +50,10 @@ class TimeFlow const LifeModel* life() const; int tMax() const; - float bMax() const; + double bMax() const; - float b(int t) const; - float filling(int t) const; + double b(int t) const; + double filling(int t) const; private: // Parent flow @@ -65,18 +64,18 @@ class TimeFlow QVector m_past; // FIXME: parallel arrays is bad - QVector m_fillings; + QVector m_fillings; // LifeModel* m_life; // TBranch m_branch; - float m_bMax; + double m_bMax; private: // The quantitative difference between the worlds - static float worldDif(const World& world1, const World& world2); + static double worldDif(const World& world1, const World& world2); }; #endif // FLOW_H diff --git a/src/timemodel.cpp b/src/timemodel.cpp index d18c0be..ed4778e 100644 --- a/src/timemodel.cpp +++ b/src/timemodel.cpp @@ -45,7 +45,7 @@ void TimeModel::next() m_curTime++; int tMax = 0; - float bSum = 0; + double bSum = 0; // Calc time flows for (int i=0; iworld(m_curTime), m_object, m_readings.state); - emit timeChangeEvent(m_flows, m_bounds); - emit updateReadingsEvent(m_readings); + emit worldChanged(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); + emit timeChanged(m_flows, m_bounds); + emit readingsUpdated(m_readings); } @@ -104,23 +104,23 @@ void TimeModel::on_chooseObject(int row, int col) m_flows[m_curFlow]->world(m_curTime).selectObject(row, col, m_object); m_readings.objectSizeAbs = m_object.size(); - m_readings.objectSizeRel = float(m_object.size()) / (m_readings.worldWidth * m_readings.worldHeight) * 100.f; + m_readings.objectSizeRel = double(m_object.size()) / (m_readings.worldWidth * m_readings.worldHeight) * 100.f; - emit updateReadingsEvent(m_readings); - emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); + emit readingsUpdated(m_readings); + emit worldChanged(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); } void TimeModel::showPast(int destTime) { m_readings.state = Readings::showPast; - emit worldChangeEvent(m_flows[m_curFlow]->world(destTime), m_object, m_readings.state); + emit worldChanged(m_flows[m_curFlow]->world(destTime), m_object, m_readings.state); m_readings.worldFill = m_flows[m_curFlow]->filling(destTime); m_readings.leapFrom = m_curTime; m_readings.leapTo = destTime; m_readings.leapDistance = m_curTime - destTime; - emit updateReadingsEvent(m_readings); + emit readingsUpdated(m_readings); } @@ -129,7 +129,7 @@ void TimeModel::gotoPast(int destTime) m_readings.state = Readings::inLoop; m_readings.leapDifMax = 0.f; m_readings.leapDifRoot = 0.f; - emit updateReadingsEvent(m_readings); + emit readingsUpdated(m_readings); m_flows[m_curFlow]->addLeap(m_curTime, destTime); m_flows.push_back(new TimeFlow(m_flows[m_curFlow], &m_object, destTime)); @@ -138,14 +138,14 @@ void TimeModel::gotoPast(int destTime) } -float TimeModel::objectSize() const +double TimeModel::objectSize() const { const World& world = m_flows[m_curFlow]->world(m_curTime); - return (float)m_object.size() / (world.rows() * world.cols()); + return (double)m_object.size() / (world.rows() * world.cols()); } void TimeModel::on_switchFlow(int flow) { m_curFlow = flow; - emit worldChangeEvent(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); + emit worldChanged(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); } diff --git a/src/timemodel.h b/src/timemodel.h index 1d38241..331395d 100644 --- a/src/timemodel.h +++ b/src/timemodel.h @@ -20,10 +20,10 @@ class TimeModel : public QObject struct Bounds { - float tMin; - float tMax; - float bMin; - float bMax; + double tMin; + double tMax; + double bMin; + double bMax; }; TimeModel(); @@ -39,14 +39,13 @@ class TimeModel : public QObject int curTime() const; int maxTime() const; - float objectSize() const; - + double objectSize() const; signals: - void worldChangeEvent(const World& world, const World::TCells& object, Readings::eStates); - void timeChangeEvent(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); - void loopEndEvent(); - void updateReadingsEvent(const Readings& readings); + void worldChanged(const World& world, const World::TCells& object, Readings::eStates); + void timeChanged(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); + void loopFinished(); + void readingsUpdated(const Readings& readings); public slots: void on_chooseObject(int col, int row); diff --git a/src/timeview.cpp b/src/timeview.cpp index 1ae60be..0c6c2ea 100644 --- a/src/timeview.cpp +++ b/src/timeview.cpp @@ -19,7 +19,7 @@ TimeView::TimeView(QWidget *parent) : } -void TimeView::on_changeTime(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds) +void TimeView::renderNewFlow(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds) { m_flows = &flows; m_bounds = &bounds; @@ -56,39 +56,39 @@ void TimeView::paintGL() if (!m_flows || !m_bounds) return; - float midY = height() * 0.8; - float x_scale = width() / (m_bounds->tMax - m_bounds->tMin); - float yRange = (m_bounds->bMax - m_bounds->bMin); - float y_scale = 0.45 * height() / (yRange > 0 ? yRange : 1); + double midY = height() * 0.8; + double x_scale = width() / (m_bounds->tMax - m_bounds->tMin); + double yRange = (m_bounds->bMax - m_bounds->bMin); + double y_scale = 0.45 * height() / (yRange > 0 ? yRange : 1); int flowNum = 0; bool inGate = false; foreach (const TimeFlow* flow, (*m_flows)) { - float x, y; + double x, y; glBegin(GL_LINE_STRIP); foreach (const TimeFlow::Point5D& point, flow->branch()) { if (point.k == TimeFlow::Point5D::leapIn) { inGate = true; - x = float(point.t - m_bounds->tMin) * x_scale; - y = float((point.b - yRange*0.3) * -y_scale + midY); + x = double(point.t - m_bounds->tMin) * x_scale; + y = double((point.b - yRange*0.3) * -y_scale + midY); } else if (point.k == TimeFlow::Point5D::leapOut) { - x = float(point.t - m_bounds->tMin) * x_scale; - y = float((point.b - yRange*0.3) * -y_scale + midY); + x = double(point.t - m_bounds->tMin) * x_scale; + y = double((point.b - yRange*0.3) * -y_scale + midY); glVertex2f(x, y); - y = float((point.b - yRange*0.0) * -y_scale + midY); + y = double((point.b - yRange*0.0) * -y_scale + midY); } else { inGate = false; - x = float(point.t - m_bounds->tMin) * x_scale; - y = float(point.b * -y_scale + midY); + x = double(point.t - m_bounds->tMin) * x_scale; + y = double(point.b * -y_scale + midY); } const QColor& color = inGate ? Settings::instance().colorGate : diff --git a/src/timeview.h b/src/timeview.h index c68f8bf..f93f931 100644 --- a/src/timeview.h +++ b/src/timeview.h @@ -14,15 +14,14 @@ class TimeView : public QGLWidget Q_OBJECT public: explicit TimeView(QWidget* parent); + void renderNewFlow(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); -public slots: - void on_changeTime(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); - -private: +protected: void initializeGL(); void resizeGL(int nWidth, int nHeight); void paintGL(); +private: const TimeModel::TimeFlows* m_flows; const TimeModel::Bounds* m_bounds; }; diff --git a/src/world.h b/src/world.h index 7794416..7cb571f 100644 --- a/src/world.h +++ b/src/world.h @@ -37,7 +37,7 @@ class World void selectObject(int row, int col, TCells& object, bool begin=true) const; private: - bool** m_cells; + bool **m_cells; int m_rows; int m_cols; }; From 209edb6a882d5f24af53fb8f096d77634ead5168 Mon Sep 17 00:00:00 2001 From: "TimeCoder (Igor Zimaev)" Date: Tue, 21 May 2013 03:11:57 +0700 Subject: [PATCH 5/7] rename slots, fix win-compilation --- src/infoui.h | 2 +- src/lifeview.cpp | 6 +++++- src/lifeview.h | 2 +- src/mainwindow.cpp | 6 +++--- src/mainwindow.h | 2 +- src/readingsui.h | 2 +- src/timeflow.h | 4 ++-- src/timemodel.cpp | 14 ++++++++------ src/timemodel.h | 4 ++-- src/timeview.cpp | 4 ++++ 10 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/infoui.h b/src/infoui.h index e2388c9..168e173 100644 --- a/src/infoui.h +++ b/src/infoui.h @@ -28,7 +28,7 @@ class InfoUI : public QDialog explicit InfoUI(QWidget *parent = 0); ~InfoUI(); -private: +protected: void closeWindow(); private: diff --git a/src/lifeview.cpp b/src/lifeview.cpp index 2cc004e..29cdc4b 100644 --- a/src/lifeview.cpp +++ b/src/lifeview.cpp @@ -8,6 +8,10 @@ #include #endif +#ifdef Q_OS_WIN +#include +#endif + #ifdef Q_OS_MAC #include #endif @@ -124,7 +128,7 @@ void LifeView::mousePressEvent(QMouseEvent* event) int row = int( event->pos().y() / height() * m_world->rows() ); int col = int( event->pos().x() / width() * m_world->cols() ); - emit objectChosen(row, col); + emit cellActivated(row, col); } diff --git a/src/lifeview.h b/src/lifeview.h index 9bf8c0d..91577d9 100644 --- a/src/lifeview.h +++ b/src/lifeview.h @@ -31,7 +31,7 @@ class LifeView : public QGLWidget void renderNewWorld(const World& world, const World::TCells& object, Readings::eStates state); signals: - void objectChosen(int col, int row); + void cellActivated(int col, int row); protected: void initializeGL(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d15f579..8698563 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -56,11 +56,11 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_timeModel, &TimeModel::loopFinished, this, &MainWindow::on_loopEnd); - connect(m_lifeView, &LifeView::objectChosen, - m_timeModel, &TimeModel::on_chooseObject); + connect(m_lifeView, &LifeView::cellActivated, + m_timeModel, &TimeModel::chooseObject); connect(ui->comboFlow, static_cast(&QComboBox::currentIndexChanged), - m_timeModel, &TimeModel::on_switchFlow); + m_timeModel, &TimeModel::switchFlow); // run start(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 503c082..50cc18c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -22,7 +22,7 @@ class TimeModel; class LifeView; class TimeView; class QTreeWidgetItem; -class Readings; +struct Readings; class QTimer; // diff --git a/src/readingsui.h b/src/readingsui.h index aa63119..c50c76a 100644 --- a/src/readingsui.h +++ b/src/readingsui.h @@ -7,7 +7,7 @@ #ifndef READINGSUI_H #define READINGSUI_H -class Readings; +struct Readings; class QTreeWidget; class QTreeWidgetItem; diff --git a/src/timeflow.h b/src/timeflow.h index 4ae8cfc..44dcf5e 100644 --- a/src/timeflow.h +++ b/src/timeflow.h @@ -64,14 +64,14 @@ class TimeFlow QVector m_past; // FIXME: parallel arrays is bad - QVector m_fillings; + QVector m_fillings; // LifeModel* m_life; // TBranch m_branch; - double m_bMax; + double m_bMax; private: // The quantitative difference between the worlds diff --git a/src/timemodel.cpp b/src/timemodel.cpp index ed4778e..1cacdb7 100644 --- a/src/timemodel.cpp +++ b/src/timemodel.cpp @@ -99,7 +99,7 @@ void TimeModel::next() } -void TimeModel::on_chooseObject(int row, int col) +void TimeModel::chooseObject(int row, int col) { m_flows[m_curFlow]->world(m_curTime).selectObject(row, col, m_object); @@ -111,6 +111,13 @@ void TimeModel::on_chooseObject(int row, int col) } +void TimeModel::switchFlow(int flow) +{ + m_curFlow = flow; + emit worldChanged(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); +} + + void TimeModel::showPast(int destTime) { m_readings.state = Readings::showPast; @@ -144,8 +151,3 @@ double TimeModel::objectSize() const return (double)m_object.size() / (world.rows() * world.cols()); } -void TimeModel::on_switchFlow(int flow) -{ - m_curFlow = flow; - emit worldChanged(m_flows[m_curFlow]->world(m_curTime), m_object, m_readings.state); -} diff --git a/src/timemodel.h b/src/timemodel.h index 331395d..6df7396 100644 --- a/src/timemodel.h +++ b/src/timemodel.h @@ -48,8 +48,8 @@ class TimeModel : public QObject void readingsUpdated(const Readings& readings); public slots: - void on_chooseObject(int col, int row); - void on_switchFlow(int flow); + void chooseObject(int col, int row); + void switchFlow(int flow); private: TimeFlows m_flows; diff --git a/src/timeview.cpp b/src/timeview.cpp index 0c6c2ea..27ae34a 100644 --- a/src/timeview.cpp +++ b/src/timeview.cpp @@ -8,6 +8,10 @@ #include #endif +#ifdef Q_OS_WIN +#include +#endif + #ifdef Q_OS_MAC #include #endif From 8b8675699686679732423a5d4690f5b7c2f500c3 Mon Sep 17 00:00:00 2001 From: "TimeCoder (Igor Zimaev)" Date: Sun, 26 May 2013 23:08:28 +0700 Subject: [PATCH 6/7] Using QPainter instead OpenGL API + rename some methods + improvement of TimeFlow class --- src/lifemodel.h | 4 +- src/lifeview.cpp | 110 ++++++++++++++++--------------------------- src/lifeview.h | 14 ++++-- src/mainwindow.cpp | 45 +++++++++++------- src/mainwindow.h | 23 +++++---- src/readings.h | 3 +- src/timeflow.cpp | 13 ++++-- src/timeflow.h | 23 ++++++--- src/timemodel.cpp | 2 +- src/timeview.cpp | 114 +++++++++++++++++++-------------------------- src/timeview.h | 11 +++-- 11 files changed, 177 insertions(+), 185 deletions(-) diff --git a/src/lifemodel.h b/src/lifemodel.h index 388e603..13b4e4b 100644 --- a/src/lifemodel.h +++ b/src/lifemodel.h @@ -37,8 +37,8 @@ class LifeModel double crossObject(const World::TCells&) const; private: - World* m_worldCur; - World* m_worldPrev; + World* m_worldCur; + World* m_worldPrev; double m_filling; }; diff --git a/src/lifeview.cpp b/src/lifeview.cpp index 29cdc4b..647bec6 100644 --- a/src/lifeview.cpp +++ b/src/lifeview.cpp @@ -1,20 +1,10 @@ +#include +#include #include #include "lifeview.h" #include "world.h" #include "settings.h" -#ifdef Q_OS_LINUX -#include -#include -#endif - -#ifdef Q_OS_WIN -#include -#endif - -#ifdef Q_OS_MAC -#include -#endif LifeView::LifeView(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), @@ -24,53 +14,44 @@ LifeView::LifeView(QWidget *parent) : m_state(Readings::showPast) { + m_backBrush = QBrush(QColor(0, 0, 0)); + m_cellsBrush = QBrush(Settings::instance().colorWorld); + m_objectBrush[Readings::showPast] = QBrush(Settings::instance().colorObjectChoose); + m_objectBrush[Readings::inLoop] = QBrush(Settings::instance().colorObjectGhost); + m_objectBrush[Readings::afterLoop] = QBrush(Settings::instance().colorObjectFinal); } -void LifeView::initializeGL() -{ - glDisable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glDisable(GL_COLOR_MATERIAL); - glEnable(GL_BLEND); - glEnable(GL_POLYGON_SMOOTH); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor(0, 0, 0, 0); -} - - -void LifeView::resizeGL(int nWidth, int nHeight) +void LifeView::renderWorld(const World& world, const World::TCells& object, Readings::eStates state) { - glViewport(0, 0, nWidth, nHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluOrtho2D(0, nWidth, 0, nHeight); // set origin to bottom left corner - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + m_world = &world; + m_object = &object; + m_state = state; + repaint(); } -void LifeView::renderNewWorld(const World& world, const World::TCells& object, Readings::eStates state) +void LifeView::paintEvent(QPaintEvent*) { - m_world = &world; - m_object = &object; - m_state = state; - updateGL(); + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing); + doPaint(painter); + painter.end(); } -void LifeView::paintGL() +void LifeView::doPaint(QPainter& painter) { - glClear(GL_COLOR_BUFFER_BIT); + painter.fillRect(0, 0, width(), height(), m_backBrush); if (!m_world) return; - double cellW = (double)width() / m_world->cols(); - double cellH = (double)height() / m_world->rows(); + double cellW = double(width()) / m_world->cols(); + double cellH = double(height()) / m_world->rows(); // - const QColor& color = Settings::instance().colorWorld; - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + QVector cellsRects; double y; double x; @@ -80,58 +61,49 @@ void LifeView::paintGL() { if (m_world->cell(row, col)) { - glBegin(GL_POLYGON); + y = cellH*((double)row); + x = cellW*((double)(col)); - y = cellH*((double)(m_world->rows()-row)); - x = cellW*((double)(col+1)); - - glVertex2f(x, y); - glVertex2f(x, y-cellH); - glVertex2f(x-cellW, y-cellH); - glVertex2f(x-cellW, y); - - glEnd(); + cellsRects << QRectF(x, y, cellW, cellH); } } } // + QVector objRects; + if (m_object) { - const QColor& color = (m_state == Readings::showPast ? Settings::instance().colorObjectChoose : - (m_state == Readings::inLoop ? Settings::instance().colorObjectGhost : Settings::instance().colorObjectFinal)); - - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - foreach(const World::TCell& cell, (*m_object)) { - glBegin(GL_POLYGON); - - y = cellH*((double)(m_world->rows()-cell.first)); - x = cellW*((double)(cell.second+1)); + y = cellH*((double)cell.first); + x = cellW*((double)(cell.second)); - glVertex2f(x, y); - glVertex2f(x, y-cellH); - glVertex2f(x-cellW, y-cellH); - glVertex2f(x-cellW, y); - - glEnd(); + objRects << QRectF(x, y, cellW, cellH); } } + + painter.setBrush(m_cellsBrush); + painter.drawRects(cellsRects); + + painter.setBrush(m_objectBrush[m_state]); + painter.drawRects(objRects); } + void LifeView::mousePressEvent(QMouseEvent* event) { if (m_fixObject) return; - int row = int( event->pos().y() / height() * m_world->rows() ); - int col = int( event->pos().x() / width() * m_world->cols() ); + int row = int( (double)event->pos().y() / height() * m_world->rows() ); + int col = int( (double)event->pos().x() / width() * m_world->cols() ); emit cellActivated(row, col); } + void LifeView::fixObject(bool fix) { m_fixObject = fix; diff --git a/src/lifeview.h b/src/lifeview.h index 91577d9..72886a4 100644 --- a/src/lifeview.h +++ b/src/lifeview.h @@ -19,6 +19,8 @@ #include "readings.h" class QMouseEvent; +class QPaintEvent; + class LifeView : public QGLWidget { @@ -28,15 +30,14 @@ class LifeView : public QGLWidget // Freeze object choose void fixObject(bool fix); - void renderNewWorld(const World& world, const World::TCells& object, Readings::eStates state); + void renderWorld(const World& world, const World::TCells& object, Readings::eStates state); signals: void cellActivated(int col, int row); protected: - void initializeGL(); - void resizeGL(int nWidth, int nHeight); - void paintGL(); + void paintEvent(QPaintEvent *event); + void doPaint(QPainter& painter); void mousePressEvent(QMouseEvent* event); private: @@ -44,6 +45,11 @@ class LifeView : public QGLWidget const World::TCells *m_object; bool m_fixObject; Readings::eStates m_state; + + QBrush m_backBrush; + QBrush m_cellsBrush; + QBrush m_objectBrush[Readings::statesCount]; + }; #endif // LIFEVIEW_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8698563..946cdd2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -35,26 +35,39 @@ MainWindow::MainWindow(QWidget *parent) : ui->comboFlow->addItem("r1 - branch"); ui->comboFlow->setCurrentIndex(0); + connect(ui->btnOn, &QAbstractButton::clicked, this, &MainWindow::timeMachineOn); + connect(ui->btnLeap, &QAbstractButton::clicked, this, &MainWindow::timeLeap); + + connect(ui->sliderTime, &QSlider::sliderPressed, this, &MainWindow::enableControls); + connect(ui->sliderTime, &QSlider::valueChanged, this, &MainWindow::showPast); + connect(ui->sliderTime, &QSlider::sliderReleased, this, &MainWindow::timeMachineReady); + + connect(ui->actionSettings, &QAction::triggered, this, &MainWindow::showSettingsDialog); + connect(ui->actionInfo, &QAction::triggered, this, &MainWindow::showInfoDialog); + connect(ui->actionRestart, &QAction::triggered, this, &MainWindow::restartSimulation); + connect(ui->actionPlay, &QAction::triggered, this, &MainWindow::playSimulation); + connect(ui->actionPause, &QAction::triggered, this, &MainWindow::pauseSimulation); + // // Setup timer // m_timer = new QTimer(this); - connect(m_timer, &QTimer::timeout, this, &MainWindow::on_render); + connect(m_timer, &QTimer::timeout, this, &MainWindow::renderNext); // // bind models and views // connect(m_timeModel, &TimeModel::worldChanged, - m_lifeView, &LifeView::renderNewWorld); + m_lifeView, &LifeView::renderWorld); connect(m_timeModel, &TimeModel::timeChanged, - m_timeView, &TimeView::renderNewFlow); + m_timeView, &TimeView::renderFlows); connect(m_timeModel, &TimeModel::readingsUpdated, - this, &MainWindow::on_updateReadings); + this, &MainWindow::updateReadings); connect(m_timeModel, &TimeModel::loopFinished, - this, &MainWindow::on_loopEnd); + this, &MainWindow::timeMachineLock); connect(m_lifeView, &LifeView::cellActivated, m_timeModel, &TimeModel::chooseObject); @@ -116,7 +129,7 @@ void MainWindow::setPause(const bool pause) } -void MainWindow::on_render() +void MainWindow::renderNext() { if (!m_pause && !m_tmOn) { @@ -144,7 +157,7 @@ void MainWindow::enableControls() } -void MainWindow::on_btnOn_clicked() +void MainWindow::timeMachineOn() { ui->sliderTime->setMaximum(m_timeModel->curTime()); ui->sliderTime->setValue(m_timeModel->curTime()); @@ -154,27 +167,23 @@ void MainWindow::on_btnOn_clicked() } -void MainWindow::on_sliderTime_sliderPressed() -{ - enableControls(); -} -void MainWindow::on_sliderTime_valueChanged(int value) +void MainWindow::showPast(int time) { - m_timeModel->showPast(value); - ui->lcd1->display(value); + m_timeModel->showPast(time); + ui->lcd1->display(time); } -void MainWindow::on_sliderTime_sliderReleased() +void MainWindow::timeMachineReady() { m_choosedTime = true; enableControls(); } -void MainWindow::on_btnLeap_clicked() +void MainWindow::timeLeap() { m_timeModel->gotoPast(ui->sliderTime->value()); m_tmOn = false; @@ -182,7 +191,7 @@ void MainWindow::on_btnLeap_clicked() } -void MainWindow::on_updateReadings(const Readings& readings) +void MainWindow::updateReadings(const Readings& readings) { m_choosedObject = (readings.objectSizeAbs > 0); m_readingsUI.update(readings); @@ -190,7 +199,7 @@ void MainWindow::on_updateReadings(const Readings& readings) } -void MainWindow::on_loopEnd() +void MainWindow::timeMachineLock() { // only one travel in past! m_tmBlocked = true; diff --git a/src/mainwindow.h b/src/mainwindow.h index 50cc18c..9f75790 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -35,15 +35,16 @@ class MainWindow : public QMainWindow explicit MainWindow(QWidget *parent = 0); ~MainWindow(); -public: - void on_render(); - void on_sliderTime_sliderPressed(); - void on_sliderTime_valueChanged(int value); - void on_sliderTime_sliderReleased(); - void on_btnLeap_clicked(); - void on_btnOn_clicked(); - void on_updateReadings(const Readings&); - void on_loopEnd(); +protected slots: + void renderNext(); + void timeMachineOn(); + void timeMachineReady(); + void timeMachineLock(); + + void showPast(int time); + void timeLeap(); + + void updateReadings(const Readings&); void showSettingsDialog(); void showInfoDialog(); @@ -51,6 +52,8 @@ class MainWindow : public QMainWindow void playSimulation(); void pauseSimulation(); + void enableControls(); + protected: void resizeEvent(QResizeEvent* e); @@ -58,7 +61,7 @@ class MainWindow : public QMainWindow void start(); bool pause() const; void setPause(const bool pause); - void enableControls(); + private: Ui::MainWindow* ui; diff --git a/src/readings.h b/src/readings.h index a2efe0e..248a4a2 100644 --- a/src/readings.h +++ b/src/readings.h @@ -21,7 +21,8 @@ struct Readings { showPast, inLoop, - afterLoop + afterLoop, + statesCount }; eStates state; diff --git a/src/timeflow.cpp b/src/timeflow.cpp index ca04256..4fd4af5 100644 --- a/src/timeflow.cpp +++ b/src/timeflow.cpp @@ -141,10 +141,17 @@ double TimeFlow::bMax() const } -void TimeFlow::addLeap(int from, int to) +void TimeFlow::setLeap(int from, int to) { - m_branch.push_back(Point5D(from, b(from), Point5D::leapIn)); - m_branch.push_back(Point5D(to, b(to), Point5D::leapOut)); + m_leapInfo.was = true; + m_leapInfo.from = Point5D(from, b(from)); + m_leapInfo.to = Point5D(to, b(to)); +} + + +const TimeFlow::LeapInfo& TimeFlow::leap() const +{ + return m_leapInfo; } diff --git a/src/timeflow.h b/src/timeflow.h index 44dcf5e..eae8819 100644 --- a/src/timeflow.h +++ b/src/timeflow.h @@ -18,17 +18,23 @@ class TimeFlow // Point of multiversum, t - time axis, b - axis of alternate realities struct Point5D { - enum Kind { track, normal, leapIn, leapOut }; - - int t; + int t; double b; - Kind k; Point5D(){} - Point5D(int time, double branch, Kind kind = normal) - : t(time), b(branch), k(kind) + Point5D(int time, double branch) + : t(time), b(branch) { } }; + + struct LeapInfo + { + bool was; + Point5D from; + Point5D to; + LeapInfo() : was(false) {} + }; + typedef QVector TBranch; TimeFlow(); @@ -43,7 +49,8 @@ class TimeFlow void next(); // Add tonnel in past - void addLeap(int from, int to); + void setLeap(int from, int to); + const LeapInfo& leap() const; const TBranch& branch() const; const World& world(int time) const; @@ -73,6 +80,8 @@ class TimeFlow TBranch m_branch; double m_bMax; + LeapInfo m_leapInfo; + private: // The quantitative difference between the worlds static double worldDif(const World& world1, const World& world2); diff --git a/src/timemodel.cpp b/src/timemodel.cpp index 1cacdb7..503aad5 100644 --- a/src/timemodel.cpp +++ b/src/timemodel.cpp @@ -138,7 +138,7 @@ void TimeModel::gotoPast(int destTime) m_readings.leapDifRoot = 0.f; emit readingsUpdated(m_readings); - m_flows[m_curFlow]->addLeap(m_curTime, destTime); + m_flows[m_curFlow]->setLeap(m_curTime, destTime); m_flows.push_back(new TimeFlow(m_flows[m_curFlow], &m_object, destTime)); m_curFlow++; m_curTime = destTime-1; diff --git a/src/timeview.cpp b/src/timeview.cpp index 27ae34a..f312f02 100644 --- a/src/timeview.cpp +++ b/src/timeview.cpp @@ -3,108 +3,90 @@ #include "timeflow.h" #include "settings.h" -#ifdef Q_OS_LINUX -#include -#include -#endif - -#ifdef Q_OS_WIN -#include -#endif - -#ifdef Q_OS_MAC -#include -#endif TimeView::TimeView(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), m_flows(NULL) { + m_backBrush = QBrush(QColor(0, 0, 0)); + m_curvePens[trunk] = QPen(Settings::instance().colorWorld, 1.5); + m_curvePens[canal] = QPen(Settings::instance().colorGate, 1.5); + m_curvePens[branch] = QPen(Settings::instance().colorObjectChoose, 1.5); } -void TimeView::renderNewFlow(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds) +void TimeView::renderFlows(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds) { m_flows = &flows; m_bounds = &bounds; - updateGL(); + repaint(); } -void TimeView::initializeGL() +void TimeView::paintEvent(QPaintEvent*) { - glDisable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glDisable(GL_COLOR_MATERIAL); - glEnable(GL_BLEND); - glEnable(GL_POLYGON_SMOOTH); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor(0, 0, 0, 0); + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing); + doPaint(painter); + painter.end(); } -void TimeView::resizeGL(int nWidth, int nHeight) +void TimeView::doPaint(QPainter& painter) { - glViewport(0, 0, nWidth, nHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluOrtho2D(0, nWidth, 0, nHeight); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - - -void TimeView::paintGL() -{ - glClear(GL_COLOR_BUFFER_BIT); + painter.fillRect(0, 0, width(), height(), m_backBrush); if (!m_flows || !m_bounds) return; - double midY = height() * 0.8; + double midY = height() * 0.2; double x_scale = width() / (m_bounds->tMax - m_bounds->tMin); double yRange = (m_bounds->bMax - m_bounds->bMin); double y_scale = 0.45 * height() / (yRange > 0 ? yRange : 1); int flowNum = 0; - bool inGate = false; + QVector curve; foreach (const TimeFlow* flow, (*m_flows)) { double x, y; - glBegin(GL_LINE_STRIP); + curve.clear(); + foreach (const TimeFlow::Point5D& point, flow->branch()) { - if (point.k == TimeFlow::Point5D::leapIn) - { - inGate = true; - x = double(point.t - m_bounds->tMin) * x_scale; - y = double((point.b - yRange*0.3) * -y_scale + midY); - } - else - if (point.k == TimeFlow::Point5D::leapOut) - { - x = double(point.t - m_bounds->tMin) * x_scale; - y = double((point.b - yRange*0.3) * -y_scale + midY); - glVertex2f(x, y); - y = double((point.b - yRange*0.0) * -y_scale + midY); - } - else - { - inGate = false; - x = double(point.t - m_bounds->tMin) * x_scale; - y = double(point.b * -y_scale + midY); - } - - const QColor& color = inGate ? Settings::instance().colorGate : - (flowNum == 0 ? Settings::instance().colorWorld : Settings::instance().colorObjectChoose); - - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glVertex2f(x, y); + x = double(point.t - m_bounds->tMin) * x_scale; + y = double(point.b * y_scale + midY); + curve << QPointF(x, y); + } + + painter.setPen(m_curvePens[flowNum == 0 ? trunk : branch]); + painter.drawPolyline(curve); + + TimeFlow::LeapInfo leap = flow->leap(); + + if (leap.was) + { + curve.clear(); + + x = double(leap.from.t - m_bounds->tMin) * x_scale; + y = double(leap.from.b * y_scale + midY); + curve << QPointF(x, y); + + y = double((leap.from.b - yRange*0.3) * y_scale + midY); + curve << QPointF(x, y); + + x = double(leap.to.t - m_bounds->tMin) * x_scale; + y = double((leap.to.b - yRange*0.3) * y_scale + midY); + curve << QPointF(x, y); + + y = double(leap.to.b * y_scale + midY); + curve << QPointF(x, y); + + painter.setPen(m_curvePens[canal]); + painter.drawPolyline(curve); } - glEnd(); flowNum++; } - } diff --git a/src/timeview.h b/src/timeview.h index f93f931..f07b571 100644 --- a/src/timeview.h +++ b/src/timeview.h @@ -14,16 +14,19 @@ class TimeView : public QGLWidget Q_OBJECT public: explicit TimeView(QWidget* parent); - void renderNewFlow(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); + void renderFlows(const TimeModel::TimeFlows& flows, const TimeModel::Bounds& bounds); protected: - void initializeGL(); - void resizeGL(int nWidth, int nHeight); - void paintGL(); + void paintEvent(QPaintEvent *event); + void doPaint(QPainter& painter); private: const TimeModel::TimeFlows* m_flows; const TimeModel::Bounds* m_bounds; + QBrush m_backBrush; + + enum { trunk, canal, branch, count }; + QPen m_curvePens[count]; }; #endif // TIMEVIEW_H From 35c506005f912948e331ab43d34d400ad51f60eb Mon Sep 17 00:00:00 2001 From: Illya Kovalevskyy Date: Tue, 17 Dec 2013 22:46:48 +0200 Subject: [PATCH 7/7] Unused method removed --- src/infoui.cpp | 7 +------ src/infoui.h | 3 --- src/mainwindow.h | 3 ++- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/infoui.cpp b/src/infoui.cpp index ca857db..b236cc7 100644 --- a/src/infoui.cpp +++ b/src/infoui.cpp @@ -7,15 +7,10 @@ InfoUI::InfoUI(QWidget *parent) : { ui->setupUi(this); connect(ui->closeButton, &QPushButton::clicked, - this, &InfoUI::closeWindow); + this, &InfoUI::close); } InfoUI::~InfoUI() { delete ui; } - -void InfoUI::closeWindow() -{ - close(); -} diff --git a/src/infoui.h b/src/infoui.h index 168e173..32fc872 100644 --- a/src/infoui.h +++ b/src/infoui.h @@ -27,9 +27,6 @@ class InfoUI : public QDialog public: explicit InfoUI(QWidget *parent = 0); ~InfoUI(); - -protected: - void closeWindow(); private: Ui::InfoUI *ui; diff --git a/src/mainwindow.h b/src/mainwindow.h index 9f75790..18d2408 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -18,11 +18,12 @@ namespace Ui { class MainWindow; } +struct Readings; class TimeModel; class LifeView; class TimeView; + class QTreeWidgetItem; -struct Readings; class QTimer; //