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

List:       kde-commits
Subject:    playground/libs/krichtext
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2008-05-06 0:11:02
Message-ID: 1210032662.656753.15134.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 804433 by skelly:

Change selectLinkText to accept a cursor as a parameter. Also add a convenience \
function to use the current active cursor if none is specified.

Also in this change, functionality to handle different rich text settings per app.




 M  +23 -18    krichtextedit.cpp  
 M  +9 -0      krichtextedit.h  
 M  +19 -0     krichtexteditor.cpp  
 M  +1 -0      krichtexteditor.h  
 M  +17 -2     krichtextwidget.cpp  


--- trunk/playground/libs/krichtext/krichtextedit.cpp #804432:804433
@@ -308,46 +308,51 @@
 
 QString KRichTextEdit::currentLinkText() const
 {
-    selectLinkText();
     QTextCursor cursor = textCursor();
+    selectLinkText(&cursor);
     return cursor.selectedText();
 }
 
 void KRichTextEdit::selectLinkText() const
 {
     QTextCursor cursor = textCursor();
+    selectLinkText(&cursor);
+    d->setTextCursor(cursor);
+}
+
+void KRichTextEdit::selectLinkText(QTextCursor *cursor) const
+{
+//     QTextCursor cursor = textCursor();
      // If the cursor is on a link, select the text of the link.
-    if (cursor.charFormat().isAnchor()) {
-        QString aHref = cursor.charFormat().anchorHref();
+    if (cursor->charFormat().isAnchor()) {
+        QString aHref = cursor->charFormat().anchorHref();
 
         // Move cursor to start of link
-        while (cursor.charFormat().anchorHref() == aHref) {
-            if (cursor.atStart())
+        while (cursor->charFormat().anchorHref() == aHref) {
+            if (cursor->atStart())
                 break;
-            cursor.setPosition(cursor.position() - 1);
+            cursor->setPosition(cursor->position() - 1);
         }
-        if (cursor.charFormat().anchorHref() != aHref)
-            cursor.setPosition(cursor.position() + 1, QTextCursor::KeepAnchor);
+        if (cursor->charFormat().anchorHref() != aHref)
+            cursor->setPosition(cursor->position() + 1, QTextCursor::KeepAnchor);
 
         // Move selection to the end of the link
-        while (cursor.charFormat().anchorHref() == aHref) {
-            if (cursor.atEnd())
+        while (cursor->charFormat().anchorHref() == aHref) {
+            if (cursor->atEnd())
                 break;
-            cursor.setPosition(cursor.position() + 1, QTextCursor::KeepAnchor);
+            cursor->setPosition(cursor->position() + 1, QTextCursor::KeepAnchor);
         }
-        if (cursor.charFormat().anchorHref() != aHref)
-            cursor.setPosition(cursor.position() - 1, QTextCursor::KeepAnchor);
-        d->setTextCursor(cursor);
+        if (cursor->charFormat().anchorHref() != aHref)
+            cursor->setPosition(cursor->position() - 1, QTextCursor::KeepAnchor);
     }
-    else if (cursor.hasSelection())
+    else if (cursor->hasSelection())
     {
         // Nothing to to
     } else {
 
         // Select current word
-        cursor.movePosition( QTextCursor::StartOfWord );
-        cursor.movePosition( QTextCursor::EndOfWord, QTextCursor::KeepAnchor );
-        d->setTextCursor(cursor);
+        cursor->movePosition( QTextCursor::StartOfWord );
+        cursor->movePosition( QTextCursor::EndOfWord, QTextCursor::KeepAnchor );
     }
 }
 
--- trunk/playground/libs/krichtext/krichtextedit.h #804432:804433
@@ -124,10 +124,19 @@
      * text of the link. If the cursor is not on a link, selects the current word
      * or existing selection.
      *
+     *
+     * @param cursor The cursor to use to select the text.
      * @sa updateLink
      */
+    void selectLinkText(QTextCursor* cursor) const;
+
+    /**
+     * Convenience function to select the link text using the active cursor in the \
TextEdit +     *
+     */
     void selectLinkText() const;
 
+
     /**
      * Replaces the current selection with a hyperlink with the link URL @a linkUrl
      * and the link text @a linkText.
--- trunk/playground/libs/krichtext/krichtexteditor.cpp #804432:804433
@@ -36,6 +36,7 @@
 #include <KIO/NetAccess>
 #include <KSaveFile>
 #include <KXMLGUIFactory>
+#include <KStatusBar>
 
 #include "krichtextwidget.h"
 
@@ -48,9 +49,14 @@
 
     setCentralWidget(textArea);
 
+    textArea->setRichTextSupport( KRichTextWidget::FullListSupport );
     setupGUI();
     guiFactory()->addClient(textArea);
 
+    statusBar()->insertItem( "", 0, 1 );
+    statusBar()->setItemAlignment( 0, Qt::AlignLeft | Qt::AlignVCenter );
+    connect(textArea, SIGNAL(cursorPositionChanged()),
+        SLOT(cursorPositionChanged()));
 }
 
 void KRichTextEditor::setupActions()
@@ -71,6 +77,19 @@
                         actionCollection());
 }
 
+void KRichTextEditor::cursorPositionChanged()
+{
+ // Show link target in status bar
+  if ( textArea->textCursor().charFormat().isAnchor() ) {
+    QString text = textArea->currentLinkText();
+    QString url = textArea->currentLinkUrl();
+    statusBar()->changeItem( text + " -> " + url, 0 );
+  }
+  else {
+    statusBar()->changeItem( QString(), 0 );
+  }
+}
+
 void KRichTextEditor::newFile()
 {
 //maybeSave
--- trunk/playground/libs/krichtext/krichtexteditor.h #804432:804433
@@ -38,6 +38,7 @@
     void saveFile();
     void saveFileAs();
     void saveFileAs(const QString &outputFileName);
+    void cursorPositionChanged();
 
 private:
     KRichTextWidget* textArea;
--- trunk/playground/libs/krichtext/krichtextwidget.cpp #804432:804433
@@ -37,6 +37,8 @@
 #include <KFontSizeAction>
 #include <KGlobalSettings>
 #include <KIcon>
+#include <KStandardDirs>
+#include <KIO/NetAccess>
 #include <KToggleAction>
 #include <KActionCollection>
 
@@ -93,10 +95,23 @@
 
     setComponentData(KComponentData("krichtextwidget"));
 
-    setRichTextSupport( \
(KRichTextWidget::RichTextSupport)(KRichTextWidget::FullSupport) ); +    // In order \
to make this widget usable in multiple applications each with different toolbar +    \
// configurations, the krichtextwidgetui.rc file is copied into the local appdata \
directory +    // of the parent application on first use.
+    QString targetPath = KStandardDirs::locateLocal("appdata", \
"krichtextwidgetui.rc");  
-    setXMLFile( "krichtextwidgetui.rc" );
+    if (KStandardDirs::locate("appdata", "krichtextwidgetui.rc").isEmpty())
+    {
+        // krichtextwidgetui.rc not yet in the local appdata directory, so copy it \
in. +        QString sourcePath = KStandardDirs::locate("data", \
"krichtextwidget/krichtextwidgetui.rc"); +        \
KIO::NetAccess::file_copy(sourcePath, targetPath); +    }
 
+    setRichTextSupport( KRichTextWidget::FullSupport );
+
+    setXMLFile( targetPath );
+    setLocalXMLFile( targetPath ); 
+
     connect(this, SIGNAL(selectionFinished()), this, SLOT(onSelectionFinished()));
     connect(this, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
             this, SLOT(updateCharFormatActions(const QTextCharFormat &)));


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

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