예제 #1
0
        /**
         * @brief UML syntax highlighting.
         * @param text
         */
        void highlightBlockUml(const QString &text) {

            if(highlightRestOfLine(text, REGEX_MLC_ON, format_comment) == true) {
                multiLineComment=true;
            }

            if(highlightRestOfLine(text, REGEX_MLC_OFF, format_comment) == true) {
                multiLineComment=false;
            }

            if(multiLineComment == true) {
                setFormat(0, text.length(), format_comment);
                return;
            }

            //------------------------------------------------------------

            highlightWords(text, REGEX_KEYWORD, format_keyword);
            highlightWords(text, REGEX_KEYWORD2, format_keyword);

            highlightWords(text, REGEX_NOTE1,   format_keyword);
            highlightWord( text, REGEX_NOTE2,   format_keyword);

            highlightWords(text, REGEX_HTML_TAG, format_html);

            highlightWords(text, REGEX_MASK, format_mask );

            highlightWords(text, REGEX_COLOR, format_color );

            highlightWord(text, REGEX_SEPARATOR, format_separator);

            //    highlightWords(text, REGEX_ARROWS1, format_arrow);
            //    highlightWords(text, REGEX_ARROWS2, format_arrow);
            // 	highlightArrorws(text);

            //------------------------------------------------------------

            highlightWord(text, REGEX_SKIN,      format_skin);
            highlightWord(text, REGEX_OPTION,    format_option);

            highlightWord(text, REGEX_DECORATION, format_decoration);

            highlightRestOfLine(text, REGEX_COMMENT, format_comment);
        }
예제 #2
0
파일: SciDoc.cpp 프로젝트: MikeTekOn/juffed
	Interior(QWidget* w) {
//		LOGGER;

		curEdit_ = NULL;

		spl_ = new QSplitter(Qt::Vertical);
		QVBoxLayout* vBox = new QVBoxLayout();
		vBox->setContentsMargins(0, 0, 0, 0);
		vBox->addWidget(spl_);
		w->setLayout(vBox);

		edit1_ = createEdit();
		edit2_ = createEdit();
		spl_->addWidget(edit1_);
		spl_->addWidget(edit2_);
		edit1_->setDocument(edit2_->document());
		w->setFocusProxy(spl_);
		spl_->setSizes(QList<int>() << 0 << spl_->height());
		
		hlTimer_ = new QTimer( w );
		hlTimer_->setSingleShot( true );
		connect(hlTimer_, SIGNAL(timeout()), w, SLOT(highlightWord()));
	}
예제 #3
0
        void highlightBlock(const QString &text)
        {
            qDebug() << codeType << ':' << text;

            if(text.size() == 0 || text.contains(REGEX_EMPTY)) return;

            if(REGEX_START_1.indexIn(text) > -1) {
                // Start 1: @start<TYPE>

                QString type = REGEX_START_1.cap(1);

                if(type == "uml") {
                    codeType = UML;
                } else if(type == "salt") {
                    codeType = SALT;
                } else if(type == "dot") {
                    codeType = DOT;
                } else if(type == "ditaa") {
                    codeType = DITAA;
                } else if(type == "jcckit") {
                    codeType = JCCKIT;
                } else {
                    codeType = UNKNOWN;
                    return;
                }

                highlightWord(text, REGEX_START_1, format_start_end);

                endtag = "@end" + type;
                return;
            }

            switch(codeType) {
                case UML:

                    if(REGEX_START_2.indexIn(text) > -1) {
                        // Start 2: @startuml + <TYPE>

                        QString type = REGEX_START_2.cap(1);

                        if(type == "salt") {
                            codeType = SALT;
                        } else if(type == "digraph" || type == "graph") {
                            codeType = DOT;
                        } else if(type == "ditaa") {
                            codeType = DITAA;
                        } else if(type == "jcckit") {
                            codeType = JCCKIT;
                        }
                        return;
                    }

                    highlightBlockUml(text);
                    break;
                case SALT:
                    highlightBlockSalt(text);
                    break;
                case DITAA:
                    highlightBlockDitaa(text);
                    break;
                case JCCKIT:
                    highlightBlockJcckit(text);
                    break;
                case DOT:
                    highlightBlockDot(text);
                    break;
                case PLANTUML:
                    // highlightBlockPlantUml(text);
                    break;
                default:
                    return;
            }

            if(codeType != UNKNOWN && highlightWord( text, QRegExp(endtag), format_start_end)) {
                return;
            } else if(highlightWords( text, QRegExp("@start\\w*\\b"), format_error)) {
                return;
            }
        }
예제 #4
0
파일: SciDoc.cpp 프로젝트: MikeTekOn/juffed
QPixmap markerPixmap(const QColor& color, const QColor& bgColor) {
	// create unique string-name for color combinations
	QString cacheName(color.name()+bgColor.name());
	QPixmap px(16, 16);

	// The method signature was changed: it's
	// bool QPixmapCache::find ( const QString & key, QPixmap & pm ) in Qt <= 4.5
	// and
	// bool QPixmapCache::find ( const QString & key, QPixmap * pm ) in Qt >= 4.6
#if QT_VERSION >= 0x040600
	if ( QPixmapCache::find(cacheName, &px) ) {
#else
	if ( QPixmapCache::find(cacheName, px) ) {
#endif
		return px;
	}

	px.fill(bgColor);

	QPainter p(&px);
	// As we are using pixmap cache for most pixmap access
	// we can use more resource and time consuming rendering
	// to get better results (smooth rounded bullet in this case).
	// Remember: painting is performed only once per running juffed
	//           in the ideal case.
	p.setRenderHint(QPainter::Antialiasing);

	int red   = color.red();
	int green = color.green();
	int blue  = color.blue();

	QColor light(red + (255 - red) / 2, green + (255 - green) / 2, blue + (255 - blue) / 2);
	QColor dark(red / 2, green / 2, blue / 2);

	QRadialGradient gr(0.4, 0.4, 0.5, 0.4, 0.4);
	gr.setCoordinateMode(QGradient::ObjectBoundingMode);
	gr.setColorAt(0, light);
	gr.setColorAt(1, dark);
	p.setPen(dark);
	p.setBrush(gr);
	p.drawEllipse(1, 1, 14, 14);

	p.end();

	QPixmapCache::insert(cacheName, px);
	return px;
}

class SciDoc::Interior {
public:
	Interior(QWidget* w) {
//		LOGGER;

		curEdit_ = NULL;

		spl_ = new QSplitter(Qt::Vertical);
		QVBoxLayout* vBox = new QVBoxLayout();
		vBox->setContentsMargins(0, 0, 0, 0);
		vBox->addWidget(spl_);
		w->setLayout(vBox);

		edit1_ = createEdit();
		edit2_ = createEdit();
		spl_->addWidget(edit1_);
		spl_->addWidget(edit2_);
		edit1_->setDocument(edit2_->document());
		w->setFocusProxy(spl_);
		spl_->setSizes(QList<int>() << 0 << spl_->height());
		
		hlTimer_ = new QTimer( w );
		hlTimer_->setSingleShot( true );
		connect(hlTimer_, SIGNAL(timeout()), w, SLOT(highlightWord()));
	}

	JuffScintilla* createEdit() {
//		LOGGER;
		JuffScintilla* edit = new JuffScintilla();
		edit->setFocusPolicy(Qt::ClickFocus);
		edit->setUtf8(true);
		edit->setFolding(QsciScintilla::BoxedTreeFoldStyle);
		edit->setAutoIndent(true);
		edit->setBraceMatching(QsciScintilla::SloppyBraceMatch);

		// margins
		edit->setMarginLineNumbers(0, false);
		edit->setMarginLineNumbers(1, true);
		edit->setMarginSensitivity(0, true);
		edit->setMarginWidth(0, 20);
		edit->setMarginWidth(2, 12);

		// markers
		edit->markerDefine(QsciScintilla::Background, 2);
		//	Set the 0th margin accept markers numbered 1 and 2
		//	Binary mask for markers 1 and 2 is 00000110 ( == 6 )
		edit->setMarginMarkerMask(0, 6);
		edit->setMarginMarkerMask(1, 0);

		return edit;
	}

	void setCurrentEdit(JuffScintilla* edit) {
//		LOGGER;

		curEdit_ = edit;
		spl_->setFocusProxy(edit);
	}

	JuffScintilla* edit1_;
	JuffScintilla* edit2_;
	JuffScintilla* curEdit_;
	QString syntax_;
	QSplitter* spl_;
	QTimer* hlTimer_;
};

SciDoc::SciDoc(const QString& fileName) : Juff::Document(fileName) {
//	LOGGER;

	int_ = new Interior(this);

	JuffScintilla* edits[] = { int_->edit1_, int_->edit2_ };
	for ( int i = 0; i < 2; ++i) {
		JuffScintilla* edit = edits[i];
		connect(edit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(onCursorMoved(int, int)));
	//	connect(int_->edit1_, SIGNAL(contextMenuCalled(int, int)), this, SIGNAL(contextMenuCalled(int, int)));
		connect(edit, SIGNAL(marginClicked(int, int, Qt::KeyboardModifiers)), SLOT(onMarginClicked(int, int, Qt::KeyboardModifiers)));
		connect(edit, SIGNAL(focusReceived()), SLOT(onEditFocused()));
		connect(edit, SIGNAL(markersMenuRequested(const QPoint&)), SIGNAL(markersMenuRequested(const QPoint&)));
		connect(edit, SIGNAL(escapePressed()), SIGNAL(escapePressed()));
	}
	connect(int_->edit1_, SIGNAL(modificationChanged(bool)), this, SIGNAL(modified(bool)));
	connect(int_->edit1_, SIGNAL(linesChanged()), SLOT(onLineCountChanged()));
	connect(int_->edit1_, SIGNAL(textChanged()), this, SIGNAL(textChanged()));

	QString lexName = "none";
	SciDoc::Eol eol = guessEol(fileName);
	std::pair<bool,int> indentation = guessIndentation(fileName);
	if ( !fileName.isEmpty() && !isNoname() ) {
		QString codecName = Document::guessCharset(fileName);
		if ( !codecName.isEmpty() )
			setCharset(codecName);
		readFile();
		setEol(eol);
		setIndentationsUseTabs(indentation.first);
		setTabWidth(indentation.second);
		int_->edit1_->setModified(false);

		//	syntax highlighting
		lexName = LexerStorage::instance()->lexerName(fileName);
	}
	else {
		setEol(eol);
		setIndentationsUseTabs(indentation.first);
		setTabWidth(indentation.second);
	}
	
	
	
	
	setLexer(lexName);

	applySettings();

	QAction* hlWordAct = new QAction("", this);
	hlWordAct->setShortcut(QKeySequence("Ctrl+H"));
	connect(hlWordAct, SIGNAL(triggered()), SLOT(highlightWord()));
	addAction(hlWordAct);
}

/*SciDoc::SciDoc(Juff::Document* doc) : Juff::Document(doc) {
	SciDoc* d = qobject_cast<SciDoc*>(doc);
	if ( d != 0 ) {
		int_->edit1_->setDocument(d->int_->edit1_->document());
		int_->edit2_->setDocument(d->int_->edit2_->document());
	}
}*/

SciDoc::~SciDoc() {
	delete int_;
}

QString SciDoc::type() const {
	return "QSci";
}

bool SciDoc::supportsAction(Juff::ActionID id) const {
	switch (id) {
		case Juff::FileClone : return true;
		default :              return Juff::Document::supportsAction(id);
	}
}

/*Juff::Document* SciDoc::createClone() {
	if ( hasClone() )
		return NULL;
	else
		return new SciDoc(this);
}

void SciDoc::updateClone() {
	LOGGER;

//	SciDoc* cln = qobject_cast<SciDoc*>(clone());
//	if ( cln != 0 ) {
//		if ( cln->int_->syntax_ != int_->syntax_ ) {
//			cln->int_->syntax_ = int_->syntax_;
//			QsciLexer* lexer = LexerStorage::instance()->lexer(int_->syntax_);
//			cln->int_->edit1_->setLexer(lexer);
//			cln->int_->edit2_->setLexer(lexer);
//		}
//	}

	Juff::Document::updateClone();
}*/

void SciDoc::init() {
	int_->setCurrentEdit(int_->edit2_);
}
void MyCPPSyntaxHighlighter::highlightBlock(const QString &text){
    //Comments
    enum { NormalState = -1, InsideCStyleComment, InsideQuote };
    int state = previousBlockState();
    int start = 0;
    int startQuote = 0;
    QColor commentColor = Qt::darkGreen;//QColor (100,170,100,255);
    QColor commandColor = Qt::darkBlue;
    QColor dataTypeColor = Qt::darkMagenta;
    QColor includeColor = Qt::darkRed;
    for (int i = 0; i < text.length(); ++i) {

        if (state == InsideCStyleComment) {
            if (text.mid(i, 2) == "*/") {
                state = NormalState;
                setFormat(start, i - start + 2, commentColor);
            }
        } else {

            if (text.at(i)=='"' && state == InsideQuote){
                setFormat(startQuote, i - startQuote + 1, commentColor);
                state = NormalState;
            }
            if (text.mid(i, 2) == "//") {
                setFormat(i, text.length() - i, commentColor);
                break;
            } else if (text.mid(i, 2) == "/*") {
                start = i;
                state = InsideCStyleComment;
            }
            if (text.at(i)=='"' && state == NormalState){
                startQuote = i;
                state = InsideQuote;
            }

            highlightWord(i,text,"if",commandColor);
            highlightWord(i,text,"for",commandColor);
            highlightWord(i,text,"while",commandColor);
            highlightWord(i,text,"do",commandColor);
            highlightWord(i,text,"until",commandColor);
            highlightWord(i,text,"double",dataTypeColor);
            highlightWord(i,text,"float",dataTypeColor);
            highlightWord(i,text,"int",dataTypeColor);
            highlightWord(i,text,"long",dataTypeColor);
            highlightWord(i,text,"unsigned",dataTypeColor);
            highlightWord(i,text,"void",dataTypeColor);
            highlightWord(i,text,"char",dataTypeColor);
//            highlightWord(i,text,"#include",includeColor);
//            highlightWord(i,text,"#ifdef",includeColor);
//            highlightWord(i,text,"#ifndef",includeColor);
//            highlightWord(i,text,"#define",includeColor);
//            highlightWord(i,text,"#endif",includeColor);
//            highlightWord(i,text,"#else",includeColor);
//            highlightWord(i,text,"#error",includeColor);
//            highlightWord(i,text,"#if",includeColor);
            if (text.at(i)=='#'){
                int end = text.indexOf(QRegExp("[\\W\\n\\r]"),i+1);
                setFormat(i, end - i, includeColor);
            }


        }
    }
    if (state == InsideCStyleComment)
        setFormat(start, text.length() - start, commentColor);

    setCurrentBlockState(state);
}