add support for turnouts
This commit is contained in:
parent
fede535b95
commit
4ff73760e5
12 changed files with 184 additions and 44 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <QDebug>
|
||||
#include <QSlider>
|
||||
#include "../items/train.h"
|
||||
#include "../items/turnout.h"
|
||||
|
||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
|
@ -23,14 +24,29 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
|||
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);
|
||||
connect(ui->radioButton_left, &QRadioButton::clicked, this, [this](){moveToValue(0);});
|
||||
connect(ui->radioButton_right, &QRadioButton::clicked, this, [this](){moveToValue(1);});
|
||||
|
||||
Train* train = dynamic_cast<Train*>(workingRelay.get());
|
||||
if(!train)
|
||||
{
|
||||
Turnout* turnout = dynamic_cast<Turnout*>(workingRelay.get());
|
||||
|
||||
if(turnout)
|
||||
{
|
||||
ui->checkBox_f1->hide();
|
||||
ui->checkBox_f2->hide();
|
||||
ui->checkBox_f3->hide();
|
||||
ui->checkBox_f4->hide();
|
||||
ui->slider->hide();
|
||||
}
|
||||
|
||||
if(!train)
|
||||
{
|
||||
ui->pushButton_reverse->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->radioButton_left->hide();
|
||||
ui->radioButton_right->hide();
|
||||
uint8_t functionMask = train->getFunctionMask();
|
||||
if(!(functionMask & (1 << 0)))
|
||||
ui->checkBox_f1->hide();
|
||||
|
|
@ -40,8 +56,7 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
|||
ui->checkBox_f3->hide();
|
||||
if(!(functionMask & (1 << 3)))
|
||||
ui->checkBox_f4->hide();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else disable();
|
||||
}
|
||||
|
|
@ -56,11 +71,21 @@ void ItemWidget::deleteItem()
|
|||
|
||||
void ItemWidget::moveToValue(int value)
|
||||
{
|
||||
qDebug()<<__func__;
|
||||
ui->slider->blockSignals(true);
|
||||
ui->radioButton_left->blockSignals(true);
|
||||
ui->radioButton_right->blockSignals(true);
|
||||
|
||||
ui->pushButton_reverse->setDisabled(value != 0);
|
||||
ui->slider->setValue(value);
|
||||
ui->radioButton_left->setChecked(!value);
|
||||
ui->radioButton_right->setChecked(value);
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setValue(value);
|
||||
else disable();
|
||||
|
||||
ui->slider->blockSignals(false);
|
||||
ui->radioButton_left->blockSignals(false);
|
||||
ui->radioButton_right->blockSignals(false);
|
||||
}
|
||||
|
||||
void ItemWidget::f1(int value)
|
||||
|
|
@ -97,10 +122,13 @@ void ItemWidget::reverse()
|
|||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
Train* train = dynamic_cast<Train*>(workingItem.get());
|
||||
if(train && ui->slider->value() == 0)
|
||||
if(train && workingItem->getValue() == 0)
|
||||
train->reverse();
|
||||
else
|
||||
ui->slider->setValue(0);
|
||||
{
|
||||
qDebug()<<"!((bool)workingItem->getValue()) "<<!((bool)workingItem->getValue());
|
||||
moveToValue(!((bool)workingItem->getValue()));
|
||||
}
|
||||
}
|
||||
else disable();
|
||||
}
|
||||
|
|
@ -130,14 +158,17 @@ bool ItemWidget::controles(const ItemData& relay)
|
|||
|
||||
void ItemWidget::stepUp()
|
||||
{
|
||||
ui->slider->setValue(ui->slider->value()+1);
|
||||
moveToValue(ui->slider->value()+1);
|
||||
}
|
||||
|
||||
void ItemWidget::stepDown()
|
||||
{
|
||||
if(ui->slider->value() == 0)
|
||||
{
|
||||
moveToValue(0);
|
||||
ui->slider->setValue(ui->slider->value()-1);
|
||||
return;
|
||||
}
|
||||
moveToValue(ui->slider->value()-1);
|
||||
}
|
||||
|
||||
void ItemWidget::setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue