diff --git a/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.cpp b/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.cpp index 2b9d2b875049a1e39cf02e9badf0d99c50f2c2a1..45822d5d373eae58a31367bf8ae1fdb27974fc41 100644 --- a/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.cpp +++ b/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.cpp @@ -8,9 +8,6 @@ #include <QFileDialog> #include <QPrinter> #include <QPrintDialog> -#include <QMessageBox> -#include <QTextStream> -#include <QApplication> /** * Constructor @@ -21,7 +18,14 @@ ScriptOutputDisplay::ScriptOutputDisplay(QWidget * parent) : QTextEdit(parent), m_copy(NULL), m_clear(NULL), m_save(NULL) { - setReadOnly(true); + //the control is readonly, but if you set it read only then ctrl+c for copying does not work + //this approach allows ctrl+c and disables user editing through the use of the KeyPress handler + //and disabling drag and drop + //also the mouseMoveEventHandler prevents dragging out of the control affecting the text. + setReadOnly(false); + this->setAcceptDrops(false); + + setLineWrapMode(QTextEdit::WidgetWidth); setLineWrapColumnOrWidth(105); setAutoFormatting(QTextEdit::AutoNone); @@ -35,6 +39,17 @@ ScriptOutputDisplay::ScriptOutputDisplay(QWidget * parent) : initActions(); } +/** Mouse move event handler - overridden to prevent dragging out of the control affecting the text + * it does this by temporarily setting the control to read only while the base event handler operates + * @param e the mouse move event + */ +void ScriptOutputDisplay::mouseMoveEvent(QMouseEvent * e) + { + this->setReadOnly(true); + QTextEdit::mouseMoveEvent(e); + this->setReadOnly(false); + } + /** * Is there anything here */ @@ -52,6 +67,22 @@ void ScriptOutputDisplay::populateEditMenu(QMenu &editMenu) editMenu.addAction(m_clear); } + + +/** + * Capture key presses. + * @param event A pointer to the QKeyPressEvent object + */ +void ScriptOutputDisplay::keyPressEvent(QKeyEvent* event) +{ + if ((event->key() == Qt::Key_C) && (event->modifiers() == Qt::KeyboardModifier::ControlModifier)) + { + this->copy(); + } + //accept all key presses to prevent keyboard interaction + event->accept(); +} + /** * Display an output message that is not an error * @param msg :: The string message diff --git a/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.h b/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.h index 52941fcd8415fc754103d407e32b4ebdb7516057..9afaefe92ec4e4b3f9e19fc778100b092691d2b0 100644 --- a/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.h +++ b/Code/Mantid/MantidPlot/src/ScriptOutputDisplay.h @@ -20,6 +20,10 @@ public: /// Add actions applicable to an edit menu void populateEditMenu(QMenu &editMenu); + ///Capture key presses + virtual void keyPressEvent(QKeyEvent* event); + //squash dragging ability + void mouseMoveEvent(QMouseEvent * e); public slots: /// Print the text within the window