1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-02-07 13:41:27 +00:00

Initial support for mouse in applications.

This commit is contained in:
Filippo Scognamiglio 2014-07-02 02:38:28 +02:00
parent f1dc94fab2
commit 2fe6d147d9
7 changed files with 128 additions and 44 deletions

View File

@ -130,8 +130,11 @@ Item{
MouseArea{ MouseArea{
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
anchors.fill: parent anchors.fill: parent
onWheel: onWheel:{
wheel.angleDelta.y > 0 ? kterminal.scrollUp() : kterminal.scrollDown() var coord = correctDistortion(wheel.x, wheel.y);
var lines = wheel.angleDelta.y > 0 ? -2 : 2;
kterminal.scrollWheel(coord.width, coord.height, lines);
}
onClicked: { onClicked: {
if (mouse.button == Qt.RightButton){ if (mouse.button == Qt.RightButton){
contextmenu.popup(); contextmenu.popup();
@ -157,7 +160,8 @@ Item{
} }
onReleased: { onReleased: {
if (mouse.button == Qt.LeftButton){ if (mouse.button == Qt.LeftButton){
kterminal.mouseRelease(mouse.x, mouse.y); var coord = correctDistortion(mouse.x, mouse.y);
kterminal.mouseRelease(coord.width, coord.height);
} }
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-06-28T10:14:09. --> <!-- Written by QtCreator 3.0.1, 2014-07-02T00:31:14. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@ -190,17 +190,17 @@ void Session::addView(KTerminalDisplay * widget)
if ( _emulation != 0 ) { if ( _emulation != 0 ) {
// connect emulation - view signals and slots // connect emulation - view signals and slots
connect( widget , SIGNAL(keyPressedSignal(QKeyEvent *)) , _emulation , QObject::connect( widget , SIGNAL(keyPressedSignal(QKeyEvent *)) , _emulation ,
SLOT(sendKeyEvent(QKeyEvent *)) ); SLOT(sendKeyEvent(QKeyEvent *)) );
// connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation , connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation ,
// SLOT(sendMouseEvent(int,int,int,int)) ); SLOT(sendMouseEvent(int,int,int,int)) );
// connect( widget , SIGNAL(sendStringToEmu(const char *)) , _emulation , // connect( widget , SIGNAL(sendStringToEmu(const char *)) , _emulation ,
// SLOT(sendString(const char *)) ); // SLOT(sendString(const char *)) );
// allow emulation to notify view when the foreground process // allow emulation to notify view when the foreground process
// indicates whether or not it is interested in mouse signals // indicates whether or not it is interested in mouse signals
// connect( _emulation , SIGNAL(programUsesMouseChanged(bool)) , widget , connect( _emulation , SIGNAL(programUsesMouseChanged(bool)) , widget ,
// SLOT(setUsesMouse(bool)) ); SLOT(setUsesMouse(bool)) );
//widget->setUsesMouse( _emulation->programUsesMouse() ); //widget->setUsesMouse( _emulation->programUsesMouse() );

View File

@ -158,6 +158,7 @@ KTerminalDisplay::KTerminalDisplay(QQuickItem *parent) :
,_lineSpacing(2) ,_lineSpacing(2)
,_colorsInverted(false) ,_colorsInverted(false)
,_cursorShape(BlockCursor) ,_cursorShape(BlockCursor)
,_mouseMarks(false)
,m_session(0) ,m_session(0)
,m_focusOnClick(true) ,m_focusOnClick(true)
,m_showVKBonClick(true) ,m_showVKBonClick(true)
@ -184,6 +185,8 @@ KTerminalDisplay::KTerminalDisplay(QQuickItem *parent) :
_topMargin = DEFAULT_TOP_MARGIN; _topMargin = DEFAULT_TOP_MARGIN;
_leftMargin = DEFAULT_LEFT_MARGIN; _leftMargin = DEFAULT_LEFT_MARGIN;
connect(this, SIGNAL(mouseSignal(int,int,int,int)), this, SLOT(banana(int,int,int,int)));
// setup timers for blinking cursor and text // setup timers for blinking cursor and text
_blinkTimer = new QTimer(this); _blinkTimer = new QTimer(this);
connect(_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkEvent())); connect(_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkEvent()));
@ -213,6 +216,10 @@ KTerminalDisplay::~KTerminalDisplay()
delete[] _image; delete[] _image;
} }
void KTerminalDisplay::banana(int x, int y, int z, int w){
qDebug() << "Called banana " << x << " " << y << " " << z << " " << w;
}
void KTerminalDisplay::setSession(KSession * session) void KTerminalDisplay::setSession(KSession * session)
{ {
if (m_session != session) { if (m_session != session) {
@ -243,18 +250,6 @@ ScreenWindow* KTerminalDisplay::screenWindow() const
return _screenWindow; return _screenWindow;
} }
void KTerminalDisplay::scrollDown(){
_screenWindow->scrollBy( ScreenWindow::ScrollLines, +2 );
_screenWindow->scrollCount();
updateImage();
}
void KTerminalDisplay::scrollUp(){
_screenWindow->scrollBy( ScreenWindow::ScrollLines, -2 );
updateImage();
}
void KTerminalDisplay::forcedFocus() void KTerminalDisplay::forcedFocus()
{ {
@ -456,41 +451,107 @@ QStringList KTerminalDisplay::availableColorSchemes()
return ret; return ret;
} }
void KTerminalDisplay::scrollWheel(qreal x, qreal y, int lines){
if(_mouseMarks){
int charLine;
int charColumn;
getCharacterPosition(QPoint(x,y) , charLine , charColumn);
emit mouseSignal(lines > 0 ? 5 : 4,
charColumn + 1,
charLine + 1,
0);
} else {
if(_screenWindow->lineCount() == _screenWindow->windowLines()){
const int keyCode = lines > 0 ? Qt::Key_Down : Qt::Key_Up;
QKeyEvent keyEvent(QEvent::KeyPress, keyCode, Qt::NoModifier);
emit keyPressedSignal(&keyEvent);
emit keyPressedSignal(&keyEvent);
} else {
_screenWindow->scrollBy( ScreenWindow::ScrollLines, lines );
_screenWindow->scrollCount();
updateImage();
}
}
}
void KTerminalDisplay::mousePress(qreal x, qreal y){ void KTerminalDisplay::mousePress(qreal x, qreal y){
if (m_focusOnClick) forcedFocus(); if (m_focusOnClick) forcedFocus();
if (m_showVKBonClick) ShowVKB(true); if (m_showVKBonClick) ShowVKB(true);
emit clicked(); QPoint pos(x,y);
qDebug() << "Mousepress " <<pos;
int charLine; int charLine;
int charColumn; int charColumn;
getCharacterPosition(QPoint(x,y), charLine, charColumn); getCharacterPosition(QPoint(x,y), charLine, charColumn);
QPoint pos = QPoint(charColumn, charLine);
_wordSelectionMode = false; _wordSelectionMode = false;
_lineSelectionMode = false; _lineSelectionMode = false;
if(_mouseMarks){
emit mouseSignal(0, charColumn + 1, charLine + 1, 0);
return;
} else {
QPoint pos = QPoint(charColumn, charLine);
_screenWindow->clearSelection(); _screenWindow->clearSelection();
_iPntSel = _pntSel = pos; _iPntSel = _pntSel = pos;
_actSel = 1; // left mouse button pressed but nothing selected yet. _actSel = 1; // left mouse button pressed but nothing selected yet.
}
} }
void KTerminalDisplay::mouseMove(qreal x, qreal y){ void KTerminalDisplay::mouseMove(qreal x, qreal y){
QPoint pos(x, y); QPoint pos(x, y);
qDebug() << "Mouse move" << pos;
if(_mouseMarks){
int charLine;
int charColumn;
getCharacterPosition(pos, charLine, charColumn);
emit mouseSignal(0, charColumn + 1, charLine + 1, 1);
} else {
extendSelection(pos); extendSelection(pos);
}
} }
void KTerminalDisplay::mouseDoubleClick(qreal x, qreal y){ void KTerminalDisplay::mouseDoubleClick(qreal x, qreal y){
_wordSelectionMode = true;
QPoint pos(x, y); QPoint pos(x, y);
if(_mouseMarks){
int charLine;
int charColumn;
getCharacterPosition(pos, charLine, charColumn);
//emit mouseSignal(0, charColumn + 1, charLine + 1, 0);
//emit mouseSignal(0, charColumn + 1, charLine + 1, 0);
} else {
_wordSelectionMode = true;
extendSelection(pos); extendSelection(pos);
}
} }
void KTerminalDisplay::mouseRelease(qreal x, qreal y){ void KTerminalDisplay::mouseRelease(qreal x, qreal y){
Q_UNUSED(x);
Q_UNUSED(y);
_actSel = 0; _actSel = 0;
QPoint pos(x,y);
qDebug() << "Mousepress " << pos;
if(_mouseMarks){
int charLine;
int charColumn;
getCharacterPosition(QPoint(x,y), charLine, charColumn);
//emit mouseSignal(0, charColumn + 1, charLine + 1, 2);
}
}
void KTerminalDisplay::setUsesMouse(bool usesMouse){
_mouseMarks = !usesMouse;
} }
void KTerminalDisplay::setAutoFocus(bool au) void KTerminalDisplay::setAutoFocus(bool au)

View File

@ -100,9 +100,6 @@ public:
Q_INVOKABLE void setLineSpacing(uint); Q_INVOKABLE void setLineSpacing(uint);
uint lineSpacing() const; uint lineSpacing() const;
Q_INVOKABLE void scrollDown();
Q_INVOKABLE void scrollUp();
void emitSelection(bool useXselection,bool appendReturn); void emitSelection(bool useXselection,bool appendReturn);
/** /**
@ -314,11 +311,14 @@ public slots:
void setColorScheme(const QString &name); void setColorScheme(const QString &name);
QStringList availableColorSchemes(); QStringList availableColorSchemes();
void scrollWheel(qreal x, qreal y, int lines);
void mousePress(qreal x, qreal y); void mousePress(qreal x, qreal y);
void mouseMove(qreal x, qreal y); void mouseMove(qreal x, qreal y);
void mouseDoubleClick(qreal x, qreal y); void mouseDoubleClick(qreal x, qreal y);
void mouseRelease(qreal x, qreal y); void mouseRelease(qreal x, qreal y);
void setUsesMouse(bool usesMouse);
bool autoFocus() { return m_focusOnClick; } bool autoFocus() { return m_focusOnClick; }
void setAutoFocus(bool au); void setAutoFocus(bool au);
bool autoVKB() { return m_showVKBonClick; } bool autoVKB() { return m_showVKBonClick; }
@ -409,6 +409,8 @@ public slots:
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
void banana(int x, int y, int z, int w);
void setSession(KSession * session); void setSession(KSession * session);
KSession * getSession() const { return m_session; } KSession * getSession() const { return m_session; }
@ -418,7 +420,8 @@ signals:
void changedAutoFocus(bool au); void changedAutoFocus(bool au);
void updatedImage(); void updatedImage();
void clicked();
void mouseSignal(int,int,int,int);
void terminalSizeChanged(); void terminalSizeChanged();
void paintedFontSizeChanged(); void paintedFontSizeChanged();
@ -702,6 +705,8 @@ private:
static bool _antialiasText; // do we antialias or not static bool _antialiasText; // do we antialias or not
bool _mouseMarks;
//the delay in milliseconds between redrawing blinking text //the delay in milliseconds between redrawing blinking text
static const int TEXT_BLINK_DELAY = 500; static const int TEXT_BLINK_DELAY = 500;
static const int DEFAULT_LEFT_MARGIN = 1; static const int DEFAULT_LEFT_MARGIN = 1;

View File

@ -74,7 +74,13 @@ Module {
name: "changedAutoFocus" name: "changedAutoFocus"
Parameter { name: "au"; type: "bool" } Parameter { name: "au"; type: "bool" }
} }
Signal { name: "clicked" } Signal {
name: "mouseSignal"
Parameter { type: "int" }
Parameter { type: "int" }
Parameter { type: "int" }
Parameter { type: "int" }
}
Signal { Signal {
name: "keyPressedSignal" name: "keyPressedSignal"
Parameter { name: "e"; type: "QKeyEvent"; isPointer: true } Parameter { name: "e"; type: "QKeyEvent"; isPointer: true }
@ -121,6 +127,12 @@ Module {
Parameter { name: "name"; type: "string" } Parameter { name: "name"; type: "string" }
} }
Method { name: "availableColorSchemes"; type: "QStringList" } Method { name: "availableColorSchemes"; type: "QStringList" }
Method {
name: "scrollWheel"
Parameter { name: "x"; type: "double" }
Parameter { name: "y"; type: "double" }
Parameter { name: "lines"; type: "int" }
}
Method { Method {
name: "mousePress" name: "mousePress"
Parameter { name: "x"; type: "double" } Parameter { name: "x"; type: "double" }
@ -191,7 +203,9 @@ Module {
name: "setLineSpacing" name: "setLineSpacing"
Parameter { name: "i"; type: "uint"} Parameter { name: "i"; type: "uint"}
} }
Method { name: "scrollUp" } Method {
Method { name: "scrollDown" } name: "setUsesMouse"
Parameter { name: "usesMouse"; type: "bool"}
}
} }
} }