Esempio n. 1
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. 2
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. 3
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);
      }
  	}
  }
}