diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.cpp index 764f80fc49be7d88525cc3d618603fa3fee8a5dd..94c9a41b8f38e5c97f24c8a18514fb65efe5b8f9 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.cpp @@ -166,6 +166,10 @@ void InputControllerDrawShape::mousePressEvent(QMouseEvent *event) { emit addShape( m_shapeType, event->x(), event->y(), m_borderColor, m_fillColor ); } + else if ( event->modifiers() & Qt::ControlModifier ) + { + emit selectCtrlAt( event->x(), event->y() ); + } else { emit selectAt( event->x(), event->y() ); diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.h index d79b6da0557090b1e53d7d67355a806dad42461b..b6e091a52d633c9c18183249de612a3bcb587f29 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InputController.h @@ -140,6 +140,8 @@ signals: void moveRightBottomTo(int,int); /// Select a shape or a conrol point at a location on the screen. void selectAt(int,int); + /// Select a shape with ctrl key pressed at a location on the screen. + void selectCtrlAt(int,int); /// Move selected shape or a control point by a displacement vector. void moveBy(int,int); /// Sent when the mouse is moved to a new position with the buttons up diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp index 3ed4b7214731ddb19e606b7d45379a3fb757306f..b8d8ef6b07d6925784667665f3b5b1d0d2ec1192 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp @@ -462,20 +462,6 @@ void InstrumentWindow::changeColormap(const QString &filename) } } -void InstrumentWindow::showPickOptions() -{ - if ( !m_selectedDetectors.empty() ) - { - QMenu context(m_InstrumentDisplay); - - context.addAction(mInfoAction); - context.addAction(mPlotAction); - context.addAction(mDetTableAction); - - context.exec(QCursor::pos()); - } -} - /** * This is slot for the dialog to appear when a detector is picked and the info menu is selected */ @@ -933,12 +919,6 @@ void InstrumentWindow::setBinRange(double xmin,double xmax) m_xIntegration->setRange(xmin,xmax); } -void InstrumentWindow::multipleDetectorsSelected(QList<int>& detlist) -{ - m_selectedDetectors = detlist; - showPickOptions(); -} - /** * Update the display to view a selected component. The selected component * is visible the rest of the instrument is hidden. diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h index be9f36b9bed213aef3e0a5e670e7bca97aeb5f6b..e7558211867e64d02312d9835f4af68601c1583b 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h @@ -127,9 +127,7 @@ protected: public slots: void tabChanged(int); - void multipleDetectorsSelected(QList<int>&); void componentSelected(Mantid::Geometry::ComponentID id); - void showPickOptions(); void spectraInfoDialog(); void plotSelectedSpectra(); void showDetectorTable(); diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.cpp index 94504bed97e810049f5d3faa503f2f9d78fb748d..92fc670dd14e71e6ec388c15fd57fd9f13bb1afc 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.cpp @@ -58,8 +58,6 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor* rootActor,const Mant setInputController(AddPeakMode, pickController); connect(pickController,SIGNAL(pickPointAt(int,int)),this,SLOT(pickDetectorAt(int,int))); connect(pickController,SIGNAL(touchPointAt(int,int)),this,SLOT(touchDetectorAt(int,int))); - connect(pickController,SIGNAL(setSelection(QRect)),this,SLOT(setSelectionRect(QRect))); - connect(pickController,SIGNAL(finishSelection()),this,SLOT(selectMultipleDetectors())); // create and connect the mask drawing input controller InputControllerDrawShape* drawController = new InputControllerDrawShape(this); @@ -68,6 +66,7 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor* rootActor,const Mant connect(this,SIGNAL(signalToStartCreatingShape2D(QString,QColor,QColor)),drawController,SLOT(startCreatingShape2D(QString,QColor,QColor))); connect(drawController,SIGNAL(moveRightBottomTo(int,int)),&m_maskShapes,SLOT(moveRightBottomTo(int,int))); connect(drawController,SIGNAL(selectAt(int,int)),&m_maskShapes,SLOT(selectShapeOrControlPointAt(int,int))); + connect(drawController,SIGNAL(selectCtrlAt(int,int)),&m_maskShapes,SLOT(addToSelectionShapeAt(int,int))); connect(drawController,SIGNAL(moveBy(int,int)),&m_maskShapes,SLOT(moveShapeOrControlPointBy(int,int))); connect(drawController,SIGNAL(touchPointAt(int,int)),&m_maskShapes,SLOT(touchShapeOrControlPointAt(int,int))); connect(drawController,SIGNAL(disabled()),&m_maskShapes,SLOT(deselectAll())); @@ -715,17 +714,6 @@ void ProjectionSurface::emptySelectionRect() m_selectRect = QRect(); } -/** - * Send multipleDetectorsSelected signal. - */ -void ProjectionSurface::selectMultipleDetectors() -{ - QList<int> detList; - getSelectedDetectors(detList); - emit multipleDetectorsSelected(detList); - emptySelectionRect(); -} - /** * Select multiple mask shapes as a result of a rubber-band selection * @param rect :: The rubber band rect. diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.h index 65b55044c504f68a61f797c74769874c62bb9bb0..e3aa96858ad673ddd3a59c694da3eb1cc4bd9527 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/ProjectionSurface.h @@ -190,7 +190,6 @@ signals: // detector selection void singleDetectorTouched(int); void singleDetectorPicked(int); - void multipleDetectorsSelected(QList<int>&); // shape manipulation void signalToStartCreatingShape2D(const QString& type,const QColor& borderColor,const QColor& fillColor); @@ -214,7 +213,6 @@ protected slots: void setSelectionRect(const QRect& rect); void emptySelectionRect(); - void selectMultipleDetectors(); void selectMultipleMasks(const QRect& rect); void pickDetectorAt(int x,int y); void touchDetectorAt(int x,int y); diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.cpp index 0050a5967aa638b33282cc56a51766e4e6ea80c3..c63004a0b747091fe56e3a2d9358ea10fc1d7f1f 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.cpp @@ -259,6 +259,26 @@ void Shape2DCollection::selectShapeOrControlPointAt(int x, int y) } } +/** + * Add a shape under the cursor to the selection. + * @param x :: Mouse x coordinate. + * @param y :: Mouse y coordinate. + */ +void Shape2DCollection::addToSelectionShapeAt(int x, int y) +{ + // if there is a selected shape under the cursor deselect it + if ( isOverSelectionAt( x, y ) ) + { + deselectAtXY(x,y); + return; + } + // try selecting a shape without editing it + if ( !selectAtXY( x, y, false ) ) + { + deselectAll(); + } +} + /** * Move the current control point or entire shape by (dx,dy). * @param dx :: Shift in the x direction in screen pixels. @@ -319,9 +339,13 @@ void Shape2DCollection::touchShapeOrControlPointAt(int x, int y) /** * Select a shape which contains a point (x,y) of the screen. */ -bool Shape2DCollection::selectAtXY(int x,int y) +bool Shape2DCollection::selectAtXY(int x, int y, bool edit) { - deselectAll(); + if ( edit ) + { + // if shape has to be edited (resized) it must be the only selection + deselectAll(); + } QPointF p = m_transform.inverted().map(QPointF(x,y)); foreach(Shape2D* shape,m_shapes) { @@ -335,6 +359,25 @@ bool Shape2DCollection::selectAtXY(int x,int y) return false; } +/** + * Deselect a shape under the cursor. + * @param x :: Mouse x coordinate. + * @param y :: Mouse y coordinate. + */ +void Shape2DCollection::deselectAtXY(int x, int y) +{ + QPointF p = m_transform.inverted().map(QPointF(x,y)); + foreach(Shape2D* shape,m_shapes) + { + bool picked = shape->selectAt(p); + if (picked) + { + removeFromSelection(shape); + return; + } + } +} + /** * Select all shapes included in a rectangle. * @param rect :: Rectangle in current screen coordinates containing selected shapes. @@ -397,8 +440,8 @@ bool Shape2DCollection::hasSelection() const } /** - * Make a shape current. - * @param shape :: Pointer to a shape which is to become current. The shape must be in the collection. + * Add a shape to selection. If it's the only selection start editing it. + * @param shape :: Pointer to a shape which is to become select. */ void Shape2DCollection::addToSelection(Shape2D* shape) { @@ -411,6 +454,24 @@ void Shape2DCollection::addToSelection(Shape2D* shape) } } +/** + * Remove a shape from selection. + * @param shape :: Pointer to a shape to deselect. + */ +void Shape2DCollection::removeFromSelection(Shape2D *shape) +{ + foreach(Shape2D* s, m_selectedShapes) + { + if ( s == shape ) + { + shape->setSelected(false); + shape->edit(false); + m_selectedShapes.removeOne(shape); + return; + } + } +} + /** * Start editing a shape. * @param shape :: A shape to edit. diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.h index cc9fe3b7342a124c64d8b01ad9b2120a67dd8f09..2ec891df30af29206f73704c74b3d3b207e02625 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2DCollection.h @@ -44,7 +44,8 @@ public: void keyPressEvent(QKeyEvent*); - bool selectAtXY(int x,int y); + bool selectAtXY(int x,int y, bool edit = true); + void deselectAtXY(int x,int y); bool selectIn(const QRect& rect); void removeCurrentShape(); bool isEmpty()const{return m_shapes.isEmpty();} @@ -89,6 +90,7 @@ public slots: void deselectAll(); void moveRightBottomTo(int,int); void selectShapeOrControlPointAt(int x,int y); + void addToSelectionShapeAt(int x,int y); void moveShapeOrControlPointBy(int dx,int dy); void touchShapeOrControlPointAt(int x,int y); void removeSelectedShapes(); @@ -106,6 +108,7 @@ protected: bool isOverCurrentAt(int x,int y); bool isOverSelectionAt(int x,int y); void addToSelection(Shape2D* shape); + void removeFromSelection(Shape2D* shape); void edit(Shape2D* shape); void finishEdit(); QList<Shape2D*> getSelectedShapes() const {return m_selectedShapes;}