kalarm/lib

colourlist.h

00001 /*
00002  *  colourlist.h  -  an ordered list of colours
00003  *  Program:  kalarm
00004  *  Copyright (C) 2003, 2005 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef COLOURLIST_H
00022 #define COLOURLIST_H
00023 
00024 #include <qtl.h>
00025 #include <qcolor.h>
00026 #include <qvaluelist.h>
00027 
00028 
00039 class ColourList
00040 {
00041     public:
00042         typedef size_t  size_type;
00043         typedef QValueListConstIterator<QRgb>  const_iterator;
00044 
00046         ColourList()  { }
00048         ColourList(const ColourList& l)       : mList(l.mList) { }
00050         ColourList(const QValueList<QRgb>& list) : mList(list) { qHeapSort(mList); }
00054         ColourList(const QColor* list);
00056         ColourList&    operator=(const ColourList& l)        { mList = l.mList;  return *this; }
00058         ColourList&    operator=(const QValueList<QRgb>& list) { mList = list;  qHeapSort(mList);  return *this; }
00060         void           clear()                               { mList.clear(); }
00062         void           insert(const QColor& c);
00064         void           remove(const QColor& c)               { mList.remove(c.rgb()); }
00066         ColourList&    operator+=(const QColor& c)           { insert(c);  return *this; }
00068         ColourList&    operator+=(const ColourList& list)    { mList += list.mList;  qHeapSort(mList);  return *this; }
00070         bool           operator==(const ColourList& l) const { return mList == l.mList; }
00072         bool           operator!=(const ColourList& l) const { return mList != l.mList; }
00074         size_type      count() const                         { return mList.count(); }
00076         bool           isEmpty() const                       { return mList.isEmpty(); }
00078         const_iterator begin() const                         { return mList.begin(); }
00080         const_iterator end() const                           { return mList.end(); }
00082         const_iterator fromLast() const                      { return mList.fromLast(); }
00084         const_iterator at(size_type i) const                 { return mList.at(i); }
00086         size_type      contains(const QColor& c) const       { return mList.contains(c.rgb()); }
00090         const_iterator find(const QColor& c) const           { return mList.find(c.rgb()); }
00094         const_iterator find(const_iterator it, const QColor& c) const   { return mList.find(it, c.rgb()); }
00098         int            findIndex(const QColor& c) const      { return mList.findIndex(c.rgb()); }
00100         QColor         first() const                         { return QColor(mList.first()); }
00102         QColor         last() const                          { return QColor(mList.last()); }
00104         QColor         operator[](size_type i) const         { return QColor(mList[i]); }
00105     private:
00106         void              sort();
00107         QValueList<QRgb>  mList;
00108 };
00109 
00110 #endif // COLOURLIST_H
KDE Home | KDE Accessibility Home | Description of Access Keys