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-03 21:01:52 +01:00
|
|
|
// TODO: Frame shifts slightly when style changes
|
|
|
|
void ConnectionsListItem::setSelected(bool selected) {
|
|
|
|
if (selected == this->isSelected)
|
|
|
|
return;
|
|
|
|
this->isSelected = selected;
|
|
|
|
|
|
|
|
this->setStyleSheet(selected ? ".ConnectionsListItem { border: 1px solid rgb(255, 0, 255); }" : "");
|
|
|
|
if (selected)
|
|
|
|
emit this->selected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsListItem::mousePressEvent(QMouseEvent *) {
|
|
|
|
this->setSelected(true);
|
|
|
|
}
|
|
|
|
|
2024-07-08 16:44:23 +01:00
|
|
|
void ConnectionsListItem::mouseDoubleClickEvent(QMouseEvent *) {
|
|
|
|
emit doubleClicked();
|
|
|
|
}
|
|
|
|
|
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;
|
2024-07-03 21:01:52 +01:00
|
|
|
this->setSelected(true);
|
2024-07-02 19:05:54 +01:00
|
|
|
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;
|
2024-07-03 21:01:52 +01:00
|
|
|
this->setSelected(true);
|
2024-07-02 19:05:54 +01:00
|
|
|
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;
|
2024-07-03 21:01:52 +01:00
|
|
|
this->setSelected(true);
|
2024-07-02 19:05:54 +01:00
|
|
|
emit this->edited();
|
2024-07-01 18:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsListItem::on_button_Delete_clicked()
|
|
|
|
{
|
2024-07-08 16:44:23 +01:00
|
|
|
emit this->deleteRequested();
|
2024-07-01 18:58:58 +01:00
|
|
|
}
|