27 #include <QDesktopServices>
29 #include <QApplication>
31 #include <QtCore/QString>
33 #include <QtCore/QSharedData>
41 QMutableListIterator<Filter*> iter(*
this);
43 while ( iter.hasNext() )
65 QListIterator<Filter*> iter(*
this);
66 while (iter.hasNext())
71 QListIterator<Filter*> iter(*
this);
72 while (iter.hasNext())
73 iter.next()->setBuffer(buffer,linePositions);
77 QListIterator<Filter*> iter(*
this);
78 while (iter.hasNext())
79 iter.next()->process();
87 QListIterator<Filter*> iter(*
this);
88 while (iter.hasNext())
92 if ( spot !=
nullptr )
104 QListIterator<Filter*> iter(*
this);
105 while (iter.hasNext())
108 list <<
filter->hotSpots();
115 , _linePositions(nullptr)
141 QString* newBuffer =
new QString();
143 setBuffer( newBuffer , newLinePositions );
152 QTextStream lineStream(
_buffer);
153 decoder.
begin(&lineStream);
155 for (
int i=0 ; i < lines ; i++)
171 lineStream << QChar(
'\n');
178 _linePositions(nullptr),
186 while (iter.hasNext())
216 nextLine =
_buffer->length() + 1;
226 if (
_linePositions->value(i) <= position && position < nextLine )
271 while (spotIter.hasNext())
273 HotSpot* spot = spotIter.next();
287 : _startLine(startLine)
288 , _startColumn(startColumn)
290 , _endColumn(endColumn)
345 _capturedTexts = texts;
349 return _capturedTexts;
373 static const QString emptyString(
"");
396 endLine,endColumn,
_type);
409 int endLine,
int endColumn,
413 endLine,endColumn, t);
419 endLine,endColumn,t);
431 static const QString emptyString(
"");
454 endLine,endColumn,
_type);
461 this, SLOT (request_open_file (
const QString&,
int)));
473 int endLine,
int endColumn,
Type t)
481 QString url = capturedTexts().first();
483 const UrlType kind = urlType();
485 if ( kind == StandardUrl )
487 else if ( kind == Email )
494 QString url = capturedTexts().first();
503 return ParseErrorLink;
510 QString url = capturedTexts().first();
512 const UrlType kind = urlType();
514 const QString& actionName =
object ?
object->objectName() : QString();
516 if ( actionName ==
"copy-action" )
520 QApplication::clipboard()->setText(url);
524 if ( !
object || actionName ==
"open-action" )
526 if ( kind == StandardUrl )
530 if (!url.contains(
"://"))
531 url.prepend(
"http://");
532 QDesktopServices::openUrl (QUrl (url));
534 else if ( kind == Email )
536 url.prepend(
"mailto:");
537 QDesktopServices::openUrl (QUrl (url));
548 _urlObject->request_open_file (file_name,
line.toInt ());
551 else if (kind == ParseErrorLink)
560 _urlObject->request_open_file (file_name,
line.toInt ());
608 _filter->activate(sender());
614 const UrlType kind = urlType();
616 QAction* openAction =
new QAction(_urlObject);
617 QAction* copyAction =
new QAction(_urlObject);;
619 Q_ASSERT (kind == StandardUrl || kind == Email
621 || kind == ParseErrorLink);
623 if ( kind == StandardUrl )
625 openAction->setText(tr (
"Open Link"));
626 copyAction->setText(tr (
"Copy Link Address"));
628 else if ( kind == Email )
630 openAction->setText(tr (
"Send Email To..."));
631 copyAction->setText(tr (
"Copy Email Address"));
635 QString url = capturedTexts().first();
641 openAction->setText(tr (
"Edit %1 at line %2")
642 .arg (file_name).arg (
line));
645 else if ( kind == ParseErrorLink )
647 QString url = capturedTexts().first();
653 openAction->setText(tr (
"Edit %1 at line %2")
654 .arg (file_name).arg (
line));
661 openAction->setObjectName(
"open-action");
662 copyAction->setObjectName(
"copy-action");
664 QObject::connect( openAction , SIGNAL(triggered()) , _urlObject , SLOT(activated()) );
667 if (kind !=
ErrorLink && kind != ParseErrorLink)
669 QObject::connect ( copyAction , SIGNAL(triggered()) ,
670 _urlObject , SLOT(activated()) );
679 QFileInfo file_info = QFileInfo (file);
685 if (file_info.isAbsolute () && file_info.exists ())
static const int LINE_WRAPPED
static const int LINE_DEFAULT
A single character in the terminal which consists of a unicode character value, foreground and backgr...
void process()
Processes each filter in the chain.
bool containsFilter(Filter *filter)
Returns true if the chain contains filter.
void addFilter(Filter *filter)
Adds a new filter to the chain.
void removeFilter(Filter *filter)
Removes a filter from the chain.
void reset()
Resets each filter in the chain.
Filter::HotSpot * hotSpotAt(int line, int column) const
Returns the first hotspot which occurs at line, column or 0 if no hotspot was found.
QList< Filter::HotSpot * > hotSpots() const
Returns a list of all the hotspots in all the chain's filters.
void setBuffer(const QString *buffer, const QList< int > *linePositions)
Sets the buffer for each filter in the chain to process.
void clear()
Removes all filters from the chain.
virtual QString tooltip() const
Returns the text of a tooltip to be shown when the mouse moves over the hotspot, or an empty string i...
int endLine() const
Returns the line where the hotspot area ends.
int startLine() const
Returns the line when the hotspot area starts.
int endColumn() const
Returns the column on endLine() where the hotspot area ends.
virtual QList< QAction * > actions()
Returns a list of actions associated with the hotspot which can be used in a menu or toolbar.
void setType(Type type)
Sets the type of a hotspot.
Type type() const
Returns the type of the hotspot.
HotSpot(int startLine, int startColumn, int endLine, int endColumn)
Constructs a new hotspot which covers the area from (startLine,startColumn) to (endLine,...
int startColumn() const
Returns the column on startLine() where the hotspot area starts.
A filter processes blocks of text looking for certain patterns (such as URLs or keywords from a list)...
QList< HotSpot * > _hotspotList
void setBuffer(const QString *buffer, const QList< int > *linePositions)
TODO: Document me.
QList< HotSpot * > hotSpotsAtLine(int line) const
Returns the list of hotspots identified by the filter which occur on a given line.
HotSpot * hotSpotAt(int line, int column) const
Adds a new line of text to the filter and increments the line count.
const QString * buffer()
Returns the internal buffer.
QMultiHash< int, HotSpot * > _hotspots
Type
Represents an area of text which matched the pattern a particular filter has been looking for.
const QList< int > * _linePositions
QList< HotSpot * > hotSpots() const
Returns the list of hotspots identified by the filter.
Filter()
Constructs a new filter.
void reset()
Empties the filters internal buffer and resets the line count back to 0.
void getLineColumn(int position, int &startLine, int &startColumn)
Converts a character position within buffer() to a line and column.
void addHotSpot(HotSpot *)
Adds a new hotspot to the list.
A terminal character decoder which produces plain text, ignoring colours and other appearance-related...
void setTrailingWhitespace(bool enable)
Set whether trailing whitespace at the end of lines should be included in the output.
virtual void decodeLine(const Character *const characters, int count, LineProperty properties)
Converts a line of terminal characters with associated properties into a text string and writes the s...
virtual void begin(QTextStream *output)
Begin decoding characters.
virtual void end()
End decoding.
Type of hotspot created by RegExpFilter.
virtual void activate(QObject *object=nullptr)
Causes the an action associated with a hotspot to be triggered.
HotSpot(int startLine, int startColumn, int endLine, int endColumn, Filter::Type)
QStringList capturedTexts() const
Returns the texts found by the filter when matching the filter's regular expression.
void setCapturedTexts(const QStringList &texts)
Sets the captured texts associated with this hotspot.
A filter which searches for sections of text matching a regular expression and creates a new RegExpFi...
virtual void process()
Reimplemented to search the filter's text buffer for text matching regExp()
void setRegExp(const QRegExp &text)
Sets the regular expression which the filter searches for in blocks of text.
void request_edit_mfile_signal(const QString &, int)
QRegExp regExp() const
Returns the regular expression which the filter searches for in blocks of text.
RegExpFilter(Type)
Constructs a new regular expression filter.
void request_open_file_signal(const QString &, int)
virtual RegExpFilter::HotSpot * newHotSpot(int startLine, int startColumn, int endLine, int endColumn, Type)
Called when a match for the regular expression is encountered.
TerminalImageFilterChain()
QList< int > * _linePositions
void setImage(const Character *const image, int lines, int columns, const QVector< LineProperty > &lineProperties)
Set the current terminal image to image.
virtual ~TerminalImageFilterChain()
Hotspot type created by UrlFilter instances.
FilterObject * get_urlObject()
FilterObject * _urlObject
virtual void activate(QObject *object=nullptr)
Open a web browser at the current URL.
virtual QString tooltip() const
Returns the text of a tooltip to be shown when the mouse moves over the hotspot, or an empty string i...
HotSpot(int startLine, int startColumn, int endLine, int endColumn, Type t)
virtual QList< QAction * > actions()
Returns a list of actions associated with the hotspot which can be used in a menu or toolbar.
void request_open_file(const QString &, int)
static const QRegExp FullUrlRegExp
virtual void process()
Reimplemented to search the filter's text buffer for text matching regExp()
static const QRegExp CompleteUrlRegExp
static const QRegExp ErrorLinkRegExp
static const QRegExp ParseErrorLinkRegExp
virtual HotSpot * newHotSpot(int, int, int, int, Type)
Called when a match for the regular expression is encountered.
static const QRegExp CompleteErrorLinkRegExp
static const QRegExp EmailAddressRegExp
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)