Skip to content
Snippets Groups Projects
Commit 81be0e99 authored by Dan Nixon's avatar Dan Nixon
Browse files

Merge pull request #13037 from mantidproject/feature/5895_Script_window_output_copy

SetScriptOutputDisplay allows copying with ctrl+c
parents f2cdfdf3 779e000a
No related branches found
No related tags found
No related merge requests found
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <QPrinter> #include <QPrinter>
#include <QPrintDialog> #include <QPrintDialog>
#include <QMessageBox>
#include <QTextStream>
#include <QApplication>
/** /**
* Constructor * Constructor
...@@ -21,7 +18,14 @@ ...@@ -21,7 +18,14 @@
ScriptOutputDisplay::ScriptOutputDisplay(QWidget * parent) : ScriptOutputDisplay::ScriptOutputDisplay(QWidget * parent) :
QTextEdit(parent), m_copy(NULL), m_clear(NULL), m_save(NULL) 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); setLineWrapMode(QTextEdit::WidgetWidth);
setLineWrapColumnOrWidth(105); setLineWrapColumnOrWidth(105);
setAutoFormatting(QTextEdit::AutoNone); setAutoFormatting(QTextEdit::AutoNone);
...@@ -35,6 +39,17 @@ ScriptOutputDisplay::ScriptOutputDisplay(QWidget * parent) : ...@@ -35,6 +39,17 @@ ScriptOutputDisplay::ScriptOutputDisplay(QWidget * parent) :
initActions(); 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 * Is there anything here
*/ */
...@@ -52,6 +67,22 @@ void ScriptOutputDisplay::populateEditMenu(QMenu &editMenu) ...@@ -52,6 +67,22 @@ void ScriptOutputDisplay::populateEditMenu(QMenu &editMenu)
editMenu.addAction(m_clear); 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 * Display an output message that is not an error
* @param msg :: The string message * @param msg :: The string message
......
...@@ -20,6 +20,10 @@ public: ...@@ -20,6 +20,10 @@ public:
/// Add actions applicable to an edit menu /// Add actions applicable to an edit menu
void populateEditMenu(QMenu &editMenu); void populateEditMenu(QMenu &editMenu);
///Capture key presses
virtual void keyPressEvent(QKeyEvent* event);
//squash dragging ability
void mouseMoveEvent(QMouseEvent * e);
public slots: public slots:
/// Print the text within the window /// Print the text within the window
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment