File indexing completed on 2024-10-06 03:29:14

0001 /*
0002     SPDX-FileCopyrightText: 2021 Valentin Boettcher <hiro at protagon.space; @hiro98:tchncs.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef CATALOGCOLOREDITOR_H
0008 #define CATALOGCOLOREDITOR_H
0009 
0010 #include <QDialog>
0011 #include "catalogsdb.h"
0012 
0013 namespace Ui
0014 {
0015 class CatalogColorEditor;
0016 }
0017 
0018 /**
0019  * A form for editing catalog color scheme mappings.
0020  *
0021  * If the constructor with the id is used, the dialog takes care of
0022  * editing the database. Otherwise `CatalogColorEditor::colors` may be
0023  * used.
0024  */
0025 class CatalogColorEditor : public QDialog
0026 {
0027     Q_OBJECT
0028     using color_map = CatalogsDB::CatalogColorMap;
0029 
0030   public:
0031     explicit CatalogColorEditor(const int id, QWidget *parent = nullptr);
0032     explicit CatalogColorEditor(color_map colors, QWidget *parent = nullptr);
0033     explicit CatalogColorEditor(const QString &colors, QWidget *parent = nullptr);
0034 
0035     ~CatalogColorEditor();
0036 
0037     color_map colors() { return m_colors; }
0038     QString color_string() { return CatalogsDB::to_color_string(m_colors); };
0039 
0040   private:
0041     Ui::CatalogColorEditor *ui;
0042     color_map m_colors;
0043     int m_id;
0044 
0045     void writeColors();
0046     void init();
0047     void make_color_button(const QString &name, const QColor &color);
0048 };
0049 
0050 #endif // CATALOGCOLOREDITOR_H