From 2bcb137a5bf2684f9d8f70adcfccb19dafb18369 Mon Sep 17 00:00:00 2001 From: Petr Vanek Date: Mon, 14 Jul 2014 13:22:13 +0200 Subject: [PATCH] Url activation & filters #21 --- CMakeLists.txt | 2 +- lib/Filter.cpp | 10 ++++------ lib/Filter.h | 19 ++++++++++++------- lib/TerminalDisplay.cpp | 13 +++---------- lib/TerminalDisplay.h | 9 +++++---- lib/qtermwidget.cpp | 13 +++++++++++++ lib/qtermwidget.h | 16 ++++++++++++++++ 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63a5af5..183bb85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ set(HDRS set(UI lib/SearchBar.ui) # for distribution -set(HDRS_DISTRIB lib/qtermwidget.h ) +set(HDRS_DISTRIB lib/qtermwidget.h lib/Filter.h) # dirs set ( KB_LAYOUT_DIR ${CMAKE_INSTALL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/kb-layouts/ ) diff --git a/lib/Filter.cpp b/lib/Filter.cpp index 4738974..93de72c 100644 --- a/lib/Filter.cpp +++ b/lib/Filter.cpp @@ -330,7 +330,7 @@ RegExpFilter::HotSpot::HotSpot(int startLine,int startColumn,int endLine,int end setType(Marker); } -void RegExpFilter::HotSpot::activate(QObject*) +void RegExpFilter::HotSpot::activate(const QString&) { } @@ -443,21 +443,19 @@ UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const return Unknown; } -void UrlFilter::HotSpot::activate(QObject* object) +void UrlFilter::HotSpot::activate(const QString& actionName) { QString url = capturedTexts().first(); const UrlType kind = urlType(); - const QString& actionName = object ? object->objectName() : QString(); - if ( actionName == "copy-action" ) { QApplication::clipboard()->setText(url); return; } - if ( !object || actionName == "open-action" ) + if ( actionName.isEmpty() || actionName == "open-action" ) { if ( kind == StandardUrl ) { @@ -511,7 +509,7 @@ void FilterObject::emitActivated(const QUrl& url) void FilterObject::activated() { - _filter->activate(sender()); + _filter->activate(sender()->objectName()); } FilterObject* UrlFilter::HotSpot::getUrlObject() const diff --git a/lib/Filter.h b/lib/Filter.h index 2daae09..161773b 100644 --- a/lib/Filter.h +++ b/lib/Filter.h @@ -29,11 +29,13 @@ #include // Local -#include "Character.h" namespace Konsole { +typedef unsigned char LineProperty; +class Character; + /** * A filter processes blocks of text looking for certain patterns (such as URLs or keywords from a list) * and marks the areas which match the filter's patterns as 'hotspots'. @@ -103,12 +105,12 @@ public: /** * Causes the an action associated with a hotspot to be triggered. * - * @param object The object which caused the hotspot to be triggered. This is - * typically null ( in which case the default action should be performed ) or - * one of the objects from the actions() list. In which case the associated + * @param action The action to trigger. This is + * typically empty ( in which case the default action should be performed ) or + * one of the object names from the actions() list. In which case the associated * action should be performed. */ - virtual void activate(QObject* object = 0) = 0; + virtual void activate(const QString& action = QString()) = 0; /** * Returns a list of actions associated with the hotspot which can be used in a * menu or toolbar @@ -200,7 +202,7 @@ public: { public: HotSpot(int startLine, int startColumn, int endLine , int endColumn); - virtual void activate(QObject* object = 0); + virtual void activate(const QString& action = QString()); /** Sets the captured texts associated with this hotspot */ void setCapturedTexts(const QStringList& texts); @@ -268,7 +270,7 @@ public: * Open a web browser at the current URL. The url itself can be determined using * the capturedTexts() method. */ - virtual void activate(QObject* object = 0); + virtual void activate(const QString& action = QString()); virtual QString tooltip() const; private: @@ -388,4 +390,7 @@ private: }; } + +typedef Konsole::Filter Filter; + #endif //FILTER_H diff --git a/lib/TerminalDisplay.cpp b/lib/TerminalDisplay.cpp index 2d7e799..2107ad9 100644 --- a/lib/TerminalDisplay.cpp +++ b/lib/TerminalDisplay.cpp @@ -1776,16 +1776,9 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev) emit mouseSignal( 0, charColumn + 1, charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , 0); } - if (ev->modifiers() & Qt::ControlModifier) - { - Filter::HotSpot *spot = _filterChain->hotSpotAt(charLine, charColumn); - if (spot && spot->type() == Filter::HotSpot::Link) - { - QObject action; - action.setObjectName ("open-action"); - spot->activate(&action); - } - } + Filter::HotSpot *spot = _filterChain->hotSpotAt(charLine, charColumn); + if (spot && spot->type() == Filter::HotSpot::Link) + spot->activate("open-action"); } } else if ( ev->button() == Qt::MidButton ) diff --git a/lib/TerminalDisplay.h b/lib/TerminalDisplay.h index 2bc722f..c32d799 100644 --- a/lib/TerminalDisplay.h +++ b/lib/TerminalDisplay.h @@ -428,6 +428,10 @@ public: void setMotionAfterPasting(MotionAfterPasting action); int motionAfterPasting(); + + // maps a point on the widget to the position ( ie. line and column ) + // of the character at that point. + void getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const; public slots: @@ -565,6 +569,7 @@ signals: void copyAvailable(bool); void termGetFocus(); void termLostFocus(); + void notifyBell(const QString&); protected: @@ -668,10 +673,6 @@ private: // maps an area in the character image to an area on the widget QRect imageToWidget(const QRect& imageArea) const; - // maps a point on the widget to the position ( ie. line and column ) - // of the character at that point. - void getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const; - // the area where the preedit string for input methods will be draw QRect preeditRect() const; diff --git a/lib/qtermwidget.cpp b/lib/qtermwidget.cpp index d4a796b..dd8b867 100644 --- a/lib/qtermwidget.cpp +++ b/lib/qtermwidget.cpp @@ -606,3 +606,16 @@ void QTermWidget::setSilenceTimeout(int seconds) { m_impl->m_session->setMonitorSilenceSeconds(seconds); } + +Filter::HotSpot* QTermWidget::getHotSpotAt(const QPoint &pos) const +{ + int row = 0, column = 0; + m_impl->m_terminalDisplay->getCharacterPosition(pos, row, column); + return getHotSpotAt(row, column); +} + +Filter::HotSpot* QTermWidget::getHotSpotAt(int row, int column) const +{ + return m_impl->m_terminalDisplay->filterChain()->hotSpotAt(row, column); +} + diff --git a/lib/qtermwidget.h b/lib/qtermwidget.h index 74ca028..9c550ee 100644 --- a/lib/qtermwidget.h +++ b/lib/qtermwidget.h @@ -21,6 +21,7 @@ #define _Q_TERM_WIDGET #include +#include "Filter.h" class QVBoxLayout; struct TermWidgetImpl; @@ -149,6 +150,21 @@ public: void setMonitorSilence(bool); void setSilenceTimeout(int seconds); + /** Returns the available hotspot for the given point \em pos. + * + * This method may return a nullptr if no hotspot is available. + * + * @param[in] pos The point of interest in the QTermWidget coordinates. + * @return Hotspot for the given position, or nullptr if no hotspot. + */ + Filter::HotSpot* getHotSpotAt(const QPoint& pos) const; + + /** Returns the available hotspots for the given row and column. + * + * @return Hotspot for the given position, or nullptr if no hotspot. + */ + Filter::HotSpot* getHotSpotAt(int row, int column) const; + signals: void finished(); void copyAvailable(bool);