BIC in =?iso-8859-1?q?kdeui=2Fkeditcl2=2Ecpp

Laurent Montel lmontel at mandrakesoft.com
Mon May 19 15:29:42 BST 2003


?=
Date: Mon, 19 May 2003 16:29:03 +0200
User-Agent: KMail/1.5.9
Cc: qt-bugs at trolltech.com,
 kde-devel at kde.org
References: <200305191455.54001.l.lunak at suse.cz> <200305191538.16786.montel at kde.org>
In-Reply-To: <200305191538.16786.montel at kde.org>
X-KMail-Link-Message: 5929475
X-KMail-Link-Type: reply
MIME-Version: 1.0
Content-Disposition: inline
X-KMail-Identity: 82950674
Content-Type: Multipart/Mixed;
  boundary="Boundary-00=_voOy+19vQMvJesH"
Message-Id: <200305191629.03739.lmontel at mandrakesoft.com>
Status: RO
X-Status: Q
X-KMail-EncryptionState:  
X-KMail-SignatureState:  
X-KMail-MDN-Sent:  


--Boundary-00=_voOy+19vQMvJesH
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

Le Monday 19 May 2003 15:38, Laurent Montel a écrit :
> Le Monday 19 May 2003 14:55, Lubos Lunak a écrit :
> >  Hello,
> >
> >  would it be please possible to rewrite this
> > http://webcvs.kde.org/cgi-bin/cvsweb.cgi/kdelibs/kdeui/keditcl2.cpp.diff?
> >r1 =1.52&r2=1.53&f=h in a way that doesn't involve using private classes,
> > thus avoiding breaking when the private classes change? Good luck that I
> > didn't forget my crystal ball today, so that I spent only about half an
> > hour finding out why KWin crashes on QTextParagraph::str being NULL when
> > there was absolutely no way how it could be so (my crystal ball says it
> > was so because I compiled with -O0, which cause out-of-line copies of
> > some inline functions from
> > qrichtext_p.h, and those took precedence over the correct ones from Qt).
> >
> >  If API of the public classes doesn't provide everything necessary to
> > implement the method in KEdit, send them a patch, so that it gets in Qt
> > in time for Qt3.2final. My crystal ball says that it can possibly break
> > even with -O2. I don't care that much if e.g. Stano wants to have fun
> > using QRichText internals in KBabel, but we definitely must avoid such
> > things in libraries.
>
> Ok I created a patch for qt-3.2-beta1.
> "Qt people" could you add this patch to qtextedit please.
> This patch allows to recover string under cursor.
> It will use in kedit programm.
>
> We can use it for spell checking.
>
> Thanks a lot.
> Regards.

Oops I forgot attachment :(

--Boundary-00=_voOy+19vQMvJesH
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="qtextedit-patch.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="qtextedit-patch.diff"

? 3rdparty/opentype/Makefile
cvs server: Diffing .
cvs server: Diffing .obj
cvs server: Diffing .tmp
cvs server: Diffing 3rdparty
cvs server: Diffing 3rdparty/libjpeg
cvs server: Diffing 3rdparty/libmng
cvs server: Diffing 3rdparty/libmng/doc
cvs server: Diffing 3rdparty/libmng/doc/man
cvs server: Diffing 3rdparty/libmng/doc/rpm
cvs server: Diffing 3rdparty/libmng/makefiles
cvs server: Diffing 3rdparty/libpng
cvs server: Diffing 3rdparty/libpng/projects
cvs server: Diffing 3rdparty/libpng/projects/beos
cvs server: Diffing 3rdparty/libpng/projects/borland
cvs server: Diffing 3rdparty/libpng/projects/msvc
cvs server: Diffing 3rdparty/libpng/scripts
cvs server: Diffing 3rdparty/opentype
cvs server: Diffing 3rdparty/zlib
cvs server: Diffing 3rdparty/zlib/amiga
cvs server: Diffing 3rdparty/zlib/msdos
cvs server: Diffing 3rdparty/zlib/nt
cvs server: Diffing 3rdparty/zlib/os2
cvs server: Diffing attic
cvs server: Diffing canvas
cvs server: Diffing codecs
cvs server: Diffing compat
cvs server: Diffing dialogs
cvs server: Diffing embedded
cvs server: Diffing iconview
cvs server: Diffing kernel
cvs server: Diffing moc
cvs server: Diffing network
cvs server: Diffing opengl
cvs server: Diffing sql
cvs server: Diffing sql/drivers
cvs server: Diffing sql/drivers/mysql
cvs server: Diffing sql/drivers/odbc
cvs server: Diffing sql/drivers/psql
cvs server: Diffing styles
cvs server: Diffing table
cvs server: Diffing tmp
cvs server: Diffing tools
cvs server: Diffing widgets
Index: widgets/qtextedit.cpp
===================================================================
RCS file: /home/kde/qt-copy/src/widgets/qtextedit.cpp,v
retrieving revision 1.35
diff -u -u -p -r1.35 qtextedit.cpp
--- widgets/qtextedit.cpp	16 May 2003 13:03:11 -0000	1.35
+++ widgets/qtextedit.cpp	19 May 2003 13:32:35 -0000
@@ -1,5 +1,5 @@
 /****************************************************************************
-** 
+**
 **
 ** Implementation of the QTextEdit class
 **
@@ -6862,6 +6862,44 @@ void QTextEdit::setAutoFormatting( uint 
 uint QTextEdit::autoFormatting() const
 {
     return d->autoFormatting;
+}
+
+QString QTextEdit::selectWordUnderCursor( ) const
+{
+    QTextCursor c1 = *textCursor();
+    QTextCursor c2 = *textCursor();
+    QTextCursor cursor = *textCursor();
+
+    if ( cursor.index() > 0 && !cursor.paragraph()->at( cursor.index()-1 )->c.isSpace() )
+        c1.gotoWordLeft();
+    if ( !cursor.paragraph()->at( cursor.index() )->c.isSpace() && !cursor.atParagEnd() )
+        c2.gotoWordRight();
+
+    // The above is almost correct, but gotoWordRight also skips the spaces/punctuations
+    // until the next word. So the 'word under cursor' contained e.g. that trailing space.
+    // To be on the safe side, we skip spaces/punctuations on both sides:
+    QTextString *s = cursor.paragraph()->string();
+    bool beginFound=false;
+    for ( int i = c1.index(); i< c2.index(); i++)
+    {
+        QChar ch = s->at(i).c;
+        if( !beginFound && !ch.isSpace() && !ch.isPunct() )
+        {
+            c1.setIndex(i);
+            beginFound=true;
+        }
+        else if ( beginFound && (ch.isSpace() || ch.isPunct()) )
+        {
+            c2.setIndex(i);
+            break;
+        }
+    }
+
+    document()->setSelectionStart( (int)QTextDocument::Standard, c1 );
+    document()->setSelectionEnd( (int)QTextDocument::Standard, c2 );
+    QString text = selectedText(  );
+    //textDocument()->removeSelection( KoTextDocument::Temp );
+    return text;
 }
 
 #endif //QT_NO_TEXTEDIT
Index: widgets/qtextedit.h
===================================================================
RCS file: /home/kde/qt-copy/src/widgets/qtextedit.h,v
retrieving revision 1.24
diff -u -u -p -r1.24 qtextedit.h
--- widgets/qtextedit.h	16 May 2003 13:03:12 -0000	1.24
+++ widgets/qtextedit.h	19 May 2003 13:32:35 -0000
@@ -1,5 +1,5 @@
 /****************************************************************************
-** 
+**
 **
 ** Definition of the QTextEdit class
 **
@@ -301,6 +301,7 @@ public:
 
     void setAutoFormatting( uint features );
     uint autoFormatting() const;
+    QString selectWordUnderCursor() const;
 
 public slots:
     void setEnabled( bool );
@@ -395,7 +396,7 @@ public slots:
     void setMaxLogLines( int numLines );
     int maxLogLines();
 #endif
-    
+
 signals:
     void textChanged();
     void selectionChanged();
cvs server: Diffing workspace
cvs server: Diffing xml

--Boundary-00=_voOy+19vQMvJesH--




More information about the kde-core-devel mailing list