1bb02e0acSNicolas Bonnefon /* 2bb02e0acSNicolas Bonnefon * Copyright (C) 2009, 2010 Nicolas Bonnefon and other contributors 3bb02e0acSNicolas Bonnefon * 4bb02e0acSNicolas Bonnefon * This file is part of glogg. 5bb02e0acSNicolas Bonnefon * 6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9bb02e0acSNicolas Bonnefon * (at your option) any later version. 10bb02e0acSNicolas Bonnefon * 11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15bb02e0acSNicolas Bonnefon * 16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18bb02e0acSNicolas Bonnefon */ 19bb02e0acSNicolas Bonnefon 20bb02e0acSNicolas Bonnefon #ifndef FILTERSET_H 21bb02e0acSNicolas Bonnefon #define FILTERSET_H 22bb02e0acSNicolas Bonnefon 23bb02e0acSNicolas Bonnefon #include <QRegExp> 24bb02e0acSNicolas Bonnefon #include <QColor> 25bb02e0acSNicolas Bonnefon #include <QMetaType> 26bb02e0acSNicolas Bonnefon 27bb02e0acSNicolas Bonnefon #include "persistable.h" 28bb02e0acSNicolas Bonnefon 29bb02e0acSNicolas Bonnefon // Represents a filter, i.e. a regexp and the colors matching text 30bb02e0acSNicolas Bonnefon // should be rendered in. 31bb02e0acSNicolas Bonnefon class Filter 32bb02e0acSNicolas Bonnefon { 33bb02e0acSNicolas Bonnefon public: 34bb02e0acSNicolas Bonnefon // Construct an uninitialized Filter (when reading from a config file) 35bb02e0acSNicolas Bonnefon Filter(); 36*b9c9a815SAnton Filimonov Filter(const QString& pattern, bool ignoreCase, 37bb02e0acSNicolas Bonnefon const QString& foreColor, const QString& backColor ); 38bb02e0acSNicolas Bonnefon 39bb02e0acSNicolas Bonnefon // Tests the string passed for a match, returns a value just like 40bb02e0acSNicolas Bonnefon // QRegExp::indexIn (i.e. -1 if no match) 41bb02e0acSNicolas Bonnefon int indexIn( const QString& string ) const; 42bb02e0acSNicolas Bonnefon 43bb02e0acSNicolas Bonnefon // Accessor functions 44bb02e0acSNicolas Bonnefon QString pattern() const; 45bb02e0acSNicolas Bonnefon void setPattern( const QString& pattern ); 46*b9c9a815SAnton Filimonov bool ignoreCase() const; 47*b9c9a815SAnton Filimonov void setIgnoreCase( bool ignoreCase ); 48bb02e0acSNicolas Bonnefon const QString& foreColorName() const; 49bb02e0acSNicolas Bonnefon void setForeColor( const QString& foreColorName ); 50bb02e0acSNicolas Bonnefon const QString& backColorName() const; 51bb02e0acSNicolas Bonnefon void setBackColor( const QString& backColorName ); 52bb02e0acSNicolas Bonnefon 53bb02e0acSNicolas Bonnefon // Operators for serialization 54bb02e0acSNicolas Bonnefon // (must be kept to migrate filters from <=0.8.2) 55bb02e0acSNicolas Bonnefon friend QDataStream& operator<<( QDataStream& out, const Filter& object ); 56bb02e0acSNicolas Bonnefon friend QDataStream& operator>>( QDataStream& in, Filter& object ); 57bb02e0acSNicolas Bonnefon 58bb02e0acSNicolas Bonnefon // Reads/writes the current config in the QSettings object passed 59bb02e0acSNicolas Bonnefon void saveToStorage( QSettings& settings ) const; 60bb02e0acSNicolas Bonnefon void retrieveFromStorage( QSettings& settings ); 61bb02e0acSNicolas Bonnefon 62bb02e0acSNicolas Bonnefon private: 63bb02e0acSNicolas Bonnefon QRegExp regexp_; 64bb02e0acSNicolas Bonnefon QString foreColorName_; 65bb02e0acSNicolas Bonnefon QString backColorName_; 66bb02e0acSNicolas Bonnefon bool enabled_; 67bb02e0acSNicolas Bonnefon }; 68bb02e0acSNicolas Bonnefon 69bb02e0acSNicolas Bonnefon // Represents an ordered set of filters to be applied to each line displayed. 70bb02e0acSNicolas Bonnefon class FilterSet : public Persistable 71bb02e0acSNicolas Bonnefon { 72bb02e0acSNicolas Bonnefon public: 73bb02e0acSNicolas Bonnefon // Construct an empty filter set 74bb02e0acSNicolas Bonnefon FilterSet(); 75bb02e0acSNicolas Bonnefon 76bb02e0acSNicolas Bonnefon // Returns weither the passed line match a filter of the set, 77bb02e0acSNicolas Bonnefon // if so, it returns the fore/back colors the line should use. 78bb02e0acSNicolas Bonnefon // Ownership of the colors is transfered to the caller. 79bb02e0acSNicolas Bonnefon bool matchLine( const QString& line, 80bb02e0acSNicolas Bonnefon QColor* foreColor, QColor* backColor ) const; 81bb02e0acSNicolas Bonnefon 82bb02e0acSNicolas Bonnefon // Reads/writes the current config in the QSettings object passed 83bb02e0acSNicolas Bonnefon virtual void saveToStorage( QSettings& settings ) const; 84bb02e0acSNicolas Bonnefon virtual void retrieveFromStorage( QSettings& settings ); 85bb02e0acSNicolas Bonnefon 86bb02e0acSNicolas Bonnefon // Should be private really, but I don't know how to have 87bb02e0acSNicolas Bonnefon // it recognised by QVariant then. 88bb02e0acSNicolas Bonnefon typedef QList<Filter> FilterList; 89bb02e0acSNicolas Bonnefon 90bb02e0acSNicolas Bonnefon // Operators for serialization 91bb02e0acSNicolas Bonnefon // (must be kept to migrate filters from <=0.8.2) 92bb02e0acSNicolas Bonnefon friend QDataStream& operator<<( 93bb02e0acSNicolas Bonnefon QDataStream& out, const FilterSet& object ); 94bb02e0acSNicolas Bonnefon friend QDataStream& operator>>( 95bb02e0acSNicolas Bonnefon QDataStream& in, FilterSet& object ); 96bb02e0acSNicolas Bonnefon 97bb02e0acSNicolas Bonnefon private: 98bb02e0acSNicolas Bonnefon static const int FILTERSET_VERSION; 99bb02e0acSNicolas Bonnefon 100bb02e0acSNicolas Bonnefon FilterList filterList; 101bb02e0acSNicolas Bonnefon 102bb02e0acSNicolas Bonnefon // To simplify this class interface, FilterDialog can access our 103bb02e0acSNicolas Bonnefon // internal structure directly. 104bb02e0acSNicolas Bonnefon friend class FiltersDialog; 105bb02e0acSNicolas Bonnefon }; 106bb02e0acSNicolas Bonnefon 107bb02e0acSNicolas Bonnefon Q_DECLARE_METATYPE(Filter) 108bb02e0acSNicolas Bonnefon Q_DECLARE_METATYPE(FilterSet) 109bb02e0acSNicolas Bonnefon Q_DECLARE_METATYPE(FilterSet::FilterList) 110bb02e0acSNicolas Bonnefon 111bb02e0acSNicolas Bonnefon #endif 112