From fede535b95e1c86d9e37237560afbb687bd08c1c Mon Sep 17 00:00:00 2001 From: uvos Date: Fri, 14 Jan 2022 23:25:56 +0100 Subject: [PATCH] inital commit --- src/auxitem.cpp | 18 ++ src/auxitem.h | 20 +++ src/items/auxitem.cpp | 18 ++ src/items/auxitem.h | 20 +++ src/items/item.cpp | 62 +++++++ src/items/item.h | 58 ++++++ src/items/itemstore.cpp | 59 +++++++ src/items/itemstore.h | 34 ++++ src/items/train.cpp | 32 ++++ src/items/train.h | 25 +++ src/main.cpp | 106 +++++++++++ src/mainobject.cpp | 14 ++ src/mainobject.h | 47 +++++ src/microcontroller.cpp | 166 +++++++++++++++++ src/microcontroller.h | 78 ++++++++ src/ui/alarmsettingsdialog.ui.orig | 142 +++++++++++++++ src/ui/itemcreationdialog.cpp | 30 ++++ src/ui/itemcreationdialog.h | 33 ++++ src/ui/itemcreationdialog.ui | 116 ++++++++++++ src/ui/itemscrollbox.cpp | 54 ++++++ src/ui/itemscrollbox.h | 44 +++++ src/ui/itemsettingsdialog.cpp | 176 ++++++++++++++++++ src/ui/itemsettingsdialog.h | 37 ++++ src/ui/itemsettingsdialog.ui | 274 +++++++++++++++++++++++++++++ src/ui/itemwidget.cpp | 170 ++++++++++++++++++ src/ui/itemwidget.h | 56 ++++++ src/ui/itemwidget.ui | 126 +++++++++++++ src/ui/mainwindow.cpp | 45 +++++ src/ui/mainwindow.h | 46 +++++ src/ui/mainwindow.ui | 129 ++++++++++++++ src/ui/relayscrollbox.ui | 68 +++++++ trainControllerUI.pro | 54 ++++++ 32 files changed, 2357 insertions(+) create mode 100644 src/auxitem.cpp create mode 100644 src/auxitem.h create mode 100644 src/items/auxitem.cpp create mode 100644 src/items/auxitem.h create mode 100644 src/items/item.cpp create mode 100644 src/items/item.h create mode 100644 src/items/itemstore.cpp create mode 100644 src/items/itemstore.h create mode 100644 src/items/train.cpp create mode 100644 src/items/train.h create mode 100644 src/main.cpp create mode 100644 src/mainobject.cpp create mode 100644 src/mainobject.h create mode 100644 src/microcontroller.cpp create mode 100644 src/microcontroller.h create mode 100644 src/ui/alarmsettingsdialog.ui.orig create mode 100644 src/ui/itemcreationdialog.cpp create mode 100644 src/ui/itemcreationdialog.h create mode 100644 src/ui/itemcreationdialog.ui create mode 100644 src/ui/itemscrollbox.cpp create mode 100644 src/ui/itemscrollbox.h create mode 100644 src/ui/itemsettingsdialog.cpp create mode 100644 src/ui/itemsettingsdialog.h create mode 100644 src/ui/itemsettingsdialog.ui create mode 100644 src/ui/itemwidget.cpp create mode 100644 src/ui/itemwidget.h create mode 100644 src/ui/itemwidget.ui create mode 100644 src/ui/mainwindow.cpp create mode 100644 src/ui/mainwindow.h create mode 100644 src/ui/mainwindow.ui create mode 100644 src/ui/relayscrollbox.ui create mode 100644 trainControllerUI.pro diff --git a/src/auxitem.cpp b/src/auxitem.cpp new file mode 100644 index 0000000..8f104c5 --- /dev/null +++ b/src/auxitem.cpp @@ -0,0 +1,18 @@ +#include "auxitem.h" + +AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro) +{ + +} + +void AuxItem::setValue(uint8_t value) +{ + Item::setValue(value); + micro_->setAuxPwm(value); +} + +void AuxItem::store(QJsonObject &json) +{ + json["Type"] = "Aux"; + Item::store(json); +} diff --git a/src/auxitem.h b/src/auxitem.h new file mode 100644 index 0000000..a1e6765 --- /dev/null +++ b/src/auxitem.h @@ -0,0 +1,20 @@ +#pragma once + +#include "item.h" +#include "../microcontroller.h" + +class AuxItem: public Item +{ + Q_OBJECT +private: + Microcontroller* micro_; + +public slots: + + virtual void setValue(uint8_t value); + +public: + AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr); + + virtual void store(QJsonObject& json); +}; diff --git a/src/items/auxitem.cpp b/src/items/auxitem.cpp new file mode 100644 index 0000000..8f104c5 --- /dev/null +++ b/src/items/auxitem.cpp @@ -0,0 +1,18 @@ +#include "auxitem.h" + +AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro) +{ + +} + +void AuxItem::setValue(uint8_t value) +{ + Item::setValue(value); + micro_->setAuxPwm(value); +} + +void AuxItem::store(QJsonObject &json) +{ + json["Type"] = "Aux"; + Item::store(json); +} diff --git a/src/items/auxitem.h b/src/items/auxitem.h new file mode 100644 index 0000000..a1e6765 --- /dev/null +++ b/src/items/auxitem.h @@ -0,0 +1,20 @@ +#pragma once + +#include "item.h" +#include "../microcontroller.h" + +class AuxItem: public Item +{ + Q_OBJECT +private: + Microcontroller* micro_; + +public slots: + + virtual void setValue(uint8_t value); + +public: + AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr); + + virtual void store(QJsonObject& json); +}; diff --git a/src/items/item.cpp b/src/items/item.cpp new file mode 100644 index 0000000..96c3390 --- /dev/null +++ b/src/items/item.cpp @@ -0,0 +1,62 @@ +#include "item.h" +#include "../microcontroller.h" + +#include + +ItemData::ItemData(uint32_t itemIdIn, QString name, uint8_t value): name_(name), value_(value), itemId_(itemIdIn) +{ + +} + +QString ItemData::getName() const +{ + return name_; +} + +void ItemData::setName(QString name) +{ + name_ = name; +} + +uint8_t ItemData::getValue() const +{ + return value_; +} + +uint32_t ItemData::id() const +{ + return itemId_; +} + + +//item + +Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name, value) +{ + +} + +Item::Item(const ItemData& itemData, QObject *parent): QObject(parent), ItemData(itemData) +{ + +} + +Item::~Item() +{ +} + +void Item::setFunction(uint8_t function, bool on) +{ + functionChanged(function, on); +} + +void Item::setValue(uint8_t value) +{ + value_ = value; + valueChanged(value_); +} + +void Item::informValue(uint8_t value) +{ + Item::setValue(value); +} diff --git a/src/items/item.h b/src/items/item.h new file mode 100644 index 0000000..e8cc87b --- /dev/null +++ b/src/items/item.h @@ -0,0 +1,58 @@ +#pragma once +#include +#include +#include +#include +#include +#include + +class Actor; + +class ItemData +{ +protected: + QString name_; + uint8_t value_; + uint32_t itemId_; + +public: + + ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0); + + inline bool operator==(const ItemData& in) const{ return itemId_==in.itemId_; } + inline bool operator!=(const ItemData& in) const{ return itemId_!=in.itemId_; } + + uint32_t id() const; + + void setName(QString name); + uint8_t getValue() const; + virtual QString getName() const; +}; + + +class Item: public QObject, public ItemData +{ + Q_OBJECT +private: + +signals: + + void valueChanged(uint8_t value); + void functionChanged(uint8_t function, bool on); + +public slots: + + virtual void setValue(uint8_t value); + virtual void setFunction(uint8_t funciton, bool value); + +public: + + Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr); + Item(const ItemData& itemData, QObject *parent = nullptr); + + virtual ~Item(); + + void informValue(uint8_t value); + +}; + diff --git a/src/items/itemstore.cpp b/src/items/itemstore.cpp new file mode 100644 index 0000000..4688361 --- /dev/null +++ b/src/items/itemstore.cpp @@ -0,0 +1,59 @@ +#include "itemstore.h" +#include + +ItemStore::ItemStore(QObject *parent): QObject(parent) +{ +} + +void ItemStore::addItem(std::shared_ptr item) +{ + bool mached = false; + for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true; + if(!mached) + { + items_.push_back(std::shared_ptr(item)); + itemAdded(std::weak_ptr(items_.back())); + } +} + +void ItemStore::addItems(const std::vector>& itemIn) +{ + for(unsigned j = 0; j < itemIn.size(); j++) + addItem(itemIn[j]); + +} + +void ItemStore::removeItem(const ItemData& item) +{ + for(unsigned j = 0; j < items_.size(); j++) + { + if(item == *items_[j]) + { + items_.erase(items_.begin()+j); + --j; + } + } +} + + +void ItemStore::clear() +{ + for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]); + items_.clear(); +} + + +void ItemStore::itemStateChanged(const ItemData& item) +{ + + for(unsigned i = 0; i < items_.size(); i++ ) + { + if(items_[i]->operator==(item)) + { + + if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue()); + } + + } + +} diff --git a/src/items/itemstore.h b/src/items/itemstore.h new file mode 100644 index 0000000..fa0b004 --- /dev/null +++ b/src/items/itemstore.h @@ -0,0 +1,34 @@ +#pragma once +#include +#include +#include "item.h" + +#include + +class ItemStore: public QObject +{ + Q_OBJECT +private: + std::vector< std::shared_ptr > items_; + +public: + + ItemStore(QObject *parent = nullptr); + virtual ~ItemStore(){} + + inline std::vector< std::shared_ptr >* getItems(){ return &items_; } + + void clear(); + +signals: + + void itemDeleted(ItemData item); + void itemAdded(std::weak_ptr Item); + +public slots: + + void removeItem(const ItemData& item); + void addItem(std::shared_ptr item); + void addItems(const std::vector>& itemsIn); + void itemStateChanged(const ItemData& item); +}; diff --git a/src/items/train.cpp b/src/items/train.cpp new file mode 100644 index 0000000..e1ab282 --- /dev/null +++ b/src/items/train.cpp @@ -0,0 +1,32 @@ +#include "train.h" + +Train::Train(uint8_t id, uint8_t address, uint8_t functionMask): + functionMask_(functionMask), + train_id_(id) +{ + itemId_ = address; + name_ = QString("Train ")+QString::number(id); +} + +Microcontroller *Train::micro = nullptr; + +void Train::setFunction(uint8_t funciton, bool value) +{ + Item::setFunction(funciton, value); + if(micro) + micro->itemSetFunction(train_id_, funciton, value); +} + +void Train::setValue(uint8_t value) +{ + Item::setValue(value); + if(micro) + micro->itemSetSpeed(train_id_, value); +} + +void Train::reverse() +{ + if(micro) + micro->itemReverse(train_id_); +} + diff --git a/src/items/train.h b/src/items/train.h new file mode 100644 index 0000000..1764a15 --- /dev/null +++ b/src/items/train.h @@ -0,0 +1,25 @@ +#ifndef TRAIN_H +#define TRAIN_H + +#include "item.h" +#include "../microcontroller.h" + +class Train : public Item +{ + Q_OBJECT + uint8_t functionMask_; + uint8_t train_id_; +public: + static Microcontroller *micro; + + Train(uint8_t id = 0, uint8_t address = 0, uint8_t functionMask = 0); + + uint8_t getFunctionMask() {return functionMask_;} + +public slots: + void reverse(); + virtual void setFunction(uint8_t function, bool on); + virtual void setValue(uint8_t value); +}; + +#endif // TRAIN_H diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a75e1ad --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "microcontroller.h" +#include "ui/mainwindow.h" +#include "items/itemstore.h" +#include "items/train.h" + +#define BAUD QSerialPort::Baud38400 + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + //set info + QCoreApplication::setOrganizationName("UVOS"); + QCoreApplication::setOrganizationDomain("uvos.xyz"); + QCoreApplication::setApplicationName("traincontrollerui"); + QCoreApplication::setApplicationVersion("0.1"); + + QDir::setCurrent(a.applicationDirPath()); + + //parse comand line + QCommandLineParser parser; + parser.setApplicationDescription("Smart Home Interface"); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection")); + parser.addOption(tcpOption); + QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "adress"); + parser.addOption(hostOption); + QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port in TCP mode or Serial port in serial mode"), "port"); + parser.addOption(portOption); + QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main", "Use serial connection")); + parser.addOption(serialOption); + QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate")); + parser.addOption(baudOption); + parser.process(a); + + QIODevice* masterIODevice = nullptr; + + if(parser.isSet(tcpOption)) + { + QTcpSocket* microSocket = new QTcpSocket; + + int port = 6856; + if(parser.isSet(portOption)) port = parser.value(portOption).toInt(); + + QString host("127.0.0.1"); + if(parser.isSet(hostOption)) host = parser.value(hostOption); + std::cout<<"connecting to "<connectToHost(host, port, QIODevice::ReadWrite); + if(!microSocket->waitForConnected(3000)) + { + std::cout<<"Can not connect to to Server.\n"; + QMessageBox::critical(nullptr, "Error", "Can not connect to to Server"); + return 1; + } + masterIODevice = microSocket; + } + else + { + QSerialPort* microPort = new QSerialPort; + if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption)); + else microPort->setPortName("ttyUSB0"); + + if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt()); + else microPort->setBaudRate(BAUD); + + if(!microPort->open(QIODevice::ReadWrite)) + { + QMessageBox::critical(nullptr, "Error", QString("Can not open serial port ")+microPort->portName()); + std::cout<<"Can not open serial port "<portName().toStdString()<<". Continueing in demo mode"<<'\n'; + return 1; + } + masterIODevice = microPort; + } + + Microcontroller micro(masterIODevice); + micro.setPower(true); + + Train::micro = µ + + ItemStore items; + + QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems); + + //mainwindow + MainWindow w(µ, &items); + + w.show(); + + int retVal = a.exec(); + micro.setPower(false); + + if(masterIODevice) + delete masterIODevice; + return retVal; +} + diff --git a/src/mainobject.cpp b/src/mainobject.cpp new file mode 100644 index 0000000..4af15c0 --- /dev/null +++ b/src/mainobject.cpp @@ -0,0 +1,14 @@ +#include "mainobject.h" + +MainObject::MainObject(QIODevice* ioDevice) : + masterIODevice(ioDevice), + micro(masterIODevice) +{ + //connect item store + QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems); +} + +MainObject::~MainObject() +{ +} + diff --git a/src/mainobject.h b/src/mainobject.h new file mode 100644 index 0000000..234bd16 --- /dev/null +++ b/src/mainobject.h @@ -0,0 +1,47 @@ +#ifndef MAINOBJECT_H +#define MAINOBJECT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifndef Q_OS_ANDROID +#include +#include +#include +#endif + +#include "microcontroller.h" +#include "ui/mainwindow.h" +#include "items/itemstore.h" +#include "items/auxitem.h" + +class MainObject : public QObject +{ + Q_OBJECT +public: + + //io + QIODevice * const masterIODevice = nullptr; + + Microcontroller micro; + + const QString settingsPath; + + //items + ItemStore items; + +public: + explicit MainObject(QIODevice* ioDevice); + ~MainObject(); +}; + +#endif // MAINOBJECT_H diff --git a/src/microcontroller.cpp b/src/microcontroller.cpp new file mode 100644 index 0000000..5d15a00 --- /dev/null +++ b/src/microcontroller.cpp @@ -0,0 +1,166 @@ +#include "microcontroller.h" + +#include +#include +#include "items/train.h" + +void Microcontroller::itemSetSpeed(uint8_t id, uint8_t speed) +{ + qDebug()<<__func__; + std::stringstream ss; + ss<<"train "<<(unsigned)id<<" speed "<<(unsigned)speed<<'\n'; + write(ss.str().c_str()); +} + +void Microcontroller::itemReverse(uint8_t id) +{ + std::stringstream ss; + ss<<"train "<<(unsigned)id<<" reverse\n"; + write(ss.str().c_str()); +} + +void Microcontroller::itemSetFunction(uint8_t id, uint8_t function, bool on) +{ + std::stringstream ss; + ss<<"train "<<(unsigned)id<<" function "<<(unsigned)function<<' '<<(on ? "on" : "off")<<'\n'; + write(ss.str().c_str()); +} + +void Microcontroller::setPower(bool on) +{ + write(on ? "power on\n" : "power off\n"); +} + +void Microcontroller::estop() +{ + write("stop\n"); +} + +void Microcontroller::write(const QByteArray& buffer) +{ + qDebug()<write(buffer); + _port->waitForBytesWritten(1000); + } + std::this_thread::sleep_for(std::chrono::milliseconds(40)); +} + +void Microcontroller::write(char* buffer, const size_t length) +{ + qDebug()<write(buffer, length); + _port->waitForBytesWritten(1000); + } + std::this_thread::sleep_for(std::chrono::milliseconds(40)); +} + +bool Microcontroller::connected() +{ + if(_port != nullptr) + return _port->isOpen(); + else return false; +} + +void Microcontroller::requestState() +{ + write("train list\n"); +} + +//housekeeping + +Microcontroller::Microcontroller(QIODevice* port) +{ + setIODevice(port); +} + +Microcontroller::Microcontroller() +{ +} + +Microcontroller::~Microcontroller() +{ +} + +void Microcontroller::setIODevice(QIODevice *port) +{ + _port = port; + QObject::connect(_port, &QIODevice::readyRead, this, &Microcontroller::isReadyRead); +} + +std::shared_ptr Microcontroller::processTrainLine(const QString& buffer) +{ + QStringList bufferList = buffer.split(' '); + if(bufferList.size() >= 9 && buffer.startsWith("NUMBER:")) + { + return std::shared_ptr(new Train(bufferList[1].toInt(), bufferList[3].toInt(), bufferList[12].toInt())); + } + return nullptr; +} + +void Microcontroller::processList(const QString& buffer) +{ + QStringList bufferList = buffer.split(' '); + if(bufferList.size() >= 13 && buffer.startsWith("NUMBER:")) + { + itemList.push_back(processTrainLine(buffer)); + } + else + { + listMode = false; + if(!itemList.empty()) + { + qDebug()<<"got item list " << itemList.size(); + gotItemList(itemList); + itemList.clear(); + } + } +} + +void Microcontroller::processItemState(const QString& buffer) +{ + itemChanged(static_cast(*processTrainLine(buffer))); +} + + +void Microcontroller::processMicroReturn() +{ + if(listMode) + processList(_buffer); + else + { + if(_buffer.startsWith("Trains:")) + { + listMode = true; + itemList.clear(); + } + else if(_buffer.startsWith("NUMBER:")) + { + processItemState(_buffer); + } + else if(_buffer.startsWith("TrainController")) + { + requestState(); + } + } + +} + +void Microcontroller::isReadyRead() +{ + char charBuf; + while(_port->getChar(&charBuf)) + { + _buffer.push_back(charBuf); + if( _buffer.endsWith('\n') ) + { + _buffer.remove('\n'); + processMicroReturn(); + textRecived(_buffer); + _buffer.clear(); + } + } +} diff --git a/src/microcontroller.h b/src/microcontroller.h new file mode 100644 index 0000000..f4ec474 --- /dev/null +++ b/src/microcontroller.h @@ -0,0 +1,78 @@ +#ifndef MICROCONTROLLER_H +#define MICROCONTROLLER_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "items/item.h" + +class Microcontroller : public QObject +{ + + Q_OBJECT + +public: + + static constexpr char AMP_RELAY = 0; + static constexpr char SENSOR_TEMPERATURE = 1; + static constexpr char SENSOR_DOOR = 0 ; + +private: + + bool listMode = false; + + //uint8_t _auxState = 0; + + QIODevice* _port = nullptr; + + std::vector< std::shared_ptr > itemList; + + QScopedPointer loop; + QString _buffer; + + void processMicroReturn(); + void processList(const QString& buffer); + void processItemState(const QString& buffer); + std::shared_ptr processTrainLine(const QString& buffer); + + void write(char *buffer, const size_t length); + void write(const QByteArray& buffer); + +public: + Microcontroller(QIODevice* port); + Microcontroller(); + ~Microcontroller(); + bool connected(); + void setIODevice(QIODevice* port); + +public slots: + void requestState(); + + void itemSetSpeed(uint8_t id, uint8_t speed); + void itemReverse(uint8_t id); + void itemSetFunction(uint8_t id, uint8_t function, bool on); + void estop(); + void setPower(bool on); + +private slots: + void isReadyRead(); + +signals: + void textRecived(const QString string); + void itemChanged(ItemData relay); + void auxStateChanged(int value); + void gotItemList(std::vector< std::shared_ptr >&); +}; + +#endif // MICROCONTROLLER_H diff --git a/src/ui/alarmsettingsdialog.ui.orig b/src/ui/alarmsettingsdialog.ui.orig new file mode 100644 index 0000000..55297a9 --- /dev/null +++ b/src/ui/alarmsettingsdialog.ui.orig @@ -0,0 +1,142 @@ + + + AlarmSettingsDialog + + + + 0 + 0 + 423 + 281 + + + + Dialog + + + + + + Sound File: + + + + + + + 0 + + + 0 + + + + + false + + + + + + + Change + + + + + + + + + 0 + + + + + Sunrise + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Enable + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AlarmSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AlarmSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/itemcreationdialog.cpp b/src/ui/itemcreationdialog.cpp new file mode 100644 index 0000000..55b26ca --- /dev/null +++ b/src/ui/itemcreationdialog.cpp @@ -0,0 +1,30 @@ +#include "itemcreationdialog.h" +#include "ui_itemcreationdialog.h" + +ItemCreationDialog::ItemCreationDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ItemCreationDialog) +{ + ui->setupUi(this); + connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ItemCreationDialog::itemTypeChanged); + connect(ui->lineEdit, &QLineEdit::textChanged, this, &ItemCreationDialog::itemNameChanged); +} + +ItemCreationDialog::~ItemCreationDialog() +{ + delete ui; +} + +void ItemCreationDialog::itemTypeChanged(const QString& type) +{ + ui->verticalLayout->removeWidget(widget); +} + +void ItemCreationDialog::itemNameChanged(const QString& name) +{ + if(item) + { + item->setName(name); + } +} + diff --git a/src/ui/itemcreationdialog.h b/src/ui/itemcreationdialog.h new file mode 100644 index 0000000..57421ae --- /dev/null +++ b/src/ui/itemcreationdialog.h @@ -0,0 +1,33 @@ +#ifndef ITEMCREATIONDIALOG_H +#define ITEMCREATIONDIALOG_H + +#include +#include +#include "../items/item.h" + +namespace Ui { +class ItemCreationDialog; +} + +class ItemCreationDialog : public QDialog +{ + Q_OBJECT + + QWidget* widget; + +public: + explicit ItemCreationDialog(QWidget *parent = nullptr); + ~ItemCreationDialog(); + + std::shared_ptr item; + +private slots: + + void itemTypeChanged(const QString& type); + void itemNameChanged(const QString& name); + +private: + Ui::ItemCreationDialog *ui; +}; + +#endif // ITEMCREATIONDIALOG_H diff --git a/src/ui/itemcreationdialog.ui b/src/ui/itemcreationdialog.ui new file mode 100644 index 0000000..4b55d6d --- /dev/null +++ b/src/ui/itemcreationdialog.ui @@ -0,0 +1,116 @@ + + + ItemCreationDialog + + + + 0 + 0 + 400 + 140 + + + + Create Item + + + + :/images/UVOSicon.bmp:/images/UVOSicon.bmp + + + + + + + + Type + + + + + + + + Message + + + + + System + + + + + + + + + + + + Name + + + + + + + Item + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + ItemCreationDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ItemCreationDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/itemscrollbox.cpp b/src/ui/itemscrollbox.cpp new file mode 100644 index 0000000..6b03112 --- /dev/null +++ b/src/ui/itemscrollbox.cpp @@ -0,0 +1,54 @@ +#include "itemscrollbox.h" +#include "ui_relayscrollbox.h" + +ItemScrollBox::ItemScrollBox(QWidget *parent) : + QWidget(parent), + ui(new Ui::RelayScrollBox) +{ + ui->setupUi(this); + QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture); + QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture); +} + +ItemScrollBox::~ItemScrollBox() +{ + delete ui; +} + +void ItemScrollBox::addItem(std::weak_ptr item) +{ + static int lifetimeNum = 0; + if(auto workItem = item.lock()) + { + widgets_.push_back(new ItemWidget(item, this)); + if(lifetimeNum == 0) + widgets_.back()->setShortcuts(QKeySequence(Qt::Key_Q), QKeySequence(Qt::Key_A), QKeySequence(Qt::Key_Z)); + else if(lifetimeNum == 1) + widgets_.back()->setShortcuts(QKeySequence(Qt::Key_W), QKeySequence(Qt::Key_S), QKeySequence(Qt::Key_X)); + else if(lifetimeNum == 2) + widgets_.back()->setShortcuts(QKeySequence(Qt::Key_E), QKeySequence(Qt::Key_D), QKeySequence(Qt::Key_C)); + else if(lifetimeNum == 3) + widgets_.back()->setShortcuts(QKeySequence(Qt::Key_R), QKeySequence(Qt::Key_F), QKeySequence(Qt::Key_V)); + else if(lifetimeNum == 4) + widgets_.back()->setShortcuts(QKeySequence(Qt::Key_T), QKeySequence(Qt::Key_G), QKeySequence(Qt::Key_B)); + ui->relayWidgetVbox->addWidget(widgets_.back()); + connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest); + connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem); + lifetimeNum++; + } +} + +void ItemScrollBox::removeItem(const ItemData& item) +{ + for(unsigned i = 0; i < widgets_.size(); i++) + { + if(widgets_[i]->controles(item)) + { + ui->relayWidgetVbox->removeWidget(widgets_[i]); + delete widgets_[i]; + widgets_.erase(widgets_.begin()+i); + } + } +} + + diff --git a/src/ui/itemscrollbox.h b/src/ui/itemscrollbox.h new file mode 100644 index 0000000..c95a7dc --- /dev/null +++ b/src/ui/itemscrollbox.h @@ -0,0 +1,44 @@ +#ifndef RELAYSCROLLBOX_H +#define RELAYSCROLLBOX_H + +#include +#include +#include +#include +#include "itemwidget.h" +#include "../items/item.h" +#include "../items/itemstore.h" + + +namespace Ui { +class RelayScrollBox; +} + +class ItemScrollBox : public QWidget +{ + Q_OBJECT +private: + std::vector< ItemWidget* > widgets_; + +signals: + void deleteRequest(const ItemData& item); + + +public: + explicit ItemScrollBox(QWidget *parent = nullptr); + ~ItemScrollBox(); + + void setItemStore(ItemStore* itemStore); + +public slots: + + void addItem(std::weak_ptr item); + void removeItem(const ItemData& item); + +private: + Ui::RelayScrollBox *ui; +}; + +#endif // RELAYSCROLLBOX_H + + diff --git a/src/ui/itemsettingsdialog.cpp b/src/ui/itemsettingsdialog.cpp new file mode 100644 index 0000000..179ce19 --- /dev/null +++ b/src/ui/itemsettingsdialog.cpp @@ -0,0 +1,176 @@ + #include "itemsettingsdialog.h" +#include "ui_itemsettingsdialog.h" +#include + +ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr item, QWidget *parent) : + QDialog(parent), + item_(item), + ui(new Ui::ItemSettingsDialog) +{ + ui->setupUi(this); + + setModal(false); + + ui->label_name->setText(item_->getName()); + ui->checkBox_Override->setChecked(item_->getOverride()); + + + if(std::shared_ptr relay = std::dynamic_pointer_cast(item_)) + { + itemSpecificWidget_ = new RelayItemSettingsWidget(relay); + } + else if(std::shared_ptr msgItem = std::dynamic_pointer_cast(item_)) + { + itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem); + } + else if(std::shared_ptr sysItem = std::dynamic_pointer_cast(item_)) + { + itemSpecificWidget_ = new SystemItemSettingsWidget(sysItem); + } + + if(itemSpecificWidget_) + { + ui->verticalLayout_2->addWidget(itemSpecificWidget_); + } + + connect(ui->pushButton_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor); + connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor); + connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor); + connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride); + + + ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor")); + ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action")); + ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled")); + ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + ui->tableWidget->horizontalHeader()->resizeSection(1, 60); + ui->tableWidget->horizontalHeader()->resizeSection(2, 75); + loadActorList(); +} + +ItemSettingsDialog::~ItemSettingsDialog() +{ + if(itemSpecificWidget_) delete itemSpecificWidget_; + delete ui; +} + +void ItemSettingsDialog::changeOverride() +{ + item_->setOverride(ui->checkBox_Override->isChecked()); +} + +void ItemSettingsDialog::loadActorList() +{ + //ui->listWidget->clear(); + ui->tableWidget->setRowCount(item_->getActors().size()); + + for(unsigned i = 0; i < item_->getActors().size(); i++) + { + ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName())); + ui->tableWidget->setItem(i, 1, new QTableWidgetItem(item_->getActors()[i]->actionName())); + ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N")); + } +} + +void ItemSettingsDialog::addActor() +{ + ActorSettingsDialog* dialog = nullptr; + std::shared_ptr actor = nullptr; + + if(ui->comboBox->currentText() == "Alarm") + { + std::shared_ptr alarm = std::shared_ptr(new AlarmTime); + actor = alarm; + dialog = new ActorSettingsDialog(alarm, this); + } + else if(ui->comboBox->currentText() == "Sensor") + { + std::shared_ptr sensorActor = std::shared_ptr(new SensorActor); + actor = sensorActor; + dialog = new ActorSettingsDialog(sensorActor, this); + } + else if(ui->comboBox->currentText() == "Timer" ) + { + std::shared_ptr timerActor = std::shared_ptr(new TimerActor); + actor = timerActor; + dialog = new ActorSettingsDialog(timerActor, this); + } + else if(ui->comboBox->currentText() == "Regulator") + { + std::shared_ptr regulator = std::shared_ptr(new Regulator); + actor = regulator; + dialog = new ActorSettingsDialog(regulator, this); + } + + else if(ui->comboBox->currentText() == "Polynomal") + { + std::shared_ptr polynomalActor = std::shared_ptr(new PolynomalActor); + actor = polynomalActor; + dialog = new ActorSettingsDialog(polynomalActor, this); + } + + else if(ui->comboBox->currentText() == "Multi Factor") + { + std::shared_ptr polynomalActor = std::shared_ptr(new MultiFactorActor); + actor = polynomalActor; + dialog = new ActorSettingsDialog(polynomalActor, this); + } + + + if(dialog != nullptr) + { + dialog->setParent(this); + dialog->show(); + if(dialog->exec() == QDialog::Accepted) + { + item_->addActor(actor); + loadActorList(); + } + delete dialog; + } + +} + +void ItemSettingsDialog::removeActor() +{ + if(item_->getActors().size() > ui->tableWidget->currentRow()) + { + item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow())); + loadActorList(); + } +} + +void ItemSettingsDialog::editActor() +{ + if(item_->getActors().size() > ui->tableWidget->currentRow()) + { + std::shared_ptr actor = item_->getActors()[ui->tableWidget->currentRow()]; + + std::shared_ptr alarmTime = std::dynamic_pointer_cast(actor); + std::shared_ptr regulator = std::dynamic_pointer_cast(actor); + std::shared_ptr sensorActor = std::dynamic_pointer_cast(actor); + std::shared_ptr timerActor = std::dynamic_pointer_cast(actor); + std::shared_ptr polynomalActor = std::dynamic_pointer_cast(actor); + std::shared_ptr factorActor = std::dynamic_pointer_cast(actor); + + ActorSettingsDialog* dialog; + + if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this); + else if(regulator) dialog = new ActorSettingsDialog(regulator, this); + else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this); + else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this); + else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this); + else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this); + else dialog = new ActorSettingsDialog(actor, this); + dialog->setParent(this); + dialog->show(); + dialog->exec(); + + for(int i = 0; i < ui->tableWidget->rowCount() && i < item_->getActors().size(); ++i) + { + ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName()); + ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName()); + ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N"); + } + } +} diff --git a/src/ui/itemsettingsdialog.h b/src/ui/itemsettingsdialog.h new file mode 100644 index 0000000..ca12f21 --- /dev/null +++ b/src/ui/itemsettingsdialog.h @@ -0,0 +1,37 @@ +#ifndef RELAYSETTINGSDIALOG_H +#define RELAYSETTINGSDIALOG_H + +#include +#include +#include +#include "../items/item.h" + +namespace Ui { +class ItemSettingsDialog; +} + +class ItemSettingsDialog : public QDialog +{ + Q_OBJECT + std::shared_ptr item_; + QWidget* itemSpecificWidget_ = nullptr; + +private: + void loadActorList(); + +public: + explicit ItemSettingsDialog(std::shared_ptr item, QWidget *parent = nullptr); + ~ItemSettingsDialog(); + +private slots: + + void removeActor(); + void addActor(); + void editActor(); + void changeOverride(); + +private: + Ui::ItemSettingsDialog *ui; +}; + +#endif // RELAYSETTINGSDIALOG_H diff --git a/src/ui/itemsettingsdialog.ui b/src/ui/itemsettingsdialog.ui new file mode 100644 index 0000000..871bb9f --- /dev/null +++ b/src/ui/itemsettingsdialog.ui @@ -0,0 +1,274 @@ + + + ItemSettingsDialog + + + + 0 + 0 + 577 + 390 + + + + Item Settings + + + + :/images/UVOSicon.bmp:/images/UVOSicon.bmp + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + 0 + + + 10 + + + + + Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 5 + 0 + + + + Qt::LeftToRight + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + Override + + + + + + + QFrame::StyledPanel + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAlwaysOff + + + false + + + QAbstractItemView::NoEditTriggers + + + false + + + false + + + false + + + QAbstractItemView::SelectRows + + + false + + + Qt::SolidLine + + + false + + + 0 + + + 3 + + + false + + + 32 + + + true + + + false + + + 32 + + + + + + + + + + 0 + + + 0 + + + + + Remove + + + + + + + Edit + + + + + + + + + + + + 0 + 0 + + + + Act on + + + + + + + + Sensor + + + + + Polynomal + + + + + Regulator + + + + + Alarm + + + + + Timer + + + + + Multi Factor + + + + + + + + + 0 + 0 + + + + Add + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + ItemSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ItemSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/itemwidget.cpp b/src/ui/itemwidget.cpp new file mode 100644 index 0000000..30fd342 --- /dev/null +++ b/src/ui/itemwidget.cpp @@ -0,0 +1,170 @@ +#include "itemwidget.h" +#include "ui_itemwidget.h" + +#include +#include +#include +#include "../items/train.h" + +ItemWidget::ItemWidget(std::weak_ptr item, QWidget *parent) : + QWidget(parent), + item_(item), + ui(new Ui::ItemWidget) +{ + ui->setupUi(this); + + if(auto workingRelay = item_.lock()) + { + ui->label->setText(workingRelay->getName()); + + connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue); + connect(ui->checkBox_f1, &QCheckBox::stateChanged, this, &ItemWidget::f1); + connect(ui->checkBox_f2, &QCheckBox::stateChanged, this, &ItemWidget::f2); + connect(ui->checkBox_f3, &QCheckBox::stateChanged, this, &ItemWidget::f3); + connect(ui->checkBox_f4, &QCheckBox::stateChanged, this, &ItemWidget::f4); + connect(ui->pushButton_reverse, &QPushButton::clicked, this, &ItemWidget::reverse); + + Train* train = dynamic_cast(workingRelay.get()); + if(!train) + { + ui->pushButton_reverse->hide(); + } + else + { + uint8_t functionMask = train->getFunctionMask(); + if(!(functionMask & (1 << 0))) + ui->checkBox_f1->hide(); + if(!(functionMask & (1 << 1))) + ui->checkBox_f2->hide(); + if(!(functionMask & (1 << 2))) + ui->checkBox_f3->hide(); + if(!(functionMask & (1 << 3))) + ui->checkBox_f4->hide(); + } + + } + else disable(); +} + +void ItemWidget::deleteItem() +{ + if(auto workingItem = item_.lock()) + { + deleteRequest(*workingItem); + } +} + +void ItemWidget::moveToValue(int value) +{ + qDebug()<<__func__; + ui->pushButton_reverse->setDisabled(value != 0); + if(auto workingItem = item_.lock()) + workingItem->setValue(value); + else disable(); +} + +void ItemWidget::f1(int value) +{ + if(auto workingItem = item_.lock()) + workingItem->setFunction(0, value == Qt::Checked); + else disable(); +} + +void ItemWidget::f2(int value) +{ + if(auto workingItem = item_.lock()) + workingItem->setFunction(1, value == Qt::Checked); + else disable(); +} + + +void ItemWidget::f3(int value) +{ + if(auto workingItem = item_.lock()) + workingItem->setFunction(2, value == Qt::Checked); + else disable(); +} + +void ItemWidget::f4(int value) +{ + if(auto workingItem = item_.lock()) + workingItem->setFunction(3, value == Qt::Checked); + else disable(); +} + +void ItemWidget::reverse() +{ + if(auto workingItem = item_.lock()) + { + Train* train = dynamic_cast(workingItem.get()); + if(train && ui->slider->value() == 0) + train->reverse(); + else + ui->slider->setValue(0); + } + else disable(); +} + +void ItemWidget::disable() +{ + ui->checkBox_f1->setEnabled(false); + ui->checkBox_f2->setEnabled(false); + ui->checkBox_f3->setEnabled(false); + ui->checkBox_f4->setEnabled(false); + ui->label->setEnabled(false); + ui->slider->setEnabled(false); + ui->pushButton_reverse->setEnabled(false); +} + +bool ItemWidget::controles(const ItemData& relay) +{ + if(auto workingRelay = item_.lock()) + { + if(relay == *workingRelay) + return true; + else + return false; + } + return true; +} + +void ItemWidget::stepUp() +{ + ui->slider->setValue(ui->slider->value()+1); +} + +void ItemWidget::stepDown() +{ + if(ui->slider->value() == 0) + moveToValue(0); + ui->slider->setValue(ui->slider->value()-1); +} + +void ItemWidget::setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev) +{ + shortcuts_.clear(); + shortcuts_.push_back(std::unique_ptr(new QShortcut(up, this))); + connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepUp); + shortcuts_.push_back(std::unique_ptr(new QShortcut(down, this))); + connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepDown); + shortcuts_.push_back(std::unique_ptr(new QShortcut(rev, this))); + connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::reverse); +} + +std::weak_ptr ItemWidget::getItem() +{ + return item_; +} + +void ItemWidget::stateChanged(int state) +{ + qDebug()<<"widget got state "<slider->blockSignals(true); + ui->slider->setValue(state); + ui->slider->blockSignals(false); +} + +ItemWidget::~ItemWidget() +{ + delete ui; +} diff --git a/src/ui/itemwidget.h b/src/ui/itemwidget.h new file mode 100644 index 0000000..5dcbcca --- /dev/null +++ b/src/ui/itemwidget.h @@ -0,0 +1,56 @@ +#ifndef RELAYWIDGET_H +#define RELAYWIDGET_H + +#include +#include +#include +#include "itemsettingsdialog.h" +#include "../items/item.h" + +namespace Ui { +class ItemWidget; +} + +class ItemWidget : public QWidget +{ + Q_OBJECT +private: + std::weak_ptr item_; + + std::vector< std::unique_ptr > shortcuts_; + + void disable(); + +signals: + + void deleteRequest(const ItemData& item); + +private slots: + void moveToValue(int value); + void deleteItem(); + + void stepUp(); + void stepDown(); + + void f1(int state); + void f2(int state); + void f3(int state); + void f4(int state); + void reverse(); + +public: + explicit ItemWidget(std::weak_ptr item, QWidget *parent); + std::weak_ptr getItem(); + bool controles(const ItemData& relay); + ~ItemWidget(); + void setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev); + +public slots: + + void stateChanged(int state); + +private: + Ui::ItemWidget *ui; +}; + +#endif // RELAYWIDGET_H diff --git a/src/ui/itemwidget.ui b/src/ui/itemwidget.ui new file mode 100644 index 0000000..56024d7 --- /dev/null +++ b/src/ui/itemwidget.ui @@ -0,0 +1,126 @@ + + + ItemWidget + + + + 0 + 0 + 264 + 83 + + + + + 0 + 0 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + TextLabel + + + + + + + + + + + 14 + + + 1 + + + true + + + Qt::Horizontal + + + + + + + Reverse + + + + + + + + + + + F1 + + + + + + + F2 + + + + + + + F3 + + + + + + + F4 + + + + + + + + + + + + + Qt::Horizontal + + + + + + + + diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp new file mode 100644 index 0000000..93187a4 --- /dev/null +++ b/src/ui/mainwindow.cpp @@ -0,0 +1,45 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "itemscrollbox.h" +#include "itemsettingsdialog.h" +#include "itemcreationdialog.h" + +MainWindow::MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent) : + QMainWindow(parent), + stopShort(QKeySequence(Qt::Key_Space), this), + ui(new Ui::MainWindow), + _micro(micro) +{ + ui->setupUi(this); + + connect(&stopShort, &QShortcut::activated, _micro, &Microcontroller::estop); + connect(ui->pushButton_stop, &QPushButton::clicked, _micro, &Microcontroller::estop); + connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState); + + connect(items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem); + connect(items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem); + + for(size_t i = 0; i < items->getItems()->size(); ++i) + { + ui->relayList->addItem(items->getItems()->at(i)); + } + + connect(ui->relayList, &ItemScrollBox::deleteRequest, items, &ItemStore::removeItem); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +/* +void MainWindow::showItemCreationDialog() +{ + ItemCreationDialog diag(this); + diag.show(); + if(diag.exec()) + { + createdItem(diag.item); + } +} +*/ diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h new file mode 100644 index 0000000..890b84b --- /dev/null +++ b/src/ui/mainwindow.h @@ -0,0 +1,46 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include "../microcontroller.h" +#include "../items/itemstore.h" + + +class MainObject; + +namespace Ui +{ +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + QShortcut stopShort; + +public: + explicit MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow *ui; + + Microcontroller *_micro; + +signals: + + void createdItem(std::shared_ptr item); + +private slots: + + //void showItemCreationDialog(); + +}; + +#endif // MAINWINDOW_H + diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui new file mode 100644 index 0000000..9526a35 --- /dev/null +++ b/src/ui/mainwindow.ui @@ -0,0 +1,129 @@ + + + MainWindow + + + + 0 + 0 + 844 + 300 + + + + + 0 + 50 + + + + + 300 + 300 + + + + Train Controller + + + + :/images/UVOSicon.bmp:/images/UVOSicon.bmp + + + + + 0 + 0 + + + + Qt::LeftToRight + + + false + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + 0 + + + 0 + + + + + Refesh + + + + + + + Stop + + + + + + + Add Item + + + + + + + + + + + + + + ItemScrollBox + QWidget +
itemscrollbox.h
+ 1 +
+
+ + +
diff --git a/src/ui/relayscrollbox.ui b/src/ui/relayscrollbox.ui new file mode 100644 index 0000000..cb0fae2 --- /dev/null +++ b/src/ui/relayscrollbox.ui @@ -0,0 +1,68 @@ + + + RelayScrollBox + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + QFrame::NoFrame + + + 0 + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + true + + + + + 0 + 0 + 388 + 288 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + diff --git a/trainControllerUI.pro b/trainControllerUI.pro new file mode 100644 index 0000000..56f69b7 --- /dev/null +++ b/trainControllerUI.pro @@ -0,0 +1,54 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-06-01T22:31:38 +# +#------------------------------------------------- + +QT += core gui widgets network multimedia + +QT += serialport + +TARGET = traincontrollerui +TEMPLATE = app + +INCLUDEPATH += /usr/include/libnl3/ + +LIBS += -lnl-3 -lnl-genl-3 + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +QMAKE_CXXFLAGS += -std=c++17 -O2 + +SOURCES += \ + src/items/train.cpp \ + src/mainobject.cpp \ + src/ui/itemwidget.cpp \ + src/ui/itemscrollbox.cpp \ + src/ui/mainwindow.cpp \ + src/items/item.cpp \ + src/items/itemstore.cpp\ + src/main.cpp \ + src/microcontroller.cpp + +HEADERS += \ + src/items/train.h \ + src/mainobject.h \ + src/ui/itemwidget.h \ + src/ui/itemscrollbox.h \ + src/ui/mainwindow.h \ + src/items/item.h \ + src/items/itemstore.h + +HEADERS += \ + src/microcontroller.h \ + +INCLUDEPATH += src/ui/ + +FORMS += \ + src/ui/mainwindow.ui \ + src/ui/relayscrollbox.ui \ + src/ui/itemwidget.ui