예제 #1
0
void ArthurFrame::showSource()
{
    // Check for existing source
    if (findChild<QTextBrowser *>())
        return;

    QString contents;
    if (m_sourceFileName.isEmpty()) {
        contents = QString("No source for widget: '%1'").arg(objectName());
    } else {
        QFile f(m_sourceFileName);
        if (!f.open(QFile::ReadOnly))
            contents = QString("Could not open file: '%1'").arg(m_sourceFileName);
        else
            contents = f.readAll();
    }

    contents.replace('&', "&amp;");
    contents.replace('<', "&lt;");
    contents.replace('>', "&gt;");

    QStringList keywords;
    keywords << "for " << "if " << "switch " << " int " << "#include " << "const"
             << "void " << "uint " << "case " << "double " << "#define " << "static"
             << "new" << "this";

    foreach (QString keyword, keywords)
        contents.replace(keyword, QLatin1String("<font color=olive>") + keyword + QLatin1String("</font>"));
    contents.replace("(int ", "(<font color=olive><b>int </b></font>");

    QStringList ppKeywords;
    ppKeywords << "#ifdef" << "#ifndef" << "#if" << "#endif" << "#else";

    foreach (QString keyword, ppKeywords)
        contents.replace(keyword, QLatin1String("<font color=navy>") + keyword + QLatin1String("</font>"));

    contents.replace(QRegExp("(\\d\\d?)"), QLatin1String("<font color=navy>\\1</font>"));

    QRegExp commentRe("(//.+)\\n");
    commentRe.setMinimal(true);
    contents.replace(commentRe, QLatin1String("<font color=red>\\1</font>\n"));

    QRegExp stringLiteralRe("(\".+\")");
    stringLiteralRe.setMinimal(true);
    contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>"));

    QString html = contents;
    html.prepend("<html><pre>");
    html.append("</pre></html>");

    QTextBrowser *sourceViewer = new QTextBrowser(0);
    sourceViewer->setWindowTitle("Source: " + m_sourceFileName.mid(5));
    sourceViewer->setParent(this, Qt::Dialog);
    sourceViewer->setAttribute(Qt::WA_DeleteOnClose);
    sourceViewer->setLineWrapMode(QTextEdit::NoWrap);
    sourceViewer->setHtml(html);
    sourceViewer->resize(600, 600);
    sourceViewer->show();
}
예제 #2
0
/*!
    Constructs a new about box on top of given \a parent window.
*/
AboutBox::AboutBox(QWidget * parent) : QDialog(parent)
{
    setWindowTitle("About MaxCalc");

    tstring labelText = _T("MaxCalc v");
    labelText += Constants::VERSION;
    labelText += _T(" (");
    labelText += _T("built: ");
    tstring date = stringToWideString(__DATE__);
    labelText += date;
    labelText += _T(")<br>");
    labelText += Constants::COPYRIGHT;
    labelText += _T("<br><a href='");
    labelText += Constants::WEBSITE;
    labelText += _T("'>");
    labelText += Constants::WEBSITE;
    labelText += _T("</a>");

    QTextBrowser * label = new QTextBrowser;
    label->setHtml(QString::fromWCharArray(labelText.c_str()));
    label->setOpenExternalLinks(true);
    label->setFrameStyle(QFrame::NoFrame);
    QPalette p;
    p.setColor(QPalette::Base, p.color(QPalette::Background));
    label->setPalette(p);
    label->setLineWrapMode(QTextEdit::NoWrap);
    label->document()->adjustSize();
    label->setMinimumSize(label->document()->size().toSize());
    label->setMaximumSize(label->document()->size().toSize());

    QPushButton * closeButton = new QPushButton;
    closeButton->setText(tr("&Close"));

    QGridLayout * layout = new QGridLayout;
    layout->addWidget(label, 1, 0, 1, -1);
    layout->addItem(new QSpacerItem(20, 10, QSizePolicy::Minimum,
        QSizePolicy::Fixed), 2, 1, 1, 1);
    layout->addItem(new QSpacerItem(20, 20,
        QSizePolicy::Expanding), 3, 0, 1, 1);
    layout->addWidget(closeButton, 3, 1, 1, 1);
    layout->addItem(new QSpacerItem(20, 20,
        QSizePolicy::Expanding), 3, 2, 1, 1);    

    setLayout(layout);

    setMaximumSize(sizeHint());
    setMinimumSize(sizeHint());

    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
}