83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include "itemscrollbox.h"
|
|
#include "itemsettingsdialog.h"
|
|
#include "itemcreationdialog.h"
|
|
#include "../mainobject.h"
|
|
|
|
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::MainWindow),
|
|
colorChooser(this),
|
|
_micro(&mainObject->micro),
|
|
_powerItem(&mainObject->powerItem)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
if(!mainObject->master) connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast);
|
|
else ui->pushButton_broadcast->hide();
|
|
|
|
connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
|
|
|
|
//Relays
|
|
if(mainObject->master)connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
|
|
else connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
|
|
connect(&mainObject->items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
|
connect(&mainObject->items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
|
|
|
for(size_t i = 0; i < mainObject->items.getItems()->size(); ++i)
|
|
{
|
|
ui->relayList->addItem(mainObject->items.getItems()->at(i));
|
|
}
|
|
|
|
//Sensors
|
|
ui->sensorListView->setShowHidden(false);
|
|
ui->sensorListView->sensorsChanged(*globalSensors.getSensors());
|
|
connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
|
|
|
|
//RGB Leds
|
|
connect(&colorChooser, SIGNAL(colorSelected(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
|
|
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
|
|
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
|
|
|
|
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
|
connect(ui->relayList, &ItemScrollBox::deleteRequest, &mainObject->items, &ItemStore::removeItem);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::showPowerItemDialog()
|
|
{
|
|
ItemSettingsDialog diag(_powerItem, this);
|
|
diag.show();
|
|
diag.exec();
|
|
}
|
|
|
|
void MainWindow::slotChangedRgb(const QColor color)
|
|
{
|
|
_micro->changeRgbColor(color);
|
|
}
|
|
|
|
void MainWindow::showItemCreationDialog()
|
|
{
|
|
ItemCreationDialog diag(this);
|
|
diag.show();
|
|
if(diag.exec())
|
|
{
|
|
createdItem(diag.item);
|
|
}
|
|
}
|
|
|
|
void MainWindow::changeHeaderLableText(QString string)
|
|
{
|
|
if(string.size() > 28)
|
|
{
|
|
string.remove(28, string.size()-(28));
|
|
string.append("...");
|
|
}
|
|
ui->label_serialRecive->setText(string);
|
|
}
|