r17595 by craig - #9156: Add first part of patch to add adjust frame height to nearest text height/descender

scribus-commit scribus-commit at lists.scribus.net
Tue Jun 19 19:26:00 UTC 2012


Author: craig
Date: Tue Jun 19 19:25:59 2012
New Revision: 17595

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17595
Log:
#9156: Add first part of patch to add adjust frame height to nearest text height/descender

Modified:
    trunk/Scribus/scribus/actionmanager.cpp
    trunk/Scribus/scribus/canvasmode_normal.cpp
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem.h
    trunk/Scribus/scribus/pageitem_textframe.cpp
    trunk/Scribus/scribus/pageitem_textframe.h
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/ui/contextmenu.cpp

Modified: trunk/Scribus/scribus/actionmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/actionmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/actionmanager.cpp (original)
+++ trunk/Scribus/scribus/actionmanager.cpp Tue Jun 19 19:25:59 2012
@@ -448,6 +448,8 @@
 	name="tableDistributeColumnsEvenly";
 	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
 	name="tableAdjustFrameToTable";
+	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
+	name="itemAdjustFrameHeightToText";
 	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
 	name = "tableAdjustTableToFrame";
 	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
@@ -1107,6 +1109,7 @@
 	disconnect( (*scrActions)["tableDistributeColumnsEvenly"], 0, 0, 0 );
 	disconnect( (*scrActions)["tableAdjustFrameToTable"], 0, 0, 0 );
 	disconnect( (*scrActions)["tableAdjustTableToFrame"], 0, 0, 0 );
+	disconnect( (*scrActions)["itemAdjustFrameHeightToText"], 0, 0, 0 );
 	disconnect( (*scrActions)["itemAdjustFrameToImage"], 0, 0, 0 );
 	disconnect( (*scrActions)["itemAdjustImageToFrame"], 0, 0, 0 );
 	disconnect( (*scrActions)["itemLock"], 0, 0, 0);
@@ -1129,7 +1132,6 @@
 	disconnect( (*scrActions)["itemRaise"], 0, 0, 0);
 	disconnect( (*scrActions)["toolsUnlinkTextFrameWithTextCopy"], 0, 0, 0 );
 	disconnect( (*scrActions)["toolsUnlinkTextFrameWithTextCut"], 0, 0, 0 );
-
 }
 
 void ActionManager::connectNewDocActions(ScribusDoc *currDoc)
@@ -1159,6 +1161,7 @@
 	connect( (*scrActions)["tableDistributeColumnsEvenly"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_DistributeTableColumnsEvenly()));
 	connect( (*scrActions)["tableAdjustFrameToTable"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustFrameToTable()));
 	connect( (*scrActions)["tableAdjustTableToFrame"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustTableToFrame()));
+	connect( (*scrActions)["itemAdjustFrameHeightToText"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustFrameHeightToText()) );
 	connect( (*scrActions)["itemAdjustFrameToImage"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustFrametoImageSize()) );
 	connect( (*scrActions)["itemAdjustImageToFrame"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustImagetoFrameSize()) );
 	connect( (*scrActions)["itemsUnWeld"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_UnWeld()) );
@@ -1464,6 +1467,7 @@
 	(*scrActions)["tableDistributeColumnsEvenly"]->setTexts(tr("Distribute Columns Evenly"));
 	(*scrActions)["tableAdjustFrameToTable"]->setTexts(tr("Adjust Frame to Table"));
 	(*scrActions)["tableAdjustTableToFrame"]->setTexts(tr("Adjust Table to Frame"));
+	(*scrActions)["itemAdjustFrameHeightToText"]->setTexts( tr("Adjust Frame Height to Text"));
 	(*scrActions)["itemAdjustFrameToImage"]->setTexts( tr("Adjust Frame to Image"));
 	(*scrActions)["itemAdjustImageToFrame"]->setTexts( tr("Adjust Image to Frame"));
 	(*scrActions)["itemToggleInlineImage"]->setTexts( tr("Embed Image"));
@@ -1940,6 +1944,7 @@
 		<< "tableDistributeColumnsEvenly"
 		<< "tableAdjustFrameToTable"
 		<< "tableAdjustTableToFrame"
+		<< "itemAdjustFrameHeightToText"
 		<< "itemAdjustFrameToImage" 
 		<< "itemAdjustImageToFrame" 
 		<< "itemToggleInlineImage" 

Modified: trunk/Scribus/scribus/canvasmode_normal.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/canvasmode_normal.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_normal.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_normal.cpp Tue Jun 19 19:25:59 2012
@@ -223,6 +223,9 @@
 		}
 		else if (currItem->itemType() == PageItem::TextFrame)
 		{
+			// See if double click was on a frame handle
+			FPoint p = m_canvas->globalToCanvas(m->globalPos());
+			Canvas::FrameHandle fh = m_canvas->frameHitTest(QPointF(p.x(),p.y()), currItem);
 			//CB old code
 			//emit currItem->isAnnotation() ? AnnotProps() : Amode(modeEdit);
 			//mousePressEvent(m);
@@ -233,6 +236,8 @@
 				m_view->requestMode(submodeAnnotProps);
 				//mousePressEvent(m);
 			}
+			else if (fh == Canvas::SOUTH)
+				currItem->asTextFrame()->setTextFrameHeight();
 			//else if not in mode edit, set mode edit
 			else if (m_doc->appMode != modeEdit)
 			{

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Tue Jun 19 19:25:59 2012
@@ -7470,3 +7470,4 @@
 	}
 	weldList.clear();
 }
+

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h (original)
+++ trunk/Scribus/scribus/pageitem.h Tue Jun 19 19:25:59 2012
@@ -1574,8 +1574,8 @@
 	//void textToFrameDistances(double, double, double, double); //left, top, bottom, right: Extra, TExtra, BExtra, RExtra
 	//FIXME: columns, grid ?
 	
+public:
 	//items welding (item follows while item moves which they are connected with)
-public:
 	struct weldingInfo
 	{
 		PageItem *weldItem;

Modified: trunk/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp Tue Jun 19 19:25:59 2012
@@ -1427,6 +1427,7 @@
 		current.mustLineEnd = current.colRight;
 		current.restartX = 0;
 		int lastStat = 0, curStat = 0;
+		setMaxY(-1);
 
 		for (int a = firstInFrame(); a < itemText.length(); ++a)
 		{
@@ -1823,7 +1824,7 @@
 				}
 			}
 			current.recalculateY = true;
-			int maxYAsc = 0, maxYDesc = 0;
+			double maxYAsc = 0.0, maxYDesc = 0.0;
 			if (current.startOfCol)
 			{
 				//qMax is used for glyphs shifted or vertically scalled above ascent or below descent
@@ -1835,13 +1836,13 @@
 					else if (firstLineOffset() == FLOPLineSpacing)
 						addAsce = style.lineSpacing();
 				}
-				maxYAsc = static_cast<int>(floor(current.yPos - addAsce));
+				maxYAsc = current.yPos - addAsce;
 			}
 			else
-				maxYAsc = static_cast<int>(floor(current.yPos - qMax(realAsce, asce)));
+				maxYAsc = current.yPos - qMax(realAsce, asce);
 			//fix for glyphs with negative realAsce value
-			maxYAsc = qMax(maxYAsc, 0);
-			maxYDesc = static_cast<int>(ceil(current.yPos + qMax(realDesc, desc)));
+			maxYAsc = qMax(maxYAsc, 0.0);
+			maxYDesc = current.yPos + qMax(realDesc, desc);
 
 			if (current.itemsInLine == 0 && !current.afterOverflow)
 			{
@@ -1849,8 +1850,8 @@
 				goNoRoom = false;
 
 				// find line`s start
-				pt1 = QPoint(static_cast<int>(floor(current.xPos)), maxYAsc);
-				pt2 = QPoint(static_cast<int>(ceil(current.xPos + (style.minGlyphExtension() * wide))),maxYDesc);
+				pt1 = QPoint(static_cast<int>(floor(current.xPos)), static_cast<int>(floor(maxYAsc)));
+				pt2 = QPoint(static_cast<int>(ceil(current.xPos + (style.minGlyphExtension() * wide))), static_cast<int>(ceil(maxYDesc)));
 				pt = QRect(pt1, pt2);
 				realEnd = 0;
 				//check if there is overflow at start of line, if so jump behind it and check again
@@ -1877,7 +1878,7 @@
 					//check if in indent any overflow occurs
 					while (Xpos <= Xend && Xpos < current.colRight)
 					{
-						pt.moveTopLeft(QPoint(static_cast<int>(floor(Xpos)),maxYAsc));
+						pt.moveTopLeft(QPoint(static_cast<int>(floor(Xpos)), static_cast<int>(floor(maxYAsc))));
 						if (!regionContainsRect(m_availableRegion, pt))
 						{
 							Xpos = current.xPos = realEnd = findRealOverflowEnd(m_availableRegion, pt, current.colRight);
@@ -1909,7 +1910,7 @@
 							current.yPos += (current.startOfCol ? 1 : style.lineSpacing());
 						else
 							current.yPos++;
-						lastLineY = maxYAsc +1;
+						lastLineY = maxYAsc;
 						if (current.startOfCol)
 						{
 							//qMax is used for glyphs shifted or vertically scalled above ascent or below descent
@@ -1921,13 +1922,13 @@
 								else if (firstLineOffset() == FLOPLineSpacing)
 									addAsce = style.lineSpacing();
 							}
-							maxYAsc = static_cast<int>(floor(current.yPos - addAsce));
+							maxYAsc = current.yPos - addAsce;
 						}
 						else
-							maxYAsc = static_cast<int>(floor(current.yPos - qMax(realAsce, asce)));
-						maxYDesc = static_cast<int>(ceil(current.yPos + qMax(realDesc, desc)));
-
-						pt.moveTopLeft(QPoint(static_cast<int>(floor(current.xPos)),maxYAsc));
+							maxYAsc = current.yPos - qMax(realAsce, asce);
+						maxYDesc = current.yPos + qMax(realDesc, desc);
+
+						pt.moveTopLeft(QPoint(static_cast<int>(floor(current.xPos)), static_cast<int>(floor(maxYAsc))));
 						done = false;
 					}
 					if (current.isEndOfCol(realDesc))
@@ -2220,24 +2221,24 @@
 				{
 					if (hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN)
 					{
-						pt1 = QPoint(charStart, maxYAsc);
-						pt2 = QPoint(static_cast<int>(charEnd + hyphWidth), maxYDesc);
+						pt1 = QPoint(charStart,  static_cast<int>(floor(maxYAsc)));
+						pt2 = QPoint(static_cast<int>(charEnd + hyphWidth), static_cast<int>(ceil(maxYDesc)));
 					}
 					else
 					{
-						pt1 = QPoint(charStart, maxYAsc);
-						pt2 = QPoint(charEnd, maxYDesc);
+						pt1 = QPoint(charStart, static_cast<int>(floor(maxYAsc)));
+						pt2 = QPoint(charEnd, static_cast<int>(ceil(maxYDesc)));
 					}
 				}
 				else if (!legacy && SpecialChars::isBreakingSpace(hl->ch))
 				{
-					pt1 = QPoint(static_cast<int>(qMax(floor(breakPos - current.maxShrink - (style.minGlyphExtension() * wide)),0.0)), maxYAsc);
-					pt2 = QPoint(charEnd, maxYDesc);
+					pt1 = QPoint(static_cast<int>(qMax(floor(breakPos - current.maxShrink - (style.minGlyphExtension() * wide)),0.0)), static_cast<int>(floor(maxYAsc)));
+					pt2 = QPoint(charEnd, static_cast<int>(ceil(maxYDesc)));
 				}
 				else
 				{
-					pt1 = QPoint(charStart, maxYAsc);
-					pt2 = QPoint(charEnd, maxYDesc);
+					pt1 = QPoint(charStart, static_cast<int>(floor(maxYAsc)));
+					pt2 = QPoint(charEnd, static_cast<int>(ceil(maxYDesc)));
 				}
 				pt = QRect(pt1, pt2);
 				if (!regionContainsRect(m_availableRegion, pt))
@@ -2323,6 +2324,8 @@
 					else
 						inOverflow = true;
 				}
+				else
+					setMaxY(maxYDesc);
 			}
 
 			// hyphenation
@@ -2399,7 +2402,7 @@
 				{
 					// find end of line
 					current.breakLine(itemText, style, firstLineOffset(), a);
-					EndX = current.endOfLine(m_availableRegion, style.rightMargin(), maxYAsc, maxYDesc);
+					EndX = current.endOfLine(m_availableRegion, style.rightMargin(), static_cast<int>(floor(maxYAsc)), static_cast<int>(ceil(maxYDesc)));
 					current.finishLine(EndX);
 					//addLine = true;
 					assert(current.addLine);
@@ -2476,7 +2479,7 @@
 						current.updateHeightMetrics(itemText);
 						//current.updateLineOffset(itemText, style, firstLineOffset());
 						//current.xPos = current.breakXPos;
-						EndX = current.endOfLine(m_availableRegion, current.rightMargin, maxYAsc, maxYDesc);
+						EndX = current.endOfLine(m_availableRegion, current.rightMargin, static_cast<int>(floor(maxYAsc)), static_cast<int>(ceil(maxYDesc)));
 						current.finishLine(EndX);
 						
 						hyphWidth = 0.0;
@@ -2549,7 +2552,11 @@
 						}
 						goNextColumn = true;
 					}
-				}
+					else
+						setMaxY(maxYDesc);
+				}
+				else
+					setMaxY(maxYDesc);
 				if (current.line.firstItem <= current.line.lastItem && current.itemsInLine > 0)
 				{
 					if (current.addLine && current.breakIndex >= 0)
@@ -2563,6 +2570,7 @@
 						fillInTabLeaders(itemText, current.line);
 						//if right margin is set we temporally save line, not append it
 						itemText.appendLine(current.line);
+						setMaxY(maxYDesc);
 						current.restartIndex = current.line.lastItem +1;
 						a = current.restartIndex -1;
 						current.rowDesc = qMax(current.rowDesc,current.yPos + current.line.descent);
@@ -2606,7 +2614,6 @@
 							maxDX = 0;
 						}
 					}
-					lastLineY = current.rowDesc;
 					current.mustLineEnd = current.colRight;
 					current.restartRowIndex = current.restartIndex;
 				}
@@ -2749,6 +2756,7 @@
 			goNextColumn = false;
 
 			itemText.appendLine(current.line);
+			setMaxY(maxYDesc);
 			current.startOfCol = false;
 
 			if (moveLinesFromPreviousFrame ()) {
@@ -4202,7 +4210,10 @@
 	}
 	actionList << "itemConvertToOutlines";
 	if (itemText.lines() != 0)
+	{
 		actionList << "editClearContents";
+		actionList << "itemAdjustFrameHeightToText";
+	}
 }
 
 QString PageItem_TextFrame::infoDescription()
@@ -4214,3 +4225,20 @@
 {
 	invalidateLayout();
 }
+
+void PageItem_TextFrame::setMaxY(double y)
+{
+	if (y == -1)
+		maxY = 0;
+	else
+		maxY = qMax(y, maxY);
+}
+
+void PageItem_TextFrame::setTextFrameHeight()
+{
+	setHeight(ceil(maxY) + BExtra + 0.5);
+	updateClip();
+	invalid = true;
+	m_Doc->changed();
+	m_Doc->regionsChanged()->update(QRect());
+}

Modified: trunk/Scribus/scribus/pageitem_textframe.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/pageitem_textframe.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.h (original)
+++ trunk/Scribus/scribus/pageitem_textframe.h Tue Jun 19 19:25:59 2012
@@ -116,6 +116,13 @@
 	QMap<QString,StoryText> shadows;
 	bool checkKeyIsShortcut(QKeyEvent *k);
 	
+	// set text frame height to last line of text
+	double maxY;
+	void setMaxY(double y);
+
+public:
+	void setTextFrameHeight();
+
 private slots:
 	void slotInvalidateLayout();
 };

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Tue Jun 19 19:25:59 2012
@@ -799,6 +799,7 @@
 	scrMenuMgr->addMenuSeparator("Item");
 	// End Table submenu.
 	scrMenuMgr->addMenuSeparator("Item");
+	scrMenuMgr->addMenuItem(scrActions["itemAdjustFrameHeightToText"], "Item", false);
 	scrMenuMgr->addMenuItem(scrActions["itemAdjustFrameToImage"], "Item", false);
 	scrMenuMgr->addMenuItem(scrActions["itemAdjustImageToFrame"], "Item", false);
 	scrMenuMgr->addMenuItem(scrActions["itemUpdateImage"], "Item", false);
@@ -2644,6 +2645,7 @@
 #else
 	scrActions["editEditRenderSource"]->setEnabled(SelectedType==PageItem::ImageFrame && currItem && (currItem->asLatexFrame()));
 #endif
+	scrActions["itemAdjustFrameHeightToText"]->setEnabled(SelectedType==PageItem::TextFrame && currItem->itemText.length() >0);
 	if (SelectedType!=PageItem::ImageFrame)
 	{
 		scrActions["itemImageIsVisible"]->setChecked(false);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Tue Jun 19 19:25:59 2012
@@ -14389,6 +14389,31 @@
 	}
 }
 
+void ScribusDoc::itemSelection_AdjustFrameHeightToText( Selection *customSelection)
+{
+	Selection* itemSelection = (customSelection!=0) ? customSelection : m_Selection;
+	assert(itemSelection!=0);
+	uint selectedItemCount=itemSelection->count();
+	if (selectedItemCount == 0)
+		return;
+	
+	if (selectedItemCount > 0)
+	{
+		for (uint i = 0; i < selectedItemCount; ++i)
+		{
+			PageItem *currItem = itemSelection->itemAt(i);
+			if (currItem!=NULL)
+			{
+				if (currItem->asTextFrame() && (currItem->itemText.length() > 0) && !currItem->isTableItem)
+					currItem ->asTextFrame()->setTextFrameHeight();
+			}
+		}
+		regionsChanged()->update(QRectF());
+		changed();
+		itemSelection->itemAt(0)->emitAllToGUI();
+	}
+}
+
 void ScribusDoc::itemSelection_AdjustFrameToTable()
 {
 	// TODO: Do this in an undo transaction?

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Tue Jun 19 19:25:59 2012
@@ -1452,6 +1452,7 @@
 	 * Adjust an image size to fit the size of the frame
 	 */
 	void itemSelection_AdjustImagetoFrameSize(Selection* customSelection=0);
+	void itemSelection_AdjustFrameHeightToText( Selection *customSelection=0);
 	//! @brief startArrowID or endArrowID of -1 mean not applying a selection at this point.
 	void itemSelection_ApplyArrowHead(int startArrowID=-1, int endArrowID=-1, Selection* customSelection=0);
 	void itemSelection_ApplyArrowScale(int startArrowSc, int endArrowSc, Selection* customSelection);

Modified: trunk/Scribus/scribus/ui/contextmenu.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17595&path=/trunk/Scribus/scribus/ui/contextmenu.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/contextmenu.cpp (original)
+++ trunk/Scribus/scribus/ui/contextmenu.cpp Tue Jun 19 19:25:59 2012
@@ -216,7 +216,8 @@
 			addAction(m_AP->scrActions["tableAdjustFrameToTable"]);
 		if (m_actionList.contains("tableAdjustTableToFrame"))
 			addAction(m_AP->scrActions["tableAdjustTableToFrame"]);
-
+		if (m_actionList.contains("itemAdjustFrameHeightToText"))
+			addAction(m_AP->scrActions["itemAdjustFrameHeightToText"]);
 		if (m_actionList.contains("itemExtendedImageProperties"))
 			addAction(m_AP->scrActions["itemExtendedImageProperties"]);
 		if (m_actionList.contains("itemAdjustFrameToImage"))
@@ -270,6 +271,11 @@
 			}
 		}
 		
+		if ((selectedItemCount==1) && currItem->asTextFrame())
+		{
+			if (currItem->itemText.length() > 0)
+				m_AP->scrActions["itemAdjustFrameHeightToText"]->setEnabled(true);
+		}
 	}
 	//-->
 	




More information about the scribus-commit mailing list