23 #include "cfgwadalias.h"
24 #include "ui_cfgwadalias.h"
26 #include "configuration/doomseekerconfig.h"
27 #include "gui/commongui.h"
28 #include "pathfinder/filealias.h"
32 DClass<CFGWadAlias> :
public Ui::CFGWadAlias
42 QString matchTypeHelp;
53 d->resizeTimer.setSingleShot(
true);
54 d->resizeTimer.setInterval(0);
55 connect(&d->resizeTimer, SIGNAL(timeout()), d->table, SLOT(resizeRowsToContents()));
57 QHeaderView *header = d->table->horizontalHeader();
58 connect(header, SIGNAL(sectionResized(
int,
int,
int)), &d->resizeTimer, SLOT(start()));
66 d->matchTypeHelp = CFGWadAlias::tr(
"Left-to-Right will use the alias files instead of "
67 "the main file but not vice-versa.");
68 d->matchTypeHelp +=
"\n\n";
69 d->matchTypeHelp += CFGWadAlias::tr(
"All Equal will treat all files as equal and try to "
70 "match them in any combination.");
73 CFGWadAlias::~CFGWadAlias()
77 void CFGWadAlias::addAliasToTable(
const FileAlias &alias)
79 bool wasSortingEnabled = d->table->isSortingEnabled();
80 d->table->setSortingEnabled(
false);
82 int row = findRowWithWad(alias.name());
85 row = d->table->rowCount();
87 applyAliasToRow(row, alias);
92 FileAlias existingAlias = aliasFromRow(row);
94 applyAliasToRow(row, existingAlias);
97 d->table->setSortingEnabled(wasSortingEnabled);
100 void CFGWadAlias::addDefaults()
105 addAliasToTable(alias);
109 void CFGWadAlias::addNewEntry()
111 bool wasSortingEnabled = d->table->isSortingEnabled();
112 d->table->setSortingEnabled(
false);
114 int row = d->table->rowCount();
115 d->table->insertRow(row);
118 mkMatchTypeComboBox(row);
120 d->table->setSortingEnabled(wasSortingEnabled);
121 resizeRowToContents(row);
124 QList<FileAlias> CFGWadAlias::aliases()
const
126 QList<FileAlias> aliases;
127 for (
int row = 0; row < d->table->rowCount(); ++row)
133 return FileAliasList::mergeDuplicates(aliases);
136 FileAlias CFGWadAlias::aliasFromRow(
int row)
const
141 for (
const QString &candidateAlias : candidateAliases)
143 if (!candidateAlias.trimmed().isEmpty())
144 alias.
addAlias(candidateAlias.trimmed());
146 auto cboMatchType = qobject_cast<QComboBox *>(d->table->cellWidget(
148 alias.setMatchType(static_cast<FileAlias::MatchType>(
149 cboMatchType->itemData(cboMatchType->currentIndex()).toInt()));
153 void CFGWadAlias::applyAliasToRow(
int row,
const FileAlias &alias)
158 auto cboMatchType = qobject_cast<QComboBox *>(
160 int matchTypeIdx = qMax(0, cboMatchType->findData(alias.matchType()));
161 cboMatchType->setCurrentIndex(matchTypeIdx);
164 int CFGWadAlias::findRowWithWad(
const QString &wadName)
166 for (
int row = 0; row < d->table->rowCount(); ++row)
169 wadName.trimmed(), Qt::CaseInsensitive) == 0)
179 return style()->standardIcon(QStyle::SP_DirOpenIcon);
182 QComboBox *CFGWadAlias::mkMatchTypeComboBox(
int row)
184 auto cboMatchType =
new QComboBox();
185 cboMatchType->setToolTip(d->matchTypeHelp);
186 cboMatchType->addItem(tr(
"Left-to-Right"), FileAlias::LeftToRight);
187 cboMatchType->addItem(tr(
"All Equal"), FileAlias::AllEqual);
194 bool wasSortingEnabled = d->table->isSortingEnabled();
195 d->table->setSortingEnabled(
false);
197 while (d->table->rowCount() > 0)
199 d->table->removeRow(0);
202 QList<FileAlias> aliases = gConfig.doomseeker.wadAliases();
206 addAliasToTable(alias);
209 d->table->setSortingEnabled(wasSortingEnabled);
212 void CFGWadAlias::removeSelected()
214 CommonGUI::removeSelectedRowsFromQTableWidget(d->table);
217 void CFGWadAlias::resizeRowsToContents()
220 d->resizeTimer.start();
222 d->table->resizeRowsToContents();
226 void CFGWadAlias::resizeRowToContents(
int row)
229 resizeRowsToContents();
231 d->table->resizeRowToContents(row);
237 gConfig.doomseeker.setWadAliases(aliases());
240 void CFGWadAlias::showEvent(QShowEvent *event)
243 resizeRowsToContents();
246 QTableWidgetItem *CFGWadAlias::toolTipItem(
const QString &contents)
248 auto item =
new QTableWidgetItem(contents);
249 item->setToolTip(contents);