Esempio n. 1
0
void toSqlText::setFont (const QFont & font)
{
    // Only sets font lexer - one for all styles
    // this may (or may not) need to be changed in a future
    QsciLexer *lexer = super::lexer();
    if (lexer)
    {
        lexer->setDefaultFont(font);
        lexer->setFont(font);

        /* this is workaround against qscintilla 1.6 setFont(font) bug */
        if ( qobject_cast<QsciLexerSQL*>(lexer))
        {
            lexer->setFont(font, QsciLexerSQL::Default);
            lexer->setFont(font, QsciLexerSQL::Comment);
            lexer->setFont(font, QsciLexerSQL::CommentLine);
            lexer->setFont(font, QsciLexerSQL::PlusComment);
            lexer->setFont(font, QsciLexerSQL::CommentLineHash);
            lexer->setFont(font, QsciLexerSQL::CommentDocKeyword);
            lexer->setFont(font, QsciLexerSQL::CommentDocKeywordError);
            lexer->setFont(font, QsciLexerSQL::DoubleQuotedString);
            lexer->setFont(font, QsciLexerSQL::SingleQuotedString);
            lexer->setFont(font, QsciLexerSQL::PlusPrompt);
        }
        update();
    }
    super::setFont(font);
}
Esempio n. 2
0
void SciDoc::print() {
	QsciPrinter prn;
	QPrintDialog dlg(&prn, this);
	if (dlg.exec() == QDialog::Accepted) {
		prn.setWrapMode(EditorSettings::get(EditorSettings::WrapWords) || PrintSettings::get(PrintSettings::AlwaysWrap) ? QsciScintilla::WrapWord : QsciScintilla::WrapNone);

		int line1(-1), line2(-1), col1(-1), col2(-1);
		JuffScintilla* edit = int_->curEdit_;
		if ( edit ) {
			QsciLexer* lexer = edit->lexer();
			if ( !PrintSettings::get(PrintSettings::KeepBgColor) ) {
				lexer->setDefaultPaper(Qt::white);
				lexer->setPaper(Qt::white);
				lexer->setDefaultColor(Qt::black);
			}
			if ( !PrintSettings::get(PrintSettings::KeepColors) ) {
				lexer->setColor(Qt::black);
			}
			edit->getSelection(&line1, &col1, &line2, &col2);
			if (line1 >=0 && line2 >= 0 && col1 >= 0 && col2 >= 0) {
				//	We have selection. Print it.

				--line2;
				prn.printRange(edit, line1, line2);
			}
			else {
				//	We don't have selection. Print the whole text.
				prn.printRange(edit, 0);
			}
			QFont font = EditorSettings::font();
			LexerStorage::instance()->updateLexers(font);
		}
	}
}
			void EditorPage::handleMonoFontChanged ()
			{
				QsciLexer *lexer = Ui_.TextEditor_->lexer ();
				if (!lexer)
					return;

				QFont font = XmlSettingsManager::Instance ()->
						property ("MonoFont").value<QFont> ();
				lexer->setFont (font);
			}
Esempio n. 4
0
/**
 * Recursively updates lexer style properties, using the data stored in the
 * model.
 * @param  node The style node holding the lexer to update
 */
void LexerStyleModel::updateLexerStyle(const Node* node) const
{
	StyleData* data = static_cast<StyleData*>(node->data());
	QsciLexer* lexer = data->lexer_;
	int style = data->style_;

	// Update lexer properties.
	QFont font = propertyDataFromNode(node, Font)->value_.value<QFont>();
	lexer->setFont(font, style);
	QColor foreground
		= propertyDataFromNode(node, Foreground)->value_.value<QColor>();
	lexer->setColor(foreground, style);
	QColor background
		= propertyDataFromNode(node, Background)->value_.value<QColor>();
	lexer->setPaper(background, style);

	// This is really nasty, but Scintilla leaves us no choice...
	// The EOL Fill flag needs to be set in order for whitespace past the end
	// of line to be drawn in the desired background colour. We apply this flag
	// to the default style, as well as any styles that have the same background
	// colour as the default.
	if ((style == lexer->defaultStyle())
	    || (lexer->paper(style) == lexer->paper(lexer->defaultStyle()))) {
		lexer->setEolFill(true, style);
	}

	// Recursive call.
	for (int i = 0; i < node->childCount(); i++)
		updateLexerStyle(node->child(i));
}
Esempio n. 5
0
/**
 * Updates the editor widget to use a new set of configuration parameters.
 * @param  config  The configuration parameters
 */
void Editor::applyConfig(const Config& config)
{
	QsciLexer* lex = lexer();
	if (lex)
		lex->setFont(config.font_);
	else
		setFont(config.font_);

	setIndentationsUseTabs(config.indentTabs_);
	setTabWidth(config.tabWidth_);
	setCaretLineVisible(config.hlCurLine_);
}
Esempio n. 6
0
/**
 * Fills a Config structure with the current configuration options.
 * Used to get QScintilla's default values.
 * @param config
 */
void Editor::getConfig(Config& config)
{
	QsciLexer* lex = lexer();
	if (lex)
		config.font_ = lex->defaultFont();
	else
		config.font_ = font();

	config.indentTabs_ = indentationsUseTabs();
	config.tabWidth_ = tabWidth();
	config.hlCurLine_ = false;
}
Esempio n. 7
0
static QsciLexer* createLexerByExtension(QString ext)
{
	ext = ext.toLower();

	QsciLexer* lexer = 0;

    QSettings settings;
    QString themePath = settings.value("editorTheme").toString();

	if (ext == "lua")
	{
		QsciLexerLua* lexerlua = new QsciLexerLua;
		lexer = lexerlua;

		QsciAPIs* api = new QsciAPIs(lexer);
//		api->add(QString("addEventListener(type, listener, [data]) Registers a listener function and an optional data value"));
		api->load("Resources/gideros_annot.api");
		api->prepare();
		lexer->setAPIs(api);

        if (themePath != "")
        {
        QSettings editorTheme(themePath, QSettings::IniFormat);
        lexer->readSettings(editorTheme);
        }
        else
        {
            lexer->setColor(Qt::blue, QsciLexerLua::Keyword);
            lexer->setColor(QColor(0xff, 0x80, 0x00), QsciLexerLua::Number);
        }
    }
    else if (ext == "xml")
    {
        lexer = new QsciLexerXML;
    }
    else if ((ext == "hlsl") || (ext == "glsl") )
    {
        lexer = new QsciLexerCPP;

        if (themePath != "")
        {
        QSettings editorTheme(themePath, QSettings::IniFormat);
        lexer->readSettings(editorTheme);
        }
    }

    if (lexer && themePath == "")
	{ 
#ifdef Q_OS_MAC
		lexer->setFont(QFont("Monaco", 12));
#else
		lexer->setFont(QFont("Courier New", 10));
#endif
		lexer->setPaper(QColor(255, 255, 255));
	}

	return lexer;
}
Esempio n. 8
0
CodeWindow::CodeWindow( QSettings* appSettings, const ConnectorPath& conPath, QWidget* parent)
    : QDialog( parent),
    _ui( new Ui::CodeWindow)
{
    _ui->setupUi( this);

    this->setWindowTitle( QString("CodeEdit ") + conPath.normPath());

    _appSettings = appSettings;
    readSettings();

    _font = QFont("MonoSpace", 10);
    _font.setStyleHint( QFont::TypeWriter);
    MTextEdit*  textEdit = _ui->textEdit;

#ifdef QSCINTILLA
    QsciLexer*  lexer = 0;
    if (path.endsWith(".js"))
        lexer = new QsciLexerJavaScript;
    if (path.endsWith(".html") || path.endsWith(".xhtml"))
        lexer = new QsciLexerHTML;

    if (lexer) {
        lexer->setFont( _font);
        textEdit->editor()->setLexer( lexer);
    }
    else {
        textEdit->setFont( _font);
    }

    textEdit->editor()->setTabWidth(4);
    textEdit->editor()->setMarginWidth(0, 35);
    textEdit->editor()->setMarginLineNumbers(0, true);
    textEdit->editor()->setUtf8(true);
    textEdit->editor()->setAutoIndent(true);
    textEdit->editor()->setBraceMatching( QsciScintilla::StrictBraceMatch);
    textEdit->editor()->setMatchedBraceForegroundColor( Qt::red);
#else
    QFontMetrics fm( _font);
    int  tabWidthInPixels = fm.width("    ");
    textEdit->editor()->setTabStopWidth( tabWidthInPixels);
    textEdit->editor()->setCurrentFont( _font);
#endif

    QString  path = conPath.localPath();
    _isHtml = path.endsWith(".html") || path.endsWith(".xhtml");
    _isSetPlainText = true;  // Default
    _arnItem.open( path);
    setText( _arnItem.toString());
}
Esempio n. 9
0
/**
 * Provides the data to display/edit for a given index and role.
 * @param  index The index for which data is requested
 * @param  role  The requested role
 * @return The relevant data
 */
QVariant LexerStyleModel::data(const QModelIndex& index, int role) const
{
	const Node* node = nodeFromIndex(index);
	if (node == NULL || node->data() == NULL)
		return 0;

	if (node->data()->type() == StyleNode) {
		// Get the lexer and style ID for this node.
		StyleData* data = static_cast<StyleData*>(node->data());
		QsciLexer* lexer = data->lexer_;
		int style = data->style_;

		switch (index.column()) {
		case 0:
			// Show language name or style name in the first column.
			if (role == Qt::DisplayRole) {
				if (style == lexer->defaultStyle())
					return lexer->language();

				return lexer->description(style);
			}
			break;

		case 1:
			// Show a formatted text string in the second column, using the
			// style's properties.
			return styleData(node, role);
		}
	}
	else {
		// Get the lexer and style ID for this node.
		PropertyData* data = static_cast<PropertyData*>(node->data());

		switch (index.column()) {
		case 0:
			if (role == Qt::DisplayRole)
				return propertyName(data->prop_);
			break;

		case 1:
			return propertyData(data, role);
		}
	}

	return QVariant();
}
Esempio n. 10
0
DocumentEditor::DocumentEditor(DocumentEditor* document_, QWidget *parent_) : ScintillaExt(parent_), _watcher(document_->_watcher) {
	_notified = true;
	//codec
	setUtf8(true);
	_codec = document_->_codec;
	_bomMode = document_->_bomMode;
	_hasBom = document_->_hasBom;
	_charsetAutoDetect = document_->_charsetAutoDetect;

	//document info
	_autoDetectEol = document_->_autoDetectEol;
	_autoDetectIndent = document_->_autoDetectIndent;
	_isNew = document_->isNew();
	_fullPath = document_->getFullPath();

	setDocument(document_->document());

	_clone = document_;
	_isCloned = true;
	document_->_clone = this;
	document_->_isCloned = true;

	QsciLexer* l = document_->lexer();
	if(l != 0) {
		QString lexLang = l->language();
		QsciLexer* newLex = LexerManager::getInstance().lexerFactory(lexLang, this);
		if(newLex == 0) {
			//could not find the lexer
			newLex = LexerManager::getInstance().getAutoLexer(this);
		}
		setLexer(newLex);
	}

	//macro
	_macro = new QsciMacro(this);

	//load settings
	Settings settings;
	settings.applyToDocument(this);

	markerDefine(QPixmap(":/images/ledblue.png").scaled(40,16, Qt::KeepAspectRatio, Qt::SmoothTransformation), MARKER_BOOK);

	//connection
	connect(this, SIGNAL(marginClicked(int,int, Qt::KeyboardModifiers)), this, SLOT(toggleBookmark(int,int, Qt::KeyboardModifiers)));
}
Esempio n. 11
0
static QsciLexer* createLexerByExtension(QString ext)
{
	ext = ext.toLower();

	QsciLexer* lexer = 0;

	if (ext == "lua")
	{
		QsciLexerLua* lexerlua = new QsciLexerLua;
		lexer = lexerlua;

		QsciAPIs* api = new QsciAPIs(lexer);
//		api->add(QString("addEventListener(type, listener, [data]) Registers a listener function and an optional data value"));
		api->load("Resources/gideros_annot.api");
		api->prepare();
		lexer->setAPIs(api);

		lexerlua->setFoldCompact(false); // this function does not exists in QsciLexer

		lexerlua->setColor(Qt::blue, QsciLexerLua::Keyword);
		lexerlua->setColor(QColor(0xff, 0x80, 0x00), QsciLexerLua::Number);
		// to be filled
	}
	else if (ext == "xml")
	{
		lexer = new QsciLexerXML;
	}
	else if ((ext == "hlsl") || (ext == "glsl") )
	{
		lexer = new QsciLexerCPP;
	}

	if (lexer)
	{
#ifdef Q_OS_MAC
		lexer->setFont(QFont("Monaco", 12));
#else
		lexer->setFont(QFont("Courier New", 10));
#endif
		lexer->setPaper(QColor(255, 255, 255));
	}

	return lexer;
}
Esempio n. 12
0
void MainWindow::fontDialog() {
  if (tabWidget->count()) {
  	QsciLexer * lexer = getCurDoc()->lexer();
  	bool ok;

  	if (lexer) {
  	  QFont baseFont = QFontDialog::getFont(&ok, lexer->font(lexer->defaultStyle()));

  	  if (ok) {
  	    getCurDoc()->setFont(baseFont);
  	    setLexerFont(lexer, baseFont.family(), baseFont.pointSize());
  	  }
  	} else {
      QFont font = QFontDialog::getFont(&ok, getCurDoc()->font());

      if (ok) {
        getCurDoc()->setFont(font);
      }
  	}
  }
}
Esempio n. 13
0
/**
 * Reads style data from a QSettings object for the given node and all its
 * children.
 * @param  settings The QSettings object to read from
 * @param  node     The style node
 */
void LexerStyleModel::loadStyle(QSettings& settings, Node* node)
{
	// Get the lexer and style ID from the node data.
	StyleData* data = static_cast<StyleData*>(node->data());
	QsciLexer* lexer = data->lexer_;
	int style = data->style_;

	// Create a key template for the settings object, of the form
	// LEXER\STYLE\%1, where %1 will be replaced by the property name.
	QString key = QString("Style/%1/%2/%3").arg(lexer->lexer()).arg(style);

	// Get the properties.
	for (uint i = 0; i != _LastProperty; i++) {
		StyleProperty prop = static_cast<StyleProperty>(i);
		setProperty(settings.value(key.arg(propertyKey(prop))), node, prop,
		            propertyDefaultValue(lexer, style, prop));
	}

	// Recursive call.
	for (int i = 0; i < node->childCount(); i++)
		loadStyle(settings, node->child(i));
}
Esempio n. 14
0
void TextView::onLexerChanged(int index)
{
    QsciLexer *prevLexer = scintEditor->lexer();
    QsciLexer *newLexer = nullptr;
    switch (index) { // do nothing by default
        case 0:
            break;
        case 1:
            newLexer = new(std::nothrow) QsciLexerHTML();
            break;
        case 2:
            newLexer = new(std::nothrow) QsciLexerJavaScript();
            break;
        case 3:
            newLexer = new(std::nothrow) QsciLexerYAML();
            break;
        case 4:
            newLexer = new(std::nothrow) QsciLexerXML();
            break;
        case 5:
            newLexer = new(std::nothrow) QsciLexerProperties();
            break;
        default:
            logger->logError(tr("Unknown Lexer index: %1 T_T").arg(index));

    }
    if (newLexer != nullptr) {
        newLexer->setDefaultFont(GlobalsValues::GLOBAL_REGULAR_FONT);
        newLexer->setDefaultColor(QApplication::palette().text().color());
    }
    scintEditor->setLexer(newLexer);
    scintEditor->setBackgroundRole(QPalette::Base);
    delete prevLexer;

    if (newLexer == nullptr) {
        scintEditor->setFont(GlobalsValues::GLOBAL_REGULAR_FONT);
    }
}
Esempio n. 15
0
/**
 * Writes style data to a QSettings object for the given node and all its
 * children.
 * @param  settings The QSettings object to write to
 * @param  node     The style node
 */
void LexerStyleModel::storeStyle(QSettings& settings, const Node* node) const
{
	// Get the lexer and style ID from the node data.
	StyleData* data = static_cast<StyleData*>(node->data());
	QsciLexer* lexer = data->lexer_;
	int style = data->style_;

	// Create a key template for the settings object, of the form
	// LEXER\STYLE\%1, where %1 will be replaced by the property name.
	QString key = QString("Style/%1/%2/%3").arg(lexer->lexer()).arg(style);

	// Get the properties.
	for (uint i = 0; i != _LastProperty; i++) {
		StyleProperty prop = static_cast<StyleProperty>(i);
		PropertyData* propData = propertyDataFromNode(node, prop);
		QVariant value = propData->inherited_ ? inheritValue_
		                                      : propData->value_;
		settings.setValue(key.arg(propertyKey(prop)), value);
	}

	// Recursive call.
	for (int i = 0; i < node->childCount(); i++)
		storeStyle(settings, node->child(i));
}
Esempio n. 16
0
QString DocumentEditor::getType() const {
	QsciLexer* lex = lexer();
	if(lex)
		return lex->language();
	return "Normal Text";
}
Esempio n. 17
0
void DocumentEditor::toggleComment(bool lineCommentPrefered_) {
	QsciLexer* l = lexer();
	if(l == 0)
		return;
	QString comment = l->commentLine();
	QStringList commentBlock = l->commentBlock();

	if(comment.isEmpty() && commentBlock.isEmpty()){
		qDebug() << "Toggle comment is not supported for " << l->language();
		return;
	}

	if (!hasSelectedText()) {
		//if line is empty, skip it
		int line = getCurrentLine();
		if (isLineEmpty(line))
			return;

		QString selText = text(line);
		selText.remove("\n");
		selText.remove("\r");
		QString selTextTrimmed = selText.trimmed();
		int pos_start = SendScintilla(SCI_POSITIONFROMLINE, line);
		int pos_end = SendScintilla(SCI_GETLINEENDPOSITION, line);

		// check for block comments on a line
		if(commentBlock.size() >= 2){
			QString blockStart = commentBlock.first();
			QString blockEnd = commentBlock.last();
			if (selTextTrimmed.startsWith(blockStart) && selTextTrimmed.endsWith(blockEnd)) {
				beginUndoAction();

				int idx1 = selText.indexOf(blockStart);
				selText.remove(idx1, blockEnd.size());
				int idx2 = selText.lastIndexOf(blockEnd);
				selText.remove(idx2, blockEnd.size());

				SendScintilla(SCI_SETTARGETSTART, pos_start);
				SendScintilla(SCI_SETTARGETEND, pos_end);
				SendScintilla(SCI_REPLACETARGET, -1, selText.toUtf8().data());

				endUndoAction();
				return;
			}
		}

		// check for single comments
		if (!comment.isEmpty()) {
			if (selTextTrimmed.startsWith(comment)) {
				// remove comment
				int idx = selText.indexOf(comment);
				selText = selText.remove(idx, comment.size());
			} else {
				// set comment
				selText = selText.prepend(comment);
			}

			SendScintilla(SCI_SETTARGETSTART, pos_start);
			SendScintilla(SCI_SETTARGETEND, pos_end);
			SendScintilla(SCI_REPLACETARGET, -1, selText.toUtf8().data());
			return;
		}

	}else{
		// comment out the selection
		QString selText = selectedText();
		QString selTextTrimmed = selText.trimmed();
		if (selTextTrimmed.isEmpty())
			return;

		int lineFrom, lineTo, indexFrom, indexTo;
		getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo);

		int pos_start = positionFromLineIndex(lineFrom, indexFrom);
		int pos_end = positionFromLineIndex(lineTo, indexTo);

		// check if it is double commented block - to do before single check!
		if(commentBlock.size() >= 2){
			QString blockStart = commentBlock.first();
			QString blockEnd = commentBlock.last();
			// comment exists? remove?
			if (selTextTrimmed.startsWith(blockStart) && selTextTrimmed.endsWith(blockEnd)) {
				beginUndoAction();

				int idx1 = selText.indexOf(blockStart);
				selText.remove(idx1, blockStart.size());
				int idx2 = selText.lastIndexOf(blockEnd);
				selText.remove(idx2, blockEnd.size());

				SendScintilla(SCI_TARGETFROMSELECTION);
				SendScintilla(SCI_REPLACETARGET, -1, selText.toUtf8().data());
				SendScintilla(SCI_SETSEL, SendScintilla(SCI_GETTARGETSTART), SendScintilla(SCI_GETTARGETEND));

				endUndoAction();
				return;
			}
		}

		// check if this block can be single commented
		if (!comment.isEmpty() && lineCommentPrefered_) {
			bool empty_start = false, empty_end = false;

			if (indexFrom == 0)
				empty_start = true;
			else
				empty_start = getTextRange(positionFromLineIndex(lineFrom, 0), pos_start).trimmed().isEmpty();

			if (indexTo == 0)
				empty_end = true;
			else
				empty_end = getTextRange(pos_end, positionFromLineIndex(lineTo+1, 0)).trimmed().isEmpty();

			if (empty_start && empty_end) {
				beginUndoAction();

				// corrections
				if (indexTo == 0)
					lineTo--;
				if (isLineEmpty(lineFrom)) {
					lineFrom++; indexFrom = 0;
				}
				// a workaround: move cursor to the next line to replace EOL as well
				setSelection(lineFrom, 0, lineTo+1, 0);

				QStringList sl;
				for (int i = lineFrom; i <= lineTo; i++)
					sl += text(i);

				bool comm = false;
				for (int i = 0; i < sl.count(); i++)
					if (!sl.at(i).trimmed().startsWith(comment)) {
						comm = true;
						break;
					}

				for (int i = 0; i < sl.count(); i++) {
					if (comm)
						sl[i] = sl[i].prepend(comment);
					else {
						int idx = sl.at(i).indexOf(comment);
						sl[i] = sl[i].remove(idx, comment.size());
					}
				}

				SendScintilla(SCI_TARGETFROMSELECTION);
				SendScintilla(SCI_REPLACETARGET, -1, sl.join("").toUtf8().data());
				SendScintilla(SCI_SETSEL, SendScintilla(SCI_GETTARGETSTART), SendScintilla(SCI_GETTARGETEND));

				endUndoAction();
				return;
			}
		}

		// else, set double comment
		if(commentBlock.size() >= 2){
			QString blockStart = commentBlock.first();
			QString blockEnd = commentBlock.last();
			beginUndoAction();

			// last is first
			SendScintilla(SCI_INSERTTEXT, pos_end, blockEnd.toUtf8().data());
			SendScintilla(SCI_INSERTTEXT, pos_start, blockStart.toUtf8().data());

			// select everything
			if(lineFrom == lineTo)
				setSelection(lineFrom, indexFrom, lineTo, indexTo + blockStart.size() + blockEnd.size());
			else
				setSelection(lineFrom, indexFrom, lineTo, indexTo + blockEnd.size());

			endUndoAction();
			return;
		}
	}
}