r23396 by jghali - #11369: Scribus doesn't show the search results outside the viewport or outside of linked textframe

scribus-commit scribus-commit at lists.scribus.net
Thu Dec 5 06:36:39 UTC 2019


Author: jghali
Date: Thu Dec  5 06:36:39 2019
New Revision: 23396

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23396
Log:
#11369: Scribus doesn't show the search results outside the viewport or outside of linked textframe

Modified:
    trunk/Scribus/scribus/canvasmode_edit.cpp
    trunk/Scribus/scribus/canvasmode_edittable.cpp
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem.h
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/scribusview.cpp
    trunk/Scribus/scribus/scribusview.h
    trunk/Scribus/scribus/text/storytext.cpp
    trunk/Scribus/scribus/text/storytext.h
    trunk/Scribus/scribus/ui/search.cpp
    trunk/Scribus/scribus/ui/search.h

Modified: trunk/Scribus/scribus/canvasmode_edit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/canvasmode_edit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edit.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode_edit.cpp	Thu Dec  5 06:36:39 2019
@@ -378,8 +378,7 @@
 				}
 				else
 				{
-					int newPos = currItem->itemText.selectWord(oldCp);
-					currItem->itemText.setCursorPosition(newPos);
+					currItem->itemText.selectWord(oldCp);
 				}
 			}
 			currItem->HasSel = currItem->itemText.isSelected();

Modified: trunk/Scribus/scribus/canvasmode_edittable.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/canvasmode_edittable.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edittable.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode_edittable.cpp	Thu Dec  5 06:36:39 2019
@@ -342,8 +342,7 @@
 	{
 		// Regular double click selects a word.
 		m_lastCursorPos = textFrame->itemText.cursorPosition();
-		uint pos = textFrame->itemText.selectWord(textFrame->itemText.cursorPosition());
-		textFrame->itemText.setCursorPosition(pos);
+		textFrame->itemText.selectWord(textFrame->itemText.cursorPosition());
 	}
 
 	updateCanvas(true);

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp	(original)
+++ trunk/Scribus/scribus/pageitem.cpp	Thu Dec  5 06:36:39 2019
@@ -1183,6 +1183,30 @@
 	checkChanges();
 }
 
+
+/// tests if a character is displayed by this frame
+bool PageItem::frameDisplays(int textpos) const
+{
+	return 0 <= textpos && textpos < signed(m_maxChars) && textpos < itemText.length();
+}
+
+PageItem* PageItem::frameOfChar(int textPos)
+{
+	PageItem* firstFrame = this->firstInChain();
+	PageItem* nextFrame = firstFrame;
+
+	while (nextFrame)
+	{
+		if (nextFrame->invalid)
+			nextFrame->layout();
+		if (nextFrame->frameDisplays(textPos))
+			return nextFrame;
+		nextFrame = nextFrame->nextInChain();
+	}
+
+	return nullptr;
+}
+
 //return frame where is text end
 PageItem * PageItem::frameTextEnd()
 {
@@ -1531,13 +1555,6 @@
 		undoManager->action(this, is);
 	}
 }
-
-/// tests if a character is displayed by this frame
-bool PageItem::frameDisplays(int textpos) const
-{
-	return 0 <= textpos && textpos < signed(m_maxChars) && textpos < itemText.length();
-}
-
 
 /// returns the style at the current charpos
 const ParagraphStyle& PageItem::currentStyle() const
@@ -7634,7 +7651,7 @@
 
 void PageItem::replaceNamedResources(ResourceCollection& newNames)
 {
-	QMap<QString,QString>::ConstIterator it;
+	QMap<QString, QString>::ConstIterator it;
 	
 	it = newNames.colors().find(softShadowColor());
 	if (it != newNames.colors().end())

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h	(original)
+++ trunk/Scribus/scribus/pageitem.h	Thu Dec  5 06:36:39 2019
@@ -404,6 +404,10 @@
 	virtual void invalidateLayout() { invalid = true; }
 	/// creates valid layout information
 	virtual void layout() {}
+	 ///< tests if a character is displayed by this frame
+	bool frameDisplays(int textpos) const;
+	/// get frame where is displayed text char in a chain
+	PageItem* frameOfChar(int textPos);
 	/// returns frame where is text end
 	PageItem * frameTextEnd();
 	/// returns true if text overflows
@@ -418,7 +422,7 @@
 	/// returns index of last char displayed in this frame, used to be MaxChars-1
 	int lastInFrame() const;
 
-	bool frameDisplays(int textpos) const; ///< tests if a character is displayed by this fram
+	
 	const ParagraphStyle& currentStyle() const; ///< returns the style at the current charpos
 	ParagraphStyle& changeCurrentStyle(); ///< returns the style at the current charpos
 	/// returns the style at the current charpos

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Thu Dec  5 06:36:39 2019
@@ -8453,14 +8453,26 @@
 
 void ScribusMainWindow::SearchText()
 {
+	bool wasModeEdit = (doc->appMode == modeEdit);
+
 	PageItem *currItem = doc->m_Selection->itemAt(0);
-	view->requestMode(modeEdit);
-	currItem->itemText.setCursorPosition(0);
+	if (!wasModeEdit)
+	{
+		view->requestMode(modeEdit);
+		currItem->itemText.setCursorPosition(0);
+	}
+	
 	SearchReplace* dia = new SearchReplace(this, doc, currItem);
+	if (wasModeEdit)
+	{
+		QString selText = currItem->itemText.selectedText();
+		if (!selText.isEmpty())
+			dia->setSearchedText(selText);
+	}
 	dia->exec();
 	dia->disconnect();
 	delete dia;
-	slotSelect();
+	//slotSelect();
 }
 
 /* call gimp and wait upon completion */

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Thu Dec  5 06:36:39 2019
@@ -16138,6 +16138,25 @@
 	return m_tserializer;
 }
 
+bool ScribusDoc::textCanvasPosition(PageItem* item, int textPos, QPointF& canvasPos)
+{
+	canvasPos = QPointF();
+
+	if (!item->isTextFrame() && !item->isPathText() && !item->isNoteFrame())
+		return false;
+
+	PageItem *charFrame = item->frameOfChar(textPos);
+	if (!charFrame)
+		return false;
+
+	QLineF charPos = charFrame->textLayout.positionToPoint(textPos);
+
+	QTransform itemTransform = charFrame->getTransform();
+	canvasPos = itemTransform.map(QPointF(charPos.x1(), charPos.y1()));
+
+	return true;
+}
+
 void ScribusDoc::setRotationMode(int val)
 {
 	if (m_rotMode == val)

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Thu Dec  5 06:36:39 2019
@@ -1212,6 +1212,9 @@
 	//! \brief Returns a text serializer for this document, used to paste text chunks
 	Serializer *textSerializer();
 
+	//! \brief Retrieve canvas position of text char in specified text chain
+	bool textCanvasPosition(PageItem* item, int textPos, QPointF& canvasPos);
+
 	//! \brief Get rotation mode
 	int rotationMode() const {return m_rotMode;}
 	//! \brief Set rotation mode
@@ -1221,6 +1224,7 @@
 	// unncessary signals when doing updates on multiple items
 	void beginUpdate();
 	void endUpdate();
+
 	int addToInlineFrames(PageItem *item);
 	void removeInlineFrame(int fIndex);
 	void checkItemForFrames(PageItem *it, int fIndex);

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp	(original)
+++ trunk/Scribus/scribus/scribusview.cpp	Thu Dec  5 06:36:39 2019
@@ -2253,11 +2253,11 @@
 /*!
   returns the visible part of the canvas in canvas coordinates
  */
-QRectF ScribusView::visibleCanvas() const
+QRectF ScribusView::visibleCanvasRect() const
 {
 	double scale = m_canvas->scale();
-	return QRectF(horizontalScrollBar()->value() / scale,
-				  verticalScrollBar()->value() / scale,
+	return QRectF(horizontalScrollBar()->value() / scale + Doc->minCanvasCoordinate.x(),
+				  verticalScrollBar()->value() / scale + Doc->minCanvasCoordinate.y(),
 				  viewport()->width() / scale,
 				  viewport()->height() / scale);
 }

Modified: trunk/Scribus/scribus/scribusview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/scribusview.h
==============================================================================
--- trunk/Scribus/scribus/scribusview.h	(original)
+++ trunk/Scribus/scribus/scribusview.h	Thu Dec  5 06:36:39 2019
@@ -199,7 +199,7 @@
 	void setCanvasOrigin(double x, double y);
 	void setCanvasCenter(double x, double y);
 	FPoint canvasOrigin() const;
-	QRectF visibleCanvas() const;
+	QRectF visibleCanvasRect() const;
 	void setRedrawMarkerShown(bool shown);
 	
 private:

Modified: trunk/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/text/storytext.cpp
==============================================================================
--- trunk/Scribus/scribus/text/storytext.cpp	(original)
+++ trunk/Scribus/scribus/text/storytext.cpp	Thu Dec  5 06:36:39 2019
@@ -741,9 +741,43 @@
 	invalidate(pos, pos + 1);
 }
 
+void StoryText::replaceSelection(const QString& newText)
+{
+	if (selectionLength() <= 0)
+		return;
+
+	int selStart = startOfSelection();
+	int selLength = selectionLength();
+
+	int lengthDiff = newText.length() - selLength;
+	if (lengthDiff == 0)
+	{
+		for (int i = 0; i < selLength; ++i)
+			replaceChar(selStart + i, newText[i]);
+	}
+	else if (lengthDiff > 0)
+	{
+		for (int i = 0; i < selLength; ++i)
+			replaceChar(selStart + i, newText[i]);
+		for (int i = selLength; i < newText.length(); ++i)
+			insertChars(selStart + i, newText.mid(i, 1), true);
+	}
+	else
+	{
+		for (int i = 0; i < newText.length(); ++i)
+			replaceChar(selStart + i, newText[i]);
+		removeChars(selStart + newText.length(), -lengthDiff);
+	}
+
+	deselectAll();
+	if (newText.length() > 0)
+		select(selStart, newText.length());
+	setCursorPosition(selStart + newText.length());
+}
+
 int StoryText::replaceWord(int pos, QString newWord)
 {
-	int eoWord=pos;
+	int eoWord = pos;
 	while (eoWord < length())
 	{
 		if (text(eoWord).isLetterOrNumber() || SpecialChars::isIgnorableCodePoint(text(eoWord).unicode()))
@@ -756,23 +790,20 @@
 	if (lengthDiff == 0)
 	{
 		for (int j = 0; j < word.length(); ++j)
-			replaceChar(pos+j, newWord[j]);
+			replaceChar(pos + j, newWord[j]);
+	}
+	else if (lengthDiff > 0)
+	{
+		for (int j = 0; j < word.length(); ++j)
+			replaceChar(pos + j, newWord[j]);
+		for (int j = word.length(); j < newWord.length(); ++j)
+			insertChars(pos + j, newWord.mid(j, 1), true);
 	}
 	else
 	{
-		if (lengthDiff>0)
-		{
-			for (int j = 0; j < word.length(); ++j)
-				replaceChar(pos+j, newWord[j]);
-			for (int j = word.length(); j < newWord.length(); ++j)
-				insertChars(pos+j, newWord.mid(j,1), true);
-		}
-		else
-		{
-			for (int j = 0; j < newWord.length(); ++j)
-				replaceChar(pos+j, newWord[j]);
-			removeChars(pos+newWord.length(), -lengthDiff);
-		}
+		for (int j = 0; j < newWord.length(); ++j)
+			replaceChar(pos + j, newWord[j]);
+		removeChars(pos + newWord.length(), -lengthDiff);
 	}
 	return lengthDiff;
 }
@@ -1772,6 +1803,13 @@
 	;
 }
 
+QString StoryText::selectedText() const
+{
+	int selLen = selectionLength();
+	if (selLen <= 0)
+		return QString();
+	return text(startOfSelection(), selLen);
+}
 
 int StoryText::selectWord(int pos)
 {
@@ -1784,7 +1822,10 @@
 	int end = it->next();
 	int wordLength = end - start;
 	if (wordLength > 0)
+	{
 		select(start, wordLength);
+		setCursorPosition(endOfSelection());
+	}
 	else
 	{
 		deselectAll();

Modified: trunk/Scribus/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/text/storytext.h
==============================================================================
--- trunk/Scribus/scribus/text/storytext.h	(original)
+++ trunk/Scribus/scribus/text/storytext.h	Thu Dec  5 06:36:39 2019
@@ -128,7 +128,10 @@
 	void insertObject(int pos, int obj);
 	// Insert mark at cursor or specific position
 	void insertMark(Mark* Mark, int pos = -1);
+	// Replace a character
  	void replaceChar(int pos, QChar ch);
+	// Replace current selection with specified text
+	void replaceSelection(const QString& newText);
  	// Replaced a word, and return the difference in length between old and new
 	int replaceWord(int pos, QString newWord);
 	void replaceObject(int pos, int obj);
@@ -242,12 +245,13 @@
 	void extendSelection(int oldPos, int newPos);
 	int selectWord(int pos);
 	void select(int pos, int len, bool on = true);
+	QString selectedText() const;
 	bool selected(int pos) const;
 	int startOfSelection() const;
 	int endOfSelection() const;
 	int selectionLength() const;
 	bool isSelected() const;
-
+	
 	// break iterators
 	static BreakIterator* getGraphemeIterator();
 	static BreakIterator* getWordIterator();

Modified: trunk/Scribus/scribus/ui/search.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/ui/search.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/search.cpp	(original)
+++ trunk/Scribus/scribus/ui/search.cpp	Thu Dec  5 06:36:39 2019
@@ -6,20 +6,22 @@
 */
 #include "search.h"
 
+#include <QCheckBox>
+#include <QComboBox>
+#include <QGroupBox>
 #include <QHBoxLayout>
 #include <QGridLayout>
 #include <QVBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
 #include <QListView>
-#include <QGroupBox>
-#include <QCheckBox>
-#include <QLineEdit>
-#include <QComboBox>
+#include <QMessageBox>
+#include <QPixmap>
 #include <QPushButton>
-#include <QLabel>
-#include <QPixmap>
-#include <QMessageBox>
+#include <QScopedValueRollback>
 
 #include "appmodes.h"
+#include "canvas.h"
 #include "colorcombo.h"
 #include "colorlistbox.h"
 #include "commonstrings.h"
@@ -30,7 +32,9 @@
 #include "prefsmanager.h"
 #include "scpage.h"
 #include "scribus.h"
+#include "scribusview.h"
 #include "scrspinbox.h"
+#include "selection.h"
 #include "shadebutton.h"
 #include "styleselect.h"
 #include "ui/storyeditor.h"
@@ -38,14 +42,11 @@
 #include "util_text.h"
 
 SearchReplace::SearchReplace( QWidget* parent, ScribusDoc *doc, PageItem* ite, bool mode )
-	: QDialog( parent ),
-	matchesFound(0)
+	: QDialog( parent )
 {
 	m_item = ite;
 	m_doc = doc;
-	m_notFound = false;
 	m_itemMode = mode;
-	m_firstMatchPosition = -1;
 
 	setModal(true);
 	setWindowTitle( tr( "Search/Replace" ) );
@@ -365,17 +366,15 @@
 
 void SearchReplace::slotSearch()
 {
-//	if (m_itemMode)
-//		m_doc->view()->slotDoCurs(false);
-	slotDoSearch();
+	doSearch();
+
 	if (m_itemMode)
-	{
-//		m_doc->view()->slotDoCurs(true);
 		m_item->update();
-	}
-}
-
-void SearchReplace::slotDoSearch()
+	if (!m_found)
+		showNotFoundMessage();
+}
+
+void SearchReplace::doSearch()
 {
 	int maxChar = m_item->itemText.length() - 1;
 	DoReplace->setEnabled(false);
@@ -385,11 +384,11 @@
 		m_item->itemText.deselectAll();
 		m_item->HasSel = false;
 	}
+
 	QString fCol = "";
 	QString sCol = "";
 	QString sFont = "";
 	QString sText = "";
-	m_notFound = true;
 	int sStyle = 0;
 	int sAlign = 0;
 	int sSize = 0;
@@ -399,6 +398,9 @@
 	bool searchForReplace = false;
 	bool rep = false;
 	bool found = true;
+
+	m_found = true;
+
 	if ((RFill->isChecked()) || (RStroke->isChecked()) || (RStyle->isChecked()) || (RFont->isChecked())
 		|| (RStrokeS->isChecked()) || (RFillS->isChecked()) || (RSize->isChecked()) || (RText->isChecked())
 		|| (REffect->isChecked())  || (RAlign->isChecked()))
@@ -431,17 +433,18 @@
 		sSize = qRound(SSizeVal->value() * 10);
 	if (sText.length() > 0)
 		found = false;
-
-	uint as = m_item->itemText.cursorPosition();
-	m_replStart = as;
+	
 	int a, textLen(0);
+	int cursorPos = m_item->itemText.cursorPosition();
+	m_replStart = cursorPos;
+
 	if (m_itemMode)
 	{
 		Qt::CaseSensitivity cs = Qt::CaseSensitive;
 		if (CaseIgnore->isChecked())
 			cs = Qt::CaseInsensitive;
 
-		for (a = as; a < m_item->itemText.length(); ++a)
+		for (a = cursorPos; a < m_item->itemText.length(); ++a)
 		{
 			found = true;
 			if (SText->isChecked())
@@ -525,9 +528,45 @@
 			}
 			if (SText->isChecked())
 			{
-				for (int xx = m_replStart; xx < a+1; ++xx)
+				for (int xx = m_replStart; xx < a + 1; ++xx)
 					m_item->itemText.select(qMin(xx, maxChar), 1, false);
 				m_item->HasSel = false;
+			}
+		}
+		if (found && !m_replacingAll)
+		{
+			QPointF textCanvasPos;
+			int foundPos = m_item->itemText.cursorPosition();
+			if (m_item->itemText.selectionLength() > 0)
+				foundPos = m_item->itemText.startOfSelection();
+			bool cPosFound = m_doc->textCanvasPosition(m_item, foundPos, textCanvasPos);
+			if (cPosFound)
+			{
+				QRectF updateRect;
+				PageItem* textItem = m_item->frameOfChar(foundPos);
+				if (textItem != m_item)
+				{
+					updateRect = m_item->getVisualBoundingRect();
+					updateRect = updateRect.united(textItem->getVisualBoundingRect());
+					int selLength = m_item->itemText.selectionLength();
+					m_item->itemText.deselectAll();
+					m_item->HasSel = false;
+					m_doc->m_Selection->delaySignalsOn();
+					m_doc->m_Selection->removeItem(m_item);
+					m_doc->m_Selection->addItem(textItem);
+					m_item = textItem;
+					m_item->itemText.deselectAll();
+					if (selLength > 0)
+						m_item->itemText.select(foundPos, selLength);
+					m_item->itemText.setCursorPosition(foundPos + selLength);
+					m_item->HasSel = true;
+					m_doc->m_Selection->delaySignalsOff();
+				}
+				QRectF visibleCanvasRect = m_doc->view()->visibleCanvasRect();
+				if (!visibleCanvasRect.contains(textCanvasPos))
+					m_doc->view()->setCanvasCenterPos(textCanvasPos.x(), textCanvasPos.y());
+				if (!updateRect.isEmpty())
+					m_doc->regionsChanged()->update(updateRect.adjusted(-10.0, -10.0, 10.0, 10.0));
 			}
 		}
 		if ((!found) || (a == m_item->itemText.length()))
@@ -536,9 +575,8 @@
 			m_item->update();
 			DoReplace->setEnabled(false);
 			AllReplace->setEnabled(false);
-			ScMessageBox::information(this, tr("Search/Replace"), tr("Search finished"));
 			m_item->itemText.setCursorPosition(0);
-			m_notFound = false;
+			m_found = false;
 		}
 	}
 	else if (m_doc->scMW()->CurrStED != nullptr)
@@ -662,15 +700,12 @@
 				DoReplace->setEnabled(true);
 				AllReplace->setEnabled(true);
 			}
-			matchesFound++;
+			m_matchesFound++;
 			m_firstMatchPosition = storyTextEdit->textCursor().selectionStart();
 		}
 		else
 		{
-			ScMessageBox::information(this, tr("Search/Replace"),
-					tr("Search finished, found %1 matches").arg(matchesFound));
-			matchesFound = 0;
-			m_notFound = false;
+			m_found = false;
 			QTextCursor cursor = storyTextEdit->textCursor();
 			cursor.clearSelection();
 			cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
@@ -681,55 +716,22 @@
 
 void SearchReplace::slotReplace()
 {
-//	if (m_itemMode)
-//		m_doc->view()->slotDoCurs(false);
-	slotDoReplace();
+	doReplace();
+
+	if (m_itemMode)
+		m_item->update();
+	if (!m_found)
+		showNotFoundMessage();
+}
+
+void SearchReplace::doReplace()
+{
 	if (m_itemMode)
 	{
-//		m_doc->view()->slotDoCurs(true);
-		m_item->update();
-	}
-}
-
-void SearchReplace::slotDoReplace()
-{
-	if (m_itemMode)
-	{
-		QString repl, sear;
-		int cs, cx;
-		int textLen = 0;
 		if (RText->isChecked())
 		{
-			repl = RTextVal->text();
-			sear = STextVal->text();
-			textLen = m_item->itemText.selectionLength();
-			if (textLen == repl.length())
-			{
-				for (cs = 0; cs < textLen; ++cs)
-					m_item->itemText.replaceChar(m_replStart+cs, repl[cs]);
-			}
-			else
-			{
-				if (textLen < repl.length())
-				{
-					for (cs = 0; cs < textLen; ++cs)
-						m_item->itemText.replaceChar(m_replStart+cs, repl[cs]);
-					for (cx = cs; cx < repl.length(); ++cx)
-						m_item->itemText.insertChars(m_replStart+cx, repl.mid(cx,1), true);
-				}
-				else
-				{
-					for (cs = 0; cs < repl.length(); ++cs)
-						m_item->itemText.replaceChar(m_replStart+cs, repl[cs]);
-					m_item->itemText.removeChars(m_replStart+cs, textLen - cs);
-				}
-			}
-			m_item->itemText.deselectAll();
-			if (repl.length() > 0)
-			{
-				m_item->itemText.select(m_replStart, repl.length());
-				m_item->itemText.setCursorPosition(m_replStart + repl.length());
-			}
+			QString repl = RTextVal->text();
+			m_item->itemText.replaceSelection(repl);
 		}
 		if (RStyle->isChecked())
 		{
@@ -761,17 +763,13 @@
 		{
 			int s = REffVal->getStyle() & ScStyle_UserStyles;
 			m_doc->currentStyle.charStyle().setFeatures(static_cast<StyleFlag>(s).featureList()); // ???
-			for (int a = 0; a < m_item->itemText.length(); ++a)
-			{
-				if (m_item->itemText.selected(a))
+			for (int i = 0; i < m_item->itemText.length(); ++i)
+			{
+				if (m_item->itemText.selected(i))
 				{
-//                    StyleFlag fl = m_item->itemText.charStyle(a).effects();
-//					fl &= static_cast<StyleFlag>(~1919);
-//					fl |= static_cast<StyleFlag>(s);
-//					m_item->itemText.item(a)->setFeatures(fl.featureList());
 					CharStyle newFeatures;
 					newFeatures.setFeatures(static_cast<StyleFlag>(s).featureList());
-					m_item->itemText.applyCharStyle(a, 1, newFeatures);
+					m_item->itemText.applyCharStyle(i, 1, newFeatures);
 				}
 			}
 		}
@@ -830,7 +828,7 @@
 	}
 	DoReplace->setEnabled(false);
 	AllReplace->setEnabled(false);
-	slotDoSearch();
+	doSearch();
 }
 
 int SearchReplace::firstMatchCursorPosition()
@@ -838,24 +836,48 @@
 	return m_firstMatchPosition;
 }
 
+void SearchReplace::setSearchedText(const QString& text)
+{
+	if (SText->isChecked())
+		STextVal->setText(text);
+}
+
 void SearchReplace::slotReplaceAll()
 {
+	QScopedValueRollback<bool> replaceAllRollback(m_replacingAll, true);
+
 	if (m_itemMode)
-	{
-//		m_doc->view()->slotDoCurs(false);
 		m_doc->DoDrawing = false;
-	}
+
 	do
 	{
-		slotDoReplace();
-//		slotDoSearch();
+		doReplace();
 	}
-	while (m_notFound);
+	while (m_found);
+
 	if (m_itemMode)
 	{
 		m_doc->DoDrawing = true;
-//		m_doc->view()->slotDoCurs(true);
-		m_item->update();
+		if (m_item->isTextFrame())
+			m_item->asTextFrame()->invalidateLayout(true);
+		m_doc->regionsChanged()->update(QRectF());
+	}
+
+	showNotFoundMessage();
+}
+
+void SearchReplace::showNotFoundMessage()
+{
+	if (m_found)
+		return;
+
+	if (m_itemMode)
+		ScMessageBox::information(this, tr("Search/Replace"), tr("Search finished"));
+	else
+	{
+		ScMessageBox::information(this, tr("Search/Replace"),
+					tr("Search finished, found %1 matches").arg(m_matchesFound));
+		m_matchesFound = 0;
 	}
 }
 
@@ -1060,7 +1082,7 @@
 		replaceEnabled &= m_doc->scMW()->CurrStED->Editor->textCursor().hasSelection();
 	else
 		replaceEnabled = false;
-	replaceEnabled &= m_notFound;
+	replaceEnabled &= m_found;
 	DoReplace->setEnabled(replaceEnabled);
 	AllReplace->setEnabled(replaceEnabled);
 }

Modified: trunk/Scribus/scribus/ui/search.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23396&path=/trunk/Scribus/scribus/ui/search.h
==============================================================================
--- trunk/Scribus/scribus/ui/search.h	(original)
+++ trunk/Scribus/scribus/ui/search.h	Thu Dec  5 06:36:39 2019
@@ -35,9 +35,9 @@
 public:
 	SearchReplace( QWidget* parent, ScribusDoc *doc, PageItem* ite, bool mode = true );
 	~SearchReplace() {};
-	virtual void slotDoSearch();
-	virtual void slotDoReplace();
+
 	int firstMatchCursorPosition();
+	void setSearchedText(const QString& text);
 
 	QLabel* SText1;
 	QLabel* RText1;
@@ -126,8 +126,9 @@
 
 	uint m_replStart;
 	PrefsContext* m_prefs;
-	bool m_notFound;
+	bool m_found { false };
 	bool m_itemMode;
+	bool m_replacingAll { false };
 
 	QVBoxLayout* SearchReplaceLayout;
 	QHBoxLayout* SelLayout;
@@ -136,11 +137,15 @@
 	QHBoxLayout* OptsLayout;
 	QHBoxLayout* ButtonsLayout;
 
+	virtual void doSearch();
+	virtual void doReplace();
+	virtual void showNotFoundMessage();
+
 	virtual void readPrefs();
 
 	/// Number of matches found thus far in a search
-	int matchesFound;
-	int m_firstMatchPosition;
+	int m_matchesFound { 0 };
+	int m_firstMatchPosition { -1 };
 
 };
 




More information about the scribus-commit mailing list