summaryrefslogtreecommitdiff
path: root/src/frontend/crossrefrendering.cpp
blob: 9785ee7615cec9d9a4ff8fb7878edbe5cc4e831b (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
//
// C++ Implementation: crossrefrendering
//
// Description:
//
//
// Author: The BibleTime team <info@bibletime.info>, (C) 2004, 2007
//
// Copyright: See COPYING file that comes with this distribution


#include "crossrefrendering.h"

#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/keys/cswordversekey.h"
#include "backend/managers/creferencemanager.h"

namespace InfoDisplay {

/**
 */
CrossRefRendering::CrossRefRendering( CSwordBackend::DisplayOptions displayOptions,
                                      CSwordBackend::FilterOptions filterOptions
                                    )
        : CHTMLExportRendering(Settings(), displayOptions, filterOptions) {}

const QString CrossRefRendering::finishText( const QString& text, KeyTree& ) {
    //   qDebug("CrossRefRendering::finishText");
    return text;
}

const QString CrossRefRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo*  module ) {
    QString linkText;

    const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
    CSwordVerseKey vk(module); //only valid for bible modules, i.e. isBible == true
    if (isBible) {
        vk.key(item.key());
    }

    switch (item.settings().keyRenderingFace) {
        case KeyTreeItem::Settings::NoKey: {
            linkText = QString::null;
            break; //no key is valid for all modules
        }
        case KeyTreeItem::Settings::CompleteShort: {
            if (isBible) {
                linkText = QString::fromUtf8(vk.getShortText());
                break;
            }
            //fall through for non-Bible modules
        }
        case KeyTreeItem::Settings::CompleteLong: {
            if (isBible) {
                linkText = vk.key();
                break;
            }
            //fall through for non-Bible modules
        }
        case KeyTreeItem::Settings::SimpleKey: {
            if (isBible) {
                linkText = QString::number(vk.Verse());
                break;
            }
            //fall through for non-Bible modules
        }
        default: { //default behaviour to return the passed key
            linkText = item.key();
            break;
        }
    }

    if (!linkText.isEmpty()) { //if we have a valid link text
        //     qWarning("rendering");
        return QString("<a href=\"%1\">%2</a>")
               .arg(
                   CReferenceManager::encodeHyperlink(
                       module->name(),
                       item.key(),
                       CReferenceManager::typeFromModule(module->type())
                   )
               )
               .arg(linkText);
    }

    return QString::null;
}

}