예제 #1
0
void LuaEditor::initLexer()
{
    lexer = new QsciLexerLua;
    lexer->setFoldCompact(false);
    lexer->setColor(QColor(128, 128, 255), 5);
    lexer->setColor(QColor(0, 220, 0), 1);
    lexer->setColor(QColor(0, 220, 0), 2);
    lexer->setColor(QColor(Qt::red), 6);
    lexer->setColor(QColor(Qt::red), 8);
    lexer->setColor(QColor(255, 128, 0), 13);
    lexer->setColor(QColor(51, 102, 255), 15);
    lexer->setColor(QColor(72, 61, 139), 10);
    lexer->setFont(QFont("Courier New", 11, QFont::Bold));

    QSettings settings(ORGNAME, APPNAME);
    settings.beginGroup("QtLuaPad");
    bool autoComp = settings.value("autocompletion").toBool();
    QString funcFile = settings.value("funcfile").toString().toLatin1();
    settings.endGroup();

    if(autoComp)
    {
        setAutoCompletionSource(QsciScintilla::AcsAll);
        setAutoCompletionCaseSensitivity(false);
        setAutoCompletionFillupsEnabled(true);
        setAutoCompletionThreshold(2);
        setAutoCompletionShowSingle(true);

        QsciAPIs *apis = new QsciAPIs(lexer);
        xmlDocPtr doc = xmlParseFile(funcFile.toLatin1());
        if(!doc)
        {
            QMessageBox::critical(NULL, "Unable to load keywords!",
                                  tr("Could not load keywords file. No such file or directory."),
                                  QMessageBox::Ok, QMessageBox::NoButton);
            return;
        }

        xmlNodePtr root = xmlDocGetRootElement(doc);
        if (xmlStrcmp(root->name, (const xmlChar*)"functions"))
        {
            QMessageBox::critical(NULL, "Error", tr("Malformed functions file."));
            return;
        }
        for (xmlNodePtr p = root->children; p; p = p->next)
        {
            if(p->type != XML_ELEMENT_NODE)
                continue;

            if(xmlStrcmp(p->name, (const xmlChar*)"function"))
                continue;

            QString func = QString((const char*)p->children->content);
            apis->add(func);
        }
        apis->prepare();
        lexer->setAPIs(apis);
    }
}
/**
 * Initializes the autocompletion.
 * @param additionalElements
 *      Additional elements for the autocompletion api.
 */
void SingleDocument::initAutoCompletion(QStringList additionalElements)
{

    if(lexer() && lexer()->apis())
    {
        QsciAPIs* apis = static_cast<QsciAPIs*>(lexer()->apis());
        apis->clear();
        QMap<QString, QStringList>::iterator i;
        for (i = g_apiFiles.begin(); i != g_apiFiles.end(); ++i)
        {
            for(auto el : i.value())
            {
                apis->add(el);
            }
        }

        for(auto el : additionalElements)
        {
            apis->add(el);
        }
        apis->prepare();
    }

}
예제 #3
0
QsciLexerQSS::QsciLexerQSS(QObject *parent)
    : QsciLexerCSS(parent)
{
    QsciAPIs *api = new QsciAPIs(this);

    const QString stringKeywords = QString(keywords(1)) + keywords(2);

    QStringList listKeywords = stringKeywords.split(QRegExp("\\s+"), QString::SkipEmptyParts);

    // Qt classes
    listKeywords
                << "QAbstractScrollArea"
                << "QCheckBox"
                << "QColumnView"
                << "QComboBox"
                << "QDateEdit"
                << "QDateTimeEdit"
                << "QDialog"
                << "QDialogButtonBox"
                << "QDockWidget"
                << "QDoubleSpinBox"
                << "QFrame"
                << "QGroupBox"
                << "QHeaderView"
                << "QLabel"
                << "QLineEdit"
                << "QListView"
                << "QListWidget"
                << "QMainWindow"
                << "QMenu"
                << "QMenuBar"
                << "QMessageBox"
                << "QProgressBar"
                << "QPushButton"
                << "QRadioButton"
                << "QScrollBar"
                << "QSizeGrip"
                << "QSlider"
                << "QSpinBox"
                << "QSplitter"
                << "QStatusBar"
                << "QTabBar"
                << "QTabWidget"
                << "QTableView"
                << "QTableWidget"
                << "QTextEdit"
                << "QTimeEdit"
                << "QToolBar"
                << "QToolButton"
                << "QToolBox"
                << "QToolTip"
                << "QTreeView"
                << "QTreeWidget"
                << "QWidget"

                // alignment
                << "top"
                << "bottom"
                << "left"
                << "right"
                << "center"

                // attachment
                << "scroll"
                << "fixed"

                // border image
                << "none"
                << "stretch"
                << "repeat"

                // border style
                << "dashed"
                << "dot-dash"
                << "dot-dot-dash"
                << "dotted"
                << "double"
                << "inset"
                << "outset"
                << "ridge"
                << "solid"
                << "none"

                // font
                << "normal"
                << "italic"
                << "oblique"
                << "bold"

                // gradients
                << "qlineargradient"
                << "qradialgradient"
                << "qconicalgradient"

                // origin
                << "margin"
                << "border"
                << "padding"
                << "content"

                // palette role
                << "alternate-base"
                << "base"
                << "bright-text"
                << "button"
                << "button-text"
                << "dark"
                << "highlight"
                << "highlighted-text"
                << "light"
                << "link"
                << "link-visited"
                << "mid"
                << "midlight"
                << "shadow"
                << "text"
                << "window"
                << "window-text"

                // repeat
                << "repeat"
                << "repeat-x"
                << "repeat-y"
                << "no-repeat"
                    ;

    listKeywords.removeDuplicates();

    foreach(const QString &word, listKeywords)
    {
        api->add(word);
    }