View Issue Details

IDProjectCategoryView StatusLast Update
0015554ScribusCanvaspublic2019-06-04 20:55
ReporterGibbz Assigned Tojghali  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.5.4 
Fixed in Version1.5.5.svn 
Summary0015554: Fix shift selection mode for multiple selection
DescriptionThis patch fixes the shift selection mode.
Previously this would only work in single object mode, but now it works with multiple selection mode.
Also added some extra comments to help with debugging.
TagsNo tags attached.
PatchYes

Activities

Gibbz

2019-01-25 05:15

reporter  

shift_select.patch (10,827 bytes)   
diff --git a/scribus/canvasmode_normal.cpp b/scribus/canvasmode_normal.cpp
index 8eabfd951..5cbd2b5be 100644
--- a/scribus/canvasmode_normal.cpp
+++ b/scribus/canvasmode_normal.cpp
@@ -295,7 +295,7 @@ void CanvasMode_Normal::mouseDoubleClickEvent(QMouseEvent *m)
 
 void CanvasMode_Normal::mouseMoveEvent(QMouseEvent *m)
 {
-// 	qDebug()<<"CanvasMode_Normal::mouseMoveEvent";
+//	qDebug()<<"CanvasMode_Normal::mouseMoveEvent";
 // 	const double mouseX = m->globalX();
 // 	const double mouseY = m->globalY();
 	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
@@ -361,6 +361,7 @@ void CanvasMode_Normal::mouseMoveEvent(QMouseEvent *m)
 		if ((m_view->cursor().shape() == Qt::SplitHCursor) || (m_view->cursor().shape() == Qt::SplitVCursor))
 			m_view->setCursor(QCursor(Qt::ArrowCursor));
 	}
+
 	//<<#10116 Show overflow counter HUD
 	if (!movingOrResizing && mouseIsOnPage)
 	{
@@ -450,6 +451,7 @@ void CanvasMode_Normal::mouseMoveEvent(QMouseEvent *m)
 			}
 		}
 	}
+
 	//>>#10116
 	if (m_doc->drawAsPreview)
 		return;
@@ -499,6 +501,7 @@ void CanvasMode_Normal::mouseMoveEvent(QMouseEvent *m)
 		}
 		if (m_doc->DragP)
 			return;
+
 		//Operations run here:
 		//Item resize, esp after creating a new one
 		if (m_view->moveTimerElapsed() && m_canvas->m_viewMode.m_MouseButtonPressed && (m->buttons() & Qt::LeftButton) && 
@@ -725,6 +728,8 @@ void CanvasMode_Normal::mouseMoveEvent(QMouseEvent *m)
 				}
 			}
 		}
+
+		// move page item
 		if ((!m_canvas->m_viewMode.m_MouseButtonPressed) && (m_doc->appMode != modeDrawBezierLine))
 		{
 			if (m_doc->m_Selection->isMultipleSelection())
@@ -880,59 +885,32 @@ void CanvasMode_Normal::mousePressEvent(QMouseEvent *m)
 		else
 			m_view->setCursor(QCursor(Qt::ArrowCursor));
 #if 1				
-		if (m_doc->m_Selection->isMultipleSelection() && (!m_doc->drawAsPreview))
+		// normal edit mode mode
+		m_canvas->PaintSizeRect(QRect());
+		double gx, gy, gh, gw;
+		bool shiftSel = true;
+		m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
+		m_dragConstrainInitPtX = qRound(gx);
+		m_dragConstrainInitPtY = qRound(gy);
+		m_frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), QRectF(gx, gy, gw, gh));
+		if (m_frameResizeHandle == Canvas::OUTSIDE ||
+			(m_frameResizeHandle == Canvas::INSIDE && m->modifiers() != Qt::NoModifier))
 		{
-			m_canvas->PaintSizeRect(QRect());
-			double gx, gy, gh, gw;
-			bool shiftSel = true;
-			m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
-			m_dragConstrainInitPtX = qRound(gx);
-			m_dragConstrainInitPtY = qRound(gy);
-			m_frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), QRectF(gx, gy, gw, gh));
-			if (m_frameResizeHandle == Canvas::OUTSIDE ||
-				(m_frameResizeHandle == Canvas::INSIDE && m->modifiers() != Qt::NoModifier))
-			{
-				m_frameResizeHandle = 0;
-				m_doc->m_Selection->delaySignalsOn();
-				m_view->updatesOn(false);
-				shiftSel = SeleItem(m);
-				m_view->updatesOn(true);
-				m_doc->m_Selection->delaySignalsOff();
-			}
-			if (((m_doc->m_Selection->count() == 0) || (!shiftSel)) && (m->modifiers() == Qt::ShiftModifier))
-			{
-				m_shiftSelItems = true;
-				m_mouseCurrentPoint = m_mousePressPoint = m_mouseSavedPoint = mousePointDoc;
-			}
-			else
-				m_shiftSelItems = false;
-			m_canvas->setRenderModeFillBuffer();
+			m_frameResizeHandle = 0;
+			m_doc->m_Selection->delaySignalsOn();
+			m_view->updatesOn(false);
+			shiftSel = SeleItem(m);
+			m_view->updatesOn(true);
+			m_doc->m_Selection->delaySignalsOff();
 		}
-		else // not multiple selection
+		if (((m_doc->m_Selection->count() == 0) || (!shiftSel)) && (m->modifiers() == Qt::ShiftModifier))
 		{
-			m_dragConstrainInitPtX = qRound(currItem->xPos());
-			m_dragConstrainInitPtY = qRound(currItem->yPos());
-			
-			// don't call SeleItem() without need here:
-			m_frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem);
-			//#6797
-			if (m_frameResizeHandle <= 0 || m->modifiers() != Qt::NoModifier)
-			{
-				m_doc->m_Selection->delaySignalsOn();
-				m_view->updatesOn(false);
-				SeleItem(m); //Where we send the mouse press event to select an item
-				if (GetItem(&currItem) && (!m_doc->drawAsPreview))
-					m_frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem);
-				else
-					m_frameResizeHandle = 0;
-				m_view->updatesOn(true);
-				m_doc->m_Selection->delaySignalsOff();
-			}
-			if (!(currItem && !currItem->locked() && m_frameResizeHandle > 0) && (!m_doc->drawAsPreview))
-			{
-				m_mouseCurrentPoint = m_mousePressPoint = m_mouseSavedPoint = mousePointDoc;
-			}
+			m_shiftSelItems = true;
+			m_mouseCurrentPoint = m_mousePressPoint = m_mouseSavedPoint = mousePointDoc;
 		}
+		else
+			m_shiftSelItems = false;
+
 		m_canvas->setRenderModeFillBuffer();
 #endif
 	}
@@ -989,7 +967,6 @@ void CanvasMode_Normal::mousePressEvent(QMouseEvent *m)
 }
 
 
-
 void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 {
 //	qDebug("CanvasMode_Normal::mouseReleaseEvent");
@@ -1004,6 +981,9 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 	m_view->setRedrawMarkerShown(false);
 //	m_view->stopDragTimer();
 	//m_canvas->update(); //ugly in a mouseReleaseEvent!!!!!!!
+
+	// right click
+	// opens context menu
 	if (m->button() == Qt::RightButton && (!m_doc->DragP) )
 	{
 		if ((!GetItem(&currItem)) && (!m_doc->drawAsPreview))
@@ -1017,6 +997,8 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 			return;
 		}
 	}
+
+	// link text frames
 	//<<#10116: Click on overflow icon to get into link frame mode
 	PageItem* clickedItem=nullptr;
 	clickedItem = m_canvas->itemUnderCursor(m->globalPos(), clickedItem, m->modifiers());
@@ -1031,6 +1013,8 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 			}
 		}
 	}
+
+	// drag move?
 	//>>#10116
 	if (m_view->moveTimerElapsed() && (GetItem(&currItem)))
 	{
@@ -1142,13 +1126,18 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 			m_doc->changed();
 		}
 	}
+
+
 	//CB Drag selection performed here
 	if (((m_doc->m_Selection->count() == 0) && (m_view->HaveSelRect) && (!m_view->MidButt)) || ((m_shiftSelItems) && (m_view->HaveSelRect) && (!m_view->MidButt)))
 	{
+		// get newly selection rectangle
 		double dx = m_mouseSavedPoint.x() - m_mousePressPoint.x();
 		double dy = m_mouseSavedPoint.y() - m_mousePressPoint.y();
 		QRectF canvasSele = QRectF(m_mousePressPoint.x(), m_mousePressPoint.y(), dx, dy).normalized();
 		QRectF localSele  = m_canvas->canvasToLocal(canvasSele).normalized();
+
+		// not in master page node
 		if (!m_doc->masterPageMode())
 		{
 			uint docPagesCount=m_doc->Pages->count();
@@ -1169,27 +1158,51 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 			}
 			m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
 		}
+
+		// if document is not empty
 		int docItemCount=m_doc->Items->count();
 		if (docItemCount != 0)
 		{
 			m_doc->m_Selection->delaySignalsOn();
-			// loop over all items and select
+
+			// modifier keys
 			bool altPressed = m->modifiers() & Qt::AltModifier;
 			bool shiftPressed = m->modifiers() & Qt::ShiftModifier;
+			/*
+			// if shift key is pressed, we want to remove these objects from the list
+			Selection previous_selection(this, false);
+			previous_selection.copy(*m_doc->m_Selection, true);
+			*/
 
+			// loop each item in document
 			for (int a = 0; a < docItemCount; ++a)
 			{
 				PageItem* docItem = m_doc->Items->at(a);
 				if ((m_doc->masterPageMode()) && (docItem->OnMasterPage != m_doc->currentPage()->pageName()))
 					continue;
-				QRect  apr2 = m_canvas->canvasToLocal( docItem->getCurrentBoundingRect(docItem->lineWidth()) );
+
+				// check layer is active, selectable, not locked
 				if (((docItem->LayerID == m_doc->activeLayer()) || (m_doc->layerSelectable(docItem->LayerID))) && (!m_doc->layerLocked(docItem->LayerID)))
 				{
+					// get current item rect/bounding box
+					QRect apr2 = m_canvas->canvasToLocal( docItem->getCurrentBoundingRect(docItem->lineWidth()) );
+
+					bool is_selected = docItem->isSelected();
 					bool redrawSelection = false;
+
+					// alt selection
 					bool select = altPressed ? localSele.intersects(apr2) :
                                                localSele.contains(apr2);
-					if (select)
-						m_view->SelectItemNr(a, redrawSelection);
+
+					// make selection
+					if (!is_selected && select)
+						//docItem->setSelected(true);
+						m_doc->m_Selection->addItem(docItem);
+						//m_view->SelectItemNr(a, redrawSelection);
+					else if (is_selected && shiftPressed && select) // shift selection - invert selection
+						m_doc->m_Selection->removeItem(docItem);
+						//docItem->setSelected(false);
+						//m_view->Deselect(docItem);
 				}
 			}
 			m_doc->m_Selection->delaySignalsOff();
@@ -1203,9 +1216,11 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 		}
 		m_view->HaveSelRect = false;
 		m_shiftSelItems = false;
-//		m_view->redrawMarker->hide();
+		//m_view->redrawMarker->hide();
 		m_view->updateContents();
 	}
+
+	// ??
 	if (m_doc->appMode != modeEdit)
 	{
 		if (!PrefsManager::instance()->appPrefs.uiPrefs.stickyTools)
@@ -1216,6 +1231,8 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 			m_view->requestMode(appMode);
 		}
 	}
+
+	// ??
 	if (GetItem(&currItem))
 	{
 		if (m_doc->m_Selection->count() > 1)
@@ -1232,6 +1249,7 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 	}
 	else
 		m_view->Deselect(true);
+
 	xSnap = ySnap = 0;
 	m_canvas->setRenderModeUseBuffer(false);
 	m_doc->DragP = false;
@@ -1248,6 +1266,7 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 	}
 	for (int i = 0; i < m_doc->m_Selection->count(); ++i)
 		m_doc->m_Selection->itemAt(i)->checkChanges(true);
+
 	//Commit drag created items to undo manager.
 	if (m_doc->m_Selection->count() > 0)
 	{
@@ -1256,6 +1275,7 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 			m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0));
 		}
 	}
+
 	//Make sure the Zoom spinbox and page selector don't have focus if we click on the canvas
 	m_view->m_ScMW->zoomSpinBox->clearFocus();
 	m_view->m_ScMW->pageSelector->clearFocus();
@@ -1267,6 +1287,8 @@ void CanvasMode_Normal::mouseReleaseEvent(QMouseEvent *m)
 			m_doc->nodeEdit.finishTransaction(currItem);
 		}
 	}
+
+	// anotation
 	if (m_doc->drawAsPreview && !m_doc->editOnPreview)
 	{
 		if (m_doc->m_Selection->count() == 1)
shift_select.patch (10,827 bytes)   

jghali

2019-01-25 09:32

administrator   ~0045858

What does this patch fix exactly?

Gibbz

2019-01-29 01:41

reporter   ~0045870

Currently, scribus shift select with a single click (no drag selection) will invert the currently clicked object.
This patch extends that behavior to work with click and drag to be consistent and more useful.

jghali

2019-01-29 05:19

administrator   ~0045871

OK, thanks.

jghali

2019-02-03 01:30

administrator   ~0045881

Applied!

Issue History

Date Modified Username Field Change
2019-01-25 05:15 Gibbz New Issue
2019-01-25 05:15 Gibbz File Added: shift_select.patch
2019-01-25 09:32 jghali Note Added: 0045858
2019-01-29 01:41 Gibbz Note Added: 0045870
2019-01-29 05:19 jghali Note Added: 0045871
2019-02-03 01:29 jghali Summary [Patch] Fix shift selection mode => Fix shift selection mode for multiple selection
2019-02-03 01:30 jghali Assigned To => jghali
2019-02-03 01:30 jghali Status new => resolved
2019-02-03 01:30 jghali Resolution open => fixed
2019-02-03 01:30 jghali Fixed in Version => 1.5.5.svn
2019-02-03 01:30 jghali Note Added: 0045881
2019-06-04 20:55 cbradney Status resolved => closed