File indexing completed on 2024-12-08 12:08:59
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 #include "catalogeditform.h" 0008 #include "dialogs/catalogcoloreditor.h" 0009 #include "kstarsdata.h" 0010 #include "ui_catalogeditform.h" 0011 #include "catalogsdb.h" 0012 #include <QColorDialog> 0013 0014 CatalogEditForm::CatalogEditForm(QWidget *parent, const CatalogsDB::Catalog &catalog, 0015 const int min_id, const bool allow_id_edit) 0016 : QDialog(parent), ui(new Ui::CatalogEditForm), m_catalog{ catalog } 0017 { 0018 ui->setupUi(this); 0019 ui->id->setMinimum(min_id); 0020 ui->id->setEnabled(allow_id_edit); 0021 0022 fill_form_from_catalog(); 0023 connect(ui->id, QOverload<int>::of(&QSpinBox::valueChanged), 0024 [&](const int id) { m_catalog.id = id; }); 0025 0026 connect(ui->name, &QLineEdit::textChanged, 0027 [&](const QString &s) { m_catalog.name = s; }); 0028 0029 connect(ui->author, &QLineEdit::textChanged, 0030 [&](const QString &s) { m_catalog.author = s; }); 0031 0032 connect(ui->source, &QLineEdit::textChanged, 0033 [&](const QString &s) { m_catalog.source = s; }); 0034 0035 connect(ui->description, &QTextEdit::textChanged, 0036 [&]() { m_catalog.description = ui->description->toHtml(); }); 0037 0038 connect(ui->license, &QLineEdit::textChanged, 0039 [&](const QString &s) { m_catalog.license = s; }); 0040 0041 connect(ui->maintainer, &QLineEdit::textChanged, 0042 [&](const QString &s) { m_catalog.maintainer = s; }); 0043 0044 connect(ui->color, &QPushButton::clicked, [&]() { 0045 CatalogColorEditor editor{ 0046 m_catalog.color == "" ? 0047 KStarsData::Instance()->colorScheme()->colorNamed("DSOColor").name() : 0048 m_catalog.color 0049 }; 0050 0051 if (editor.exec() != QDialog::Accepted) 0052 return; 0053 0054 m_catalog.color = editor.color_string(); 0055 }); 0056 } 0057 0058 CatalogEditForm::~CatalogEditForm() 0059 { 0060 delete ui; 0061 } 0062 0063 void CatalogEditForm::fill_form_from_catalog() 0064 { 0065 ui->id->setValue(m_catalog.id); 0066 ui->name->setText(m_catalog.name); 0067 ui->author->setText(m_catalog.author); 0068 ui->source->setText(m_catalog.source); 0069 ui->description->setHtml(m_catalog.description); 0070 ui->license->setText(m_catalog.license); 0071 ui->maintainer->setText(m_catalog.maintainer); 0072 }