File indexing completed on 2025-01-26 05:24:22
0001 /* 0002 This file is part of the Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2009, 2013 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "createdialog.hpp" 0010 0011 // Kasten gui 0012 #include <abstractmodeldatageneratorconfigeditor.hpp> 0013 // KF 0014 #include <KLocalizedString> 0015 // Qt 0016 #include <QVBoxLayout> 0017 #include <QLabel> 0018 #include <QPushButton> 0019 #include <QIcon> 0020 #include <QFont> 0021 #include <QDialogButtonBox> 0022 0023 namespace Kasten { 0024 0025 CreateDialog::CreateDialog(AbstractModelDataGeneratorConfigEditor* configEditor, 0026 AbstractModelDataGenerator* generator, 0027 QWidget* parent) 0028 : QDialog(parent) 0029 , mConfigEditor(configEditor) 0030 , m_generator(generator) 0031 { 0032 setAttribute(Qt::WA_DeleteOnClose, true); 0033 mConfigEditor->setParent(this); 0034 0035 setWindowTitle(i18nc("@title:window", "Create")); 0036 0037 // editor 0038 auto* editorLabel = new QLabel(mConfigEditor->name()); 0039 QFont font = editorLabel->font(); 0040 font.setBold(true); 0041 editorLabel->setFont(font); 0042 0043 // dialog buttons 0044 auto* dialogButtonBox = new QDialogButtonBox; 0045 auto* createButton = new QPushButton(QIcon::fromTheme(QStringLiteral("document-new")), 0046 i18nc("@action:button create the new document", "&Create")); 0047 createButton->setToolTip(i18nc("@info:tooltip", 0048 "Create a new document with the generated data.")); 0049 createButton->setWhatsThis(xi18nc("@info:whatsthis", 0050 "If you press the <interface>Create</interface> button, " 0051 "the data will be generated with the settings you entered above " 0052 "and inserted in a new document.")); 0053 0054 dialogButtonBox->addButton(createButton, QDialogButtonBox::AcceptRole); 0055 connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0056 dialogButtonBox->addButton(QDialogButtonBox::Cancel); 0057 connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0058 0059 createButton->setEnabled(configEditor->isValid()); 0060 connect(configEditor, &AbstractModelDataGeneratorConfigEditor::validityChanged, 0061 createButton, &QWidget::setEnabled); 0062 0063 // main layout 0064 auto* layout = new QVBoxLayout; 0065 layout->addWidget(editorLabel); 0066 layout->addWidget(mConfigEditor); 0067 layout->addStretch(); 0068 layout->addWidget(dialogButtonBox); 0069 0070 setLayout(layout); 0071 0072 connect(this, &QDialog::finished, this, &CreateDialog::onFinished); 0073 } 0074 0075 CreateDialog::~CreateDialog() = default; 0076 0077 void CreateDialog::onFinished(int result) 0078 { 0079 if (result != QDialog::Accepted) { 0080 return; 0081 } 0082 0083 Q_EMIT createAccepted(m_generator); 0084 } 0085 0086 } 0087 0088 #include "moc_createdialog.cpp"