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

List:       koffice-devel
Subject:    koffice
From:       Thomas Zander <zander () kde ! org>
Date:       2007-07-08 16:34:28
Message-ID: 1183912468.886533.23471.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 685336 by zander:

Introduce a KoFind class which is a controller that creates the find
actions and is able to work with the text tool to let the user search for text
in the current text document.
This will work for all KOffice apps; so feel free to add it to your app
if you think it makes sense to have a Find on the current text-shape.
CCMAIL: koffice-devel@kde.org

TODO; limit results based on text-style / replace.


 M  +4 -6      kword/part/KWView.cpp  
 M  +1 -0      libs/kotext/CMakeLists.txt  
 A             libs/kotext/KoFind.cpp   [License: LGPL (v2+)]
 A             libs/kotext/KoFind.h   [License: LGPL (v2+)]
 M  +0 -1      libs/kotext/KoRulerController.cpp  
 M  +3 -3      libs/kotext/KoText.h  
 M  +30 -4     shapes/text/TextTool.cpp  
 M  +5 -1      shapes/text/TextTool.h  


--- trunk/koffice/kword/part/KWView.cpp #685335:685336
@@ -37,6 +37,7 @@
 #include <KoPasteController.h>
 #include <KoShape.h>
 #include <KoText.h>
+#include <KoFind.h>
 #include <KoShapeContainer.h>
 #include <KoShapeManager.h>
 #include <KoSelection.h>
@@ -87,8 +88,10 @@
 
     setupActions();
 
-    connect( kwcanvas()->shapeManager()->selection(), SIGNAL( selectionChanged() ), \
this, SLOT( selectionChanged() ) ); +    connect( \
m_canvas->shapeManager()->selection(), SIGNAL( selectionChanged() ), this, SLOT( \
selectionChanged() ) );  
+    new KoFind(this, m_canvas->resourceProvider(), actionCollection());
+
     m_zoomController = new KoZoomController(m_gui->canvasController(), \
&m_zoomHandler, actionCollection(), true);  KoZoomMode::Modes modes = \
KoZoomMode::ZOOM_WIDTH;  if ( m_canvas->viewMode()->hasPages() )
@@ -245,11 +248,6 @@
     // -------------- Edit actions
     m_actionEditCut = actionCollection()->addAction(KStandardAction::Cut,  \
                "edit_cut", this, SLOT( editCut() ));
     m_actionEditCopy = actionCollection()->addAction(KStandardAction::Copy,  \
                "edit_copy", this, SLOT( editCopy() ));
-    m_actionEditFind = actionCollection()->addAction(KStandardAction::Find,  \
                "edit_find", this, SLOT( editFind() ));
-    m_actionEditFindNext = actionCollection()->addAction(KStandardAction::FindNext,  \
                "edit_findnext", this, SLOT( editFindNext() ));
-    m_actionEditFindPrevious = \
actionCollection()->addAction(KStandardAction::FindPrev,  "edit_findprevious", this, \
                SLOT( editFindPrevious() ));
-    m_actionEditReplace = actionCollection()->addAction(KStandardAction::Replace,  \
                "edit_replace", this, SLOT( editReplace() ));
-    m_actionEditSelectAll = \
actionCollection()->addAction(KStandardAction::SelectAll,  "edit_selectall", this, \
                SLOT( editSelectAll() ));
     new KAction( i18n( "Select All Frames" ), 0, this, SLOT( editSelectAllFrames() \
                ), actionCollection(), "edit_selectallframes" );
     m_actionEditSelectCurrentFrame = new KAction( i18n( "Select Frame" ), 0,
     0, this, SLOT( editSelectCurrentFrame() ),
--- trunk/koffice/libs/kotext/CMakeLists.txt #685335:685336
@@ -53,6 +53,7 @@
     KoBookmark.cpp
     KoBookmarkManager.cpp
     KoRulerController.cpp
+    KoFind.cpp
 
     styles/Styles_p.cpp
     styles/KoCharacterStyle.cpp
--- trunk/koffice/libs/kotext/KoRulerController.cpp #685335:685336
@@ -88,7 +88,6 @@
     }
 
     void tabsChanged(bool final) {
-kDebug() << "tabsChanged\n";
         Q_UNUSED(final); // TODO use this to cache the tab struct I'm altering.
         QTextBlock block = currentBlock();
         if(! block.isValid())
--- trunk/koffice/libs/kotext/KoText.h #685335:685336
@@ -37,9 +37,9 @@
     enum Options {
         ShowTextFrames =  278622039,
         BidiDocument = 493038196,
-        CurrentTextDocument = 382490375,
-        CurrentTextPosition = 183523,
-        CurrentTextAnchor = 341899485
+        CurrentTextDocument = 382490375, ///< set by the text plugin whenever the \
document is changed +        CurrentTextPosition = 183523,   ///<  set by the text \
plugin whenever the position is changed +        CurrentTextAnchor = 341899485   ///< \
set by the text plugin whenever the anchor-position is changed  };
 
     /// enum for a type of tabulator used
--- trunk/koffice/shapes/text/TextTool.cpp #685335:685336
@@ -108,6 +108,7 @@
     m_allowActions(true),
     m_allowAddUndoCommand(true),
     m_trackChanges(false),
+    m_allowResourceProviderUpdates(true),
     m_prevCursorPosition(-1),
     m_currentCommand(0),
     m_currentCommandHasChildren(false)
@@ -357,7 +358,7 @@
     if(canMoveCaret) {
         bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
         if(m_caret.hasSelection() && !shiftPressed)
-            repaintSelection(m_caret.position(), m_caret.anchor()); // will erase \
selection +            repaintSelection(); // will erase selection
         else if(! m_caret.hasSelection())
             repaintCaret();
         int prevPosition = m_caret.position();
@@ -441,6 +442,7 @@
             clipboard->setText(m_caret.selectedText(), QClipboard::Selection);
     }
     KoCanvasResourceProvider *p = m_canvas->resourceProvider();
+    m_allowResourceProviderUpdates = false;
     if(m_textShapeData) {
         p->setResource(KoText::CurrentTextPosition, m_caret.position());
         p->setResource(KoText::CurrentTextAnchor, m_caret.anchor());
@@ -453,6 +455,7 @@
         p->clearResource(KoText::CurrentTextAnchor);
         p->clearResource(KoText::CurrentTextDocument);
     }
+    m_allowResourceProviderUpdates = true;
 }
 
 void TextTool::copy() const {
@@ -526,7 +529,7 @@
     if(qAbs(pos - m_caret.position()) <= 1) // clicked between two words
         m_caret.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor);
 
-    repaintSelection(m_caret.anchor(), m_caret.position());
+    repaintSelection();
 }
 
 void TextTool::mouseMoveEvent( KoPointerEvent *event ) {
@@ -686,7 +689,7 @@
         useCursor(Qt::BlankCursor);
         bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
         if(m_caret.hasSelection() && !shiftPressed)
-            repaintSelection(m_caret.position(), m_caret.anchor()); // will erase \
selection +            repaintSelection(); // will erase selection
         else if(! m_caret.hasSelection())
             repaintCaret();
         QTextBlockFormat format = m_caret.blockFormat();
@@ -898,7 +901,7 @@
 
 void TextTool::repaintDecorations() {
     if(m_textShapeData)
-        repaintSelection(m_caret.position(), m_caret.anchor());
+        repaintSelection();
 }
 
 void TextTool::repaintCaret() {
@@ -918,6 +921,10 @@
     }
 }
 
+void TextTool::repaintSelection() {
+    repaintSelection(m_caret.position(), m_caret.anchor());
+}
+
 void TextTool::repaintSelection(int startPosition, int endPosition) {
     QList<TextShape *> shapes;
     if(m_textShapeData->position() > startPosition || m_textShapeData->endPosition() \
< endPosition) { @@ -1400,6 +1407,25 @@
     updateActions();
 }
 
+void TextTool::resourceChanged(int key, const QVariant &var) {
+    if(m_allowResourceProviderUpdates == false)
+        return;
+    if(key == KoText::CurrentTextPosition) {
+        repaintSelection();
+        m_caret.setPosition(var.toInt());
+        ensureCursorVisible();
+    }
+    else if(key == KoText::CurrentTextAnchor) {
+        repaintSelection();
+        int pos = m_caret.position();
+        m_caret.setPosition(var.toInt());
+        m_caret.setPosition(pos, QTextCursor::KeepAnchor);
+    }
+    else return;
+
+    repaintSelection();
+}
+
 // ---------- editing plugins methods.
 void TextTool::editingPluginEvents() {
     if(m_prevCursorPosition == -1 || m_prevCursorPosition == m_caret.position())
--- trunk/koffice/shapes/text/TextTool.h #685335:685336
@@ -88,6 +88,8 @@
 public slots:
     /// add a command to the undo stack, executing it as well.
     void addCommand(QUndoCommand *command);
+    /// reimplemented from KoTool
+    virtual void resourceChanged (int key, const QVariant &res);
 
 signals:
     /// emitted every time a different styleManager is set.
@@ -157,6 +159,7 @@
 
 private:
     void repaintCaret();
+    void repaintSelection();
     void repaintSelection(int from, int to);
     void ensureCursorVisible();
     QRectF textRect(int startPosition, int endPosition) const;
@@ -183,6 +186,7 @@
     bool m_allowActions;
     bool m_allowAddUndoCommand;
     bool m_trackChanges;
+    bool m_allowResourceProviderUpdates;
     int m_prevCursorPosition; /// used by editingPluginEvents
 
     QAction *m_actionFormatBold;
@@ -211,7 +215,7 @@
     };
     UpdatePageDirection m_updateParagDirection;
 
-    /// structur that allows us to remember the text position and selection of \
previously edited documents. +    /// structure that allows us to remember the text \
position and selection of previously edited documents.  struct TextSelection {
         QTextDocument *document; // be warned that this may end up being a dangling \
pointer, so don't use.  int position;
_______________________________________________
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