File indexing completed on 2024-11-24 03:56:28

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include "custom_settings_group.hpp"
0010 
0011 #include <QPalette>
0012 #include <QMap>
0013 
0014 namespace app::settings {
0015 
0016 class PaletteSettings : public CustomSettingsGroupBase
0017 {
0018 public:
0019     class Palette : public QPalette
0020     {
0021     public:
0022         Palette() = default;
0023         Palette(const QPalette& oth, bool built_in = false) : QPalette(oth), built_in(built_in) {}
0024         Palette(QPalette&& oth, bool built_in = false) : QPalette(std::move(oth)), built_in(built_in) {}
0025         Palette(const Palette& oth) : QPalette(oth), built_in(oth.built_in) {}
0026         Palette(Palette&& oth) : QPalette(std::move(oth)), built_in(oth.built_in) {}
0027         Palette& operator=(const Palette& oth)
0028         {
0029             QPalette::operator=(oth);
0030             built_in = oth.built_in;
0031             return *this;
0032         }
0033         Palette& operator=(Palette&& oth)
0034         {
0035             QPalette::operator=(std::move(oth));
0036             built_in = oth.built_in;
0037             return *this;
0038         }
0039         Palette& operator=(const QPalette& oth)
0040         {
0041             QPalette::operator=(oth);
0042             return *this;
0043         }
0044         Palette& operator=(QPalette&& oth)
0045         {
0046             QPalette::operator=(std::move(oth));
0047             return *this;
0048         }
0049 
0050         bool built_in = false;
0051     };
0052 
0053     PaletteSettings();
0054 
0055     QString slug() const override;
0056     QString label() const override;
0057     QIcon icon() const override;
0058     void load ( QSettings & settings ) override;
0059     void save ( QSettings & settings ) override;
0060     QWidget * make_widget ( QWidget * parent ) override;
0061 
0062     void load_palette(const QSettings& settings, bool mark_built_in = false);
0063     void write_palette(QSettings& settings, const QString& name, const QPalette& palette);
0064 
0065     const QPalette& palette() const;
0066 
0067     static const std::vector<std::pair<QString, QPalette::ColorRole>>& roles();
0068 
0069     void set_selected(const QString& name);
0070     void apply_palette(const QPalette& palette);
0071     void set_style(const QString& name);
0072 
0073     static QString color_to_string(const QColor& c);
0074     static QColor string_to_color(const QString& s);
0075 
0076     QMap<QString, Palette> palettes;
0077     QString selected;
0078     Palette default_palette;
0079     QString style;
0080 };
0081 
0082 } // namespace app::settings