File indexing completed on 2025-01-26 05:24:14
0001 /* 0002 This file is part of the Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2008, 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 "copyasdialog.hpp" 0010 0011 // Kasten gui 0012 #include <Kasten/AbstractModelStreamEncoderConfigEditor> 0013 #include <Kasten/AbstractSelectionView> 0014 // KF 0015 #include <KLocalizedString> 0016 // Qt 0017 #include <QSplitter> 0018 #include <QGroupBox> 0019 #include <QHBoxLayout> 0020 #include <QVBoxLayout> 0021 #include <QLabel> 0022 #include <QPushButton> 0023 #include <QIcon> 0024 #include <QFont> 0025 #include <QDialogButtonBox> 0026 0027 namespace Kasten { 0028 0029 CopyAsDialog::CopyAsDialog(const QString& remoteTypeName, 0030 AbstractModelStreamEncoderConfigEditor* configEditor, 0031 AbstractModelStreamEncoder* encoder, 0032 QWidget* parent) 0033 : QDialog(parent) 0034 , mConfigEditor(configEditor) 0035 , m_encoder(encoder) 0036 { 0037 setAttribute(Qt::WA_DeleteOnClose, true); 0038 mConfigEditor->setParent(this); 0039 0040 setWindowTitle(i18nc("@title:window", "Copy As")); 0041 0042 auto* splitter = new QSplitter(this); 0043 0044 // config editor 0045 auto* editorPage = new QWidget(splitter); 0046 auto* editorPageLayout = new QVBoxLayout(editorPage); 0047 auto* editorLabel = new QLabel(remoteTypeName); 0048 QFont font = editorLabel->font(); 0049 font.setBold(true); 0050 editorLabel->setFont(font); 0051 0052 editorPageLayout->addWidget(editorLabel); 0053 editorPageLayout->addWidget(mConfigEditor); 0054 editorPageLayout->addStretch(); 0055 0056 splitter->addWidget(editorPage); 0057 splitter->setCollapsible(0, false); 0058 0059 mPreviewView = configEditor->createPreviewView(); 0060 0061 if (mPreviewView) { 0062 auto* previewBox = new QGroupBox(i18nc("@title:group", "Preview"), this); 0063 splitter->addWidget(previewBox); 0064 0065 auto* previewBoxLayout = new QHBoxLayout(previewBox); 0066 0067 previewBoxLayout->addWidget(mPreviewView->widget()); 0068 } 0069 0070 // dialog buttons 0071 auto* dialogButtonBox = new QDialogButtonBox; 0072 auto* exportButton = new QPushButton(QIcon::fromTheme(QStringLiteral("edit-copy")), 0073 i18nc("@action:button", "&Copy to clipboard")); 0074 exportButton->setToolTip(i18nc("@info:tooltip", 0075 "Copy the selected data to the clipboard.")); 0076 exportButton->setWhatsThis(xi18nc("@info:whatsthis", 0077 "If you press the <interface>Copy to clipboard</interface> " 0078 "button, the selected data will be copied to the clipboard " 0079 "with the settings you entered above.")); 0080 0081 dialogButtonBox->addButton(exportButton, QDialogButtonBox::AcceptRole); 0082 connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0083 dialogButtonBox->addButton(QDialogButtonBox::Cancel); 0084 connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0085 0086 exportButton->setEnabled(configEditor->isValid()); 0087 connect(configEditor, &AbstractModelStreamEncoderConfigEditor::validityChanged, 0088 exportButton, &QWidget::setEnabled); 0089 0090 // main layout 0091 auto* layout = new QVBoxLayout; 0092 layout->addWidget(splitter); 0093 layout->addStretch(); 0094 layout->addWidget(dialogButtonBox); 0095 0096 setLayout(layout); 0097 0098 connect(this, &QDialog::finished, this, &CopyAsDialog::onFinished); 0099 } 0100 0101 CopyAsDialog::~CopyAsDialog() 0102 { 0103 delete mPreviewView; 0104 } 0105 0106 void CopyAsDialog::setData(AbstractModel* model, const AbstractModelSelection* selection) 0107 { 0108 m_selection = selection; 0109 0110 if (mPreviewView) { 0111 mPreviewView->setData(model, selection); 0112 } 0113 } 0114 0115 void CopyAsDialog::onFinished(int result) 0116 { 0117 if (result != QDialog::Accepted) { 0118 return; 0119 } 0120 0121 Q_EMIT copyAccepted(m_encoder, m_selection); 0122 } 0123 0124 } 0125 0126 #include "moc_copyasdialog.cpp"