1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/mapeditor/mapsettings/rumorsettings.cpp

84 lines
2.1 KiB
C++
Raw Normal View History

2023-09-08 17:54:34 +02:00
/*
* rumorsettings.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "rumorsettings.h"
#include "ui_rumorsettings.h"
#include "../mapcontroller.h"
2023-09-08 17:54:34 +02:00
RumorSettings::RumorSettings(QWidget *parent) :
AbstractSettings(parent),
ui(new Ui::RumorSettings)
{
ui->setupUi(this);
}
RumorSettings::~RumorSettings()
{
delete ui;
}
void RumorSettings::initialize(MapController & c)
2023-09-08 17:54:34 +02:00
{
AbstractSettings::initialize(c);
for(auto & rumor : controller->map()->rumors)
2023-09-08 17:54:34 +02:00
{
auto * item = new QListWidgetItem(QString::fromStdString(rumor.name));
2023-09-28 13:28:37 +02:00
item->setData(Qt::UserRole, QVariant(QString::fromStdString(rumor.text.toString())));
2023-09-08 17:54:34 +02:00
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->rumors->addItem(item);
}
}
void RumorSettings::update()
2023-09-08 17:54:34 +02:00
{
controller->map()->rumors.clear();
2023-09-08 17:54:34 +02:00
for(int i = 0; i < ui->rumors->count(); ++i)
{
Rumor rumor;
rumor.name = ui->rumors->item(i)->text().toStdString();
2023-09-29 00:24:45 +02:00
rumor.text.appendTextID(mapRegisterLocalizedString("map", *controller->map(), TextIdentifier("header", "rumor", i, "text"), ui->rumors->item(i)->data(Qt::UserRole).toString().toStdString()));
controller->map()->rumors.push_back(rumor);
2023-09-08 17:54:34 +02:00
}
}
void RumorSettings::on_message_textChanged()
{
if(auto item = ui->rumors->currentItem())
item->setData(Qt::UserRole, QVariant(ui->message->toPlainText()));
}
void RumorSettings::on_add_clicked()
{
auto * item = new QListWidgetItem(tr("New rumor"));
item->setData(Qt::UserRole, QVariant(""));
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->rumors->addItem(item);
emit ui->rumors->itemActivated(item);
}
void RumorSettings::on_remove_clicked()
{
if(auto item = ui->rumors->currentItem())
{
ui->message->setPlainText("");
ui->rumors->takeItem(ui->rumors->row(item));
}
}
void RumorSettings::on_rumors_itemSelectionChanged()
{
if(auto item = ui->rumors->currentItem())
ui->message->setPlainText(item->data(Qt::UserRole).toString());
}