File indexing completed on 2024-11-24 03:43:19

0001 /*******************************************************************
0002 *
0003 * Copyright 2007  Aron Boström <c02ab@efd.lth.se>
0004 *
0005 * Bovo is free software; you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation; either version 2, or (at your option)
0008 * any later version.
0009 *
0010 * Bovo is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with Bovo; see the file COPYING.  If not, write to
0017 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
0018 * Boston, MA 02110-1301, USA.
0019 *
0020 ********************************************************************/
0021 
0022 
0023 #include "theme.h"
0024 
0025 #include "settings.h"
0026 
0027 #include <KConfig>
0028 #include <KConfigGroup>
0029 #include <KDesktopFile>
0030 
0031 #include <QStandardPaths>
0032 
0033 namespace gui {
0034 
0035 Theme::Theme() = default;
0036 
0037 Theme::Theme(const QString& path, const int id)
0038   : m_id(id), m_path(path) {
0039     QString themePath = QStringLiteral("themes/%1/").arg(m_path);
0040             themePath = QStandardPaths::locate(QStandardPaths::AppDataLocation, themePath, QStandardPaths::LocateDirectory);
0041     QString themerc = themePath + QLatin1String("themerc");
0042     KDesktopFile themeConfig(themerc);
0043     m_name = themeConfig.readName();
0044     m_comment = themeConfig.readComment();
0045 
0046     KConfig config(themerc);
0047     KConfigGroup configGroup(&config, QStringLiteral("Config"));
0048     m_backgroundColor = configGroup.readEntry("BackgroundColor", "white");
0049     m_fill = configGroup.readEntry("Fill", 0.75);
0050     m_gridColor = configGroup.readEntry("GridColor", "black");
0051 
0052     QString gridTypeStr = configGroup.readEntry("GridType", "svg");
0053     if (gridTypeStr == QLatin1String("svg")) {
0054         m_gridType = SvgGrid;
0055     } else if (gridTypeStr == QLatin1String("gomoku")) {
0056         m_gridType = GomokuGrid;
0057     } else if (gridTypeStr == QLatin1String("squares")) {
0058         m_gridType = SquaresGrid;
0059     }
0060 
0061     m_svg = themePath + configGroup.readEntry("Svg", "theme.svg");
0062 }
0063 
0064 QColor Theme::backgroundColor() const {
0065     return m_backgroundColor;
0066 }
0067 
0068 QString Theme::comment() const {
0069     return m_comment;
0070 }
0071 
0072 qreal Theme::fill() const {
0073     return m_fill;
0074 }
0075 
0076 QColor Theme::gridColor() const {
0077     return m_gridColor;
0078 }
0079 
0080 GridType Theme::gridType() const {
0081     return m_gridType;
0082 }
0083 
0084 int Theme::id() const {
0085     return m_id;
0086 }
0087 
0088 QString Theme::name() const {
0089     return m_name;
0090 }
0091 
0092 QString Theme::path() const {
0093     return m_path;
0094 }
0095 
0096 QString Theme::svg() const {
0097     return m_svg;
0098 }
0099 
0100 
0101 
0102 } /* namespace gui */