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 #include "fontlistview.h"
8 #include "fontlistmodel.h"
9 
10 
FontListView(QWidget * parent)11 FontListView::FontListView(QWidget * parent)
12 	: QTableView(parent)
13 {
14 	setSelectionMode(QAbstractItemView::SingleSelection);
15 	setSelectionBehavior(QAbstractItemView::SelectRows);
16 	sortByColumn(FontListModel::SortIndex, Qt::AscendingOrder);
17 	// do not show default sorting to user
18 	hideColumn(FontListModel::SortIndex);
19 	setSortingEnabled(false);
20 	setAlternatingRowColors(true);
21 }
22 
setModel(QAbstractItemModel * model)23 void FontListView::setModel(QAbstractItemModel * model)
24 {
25 	QTableView::setModel(model);
26 	resizeColumnsToContents();
27 }
28 
setFonts(const SCFonts & f)29 void FontListView::setFonts(const SCFonts& f)
30 {
31 	qobject_cast<FontListModel*>(model())->setFonts(f.keys());
32 	if (!isSortingEnabled())
33 		sortByColumn(FontListModel::SortIndex, Qt::AscendingOrder);
34 }
35 
fontName(int i)36 QString FontListView::fontName(int i)
37 {
38 	FontListModel* fontModel = qobject_cast<FontListModel*>(model());
39 	QModelIndex cellIndex = fontModel->index(i, FontListModel::FontName);
40 	return fontModel->nameForIndex(cellIndex);
41 }
42 
isFontUsable(int i)43 bool FontListView::isFontUsable(int i)
44 {
45 	FontListModel* fontModel = qobject_cast<FontListModel*>(model());
46 	QModelIndex cellIndex = fontModel->index(i, FontListModel::FontUsable);
47 	QVariant    checkData = fontModel->data(cellIndex, Qt::CheckStateRole);
48 	Qt::CheckState checkState = static_cast<Qt::CheckState>(checkData.toInt());
49 	return (checkState == Qt::Checked);
50 }
51 
isFontSubsetted(int i)52 bool FontListView::isFontSubsetted(int i)
53 {
54 	FontListModel* fontModel = qobject_cast<FontListModel*>(model());
55 	QModelIndex cellIndex = fontModel->index(i, FontListModel::FontSubset);
56 	QVariant    checkData = fontModel->data(cellIndex, Qt::CheckStateRole);
57 	Qt::CheckState checkState = static_cast<Qt::CheckState>(checkData.toInt());
58 	return (checkState == Qt::Checked);
59 }
60 
61