diff --git a/Otarcik_CAN/Sources/GeneralMessagesLogDispatcher.cpp b/Otarcik_CAN/Sources/GeneralMessagesLogDispatcher.cpp new file mode 100644 index 0000000..65d316b --- /dev/null +++ b/Otarcik_CAN/Sources/GeneralMessagesLogDispatcher.cpp @@ -0,0 +1,83 @@ +#include "GeneralMessagesLogDispatcher.h" + + + +//singleton instantiation +CGeneralMessagesLogDispatcher CGeneralMessagesLogDispatcher::mSingleton; + + +CGeneralMessagesLogDispatcher::CGeneralMessagesLogDispatcher() +{ + mGeneralStatusPageHandle = 0; + + mNbLinesInGUILog = 0; + +} + +CGeneralMessagesLogDispatcher::~CGeneralMessagesLogDispatcher() +{ + +} + +int CGeneralMessagesLogDispatcher::AddLogMessage(QString LogLine, bool AddToGUILogPanel) +{ + //TODO: Add text to log file... + + LogLine.remove('\n'); + LogLine.remove('\r'); + LogLine.append('\n'); + + + + if(AddToGUILogPanel == true) + { + if(mNbLinesInGUILog == GENERAL_MESSAGES_MAX_LOG_LINES) + { + //Make shure we are able to remove first line + int FirstLineLength = mGeneralMsgGUILog.indexOf(QChar('\n')); + if(FirstLineLength != -1) + { + mGeneralMsgGUILog.remove(0,FirstLineLength+1); + mGeneralMsgGUILog.append(LogLine); + } + else + { + qDebug("Something fucked-up happened in CGeneralMessagesLogDispatch::AddLogMessage"); + return RET_GENERAL_ERROR; + } + } + else + { + mGeneralMsgGUILog.append(LogLine); + mNbLinesInGUILog++; + } + + if(mGeneralStatusPageHandle != 0) + { + mGeneralStatusPageHandle->SetGeneralMsgText(mGeneralMsgGUILog); + } + else + { + qDebug("Someone forgot to assing their pointers in CGeneralMessagesLogDispatch::AddLogMessage!! This needs to be fixed"); + return RET_GENERAL_ERROR; + } + + } + + return RET_OK; +} + +int CGeneralMessagesLogDispatcher::BindGuiPageHandle(CGeneralStatusPage *Handle) +{ + if(Handle == 0) + { + return RET_GENERAL_ERROR; + } + else + { + mGeneralStatusPageHandle = Handle; + } + + return RET_OK; + +} diff --git a/Otarcik_CAN/Sources/GeneralMessagesLogDispatcher.h b/Otarcik_CAN/Sources/GeneralMessagesLogDispatcher.h new file mode 100644 index 0000000..4cd1109 --- /dev/null +++ b/Otarcik_CAN/Sources/GeneralMessagesLogDispatcher.h @@ -0,0 +1,30 @@ +#ifndef GENERALMESSAGESLOGDISPATCHER_H +#define GENERALMESSAGESLOGDISPATCHER_H + +#include +#include "defines.h" +#include "GeneralStatusPage.h" + + +class CGeneralMessagesLogDispatcher +{ +public: + + //CGeneralMessagesLogDispatcher is a singleton class + static CGeneralMessagesLogDispatcher* instance(){return &mSingleton;} + static CGeneralMessagesLogDispatcher mSingleton; + + CGeneralMessagesLogDispatcher(); + virtual ~CGeneralMessagesLogDispatcher(); + + int AddLogMessage(QString LogLine, bool AddToGUILogPanel = true); + CGeneralStatusPage *mGeneralStatusPageHandle; + int BindGuiPageHandle(CGeneralStatusPage *Handle); + +private: + QString mGeneralMsgGUILog; + unsigned int mNbLinesInGUILog; //Keep the count of lines displayed in the GUI so we don't EVER buffer overrun + +}; + +#endif // GENERALMESSAGESLOGDISPATCHER_H diff --git a/Otarcik_CAN/Sources/Gui/GeneralStatusPage.cpp b/Otarcik_CAN/Sources/Gui/GeneralStatusPage.cpp new file mode 100644 index 0000000..5165efd --- /dev/null +++ b/Otarcik_CAN/Sources/Gui/GeneralStatusPage.cpp @@ -0,0 +1,20 @@ +#include "GeneralStatusPage.h" +#include "ui_GeneralStatusPage.h" + +CGeneralStatusPage::CGeneralStatusPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::CGeneralStatusPage) +{ + ui->setupUi(this); +} + +CGeneralStatusPage::~CGeneralStatusPage() +{ + delete ui; +} + +int CGeneralStatusPage::SetGeneralMsgText(QString Txt) +{ + ui->mGenMsgTextEdit->setText(Txt); + return RET_OK; +} diff --git a/Otarcik_CAN/Sources/Gui/GeneralStatusPage.h b/Otarcik_CAN/Sources/Gui/GeneralStatusPage.h new file mode 100644 index 0000000..1897cfe --- /dev/null +++ b/Otarcik_CAN/Sources/Gui/GeneralStatusPage.h @@ -0,0 +1,27 @@ +#ifndef GENERALSTATUSPAGE_H +#define GENERALSTATUSPAGE_H + +#include +#include "defines.h" + + +namespace Ui { +class CGeneralStatusPage; +} + +class CGeneralStatusPage : public QWidget +{ + Q_OBJECT + +public: + explicit CGeneralStatusPage(QWidget *parent = 0); + ~CGeneralStatusPage(); + + int SetGeneralMsgText(QString Txt); + + +private: + Ui::CGeneralStatusPage *ui; +}; + +#endif // GENERALSTATUSPAGE_H diff --git a/Otarcik_CAN/Sources/Gui/GeneralStatusPage.ui b/Otarcik_CAN/Sources/Gui/GeneralStatusPage.ui new file mode 100644 index 0000000..f4f2709 --- /dev/null +++ b/Otarcik_CAN/Sources/Gui/GeneralStatusPage.ui @@ -0,0 +1,29 @@ + + + CGeneralStatusPage + + + + 0 + 0 + 1147 + 492 + + + + Form + + + + + 660 + 30 + 441 + 451 + + + + + + + diff --git a/Otarcik_CAN/Sources/Gui/MainWindow.ui b/Otarcik_CAN/Sources/Gui/MainWindow.ui index 25e3ff1..78eca9a 100644 --- a/Otarcik_CAN/Sources/Gui/MainWindow.ui +++ b/Otarcik_CAN/Sources/Gui/MainWindow.ui @@ -1,24 +1,446 @@ + CMainWindow - - + + + true + + 0 0 - 400 - 300 + 1186 + 511 - - CMainWindow + + + + + + + 0 + 0 + 0 + + + + + + + 203 + 203 + 203 + + + + + + + 255 + 255 + 255 + + + + + + + 229 + 229 + 229 + + + + + + + 101 + 101 + 101 + + + + + + + 135 + 135 + 135 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 206 + 206 + 206 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 229 + 229 + 229 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 203 + 203 + 203 + + + + + + + 255 + 255 + 255 + + + + + + + 229 + 229 + 229 + + + + + + + 101 + 101 + 101 + + + + + + + 135 + 135 + 135 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 206 + 206 + 206 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 229 + 229 + 229 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 101 + 101 + 101 + + + + + + + 203 + 203 + 203 + + + + + + + 255 + 255 + 255 + + + + + + + 229 + 229 + 229 + + + + + + + 101 + 101 + 101 + + + + + + + 135 + 135 + 135 + + + + + + + 101 + 101 + 101 + + + + + + + 255 + 255 + 255 + + + + + + + 101 + 101 + 101 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 203 + 203 + 203 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + - - - - + + Otracik + + + 3.000000000000000 + + + true + + + - - + diff --git a/Otarcik_CAN/Sources/MainWindow.cpp b/Otarcik_CAN/Sources/MainWindow.cpp index 840a363..088efa4 100644 --- a/Otarcik_CAN/Sources/MainWindow.cpp +++ b/Otarcik_CAN/Sources/MainWindow.cpp @@ -6,9 +6,18 @@ CMainWindow::CMainWindow(QWidget *parent) : ui(new Ui::CMainWindow) { ui->setupUi(this); + + mGeneralStatusPage = new CGeneralStatusPage(this); + mMainWindowWidget = new QTabWidget(this); + + setCentralWidget(mMainWindowWidget); + mMainWindowWidget->addTab(mGeneralStatusPage,"Status"); + + resize(1700,768); } CMainWindow::~CMainWindow() { delete ui; } + diff --git a/Otarcik_CAN/Sources/MainWindow.h b/Otarcik_CAN/Sources/MainWindow.h index 1b801bd..0c8453f 100644 --- a/Otarcik_CAN/Sources/MainWindow.h +++ b/Otarcik_CAN/Sources/MainWindow.h @@ -2,6 +2,9 @@ #define MAINWINDOW_H #include +#include +#include "GeneralStatusPage.h" +#include namespace Ui { class CMainWindow; @@ -15,6 +18,10 @@ public: explicit CMainWindow(QWidget *parent = 0); ~CMainWindow(); + QTabWidget *mMainWindowWidget; + CGeneralStatusPage *mGeneralStatusPage; + + private: Ui::CMainWindow *ui; }; diff --git a/Otarcik_CAN/Sources/OtarcikCan.cpp b/Otarcik_CAN/Sources/OtarcikCan.cpp index 2d34cf8..c0c6916 100644 --- a/Otarcik_CAN/Sources/OtarcikCan.cpp +++ b/Otarcik_CAN/Sources/OtarcikCan.cpp @@ -12,6 +12,14 @@ COtarcikCan::~COtarcikCan() int COtarcikCan::Start() { + w.show(); + + CGeneralMessagesLogDispatcher::instance()->BindGuiPageHandle(w.mGeneralStatusPage); + + + + CGeneralMessagesLogDispatcher::instance()->AddLogMessage("OtarcikCan modules starting..."); + mPCANInterface->Init(); return 0; } diff --git a/Otarcik_CAN/Sources/OtarcikCan.h b/Otarcik_CAN/Sources/OtarcikCan.h index 1290a63..67c8436 100644 --- a/Otarcik_CAN/Sources/OtarcikCan.h +++ b/Otarcik_CAN/Sources/OtarcikCan.h @@ -2,7 +2,9 @@ #define OTARCIKCAN_H #include +#include "MainWindow.h" #include "PCANInterface.h" +#include "GeneralMessagesLogDispatcher.h" class COtarcikCan : public QObject { @@ -10,6 +12,7 @@ class COtarcikCan : public QObject public: explicit COtarcikCan(QObject *parent = 0); ~COtarcikCan(); + CMainWindow w; int Start(); diff --git a/Otarcik_CAN/Sources/PCANInterface.cpp b/Otarcik_CAN/Sources/PCANInterface.cpp index 6ab0d48..aea462d 100644 --- a/Otarcik_CAN/Sources/PCANInterface.cpp +++ b/Otarcik_CAN/Sources/PCANInterface.cpp @@ -1,4 +1,5 @@ #include "PCANInterface.h" +#include "GeneralMessagesLogDispatcher.h" CPCANInterface::CPCANInterface(QObject *parent) : QObject(parent) { @@ -16,6 +17,8 @@ int CPCANInterface::Init() char strMsg[256]; CAN_GetErrorText(Result, 0, strMsg); qDebug("%s",strMsg); + CGeneralMessagesLogDispatcher::instance()->AddLogMessage(strMsg); + } diff --git a/Otarcik_CAN/Sources/defines.h b/Otarcik_CAN/Sources/defines.h index fbc7a4e..4ca25f3 100644 --- a/Otarcik_CAN/Sources/defines.h +++ b/Otarcik_CAN/Sources/defines.h @@ -1,4 +1,25 @@ #ifndef DEFINES_H #define DEFINES_H + + +#define GENERAL_MESSAGES_MAX_LOG_LINES 5000 //The number of lines of general status log we keep in the general status window (avoids fucking up because you know.... RAM) + +enum eOtarcikGeneralReturns +{ + RET_OK = 0, + RET_GENERAL_ERROR, + + + + RET_MAX_ERROR +}; + + + + + #endif // DEFINES_H + + + diff --git a/Otarcik_CAN/Sources/main.cpp b/Otarcik_CAN/Sources/main.cpp index 11de6a2..f00504d 100644 --- a/Otarcik_CAN/Sources/main.cpp +++ b/Otarcik_CAN/Sources/main.cpp @@ -1,4 +1,3 @@ -#include "MainWindow.h" #include #include "OtarcikCan.h" @@ -6,11 +5,10 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - CMainWindow w; COtarcikCan OtarcikCanProgram; //Instanciate the program - w.show(); + OtarcikCanProgram.Start(); diff --git a/Otarcik_CAN/ui_GeneralStatusPage.h b/Otarcik_CAN/ui_GeneralStatusPage.h new file mode 100644 index 0000000..b7dadfd --- /dev/null +++ b/Otarcik_CAN/ui_GeneralStatusPage.h @@ -0,0 +1,51 @@ +/******************************************************************************** +** Form generated from reading UI file 'GeneralStatusPage.ui' +** +** Created by: Qt User Interface Compiler version 5.14.2 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_GENERALSTATUSPAGE_H +#define UI_GENERALSTATUSPAGE_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_CGeneralStatusPage +{ +public: + QTextEdit *mGenMsgTextEdit; + + void setupUi(QWidget *CGeneralStatusPage) + { + if (CGeneralStatusPage->objectName().isEmpty()) + CGeneralStatusPage->setObjectName(QString::fromUtf8("CGeneralStatusPage")); + CGeneralStatusPage->resize(1147, 492); + mGenMsgTextEdit = new QTextEdit(CGeneralStatusPage); + mGenMsgTextEdit->setObjectName(QString::fromUtf8("mGenMsgTextEdit")); + mGenMsgTextEdit->setGeometry(QRect(660, 30, 441, 451)); + + retranslateUi(CGeneralStatusPage); + + QMetaObject::connectSlotsByName(CGeneralStatusPage); + } // setupUi + + void retranslateUi(QWidget *CGeneralStatusPage) + { + CGeneralStatusPage->setWindowTitle(QCoreApplication::translate("CGeneralStatusPage", "Form", nullptr)); + } // retranslateUi + +}; + +namespace Ui { + class CGeneralStatusPage: public Ui_CGeneralStatusPage {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_GENERALSTATUSPAGE_H diff --git a/Otarcik_CAN/ui_MainWindow.h b/Otarcik_CAN/ui_MainWindow.h index de08ec5..40ec4d1 100644 --- a/Otarcik_CAN/ui_MainWindow.h +++ b/Otarcik_CAN/ui_MainWindow.h @@ -12,9 +12,7 @@ #include #include #include -#include #include -#include #include QT_BEGIN_NAMESPACE @@ -22,8 +20,6 @@ QT_BEGIN_NAMESPACE class Ui_CMainWindow { public: - QMenuBar *menuBar; - QToolBar *mainToolBar; QWidget *centralWidget; QStatusBar *statusBar; @@ -31,13 +27,75 @@ public: { if (CMainWindow->objectName().isEmpty()) CMainWindow->setObjectName(QString::fromUtf8("CMainWindow")); - CMainWindow->resize(400, 300); - menuBar = new QMenuBar(CMainWindow); - menuBar->setObjectName(QString::fromUtf8("menuBar")); - CMainWindow->setMenuBar(menuBar); - mainToolBar = new QToolBar(CMainWindow); - mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); - CMainWindow->addToolBar(mainToolBar); + CMainWindow->setEnabled(true); + CMainWindow->resize(1186, 511); + QPalette palette; + QBrush brush(QColor(0, 0, 0, 255)); + brush.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::WindowText, brush); + QBrush brush1(QColor(203, 203, 203, 255)); + brush1.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::Button, brush1); + QBrush brush2(QColor(255, 255, 255, 255)); + brush2.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::Light, brush2); + QBrush brush3(QColor(229, 229, 229, 255)); + brush3.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::Midlight, brush3); + QBrush brush4(QColor(101, 101, 101, 255)); + brush4.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::Dark, brush4); + QBrush brush5(QColor(135, 135, 135, 255)); + brush5.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::Mid, brush5); + palette.setBrush(QPalette::Active, QPalette::Text, brush); + palette.setBrush(QPalette::Active, QPalette::BrightText, brush2); + palette.setBrush(QPalette::Active, QPalette::ButtonText, brush); + QBrush brush6(QColor(206, 206, 206, 255)); + brush6.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::Base, brush6); + QBrush brush7(QColor(240, 240, 240, 255)); + brush7.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::Window, brush7); + palette.setBrush(QPalette::Active, QPalette::Shadow, brush); + palette.setBrush(QPalette::Active, QPalette::AlternateBase, brush3); + QBrush brush8(QColor(255, 255, 220, 255)); + brush8.setStyle(Qt::SolidPattern); + palette.setBrush(QPalette::Active, QPalette::ToolTipBase, brush8); + palette.setBrush(QPalette::Active, QPalette::ToolTipText, brush); + palette.setBrush(QPalette::Inactive, QPalette::WindowText, brush); + palette.setBrush(QPalette::Inactive, QPalette::Button, brush1); + palette.setBrush(QPalette::Inactive, QPalette::Light, brush2); + palette.setBrush(QPalette::Inactive, QPalette::Midlight, brush3); + palette.setBrush(QPalette::Inactive, QPalette::Dark, brush4); + palette.setBrush(QPalette::Inactive, QPalette::Mid, brush5); + palette.setBrush(QPalette::Inactive, QPalette::Text, brush); + palette.setBrush(QPalette::Inactive, QPalette::BrightText, brush2); + palette.setBrush(QPalette::Inactive, QPalette::ButtonText, brush); + palette.setBrush(QPalette::Inactive, QPalette::Base, brush6); + palette.setBrush(QPalette::Inactive, QPalette::Window, brush7); + palette.setBrush(QPalette::Inactive, QPalette::Shadow, brush); + palette.setBrush(QPalette::Inactive, QPalette::AlternateBase, brush3); + palette.setBrush(QPalette::Inactive, QPalette::ToolTipBase, brush8); + palette.setBrush(QPalette::Inactive, QPalette::ToolTipText, brush); + palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush4); + palette.setBrush(QPalette::Disabled, QPalette::Button, brush1); + palette.setBrush(QPalette::Disabled, QPalette::Light, brush2); + palette.setBrush(QPalette::Disabled, QPalette::Midlight, brush3); + palette.setBrush(QPalette::Disabled, QPalette::Dark, brush4); + palette.setBrush(QPalette::Disabled, QPalette::Mid, brush5); + palette.setBrush(QPalette::Disabled, QPalette::Text, brush4); + palette.setBrush(QPalette::Disabled, QPalette::BrightText, brush2); + palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush4); + palette.setBrush(QPalette::Disabled, QPalette::Base, brush7); + palette.setBrush(QPalette::Disabled, QPalette::Window, brush7); + palette.setBrush(QPalette::Disabled, QPalette::Shadow, brush); + palette.setBrush(QPalette::Disabled, QPalette::AlternateBase, brush1); + palette.setBrush(QPalette::Disabled, QPalette::ToolTipBase, brush8); + palette.setBrush(QPalette::Disabled, QPalette::ToolTipText, brush); + CMainWindow->setPalette(palette); + CMainWindow->setWindowOpacity(3.000000000000000); + CMainWindow->setAutoFillBackground(true); centralWidget = new QWidget(CMainWindow); centralWidget->setObjectName(QString::fromUtf8("centralWidget")); CMainWindow->setCentralWidget(centralWidget); @@ -52,7 +110,7 @@ public: void retranslateUi(QMainWindow *CMainWindow) { - CMainWindow->setWindowTitle(QCoreApplication::translate("CMainWindow", "CMainWindow", nullptr)); + CMainWindow->setWindowTitle(QCoreApplication::translate("CMainWindow", "Otracik", nullptr)); } // retranslateUi };