c7cd4bed449eaf5d088383863786d36d925d623b
[colorflood] / colorflood / src / colorscheme.cpp
1 /*
2   Copyright 2010 Serge Ziryukin <ftrvxmtrx@gmail.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; version 2 of the License.
7
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   GNU General Public License for more details.
12 */
13
14 #include <QSettings>
15 #include "colorscheme.hpp"
16
17 static int currentScheme = 0;
18 static QVector<QPair<QString, QVector<QBrush> > > schemes;
19
20 ColorScheme::ColorScheme ()
21 {
22     schemes.clear();
23
24     QVector<QBrush> s;
25
26     s << QColor(0x00, 0x00, 0xff); // blue
27     s << QColor(0xff, 0x00, 0x00); // red
28     s << QColor(0x00, 0xff, 0x00); // green
29     s << QColor(0xff, 0xff, 0x00); // yellow
30     s << QColor(0xff, 0x00, 0xff); // magenta
31     s << QColor(0x80, 0x00, 0x80); // purple
32     schemes << QPair<QString, QVector<QBrush> >(QObject::tr("Default"), s);
33
34     s.clear();
35     s << QBrush(QColor(0x00, 0x00, 0x00), Qt::SolidPattern);
36     s << QBrush(QColor(0x33, 0x33, 0x33), Qt::Dense3Pattern);
37     s << QBrush(QColor(0x66, 0x66, 0x66), Qt::Dense1Pattern);
38     s << QBrush(QColor(0x99, 0x99, 0x99), Qt::SolidPattern);
39     s << QBrush(QColor(0xcc, 0xcc, 0xcc), Qt::CrossPattern);
40     s << QBrush(QColor(0xff, 0xff, 0xff), Qt::SolidPattern);
41     schemes << QPair<QString, QVector<QBrush> >(QObject::tr("Black-and-white"), s);
42
43     QSettings settings;
44     currentScheme = settings.value("colorScheme", 0).toInt();
45
46     if (currentScheme < 0 || currentScheme > s.size())
47         currentScheme = 0;
48 }
49
50 ColorScheme::~ColorScheme ()
51 {
52     QSettings settings;
53     settings.setValue("colorScheme", currentScheme);
54 }
55
56 int ColorScheme::getNumSchemes ()
57 {
58     return schemes.size();
59 }
60
61 QString ColorScheme::getSchemeName (int scheme)
62 {
63     Q_ASSERT(scheme > 0 && scheme < getNumSchemes());
64     return schemes.at(scheme).first;
65 }
66
67 const QVector<QBrush> &ColorScheme::getScheme (int scheme)
68 {
69     Q_ASSERT(scheme > 0 && scheme < getNumSchemes());
70     return schemes.at(scheme).second;
71 }
72
73 QString ColorScheme::getSchemeName ()
74 {
75     return schemes.at(currentScheme).first;
76 }
77
78 const QVector<QBrush> &ColorScheme::getScheme ()
79 {
80     return schemes.at(currentScheme).second;
81 }
82
83 void ColorScheme::setScheme (int scheme)
84 {
85     Q_ASSERT(scheme >= 0 && scheme < getNumSchemes());
86     currentScheme = scheme;
87 }