On Monday 09 June 2003 08:53 am, Guillaume Laurent wrote:

> - how's the selection rectangle displayed ? I'm guessing a QCanvasRectangle
> with a specific QPen/QBrush ?

It's very similar to the way the current selection guides work.  Right now the 
only difference is in the QBrush (its a Qt::Dense7Pattern).  Im not sure I 
like how that is working and have yet to try Qt::NoBrush. So, basically what 
I call m_multiGuide is only displayed when you have multiple selections and 
select the move tool.  That is what yo usee in the screen shots.  I thought 
about how the current guides work with single selections and decided it would 
not be appropriate for multiple selections across multiple tracks.

> - how do you select/unselect which segments to move ?

This should be the same way as before, since the guide should disappear the 
same way the current guides do.  So, simply use the normal way of selecting 
segments and select the Move tool again and begin your move and the 
m_multiGuide should appear. Although this is not what it does now -- its 
very, very rough and I just wanted to see if i could get the basic idea 
working.

I am pretty confident implementing it completely shouldn't be too terribly 
difficult.

See the attached patch for the stuff I have added.

-- 
Levi Burton
http://www.puresimplicity.net/~ldb/
Index: segmenttool.cpp
===================================================================
RCS file: /cvsroot/rosegarden/gui/segmenttool.cpp,v
retrieving revision 1.26
diff -u -w -r1.26 segmenttool.cpp
--- segmenttool.cpp	7 Jun 2003 22:48:53 -0000	1.26
+++ segmenttool.cpp	9 Jun 2003 14:03:00 -0000
@@ -41,6 +41,7 @@
 using Rosegarden::SnapGrid;
 using Rosegarden::Note;
 using Rosegarden::SegmentSelection;
+using Rosegarden::Segment;
 
 //////////////////////////////////////////////////////////////////////
 //                 Segment Tools
@@ -359,7 +360,8 @@
 SegmentMover::SegmentMover(SegmentCanvas *c, RosegardenGUIDoc *d)
     : SegmentTool(c, d),
     m_foreGuide(new QCanvasRectangle(m_canvas->canvas())),
-    m_topGuide(new QCanvasRectangle(m_canvas->canvas()))
+      m_topGuide(new QCanvasRectangle(m_canvas->canvas())),
+      m_multiGuide(new QCanvasRectangle(m_canvas->canvas()))
 {
     m_foreGuide->setPen(RosegardenGUIColours::MovementGuide);
     m_foreGuide->setBrush(RosegardenGUIColours::MovementGuide);
@@ -369,6 +371,10 @@
     m_topGuide->setBrush(RosegardenGUIColours::MovementGuide);
     m_topGuide->hide();
 
+    m_multiGuide->setPen(RosegardenGUIColours::MovementGuide);
+    m_multiGuide->setBrush(Qt::Dense7Pattern);
+    m_multiGuide->hide();
+
     RG_DEBUG << "SegmentMover()\n";
 }
 
@@ -382,6 +388,64 @@
     SegmentItem *item = m_canvas->findSegmentClickedOn(e->pos());
 
     if (item) {
+        SegmentSelector* selector = 
+            dynamic_cast<SegmentSelector*>
+            (getToolBox()->getTool(SegmentSelector::ToolName));
+
+        SegmentSelection selection = selector->getSelectedSegments();
+
+        if (selection.size() > 1) {
+            Segment *segment1, *segment2, *segment3, *segment4;
+            timeT earliestTime = 0, latestTime = 0;
+            TrackId lowTrack = 0, highTrack = 0;
+
+            for (SegmentSelection::iterator it = selection.begin();
+                 it != selection.end(); it++) {
+                
+                if (it == selection.begin() || 
+                    (*it)->getStartTime() < earliestTime) {
+                    earliestTime = (*it)->getStartTime();
+                    segment1 = dynamic_cast<Segment*>(*it);
+                }
+
+                if ((*it)->getEndTime() > latestTime) {
+                    latestTime = (*it)->getEndMarkerTime();
+                    segment2 = dynamic_cast<Segment*>(*it);
+                }
+
+                if (it == selection.begin() || 
+                    (*it)->getTrack() < lowTrack) {
+                    lowTrack = (*it)->getTrack();
+                    segment3 = dynamic_cast<Segment*>(*it);
+                }
+
+                if (it == selection.begin() || 
+                    (*it)->getTrack() > highTrack) {
+                    highTrack = (*it)->getTrack();
+                    segment4 = dynamic_cast<Segment*>(*it);                
+                }
+
+                // 1 below m_multiGuide.  Not necessary if Qt::NoBrush used.
+                m_canvas->getSegmentItem(dynamic_cast<Segment*>(*it))->setZ(-1);
+            }
+
+            SegmentItem *item1, *item2, *item3, *item4;
+
+            item1 = m_canvas->getSegmentItem(segment1);
+            item2 = m_canvas->getSegmentItem(segment2);
+            item3 = m_canvas->getSegmentItem(segment3);
+            item4 = m_canvas->getSegmentItem(segment4);
+
+            m_multiGuide->setX(int(item1->x()));
+            m_multiGuide->setY(int(item3->y()));
+            m_multiGuide->setZ(0); // 1 above whats selected, 1 below whats not.
+            m_multiGuide->setSize(int(item2->x() + item2->width() - item1->x()), 
+                                  int(item4->y() + item4->height() - item3->y()));
+            m_multiGuide->show();
+            m_canvas->canvas()->update();
+            return;
+        }                
+        
         m_currentItem = item;
 	m_currentItemStartX = item->x();
 	m_clickPoint = e->pos();
@@ -445,12 +509,15 @@
         if (newY < 0) newY = 0;
 
 	timeT newStartTime = m_canvas->grid().snapX(newX);
+
 	m_currentItem->setEndTime(m_currentItem->getEndTime() + newStartTime -
 				  m_currentItem->getStartTime());
 	m_currentItem->setStartTime(newStartTime);
 
 	TrackId track = m_canvas->grid().getYBin(newY);
 
+        //std::cout << "newTrack " << track << std::endl;
+
         int nbTracks = m_doc->getComposition().getNbTracks();
 
         if (track >= ((unsigned int)nbTracks)) {
Index: segmenttool.h
===================================================================
RCS file: /cvsroot/rosegarden/gui/segmenttool.h,v
retrieving revision 1.9
diff -u -w -r1.9 segmenttool.h
--- segmenttool.h	27 Apr 2003 15:47:45 -0000	1.9
+++ segmenttool.h	9 Jun 2003 14:03:01 -0000
@@ -177,7 +177,7 @@
 
     QCanvasRectangle *m_foreGuide;
     QCanvasRectangle *m_topGuide;
-
+    QCanvasRectangle *m_multiGuide;
 };
 
 /**
@@ -291,7 +291,6 @@
 
     QCanvasRectangle *m_foreGuide;
     QCanvasRectangle *m_topGuide;
-
 };
 
 

Reply via email to