SqlEditorWidget::SqlEditorWidget(QWidget * parent) : QsciScintilla(parent), m_searchText(""), m_searchIndicator(9) // see QsciScintilla docs { m_prefs = Preferences::instance(); setMarginLineNumbers(0, true); setBraceMatching(SloppyBraceMatch); setAutoIndent(true); QsciLexerSQL * lexer = new QsciLexerSQL(this); QsciAPIs * api = new QsciAPIs(lexer); if (!api->load(":/api/sqlite.api")) qDebug("api is not loaded"); else { api->prepare(); lexer->setAPIs(api); } setAutoCompletionSource(QsciScintilla::AcsAll); setAutoCompletionCaseSensitivity(false); setAutoCompletionReplaceWord(true); setCaretLineVisible(m_prefs->activeHighlighting()); setCaretLineBackgroundColor(m_prefs->activeHighlightColor()); setUtf8(true); setFolding(QsciScintilla::BoxedFoldStyle); lexer->setFoldComments(true); lexer->setFoldCompact(false); setLexer(lexer); // search all occurrences // allow indicator painting *under* the text (but it makes editor slower a bit...) // It paints a colored box under the text for all occurrences of m_searchText. SendScintilla(QsciScintilla::SCI_SETTWOPHASEDRAW, 1); SendScintilla(QsciScintilla::SCI_INDICSETSTYLE, m_searchIndicator, QsciScintilla::INDIC_ROUNDBOX); // TODO/FIXME: make it configurable SendScintilla(QsciScintilla::SCI_INDICSETFORE, m_searchIndicator, QColor(255, 230, 90, 100)); SendScintilla(QsciScintilla::SCI_INDICSETUNDER, m_searchIndicator, 1); // end of search all occurrences connect(this, SIGNAL(linesChanged()), this, SLOT(linesChanged())); connect(this, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(cursorPositionChanged(int, int))); setCursorPosition(0, 0); linesChanged(); prefsChanged(); }
QsciLexer * toSyntaxAnalyzerNL::createLexer(QObject *parent) { QsciLexerSQL *retval = new QsciLexerSQL(parent); retval->setFoldComments(true); retval->setFoldCompact(false); toStylesMap sMap = toConfigurationNewSingle::Instance().option(ToConfiguration::Editor::EditStyleMap).value<toStylesMap>(); sMap.updateLexer(retval); return retval; }
void QgsCodeEditorSQL::setSciLexerSQL() { QFont font = getMonospaceFont(); QsciLexerSQL* sqlLexer = new QsciLexerSQL( this ); sqlLexer->setDefaultFont( font ); sqlLexer->setFont( font, -1 ); font.setBold( true ); sqlLexer->setFont( font, QsciLexerSQL::Keyword ); sqlLexer->setColor( Qt::darkYellow, QsciLexerSQL::DoubleQuotedString ); // fields setLexer( sqlLexer ); }
void QgsCodeEditorSQL::setSciLexerSQL() { QFont font = getMonospaceFont(); #ifdef Q_OS_MAC // The font size gotten from getMonospaceFont() is too small on Mac font.setPointSize( QLabel().font().pointSize() ); #endif QsciLexerSQL* sqlLexer = new QgsCaseInsensitiveLexerSQL( this ); sqlLexer->setDefaultFont( font ); sqlLexer->setFont( font, -1 ); font.setBold( true ); sqlLexer->setFont( font, QsciLexerSQL::Keyword ); sqlLexer->setColor( Qt::darkYellow, QsciLexerSQL::DoubleQuotedString ); // fields setLexer( sqlLexer ); }
Preferences::Preferences(QObject *parent) : QObject(parent) { QFont f(QApplication::font()); // f.setPointSize(sqlFontSize()); QSettings s("yarpen.cz", "sqliteman"); m_checkQtVersion = s.value("checkQtVersion", true).toBool(); // FIXME should we have special label for empty blob m_nullHighlight = s.value("prefs/nullCheckBox", true).toBool(); m_blobHighlight = s.value("prefs/blobCheckBox", true).toBool(); m_nullHighlightText = s.value("prefs/nullAliasEdit", "{null}").toString(); m_blobHighlightText = s.value("prefs/blobAliasEdit", "{blob}").toString(); m_nullHighlightColor = s.value("prefs/nullBgButton", stdLightColor()).value<QColor>(); m_blobHighlightColor = s.value("prefs/blobBgButton", stdLightColor()).value<QColor>(); m_recentlyUsedCount = s.value("prefs/recentlyUsedSpinBox", 5).toInt(); m_openLastDB = s.value("prefs/openLastDB", true).toBool(); m_openLastSqlFile = s.value("prefs/openLastSqlFile", true).toBool(); m_readRows = s.value("prefs/readRowsComboBox", 0).toInt(); m_lastDB = s.value("lastDatabase", QString()).toString(); m_newInItemView = s.value("prefs/openNewInItemView", false).toBool(); m_GUItranslator = s.value("prefs/languageComboBox", 0).toInt(); m_GUIstyle = s.value("prefs/styleComboBox", 0).toInt(); m_GUIfont = s.value("prefs/applicationFont", f).value<QFont>(); m_cropColumns = s.value("prefs/cropColumnsCheckBox", false).toBool(); m_sqlFont = s.value("prefs/sqleditor/font", f).value<QFont>(); m_sqlFontSize = s.value("prefs/sqleditor/fontSize", f.pointSize()).toInt(); m_activeHighlighting = s.value("prefs/sqleditor/useActiveHighlightCheckBox", true).toBool(); m_activeHighlightColor = s.value("prefs/sqleditor/activeHighlightButton", stdDarkColor()).value<QColor>(); m_textWidthMark = s.value("prefs/sqleditor/useTextWidthMarkCheckBox", true).toBool(); m_textWidthMarkSize = s.value("prefs/sqleditor/textWidthMarkSpinBox", 60).toInt(); m_codeCompletion = s.value("prefs/sqleditor/useCodeCompletion", false).toBool(); m_codeCompletionLength = s.value("prefs/sqleditor/completionLengthBox", 3).toInt(); m_useShortcuts = s.value("prefs/sqleditor/useShortcuts", false).toBool(); m_shortcuts = s.value("prefs/sqleditor/shortcuts", QMap<QString,QVariant>()).toMap(); // qscintilla QsciLexerSQL syntaxLexer; m_syDefaultColor = s.value("prefs/qscintilla/syDefaultColor", syntaxLexer.defaultColor(QsciLexerSQL::Default)).value<QColor>(); m_syKeywordColor = s.value("prefs/qscintilla/syKeywordColor", syntaxLexer.defaultColor(QsciLexerSQL::Keyword)).value<QColor>(); m_syNumberColor = s.value("prefs/qscintilla/syNumberColor", syntaxLexer.defaultColor(QsciLexerSQL::Number)).value<QColor>(); m_syStringColor = s.value("prefs/qscintilla/syStringColor", syntaxLexer.defaultColor(QsciLexerSQL::SingleQuotedString)).value<QColor>(); m_syCommentColor = s.value("prefs/qscintilla/syCommentColor", syntaxLexer.defaultColor(QsciLexerSQL::Comment)).value<QColor>(); // data m_dateTimeFormat = s.value("data/dateTimeFormat", "MM/dd/yyyy").toString(); // data export m_exportFormat = s.value("dataExport/format", 0).toInt(); m_exportDestination = s.value("dataExport/destination", 0).toInt(); m_exportHeaders = s.value("dataExport/headers", true).toBool(); m_exportEncoding = s.value("dataExport/encoding", "UTF-8").toString(); m_exportEol = s.value("dataExport/eol", 0).toInt(); // extensions m_allowExtensionLoading = s.value("extensions/allowLoading", true).toBool(); m_extensionList = s.value("extensions/list", QStringList()).toStringList(); }
QVariant ToConfiguration::Editor::defaultValue(int option) const { switch (option) { case SyntaxHighlightingInt: return QVariant((int) 0); case EditorTypeInt: return QVariant((int) 0); case UseMaxTextWidthMarkBool: return QVariant((bool) false); case MaxTextWidthMarkInt: return QVariant((int)75); case KeywordUpperBool: return QVariant((bool) false); case ObjectNamesUpperBool: return QVariant((bool) false); case CodeCompleteBool: return QVariant((bool) true); case CompleteSortBool: return QVariant((bool) true); case UseEditorShortcutsBool: return QVariant((bool) false); case EditorShortcutsMap: return QVariant(QMap<QString, QVariant>()); case AutoIndentBool: return QVariant((bool) true); case UseSpacesForIndentBool: return QVariant((bool) false); case TabStopInt: return QVariant((int) 8); case ConfTextFont: return QVariant(QString("")); case ConfCodeFont: { QFont fo; QFont mono; #if defined(Q_OS_WIN) mono = QFont("Courier New", 10); #elif defined(Q_OS_MAC) mono = QFont("Courier", 12); #else // TODO #endif mono.setStyleHint(QFont::Monospace, QFont::NoAntialias); fo = mono.resolve(fo); QString fontName = fo.toString(); return QVariant(fontName); } case ListTextFont: return QVariant(QString("")); case Extensions: return QVariant(QString("SQL (*.sql *.pkg *.pkb), Text (*.txt), All (*)")); case EditStyleMap: { static toStylesMap retval; if (!retval.isEmpty()) return QVariant::fromValue(retval); QMetaEnum StyleNameEnum(ENUM_REF(toSyntaxAnalyzer,WordClassEnum)); QsciLexerSQL *l = new QsciLexerSQL(NULL); for (int idx = 0; idx < StyleNameEnum.keyCount(); idx++) { QColor fg = l->color((int)StyleNameEnum.value(idx)); QColor bg = l->paper((int)StyleNameEnum.value(idx)); QFont fo = Utils::toStringToFont(defaultValue(ConfCodeFont).toString()); QString styleName = StyleNameEnum.key(idx); int styleNameEnum = StyleNameEnum.value(idx); retval.insert(styleNameEnum, toStyle(fg, bg, fo)); } delete l; return QVariant::fromValue(retval); } default: Q_ASSERT_X( false, qPrintable(__QHERE__), qPrintable(QString("Context Editor un-registered enum value: %1").arg(option))); return QVariant(); } }