23 #include "maplistselector.h" 25 #include "commongui.h" 26 #include "modreader.h" 30 #include <QScopedPointer> 31 #include <QSharedPointer> 34 MapEntry::MapEntry(
const QString &name,
const QString &originalFile,
const bool &isIwad)
37 this->originalFile = originalFile;
38 this->isIwad = isIwad;
41 DClass<MapListSelector> :
public Ui::MapListSelector
45 QList<MapEntry> mapList;
46 QScopedPointer<QTimer> checkWadTimer;
53 d->checkWadTimer.reset(
new QTimer);
57 connect(d->checkWadTimer.data(), SIGNAL(timeout()),
this, SLOT(performCheckStep()));
60 MapListSelector::~MapListSelector()
67 d->progressBar->setMaximum(d->progressBar->value() + paths.size());
68 setIfFinishedStateIsEnabled(
false);
69 d->checkWadTimer->start(0);
74 QStringList tempSelectedMapList;
75 for (
int i = 0; i < d->listMapsWidget->count(); ++i)
77 QListWidgetItem *item = d->listMapsWidget->item(i);
78 if (item->checkState() == Qt::Checked)
79 tempSelectedMapList << item->text();
81 return tempSelectedMapList;
84 void MapListSelector::performCheckStep()
86 if (d->paths.isEmpty())
88 d->checkWadTimer->stop();
89 setMapsOfCheckableList(d->mapList);
90 setIfFinishedStateIsEnabled(
true);
93 QString path = d->paths.takeFirst();
94 QSharedPointer<ModReader> modReader = ModReader::create(path);
95 if (!modReader.isNull() && modReader->load())
97 for (
const QString &tempMap : modReader->getAllMaps())
99 addEntryToMapList(
MapEntry(tempMap, QFile(path).fileName(), modReader->isIwad()));
102 d->progressBar->setValue(d->progressBar->value() + 1);
105 void MapListSelector::addEntryToMapList(
const MapEntry &newEntry)
107 bool equalEntryFound =
false;
108 for (
int i = 0; i < d->mapList.size(); ++i)
110 if (d->mapList[i].name == newEntry.name)
112 d->mapList.replace(i, newEntry);
113 equalEntryFound =
true;
116 if (!equalEntryFound)
117 d->mapList.append(newEntry);
120 void MapListSelector::setMapsOfCheckableList(
const QList<MapEntry> &list)
122 d->listMapsWidget->clear();
123 for (
const MapEntry &mapEntry : list)
125 auto item =
new QListWidgetItem(mapEntry.name, d->listMapsWidget);
126 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
127 item->setCheckState(Qt::Checked);
130 item->setBackground(Qt::lightGray);
131 item->setForeground(Qt::black);
133 item->setToolTip(
"File: " + mapEntry.originalFile);
137 void MapListSelector::setIfFinishedStateIsEnabled(
const bool &state)
139 d->btnAdd->setEnabled(state);
140 d->checkAll->setEnabled(state);
141 d->descriptionSelect->setVisible(state);
142 d->listMapsWidget->setVisible(state);
143 d->descriptionLoading->setVisible(!state);
144 d->progressBar->setVisible(!state);
148 void MapListSelector::accept()
153 void MapListSelector::reject()
155 d->listMapsWidget->clear();
156 d->checkWadTimer->stop();
160 void MapListSelector::selectAll()
162 Qt::CheckState checkState = d->checkAll->checkState();
163 for (
int i = 0; i < d->listMapsWidget->count(); ++i)
164 d->listMapsWidget->item(i)->setCheckState(checkState);
167 void MapListSelector::listItemChanged()
169 QStringList checkedMaps = selectedMaps();
170 if (checkedMaps.size() > 0 && checkedMaps.size() < d->listMapsWidget->count())
171 d->checkAll->setCheckState(Qt::PartiallyChecked);
174 d->checkAll->setCheckState((checkedMaps.size() == 0) ?
175 Qt::Unchecked : Qt::Checked);
179 void MapListSelector::showContextMenu(
const QPoint &pos)
181 QPoint globalPos = d->listMapsWidget->mapToGlobal(pos);
184 myMenu.addAction(tr(
"Invert selection"),
this, SLOT(invertSelection()));
185 myMenu.exec(globalPos);
188 void MapListSelector::invertSelection()
190 for (
int i = 0; i < d->listMapsWidget->count(); ++i)
192 QListWidgetItem *item = d->listMapsWidget->item(i);
193 if (item->isSelected())
194 item->setCheckState(item->checkState() == Qt::Unchecked ?
195 Qt::Checked : Qt::Unchecked);
Stores the name of the map and the mod where it came from.
Prompts the user to select a list of maps to insert.
const QStringList selectedMaps()
returns the list of maps that were checked.
void addPaths(const QStringList &paths)
adds the paths to check for maps. Please note that it will immediately start checking them...