1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 #include <QCheckBox>
9 
10 #include "smstyleimport.h"
11 
12 
SMStyleImport(QWidget * parent,StyleSet<ParagraphStyle> * pstyleList,StyleSet<CharStyle> * cstyleList,QHash<QString,multiLine> * lstyleList)13 SMStyleImport::SMStyleImport(QWidget* parent,
14 							 StyleSet<ParagraphStyle> *pstyleList,
15 							 StyleSet<CharStyle> *cstyleList,
16 							 QHash<QString, multiLine> *lstyleList)
17 	: QDialog(parent, Qt::WindowFlags())
18 {
19 	setupUi(this);
20 	setModal(true);
21 	cstyleItem = new QTreeWidgetItem(styleWidget);
22 	cstyleItem->setText(0, tr("Character Styles"));
23 	for (int x = 0; x < cstyleList->count(); ++x)
24 	{
25 		CharStyle& vg ((*cstyleList)[x]);
26 		QCheckBox *box = new QCheckBox(vg.name());
27 		box->setChecked(true);
28 		QTreeWidgetItem *item = new QTreeWidgetItem(cstyleItem, cType);
29 		styleWidget->setItemWidget(item, 0, box);
30 	}
31 	styleWidget->expandItem(cstyleItem);
32 
33 	pstyleItem = new QTreeWidgetItem(styleWidget);
34 	pstyleItem->setText(0, tr("Paragraph Styles"));
35 	for (int x = 0; x < pstyleList->count(); ++x)
36 	{
37 		ParagraphStyle& vg ((*pstyleList)[x]);
38 		QCheckBox *box = new QCheckBox(vg.name());
39 		box->setChecked(true);
40 		QTreeWidgetItem *item = new QTreeWidgetItem(pstyleItem, pType);
41 		styleWidget->setItemWidget(item, 0, box);
42 	}
43 	styleWidget->expandItem(pstyleItem);
44 
45 	lstyleItem = new QTreeWidgetItem(styleWidget);
46 	lstyleItem->setText(0, tr("Line Styles"));
47 	QList<QString> lkeys = lstyleList->keys();
48 	for (int x = 0; x < lkeys.count(); ++x)
49 	{
50 		QCheckBox *box = new QCheckBox(lkeys[x]);
51 		box->setChecked(true);
52 		QTreeWidgetItem *item = new QTreeWidgetItem(lstyleItem, lType);
53 		styleWidget->setItemWidget(item, 0, box);
54 	}
55 	styleWidget->expandItem(lstyleItem);
56 
57 	connect(importAllCheckBox, SIGNAL(clicked(bool)), this, SLOT(checkAll(bool)));
58 }
59 
clashRename()60 bool SMStyleImport::clashRename()
61 {
62 	return renameButton->isChecked();
63 }
64 
paragraphStyles()65 QStringList SMStyleImport::paragraphStyles()
66 {
67 	return commonStyles(pstyleItem, pType);
68 }
69 
characterStyles()70 QStringList SMStyleImport::characterStyles()
71 {
72 	return commonStyles(cstyleItem, cType);
73 }
74 
lineStyles()75 QStringList SMStyleImport::lineStyles()
76 {
77 	return commonStyles(lstyleItem, lType);
78 }
79 
commonStyles(QTreeWidgetItem * rootItem,int type)80 QStringList SMStyleImport::commonStyles(QTreeWidgetItem * rootItem, int type)
81 {
82 	QStringList ret;
83 	QTreeWidgetItemIterator it(styleWidget);
84 
85 	while (*it)
86 	{
87 		if ((*it)->type() == type)
88 		{
89 			QCheckBox *w = qobject_cast<QCheckBox*>(styleWidget->itemWidget((*it), 0));
90 			if (w && w->isChecked())
91 				ret.append(w->text());
92 		}
93 		++it;
94 	}
95 	return ret;
96 }
97 
checkAll(bool allChecked)98 void SMStyleImport::checkAll(bool allChecked)
99 {
100 	QStringList ret;
101 	QTreeWidgetItemIterator it(styleWidget);
102 
103 	while (*it)
104 	{
105 		QCheckBox *w = qobject_cast<QCheckBox*>(styleWidget->itemWidget((*it), 0));
106 		if (w)
107 			w->setCheckState(allChecked ? Qt::Checked : Qt::Unchecked);
108 		++it;
109 	}
110 }
111 
112