void ParagraphBulletsNumbers::customCharButtonPressed() { KoDialog *dialog = new KoDialog(this); dialog->setModal(true); dialog->setButtons(KoDialog::Ok | KoDialog::Cancel); dialog->setDefaultButton(KoDialog::Ok); KCharSelect *kcs = new KCharSelect(dialog, 0, KCharSelect::SearchLine | KCharSelect::FontCombo | KCharSelect::BlockCombos | KCharSelect::CharacterTable | KCharSelect::DetailBrowser); dialog->setMainWidget(kcs); if (dialog->exec() == KoDialog::Accepted) { QChar character = kcs->currentChar(); widget.customCharacter->setText(character); // also switch to the custom list style. foreach(int row, m_mapping.keys()) { if (m_mapping[row] == KoListStyle::BulletCharLabelType) { widget.listTypes->setCurrentRow(row); break; } } }
KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteArray& from, const QByteArray& to) { dbgFile << "HeightMap export! From:" << from << ", To:" << to; if (from != "application/x-krita") return KisImportExportFilter::NotImplemented; KisDocument *inputDoc = inputDocument(); QString filename = outputFile(); if (!inputDoc) return KisImportExportFilter::NoDocumentCreated; if (filename.isEmpty()) return KisImportExportFilter::FileNotFound; KisImageWSP image = inputDoc->image(); Q_CHECK_PTR(image); if (inputDoc->image()->width() != inputDoc->image()->height()) { inputDoc->setErrorMessage(i18n("Cannot export this image to a heightmap: it is not square")); return KisImportExportFilter::WrongFormat; } if (inputDoc->image()->colorSpace()->colorModelId() != GrayAColorModelID) { inputDoc->setErrorMessage(i18n("Cannot export this image to a heightmap: it is not grayscale")); return KisImportExportFilter::WrongFormat; } KoDialog* kdb = new KoDialog(0); kdb->setWindowTitle(i18n("HeightMap Export Options")); kdb->setButtons(KoDialog::Ok | KoDialog::Cancel); Ui::WdgOptionsHeightMap optionsHeightMap; QWidget* wdg = new QWidget(kdb); optionsHeightMap.setupUi(wdg); kdb->setMainWidget(wdg); QApplication::restoreOverrideCursor(); QString filterConfig = KisConfig().exportConfiguration("HeightMap"); KisPropertiesConfiguration cfg; cfg.fromXML(filterConfig); optionsHeightMap.intSize->setValue(image->width()); int endianness = cfg.getInt("endianness", 0); QDataStream::ByteOrder bo = QDataStream::LittleEndian; optionsHeightMap.radioPC->setChecked(true); if (endianness == 0) { bo = QDataStream::BigEndian; optionsHeightMap.radioMac->setChecked(true); } if (!getBatchMode()) { if (kdb->exec() == QDialog::Rejected) { return KisImportExportFilter::UserCancelled; } } if (optionsHeightMap.radioMac->isChecked()) { cfg.setProperty("endianness", 0); bo = QDataStream::BigEndian; } else { cfg.setProperty("endianness", 1); bo = QDataStream::LittleEndian; } KisConfig().setExportConfiguration("HeightMap", cfg); bool downscale = false; if (to == "image/x-r8" && image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) { downscale = (QMessageBox::question(0, i18nc("@title:window", "Downscale Image"), i18n("You specified the .r8 extension for a 16 bit/channel image. Do you want to save as 8 bit? Your image data will not be changed."), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes); } // the image must be locked at the higher levels KIS_SAFE_ASSERT_RECOVER_NOOP(image->locked()); KisPaintDeviceSP pd = new KisPaintDevice(*image->projection()); QFile f(filename); f.open(QIODevice::WriteOnly); QDataStream s(&f); s.setByteOrder(bo); KisRandomConstAccessorSP it = pd->createRandomConstAccessorNG(0, 0); bool r16 = ((image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) && !downscale); for (int i = 0; i < image->height(); ++i) { for (int j = 0; j < image->width(); ++j) { it->moveTo(i, j); if (r16) { s << KoGrayU16Traits::gray(const_cast<quint8*>(it->rawDataConst())); } else { s << KoGrayU8Traits::gray(const_cast<quint8*>(it->rawDataConst())); } } } f.close(); return KisImportExportFilter::OK; }