コード例 #1
0
QVariant BtModuleTextModel::bookData(const QModelIndex & index, int role) const {
    if (role == ModuleEntry::TextRole) {
        const CSwordBookModuleInfo *bookModule = qobject_cast<const CSwordBookModuleInfo*>(m_moduleInfoList.at(0));
        CSwordTreeKey key(bookModule->tree(), bookModule);
        int bookIndex = index.row() * 4;
        key.setIndex(bookIndex);
        Rendering::CEntryDisplay entryDisplay;
        QList<const CSwordModuleInfo*> moduleList;
        moduleList << bookModule;
        QString text = entryDisplay.textKeyRendering(moduleList, key.key(),
                                                     m_displayOptions, m_filterOptions,
                                                     Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey);
        text.replace("#CHAPTERTITLE#", "");
        return CSwordModuleSearch::highlightSearchedText(text, m_highlightWords);
        return text;
    }
    return QString();
}
コード例 #2
0
QVariant BtMiniModuleTextModel::data(const QModelIndex &index, int role) const
{
    Q_D(const BtMiniModuleTextModel);

    switch(role)
	{
    case BtMini::PreviewUpdateRole:
	case BtMini::PreviewRole:
		{
            const BtMiniModuleTextModelPrivate::List *list = d->indexList(index);

            // put to thread processing
            if(role == BtMini::PreviewUpdateRole)
            {
                ;
            }


            if(list->_module->type() == CSwordModuleInfo::GenericBook)
            {
                CSwordBookModuleInfo *b = qobject_cast<CSwordBookModuleInfo*>(list->_module);
                CSwordTreeKey k(b->tree(), b);

                k.setIndex(index.row() * 4);

                return QString("<word-breaks/><font color='#aaaaaa'><center>%1</center></font><font size='1'><br>"
                               "&nbsp;</br></font>").arg(k.key().replace('/', ' '));
            }
            else
            {

                // there was issue with VerseKey::freshtext at simoultaneous call
                static CSwordVerseKey vk(list->_module);
                vk.setModule(list->_module);
                vk.setIndex(index.row() + list->_firstEntry);
                int v = vk.getVerse();

                if(v == 0)
                    return QString();

                QString r("<font color='#aaaaaa'>");

                if(v == 1)
                    r += QString("<center><b><font size='+1'>%1 %2</font></b></center>"
                    "<font size='1'><br>&nbsp;</br></font>").arg(vk.book()).arg(vk.getChapter());

                if(v > 0)
                    r += QString("<center>%1</center></font><font size='1'><br>&nbsp;</br>").arg(v);

                return r + "</font>";
            }
		}

	case Qt::DisplayRole:
        {
			switch(d->indexDepth(index))
			{
			case 1:
                {
                    const BtMiniModuleTextModelPrivate::List & l = d->_lists[index.internalId()];
                    return l._module == 0 ? "" : l._module->name();
                }
			case 2:
				{
					QString r;
                    const BtMiniModuleTextModelPrivate::List *l = d->indexList(index);

					if(l->_module && (l->_module->type() == CSwordModuleInfo::Bible ||
						l->_module->type() == CSwordModuleInfo::Commentary))
					{
						CSwordVerseKey key(d->indexToVerseKey(index));
						const int v = key.getVerse();

                        QList<const CSwordModuleInfo*> modules;
                        modules << l->_module;

                        // parallel display
                        if(l->_name.contains(','))
                            foreach(QString s, l->_name.split(',').mid(1))
                                if(CSwordModuleInfo *m = CSwordBackend::instance()->findModuleByName(s)) modules << m;

                        if(!d->_isSearch && v == 1)
                            r += "<center><b><font size='+2' face=\"" + btConfig().getDefaultFont().family() + "\">"
                                    + key.book() + " " + QString::number(key.getChapter()) + "</font></b></center>";

                        if(v != 0)
                            r += Rendering::CEntryDisplay().textKeyRendering(modules, key.key(),
                                l->_displayOptions, l->_filterOptions,
                                l->_simpleVerseNumber ? Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey :
                                                        Rendering::CTextRendering::KeyTreeItem::Settings::CompleteShort,
                                l->_introdutions);

                        if(!d->_isSearch && v == key.getVerseMax())
                            r += "<font size='1'><br>&nbsp;</font>";
					}
					else if(l->_module && l->_module->type() == CSwordModuleInfo::Lexicon)
					{
						CSwordLexiconModuleInfo *lm = qobject_cast<CSwordLexiconModuleInfo*>(l->_module);

						Rendering::CEntryDisplay ed;
                        r += ed.textKeyRendering(QList<const CSwordModuleInfo*>() << lm, lm->entries()[l->_hasScope ?
                            l->_scopeMap[index.row()] : index.row()],
                            l->_displayOptions, l->_filterOptions,
                            l->_simpleVerseNumber ? Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey :
                                                    Rendering::CTextRendering::KeyTreeItem::Settings::CompleteShort,
                            l->_introdutions);
					}
                    else if(l->_module && l->_module->type() == CSwordModuleInfo::GenericBook)
                    {
                        CSwordBookModuleInfo *b = reinterpret_cast<CSwordBookModuleInfo*>(l->_module);
                        CSwordTreeKey key(b->tree(), b);
                        key.setIndex(l->_hasScope ? l->_scopeMap[index.row()] : index.row() * 4);

						Rendering::CEntryDisplay ed;
                        r += ed.textKeyRendering(QList<const CSwordModuleInfo*>() << l->_module,
                            key.key(), l->_displayOptions, l->_filterOptions,
                            l->_simpleVerseNumber ? Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey :
                                                    Rendering::CTextRendering::KeyTreeItem::Settings::CompleteShort,
                            l->_introdutions);
                    }

                    if(d->_isSearch && !d->_searchText.isEmpty())
                        r = CSwordModuleSearch::highlightSearchedText(r, d->_searchText);

					if(l->_hasContents)
						r += l->_contents.toString();

					return r;
				}
			}
        }