Commit 4c61c8e8 authored by Mathieu Tillet's avatar Mathieu Tillet
Browse files

Allow for copy and paste of shapes

In the instrument viewer draw tab, the user can copy and paste shapes
using Ctrl+C, Ctrl+V.
parent dd0cca2c
......@@ -168,6 +168,10 @@ signals:
void setSelection(const QRect & /*_t1*/);
/// Rubber band selection is done
void finishSelection(const QRect & /*_t1*/);
/// Copy the selected shapes.
void copySelectedShapes();
/// Paste previously copied shapes.
void pasteCopiedShapes();
public slots:
void startCreatingShape2D(const QString &type, const QColor &borderColor,
......
......@@ -187,6 +187,16 @@ void InputControllerDrawShape::keyPressEvent(QKeyEvent *event) {
case Qt::Key_Backspace:
emit removeSelectedShapes();
break;
case Qt::Key_C:
if (event->modifiers() == Qt::CTRL) {
emit copySelectedShapes();
}
break;
case Qt::Key_V:
if (event->modifiers() == Qt::CTRL) {
emit pasteCopiedShapes();
}
break;
}
}
......
......@@ -128,6 +128,8 @@ public slots:
void restoreOverrideCursor();
void drawFree(const QPolygonF &polygon);
void eraseFree(const QPolygonF &polygon);
void copySelectedShapes();
void pasteCopiedShapes();
protected:
void drawShape(QPainter & /*painter*/) const override {} // never called
......@@ -158,6 +160,8 @@ protected:
size_t m_currentCP; ///< control point of m_currentShape selected to edit
QList<Shape2D *>
m_selectedShapes; ///< A list of selected shapes (can be moved or deleted)
QList<Shape2D *>
m_copiedShapes; ///< A list of shapes to be pasted if requiered
bool m_overridingCursor;
friend class InstrumentWidgetEncoder;
friend class InstrumentWidgetDecoder;
......
......@@ -101,6 +101,10 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor *rootActor)
SLOT(selectMultipleMasks(QRect)));
connect(drawController, SIGNAL(finishSelection(QRect)), this,
SIGNAL(shapeChangeFinished()));
connect(drawController, SIGNAL(copySelectedShapes()), &m_maskShapes,
SLOT(copySelectedShapes()));
connect(drawController, SIGNAL(pasteCopiedShapes()), &m_maskShapes,
SLOT(pasteCopiedShapes()));
InputControllerDrawAndErase *freeDrawController =
new InputControllerDrawAndErase(this);
......
......@@ -28,7 +28,8 @@ namespace MantidWidgets {
Shape2DCollection::Shape2DCollection()
: Shape2D(), m_wx(0), m_wy(0), m_h(0), m_currentShape(nullptr),
m_currentCP(0), m_overridingCursor(false) {}
m_currentCP(0), m_copiedShapes(QList<Shape2D *>()),
m_overridingCursor(false) {}
Shape2DCollection::~Shape2DCollection() {
foreach (Shape2D *shape, m_shapes) { delete shape; }
......@@ -532,6 +533,33 @@ void Shape2DCollection::removeSelectedShapes() {
}
}
/**
* @brief Shape2DCollection::copySelectedShapes
* Add the selected shapes to a copy buffer. Remove those previously stored.
*/
void Shape2DCollection::copySelectedShapes() {
m_copiedShapes.clear();
foreach (auto shape, m_selectedShapes) {
Shape2D *newShape = shape->clone();
newShape->setFillColor(shape->getFillColor());
// the fill color is not transmitted by the clone operator
m_copiedShapes.push_back(newShape);
}
}
/**
* @brief Shape2DCollection::pasteCopiedShapes
* Add a copy of the shapes stored in the copy buffer to the collection.
*/
void Shape2DCollection::pasteCopiedShapes() {
foreach (auto shape, m_copiedShapes) {
Shape2D *newShape = shape->clone();
newShape->moveBy(QPointF(0.1, 0.1));
newShape->setFillColor(shape->getFillColor());
addShape(newShape, false);
}
}
/**
* Restore the cursor image to default.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment