use russian tr if current language is russian
[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     /*: default color scheme name */
33     schemes << QPair<QString, QVector<QBrush> >(QObject::tr("Default"), s);
34
35     s.clear();
36     s << QBrush(QColor(0x00, 0x00, 0x00), Qt::SolidPattern);
37     s << QBrush(QColor(0x33, 0x33, 0x33), 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"), 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 QString ColorScheme::getSchemeName (int scheme)
64 {
65     Q_ASSERT(scheme > 0 && scheme < getNumSchemes());
66     return schemes.at(scheme).first;
67 }
68
69 const QVector<QBrush> &ColorScheme::getScheme (int scheme)
70 {
71     Q_ASSERT(scheme > 0 && scheme < getNumSchemes());
72     return schemes.at(scheme).second;
73 }
74
75 QString ColorScheme::getSchemeName ()
76 {
77     return schemes.at(currentScheme).first;
78 }
79
80 const QVector<QBrush> &ColorScheme::getScheme ()
81 {
82     return schemes.at(currentScheme).second;
83 }
84
85 void ColorScheme::setScheme (int scheme)
86 {
87     Q_ASSERT(scheme >= 0 && scheme < getNumSchemes());
88     currentScheme = scheme;
89 }