30 #include <QApplication>
32 #include <QtCore/QString>
34 #include <QtCore/QSharedData>
42 QMutableListIterator<Filter*> iter(*
this);
44 while ( iter.hasNext() )
62 return contains(filter);
66 QListIterator<Filter*> iter(*
this);
67 while (iter.hasNext())
72 QListIterator<Filter*> iter(*
this);
73 while (iter.hasNext())
74 iter.next()->setBuffer(buffer,linePositions);
78 QListIterator<Filter*> iter(*
this);
79 while (iter.hasNext())
80 iter.next()->process();
88 QListIterator<Filter*> iter(*
this);
89 while (iter.hasNext())
105 QListIterator<Filter*> iter(*
this);
106 while (iter.hasNext())
142 QString* newBuffer =
new QString();
144 setBuffer( newBuffer , newLinePositions );
153 QTextStream lineStream(
_buffer);
154 decoder.
begin(&lineStream);
156 for (
int i=0 ; i < lines ; i++)
172 lineStream << QChar(
'\n');
187 while (iter.hasNext())
217 nextLine =
_buffer->length() + 1;
227 if (
_linePositions->value(i) <= position && position < nextLine )
254 for (
int line = spot->startLine() ;
line <= spot->endLine() ;
line++)
270 QListIterator<HotSpot*> spotIter(
_hotspots.values(line));
272 while (spotIter.hasNext())
274 HotSpot* spot = spotIter.next();
288 : _startLine(startLine)
289 , _startColumn(startColumn)
291 , _endColumn(endColumn)
292 , _type(NotSpecified)
344 _capturedTexts = texts;
348 return _capturedTexts;
372 static const QString emptyString(
"");
399 spot->setCapturedTexts(
_searchText.capturedTexts());
411 int endLine,
int endColumn)
430 QString url = capturedTexts().first();
432 const UrlType kind = urlType();
434 if ( kind == StandardUrl )
436 else if ( kind == Email )
443 QString url = capturedTexts().first();
455 QString url = capturedTexts().first();
457 const UrlType kind = urlType();
459 const QString& actionName =
object ?
object->objectName() : QString();
461 if ( actionName ==
"copy-action" )
465 QApplication::clipboard()->setText(url);
469 if ( !
object || actionName ==
"open-action" )
471 if ( kind == StandardUrl )
475 if (!url.contains(
"://"))
477 url.prepend(
"http://");
480 else if ( kind == Email )
482 url.prepend(
"mailto:");
516 _filter->activate(sender());
522 const UrlType kind = urlType();
524 QAction* openAction =
new QAction(_urlObject);
525 QAction* copyAction =
new QAction(_urlObject);;
527 Q_ASSERT( kind == StandardUrl || kind == Email );
529 if ( kind == StandardUrl )
531 openAction->setText((
"Open Link"));
532 copyAction->setText((
"Copy Link Address"));
534 else if ( kind == Email )
536 openAction->setText((
"Send Email To..."));
537 copyAction->setText((
"Copy Email Address"));
543 openAction->setObjectName(
"open-action");
544 copyAction->setObjectName(
"copy-action");
546 QObject::connect( openAction , SIGNAL(triggered()) , _urlObject , SLOT(activated()) );
547 QObject::connect( copyAction , SIGNAL(triggered()) , _urlObject , SLOT(activated()) );
virtual QList< QAction * > actions()
Returns a list of actions associated with the hotspot which can be used in a menu or toolbar...
int startColumn() const
Returns the column on startLine() where the hotspot area starts.
QStringList capturedTexts() const
Returns the texts found by the filter when matching the filter's regular expression.
static void clear(octave_shlib &oct_file)
int endLine() const
Returns the line where the hotspot area ends.
const QList< int > * _linePositions
void addHotSpot(HotSpot *)
Adds a new hotspot to the list.
void reset()
Resets each filter in the chain.
void clear()
Removes all filters from the chain.
const QString * buffer()
Returns the internal buffer.
HotSpot(int startLine, int startColumn, int endLine, int endColumn)
A single character in the terminal which consists of a unicode character value, foreground and backgr...
void addFilter(Filter *filter)
Adds a new filter to the chain.
void getLineColumn(int position, int &startLine, int &startColumn)
Converts a character position within buffer() to a line and column.
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...
bool containsFilter(Filter *filter)
Returns true if the chain contains filter.
Represents an area of text which matched the pattern a particular filter has been looking for...
Filter::HotSpot * hotSpotAt(int line, int column) const
Returns the first hotspot which occurs at line, column or 0 if no hotspot was found.
A filter which searches for sections of text matching a regular expression and creates a new RegExpFi...
QList< int > * _linePositions
virtual ~TerminalImageFilterChain()
QRegExp regExp() const
Returns the regular expression which the filter searches for in blocks of text.
A filter processes blocks of text looking for certain patterns (such as URLs or keywords from a list)...
int startLine() const
Returns the line when the hotspot area starts.
void process()
Processes each filter in the chain.
virtual RegExpFilter::HotSpot * newHotSpot(int startLine, int startColumn, int endLine, int endColumn)
Called when a match for the regular expression is encountered.
HotSpot(int startLine, int startColumn, int endLine, int endColumn)
Constructs a new hotspot which covers the area from (startLine,startColumn) to (endLine,endColumn) in a block of text.
QList< HotSpot * > hotSpotsAtLine(int line) const
Returns the list of hotspots identified by the filter which occur on a given line.
virtual QList< QAction * > actions()
Returns a list of actions associated with the hotspot which can be used in a menu or toolbar...
QList< HotSpot * > _hotspotList
QList< Filter::HotSpot * > hotSpots() const
Returns a list of all the hotspots in all the chain's filters.
HotSpot(int startLine, int startColumn, int endLine, int endColumn)
virtual void process()
Reimplemented to search the filter's text buffer for text matching regExp()
static const int LINE_WRAPPED
void setBuffer(const QString *buffer, const QList< int > *linePositions)
Sets the buffer for each filter in the chain to process.
A terminal character decoder which produces plain text, ignoring colours and other appearance-related...
QList< HotSpot * > hotSpots() const
Returns the list of hotspots identified by the filter.
void reset()
Empties the filters internal buffer and resets the line count back to 0.
virtual RegExpFilter::HotSpot * newHotSpot(int, int, int, int)
Called when a match for the regular expression is encountered.
void setType(Type type)
Sets the type of a hotspot.
Filter()
Constructs a new filter.
HotSpot * hotSpotAt(int line, int column) const
Adds a new line of text to the filter and increments the line count.
MArray< double > filter(MArray< double > &, MArray< double > &, MArray< double > &, int dim)
TerminalImageFilterChain()
static const QRegExp EmailAddressRegExp
void setRegExp(const QRegExp &text)
Sets the regular expression which the filter searches for in blocks of text.
static const QRegExp FullUrlRegExp
RegExpFilter()
Constructs a new regular expression filter.
virtual void activate(QObject *object=0)
Open a web browser at the current URL.
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...
void removeFilter(Filter *filter)
Removes a filter from the chain.
Type of hotspot created by RegExpFilter.
void setTrailingWhitespace(bool enable)
Set whether trailing whitespace at the end of lines should be included in the output.
static const QRegExp CompleteUrlRegExp
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...
void setImage(const Character *const image, int lines, int columns, const QVector< LineProperty > &lineProperties)
Set the current terminal image to image.
static const int LINE_DEFAULT
int endColumn() const
Returns the column on endLine() where the hotspot area ends.
void setBuffer(const QString *buffer, const QList< int > *linePositions)
TODO: Document me.
virtual void end()
End decoding.
Type type() const
Returns the type of the hotspot.
void setCapturedTexts(const QStringList &texts)
Sets the captured texts associated with this hotspot.
QMultiHash< int, HotSpot * > _hotspots
virtual void begin(QTextStream *output)
Begin decoding characters.
virtual void activate(QObject *object=0)
Causes the an action associated with a hotspot to be triggered.
Hotspot type created by UrlFilter instances.