# HG changeset patch # User John Donoghue # Date 1397847879 14400 # Node ID 8b9e99c061f9ed8c3b9ef2cdaef68db8148b96c3 # Parent 1b289f45187f443b72bf32d3073ac53ba60df77a GUI: Windows GUI terminal support for double click (Bug #41468) * libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h, libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp (QConsolePrivate::selectWord): New function. (QConsolePrivate::selectLine): New function. (QWinTerminalImpl::QWinTerminalImpl): init new allowTripleClick variable. (QWinTerminalImpl::mousePressEvent): call mouseTripleClickEvent ifallowTripleClick is set. (QWinTerminalImpl::mouseReleaseEvent): only process if settingSelection is true. (QWinTerminalImpl::mouseDoubleClickEvent): New function. (QWinTerminalImpl::mouseTripleClickEvent): New function. (QWinTerminalImpl::tripleClickTimeout): New slot. diff -r 1b289f45187f -r 8b9e99c061f9 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Fri Apr 18 13:43:55 2014 +0200 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Fri Apr 18 15:04:39 2014 -0400 @@ -187,6 +187,8 @@ void sendConsoleText (const QString& s); QRect cursorRect (void); void selectAll(); + void selectWord(const QPoint& cellPos); + void selectLine(const QPoint& cellPos); void log (const char* fmt, ...); @@ -678,6 +680,67 @@ updateSelection(); } +void QConsolePrivate::selectWord (const QPoint & cellpos) +{ + QPoint begin = cellpos; + QPoint end = cellpos; + + int scrollOffset = m_consoleRect.top (); + int stride = m_consoleRect.width (); + + // get begin, end in buffer offsets + begin.ry () -= scrollOffset; + end.ry () -= scrollOffset; + + // loog at current clicked on char to determinate ig getting space chunk or nonspace chunk + if (QChar(m_buffer[begin.y ()*stride + begin.x ()].Char.UnicodeChar).isSpace () == false) + { + // from current char, go back and fwd to find start and end of block + while(begin.x () > 0 && + QChar(m_buffer[begin.y ()*stride + begin.x () -1].Char.UnicodeChar).isSpace() == false) + { + begin.rx () --; + } + + while(end.x () < m_consoleRect.width () && + QChar(m_buffer[end.y ()*stride + end.x () +1].Char.UnicodeChar).isSpace() == false) + { + end.rx () ++; + } + } + else + { + while(begin.x () > 0 && + QChar(m_buffer[begin.y ()*stride + begin.x () -1].Char.UnicodeChar).isSpace()) + { + begin.rx () --; + } + + while(end.x () < m_consoleRect.width () && + QChar(m_buffer[end.y ()*stride + end.x () +1].Char.UnicodeChar).isSpace ()) + { + end.rx () ++; + } + } + + // convert console offsets to absolute cell positions + begin.ry () += scrollOffset; + end.ry () += scrollOffset; + + m_beginSelection = begin; + m_endSelection = end; + + updateSelection (); +} + +void QConsolePrivate::selectLine (const QPoint & cellpos) +{ + m_beginSelection = QPoint (0, cellpos.y ()); + m_endSelection = QPoint (m_bufferSize.width ()-1, cellpos.y ()); + updateSelection (); +} + + void QConsolePrivate::drawSelection (QPainter& p, int cx1, int cy1, int cx2, int cy2, int cw, int ch) { @@ -1262,7 +1325,8 @@ ////////////////////////////////////////////////////////////////////////////// QWinTerminalImpl::QWinTerminalImpl (QWidget* parent) - : QTerminal (parent), d (new QConsolePrivate (this)) + : QTerminal (parent), d (new QConsolePrivate (this)), + allowTripleClick (false) { installEventFilter (this); @@ -1298,7 +1362,11 @@ void QWinTerminalImpl::mousePressEvent (QMouseEvent *event) { - if (event->button () == Qt::LeftButton) + if (allowTripleClick) + { + mouseTripleClickEvent (event); + } + else if (event->button () == Qt::LeftButton) { d->m_settingSelection = true; @@ -1308,7 +1376,7 @@ void QWinTerminalImpl::mouseReleaseEvent (QMouseEvent *event) { - if (event->button () == Qt::LeftButton) + if (event->button () == Qt::LeftButton && d->m_settingSelection) { d->m_endSelection = d->posToCell (event->pos ()); @@ -1318,6 +1386,36 @@ } } +void QWinTerminalImpl::mouseDoubleClickEvent (QMouseEvent *event) +{ + if (event->button () == Qt::LeftButton) + { + // doubleclick - select word + d->m_settingSelection = false; + + d->selectWord (d->posToCell (event->pos ())); + + allowTripleClick = true; + + QTimer::singleShot (QApplication::doubleClickInterval (),this, + SLOT (tripleClickTimeout ())); + + } +} + +void QWinTerminalImpl::mouseTripleClickEvent (QMouseEvent *event) +{ + if (event->button () == Qt::LeftButton) + { + d->selectLine (d->posToCell (event->pos ())); + } +} + +void QWinTerminalImpl::tripleClickTimeout () +{ + allowTripleClick = false; +} + ////////////////////////////////////////////////////////////////////////////// void QWinTerminalImpl::viewResizeEvent (QConsoleView*, QResizeEvent*) diff -r 1b289f45187f -r 8b9e99c061f9 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Fri Apr 18 13:43:55 2014 +0200 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Fri Apr 18 15:04:39 2014 -0400 @@ -90,6 +90,8 @@ void mouseMoveEvent (QMouseEvent *event); void mousePressEvent (QMouseEvent *event); void mouseReleaseEvent (QMouseEvent *event); + void mouseDoubleClickEvent (QMouseEvent* event); + void mouseTripleClickEvent (QMouseEvent* event); bool eventFilter(QObject *obj, QEvent *ev); @@ -100,9 +102,11 @@ void scrollValueChanged (int value); void monitorConsole (void); void updateSelection (void); + void tripleClickTimeout (void); private: QConsolePrivate* d; + bool allowTripleClick; }; //////////////////////////////////////////////////////////////////////////////