0000822: Two little tweaks for the python console

This commit is contained in:
wmayer
2012-09-05 16:01:39 +02:00
parent a26f42b7b3
commit 3140c13baf
2 changed files with 32 additions and 7 deletions

View File

@@ -442,13 +442,8 @@ void PythonConsole::OnChange( Base::Subject<const char*> &rCaller,const char* sR
void PythonConsole::keyPressEvent(QKeyEvent * e)
{
bool restartHistory = true;
QTextCursor cursor = this->textCursor();
// construct reference cursor at begin of input line ...
QTextCursor inputLineBegin = cursor;
inputLineBegin.movePosition( QTextCursor::End );
inputLineBegin.movePosition( QTextCursor::StartOfLine );
inputLineBegin.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor, promptLength );
QTextCursor cursor = this->textCursor();
QTextCursor inputLineBegin = this->inputBegin();
if (cursor < inputLineBegin)
{
@@ -579,6 +574,9 @@ void PythonConsole::keyPressEvent(QKeyEvent * e)
// the event and afterwards update the list widget
if (d->callTipsList->isVisible())
{ d->callTipsList->validateCursor(); }
// disable history restart if input line changed
restartHistory &= (inputLine != inputBlock.text().mid(promptLength));
}
// any cursor move resets the history to its latest item.
if (restartHistory)
@@ -806,6 +804,21 @@ void PythonConsole::changeEvent(QEvent *e)
TextEdit::changeEvent(e);
}
void PythonConsole::mouseReleaseEvent( QMouseEvent *e )
{
TextEdit::mouseReleaseEvent( e );
if (e->button() == Qt::LeftButton)
{
QTextCursor cursor = this->textCursor();
if (cursor.hasSelection() == false
&& cursor < this->inputBegin())
{
cursor.movePosition( QTextCursor::End );
this->setTextCursor( cursor );
}
}
}
/**
* Drops the event \a e and writes the right Python command.
*/
@@ -904,6 +917,16 @@ void PythonConsole::insertFromMimeData (const QMimeData * source)
}
}
QTextCursor PythonConsole::inputBegin( void ) const
{
// construct cursor at begin of input line ...
QTextCursor inputLineBegin( this->textCursor() );
inputLineBegin.movePosition( QTextCursor::End );
inputLineBegin.movePosition( QTextCursor::StartOfLine );
inputLineBegin.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor, promptLength );
return inputLineBegin;
}
QMimeData * PythonConsole::createMimeDataFromSelection () const
{
QMimeData* mime = new QMimeData();