1 #include <QLineEdit>
2 #include <QToolButton>
3 #include <QCheckBox>
4 #include <QComboBox>
5 #include <QTreeWidgetItem>
6 #include <QStackedWidget>
7 #include <QApplication>
8 #include <QFileDialog>
9 #include <QList>
10 #include <QIcon>
11 
12 #include "settings.h"
13 #include "additionalartworksetup.h"
14 #include "fileeditwidget.h"
15 #include "direditwidget.h"
16 #include "qmc2main.h"
17 #include "options.h"
18 #include "componentsetup.h"
19 #include "customartwork.h"
20 #include "customsoftwareartwork.h"
21 #include "macros.h"
22 
23 extern MainWindow *qmc2MainWindow;
24 extern Settings *qmc2Config;
25 extern Options *qmc2Options;
26 extern ComponentSetup *qmc2ComponentSetup;
27 
AdditionalArtworkSetup(QWidget * parent)28 AdditionalArtworkSetup::AdditionalArtworkSetup(QWidget *parent)
29 	: QDialog(parent)
30 {
31 	setupUi(this);
32 #if QT_VERSION < 0x050000
33 	treeWidget->header()->setMovable(false);
34 #else
35 	treeWidget->header()->setSectionsMovable(false);
36 #endif
37 	load();
38 }
39 
~AdditionalArtworkSetup()40 AdditionalArtworkSetup::~AdditionalArtworkSetup()
41 {
42 }
43 
adjustIconSizes()44 void AdditionalArtworkSetup::adjustIconSizes()
45 {
46 	QFont f;
47 	f.fromString(qmc2Config->value(QMC2_FRONTEND_PREFIX + "GUI/Font").toString());
48 	QFontMetrics fm(f);
49 	QSize iconSize = QSize(fm.height() - 2, fm.height() - 2);
50 	pushButtonOk->setIconSize(iconSize);
51 	pushButtonCancel->setIconSize(iconSize);
52 	pushButtonRestore->setIconSize(iconSize);
53 	toolButtonAdd->setIconSize(iconSize);
54 	toolButtonRemove->setIconSize(iconSize);
55 }
56 
on_pushButtonOk_clicked()57 void AdditionalArtworkSetup::on_pushButtonOk_clicked()
58 {
59 	save();
60 	accept();
61 }
62 
on_pushButtonCancel_clicked()63 void AdditionalArtworkSetup::on_pushButtonCancel_clicked()
64 {
65 	reject();
66 }
67 
on_pushButtonRestore_clicked()68 void AdditionalArtworkSetup::on_pushButtonRestore_clicked()
69 {
70 	load();
71 }
72 
save()73 void AdditionalArtworkSetup::save()
74 {
75 	ComponentInfo *component2Info = qmc2ComponentSetup->componentInfoHash().value("Component2");
76 	int deleteAfterIndex = component2Info->availableFeatureList().indexOf(QMC2_SYSTEM_NOTES_INDEX);
77 	for (int i = component2Info->availableFeatureList().count(); i > deleteAfterIndex; i--)
78 		component2Info->availableFeatureList().removeAt(i);
79 	ComponentInfo *component4Info = qmc2ComponentSetup->componentInfoHash().value("Component4");
80 	deleteAfterIndex = component4Info->availableFeatureList().indexOf(QMC2_SWINFO_INFO_PAGE);
81 	for (int i = component4Info->availableFeatureList().count(); i > deleteAfterIndex; i--)
82 		component4Info->availableFeatureList().removeAt(i);
83 	QHash<QString, QStringList> savedActiveFormats;
84 	QHash<QString, int> savedFallbackSettings;
85 	qmc2Config->beginGroup("Artwork");
86 	foreach (QString name, qmc2Config->childGroups()) {
87 		if ( qmc2Config->contains(QString("%1/ActiveFormats").arg(name)) )
88 			savedActiveFormats.insert(name, qmc2Config->value(QString("%1/ActiveFormats").arg(name), QStringList()).toStringList());
89 		if ( qmc2Config->contains(QString("%1/Fallback").arg(name)) )
90 			savedFallbackSettings.insert(name, qmc2Config->value(QString("%1/Fallback").arg(name), 0).toInt());
91 	}
92 	qmc2Config->endGroup();
93 	qmc2Config->remove("Artwork");
94 	int systemArtworkIndex = 0, softwareArtworkIndex = 0;
95 	for (int i = 0; i < treeWidget->topLevelItemCount(); i++) {
96 		QTreeWidgetItem *item = treeWidget->topLevelItem(i);
97 		QLineEdit *lineEditName = (QLineEdit *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_NAME);
98 		QString name = lineEditName->text();
99 		if ( !name.isEmpty() ) {
100 			QToolButton *toolButtonIcon = (QToolButton *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_ICON);
101 			if ( !toolButtonIcon->whatsThis().isEmpty() )
102 				qmc2Config->setValue(QString("Artwork/%1/Icon").arg(name), toolButtonIcon->whatsThis());
103 			QComboBox *comboBoxTarget = (QComboBox *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_TARGET);
104 			qmc2Config->setValue(QString("Artwork/%1/Target").arg(name), comboBoxTarget->currentIndex());
105 			QComboBox *comboBoxScaled = (QComboBox *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_SCALED);
106 			qmc2Config->setValue(QString("Artwork/%1/Scaled").arg(name), comboBoxScaled->currentIndex());
107 			QComboBox *comboBoxType = (QComboBox *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_TYPE);
108 			qmc2Config->setValue(QString("Artwork/%1/Type").arg(name), comboBoxType->currentIndex());
109 			QComboBox *comboBoxFormat = (QComboBox *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_FORMAT);
110 			qmc2Config->setValue(QString("Artwork/%1/Format").arg(name), comboBoxFormat->currentIndex());
111 			QStackedWidget *stackedWidgetFolderOrArchive = (QStackedWidget *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_FOLDER_OR_ARCHIVE);
112 			DirectoryEditWidget *dewFolderOrArchive = (DirectoryEditWidget *)stackedWidgetFolderOrArchive->widget(QMC2_AW_INDEX_TYPE_FOLDER);
113 			if ( !dewFolderOrArchive->lineEditDirectory->text().isEmpty() )
114 				qmc2Config->setValue(QString("Artwork/%1/Folder").arg(name), dewFolderOrArchive->lineEditDirectory->text());
115 			FileEditWidget *fewFolderOrArchive = (FileEditWidget *)stackedWidgetFolderOrArchive->widget(QMC2_AW_INDEX_TYPE_ARCHIVE);
116 			if ( !fewFolderOrArchive->lineEditFile->text().isEmpty() )
117 				qmc2Config->setValue(QString("Artwork/%1/Archive").arg(name), fewFolderOrArchive->lineEditFile->text());
118 			if ( savedActiveFormats.contains(name) )
119 				qmc2Config->setValue(QString("Artwork/%1/ActiveFormats").arg(name), savedActiveFormats[name]);
120 			if ( savedFallbackSettings.contains(name) )
121 				qmc2Config->setValue(QString("Artwork/%1/Fallback").arg(name), savedFallbackSettings[name]);
122 			QString nameCopy = name;
123 			if ( comboBoxTarget->currentIndex() == QMC2_AW_INDEX_TARGET_SYSTEM ) {
124 				int featureIndex = QMC2_USEROFFSET_INDEX + systemArtworkIndex;
125 				systemArtworkIndex++;
126 				component2Info->setShortTitle(featureIndex, name);
127 				component2Info->setLongTitle(featureIndex, nameCopy.replace("&", QString()));
128 				component2Info->setIcon(featureIndex, QIcon(toolButtonIcon->whatsThis()));
129 				component2Info->availableFeatureList() << featureIndex;
130 				CustomArtwork *customArtwork = (CustomArtwork *)component2Info->widget(featureIndex);
131 				if ( customArtwork ) {
132 					customArtwork->setName(name);
133 					customArtwork->setNum(i);
134 					customArtwork->reopenSource();
135 					featureIndex = component2Info->appliedFeatureList().indexOf(featureIndex);
136 					if ( featureIndex >= 0 ) {
137 						qmc2MainWindow->tabWidgetMachineDetail->setTabText(featureIndex, name);
138 						qmc2MainWindow->tabWidgetMachineDetail->setTabIcon(featureIndex, QIcon(qmc2Config->value(QString("Artwork/%1/Icon").arg(name), QString()).toString()));
139 					}
140 				} else
141 					component2Info->setWidget(featureIndex, new CustomArtwork(0, name, i));
142 			} else {
143 				int featureIndex = QMC2_SWINFO_USEROFFSET_PAGE + softwareArtworkIndex;
144 				softwareArtworkIndex++;
145 				component4Info->setShortTitle(featureIndex, name);
146 				component4Info->setLongTitle(featureIndex, nameCopy.replace("&", QString()));
147 				component4Info->setIcon(featureIndex, QIcon(toolButtonIcon->whatsThis()));
148 				component4Info->availableFeatureList() << featureIndex;
149 				CustomSoftwareArtwork *customArtwork = (CustomSoftwareArtwork *)component4Info->widget(featureIndex);
150 				if ( customArtwork ) {
151 					customArtwork->setName(name);
152 					customArtwork->setNum(i);
153 					customArtwork->reopenSource();
154 					featureIndex = component4Info->appliedFeatureList().indexOf(featureIndex);
155 					if ( featureIndex >= 0 ) {
156 						qmc2MainWindow->tabWidgetSoftwareDetail->setTabText(featureIndex, name);
157 						qmc2MainWindow->tabWidgetSoftwareDetail->setTabIcon(featureIndex, QIcon(qmc2Config->value(QString("Artwork/%1/Icon").arg(name), QString()).toString()));
158 					}
159 				} else
160 					component4Info->setWidget(featureIndex, new CustomSoftwareArtwork(0, name, i));
161 			}
162 		}
163 	}
164 	qmc2ComponentSetup->saveComponent("Component2");
165 	qmc2ComponentSetup->saveComponent("Component4");
166 }
167 
load()168 void AdditionalArtworkSetup::load()
169 {
170 	treeWidget->clear();
171 	QFont f;
172 	f.fromString(qmc2Config->value(QMC2_FRONTEND_PREFIX + "GUI/Font").toString());
173 	QFontMetrics fm(f);
174 	QSize iconSize = QSize(fm.height() - 2, fm.height() - 2);
175 	m_seq = 0;
176 	m_itemHash.clear();
177 	qmc2Config->beginGroup("Artwork");
178 	foreach (QString name, qmc2Config->childGroups()) {
179 		QTreeWidgetItem *newItem = new QTreeWidgetItem(treeWidget);
180 		m_itemHash[m_seq] = newItem;
181 		QCheckBox *checkBoxSelect = new QCheckBox(this);
182 		checkBoxSelect->setToolTip(tr("Select / deselect this artwork class for removal"));
183 		connect(checkBoxSelect, SIGNAL(toggled(bool)), this, SLOT(selectionFlagsChanged(bool)));
184 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_SELECT, checkBoxSelect);
185 		QLineEdit *lineEditName = new QLineEdit(this);
186 		lineEditName->setPlaceholderText(tr("Artwork name"));
187 		lineEditName->setToolTip(tr("Enter a name for this artwork class (required)"));
188 		lineEditName->setText(name);
189 		connect(lineEditName, SIGNAL(textChanged(const QString &)), this, SLOT(dataChanged(const QString &)));
190 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_NAME, lineEditName);
191 		QToolButton *toolButtonIcon = new QToolButton(this);
192 		toolButtonIcon->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
193 		toolButtonIcon->setText(tr("Choose..."));
194 		toolButtonIcon->setIconSize(iconSize);
195 		toolButtonIcon->setToolTip(tr("Choose an icon file to be used for this artwork class (optional)"));
196 		QString iconPath = qmc2Config->value(QString("%1/Icon").arg(name), QString()).toString();
197 		if ( !iconPath.isEmpty() ) {
198 			toolButtonIcon->setIcon(QIcon(iconPath));
199 			toolButtonIcon->setWhatsThis(iconPath);
200 		}
201 		connect(toolButtonIcon, SIGNAL(clicked()), this, SLOT(chooseIcon()));
202 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_ICON, toolButtonIcon);
203 		QComboBox *comboBoxTarget = new QComboBox(this);
204 		comboBoxTarget->addItem(tr("System"));
205 		comboBoxTarget->addItem(tr("Software"));
206 		comboBoxTarget->setToolTip(tr("Select system or software as <i>target</i> for this artwork class"));
207 		int index = qmc2Config->value(QString("%1/Target").arg(name), 0).toInt();
208 		if ( index >= 0 && index < 2 )
209 			comboBoxTarget->setCurrentIndex(index);
210 		connect(comboBoxTarget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
211 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_TARGET, comboBoxTarget);
212 		QComboBox *comboBoxScaled = new QComboBox(this);
213 		comboBoxScaled->addItem(tr("On"));
214 		comboBoxScaled->addItem(tr("Off"));
215 		comboBoxScaled->setToolTip(tr("Choose if images of this artwork class are scaled or not"));
216 		index = qmc2Config->value(QString("%1/Scaled").arg(name), 0).toInt();
217 		if ( index >= 0 && index < 2 )
218 			comboBoxScaled->setCurrentIndex(index);
219 		connect(comboBoxScaled, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
220 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_SCALED, comboBoxScaled);
221 		QComboBox *comboBoxType = new QComboBox(this);
222 		comboBoxType->addItem(tr("Folder"));
223 		comboBoxType->addItem(tr("Archive"));
224 		comboBoxType->setToolTip(tr("Choose if images are loaded from a folder or an archive for this artwork class"));
225 		comboBoxType->setWhatsThis(QString::number(m_seq));
226 		index = qmc2Config->value(QString("%1/Type").arg(name), 0).toInt();
227 		if ( index >= 0 && index < 2 )
228 			comboBoxType->setCurrentIndex(index);
229 		connect(comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
230 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_TYPE, comboBoxType);
231 		QComboBox *comboBoxFormat = new QComboBox(this);
232 		comboBoxFormat->addItem(QIcon(":/data/img/compressed.png"), tr("ZIP"));
233 		comboBoxFormat->addItem(QIcon(":/data/img/7z-compressed.png"), tr("7z"));
234 #if defined(QMC2_LIBARCHIVE_ENABLED)
235 		comboBoxFormat->addItem(QIcon(":/data/img/archive.png"), tr("Archive"));
236 #endif
237 		comboBoxFormat->setToolTip(tr("Select archive format"));
238 		index = qmc2Config->value(QString("%1/Format").arg(name), 0).toInt();
239 #if defined(QMC2_LIBARCHIVE_ENABLED)
240 		if ( index >= 0 && index < 3 )
241 			comboBoxFormat->setCurrentIndex(index);
242 #else
243 		if ( index >= 0 && index < 2 )
244 			comboBoxFormat->setCurrentIndex(index);
245 #endif
246 		comboBoxFormat->setEnabled(comboBoxType->currentIndex() == QMC2_AW_INDEX_TYPE_ARCHIVE);
247 		connect(comboBoxFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
248 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_FORMAT, comboBoxFormat);
249 		FileEditWidget *fewFolderOrArchive = new FileEditWidget(QString(), tr("Supported archives") + " (*.[zZ][iI][pP] *.7[zZ]);;" + tr("ZIP archives") + " (*.[zZ][iI][pP]);;" + tr("7z archives") + " (*.7[zZ]);;" + tr("All files (*)"), QString(), this, false);
250 		fewFolderOrArchive->lineEditFile->setPlaceholderText(tr("Image archive"));
251 		fewFolderOrArchive->lineEditFile->setToolTip(tr("Image archive for this artwork class (required)") + " - " + tr("use semicolon (;) to separate multiple archives"));
252 		fewFolderOrArchive->toolButtonBrowse->setToolTip(tr("Browse image archive"));
253 		fewFolderOrArchive->lineEditFile->setText(qmc2Config->value(QString("%1/Archive").arg(name), QString()).toString());
254 		fewFolderOrArchive->setWhatsThis(QString::number(m_seq));
255 		connect(fewFolderOrArchive, SIGNAL(pathBrowsed(QString)), this, SLOT(pathBrowsed(QString)));
256 		connect(fewFolderOrArchive->lineEditFile, SIGNAL(textChanged(const QString &)), this, SLOT(dataChanged(const QString &)));
257 		DirectoryEditWidget *dewFolderOrArchive = new DirectoryEditWidget(QString(), this);
258 		dewFolderOrArchive->lineEditDirectory->setPlaceholderText(tr("Image folder"));
259 		dewFolderOrArchive->lineEditDirectory->setToolTip(tr("Image folder for this artwork class (required)") + " - " + tr("use semicolon (;) to separate multiple folders"));
260 		dewFolderOrArchive->toolButtonBrowse->setToolTip(tr("Browse image folder"));
261 		dewFolderOrArchive->lineEditDirectory->setText(qmc2Config->value(QString("%1/Folder").arg(name), QString()).toString());
262 		connect(dewFolderOrArchive->lineEditDirectory, SIGNAL(textChanged(const QString &)), this, SLOT(dataChanged(const QString &)));
263 		QStackedWidget *stackedWidgetFolderOrArchive = new QStackedWidget(this);
264 		stackedWidgetFolderOrArchive->insertWidget(QMC2_AW_INDEX_TYPE_FOLDER, dewFolderOrArchive);
265 		stackedWidgetFolderOrArchive->insertWidget(QMC2_AW_INDEX_TYPE_ARCHIVE, fewFolderOrArchive);
266 		index = qmc2Config->value(QString("%1/Type").arg(name), 0).toInt();
267 		if ( index >= 0 && index < 2 )
268 			stackedWidgetFolderOrArchive->setCurrentIndex(index);
269 		treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_FOLDER_OR_ARCHIVE, stackedWidgetFolderOrArchive);
270 		connect(comboBoxType, SIGNAL(currentIndexChanged(int)), stackedWidgetFolderOrArchive, SLOT(setCurrentIndex(int)));
271 		connect(comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(toggleFormatEnabled(int)));
272 		m_seq++;
273 	}
274 	qmc2Config->endGroup();
275 	for (int i = 0; i < treeWidget->columnCount(); i++)
276 		treeWidget->resizeColumnToContents(i);
277 	pushButtonRestore->setEnabled(false);
278 }
279 
on_toolButtonAdd_clicked()280 void AdditionalArtworkSetup::on_toolButtonAdd_clicked()
281 {
282 	QFont f;
283 	f.fromString(qmc2Config->value(QMC2_FRONTEND_PREFIX + "GUI/Font").toString());
284 	QFontMetrics fm(f);
285 	QSize iconSize = QSize(fm.height() - 2, fm.height() - 2);
286 	QTreeWidgetItem *newItem = new QTreeWidgetItem(treeWidget);
287 	m_itemHash[m_seq] = newItem;
288 	QCheckBox *checkBoxSelect = new QCheckBox(this);
289 	checkBoxSelect->setToolTip(tr("Select / deselect this artwork class for removal"));
290 	connect(checkBoxSelect, SIGNAL(toggled(bool)), this, SLOT(selectionFlagsChanged(bool)));
291 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_SELECT, checkBoxSelect);
292 	QLineEdit *lineEditName = new QLineEdit(this);
293 	lineEditName->setPlaceholderText(tr("Artwork name"));
294 	lineEditName->setToolTip(tr("Enter a name for this artwork class (required)"));
295 	connect(lineEditName, SIGNAL(textChanged(const QString &)), this, SLOT(dataChanged(const QString &)));
296 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_NAME, lineEditName);
297 	QToolButton *toolButtonIcon = new QToolButton(this);
298 	toolButtonIcon->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
299 	toolButtonIcon->setText(tr("Choose..."));
300 	toolButtonIcon->setIconSize(iconSize);
301 	toolButtonIcon->setToolTip(tr("Choose an icon file to be used for this artwork class (optional)"));
302 	connect(toolButtonIcon, SIGNAL(clicked()), this, SLOT(chooseIcon()));
303 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_ICON, toolButtonIcon);
304 	QComboBox *comboBoxTarget = new QComboBox(this);
305 	comboBoxTarget->addItem(tr("System"));
306 	comboBoxTarget->addItem(tr("Software"));
307 	comboBoxTarget->setToolTip(tr("Select system or software as <i>target</i> for this artwork class"));
308 	connect(comboBoxTarget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
309 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_TARGET, comboBoxTarget);
310 	QComboBox *comboBoxScaled = new QComboBox(this);
311 	comboBoxScaled->addItem(tr("On"));
312 	comboBoxScaled->addItem(tr("Off"));
313 	comboBoxScaled->setToolTip(tr("Choose if images of this artwork class are scaled or not"));
314 	connect(comboBoxScaled, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
315 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_SCALED, comboBoxScaled);
316 	QComboBox *comboBoxType = new QComboBox(this);
317 	comboBoxType->addItem(tr("Folder"));
318 	comboBoxType->addItem(tr("Archive"));
319 	comboBoxType->setToolTip(tr("Choose if images are loaded from a folder or an archive for this artwork class"));
320 	comboBoxType->setWhatsThis(QString::number(m_seq));
321 	connect(comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
322 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_TYPE, comboBoxType);
323 	QComboBox *comboBoxFormat = new QComboBox(this);
324 	comboBoxFormat->addItem(QIcon(":/data/img/compressed.png"), tr("ZIP"));
325 	comboBoxFormat->addItem(QIcon(":/data/img/7z-compressed.png"), tr("7z"));
326 #if defined(QMC2_LIBARCHIVE_ENABLED)
327 	comboBoxFormat->addItem(QIcon(":/data/img/archive.png"), tr("Archive"));
328 #endif
329 	comboBoxFormat->setToolTip(tr("Select archive format"));
330 	comboBoxFormat->setEnabled(false);
331 	connect(comboBoxFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged(int)));
332 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_FORMAT, comboBoxFormat);
333 	FileEditWidget *fewFolderOrArchive = new FileEditWidget(QString(), tr("Supported archives") + " (*.[zZ][iI][pP] *.7[zZ]);;" + tr("ZIP archives") + " (*.[zZ][iI][pP]);;" + tr("7z archives") + " (*.7[zZ]);;" + tr("All files (*)"), QString(), this, false);
334 	fewFolderOrArchive->lineEditFile->setPlaceholderText(tr("Image archive"));
335 	fewFolderOrArchive->lineEditFile->setToolTip(tr("Image archive for this artwork class (required)") + " - " + tr("use semicolon (;) to separate multiple archives"));
336 	fewFolderOrArchive->toolButtonBrowse->setToolTip(tr("Browse image archive"));
337 	fewFolderOrArchive->setWhatsThis(QString::number(m_seq));
338 	connect(fewFolderOrArchive, SIGNAL(pathBrowsed(QString)), this, SLOT(pathBrowsed(QString)));
339 	connect(fewFolderOrArchive->lineEditFile, SIGNAL(textChanged(const QString &)), this, SLOT(dataChanged(const QString &)));
340 	DirectoryEditWidget *dewFolderOrArchive = new DirectoryEditWidget(QString(), this);
341 	dewFolderOrArchive->lineEditDirectory->setPlaceholderText(tr("Image folder"));
342 	dewFolderOrArchive->lineEditDirectory->setToolTip(tr("Image folder for this artwork class (required)") + " - " + tr("use semicolon (;) to separate multiple folders"));
343 	dewFolderOrArchive->toolButtonBrowse->setToolTip(tr("Browse image folder"));
344 	connect(dewFolderOrArchive->lineEditDirectory, SIGNAL(textChanged(const QString &)), this, SLOT(dataChanged(const QString &)));
345 	QStackedWidget *stackedWidgetFolderOrArchive = new QStackedWidget(this);
346 	stackedWidgetFolderOrArchive->insertWidget(QMC2_AW_INDEX_TYPE_FOLDER, dewFolderOrArchive);
347 	stackedWidgetFolderOrArchive->insertWidget(QMC2_AW_INDEX_TYPE_ARCHIVE, fewFolderOrArchive);
348 	treeWidget->setItemWidget(newItem, QMC2_AW_COLUMN_FOLDER_OR_ARCHIVE, stackedWidgetFolderOrArchive);
349 	connect(comboBoxType, SIGNAL(currentIndexChanged(int)), stackedWidgetFolderOrArchive, SLOT(setCurrentIndex(int)));
350 	connect(comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(toggleFormatEnabled(int)));
351 	m_seq++;
352 	for (int i = 0; i < treeWidget->columnCount(); i++)
353 		treeWidget->resizeColumnToContents(i);
354 	dataChanged();
355 }
356 
toggleFormatEnabled(int index)357 void AdditionalArtworkSetup::toggleFormatEnabled(int index)
358 {
359 	QComboBox *cb = (QComboBox *)sender();
360 	if ( !cb )
361 		return;
362 	QTreeWidgetItem *item = m_itemHash[cb->whatsThis().toInt()];
363 	if ( !item )
364 		return;
365 	treeWidget->itemWidget(item, QMC2_AW_COLUMN_FORMAT)->setEnabled(cb->currentIndex() == QMC2_AW_INDEX_TYPE_ARCHIVE);
366 }
367 
pathBrowsed(QString path)368 void AdditionalArtworkSetup::pathBrowsed(QString path)
369 {
370 	FileEditWidget *few = (FileEditWidget *)sender();
371 	if ( !few )
372 		return;
373 	QTreeWidgetItem *item = m_itemHash[few->whatsThis().toInt()];
374 	if ( !item )
375 		return;
376 	QComboBox *cb = (QComboBox *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_FORMAT);
377 	if ( !cb )
378 		return;
379 	if ( path.toLower().endsWith(".zip") )
380 		cb->setCurrentIndex(QMC2_AW_INDEX_FORMAT_ZIP);
381 	else if ( path.toLower().endsWith(".7z") )
382 		cb->setCurrentIndex(QMC2_AW_INDEX_FORMAT_7Z);
383 #if defined(QMC2_LIBARCHIVE_ENABLED)
384 	else
385 		cb->setCurrentIndex(QMC2_AW_INDEX_FORMAT_ARCHIVE);
386 #endif
387 }
388 
on_toolButtonRemove_clicked()389 void AdditionalArtworkSetup::on_toolButtonRemove_clicked()
390 {
391 	for (int i = 0; i < treeWidget->topLevelItemCount(); i++) {
392 		QTreeWidgetItem *item = treeWidget->topLevelItem(i);
393 		QCheckBox *cb = (QCheckBox *)treeWidget->itemWidget(item, QMC2_AW_COLUMN_SELECT);
394 		if ( cb && cb->isChecked() ) {
395 			item = treeWidget->takeTopLevelItem(i);
396 			delete item;
397 			i--;
398 		}
399 	}
400 	selectionFlagsChanged();
401 	dataChanged();
402 }
403 
selectionFlagsChanged(bool)404 void AdditionalArtworkSetup::selectionFlagsChanged(bool)
405 {
406 	bool enable = false;
407 	for (int i = 0; i < treeWidget->topLevelItemCount() && !enable; i++) {
408 		QCheckBox *cb = (QCheckBox *)treeWidget->itemWidget(treeWidget->topLevelItem(i), QMC2_AW_COLUMN_SELECT);
409 		if ( cb )
410 			enable = cb->isChecked();
411 	}
412 	toolButtonRemove->setEnabled(enable);
413 }
414 
chooseIcon()415 void AdditionalArtworkSetup::chooseIcon()
416 {
417 	QToolButton *tb = (QToolButton *)sender();
418 	QString fileName = QFileDialog::getOpenFileName(this, tr("Choose icon file"), tb->whatsThis(), tr("PNG files (*.png)") + ";;" + tr("All files (*)"), 0, qmc2Options->useNativeFileDialogs() ? (QFileDialog::Options)0 : QFileDialog::DontUseNativeDialog);
419 	if ( !fileName.isEmpty() ) {
420 		tb->setIcon(QIcon(fileName));
421 		tb->setWhatsThis(fileName);
422 		dataChanged();
423 	}
424 }
425 
showEvent(QShowEvent * e)426 void AdditionalArtworkSetup::showEvent(QShowEvent *e)
427 {
428 	adjustIconSizes();
429 	adjustSize();
430 	for (int i = 0; i < treeWidget->columnCount(); i++)
431 		treeWidget->resizeColumnToContents(i);
432 	restoreGeometry(qmc2Config->value(QMC2_FRONTEND_PREFIX + "Layout/AdditionalArtworkSetup/Geometry", QByteArray()).toByteArray());
433 	if ( e )
434 		QDialog::showEvent(e);
435 }
436 
hideEvent(QHideEvent * e)437 void AdditionalArtworkSetup::hideEvent(QHideEvent *e)
438 {
439 	qmc2Config->setValue(QMC2_FRONTEND_PREFIX + "Layout/AdditionalArtworkSetup/Geometry", saveGeometry());
440 	on_pushButtonCancel_clicked();
441 	if ( e )
442 		QDialog::hideEvent(e);
443 }
444