23 #include "maplistpanel.h" 24 #include "ui_maplistpanel.h" 27 #include "gui/createserverdialog.h" 28 #include "plugins/engineplugin.h" 29 #include "serverapi/gamecreateparams.h" 30 #include "commongui.h" 31 #include <QStandardItemModel> 34 DClass<MapListPanel> :
public Ui::MapListPanel
46 d->lstMaplist->setModel(
new QStandardItemModel(
this));
47 this->connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)),
48 SLOT(onFocusChanged(QWidget*, QWidget*)));
50 d->parentDialog = NULL;
52 d->lblWarning->setText(MapListPanel::tr(
"Current map isn't present on map list. Game may misbehave."));
53 d->lblWarning->setPixmap(QPixmap(
":/icons/exclamation.png"));
54 d->lblWarning->setWordWrap(
true);
57 MapListPanel::~MapListPanel()
61 void MapListPanel::addMapFromEditBoxToList()
63 addMapToMaplist(d->leMapname->text().trimmed());
66 void MapListPanel::addMapToMaplist(
const QString &map)
72 QStandardItemModel* model =
static_cast<QStandardItemModel*
>(d->lstMaplist->model());
73 QStandardItem* it =
new QStandardItem(map);
74 it->setDragEnabled(
true);
75 it->setDropEnabled(
false);
77 updateMapWarningVisibility();
80 void MapListPanel::onFocusChanged(QWidget* old, QWidget* now)
82 if (now == d->leMapname)
84 d->btnAddMapToMaplist->setDefault(
true);
86 else if (old == d->leMapname)
88 d->btnAddMapToMaplist->setDefault(
false);
92 void MapListPanel::removeSelectedFromList()
94 const bool bSelectNextLowest =
true;
96 updateMapWarningVisibility();
102 params.setRandomMapRotation(d->cbRandomMapRotation->isChecked());
105 bool MapListPanel::hasMaps()
const 107 return d->lstMaplist->model()->rowCount() > 0;
110 bool MapListPanel::isMapOnList(
const QString &mapName)
const 114 if (candidate.compare(mapName, Qt::CaseInsensitive) == 0)
122 void MapListPanel::showEvent(QShowEvent *event)
124 updateMapWarningVisibility();
127 void MapListPanel::updateMapWarningVisibility()
129 d->lblWarning->setVisible(hasMaps() && !isMapOnList(d->parentDialog->mapName()));
132 void MapListPanel::loadConfig(
Ini &config)
135 QStringList stringList = section[
"maplist"].valueString().split(
";");
136 QAbstractItemModel *model = d->lstMaplist->model();
137 model->removeRows(0, model->rowCount());
138 foreach(QString s, stringList)
142 d->cbRandomMapRotation->setChecked(section[
"randomMapRotation"]);
145 QTimer::singleShot(0,
this, SLOT(updateMapWarningVisibility()));
148 void MapListPanel::saveConfig(
Ini &config)
152 section[
"maplist"] = stringList.join(
";");
153 section[
"randomMapRotation"] = d->cbRandomMapRotation->isChecked();
158 d->parentDialog = dialog;
161 void MapListPanel::setupForEngine(
const EnginePlugin *engine)
163 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.
Dialog window allowing user to create a game.
INI section representation.
IniSection section(const QString &name)
Access configuration file section.