mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 15:12:28 +00:00 
			
		
		
		
	Initial support for mouse in applications.
This commit is contained in:
		| @@ -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); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!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> | ||||
|  <data> | ||||
|   <variable>ProjectExplorer.Project.ActiveTarget</variable> | ||||
|   | ||||
| @@ -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() ); | ||||
|  | ||||
|   | ||||
| @@ -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 " <<pos; | ||||
|  | ||||
|     int charLine; | ||||
|     int charColumn; | ||||
|     getCharacterPosition(QPoint(x,y), charLine, charColumn); | ||||
|  | ||||
|     QPoint pos = QPoint(charColumn, charLine); | ||||
|  | ||||
|     _wordSelectionMode = false; | ||||
|     _lineSelectionMode = false; | ||||
|  | ||||
|     _screenWindow->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) | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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"} | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user