Mercurial > octave-libgccjit
comparison libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp @ 18661:8b9e99c061f9 gui-release
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.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Fri, 18 Apr 2014 15:04:39 -0400 |
parents | 41489b96ebca |
children |
comparison
equal
deleted
inserted
replaced
18656:1b289f45187f | 18661:8b9e99c061f9 |
---|---|
185 void monitorConsole (void); | 185 void monitorConsole (void); |
186 void startCommand (void); | 186 void startCommand (void); |
187 void sendConsoleText (const QString& s); | 187 void sendConsoleText (const QString& s); |
188 QRect cursorRect (void); | 188 QRect cursorRect (void); |
189 void selectAll(); | 189 void selectAll(); |
190 void selectWord(const QPoint& cellPos); | |
191 void selectLine(const QPoint& cellPos); | |
190 | 192 |
191 void log (const char* fmt, ...); | 193 void log (const char* fmt, ...); |
192 | 194 |
193 void closeStandardIO (int fd, DWORD stdHandleId, const char* name); | 195 void closeStandardIO (int fd, DWORD stdHandleId, const char* name); |
194 void setupStandardIO (DWORD stdHandleId, int fd, const char* name, | 196 void setupStandardIO (DWORD stdHandleId, int fd, const char* name, |
676 m_endSelection = QPoint(m_bufferSize.width (), | 678 m_endSelection = QPoint(m_bufferSize.width (), |
677 m_cursorPos.y()); | 679 m_cursorPos.y()); |
678 updateSelection(); | 680 updateSelection(); |
679 } | 681 } |
680 | 682 |
683 void QConsolePrivate::selectWord (const QPoint & cellpos) | |
684 { | |
685 QPoint begin = cellpos; | |
686 QPoint end = cellpos; | |
687 | |
688 int scrollOffset = m_consoleRect.top (); | |
689 int stride = m_consoleRect.width (); | |
690 | |
691 // get begin, end in buffer offsets | |
692 begin.ry () -= scrollOffset; | |
693 end.ry () -= scrollOffset; | |
694 | |
695 // loog at current clicked on char to determinate ig getting space chunk or nonspace chunk | |
696 if (QChar(m_buffer[begin.y ()*stride + begin.x ()].Char.UnicodeChar).isSpace () == false) | |
697 { | |
698 // from current char, go back and fwd to find start and end of block | |
699 while(begin.x () > 0 && | |
700 QChar(m_buffer[begin.y ()*stride + begin.x () -1].Char.UnicodeChar).isSpace() == false) | |
701 { | |
702 begin.rx () --; | |
703 } | |
704 | |
705 while(end.x () < m_consoleRect.width () && | |
706 QChar(m_buffer[end.y ()*stride + end.x () +1].Char.UnicodeChar).isSpace() == false) | |
707 { | |
708 end.rx () ++; | |
709 } | |
710 } | |
711 else | |
712 { | |
713 while(begin.x () > 0 && | |
714 QChar(m_buffer[begin.y ()*stride + begin.x () -1].Char.UnicodeChar).isSpace()) | |
715 { | |
716 begin.rx () --; | |
717 } | |
718 | |
719 while(end.x () < m_consoleRect.width () && | |
720 QChar(m_buffer[end.y ()*stride + end.x () +1].Char.UnicodeChar).isSpace ()) | |
721 { | |
722 end.rx () ++; | |
723 } | |
724 } | |
725 | |
726 // convert console offsets to absolute cell positions | |
727 begin.ry () += scrollOffset; | |
728 end.ry () += scrollOffset; | |
729 | |
730 m_beginSelection = begin; | |
731 m_endSelection = end; | |
732 | |
733 updateSelection (); | |
734 } | |
735 | |
736 void QConsolePrivate::selectLine (const QPoint & cellpos) | |
737 { | |
738 m_beginSelection = QPoint (0, cellpos.y ()); | |
739 m_endSelection = QPoint (m_bufferSize.width ()-1, cellpos.y ()); | |
740 updateSelection (); | |
741 } | |
742 | |
743 | |
681 void QConsolePrivate::drawSelection (QPainter& p, int cx1, int cy1, | 744 void QConsolePrivate::drawSelection (QPainter& p, int cx1, int cy1, |
682 int cx2, int cy2, int cw, int ch) | 745 int cx2, int cy2, int cw, int ch) |
683 { | 746 { |
684 p.save (); | 747 p.save (); |
685 | 748 |
1260 } | 1323 } |
1261 | 1324 |
1262 ////////////////////////////////////////////////////////////////////////////// | 1325 ////////////////////////////////////////////////////////////////////////////// |
1263 | 1326 |
1264 QWinTerminalImpl::QWinTerminalImpl (QWidget* parent) | 1327 QWinTerminalImpl::QWinTerminalImpl (QWidget* parent) |
1265 : QTerminal (parent), d (new QConsolePrivate (this)) | 1328 : QTerminal (parent), d (new QConsolePrivate (this)), |
1329 allowTripleClick (false) | |
1266 { | 1330 { |
1267 installEventFilter (this); | 1331 installEventFilter (this); |
1268 | 1332 |
1269 connect (this, SIGNAL (set_global_shortcuts_signal (bool)), | 1333 connect (this, SIGNAL (set_global_shortcuts_signal (bool)), |
1270 parent, SLOT (set_global_shortcuts (bool))); | 1334 parent, SLOT (set_global_shortcuts (bool))); |
1296 } | 1360 } |
1297 } | 1361 } |
1298 | 1362 |
1299 void QWinTerminalImpl::mousePressEvent (QMouseEvent *event) | 1363 void QWinTerminalImpl::mousePressEvent (QMouseEvent *event) |
1300 { | 1364 { |
1365 if (allowTripleClick) | |
1366 { | |
1367 mouseTripleClickEvent (event); | |
1368 } | |
1369 else if (event->button () == Qt::LeftButton) | |
1370 { | |
1371 d->m_settingSelection = true; | |
1372 | |
1373 d->m_beginSelection = d->posToCell (event->pos ()); | |
1374 } | |
1375 } | |
1376 | |
1377 void QWinTerminalImpl::mouseReleaseEvent (QMouseEvent *event) | |
1378 { | |
1379 if (event->button () == Qt::LeftButton && d->m_settingSelection) | |
1380 { | |
1381 d->m_endSelection = d->posToCell (event->pos ()); | |
1382 | |
1383 updateSelection (); | |
1384 | |
1385 d->m_settingSelection = false; | |
1386 } | |
1387 } | |
1388 | |
1389 void QWinTerminalImpl::mouseDoubleClickEvent (QMouseEvent *event) | |
1390 { | |
1301 if (event->button () == Qt::LeftButton) | 1391 if (event->button () == Qt::LeftButton) |
1302 { | 1392 { |
1303 d->m_settingSelection = true; | 1393 // doubleclick - select word |
1304 | 1394 d->m_settingSelection = false; |
1305 d->m_beginSelection = d->posToCell (event->pos ()); | 1395 |
1306 } | 1396 d->selectWord (d->posToCell (event->pos ())); |
1307 } | 1397 |
1308 | 1398 allowTripleClick = true; |
1309 void QWinTerminalImpl::mouseReleaseEvent (QMouseEvent *event) | 1399 |
1400 QTimer::singleShot (QApplication::doubleClickInterval (),this, | |
1401 SLOT (tripleClickTimeout ())); | |
1402 | |
1403 } | |
1404 } | |
1405 | |
1406 void QWinTerminalImpl::mouseTripleClickEvent (QMouseEvent *event) | |
1310 { | 1407 { |
1311 if (event->button () == Qt::LeftButton) | 1408 if (event->button () == Qt::LeftButton) |
1312 { | 1409 { |
1313 d->m_endSelection = d->posToCell (event->pos ()); | 1410 d->selectLine (d->posToCell (event->pos ())); |
1314 | 1411 } |
1315 updateSelection (); | 1412 } |
1316 | 1413 |
1317 d->m_settingSelection = false; | 1414 void QWinTerminalImpl::tripleClickTimeout () |
1318 } | 1415 { |
1416 allowTripleClick = false; | |
1319 } | 1417 } |
1320 | 1418 |
1321 ////////////////////////////////////////////////////////////////////////////// | 1419 ////////////////////////////////////////////////////////////////////////////// |
1322 | 1420 |
1323 void QWinTerminalImpl::viewResizeEvent (QConsoleView*, QResizeEvent*) | 1421 void QWinTerminalImpl::viewResizeEvent (QConsoleView*, QResizeEvent*) |