outputmap: dialog now has icons for each row :)
Dieser Commit ist enthalten in:
Ursprung
80b08cb02a
Commit
1a9edd0492
@ -35,6 +35,8 @@
|
||||
#include "objectpropertycombobox.hpp"
|
||||
#include "propertyaddresses.hpp"
|
||||
#include "outputmapoutputactionwidget.hpp"
|
||||
#include "../board/tilepainter.hpp"
|
||||
#include "../board/getboardcolorscheme.hpp"
|
||||
#include "../dialog/objectselectlistdialog.hpp"
|
||||
#include "../network/callmethod.hpp"
|
||||
#include "../network/method.hpp"
|
||||
@ -67,6 +69,8 @@ OutputMapWidget::OutputMapWidget(ObjectPtr object, QWidget* parent)
|
||||
, m_ecosObject{dynamic_cast<Property*>(m_object->getProperty("ecos_object"))}
|
||||
, m_items{m_object->getObjectVectorProperty("items")}
|
||||
, m_table{new QTableWidget(this)}
|
||||
, m_getParentRequestId{Connection::invalidRequestId}
|
||||
, m_getItemsRequestId{Connection::invalidRequestId}
|
||||
{
|
||||
QVBoxLayout* l = new QVBoxLayout();
|
||||
|
||||
@ -97,6 +101,8 @@ OutputMapWidget::OutputMapWidget(ObjectPtr object, QWidget* parent)
|
||||
}
|
||||
l->addLayout(form);
|
||||
|
||||
const int listViewIconSize = m_table->style()->pixelMetric(QStyle::PM_ListViewIconSize);
|
||||
m_table->setIconSize({listViewIconSize, listViewIconSize});
|
||||
m_table->setColumnCount(m_columnCountNonOutput);
|
||||
m_table->setRowCount(0);
|
||||
QStringList labels;
|
||||
@ -113,6 +119,20 @@ OutputMapWidget::OutputMapWidget(ObjectPtr object, QWidget* parent)
|
||||
|
||||
setLayout(l);
|
||||
|
||||
if(auto* parentObject = m_object->getObjectProperty("parent"))
|
||||
{
|
||||
m_getParentRequestId = parentObject->getObject(
|
||||
[this](const ObjectPtr& obj, std::optional<const Error> ec)
|
||||
{
|
||||
if(obj && !ec)
|
||||
{
|
||||
m_getParentRequestId = Connection::invalidRequestId;
|
||||
m_parentObject = obj;
|
||||
updateKeyIcons();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(m_items) /*[[likely]]*/
|
||||
{
|
||||
m_getItemsRequestId = m_items->getObjects(
|
||||
@ -123,6 +143,20 @@ OutputMapWidget::OutputMapWidget(ObjectPtr object, QWidget* parent)
|
||||
updateItems(objects);
|
||||
}
|
||||
});
|
||||
|
||||
connect(&BoardSettings::instance(), &BoardSettings::changed, this, &OutputMapWidget::updateKeyIcons);
|
||||
}
|
||||
}
|
||||
|
||||
OutputMapWidget::~OutputMapWidget()
|
||||
{
|
||||
if(m_getParentRequestId != Connection::invalidRequestId)
|
||||
{
|
||||
m_object->connection()->cancelRequest(m_getParentRequestId);
|
||||
}
|
||||
if(m_getItemsRequestId != Connection::invalidRequestId)
|
||||
{
|
||||
m_object->connection()->cancelRequest(m_getItemsRequestId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,9 +238,65 @@ void OutputMapWidget::updateItems(const std::vector<ObjectPtr>& items)
|
||||
}
|
||||
}
|
||||
|
||||
updateKeyIcons();
|
||||
updateTableOutputColumns();
|
||||
}
|
||||
|
||||
void OutputMapWidget::updateKeyIcons()
|
||||
{
|
||||
if(!m_parentObject)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(auto tileIdProperty = m_parentObject->getProperty("tile_id"))
|
||||
{
|
||||
const bool darkBackground = m_table->palette().window().color().lightnessF() < 0.5;
|
||||
const auto tileId = tileIdProperty->toEnum<TileId>();
|
||||
|
||||
const int iconSize = m_table->iconSize().height();
|
||||
QImage image(iconSize, iconSize, QImage::Format_ARGB32);
|
||||
QPainter painter{&image};
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
TilePainter tilePainter{painter, iconSize, *getBoardColorScheme(darkBackground ? BoardSettings::ColorScheme::Dark : BoardSettings::ColorScheme::Light)};
|
||||
|
||||
for(size_t i = 0; i < m_itemObjects.size(); i++)
|
||||
{
|
||||
if(auto* key = m_itemObjects[i]->getProperty("key"))
|
||||
{
|
||||
image.fill(Qt::transparent);
|
||||
|
||||
if(isRailTurnout(tileId))
|
||||
{
|
||||
tilePainter.drawTurnout(tileId, image.rect(), TileRotate::Deg0, TurnoutPosition::Unknown, static_cast<TurnoutPosition>(key->toInt()));
|
||||
}
|
||||
else if(isRailSignal(tileId))
|
||||
{
|
||||
tilePainter.drawSignal(tileId, image.rect(), TileRotate::Deg0, false, static_cast<SignalAspect>(key->toInt()));
|
||||
}
|
||||
else if(tileId == TileId::RailDirectionControl)
|
||||
{
|
||||
tilePainter.drawDirectionControl(tileId, image.rect(), TileRotate::Deg0, false, static_cast<DirectionControlState>(key->toInt()));
|
||||
}
|
||||
else if(tileId == TileId::RailDecoupler)
|
||||
{
|
||||
tilePainter.drawRailDecoupler(image.rect(), TileRotate::Deg90, false, static_cast<DecouplerState>(key->toInt()));
|
||||
}
|
||||
else if(tileId == TileId::Switch)
|
||||
{
|
||||
tilePainter.drawSwitch(image.rect(), key->toBool());
|
||||
}
|
||||
else
|
||||
{
|
||||
break; // tileId not supported (yet)
|
||||
}
|
||||
|
||||
m_table->item(i, columnKey)->setIcon(QPixmap::fromImage(image));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OutputMapWidget::updateTableOutputColumns()
|
||||
{
|
||||
if(m_addresses && m_addresses->getAttributeBool(AttributeName::Visible, true))
|
||||
|
||||
@ -40,6 +40,7 @@ class OutputMapWidget : public QWidget
|
||||
|
||||
protected:
|
||||
ObjectPtr m_object;
|
||||
ObjectPtr m_parentObject;
|
||||
const bool m_hasUseColumn;
|
||||
const int m_columnCountNonOutput;
|
||||
AbstractVectorProperty* m_addresses;
|
||||
@ -48,15 +49,18 @@ class OutputMapWidget : public QWidget
|
||||
QTableWidget* m_table;
|
||||
std::vector<ObjectPtr> m_itemObjects;
|
||||
std::vector<std::vector<ObjectPtr>> m_actions;
|
||||
int m_getParentRequestId;
|
||||
int m_getItemsRequestId;
|
||||
int m_dummy;
|
||||
|
||||
void updateTableOutputActions(ObjectVectorProperty& property, int row);
|
||||
void updateItems(const std::vector<ObjectPtr>& items);
|
||||
void updateKeyIcons();
|
||||
void updateTableOutputColumns();
|
||||
|
||||
public:
|
||||
explicit OutputMapWidget(ObjectPtr object, QWidget* parent = nullptr);
|
||||
~OutputMapWidget() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren