From 2fe6d147d9cd45cbc6d2a551a72d2a1b89389d00 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Wed, 2 Jul 2014 02:38:28 +0200 Subject: [PATCH] Initial support for mouse in applications. --- app/PreprocessedTerminal.qml | 10 +- app/app.qmlproject.user | 2 +- konsole-qml-plugin/src/Session.cpp | 10 +- konsole-qml-plugin/src/TerminalDisplay.cpp | 111 ++++++++++++++++----- konsole-qml-plugin/src/TerminalDisplay.h | 13 ++- konsole-qml-plugin/src/Vt102Emulation.cpp | 6 +- konsole-qml-plugin/src/plugins.qmltypes | 20 +++- 7 files changed, 128 insertions(+), 44 deletions(-) diff --git a/app/PreprocessedTerminal.qml b/app/PreprocessedTerminal.qml index 48727df..c0f957d 100644 --- a/app/PreprocessedTerminal.qml +++ b/app/PreprocessedTerminal.qml @@ -130,8 +130,11 @@ Item{ MouseArea{ acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton anchors.fill: parent - onWheel: - wheel.angleDelta.y > 0 ? kterminal.scrollUp() : kterminal.scrollDown() + onWheel:{ + var coord = correctDistortion(wheel.x, wheel.y); + var lines = wheel.angleDelta.y > 0 ? -2 : 2; + kterminal.scrollWheel(coord.width, coord.height, lines); + } onClicked: { if (mouse.button == Qt.RightButton){ contextmenu.popup(); @@ -157,7 +160,8 @@ Item{ } onReleased: { if (mouse.button == Qt.LeftButton){ - kterminal.mouseRelease(mouse.x, mouse.y); + var coord = correctDistortion(mouse.x, mouse.y); + kterminal.mouseRelease(coord.width, coord.height); } } diff --git a/app/app.qmlproject.user b/app/app.qmlproject.user index 036922f..0d90895 100644 --- a/app/app.qmlproject.user +++ b/app/app.qmlproject.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/konsole-qml-plugin/src/Session.cpp b/konsole-qml-plugin/src/Session.cpp index 4c06535..4d59d51 100644 --- a/konsole-qml-plugin/src/Session.cpp +++ b/konsole-qml-plugin/src/Session.cpp @@ -190,17 +190,17 @@ void Session::addView(KTerminalDisplay * widget) if ( _emulation != 0 ) { // connect emulation - view signals and slots - connect( widget , SIGNAL(keyPressedSignal(QKeyEvent *)) , _emulation , + QObject::connect( widget , SIGNAL(keyPressedSignal(QKeyEvent *)) , _emulation , SLOT(sendKeyEvent(QKeyEvent *)) ); -// connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation , -// SLOT(sendMouseEvent(int,int,int,int)) ); + connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation , + SLOT(sendMouseEvent(int,int,int,int)) ); // connect( widget , SIGNAL(sendStringToEmu(const char *)) , _emulation , // SLOT(sendString(const char *)) ); // allow emulation to notify view when the foreground process // indicates whether or not it is interested in mouse signals -// connect( _emulation , SIGNAL(programUsesMouseChanged(bool)) , widget , -// SLOT(setUsesMouse(bool)) ); + connect( _emulation , SIGNAL(programUsesMouseChanged(bool)) , widget , + SLOT(setUsesMouse(bool)) ); //widget->setUsesMouse( _emulation->programUsesMouse() ); diff --git a/konsole-qml-plugin/src/TerminalDisplay.cpp b/konsole-qml-plugin/src/TerminalDisplay.cpp index 7bfc320..d4fb265 100644 --- a/konsole-qml-plugin/src/TerminalDisplay.cpp +++ b/konsole-qml-plugin/src/TerminalDisplay.cpp @@ -158,6 +158,7 @@ KTerminalDisplay::KTerminalDisplay(QQuickItem *parent) : ,_lineSpacing(2) ,_colorsInverted(false) ,_cursorShape(BlockCursor) + ,_mouseMarks(false) ,m_session(0) ,m_focusOnClick(true) ,m_showVKBonClick(true) @@ -184,6 +185,8 @@ KTerminalDisplay::KTerminalDisplay(QQuickItem *parent) : _topMargin = DEFAULT_TOP_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 _blinkTimer = new QTimer(this); connect(_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkEvent())); @@ -213,6 +216,10 @@ KTerminalDisplay::~KTerminalDisplay() 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) { if (m_session != session) { @@ -243,18 +250,6 @@ ScreenWindow* KTerminalDisplay::screenWindow() const 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() { @@ -416,8 +411,8 @@ void KTerminalDisplay::setVTFont(const QFont& f) // Disabling kerning saves some computation when rendering text. font.setKerning(false); - // Konsole cannot handle non-integer font metrics - font.setStyleStrategy(QFont::StyleStrategy(font.styleStrategy() | QFont::ForceIntegerMetrics)); + // Konsole cannot handle non-integer font metrics + font.setStyleStrategy(QFont::StyleStrategy(font.styleStrategy() | QFont::ForceIntegerMetrics)); //QWidget::setFont(font); m_font = font; @@ -456,41 +451,107 @@ QStringList KTerminalDisplay::availableColorSchemes() 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){ if (m_focusOnClick) forcedFocus(); if (m_showVKBonClick) ShowVKB(true); - emit clicked(); + QPoint pos(x,y); + qDebug() << "Mousepress " <clearSelection(); - _iPntSel = _pntSel = pos; - _actSel = 1; // left mouse button pressed but nothing selected yet. + if(_mouseMarks){ + emit mouseSignal(0, charColumn + 1, charLine + 1, 0); + return; + } else { + QPoint pos = QPoint(charColumn, charLine); + + _screenWindow->clearSelection(); + _iPntSel = _pntSel = pos; + _actSel = 1; // left mouse button pressed but nothing selected yet. + } } void KTerminalDisplay::mouseMove(qreal x, qreal y){ QPoint pos(x, y); - extendSelection(pos); + + 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); + } } void KTerminalDisplay::mouseDoubleClick(qreal x, qreal y){ - _wordSelectionMode = true; QPoint pos(x, y); - extendSelection(pos); + + 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); + } } void KTerminalDisplay::mouseRelease(qreal x, qreal y){ - Q_UNUSED(x); - Q_UNUSED(y); _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) diff --git a/konsole-qml-plugin/src/TerminalDisplay.h b/konsole-qml-plugin/src/TerminalDisplay.h index 67f43fd..831d7a5 100644 --- a/konsole-qml-plugin/src/TerminalDisplay.h +++ b/konsole-qml-plugin/src/TerminalDisplay.h @@ -100,9 +100,6 @@ public: Q_INVOKABLE void setLineSpacing(uint); uint lineSpacing() const; - Q_INVOKABLE void scrollDown(); - Q_INVOKABLE void scrollUp(); - void emitSelection(bool useXselection,bool appendReturn); /** @@ -314,11 +311,14 @@ public slots: void setColorScheme(const QString &name); QStringList availableColorSchemes(); + void scrollWheel(qreal x, qreal y, int lines); void mousePress(qreal x, qreal y); void mouseMove(qreal x, qreal y); void mouseDoubleClick(qreal x, qreal y); void mouseRelease(qreal x, qreal y); + void setUsesMouse(bool usesMouse); + bool autoFocus() { return m_focusOnClick; } void setAutoFocus(bool au); 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); KSession * getSession() const { return m_session; } @@ -418,7 +420,8 @@ signals: void changedAutoFocus(bool au); void updatedImage(); - void clicked(); + + void mouseSignal(int,int,int,int); void terminalSizeChanged(); void paintedFontSizeChanged(); @@ -702,6 +705,8 @@ private: static bool _antialiasText; // do we antialias or not + bool _mouseMarks; + //the delay in milliseconds between redrawing blinking text static const int TEXT_BLINK_DELAY = 500; static const int DEFAULT_LEFT_MARGIN = 1; diff --git a/konsole-qml-plugin/src/Vt102Emulation.cpp b/konsole-qml-plugin/src/Vt102Emulation.cpp index a3e9fb2..f33010f 100644 --- a/konsole-qml-plugin/src/Vt102Emulation.cpp +++ b/konsole-qml-plugin/src/Vt102Emulation.cpp @@ -862,13 +862,13 @@ void Vt102Emulation::reportAnswerBack() */ void Vt102Emulation::sendMouseEvent( int cb, int cx, int cy , int eventType ) -{ - if (cx < 1 || cy < 1) +{ + if (cx < 1 || cy < 1) return; // normal buttons are passed as 0x20 + button, // mouse wheel (buttons 4,5) as 0x5c + button - if (cb >= 4) + if (cb >= 4) cb += 0x3c; //Mouse motion handling diff --git a/konsole-qml-plugin/src/plugins.qmltypes b/konsole-qml-plugin/src/plugins.qmltypes index 8afdda1..cfde7ec 100644 --- a/konsole-qml-plugin/src/plugins.qmltypes +++ b/konsole-qml-plugin/src/plugins.qmltypes @@ -74,7 +74,13 @@ Module { name: "changedAutoFocus" Parameter { name: "au"; type: "bool" } } - Signal { name: "clicked" } + Signal { + name: "mouseSignal" + Parameter { type: "int" } + Parameter { type: "int" } + Parameter { type: "int" } + Parameter { type: "int" } + } Signal { name: "keyPressedSignal" Parameter { name: "e"; type: "QKeyEvent"; isPointer: true } @@ -121,6 +127,12 @@ Module { Parameter { name: "name"; type: "string" } } Method { name: "availableColorSchemes"; type: "QStringList" } + Method { + name: "scrollWheel" + Parameter { name: "x"; type: "double" } + Parameter { name: "y"; type: "double" } + Parameter { name: "lines"; type: "int" } + } Method { name: "mousePress" Parameter { name: "x"; type: "double" } @@ -191,7 +203,9 @@ Module { name: "setLineSpacing" Parameter { name: "i"; type: "uint"} } - Method { name: "scrollUp" } - Method { name: "scrollDown" } + Method { + name: "setUsesMouse" + Parameter { name: "usesMouse"; type: "bool"} + } } }