inital commit

This commit is contained in:
2022-01-14 23:25:56 +01:00
commit fede535b95
32 changed files with 2357 additions and 0 deletions

View File

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlarmSettingsDialog</class>
<widget class="QDialog" name="AlarmSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>281</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Sound File:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Sunrise</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -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);
}
}

View File

@ -0,0 +1,33 @@
#ifndef ITEMCREATIONDIALOG_H
#define ITEMCREATIONDIALOG_H
#include <QDialog>
#include <memory>
#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> item;
private slots:
void itemTypeChanged(const QString& type);
void itemNameChanged(const QString& name);
private:
Ui::ItemCreationDialog *ui;
};
#endif // ITEMCREATIONDIALOG_H

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ItemCreationDialog</class>
<widget class="QDialog" name="ItemCreationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>140</height>
</rect>
</property>
<property name="windowTitle">
<string>Create Item</string>
</property>
<property name="windowIcon">
<iconset resource="../../resources.qrc">
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>Message</string>
</property>
</item>
<item>
<property name="text">
<string>System</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="text">
<string>Item</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ItemCreationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ItemCreationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

54
src/ui/itemscrollbox.cpp Normal file
View File

@ -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> 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);
}
}
}

44
src/ui/itemscrollbox.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef RELAYSCROLLBOX_H
#define RELAYSCROLLBOX_H
#include <QWidget>
#include <vector>
#include <memory>
#include <QScroller>
#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> item);
void removeItem(const ItemData& item);
private:
Ui::RelayScrollBox *ui;
};
#endif // RELAYSCROLLBOX_H

View File

@ -0,0 +1,176 @@
#include "itemsettingsdialog.h"
#include "ui_itemsettingsdialog.h"
#include<memory>
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> 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> relay = std::dynamic_pointer_cast<Relay>(item_))
{
itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
}
else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
{
itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem);
}
else if(std::shared_ptr<SystemItem> sysItem = std::dynamic_pointer_cast<SystemItem>(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> actor = nullptr;
if(ui->comboBox->currentText() == "Alarm")
{
std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
actor = alarm;
dialog = new ActorSettingsDialog(alarm, this);
}
else if(ui->comboBox->currentText() == "Sensor")
{
std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
actor = sensorActor;
dialog = new ActorSettingsDialog(sensorActor, this);
}
else if(ui->comboBox->currentText() == "Timer" )
{
std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
actor = timerActor;
dialog = new ActorSettingsDialog(timerActor, this);
}
else if(ui->comboBox->currentText() == "Regulator")
{
std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator);
actor = regulator;
dialog = new ActorSettingsDialog(regulator, this);
}
else if(ui->comboBox->currentText() == "Polynomal")
{
std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor);
actor = polynomalActor;
dialog = new ActorSettingsDialog(polynomalActor, this);
}
else if(ui->comboBox->currentText() == "Multi Factor")
{
std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(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> actor = item_->getActors()[ui->tableWidget->currentRow()];
std::shared_ptr<AlarmTime> alarmTime = std::dynamic_pointer_cast<AlarmTime>(actor);
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
std::shared_ptr<TimerActor> timerActor = std::dynamic_pointer_cast<TimerActor>(actor);
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
std::shared_ptr<MultiFactorActor> factorActor = std::dynamic_pointer_cast<MultiFactorActor>(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");
}
}
}

View File

@ -0,0 +1,37 @@
#ifndef RELAYSETTINGSDIALOG_H
#define RELAYSETTINGSDIALOG_H
#include <QDialog>
#include <QSettings>
#include <memory>
#include "../items/item.h"
namespace Ui {
class ItemSettingsDialog;
}
class ItemSettingsDialog : public QDialog
{
Q_OBJECT
std::shared_ptr<Item> item_;
QWidget* itemSpecificWidget_ = nullptr;
private:
void loadActorList();
public:
explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr);
~ItemSettingsDialog();
private slots:
void removeActor();
void addActor();
void editActor();
void changeOverride();
private:
Ui::ItemSettingsDialog *ui;
};
#endif // RELAYSETTINGSDIALOG_H

View File

@ -0,0 +1,274 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ItemSettingsDialog</class>
<widget class="QDialog" name="ItemSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>577</width>
<height>390</height>
</rect>
</property>
<property name="windowTitle">
<string>Item Settings</string>
</property>
<property name="windowIcon">
<iconset resource="../../resources.qrc">
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</item>
<item>
<widget class="QCheckBox" name="checkBox_Override">
<property name="text">
<string>Override</string>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="autoScroll">
<bool>false</bool>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="tabKeyNavigation">
<bool>false</bool>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="gridStyle">
<enum>Qt::SolidLine</enum>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
<property name="rowCount">
<number>0</number>
</property>
<property name="columnCount">
<number>3</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>32</number>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>32</number>
</attribute>
<column/>
<column/>
<column/>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_remove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_edit">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Act on</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>Sensor</string>
</property>
</item>
<item>
<property name="text">
<string>Polynomal</string>
</property>
</item>
<item>
<property name="text">
<string>Regulator</string>
</property>
</item>
<item>
<property name="text">
<string>Alarm</string>
</property>
</item>
<item>
<property name="text">
<string>Timer</string>
</property>
</item>
<item>
<property name="text">
<string>Multi Factor</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_add">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ItemSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ItemSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

170
src/ui/itemwidget.cpp Normal file
View File

@ -0,0 +1,170 @@
#include "itemwidget.h"
#include "ui_itemwidget.h"
#include <QCheckBox>
#include <QDebug>
#include <QSlider>
#include "../items/train.h"
ItemWidget::ItemWidget(std::weak_ptr<Item> 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<Train*>(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<Train*>(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<QShortcut>(new QShortcut(up, this)));
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepUp);
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(down, this)));
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepDown);
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(rev, this)));
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::reverse);
}
std::weak_ptr<Item> ItemWidget::getItem()
{
return item_;
}
void ItemWidget::stateChanged(int state)
{
qDebug()<<"widget got state "<<state;
ui->slider->blockSignals(true);
ui->slider->setValue(state);
ui->slider->blockSignals(false);
}
ItemWidget::~ItemWidget()
{
delete ui;
}

56
src/ui/itemwidget.h Normal file
View File

@ -0,0 +1,56 @@
#ifndef RELAYWIDGET_H
#define RELAYWIDGET_H
#include <QWidget>
#include <memory>
#include <QShortcut>
#include "itemsettingsdialog.h"
#include "../items/item.h"
namespace Ui {
class ItemWidget;
}
class ItemWidget : public QWidget
{
Q_OBJECT
private:
std::weak_ptr<Item> item_;
std::vector< std::unique_ptr<QShortcut> > 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> item, QWidget *parent);
std::weak_ptr<Item> 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

126
src/ui/itemwidget.ui Normal file
View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ItemWidget</class>
<widget class="QWidget" name="ItemWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>264</width>
<height>83</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSlider" name="slider">
<property name="maximum">
<number>14</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="tracking">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_reverse">
<property name="text">
<string>Reverse</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="checkBox_f1">
<property name="text">
<string>F1</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_f2">
<property name="text">
<string>F2</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_f3">
<property name="text">
<string>F3</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_f4">
<property name="text">
<string>F4</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

45
src/ui/mainwindow.cpp Normal file
View File

@ -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);
}
}
*/

46
src/ui/mainwindow.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QColorDialog>
#include <QListWidgetItem>
#include <QTime>
#include <QShortcut>
#include <vector>
#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> item);
private slots:
//void showItemCreationDialog();
};
#endif // MAINWINDOW_H

129
src/ui/mainwindow.ui Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>844</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>50</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>300</height>
</size>
</property>
<property name="windowTitle">
<string>Train Controller</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="ItemScrollBox" name="relayList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
<property name="spacing">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_refesh">
<property name="text">
<string>Refesh</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_stop">
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_addItem">
<property name="text">
<string>Add Item</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>ItemScrollBox</class>
<extends>QWidget</extends>
<header>itemscrollbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

68
src/ui/relayscrollbox.ui Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RelayScrollBox</class>
<widget class="QWidget" name="RelayScrollBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>388</width>
<height>288</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="relayWidgetVbox"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>