Skip to content

Commit

Permalink
SetScriptOutputDisplay to be readonly without using setReadOnly
Browse files Browse the repository at this point in the history
This is because 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.

re #5895
  • Loading branch information
NickDraper committed Jul 8, 2015
1 parent 276cfae commit 2a6f1d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
39 changes: 35 additions & 4 deletions Code/Mantid/MantidPlot/src/ScriptOutputDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#include <QFileDialog>
#include <QPrinter>
#include <QPrintDialog>
#include <QMessageBox>
#include <QTextStream>
#include <QApplication>

/**
* Constructor
Expand All @@ -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);
Expand All @@ -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
*/
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/MantidPlot/src/ScriptOutputDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ScriptOutputDisplay : public QTextEdit

/// 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
Expand Down

0 comments on commit 2a6f1d2

Please sign in to comment.