Beispiel #1
0
Notebook::Notebook(QWidget *parent) :
    QWidget(parent)
{
    setupUi(this);
    titleLine->setReadOnly(true);
    contentText->setReadOnly(true);
    cancelButton->hide();
    submitButton->hide();
    nextButton->setEnabled(false);
    previousButton->setEnabled(false);
    editButton->setEnabled(false);
    removeButton->setEnabled(false);

    dialog = new FindDialog;

    connect(addButton, SIGNAL(clicked()), this, SLOT(addNote()));
    connect(submitButton, SIGNAL(clicked()), this, SLOT(submitNote()));
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
    connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
    connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
    connect(editButton, SIGNAL(clicked()), this, SLOT(editContent()));
    connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContent()));
    connect(findButton, SIGNAL(clicked()), this, SLOT(findTitle()));
    connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
    connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile()));
}
Beispiel #2
0
QString HtmlUtil::docToNavdoc(const QString &data, QString &header, QString &nav)
{
    QDomDocument doc;
    QStringList srcLines = data.split("\n");
    QStringList navLines;
    QStringList dstLines;
    navLines.append("<table class=\"unruled\"><tbody><tr><td class=\"first\"><dl>");
    int index = 0;
    if (srcLines.length() >= 1) {
        header = findTitle(data);
        if (header.isEmpty()) {
            //<!-- How to Write Go Code -->
            QString line = srcLines.at(0);
            QRegExp reg("<!--([\\w\\s]*)-->");
            if (reg.indexIn(line) >= 0) {
                header = reg.cap(1);
                header.trimmed();
            }
        }
    }
    foreach(QString source, srcLines) {
        QString line = source.trimmed();
        index++;
        if (line.length() >= 10) {
            if (line.left(3) == "<h2") {
                if (doc.setContent(line)) {
                    QDomElement e = doc.firstChildElement("h2");
                    if (!e.isNull()) {
                        QString text = e.text();
                        QString id = e.attribute("id");
                        if (id.isEmpty()) {
                            id = QString("tmp_%1").arg(index);
                            e.setAttribute("id",id);
                        }
                        //<span class="navtop"><a href="#top">[Top]</a></span>
                        QDomElement span = doc.createElement("span");
                        span.setAttribute("class","navtop");
                        QDomElement a = doc.createElement("a");
                        a.setAttribute("href","#top");
                        QDomText top = doc.createTextNode("[Top]");
                        a.appendChild(top);
                        span.appendChild(a);
                        e.appendChild(span);

                        source = doc.toString();
                        navLines << QString("<dt><a href=\"#%1\">%2</a></dt>").arg(id).arg(text);
                    }
                }
            }
            else if (line.left(3) == "<h3") {
                if (doc.setContent(line)) {
                    QDomElement e = doc.firstChildElement("h3");
                    if (!e.isNull()) {
                        QString text = e.text();
                        QString id = e.attribute("id");
                        if (id.isEmpty()) {
                            id = QString("tmp_%1").arg(index);
                            e.setAttribute("id",id);
                        }
                        source = doc.toString();
                        navLines << QString("<dd><a href=\"#%1\">%2</a></dd>").arg(id).arg(text);
                    }
                }
           }
        }
        dstLines.append(source);
    }