2024-06-26 21:03:39 +01:00
|
|
|
#include "connectionslistitem.h"
|
|
|
|
#include "ui_connectionslistitem.h"
|
|
|
|
|
|
|
|
static const QStringList directions = {"up", "down", "left", "right"};
|
|
|
|
|
2024-07-02 19:05:54 +01:00
|
|
|
ConnectionsListItem::ConnectionsListItem(QWidget *parent, MapConnection * connection, const QStringList &mapNames) :
|
2024-06-26 21:03:39 +01:00
|
|
|
QFrame(parent),
|
2024-07-02 19:05:54 +01:00
|
|
|
ui(new Ui::ConnectionsListItem),
|
|
|
|
connection(connection)
|
2024-06-26 21:03:39 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
const QSignalBlocker blocker1(ui->comboBox_Direction);
|
|
|
|
const QSignalBlocker blocker2(ui->comboBox_Map);
|
|
|
|
const QSignalBlocker blocker3(ui->spinBox_Offset);
|
|
|
|
|
|
|
|
ui->comboBox_Direction->setEditable(false);
|
|
|
|
ui->comboBox_Direction->setMinimumContentsLength(0);
|
|
|
|
ui->comboBox_Direction->addItems(directions);
|
|
|
|
|
|
|
|
ui->comboBox_Map->setMinimumContentsLength(6);
|
|
|
|
ui->comboBox_Map->addItems(mapNames);
|
2024-07-01 18:58:58 +01:00
|
|
|
|
2024-07-01 19:10:55 +01:00
|
|
|
ui->spinBox_Offset->setMinimum(INT_MIN);
|
|
|
|
ui->spinBox_Offset->setMaximum(INT_MAX);
|
2024-07-01 18:58:58 +01:00
|
|
|
|
2024-07-02 19:05:54 +01:00
|
|
|
this->updateUI();
|
2024-06-26 21:03:39 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:05:54 +01:00
|
|
|
ConnectionsListItem::~ConnectionsListItem()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsListItem::updateUI() {
|
2024-06-26 21:03:39 +01:00
|
|
|
const QSignalBlocker blocker1(ui->comboBox_Direction);
|
|
|
|
const QSignalBlocker blocker2(ui->comboBox_Map);
|
|
|
|
const QSignalBlocker blocker3(ui->spinBox_Offset);
|
|
|
|
|
2024-07-02 19:05:54 +01:00
|
|
|
ui->comboBox_Direction->setTextItem(this->connection->direction);
|
|
|
|
ui->comboBox_Map->setTextItem(this->connection->map_name);
|
|
|
|
ui->spinBox_Offset->setValue(this->connection->offset);
|
2024-06-26 21:03:39 +01:00
|
|
|
}
|
|
|
|
|
2024-07-01 18:58:58 +01:00
|
|
|
void ConnectionsListItem::on_comboBox_Direction_currentTextChanged(const QString &direction)
|
|
|
|
{
|
2024-07-02 19:05:54 +01:00
|
|
|
this->connection->direction = direction;
|
|
|
|
emit this->edited();
|
2024-07-01 18:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsListItem::on_comboBox_Map_currentTextChanged(const QString &mapName)
|
|
|
|
{
|
2024-07-02 19:05:54 +01:00
|
|
|
if (ui->comboBox_Map->findText(mapName) >= 0) {
|
|
|
|
this->connection->map_name = mapName;
|
|
|
|
emit this->edited();
|
|
|
|
}
|
2024-07-01 18:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsListItem::on_spinBox_Offset_valueChanged(int offset)
|
|
|
|
{
|
2024-07-02 19:05:54 +01:00
|
|
|
this->connection->offset = offset;
|
|
|
|
emit this->edited();
|
2024-07-01 18:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsListItem::on_button_Delete_clicked()
|
|
|
|
{
|
2024-07-02 19:05:54 +01:00
|
|
|
this->deleteLater();
|
|
|
|
emit this->deleted();
|
2024-07-01 18:58:58 +01:00
|
|
|
}
|