23 #include "cfgwadalias.h"
24 #include "ui_cfgwadalias.h"
26 #include "configuration/doomseekerconfig.h"
27 #include "gui/commongui.h"
28 #include "pathfinder/filealias.h"
31 DClass<CFGWadAlias> :
public Ui::CFGWadAlias
41 QString matchTypeHelp;
52 d->resizeTimer.setSingleShot(
true);
53 d->resizeTimer.setInterval(0);
54 connect(&d->resizeTimer, SIGNAL(timeout()), d->table, SLOT(resizeRowsToContents()));
56 QHeaderView *header = d->table->horizontalHeader();
57 connect(header, SIGNAL(sectionResized(
int,
int,
int)), &d->resizeTimer, SLOT(start()));
65 d->matchTypeHelp = CFGWadAlias::tr(
"Left-to-Right will use the alias files instead of "
66 "the main file but not vice-versa.");
67 d->matchTypeHelp +=
"\n\n";
68 d->matchTypeHelp += CFGWadAlias::tr(
"All Equal will treat all files as equal and try to "
69 "match them in any combination.");
72 CFGWadAlias::~CFGWadAlias()
76 void CFGWadAlias::addAliasToTable(
const FileAlias &alias)
78 bool wasSortingEnabled = d->table->isSortingEnabled();
79 d->table->setSortingEnabled(
false);
81 int row = findRowWithWad(alias.name());
84 row = d->table->rowCount();
86 applyAliasToRow(row, alias);
91 FileAlias existingAlias = aliasFromRow(row);
93 applyAliasToRow(row, existingAlias);
96 d->table->setSortingEnabled(wasSortingEnabled);
99 void CFGWadAlias::addDefaults()
104 addAliasToTable(alias);
108 void CFGWadAlias::addNewEntry()
110 bool wasSortingEnabled = d->table->isSortingEnabled();
111 d->table->setSortingEnabled(
false);
113 int row = d->table->rowCount();
114 d->table->insertRow(row);
117 mkMatchTypeComboBox(row);
119 d->table->setSortingEnabled(wasSortingEnabled);
120 resizeRowToContents(row);
123 QList<FileAlias> CFGWadAlias::aliases()
const
125 QList<FileAlias> aliases;
126 for (
int row = 0; row < d->table->rowCount(); ++row)
132 return FileAliasList::mergeDuplicates(aliases);
135 FileAlias CFGWadAlias::aliasFromRow(
int row)
const
140 for (
const QString &candidateAlias : candidateAliases)
142 if (!candidateAlias.trimmed().isEmpty())
143 alias.
addAlias(candidateAlias.trimmed());
145 auto cboMatchType = qobject_cast<QComboBox *>(d->table->cellWidget(
147 alias.setMatchType(static_cast<FileAlias::MatchType>(
148 cboMatchType->itemData(cboMatchType->currentIndex()).toInt()));
152 void CFGWadAlias::applyAliasToRow(
int row,
const FileAlias &alias)
157 auto cboMatchType = qobject_cast<QComboBox *>(
159 int matchTypeIdx = qMax(0, cboMatchType->findData(alias.matchType()));
160 cboMatchType->setCurrentIndex(matchTypeIdx);
163 int CFGWadAlias::findRowWithWad(
const QString &wadName)
165 for (
int row = 0; row < d->table->rowCount(); ++row)
168 wadName.trimmed(), Qt::CaseInsensitive) == 0)
178 return QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon);
181 QComboBox *CFGWadAlias::mkMatchTypeComboBox(
int row)
183 auto cboMatchType =
new QComboBox();
184 cboMatchType->setToolTip(d->matchTypeHelp);
185 cboMatchType->addItem(tr(
"Left-to-Right"), FileAlias::LeftToRight);
186 cboMatchType->addItem(tr(
"All Equal"), FileAlias::AllEqual);
193 bool wasSortingEnabled = d->table->isSortingEnabled();
194 d->table->setSortingEnabled(
false);
196 while (d->table->rowCount() > 0)
198 d->table->removeRow(0);
201 QList<FileAlias> aliases = gConfig.doomseeker.wadAliases();
205 addAliasToTable(alias);
208 d->table->setSortingEnabled(wasSortingEnabled);
211 void CFGWadAlias::removeSelected()
213 CommonGUI::removeSelectedRowsFromQTableWidget(d->table);
216 void CFGWadAlias::resizeRowsToContents()
219 d->resizeTimer.start();
221 d->table->resizeRowsToContents();
225 void CFGWadAlias::resizeRowToContents(
int row)
228 resizeRowsToContents();
230 d->table->resizeRowToContents(row);
236 gConfig.doomseeker.setWadAliases(aliases());
239 void CFGWadAlias::showEvent(QShowEvent *event)
242 resizeRowsToContents();
245 QTableWidgetItem *CFGWadAlias::toolTipItem(
const QString &contents)
247 auto item =
new QTableWidgetItem(contents);
248 item->setToolTip(contents);