23 #include "maplistpanel.h" 24 #include "ui_maplistpanel.h" 26 #include "commongui.h" 27 #include "gui/createserverdialog.h" 29 #include "maplistselector.h" 30 #include "plugins/engineplugin.h" 31 #include "serverapi/gamecreateparams.h" 33 #include <QStandardItemModel> 36 DClass<MapListPanel> :
public Ui::MapListPanel
48 d->lstMaplist->setModel(
new QStandardItemModel(
this));
49 this->connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*,QWidget*)),
50 SLOT(onFocusChanged(QWidget*,QWidget*)));
52 d->parentDialog =
nullptr;
54 d->lblWarning->setText(MapListPanel::tr(
"Current map isn't present on map list. Game may misbehave."));
55 d->lblWarning->setPixmap(QPixmap(
":/icons/exclamation.png"));
56 d->lblWarning->setWordWrap(
true);
59 MapListPanel::~MapListPanel()
63 void MapListPanel::addMapFromEditBoxToList()
65 addMapToMaplist(d->leMapname->text().trimmed());
68 void MapListPanel::addMapsFromLoadedWads()
71 mapListSelector->addPaths(d->parentDialog->wadPaths());
72 if (mapListSelector->exec() == QDialog::Accepted)
74 for (QString map : mapListSelector->selectedMaps())
81 void MapListPanel::addMapToMaplist(
const QString &map)
85 auto model =
static_cast<QStandardItemModel *
>(d->lstMaplist->model());
86 auto it =
new QStandardItem(map);
87 it->setDragEnabled(
true);
88 it->setDropEnabled(
false);
90 updateMapWarningVisibility();
93 void MapListPanel::onFocusChanged(QWidget *old, QWidget *now)
95 if (now == d->leMapname)
96 d->btnAddMapToMaplist->setDefault(
true);
97 else if (old == d->leMapname)
98 d->btnAddMapToMaplist->setDefault(
false);
101 void MapListPanel::removeSelectedFromList()
103 const bool bSelectNextLowest =
true;
105 updateMapWarningVisibility();
111 params.setRandomMapRotation(d->cbRandomMapRotation->isChecked());
114 bool MapListPanel::hasMaps()
const 116 return d->lstMaplist->model()->rowCount() > 0;
119 bool MapListPanel::isMapOnList(
const QString &mapName)
const 123 if (candidate.compare(mapName, Qt::CaseInsensitive) == 0)
129 void MapListPanel::showEvent(QShowEvent *event)
132 updateMapWarningVisibility();
135 void MapListPanel::updateMapWarningVisibility()
137 d->lblWarning->setVisible(hasMaps() && !isMapOnList(d->parentDialog->mapName()));
140 void MapListPanel::loadConfig(
Ini &config)
143 QStringList stringList = section[
"maplist"].valueString().split(
";");
144 QAbstractItemModel *model = d->lstMaplist->model();
145 model->removeRows(0, model->rowCount());
146 for (QString s : stringList)
150 d->cbRandomMapRotation->setChecked(section[
"randomMapRotation"]);
153 QTimer::singleShot(0,
this, SLOT(updateMapWarningVisibility()));
156 void MapListPanel::saveConfig(
Ini &config)
160 section[
"maplist"] = stringList.join(
";");
161 section[
"randomMapRotation"] = d->cbRandomMapRotation->isChecked();
166 d->parentDialog = dialog;
169 void MapListPanel::setupForEngine(
const EnginePlugin *engine)
171 d->cbRandomMapRotation->setVisible(engine->data()->supportsRandomMapRotation);
static QStringList listViewStandardItemsToStringList(QListView *listview)
Reads items from a QListView that uses QStandardItemModel and puts texts of these items into a list o...
Game parametrization data used when creating new games.
static void removeSelectedRowsFromStandardItemView(QAbstractItemView *view, bool bSelectNextItem=false)
Removes all selected rows from a QAbstractItemView.
Prompts the user to select a list of maps to insert.
Dialog window allowing user to create a game.
INI section representation.
IniSection section(const QString &name)
Access configuration file section.