Exemplo n.º 1
0
void TemplateIconView::addTemplateIcons(KileDocument::Type type)
{
	if(!m_templateManager) {
		return;
	}

	QString emptyIcon = QStandardPaths::locate(QStandardPaths::DataLocation, "pics/" + QString(DEFAULT_EMPTY_ICON) + ".png" );

	KileTemplate::Info emptyDocumentInfo;
	emptyDocumentInfo.name = KileTemplate::Manager::defaultEmptyTemplateCaption();
	emptyDocumentInfo.icon = emptyIcon;
	emptyDocumentInfo.type = type;
	TemplateItem *emp = new TemplateItem(this, emptyDocumentInfo);
 	setCurrentItem(emp);

	if(type == KileDocument::LaTeX) {
		// disable non standard templates
		QMap<QString,bool> map;
		map["Scrartcl"] = false;
		map["Scrbook"]  = false;
		map["Scrreprt"] = false;
		map["Scrlttr2"] = false;
		map["Beamer"]   = false;
		map["Prosper"]  = false;
		map["HA-prosper"] = false;
		
		// split search results and look, which class files are present
		QStringList list = m_output.split('\n');
		for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it) {
			QString filename = QFileInfo(*it).fileName();
			if(filename=="scrartcl.cls") {
				map["Scrartcl"] = true;
				map["Scrbook"]  = true;
				map["Scrreprt"] = true;
				map["Scrlttr2"] = true;
			}
			else if(filename=="beamer.cls") {
				map["Beamer"] = true;
			}
			else if(filename=="prosper.cls") {
				map["Prosper"] = true;
			}
			else if(filename=="HA-prosper.sty") {
				map["HA-prosper"] = true;
			}
		}
		
	
		KileTemplate::TemplateList templateList = m_templateManager->getTemplates(KileDocument::LaTeX);
		// insert all standard templates, all user-defined templates 
		// and those templates, which have a present class 
		for (KileTemplate::TemplateListIterator i=templateList.begin(); i != templateList.end(); ++i) {
			KileTemplate::Info info = *i;
			QString classname = info.name;
			if(!map.contains(classname) || map[classname]==true) {
				new TemplateItem(this, info);
			}
		}
	}
	else {
		KileTemplate::TemplateList templateList = m_templateManager->getTemplates(type);
		for (KileTemplate::TemplateListIterator i=templateList.begin(); i != templateList.end(); ++i) {
			new TemplateItem(this, *i);
		}
	}

	// sort all items (item for 'Empty Document' will always be the first one)
	sortItems();
}
Exemplo n.º 2
0
void TemplateIconView::addTemplateIcons(KileDocument::Type type)
{
	if(!m_templateManager) return;

	QString emptyIcon = KGlobal::dirs()->findResource("appdata", "pics/"+ QString(DEFAULT_EMPTY_ICON) + ".png" );

	KileTemplate::Info emptyDocumentInfo;
	emptyDocumentInfo.name = DEFAULT_EMPTY_CAPTION;
	emptyDocumentInfo.icon = emptyIcon;
	emptyDocumentInfo.type = type;
	TemplateItem *emp = new TemplateItem(this, emptyDocumentInfo);
	setSelected(emp, true);

	if(type == KileDocument::LaTeX) {
		// disable non standard templates
		QMap<QString,bool> map;
		map["Scrartcl"] = false;
		map["Scrbook"]  = false;
		map["Scrreprt"] = false;
		map["Scrlttr2"] = false;
		map["Beamer"]   = false;
		map["Prosper"]  = false;
		map["HA-prosper"] = false;
		
		// split search results and look, which class files are present
		QStringList list = QStringList::split("\n",m_output);
		for ( QStringList::Iterator it=list.begin(); it!=list.end(); ++it ) 
		{
			QString filename = QFileInfo(*it).fileName();
			if ( filename=="scrartcl.cls" )
			{
				map["Scrartcl"] = true;
				map["Scrbook"]  = true;
				map["Scrreprt"] = true;
				map["Scrlttr2"] = true;
			}
			else if ( filename=="beamer.cls" )  
				map["Beamer"] = true;
			else if ( filename=="prosper.cls" )
				map["Prosper"] = true;
			else if ( filename=="HA-prosper.sty" )
				map["HA-prosper"] = true;
		}
		
	
		KileTemplate::TemplateList templateList = m_templateManager->getTemplates(KileDocument::LaTeX);
		// insert all standard templates, all user defined templates 
		// and those templates, which have a present class 
		for (KileTemplate::TemplateListIterator i=templateList.begin(); i != templateList.end(); ++i)
		{
			KileTemplate::Info info = *i;
			QString classname = info.name;
			if ( !map.contains(classname) || map[classname]==true )
			{
				new TemplateItem(this, info);
			}
		}
	}
	else {
		KileTemplate::TemplateList templateList = m_templateManager->getTemplates(type); 
		for (KileTemplate::TemplateListIterator i=templateList.begin(); i != templateList.end(); ++i)
		{
			new TemplateItem(this, *i);
		}
	}

	// sort all items (item for 'Empty Document' will always be the first one)
	sort();
	
	// set the default item, if its given
	for ( QIconViewItem *item = firstItem(); item; item = item->nextItem() ) {
		if ( static_cast<TemplateItem*>(item)->name() == m_selicon ) {
			setSelected(item, true);
			ensureItemVisible(item);
		}
	}
}