View Issue Details

IDProjectCategoryView StatusLast Update
0012332ScribusStory Editor / Text Framespublic2014-06-14 06:39
Reporterale Assigned Tocbradney  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.5.0svn 
Target VersionFixed in Version1.5.0svn 
Summary0012332: [PATCH] truncate overflow and show number of overflowing white spaces
Description- implement the truncate function (in a similar way as clear contents)
- extend the overflow tooltip to show howmany spaces there are in the overflow
- since there is undo, remove the message from both clear and truncate
TagsNo tags attached.
Patch

Relationships

related to 0011847 closedale Continuing to improve text frame linking tool 

Activities

ale

2014-05-27 21:46

manager  

truncate.diff (14,229 bytes)
Index: scribus/actionmanager.cpp
===================================================================
--- scribus/actionmanager.cpp	(revision 19121)
+++ scribus/actionmanager.cpp	(working copy)
@@ -214,6 +214,8 @@
 	scrActions->insert(name, new ScrAction(loadIcon("16/edit-paste.png"), loadIcon("22/edit-paste.png"), "", defaultKey(name), mainWindow));
 	name="editClearContents";
 	scrActions->insert(name, new ScrAction(loadIcon("16/edit-delete.png"), loadIcon("22/edit-delete.png"), "", defaultKey(name), mainWindow));
+	name="editTruncateContents";
+	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
 	name="editSelectAll";
 	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
 	name="editSelectAllOnLayer";
@@ -1304,6 +1306,7 @@
 	disconnect( (*scrActions)["itemPreviewNormal"], SIGNAL(triggeredData(int)) , 0, 0);
 	disconnect( (*scrActions)["itemPreviewFull"], SIGNAL(triggeredData(int)) , 0, 0);
 	disconnect( (*scrActions)["editClearContents"], 0, 0, 0);
+	disconnect( (*scrActions)["editTruncateContents"], 0, 0, 0);
 }
 
 void ActionManager::connectNewSelectionActions(ScribusView* /*currView*/, ScribusDoc* currDoc)
@@ -1313,6 +1316,7 @@
 	connect( (*scrActions)["itemPreviewNormal"], SIGNAL(triggeredData(int)), currDoc, SLOT(itemSelection_ChangePreviewResolution(int)) );
 	connect( (*scrActions)["itemPreviewFull"], SIGNAL(triggeredData(int)), currDoc, SLOT(itemSelection_ChangePreviewResolution(int)) );
 	connect( (*scrActions)["editClearContents"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_ClearItem()) );
+	connect( (*scrActions)["editTruncateContents"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_TruncateItem()) );
 }
 
 void ActionManager::saveActionShortcutsPreEditMode()
@@ -1477,6 +1481,7 @@
 	(*scrActions)["editPasteContentsAbs"]->setTexts( tr("Paste (&Absolute)"));
 	(*scrActions)["editPasteImageFromClipboard"]->setTexts( tr("Paste Image from Clipboard"));
 	(*scrActions)["editClearContents"]->setTexts( tr("C&lear"));
+	(*scrActions)["editTruncateContents"]->setTexts( tr("T&runcate"));
 	(*scrActions)["editSelectAll"]->setTexts( tr("Select &All"));
 	(*scrActions)["editSelectAllOnLayer"]->setTexts( tr("Advanced Select All..."));
 	(*scrActions)["editDeselectAll"]->setTexts( tr("&Deselect All"));
@@ -2032,6 +2037,7 @@
 		<< "editPasteContentsAbs"
 		<< "editPasteImageFromClipboard"
 		<< "editClearContents"
+		<< "editTruncateContents"
 		<< "editSelectAll"
 		<< "editSelectAllOnLayer"
 		<< "editDeselectAll"
@@ -2530,6 +2536,7 @@
 	(*scrActions)["editPaste"]->setEnabled(false);
 //	scrMenuMgr->setMenuEnabled("EditPasteRecent", false);
 	(*scrActions)["editClearContents"]->setEnabled(false);
+	(*scrActions)["editTruncateContents"]->setEnabled(false);
 	(*scrActions)["editSelectAll"]->setEnabled(false);
 	(*scrActions)["editSelectAllOnLayer"]->setEnabled(false);
 	(*scrActions)["editDeselectAll"]->setEnabled(false);
Index: scribus/canvasmode_normal.cpp
===================================================================
--- scribus/canvasmode_normal.cpp	(revision 19121)
+++ scribus/canvasmode_normal.cpp	(working copy)
@@ -434,7 +434,7 @@
 				{
 					if (m_canvas->cursorOverTextFrameControl(m->globalPos(), hoveredItem))
 					{
-						QToolTip::showText(m->globalPos() + QPoint(5, 5), tr("Overflow Characters: %1").arg(hoveredItem->frameOverflowCount()), m_canvas);
+						QToolTip::showText(m->globalPos() + QPoint(5, 5), tr("Overflow Characters: %1 (%2 White Spaces)").arg(hoveredItem->frameOverflowCount()).arg(hoveredItem->frameOverflowBlankCount()), m_canvas);
 					}
 				}
 				else
Index: scribus/pageitem.cpp
===================================================================
--- scribus/pageitem.cpp	(revision 19121)
+++ scribus/pageitem.cpp	(working copy)
@@ -32,6 +32,7 @@
 #include <QFileInfo>
 #include <qdrawutil.h>
 #include <QRegExp>
+#include <QRegularExpression>
 #include <QMessageBox>
 #include <QPolygon>
 #include <cassert>
@@ -1173,6 +1174,15 @@
 	return 0;
 }
 
+int PageItem::frameOverflowBlankCount()
+{
+	if (frameOverflows())
+		return itemText.plainText().right(itemText.length() - MaxChars).count(QRegularExpression("\\s+"));
+
+	return 0;
+}
+
 int PageItem::maxCharsInFrame()
 {
 	return MaxChars;
Index: scribus/pageitem.h
===================================================================
--- scribus/pageitem.h	(revision 19121)
+++ scribus/pageitem.h	(working copy)
@@ -297,6 +297,7 @@
 	 * The view does when these are called.
 	 */
 	virtual void clearContents() {}
+	virtual void truncateContents() {}
 
 	//>> ********* Functions to work on the contents of the items *********
 
@@ -378,6 +379,7 @@
 	bool frameOverflows() const;
 	bool frameUnderflows() const;
 	int frameOverflowCount() const;
+	int frameOverflowBlankCount();
 	/// Draws the overflow marker.
 	void drawOverflowMarker(ScPainter *p);
 	/// returns index of first char displayed in this frame, used to be 0
Index: scribus/pageitem_textframe.cpp
===================================================================
--- scribus/pageitem_textframe.cpp	(revision 19121)
+++ scribus/pageitem_textframe.cpp	(working copy)
@@ -4054,6 +4054,23 @@
 	}
 }
 
+void PageItem_TextFrame::truncateContents()
+{
+	if ((this->nextInChain() == NULL) && frameOverflows())
+	{
+		ParagraphStyle defaultStyle = this->itemText.defaultStyle();
+		int pos = itemText.cursorPosition();
+		if (itemText.lengthOfSelection() == 0)
+		{
+			itemText.select(maxCharsInFrame(), itemText.length() - maxCharsInFrame(), true);
+			deleteSelectedTextFromFrame();
+		}
+		itemText.setCursorPosition(pos, true);
+
+		if(UndoManager::undoEnabled() && undoManager->getLastUndo())
+			undoManager->getLastUndo()->setName(Um::TruncateText);
+		this->itemText.setDefaultStyle(defaultStyle);
+	}
+}
+
 void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 {
 	if (frameUnderflows())
@@ -5269,6 +5286,7 @@
 	if (textLayout.lines() != 0)
 	{
 		actionList << "editClearContents";
+		actionList << "editTruncateContents";
 		actionList << "itemAdjustFrameHeightToText";
 	}
 }
Index: scribus/pageitem_textframe.h
===================================================================
--- scribus/pageitem_textframe.h	(revision 19121)
+++ scribus/pageitem_textframe.h	(working copy)
@@ -55,6 +55,7 @@
 	virtual bool isTextFrame() const { return true; }
 	
 	virtual void clearContents();
+	virtual void truncateContents();
 	
 	/**
 	* \brief Handle keyboard interaction with the text frame while in edit mode
Index: scribus/plugins/export/CMakeLists.txt
===================================================================
--- scribus/plugins/export/CMakeLists.txt	(revision 19121)
+++ scribus/plugins/export/CMakeLists.txt	(working copy)
@@ -1,3 +1,4 @@
 ADD_SUBDIRECTORY(pixmapexport)
 ADD_SUBDIRECTORY(svgexplugin)
 ADD_SUBDIRECTORY(xpsexport)
+ADD_SUBDIRECTORY(epub)
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp	(revision 19121)
+++ scribus/scribus.cpp	(working copy)
@@ -798,6 +798,7 @@
 	scrMenuMgr->addMenuItemString("editPasteContents", "EditContents");
 	scrMenuMgr->addMenuItemString("editPasteContentsAbs", "EditContents");
 	scrMenuMgr->addMenuItemString("editClearContents", "EditContents");
+	scrMenuMgr->addMenuItemString("editTruncateContents", "EditContents");
 	scrMenuMgr->addMenuItemString("itemDelete", "Edit");
 	scrMenuMgr->addMenuItemString("SEPARATOR", "Edit");
 	scrMenuMgr->addMenuItemString("editSelectAll", "Edit");
@@ -2766,6 +2767,7 @@
 		scrActions["editCopy"]->setEnabled(true);
 		scrMenuMgr->setMenuEnabled("EditContents", true);
 		scrActions["editClearContents"]->setEnabled(true);
+		scrActions["editTruncateContents"]->setEnabled(false);
 		scrActions["editSearchReplace"]->setEnabled(false);
 		scrActions["extrasHyphenateText"]->setEnabled(false);
 		scrActions["extrasDeHyphenateText"]->setEnabled(false);
@@ -2820,6 +2822,7 @@
 		scrActions["editCopy"]->setEnabled(true);
 		scrMenuMgr->setMenuEnabled("EditContents", true);
 		scrActions["editClearContents"]->setEnabled(true);
+		scrActions["editTruncateContents"]->setEnabled(true);
 		scrActions["editSearchReplace"]->setEnabled(currItem->itemText.length() != 0);
 		scrActions["extrasHyphenateText"]->setEnabled(true);
 		scrActions["extrasDeHyphenateText"]->setEnabled(true);
@@ -2937,6 +2940,7 @@
 		scrActions["editCut"]->setEnabled(true);
 		scrActions["editCopy"]->setEnabled(true);
 		scrActions["editClearContents"]->setEnabled(false);
+		scrActions["editTruncateContents"]->setEnabled(false);
 		scrActions["editSearchReplace"]->setEnabled(false);
 		scrActions["extrasHyphenateText"]->setEnabled(false);
 		scrActions["extrasDeHyphenateText"]->setEnabled(false);
@@ -3003,6 +3007,7 @@
 		scrActions["editCopy"]->setEnabled(true);
 		scrMenuMgr->setMenuEnabled("EditContents", false);
 		scrActions["editClearContents"]->setEnabled(false);
+		scrActions["editTruncateContents"]->setEnabled(false);
 		scrActions["editSearchReplace"]->setEnabled(false);
 
 		scrActions["extrasHyphenateText"]->setEnabled(false);
@@ -3195,6 +3200,7 @@
 			scrActions["itemSendToInline"]->setEnabled(true);
 			scrActions["editCut"]->setEnabled(false);
 			scrActions["editClearContents"]->setEnabled(false);
+			scrActions["editTruncateContents"]->setEnabled(false);
 			scrActions["toolsRotate"]->setEnabled(false);
 		}
 		else
@@ -6493,6 +6499,7 @@
 			zoomSpinBox->setFocusPolicy(Qt::ClickFocus);
 			pageSelector->setFocusPolicy(Qt::ClickFocus);
 			scrActions["editClearContents"]->setEnabled(false);
+			scrActions["editTruncateContents"]->setEnabled(false);
 			charPalette->setEnabled(false, 0);
 //			view->slotDoCurs(false);
 			if (currItem != 0)
@@ -6586,6 +6593,7 @@
 				scrActions["editCut"]->setEnabled(currItem->HasSel);
 				scrActions["editCopy"]->setEnabled(currItem->HasSel);
 				scrActions["editClearContents"]->setEnabled(currItem->HasSel);
+				scrActions["editTruncateContents"]->setEnabled(currItem->HasSel);
 				scrActions["editSearchReplace"]->setEnabled(true);
 
 				// Why the hell do you want to update the item here? - pm
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 19121)
+++ scribus/scribusdoc.cpp	(working copy)
@@ -11615,12 +11615,6 @@
 	uint selectedItemCount = itemSelection->count();
 	if (selectedItemCount <= 0)
 		return;
-	if (ScCore->usingGUI())
-	{
-		int t = QMessageBox::warning(m_ScMW, CommonStrings::trWarning, tr("Do you really want to clear the content of all selected frames?"),  QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
-		if (t == QMessageBox::No)
-			return;
-	}
 	for (uint i = 0; i < selectedItemCount; ++i)
 	{
 		PageItem *currItem = itemSelection->itemAt(i);
@@ -11635,6 +11629,23 @@
 	changed();
 }
 
+void ScribusDoc::itemSelection_TruncateItem(Selection* customSelection)
+{
+	Selection* itemSelection = (customSelection != 0) ? customSelection : m_Selection;
+	assert(itemSelection != 0);
+
+	uint selectedItemCount = itemSelection->count();
+	if (selectedItemCount <= 0)
+		return;
+	for (uint i = 0; i < selectedItemCount; ++i)
+	{
+		PageItem *currItem = itemSelection->itemAt(i);
+		currItem->truncateContents();
+	}
+	regionsChanged()->update(QRectF());
+	changed();
+}
+
 QList<PageItem*>* ScribusDoc::GroupOfItem(QList<PageItem*>* itemList, PageItem* item)
 {
 	if (itemList->contains(item))
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h	(revision 19121)
+++ scribus/scribusdoc.h	(working copy)
@@ -1446,6 +1446,7 @@
 	void item_setFrameShape(PageItem* item, int frameType, int count, double* points); 
 
 	void itemSelection_ClearItem(Selection* customSelection=0);
+	void itemSelection_TruncateItem(Selection* customSelection=0);
 	//! Delete the items in the current selection. When force is true, we do not warn the user and make SE happy too. Force is used from @sa Page::restorePageItemCreation
 	void itemSelection_DeleteItem(Selection* customSelection=0, bool forceDeletion=false);
 	void itemSelection_SetItemTextReversed(bool reversed, Selection* customSelection=0);
Index: scribus/ui/contextmenu.cpp
===================================================================
--- scribus/ui/contextmenu.cpp	(revision 19121)
+++ scribus/ui/contextmenu.cpp	(working copy)
@@ -473,6 +473,8 @@
 		if (currItem->asImageFrame() && m_actionList.contains("editPasteContentsAbs"))
 			menuEditContents->addAction(m_ScMW->scrActions["editPasteContentsAbs"]);
 	}
+	if (m_actionList.contains("editTruncateContents"))
+		menuEditContents->addAction(m_ScMW->scrActions["editTruncateContents"]);
 	if (m_actionList.contains("editClearContents"))
 		menuEditContents->addAction(m_ScMW->scrActions["editClearContents"]);
 	if (menuEditContents->actions().count()>0)
Index: scribus/undomanager.cpp
===================================================================
--- scribus/undomanager.cpp	(revision 19121)
+++ scribus/undomanager.cpp	(working copy)
@@ -1003,6 +1003,7 @@
 	UndoManager::AppendText         = tr("Append text");
 	UndoManager::ImportText         = tr("Import text");
 	UndoManager::ClearText          = tr("Clear text");
+	UndoManager::TruncateText       = tr("Truncate text");
 	UndoManager::AddLoremIpsum      = tr("Add Lorem Ipsum");
 	UndoManager::InsertMark         = tr("Insert mark");
 	UndoManager::InsertNote         = tr("Insert note");
@@ -1274,6 +1275,7 @@
 QString UndoManager::AppendText         = "";
 QString UndoManager::ImportText         = "";
 QString UndoManager::ClearText          = "";
+QString UndoManager::TruncateText       = "";
 QString UndoManager::ReplaceText        = "";
 QString UndoManager::InsertText         = "";
 QString UndoManager::AddLoremIpsum      = "";
Index: scribus/undomanager.h
===================================================================
--- scribus/undomanager.h	(revision 19121)
+++ scribus/undomanager.h	(working copy)
@@ -584,6 +584,7 @@
 	static QString AppendText;
 	static QString ImportText;
 	static QString ClearText;
+	static QString TruncateText;
 	static QString AddLoremIpsum;
 	static QString DeleteText;
 	static QString InsertText;
truncate.diff (14,229 bytes)

Issue History

Date Modified Username Field Change
2014-05-27 21:46 ale New Issue
2014-05-27 21:46 ale File Added: truncate.diff
2014-05-27 21:59 ale Summary truncate overflow and show number of overflowing white spaces => [PATCH] truncate overflow and show number of overflowing white spaces
2014-06-04 11:02 ale Relationship added related to 0011847
2014-06-07 11:37 cbradney Status new => resolved
2014-06-07 11:37 cbradney Fixed in Version => 1.5.0svn
2014-06-07 11:37 cbradney Resolution open => fixed
2014-06-07 11:37 cbradney Assigned To => cbradney
2014-06-14 06:39 cbradney Status resolved => closed
2015-09-17 20:08 Kunda Category Story Editor / Text Frames => Story Ed/Txt Frames
2015-09-17 20:12 Kunda Category Story Ed/Txt Frames => Story Editor / Text Frames