kalarm/lib

colourlist.h
1/*
2 * colourlist.h - an ordered list of colours
3 * Program: kalarm
4 * Copyright (C) 2003, 2005 by David Jarvie <software@astrojar.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef COLOURLIST_H
22#define COLOURLIST_H
23
24#include <tqtl.h>
25#include <tqcolor.h>
26#include <tqvaluelist.h>
27
28
40{
41 public:
42 typedef size_t size_type;
43 typedef TQValueListConstIterator<TQRgb> const_iterator;
44
48 ColourList(const ColourList& l) : mList(l.mList) { }
50 ColourList(const TQValueList<TQRgb>& list) : mList(list) { qHeapSort(mList); }
54 ColourList(const TQColor* list);
56 ColourList& operator=(const ColourList& l) { mList = l.mList; return *this; }
58 ColourList& operator=(const TQValueList<TQRgb>& list) { mList = list; qHeapSort(mList); return *this; }
60 void clear() { mList.clear(); }
62 void insert(const TQColor& c);
64 void remove(const TQColor& c) { mList.remove(c.rgb()); }
66 ColourList& operator+=(const TQColor& c) { insert(c); return *this; }
68 ColourList& operator+=(const ColourList& list) { mList += list.mList; qHeapSort(mList); return *this; }
70 bool operator==(const ColourList& l) const { return mList == l.mList; }
72 bool operator!=(const ColourList& l) const { return mList != l.mList; }
74 size_type count() const { return mList.count(); }
76 bool isEmpty() const { return mList.isEmpty(); }
78 const_iterator begin() const { return mList.begin(); }
80 const_iterator end() const { return mList.end(); }
82 const_iterator fromLast() const { return mList.fromLast(); }
84 const_iterator at(size_type i) const { return mList.at(i); }
86 size_type contains(const TQColor& c) const { return mList.contains(c.rgb()); }
90 const_iterator find(const TQColor& c) const { return mList.find(c.rgb()); }
94 const_iterator find(const_iterator it, const TQColor& c) const { return mList.find(it, c.rgb()); }
98 int findIndex(const TQColor& c) const { return mList.findIndex(c.rgb()); }
100 TQColor first() const { return TQColor(mList.first()); }
102 TQColor last() const { return TQColor(mList.last()); }
104 TQColor operator[](size_type i) const { return TQColor(mList[i]); }
105 private:
106 void sort();
107 TQValueList<TQRgb> mList;
108};
109
110#endif // COLOURLIST_H
Represents a sorted list of colours.
Definition: colourlist.h:40
ColourList()
Constructs an empty list.
Definition: colourlist.h:46
void remove(const TQColor &c)
Removes the colour c from the list.
Definition: colourlist.h:64
size_type contains(const TQColor &c) const
Returns true if the list contains the colour c.
Definition: colourlist.h:86
void clear()
Removes all values from the list.
Definition: colourlist.h:60
size_type count() const
Returns the number of colours in the list.
Definition: colourlist.h:74
TQColor operator[](size_type i) const
Returns the colour at position i in the list.
Definition: colourlist.h:104
TQColor last() const
Returns the last colour in the list.
Definition: colourlist.h:102
const_iterator begin() const
Returns an iterator pointing to the first colour in the list.
Definition: colourlist.h:78
ColourList & operator=(const TQValueList< TQRgb > &list)
Sets the list to comprise the colours in list.
Definition: colourlist.h:58
const_iterator end() const
Returns an iterator pointing past the last colour in the list.
Definition: colourlist.h:80
ColourList & operator+=(const ColourList &list)
Adds the colours in list to this list.
Definition: colourlist.h:68
bool operator==(const ColourList &l) const
Returns true if the colours in the two lists are the same.
Definition: colourlist.h:70
ColourList & operator+=(const TQColor &c)
Adds the specified colour c to the list.
Definition: colourlist.h:66
int findIndex(const TQColor &c) const
Returns the index to the first occurrence of colour c in the list.
Definition: colourlist.h:98
const_iterator find(const TQColor &c) const
Returns an iterator pointing to the first occurrence of colour c in the list.
Definition: colourlist.h:90
bool operator!=(const ColourList &l) const
Returns true if the colours in the two lists differ.
Definition: colourlist.h:72
bool isEmpty() const
Returns true if the list is empty.
Definition: colourlist.h:76
ColourList(const TQValueList< TQRgb > &list)
Constructs a list whose values are preset to the colours in list.
Definition: colourlist.h:50
ColourList & operator=(const ColourList &l)
Assignment operator.
Definition: colourlist.h:56
const_iterator fromLast() const
Returns an iterator pointing to the last colour in the list, or end() if the list is empty.
Definition: colourlist.h:82
TQColor first() const
Returns the first colour in the list.
Definition: colourlist.h:100
ColourList(const ColourList &l)
Copy constructor.
Definition: colourlist.h:48
const_iterator at(size_type i) const
Returns an iterator pointing to the colour at position i in the list.
Definition: colourlist.h:84
const_iterator find(const_iterator it, const TQColor &c) const
Returns an iterator pointing to the first occurrence of colour c in the list, starting.
Definition: colourlist.h:94
void insert(const TQColor &c)
Adds the specified colour c to the list.
Definition: colourlist.cpp:30