File indexing completed on 2024-05-12 16:35:04
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net> 0003 * Copyright 2012 Friedrich W. H. Kossebau <kossebau@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "VectorShapeConfigWidget.h" 0022 0023 #include "VectorShape.h" 0024 #include "VectorDebug.h" 0025 // KF5 0026 #include <kfilewidget.h> 0027 #include <KIO/Job> 0028 // Qt 0029 #include <QVBoxLayout> 0030 #include <QUrl> 0031 0032 void LoadWaiter::setImageData(KJob *job) 0033 { 0034 if (m_vectorShape) { 0035 KIO::StoredTransferJob *transferJob = qobject_cast<KIO::StoredTransferJob*>(job); 0036 Q_ASSERT(transferJob); 0037 0038 const QByteArray contents = transferJob->data(); 0039 const VectorShape::VectorType vectorType = VectorShape::vectorType(contents); 0040 0041 m_vectorShape->setCompressedContents(qCompress(contents), vectorType); 0042 } 0043 0044 deleteLater(); 0045 } 0046 0047 // ---------------------------------------------------- // 0048 0049 VectorShapeConfigWidget::VectorShapeConfigWidget() 0050 : m_shape(0), 0051 m_fileWidget(0) 0052 { 0053 } 0054 0055 VectorShapeConfigWidget::~VectorShapeConfigWidget() 0056 { 0057 delete m_fileWidget; 0058 } 0059 0060 void VectorShapeConfigWidget::open(KoShape *shape) 0061 { 0062 m_shape = dynamic_cast<VectorShape*>(shape); 0063 Q_ASSERT(m_shape); 0064 delete m_fileWidget; 0065 QVBoxLayout *layout = new QVBoxLayout(this); 0066 m_fileWidget = new KFileWidget(QUrl(/*QT5TODO:"kfiledialog:///OpenDialog"*/), this); 0067 m_fileWidget->setOperationMode(KFileWidget::Opening); 0068 const QStringList mimetypes = QStringList() 0069 << QLatin1String("image/x-wmf") 0070 << QLatin1String("image/x-emf") 0071 << QLatin1String("image/x-svm") 0072 << QLatin1String("image/svg+xml"); 0073 m_fileWidget->setMimeFilter(mimetypes); 0074 layout->addWidget(m_fileWidget); 0075 setLayout(layout); 0076 connect(m_fileWidget, SIGNAL(accepted()), this, SIGNAL(accept())); 0077 } 0078 0079 void VectorShapeConfigWidget::save() 0080 { 0081 if (!m_shape) 0082 return; 0083 m_fileWidget->accept(); 0084 QUrl url = m_fileWidget->selectedUrl(); 0085 if (!url.isEmpty()) { 0086 KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, 0); 0087 LoadWaiter *waiter = new LoadWaiter(m_shape); 0088 connect(job, SIGNAL(result(KJob*)), waiter, SLOT(setImageData(KJob*))); 0089 } 0090 } 0091 0092 bool VectorShapeConfigWidget::showOnShapeCreate() 0093 { 0094 return true; 0095 } 0096 0097 bool VectorShapeConfigWidget::showOnShapeSelect() 0098 { 0099 return false; 0100 }