summaryrefslogtreecommitdiffstats
path: root/scribus/smstyleimport.cpp
blob: b186704486ca16b2ef2bfae2d953ea9554b6ce89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/

#include <QCheckBox>

#include "smstyleimport.h"


SMStyleImport::SMStyleImport(QWidget* parent,
							 StyleSet<ParagraphStyle> *pstyleList,
							 StyleSet<CharStyle> *cstyleList,
							 QMap<QString, multiLine> *lstyleList)
	: QDialog( parent, 0 )
{
	setupUi(this);
	setModal(true);
	cstyleItem = new QTreeWidgetItem(styleWidget);
	cstyleItem->setText(0, tr("Character Styles"));
	for (int x = 0; x < cstyleList->count(); ++x)
	{
		CharStyle& vg ((*cstyleList)[x]);
		QCheckBox *box = new QCheckBox(vg.name());
		box->setChecked(true);
		QTreeWidgetItem *item = new QTreeWidgetItem(cstyleItem, cType);
		styleWidget->setItemWidget(item, 0, box);
	}
	styleWidget->expandItem(cstyleItem);

	pstyleItem = new QTreeWidgetItem(styleWidget);
	pstyleItem->setText(0, tr("Paragraph Styles"));
	for (int x = 0; x < pstyleList->count(); ++x)
	{
		ParagraphStyle& vg ((*pstyleList)[x]);
		QCheckBox *box = new QCheckBox(vg.name());
		box->setChecked(true);
		QTreeWidgetItem *item = new QTreeWidgetItem(pstyleItem, pType);
		styleWidget->setItemWidget(item, 0, box);
	}
	styleWidget->expandItem(pstyleItem);

	lstyleItem = new QTreeWidgetItem(styleWidget);
	lstyleItem->setText(0, tr("Line Styles"));
	QList<QString> lkeys = lstyleList->keys();
	for (int x = 0; x < lkeys.count(); ++x)
	{
		QCheckBox *box = new QCheckBox(lkeys[x]);
		box->setChecked(true);
		QTreeWidgetItem *item = new QTreeWidgetItem(lstyleItem, lType);
		styleWidget->setItemWidget(item, 0, box);
	}
	styleWidget->expandItem(lstyleItem);

	connect(importAllCheckBox, SIGNAL(clicked(bool)), this, SLOT(checkAll(bool)));
}

bool SMStyleImport::clashRename()
{
	return renameButton->isChecked();
}

QStringList SMStyleImport::paragraphStyles()
{
	return commonStyles(pstyleItem, pType);
}

QStringList SMStyleImport::characterStyles()
{
	return commonStyles(cstyleItem, cType);
}

QStringList SMStyleImport::lineStyles()
{
	return commonStyles(lstyleItem, lType);
}

QStringList SMStyleImport::commonStyles(QTreeWidgetItem * rootItem, int type)
{
	QStringList ret;
	QTreeWidgetItemIterator it(styleWidget);

	while (*it)
	{
		if ((*it)->type() == type)
		{
			QCheckBox *w = qobject_cast<QCheckBox*>(styleWidget->itemWidget((*it), 0));
			if (w && w->isChecked())
				ret.append(w->text());
		}
		++it;
	}
	return ret;
}

void SMStyleImport::checkAll(bool allChecked)
{
	QStringList ret;
	QTreeWidgetItemIterator it(styleWidget);

	while (*it)
	{
		QCheckBox *w = qobject_cast<QCheckBox*>(styleWidget->itemWidget((*it), 0));
		if (w)
			w->setCheckState(allChecked ? Qt::Checked : Qt::Unchecked);
		++it;
	}
}