/* * Copyright (c) 2007 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_bmp_import.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(KisBMPImportFactory, registerPlugin();) K_EXPORT_PLUGIN(KisBMPImportFactory("calligrafilters")) KisBMPImport::KisBMPImport(QObject *parent, const QVariantList &) : KoFilter(parent) { } KisBMPImport::~KisBMPImport() { } bool hasVisibleWidgets() { QWidgetList wl = QApplication::allWidgets(); foreach(QWidget* w, wl) { if (w->isVisible()) return true; } return false; } KoFilter::ConversionStatus KisBMPImport::convert(const QByteArray& from, const QByteArray& to) { dbgFile << "BMP import! From:" << from << ", To:" << to << 0; if (!(from == "image/bmp" || from == "image/x-xpixmap" || from == "image/gif" || from == "image/x-xbitmap")) return KoFilter::NotImplemented; if (to != "application/x-krita") return KoFilter::BadMimeType; KisDoc2 * doc = dynamic_cast(m_chain -> outputDocument()); if (!doc) return KoFilter::NoDocumentCreated; QString filename = m_chain -> inputFile(); doc->prepareForImport(); if (!filename.isEmpty()) { KUrl url(filename); if (url.isEmpty()) return KoFilter::FileNotFound; if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, qApp -> activeWindow())) { return KoFilter::FileNotFound; } QString localFile = url.toLocalFile(); QImage img(localFile); const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(doc->createUndoStore(), img.width(), img.height(), colorSpace, "imported from bmp"); KisPaintLayerSP layer = new KisPaintLayer(image, image->nextLayerName(), 255); KisTransaction(0, layer->paintDevice()); layer->paintDevice()->convertFromQImage(img, 0, 0, 0); image->addNode(layer.data(), image->rootLayer().data()); doc->setCurrentImage(image); return KoFilter::OK; } return KoFilter::StorageCreationError; } #include "kis_bmp_import.moc"