GobChartsWidget  1.0
gobchartscolours.cpp
1 /* Copyright (C) 2012 by William Hallatt.
2  *
3  * This file forms part of the "GobChartsWidget" library.
4  *
5  * This library is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have downloaded a copy of the GNU General Public License
16  * (GNUGPL.txt) and GNU Lesser General Public License (GNULGPL.txt)
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * The official website for this project is www.goblincoding.com and,
20  * although not compulsory, it would be appreciated if all works of whatever
21  * nature referring to or using this library include a reference to this site.
22  */
23 
24 #include "gobchartscolours.h"
25 
26 /*--------------------------------------------------------------------------------*/
27 
28 namespace GobChartsColours
29 {
30  namespace{
31  /* Random colour generation had limited success so I decided to rather opt for a fixed list of colours to ensure that
32  no two colours are the same. I believe this list should prove sufficient for most applications */
33  const QList<QColor> colourList = QList<QColor>()
34  << QColor(25,121,39) << QColor(237,147,21) << QColor(238,65,21)
35  << QColor(232,22,21) << QColor(228,20,186) << QColor(20,25,222) << QColor(149,14,129)
36  << QColor(79,155,29) << QColor(237,169,20) << QColor(238,96,32)
37  << QColor(231,49,57) << QColor(243,51,205) << QColor(33,81,220) << QColor(169,41,149)
38  << QColor(91,176,34) << QColor(237,191,21) << QColor(238,125,47)
39  << QColor(243,42,51) << QColor(244,82,212) << QColor(69,107,217) << QColor(164,64,149)
40  << QColor(109,212,41) << QColor(238,182,82) << QColor(251,65,74)
41  << QColor(237,22,20) << QColor(244,158,212) << QColor(109,138,181) << QColor(167,96,156);
42 
43  int colourIndex(-1); // will be set to 0 on first getNextColour call
44  }
45 
46 /*--------------------------------------------------------------------------------*/
47 
48  QColor getNextColour()
49  {
50  if( colourIndex == ( colourList.size() - 1 ) )
51  {
52  colourIndex = 0; // end of list, reset
53  }
54  else
55  {
56  colourIndex++;
57  }
58 
59  return QColor( colourList.at( colourIndex ) );
60  }
61 
62 /*--------------------------------------------------------------------------------*/
63 
65  {
66  colourIndex = -1;
67  }
68 
69 /*--------------------------------------------------------------------------------*/
70 
71 }