• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

Filter.h

Go to the documentation of this file.
00001 /*
00002     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301  USA.
00018 */
00019 
00020 #ifndef FILTER_H
00021 #define FILTER_H
00022 
00023 // Qt
00024 #include <QtGui/QAction>
00025 #include <QtCore/QList>
00026 #include <QtCore/QObject>
00027 #include <QtCore/QStringList>
00028 #include <QtCore/QHash>
00029 #include <QtCore/QRegExp>
00030 
00031 // Local
00032 #include "Character.h"
00033 
00034 namespace Konsole
00035 {
00036 
00055 class Filter
00056 {
00057 public:
00070     class HotSpot
00071     {
00072     public:
00077        HotSpot(int startLine , int startColumn , int endLine , int endColumn);
00078        virtual ~HotSpot();
00079 
00080        enum Type
00081        {
00082             // the type of the hotspot is not specified
00083             NotSpecified,
00084             // this hotspot represents a clickable link
00085             Link,
00086             // this hotspot represents a marker
00087             Marker
00088        }; 
00089 
00091        int startLine() const;
00093        int endLine() const;
00095        int startColumn() const;
00097        int endColumn() const;
00102        Type type() const;
00111        virtual void activate(QObject* object = 0) = 0; 
00116        virtual QList<QAction*> actions();
00117 
00124        virtual QString tooltip() const;
00125 
00126     protected:
00128        void setType(Type type);
00129 
00130     private:
00131        int    _startLine;
00132        int    _startColumn;
00133        int    _endLine;
00134        int    _endColumn;
00135        Type _type;
00136     
00137     };
00138 
00140     Filter();
00141     virtual ~Filter();
00142 
00144     virtual void process() = 0;
00145 
00150     void reset();
00151 
00153     //void addLine(const QString& string);
00154 
00156     HotSpot* hotSpotAt(int line , int column) const;
00157 
00159     QList<HotSpot*> hotSpots() const;
00160 
00162     QList<HotSpot*> hotSpotsAtLine(int line) const;
00163 
00167     void setBuffer(const QString* buffer , const QList<int>* linePositions);
00168 
00169 protected:
00171     void addHotSpot(HotSpot*);
00173     const QString* buffer();
00175     void getLineColumn(int position , int& startLine , int& startColumn);
00176 
00177 private:
00178     QMultiHash<int,HotSpot*> _hotspots;
00179     QList<HotSpot*> _hotspotList;
00180     
00181     const QList<int>* _linePositions;
00182     const QString* _buffer;
00183 };
00184 
00192 class RegExpFilter : public Filter
00193 {
00194 public:
00199     class HotSpot : public Filter::HotSpot
00200     {
00201     public:
00202         HotSpot(int startLine, int startColumn, int endLine , int endColumn);
00203         virtual void activate(QObject* object = 0);
00204 
00206         void setCapturedTexts(const QStringList& texts);
00208         QStringList capturedTexts() const;
00209     private:
00210         QStringList _capturedTexts;
00211     };
00212 
00214     RegExpFilter();
00215 
00222     void setRegExp(const QRegExp& text);
00224     QRegExp regExp() const;
00225 
00232     virtual void process();
00233 
00234 protected:
00239     virtual RegExpFilter::HotSpot* newHotSpot(int startLine,int startColumn,
00240                                     int endLine,int endColumn);
00241 
00242 private:
00243     QRegExp _searchText;
00244 };
00245 
00246 class FilterObject;
00247 
00249 class UrlFilter : public RegExpFilter 
00250 {
00251 public:
00256     class HotSpot : public RegExpFilter::HotSpot 
00257     {
00258     public:
00259         HotSpot(int startLine,int startColumn,int endLine,int endColumn);
00260         virtual ~HotSpot();
00261 
00262         virtual QList<QAction*> actions();
00263 
00268         virtual void activate(QObject* object = 0);
00269 
00270         virtual QString tooltip() const;
00271     private:
00272         enum UrlType
00273         {
00274             StandardUrl,
00275             Email,
00276             Unknown
00277         };
00278         UrlType urlType() const;
00279 
00280         FilterObject* _urlObject;
00281     };
00282 
00283     UrlFilter();
00284 
00285 protected:
00286     virtual RegExpFilter::HotSpot* newHotSpot(int,int,int,int);
00287 
00288 private:
00289     
00290     static const QRegExp FullUrlRegExp;
00291     static const QRegExp EmailAddressRegExp;
00292 
00293     // combined OR of FullUrlRegExp and EmailAddressRegExp
00294     static const QRegExp CompleteUrlRegExp; 
00295 };
00296 
00297 class FilterObject : public QObject
00298 {
00299 Q_OBJECT
00300 public:
00301     FilterObject(Filter::HotSpot* filter) : _filter(filter) {}
00302 private slots:
00303     void activated();
00304 private:
00305     Filter::HotSpot* _filter;
00306 };
00307 
00325 class FilterChain : protected QList<Filter*>
00326 {
00327 public:
00328     virtual ~FilterChain();
00329 
00331     void addFilter(Filter* filter);
00333     void removeFilter(Filter* filter);
00335     bool containsFilter(Filter* filter);
00337     void clear();
00338 
00340     void reset();
00344     void process();
00345 
00347     void setBuffer(const QString* buffer , const QList<int>* linePositions); 
00348 
00350     Filter::HotSpot* hotSpotAt(int line , int column) const;
00352     QList<Filter::HotSpot*> hotSpots() const;
00354     QList<Filter::HotSpot> hotSpotsAtLine(int line) const;
00355 
00356 };
00357 
00359 class TerminalImageFilterChain : public FilterChain
00360 {
00361 public:
00362     TerminalImageFilterChain();
00363     virtual ~TerminalImageFilterChain();
00364 
00372     void setImage(const Character* const image , int lines , int columns,
00373                   const QVector<LineProperty>& lineProperties);  
00374 
00375 private:
00376     QString* _buffer;
00377     QList<int>* _linePositions;
00378 };
00379 
00380 }
00381 #endif //FILTER_H

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal