update version
[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(0x60, 0x60, 0xa8);
27     s << QColor(0xf6, 0xf6, 0x1d);
28     s << QColor(0x46, 0xb0, 0xe0);
29     s << QColor(0x7e, 0xa0, 0x20);
30     s << QColor(0xf0, 0x70, 0xa0);
31     s << QColor(0xdc, 0x4a, 0x20);
32     /*: default color scheme name */
33     schemes << QPair<QString, QVector<QBrush> >(QObject::tr("Default scheme"), s);
34
35     s.clear();
36     s << QBrush(QColor(0x00, 0x00, 0x00), Qt::SolidPattern);
37     s << QBrush(QColor(0x20, 0x20, 0x20), Qt::Dense3Pattern);
38     s << QBrush(QColor(0x66, 0x66, 0x66), Qt::Dense1Pattern);
39     s << QBrush(QColor(0x99, 0x99, 0x99), Qt::SolidPattern);
40     s << QBrush(QColor(0xcc, 0xcc, 0xcc), Qt::CrossPattern);
41     s << QBrush(QColor(0xff, 0xff, 0xff), Qt::SolidPattern);
42     /*: black-and-white color scheme name */
43     schemes << QPair<QString, QVector<QBrush> >(QObject::tr("Black-and-white scheme"), s);
44
45     QSettings settings;
46     currentScheme = settings.value("colorScheme", 0).toInt();
47
48     if (currentScheme < 0 || currentScheme > s.size())
49         currentScheme = 0;
50 }
51
52 ColorScheme::~ColorScheme ()
53 {
54     QSettings settings;
55     settings.setValue("colorScheme", currentScheme);
56 }
57
58 int ColorScheme::getNumSchemes ()
59 {
60     return schemes.size();
61 }
62
63 int ColorScheme::getNextColorScheme ()
64 {
65     return (currentScheme + 1) % schemes.size();
66 }
67
68 QString ColorScheme::getSchemeName (int scheme)
69 {
70     Q_ASSERT(scheme >= 0 && scheme < getNumSchemes());
71     return schemes.at(scheme).first;
72 }
73
74 const QVector<QBrush> &ColorScheme::getScheme (int scheme)
75 {
76     Q_ASSERT(scheme > 0 && scheme < getNumSchemes());
77     return schemes.at(scheme).second;
78 }
79
80 QString ColorScheme::getSchemeName ()
81 {
82     return schemes.at(currentScheme).first;
83 }
84
85 const QVector<QBrush> &ColorScheme::getScheme ()
86 {
87     return schemes.at(currentScheme).second;
88 }
89
90 void ColorScheme::setScheme (int scheme)
91 {
92     Q_ASSERT(scheme >= 0 && scheme < getNumSchemes());
93     currentScheme = scheme;
94 }