2010-01-02 19:26 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
* contrib/hbqt/hbqt_hbqsyntaxhighlighter.cpp
* contrib/hbqt/hbqt_hbqsyntaxhighlighter.h
* contrib/hbqt/qtgui/TQSyntaxHighlighter.prg
* contrib/hbqt/qth/QSyntaxHighlighter.qth
+ Added more functions to manage highlighting properly.
This commit is contained in:
@@ -17,6 +17,13 @@
|
||||
past entries belonging to author(s): Viktor Szakats.
|
||||
*/
|
||||
|
||||
2010-01-02 19:26 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
|
||||
* contrib/hbqt/hbqt_hbqsyntaxhighlighter.cpp
|
||||
* contrib/hbqt/hbqt_hbqsyntaxhighlighter.h
|
||||
* contrib/hbqt/qtgui/TQSyntaxHighlighter.prg
|
||||
* contrib/hbqt/qth/QSyntaxHighlighter.qth
|
||||
+ Added more functions to manage highlighting properly.
|
||||
|
||||
2010-01-03 02:32 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* contrib/hbqt/tests/demoqt.prg
|
||||
+ Changed to use new EVENTS/SLOTS layout.
|
||||
|
||||
@@ -67,27 +67,27 @@ HBQSyntaxHighlighter::HBQSyntaxHighlighter( QTextDocument *parent )
|
||||
: QSyntaxHighlighter( parent )
|
||||
{
|
||||
HighlightingRule rule;
|
||||
|
||||
#if 0
|
||||
keywordFormat.setForeground( Qt::darkBlue );
|
||||
keywordFormat.setFontWeight( QFont::Bold );
|
||||
QStringList keywordPatterns;
|
||||
keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
|
||||
<< "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b"
|
||||
<< "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b"
|
||||
<< "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b"
|
||||
<< "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b"
|
||||
<< "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b"
|
||||
<< "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
|
||||
<< "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
|
||||
<< "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
|
||||
<< "\\bvoid\\b" << "\\bvolatile\\b";
|
||||
keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
|
||||
<< "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b"
|
||||
<< "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b"
|
||||
<< "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b"
|
||||
<< "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b"
|
||||
<< "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b"
|
||||
<< "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
|
||||
<< "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
|
||||
<< "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
|
||||
<< "\\bvoid\\b" << "\\bvolatile\\b";
|
||||
foreach ( const QString &pattern, keywordPatterns )
|
||||
{
|
||||
rule.pattern = QRegExp( pattern );
|
||||
rule.format = keywordFormat;
|
||||
highlightingRules.append( rule );
|
||||
}
|
||||
|
||||
#endif
|
||||
classFormat.setFontWeight( QFont::Bold );
|
||||
classFormat.setForeground( Qt::darkMagenta );
|
||||
rule.pattern = QRegExp( "\\bQ[A-Za-z]+\\b" );
|
||||
@@ -100,6 +100,29 @@ HBQSyntaxHighlighter::HBQSyntaxHighlighter( QTextDocument *parent )
|
||||
commentEndExpression = QRegExp("\\*/");
|
||||
}
|
||||
|
||||
void HBQSyntaxHighlighter::setHBRule( QString name, QString pattern, const QTextCharFormat & format )
|
||||
{
|
||||
if( pattern != "" )
|
||||
hhighlightingRules.insert( name, hHighlightingRule( QRegExp( pattern ), format ) );
|
||||
else
|
||||
hhighlightingRules.remove( name );
|
||||
}
|
||||
|
||||
void HBQSyntaxHighlighter::setHBFormat( QString name, const QTextCharFormat & format )
|
||||
{
|
||||
if( hhighlightingRules.contains( name ) )
|
||||
{
|
||||
hHighlightingRule rule = hhighlightingRules.value( name );
|
||||
QRegExp reg = rule.pattern;
|
||||
|
||||
hhighlightingRules.insert( name, hHighlightingRule( reg, format ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
hhighlightingRules.remove( name );
|
||||
}
|
||||
}
|
||||
|
||||
void HBQSyntaxHighlighter::setHBCompilerDirectives( const QStringList & directives, const QTextCharFormat & format )
|
||||
{
|
||||
HighlightingRule rule;
|
||||
@@ -123,6 +146,7 @@ void HBQSyntaxHighlighter::highlightBlock( const QString &text )
|
||||
int index( 0 );
|
||||
QRegExp expression;
|
||||
|
||||
#if 0
|
||||
foreach ( const HighlightingRule &rule, highlightingRules )
|
||||
{
|
||||
expression = QRegExp( rule.pattern );
|
||||
@@ -134,6 +158,19 @@ void HBQSyntaxHighlighter::highlightBlock( const QString &text )
|
||||
index = expression.indexIn( text, index + length );
|
||||
}
|
||||
}
|
||||
#else
|
||||
foreach ( const hHighlightingRule &rule, hhighlightingRules )
|
||||
{
|
||||
QRegExp expression( rule.pattern );
|
||||
int index = expression.indexIn( text );
|
||||
while ( index >= 0 )
|
||||
{
|
||||
int length = expression.matchedLength();
|
||||
setFormat( index, length, rule.format );
|
||||
index = expression.indexIn( text, index + length );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
setCurrentBlockState( 0 );
|
||||
|
||||
@@ -259,11 +296,27 @@ HB_FUNC( QT_HBQSYNTAXHIGHLIGHTER_SETHBCOMPILERDIRECTIVES )
|
||||
}
|
||||
|
||||
/*
|
||||
* void setHBCompilerDirectives( const QStringList & directives, const QTextCharFormat & format )
|
||||
* void setHBMultiLineCommentFormat( const QTextCharFormat & format )
|
||||
*/
|
||||
HB_FUNC( QT_HBQSYNTAXHIGHLIGHTER_SETHBMULTILINECOMMENTFORMAT )
|
||||
{
|
||||
hbqt_par_HBQSyntaxHighlighter( 1 )->setHBMultiLineCommentFormat( *hbqt_par_QTextCharFormat( 2 ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* void setRule( QString name, QString pattern, QTextCharFormat format );
|
||||
*/
|
||||
HB_FUNC( QT_HBQSYNTAXHIGHLIGHTER_SETHBRULE )
|
||||
{
|
||||
hbqt_par_HBQSyntaxHighlighter( 1 )->setHBRule( hbqt_par_QString( 2 ), hbqt_par_QString( 3 ), *hbqt_par_QTextCharFormat( 4 ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* void setFormat( QString name, const QTextCharFormat & format );
|
||||
*/
|
||||
HB_FUNC( QT_HBQSYNTAXHIGHLIGHTER_SETHBFORMAT )
|
||||
{
|
||||
hbqt_par_HBQSyntaxHighlighter( 1 )->setHBFormat( hbqt_par_QString( 2 ), *hbqt_par_QTextCharFormat( 3 ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -68,10 +68,28 @@ public:
|
||||
|
||||
void setHBCompilerDirectives( const QStringList & directives, const QTextCharFormat & format );
|
||||
void setHBMultiLineCommentFormat( const QTextCharFormat & format );
|
||||
void setHBRule( QString name, QString pattern, const QTextCharFormat & format );
|
||||
void setHBFormat( QString name, const QTextCharFormat & format );
|
||||
|
||||
protected:
|
||||
void highlightBlock( const QString &text );
|
||||
|
||||
|
||||
struct hHighlightingRule
|
||||
{
|
||||
hHighlightingRule()
|
||||
{
|
||||
}
|
||||
hHighlightingRule( QRegExp _pattern, const QTextCharFormat & _format )
|
||||
{
|
||||
pattern = _pattern;
|
||||
format = _format;
|
||||
}
|
||||
QRegExp pattern;
|
||||
QTextCharFormat format;
|
||||
};
|
||||
QMap< QString, hHighlightingRule > hhighlightingRules;
|
||||
|
||||
private:
|
||||
struct HighlightingRule
|
||||
{
|
||||
@@ -80,6 +98,8 @@ private:
|
||||
};
|
||||
QVector<HighlightingRule> highlightingRules;
|
||||
|
||||
protected:
|
||||
|
||||
QRegExp commentStartExpression;
|
||||
QRegExp commentEndExpression;
|
||||
|
||||
|
||||
@@ -117,6 +117,8 @@ CREATE CLASS HBQSyntaxHighlighter INHERIT QSyntaxHighlighter
|
||||
METHOD configure( xObject )
|
||||
METHOD setHBCompilerDirectives( pDirectives, pFormat, pFont )
|
||||
METHOD setHBMultiLineCommentFormat( pFormat )
|
||||
METHOD setHBRule( cName, cPattern, pFormat )
|
||||
METHOD setHBFormat( cName, pFormat )
|
||||
|
||||
ENDCLASS
|
||||
|
||||
@@ -143,6 +145,14 @@ METHOD HBQSyntaxHighlighter:setHBCompilerDirectives( pDirectives, pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBCompilerDirectives( ::pPtr, hbqt_ptr( pDirectives ), hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
METHOD HBQSyntaxHighlighter:setHBRule( cName, cPattern, pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBRule( ::pPtr, cName, cPattern, hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
METHOD HBQSyntaxHighlighter:setHBFormat( cName, pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBFormat( ::pPtr, cName, hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
METHOD HBQSyntaxHighlighter:setHBMultiLineCommentFormat( pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBMultiLineCommentFormat( ::pPtr, hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ CREATE CLASS HBQSyntaxHighlighter INHERIT QSyntaxHighlighter
|
||||
METHOD configure( xObject )
|
||||
METHOD setHBCompilerDirectives( pDirectives, pFormat, pFont )
|
||||
METHOD setHBMultiLineCommentFormat( pFormat )
|
||||
METHOD setHBRule( cName, cPattern, pFormat )
|
||||
METHOD setHBFormat( cName, pFormat )
|
||||
|
||||
ENDCLASS
|
||||
|
||||
@@ -95,6 +97,14 @@ METHOD HBQSyntaxHighlighter:setHBCompilerDirectives( pDirectives, pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBCompilerDirectives( ::pPtr, hbqt_ptr( pDirectives ), hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
METHOD HBQSyntaxHighlighter:setHBRule( cName, cPattern, pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBRule( ::pPtr, cName, cPattern, hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
METHOD HBQSyntaxHighlighter:setHBFormat( cName, pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBFormat( ::pPtr, cName, hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
METHOD HBQSyntaxHighlighter:setHBMultiLineCommentFormat( pFormat )
|
||||
RETURN Qt_HBQSyntaxHighlighter_setHBMultiLineCommentFormat( ::pPtr, hbqt_ptr( pFormat ) )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user