Skip to content

Commit

Permalink
Adding shapes to selection by ctrl+click. Re #7222
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jul 2, 2013
1 parent 116f83c commit eb6aa73
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class InputControllerDrawShape: public InputController
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs

public slots:
void tabChanged(int);
void multipleDetectorsSelected(QList<int>&);
void componentSelected(Mantid::Geometry::ComponentID id);
void showPickOptions();
void spectraInfoDialog();
void plotSelectedSpectra();
void showDetectorTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()));
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class ProjectionSurface: public QObject
// 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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand All @@ -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.
Expand Down Expand Up @@ -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)
{
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Shape2DCollection: public QObject, public Shape2D

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();}
Expand Down Expand Up @@ -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();
Expand All @@ -106,6 +108,7 @@ public slots:
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;}
Expand Down

0 comments on commit eb6aa73

Please sign in to comment.