[Kbabel] highlighting - first draft

Marco Wegner dubbleu@web.de
Sun, 24 Nov 2002 02:45:02 +0100


--Boundary-00=_e8C49Rmn7W7xGb1
Content-Type: Text/Plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Description: clearsigned data
Content-Disposition: inline

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

I invite you to test the latest implementation of my highlighting class.

For this please copy kbhighlighting.{cpp,h} from the archive to
kdesdk/kbabel/kbabel and apply the patch in the same directory (current
HEAD).

I have completely overhauled my previous design and made the class much
compacter than it was before. It is not yet complete but meanwhile I feel it 
is worth sharing :-)
Right now the class has the same features (should have at least) as the
implementation which is already in KBabel but is using a completely different
approach.

TODO:
- -- we have to clean out mymultilineedit.{cpp,h} now since there is a lot of
highlighting-related code which is not needed anymore (lend me a hand here,
Stanislav?). Basically everything that's still needed is a
   KBabelHighlighter * hl = new KBabelHighlighter( this );
in the constructor and a few calls to setHighlightColor().
- -- I would like to put the regular expressions into an extra file (perhaps in
XML format) so that they are not hard-coded but can be changed if the need
arises
- -- the setting of initial highlighting colors needs a little more work. We
could either read them directly from the config file or let MsgMultiLineEdit
do the reading and use KBabelHighlighting::setHighlightColor() for setting
the colors. What do you think?

IDEAS:
* I'm playing with the thought of using bold font for the tag names and tag
brackets (<, >) as well as for the entity names (similar to how it is
highlighted in kate, for instance). Opinions?

Happy testing,
Marco

- --
Marco Wegner <mail@marcowegner.de>, <dubbleu@web.de>
Contributing to KBabel http://i18n.kde.org/tools/kbabel
   and kde-i18n-de http://i18n.kde.org/teams/de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE94C8mX3rotM03gSgRAqsCAJ9ou0QpN52dBHP5Q1Ef0ftSbXKeBQCgvbQx
ZAXaTV4TF7guD+UvJHScgL0=
=8GAv
-----END PGP SIGNATURE-----

--Boundary-00=_e8C49Rmn7W7xGb1
Content-Type: text/x-diff;
  charset="us-ascii";
  name="kbhighlighting.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="kbhighlighting.diff"

Index: mymultilineedit.cpp
===================================================================
RCS file: /home/kde/kdesdk/kbabel/kbabel/mymultilineedit.cpp,v
retrieving revision 1.84
diff -u -3 -p -b -u -r1.84 mymultilineedit.cpp
--- mymultilineedit.cpp	2002/10/23 15:35:56	1.84
+++ mymultilineedit.cpp	2002/11/24 00:57:08
@@ -43,6 +43,8 @@
 #include <kmessagebox.h>
 #include <kstdaccel.h>
 
+#include "kbhighlighting.h"
+
 MyMultiLineEdit::MyMultiLineEdit(QWidget* parent,const char* name)
                 :QTextEdit(parent,name), emitUndo(true), _firstChangedLine(0), 
 		_lastChangedLine(0), _lastParagraph(0), 
@@ -556,6 +558,9 @@ MsgMultiLineEdit::MsgMultiLineEdit(QWidg
 {
    diffPos.setAutoDelete(true);
    diffPos.clear();
+   
+   highlighter = new KBabelHighlighter( this );
+   
    connect( this, SIGNAL( selectionChanged() ), this, SLOT( paintSpacePoints() ) );   
    connect( this, SIGNAL( cursorPositionChanged( int, int ) ), this, SLOT( paintSpacePoints(int, int) ) );
 }
@@ -770,6 +775,11 @@ void MsgMultiLineEdit::setHighlightColor
    _accelColor=accelColor;
    _tagColor=tagColor;
 
+   highlighter->setHighlightColor( KBabelHighlighter::Tag, tagColor );
+   highlighter->setHighlightColor( KBabelHighlighter::Entity, accelColor );
+   highlighter->setHighlightColor( KBabelHighlighter::CFormat, cformatColor );
+   highlighter->setHighlightColor( KBabelHighlighter::Masked, quoteColor );
+   
    update();
 }
 
@@ -809,11 +819,13 @@ void MsgMultiLineEdit::setTextColor(cons
   else p.setInactive( newcg );
   setPalette( p );
   _textColor = color;
+  highlighter->setHighlightColor( KBabelHighlighter::Normal, color );
 }
 
 void MsgMultiLineEdit::setErrorColor(const QColor &color )
 {
   _errorColor = color;
+  highlighter->setHighlightColor( KBabelHighlighter::Error, color );
 }
 
 void MsgMultiLineEdit::setCurrentColor(const TextColor color)
@@ -1003,7 +1015,7 @@ void MsgMultiLineEdit::ensureCursorVisib
 
 void MsgMultiLineEdit::highlight()
 {
-    if( _dontUpdate ) return;
+/*    if( _dontUpdate ) return;
     
     QColor bg;
     if( _highlightBg ) bg = _bgColor;
@@ -1148,6 +1160,7 @@ void MsgMultiLineEdit::highlight()
 	updateContents();
     }
     ensureCursorVisible();
+    */
 }
 
 void MsgMultiLineEdit::drawContents( QPainter *painter, int clipx, int clipy, int clipw, int cliph )
Index: mymultilineedit.h
===================================================================
RCS file: /home/kde/kdesdk/kbabel/kbabel/mymultilineedit.h,v
retrieving revision 1.41
diff -u -3 -p -b -u -r1.41 mymultilineedit.h
--- mymultilineedit.h	2002/10/06 09:02:18	1.41
+++ mymultilineedit.h	2002/11/24 00:57:09
@@ -30,6 +30,7 @@
 #include <qptrvector.h>
 
 class EditCommand;
+class KBabelHighlighter;
 
 class MyMultiLineEdit : public QTextEdit
 {
@@ -245,6 +246,8 @@ private:
    
    // for Alt+123 feature
    int _currentUnicodeNumber;
+   
+   KBabelHighlighter * highlighter;
 };
 
 #endif // MYMULTILINEEDIT_H
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdesdk/kbabel/kbabel/Makefile.am,v
retrieving revision 1.39
diff -u -3 -p -b -u -r1.39 Makefile.am
--- Makefile.am	2002/05/28 12:59:37	1.39
+++ Makefile.am	2002/11/24 00:57:09
@@ -20,7 +20,8 @@ libkbabel_la_SOURCES =	kbabel.cpp kbabel
 			headereditor.cpp prefwidgets.cpp\
 			mymultilineedit.cpp gotodialog.cpp\
 			cmdedit.cpp  kbabelsplash.cpp\
-			finddialog.cpp spelldlg.cpp roughtransdlg.cpp settings.cpp
+			finddialog.cpp spelldlg.cpp roughtransdlg.cpp \
+			settings.cpp kbhighlighting.cpp
 
 
 libkbabel_la_LIBADD =  ../common/libkbabelcommon.la ../kbabeldict/libkbabeldict.la $(LIB_KIO) $(LIB_KSPELL)
@@ -38,7 +39,7 @@ noinst_HEADERS   = kbabel.h kbabelview.h
                    headereditor.h prefwidgets.h mymultilineedit.h\
                    gotodialog.h cmdedit.h \
                    finddialog.h kbcatalog.h spelldlg.h roughtransdlg.h\
-                   kbabelsplash.h settings.h
+                   kbabelsplash.h settings.h kbhighlighting.h
 
 # let automoc handle all of the meta source files (moc)
 METASOURCES = AUTO

--Boundary-00=_e8C49Rmn7W7xGb1
Content-Type: application/x-tgz;
  name="kbhighlighting.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="kbhighlighting.tar.gz"

H4sIABYT4D0AA+1YbXMiNxL2Z35FF1u3GcyLwd7FFcAkLIVtEr+Da29jOJeYETDnYYbTDLZJsv89
j6RhGF7szaX2NnVV01XYSN3qbqmflrp5GIzt0djBJ7DdUcGcTne+OhVLxWL53budIuiwrP+XwjGo
fHiwv1M8fH8op4vvDyD/rlQ63KHi13dlk2Z+wATRjjUbDBw+e0WOC/9bOPRtaW+Xdr8ipYi6Y9un
oe1wwv8pEwF5Q/r5AxtwJwV205vOhYQbGc0M7ReL+zSY0zkTpkcf+cjlgmoTZjs/TuTUk5opWLye
WqieCm8k2ERqHwrOyfeGwRMTvEpzb0Ymc0lwy/YDYQ9mAZwIiLnWnido4ln2cA41mJq5FgwFY04B
FxNfuigHJxe3dMJhkTl0NRs4tklntsldnxODZTnjj7kFj6FGLjiWHnRCD+jYg14W2J5bJW6DL+gR
qMGY9hcmQn058gR0GCyQbgvypnJZBr7OyWHBcmVh28aX+7PIdpXesTfFZsbQh+092Y5DA04A7XDm
5KABsvSx3T29vO1S4+ITfWzc3DQuup+qkA3GHrj8kWtN9mTq2FCMLQnmBnN4DgXnrZvmKVY0PrTP
2t1PcJ+O292LVqdDx5c31KCrxk233bw9a9zQ1e3N1WWnVSDqcOkUx/pXjnaogoPzs3iAyPtqy58Q
TB+OORaN2SNHUE1uP8ItRiYg9OWIQQdzPHekNgjZ5QlWyR6S6wU5ehI2IBJ4m7HE6mU0c9R2zUKO
yofvgVTfp8YjAthkk4GwrRG+njeouF86+D5Ht50G3P+a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