[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Need help with Kformula internals
From:       Mark Kirby <mark () coris ! org ! uk>
Date:       2005-04-01 12:40:56
Message-ID: 200504011339.51111.mark () coris ! org ! uk
[Download RAW message or body]

I'm trying to solve BUG:58953 this is the one were you can't input a single 
'|' you allways get '| |' (line brackets).

I've attached a patch of what i have so far.

Basically i have modified sequenceelement.cc to keep a record of how many '|' 
key presses there have been. If theres been one, draw a single '|' if there 
were two consecutive presses insert line brackets.

Now the problem i have is that if you want line brackets you will get '|| |' 
in the output (because a '|' is drawn on the 1st key press).

What i want to do is remove the 1st '|' when we get the second key press and 
then draw the brackets.

I can't seem to do this. I know how to move the cursor but i cant work out how 
to actually delete or remove the text element.

Any suggestions?

I have a suspicion i'm going about this either the wrong way or in the wrong 
place.

Thanks in advance

Mark

["sequenceelement.patch" (text/x-diff)]

Index: sequenceelement.cc
===================================================================
RCS file: /home/kde/koffice/lib/kformula/sequenceelement.cc,v
retrieving revision 1.95
diff -u -3 -p -u -r1.95 sequenceelement.cc
--- sequenceelement.cc	14 Jan 2005 08:10:05 -0000	1.95
+++ sequenceelement.cc	1 Apr 2005 12:16:33 -0000
@@ -56,7 +56,7 @@
 
 KFORMULA_NAMESPACE_BEGIN
 //using namespace std;
-
+int singlePipe = 1; //The key '|' produces one '|' not '| |', '||' produces '| |'
 ElementCreationStrategy* SequenceElement::creationStrategy = 0;
 
 void SequenceElement::setCreationStrategy( ElementCreationStrategy* strategy )
@@ -1233,45 +1233,61 @@ KCommand* SequenceElement::input( Contai
     case '(': {
         BracketRequest r( container->document()->leftBracketChar(),
                           container->document()->rightBracketChar() );
+        singlePipe = 1;
         return buildCommand( container, &r );
     }
     case '[': {
         BracketRequest r( LeftSquareBracket, RightSquareBracket );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
     case '{': {
         BracketRequest r( LeftCurlyBracket, RightCurlyBracket );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
-    case '|': {
-        BracketRequest r( LeftLineBracket, RightLineBracket );
-        return buildCommand( container, &r );
+    case '|': {	
+        if (singlePipe == 0) { // We have had 2 '|' in a row so we want brackets
+	    BracketRequest r( LeftLineBracket , RightLineBracket);
+	    singlePipe = 1;
+            return buildCommand( container, &r );    
+        }
+        else if (singlePipe == 1) { // We really do only want 1 '|'
+            TextCharRequest r( ch );
+	    singlePipe = 0;
+            return buildCommand( container, &r );   
+        }
     }
     case '^': {
         IndexRequest r( upperRightPos );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
     case '_': {
         IndexRequest r( lowerRightPos );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
     case ' ': {
         Request r( req_compactExpression );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
     case '}': {
         Request r( req_addEmptyBox );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
-    case ']':
-    case ')':
-        break;
+    case ']':{singlePipe = 1;}
+    case ')':{singlePipe = 1; break;}
     case '\\': {
         Request r( req_addNameSequence );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
     default: {
         TextCharRequest r( ch );
+	singlePipe = 1;
         return buildCommand( container, &r );
     }
     }
@@ -1654,7 +1670,7 @@ BasicElement* NameSequence::replaceEleme
         return frac;
     }
     if ( name == "sqrt" ) return new RootElement();
-
+    
     return 0;
 }
 


_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic