| 795 | } |
| 796 | |
| 797 | bool OutputWidget::eventFilter(QObject* object, QEvent* event) |
| 798 | { |
| 799 | if (object == ui->textBrowser->viewport() && event->type() == QEvent::MouseButtonPress) { |
| 800 | auto* e = static_cast<QMouseEvent*>(event); |
| 801 | if (e->button() == Qt::LeftButton) { |
| 802 | _pressed = true; |
| 803 | } |
| 804 | } else if (object == ui->textBrowser->viewport() && event->type() == QEvent::MouseMove) { |
| 805 | auto* e = static_cast<QMouseEvent*>(event); |
| 806 | if (_pressed) { |
| 807 | _dragging = true; |
| 808 | } |
| 809 | } else if (object == ui->textBrowser->viewport() && event->type() == QEvent::MouseButtonRelease) { |
| 810 | auto* e = static_cast<QMouseEvent*>(event); |
| 811 | if (e->button() == Qt::LeftButton) { |
| 812 | _pressed = false; |
| 813 | if (_dragging) { |
| 814 | _dragging = false; |
| 815 | } else { |
| 816 | auto position = mouseToPosition(e->pos()); |
| 817 | auto cursor = fragmentCursor(position); |
| 818 | if (cursor.isNull()) { |
| 819 | // See if we're clicking an entire table |
| 820 | position = mouseToPosition(e->pos(), Qt::FuzzyHit); |
| 821 | if (position != -1) { |
| 822 | cursor = ui->textBrowser->textCursor(); |
| 823 | cursor.setPosition(position); |
| 824 | auto* table = cursor.currentTable(); |
| 825 | if (table != nullptr) { |
| 826 | onClickTable(table); |
| 827 | } |
| 828 | } |
| 829 | } else if (!cursor.charFormat().isAnchor()) { |
| 830 | auto* table = cursor.currentTable(); |
| 831 | if (table != nullptr) { |
| 832 | onClickTable(table); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | } else if (object == ui->textBrowser && event->type() == QEvent::KeyPress) { |
| 838 | auto* e = static_cast<QKeyEvent*>(event); |
| 839 | if (e == QKeySequence::Copy || e == QKeySequence::Cut) { |
| 840 | copySelectionToClipboard(false); |
| 841 | return true; |
| 842 | } |
| 843 | } |
| 844 | return false; |
| 845 | } |
| 846 | |
| 847 | void OutputWidget::copySelectionToClipboard(bool includeHidden) |
| 848 | { |