File indexing completed on 2024-09-22 05:16:06
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 "insertdialog.hpp" 0010 0011 // Kasten gui 0012 #include <Kasten/AbstractModelDataGeneratorConfigEditor> 0013 // KF 0014 #include <KLocalizedString> 0015 // Qt 0016 #include <QVBoxLayout> 0017 #include <QLabel> 0018 #include <QPushButton> 0019 #include <QFont> 0020 #include <QDialogButtonBox> 0021 0022 namespace Kasten { 0023 0024 InsertDialog::InsertDialog(AbstractModelDataGeneratorConfigEditor* configEditor, 0025 AbstractModelDataGenerator* generator, 0026 QWidget* parent) 0027 : QDialog(parent) 0028 , mConfigEditor(configEditor) 0029 , m_generator(generator) 0030 { 0031 setAttribute(Qt::WA_DeleteOnClose, true); 0032 mConfigEditor->setParent(this); 0033 0034 setWindowTitle(i18nc("@title:window", "Insert")); 0035 0036 // editor 0037 auto* editorLabel = new QLabel(mConfigEditor->name()); 0038 QFont font = editorLabel->font(); 0039 font.setBold(true); 0040 editorLabel->setFont(font); 0041 0042 // dialog buttons 0043 auto* dialogButtonBox = new QDialogButtonBox; 0044 auto* insertButton = new QPushButton(i18nc("@action:button", "&Insert")); 0045 insertButton->setToolTip(i18nc("@info:tooltip", 0046 "Insert the generated data into the document.")); 0047 insertButton->setWhatsThis(xi18nc("@info:whatsthis", 0048 "If you press the <interface>Insert</interface> button, " 0049 "the data will be generated with the settings you entered above " 0050 "and inserted into the document at the cursor position.")); 0051 0052 dialogButtonBox->addButton(insertButton, QDialogButtonBox::AcceptRole); 0053 connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0054 dialogButtonBox->addButton(QDialogButtonBox::Cancel); 0055 connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0056 0057 insertButton->setEnabled(configEditor->isValid()); 0058 connect(configEditor, &AbstractModelDataGeneratorConfigEditor::validityChanged, 0059 insertButton, &QWidget::setEnabled); 0060 0061 // main layout 0062 auto* layout = new QVBoxLayout; 0063 layout->addWidget(editorLabel); 0064 layout->addWidget(mConfigEditor); 0065 layout->addStretch(); 0066 layout->addWidget(dialogButtonBox); 0067 0068 setLayout(layout); 0069 0070 connect(this, &QDialog::finished, this, &InsertDialog::onFinished); 0071 } 0072 0073 InsertDialog::~InsertDialog() = default; 0074 0075 void InsertDialog::onFinished(int result) 0076 { 0077 if (result != QDialog::Accepted) { 0078 return; 0079 } 0080 0081 Q_EMIT insertAccepted(m_generator); 0082 } 0083 0084 } 0085 0086 #include "moc_insertdialog.cpp"