File indexing completed on 2024-04-28 04:32:01

0001 /*
0002  * Copyright (C) 2010-2015 by Stephen Allewell
0003  * steve.allewell@gmail.com
0004  *
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2 of the License, or
0008  * (at your option) any later version.
0009  */
0010 
0011 #include "ImportImageDlg.h"
0012 
0013 #include <QApplication>
0014 #include <QPainter>
0015 #include <QProgressDialog>
0016 
0017 #include <KHelpClient>
0018 #include <KLocalizedString>
0019 
0020 #include "FlossScheme.h"
0021 #include "SchemeManager.h"
0022 #include "SymbolLibrary.h"
0023 #include "SymbolManager.h"
0024 #include "configuration.h"
0025 
0026 const uchar alphaData[] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x04, 0x00,
0027                            0x00, 0x00, 0x04, 0x08, 0x06, 0x00, 0x00, 0x00, 0xa9, 0xf1, 0x9e, 0x7e, 0x00, 0x00, 0x00, 0x04, 0x73, 0x42, 0x49, 0x54, 0x08,
0028                            0x08, 0x08, 0x08, 0x7c, 0x08, 0x64, 0x88, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00,
0029                            0x0b, 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x31, 0x49, 0x44, 0x41, 0x54, 0x08, 0x99, 0x4d, 0xc1, 0xc1, 0x0d,
0030                            0xc0, 0x20, 0x0c, 0x04, 0x30, 0x53, 0xb1, 0x51, 0xa6, 0x65, 0x2a, 0xc4, 0x3e, 0x28, 0xd7, 0x4f, 0x1f, 0xb5, 0xc7, 0x5a, 0x2b,
0031                            0x70, 0xce, 0xd1, 0xdd, 0x1e, 0x9f, 0x7b, 0xaf, 0x24, 0xe6, 0xde, 0x1b, 0x54, 0x15, 0x98, 0x49, 0xfc, 0xbd, 0x57, 0x37, 0x14,
0032                            0x37, 0x6c, 0x77, 0x53, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82};
0033 
0034 ImportImageDlg::ImportImageDlg(QWidget *parent, const Magick::Image &originalImage)
0035     : QDialog(parent)
0036     , m_alphaSelect(nullptr)
0037     , m_originalImage(originalImage)
0038 {
0039     ui.setupUi(this);
0040 
0041     m_crop = QRect(0, 0, m_originalImage.columns(), m_originalImage.rows());
0042     m_originalSize = QSize(m_crop.width(), m_crop.height());
0043     updateWindowTitle();
0044 
0045     // disable some signals whilst the dialog is setup
0046     ui.FlossScheme->blockSignals(true);
0047     ui.UseMaximumColors->blockSignals(true);
0048     ui.MaximumColors->blockSignals(true);
0049     ui.IgnoreColor->blockSignals(true);
0050     ui.ColorButton->blockSignals(true);
0051     ui.HorizontalClothCount->blockSignals(true);
0052     ui.VerticalClothCount->blockSignals(true);
0053     ui.ClothCountLink->blockSignals(true);
0054     ui.PatternScale->blockSignals(true);
0055     ui.CropEnabled->blockSignals(true);
0056     ui.CropReset->blockSignals(true);
0057     ui.UseFractionals->blockSignals(true);
0058 
0059     ui.FlossScheme->addItems(SchemeManager::schemes());
0060     ui.CropReset->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
0061 
0062     resetImportParameters();
0063     createImageMap();
0064     renderPixmap();
0065 
0066     // unblock signals now the dialog is setup
0067     ui.FlossScheme->blockSignals(false);
0068     ui.UseMaximumColors->blockSignals(false);
0069     ui.MaximumColors->blockSignals(false);
0070     ui.IgnoreColor->blockSignals(false);
0071     ui.ColorButton->blockSignals(false);
0072     ui.HorizontalClothCount->blockSignals(false);
0073     ui.VerticalClothCount->blockSignals(false);
0074     ui.ClothCountLink->blockSignals(false);
0075     ui.PatternScale->blockSignals(false);
0076     ui.CropEnabled->blockSignals(false);
0077     ui.CropReset->blockSignals(false);
0078     ui.UseFractionals->blockSignals(false);
0079     connect(ui.ImagePreview, &ScaledPixmapLabel::imageCropped, this, &ImportImageDlg::imageCropped);
0080 }
0081 
0082 void ImportImageDlg::updateWindowTitle()
0083 {
0084     QString caption = i18n("Import Image - Image Size %1 x %2 pixels", m_crop.width(), m_crop.height());
0085     setWindowTitle(caption);
0086 }
0087 
0088 Magick::Image ImportImageDlg::convertedImage() const
0089 {
0090     return m_convertedImage;
0091 }
0092 
0093 bool ImportImageDlg::ignoreColor() const
0094 {
0095     return ui.IgnoreColor->isChecked();
0096 }
0097 
0098 Magick::Color ImportImageDlg::ignoreColorValue() const
0099 {
0100     return m_ignoreColorValue;
0101 }
0102 
0103 QString ImportImageDlg::flossScheme() const
0104 {
0105     return ui.FlossScheme->currentText();
0106 }
0107 
0108 double ImportImageDlg::horizontalClothCount() const
0109 {
0110     return ui.HorizontalClothCount->value();
0111 }
0112 
0113 double ImportImageDlg::verticalClothCount() const
0114 {
0115     return ui.VerticalClothCount->value();
0116 }
0117 
0118 bool ImportImageDlg::useFractionals() const
0119 {
0120     return ui.UseFractionals->isChecked();
0121 }
0122 
0123 QRect ImportImageDlg::croppedArea() const
0124 {
0125     return m_crop;
0126 }
0127 
0128 void ImportImageDlg::hideEvent(QHideEvent *event)
0129 {
0130     KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("DialogSizes")).writeEntry(QStringLiteral("ImportImageDlg"), size());
0131 
0132     QDialog::hideEvent(event);
0133 }
0134 
0135 void ImportImageDlg::showEvent(QShowEvent *event)
0136 {
0137     QDialog::showEvent(event);
0138 
0139     if (KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("DialogSizes")).hasKey(QStringLiteral("ImportImageDlg"))) {
0140         resize(KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("DialogSizes")).readEntry(QStringLiteral("ImportImageDlg"), QSize()));
0141     }
0142 }
0143 
0144 void ImportImageDlg::on_FlossScheme_currentIndexChanged(const QString &)
0145 {
0146     createImageMap();
0147     renderPixmap();
0148 }
0149 
0150 void ImportImageDlg::on_UseMaximumColors_toggled(bool checked)
0151 {
0152     Q_UNUSED(checked);
0153 
0154     killTimer(m_timer);
0155     m_timer = startTimer(500);
0156 }
0157 
0158 void ImportImageDlg::on_MaximumColors_valueChanged(int)
0159 {
0160     killTimer(m_timer);
0161     m_timer = startTimer(500);
0162 }
0163 
0164 void ImportImageDlg::on_IgnoreColor_toggled(bool checked)
0165 {
0166     Q_UNUSED(checked);
0167 
0168     delete m_alphaSelect;
0169     m_alphaSelect = nullptr;
0170 
0171     renderPixmap();
0172 }
0173 
0174 void ImportImageDlg::on_ColorButton_clicked(bool)
0175 {
0176     m_alphaSelect = new AlphaSelect(ui.ImagePreview);
0177     connect(m_alphaSelect, &AlphaSelect::clicked, this, &ImportImageDlg::selectColor);
0178     m_alphaSelect->show();
0179 }
0180 
0181 void ImportImageDlg::on_HorizontalClothCount_valueChanged(double horizontalClothCount)
0182 {
0183     clothCountChanged(horizontalClothCount, ui.VerticalClothCount->value());
0184 }
0185 
0186 void ImportImageDlg::on_VerticalClothCount_valueChanged(double verticalClothCount)
0187 {
0188     clothCountChanged(ui.HorizontalClothCount->value(), verticalClothCount);
0189 }
0190 
0191 void ImportImageDlg::clothCountChanged(double horizontalClothCount, double verticalClothCount)
0192 {
0193     double preferredSizeWidth = m_preferredSize.width();
0194     double preferredSizeHeight = m_preferredSize.height();
0195 
0196     QString suffix;
0197 
0198     switch (Configuration::document_UnitsFormat()) {
0199     case Configuration::EnumDocument_UnitsFormat::Stitches:
0200         suffix = QString(i18n("Stitches"));
0201         break;
0202 
0203     case Configuration::EnumDocument_UnitsFormat::Inches:
0204         preferredSizeWidth /= horizontalClothCount;
0205         preferredSizeHeight /= verticalClothCount;
0206         suffix = QString(i18n("Inches"));
0207         break;
0208 
0209     case Configuration::EnumDocument_UnitsFormat::Centimeters:
0210         preferredSizeWidth /= horizontalClothCount;
0211         preferredSizeHeight /= verticalClothCount;
0212         suffix = QString(i18n("Centimeters"));
0213         break;
0214 
0215     default:
0216         break;
0217     }
0218 
0219     if (ui.ClothCountLink->isChecked()) {
0220         ui.VerticalClothCount->setValue(horizontalClothCount);
0221     }
0222 
0223     if (Configuration::document_UnitsFormat() == Configuration::EnumDocument_UnitsFormat::Stitches) {
0224         ui.FinalSize->setText(QString(i18nc("%1 width, %2 height and %3 units",
0225                                             "%1 x %2 %3",
0226                                             QString::fromLatin1("%1").arg(preferredSizeWidth, 0, 'f', 0),
0227                                             QString::fromLatin1("%1").arg(preferredSizeHeight, 0, 'f', 0),
0228                                             suffix)));
0229     } else {
0230         ui.FinalSize->setText(QString(i18nc("%1 width, %2 height and %3 units",
0231                                             "%1 x %2 %3",
0232                                             QString::fromLatin1("%1").arg(preferredSizeWidth, 0, 'f', 2),
0233                                             QString::fromLatin1("%1").arg(preferredSizeHeight, 0, 'f', 2),
0234                                             suffix)));
0235     }
0236 }
0237 
0238 void ImportImageDlg::on_ClothCountLink_clicked(bool checked)
0239 {
0240     ui.ClothCountLink->setIcon((checked) ? QIcon::fromTheme(QStringLiteral("object-locked")) : QIcon::fromTheme(QStringLiteral("object-unlocked")));
0241 
0242     if (checked) {
0243         ui.VerticalClothCount->setValue(ui.HorizontalClothCount->value());
0244         ui.VerticalClothCount->setEnabled(false);
0245     } else {
0246         ui.VerticalClothCount->setEnabled(true);
0247     }
0248 }
0249 
0250 void ImportImageDlg::on_PatternScale_valueChanged(int)
0251 {
0252     killTimer(m_timer);
0253     m_timer = startTimer(500);
0254 }
0255 
0256 void ImportImageDlg::on_CropEnabled_toggled(bool checked)
0257 {
0258     ui.ImagePreview->setCropping(checked);
0259     if (!checked) {
0260         on_CropReset_clicked(true);
0261     }
0262 }
0263 
0264 void ImportImageDlg::on_CropReset_clicked(bool checked)
0265 {
0266     Q_UNUSED(checked);
0267 
0268     m_convertedImage = m_originalImage;
0269     m_crop = QRect(0, 0, m_originalImage.columns(), m_originalImage.rows());
0270     updateWindowTitle();
0271 
0272     renderPixmap();
0273 }
0274 
0275 void ImportImageDlg::imageCropped(const QRectF &rectF)
0276 {
0277     // rectF is new crop rectangle relative to m_convertedImage size
0278     // scale rect from m_convertedImage size to m_originalSize
0279     // m_original size may be cropped from m_originalImage, but is not scaled.
0280     // add new crop to original one.
0281     double scaleFactor = (double)m_originalSize.width() / (double)m_convertedImage.columns();
0282     QRect scaledCrop = QRect(scaleFactor * rectF.left(), scaleFactor * rectF.top(), scaleFactor * rectF.width(), scaleFactor * rectF.height());
0283     m_crop = QRect(m_crop.left() + scaledCrop.left(), m_crop.top() + scaledCrop.top(), scaledCrop.width(), scaledCrop.height());
0284 
0285     updateWindowTitle();
0286 
0287     renderPixmap();
0288 }
0289 
0290 void ImportImageDlg::on_UseFractionals_toggled(bool checked)
0291 {
0292     Q_UNUSED(checked);
0293 
0294     killTimer(m_timer);
0295     m_timer = startTimer(500);
0296 }
0297 
0298 void ImportImageDlg::calculateSizes()
0299 {
0300     m_convertedImage = m_originalImage;
0301 
0302     if (m_crop.isValid()) {
0303         m_convertedImage.chop(Magick::Geometry(m_crop.left(), m_crop.top()));
0304         m_convertedImage.crop(Magick::Geometry(m_crop.width(), m_crop.height()));
0305         m_originalSize = QSize(m_convertedImage.columns(), m_convertedImage.rows());
0306     }
0307 
0308     m_preferredSize = m_originalSize * ui.PatternScale->value() / 100;
0309     QSize imageSize = m_preferredSize;
0310 
0311     if (ui.UseFractionals->isChecked()) {
0312         imageSize *= 2;
0313     }
0314 
0315     Magick::Geometry geometry(imageSize.width(), imageSize.height());
0316     geometry.percent(false);
0317     geometry.aspect(true); // set to true to ignore maintaining the aspect ratio
0318     m_convertedImage.sample(geometry);
0319     on_HorizontalClothCount_valueChanged(ui.HorizontalClothCount->value());
0320 }
0321 
0322 void ImportImageDlg::createImageMap()
0323 {
0324     FlossScheme *scheme = SchemeManager::scheme(ui.FlossScheme->currentText());
0325     m_colorMap = *(scheme->createImageMap());
0326 }
0327 
0328 void ImportImageDlg::renderPixmap()
0329 {
0330     QPixmap alpha;
0331     alpha.loadFromData(alphaData, 143);
0332 
0333     ui.ImagePreview->setCursor(Qt::WaitCursor);
0334     calculateSizes();
0335     m_convertedImage.modifyImage();
0336 
0337     m_pixmap = QPixmap(m_convertedImage.columns(), m_convertedImage.rows());
0338     m_pixmap.fill();
0339 
0340     m_convertedImage.quantizeColorSpace(Magick::RGBColorspace);
0341     m_convertedImage.quantizeColors(
0342         ui.UseMaximumColors->isChecked()
0343             ? std::min(ui.MaximumColors->value(), SymbolManager::library(Configuration::palette_DefaultSymbolLibrary())->indexes().count())
0344             : SymbolManager::library(Configuration::palette_DefaultSymbolLibrary())->indexes().count());
0345     m_convertedImage.quantize();
0346     m_convertedImage.map(m_colorMap);
0347     m_convertedImage.modifyImage();
0348 
0349     QPainter painter;
0350     painter.begin(&m_pixmap);
0351     painter.drawTiledPixmap(m_pixmap.rect(), alpha);
0352     int width = m_convertedImage.columns();
0353     int height = m_convertedImage.rows();
0354     int pixelCount = width * height;
0355 
0356     QProgressDialog progress(i18n("Rendering preview"), i18n("Cancel"), 0, pixelCount, this);
0357     progress.setWindowModality(Qt::WindowModal);
0358 
0359 /*
0360  * ImageMagick prior to V7 used matte (opacity) to determine if an image has transparency.
0361  * 0.0 for transparent to 1.0 for opaque
0362  *
0363  * ImageMagick V7 now uses alpha (transparency).
0364  * 1.0 for transparent to 0.0 for opaque
0365  *
0366  * Access to pixels has changed too, V7 can use pixelColor to access the color of a particular
0367  * pixel, but although this was available in V6, it doesn't appear to produce the same result
0368  * and has resulted in black images when importing.
0369  */
0370 #if MagickLibVersion < 0x700
0371     bool hasTransparency = m_convertedImage.matte();
0372     double transparent = 1.0;
0373     const Magick::PixelPacket *pixels = m_convertedImage.getConstPixels(0, 0, width, height);
0374 #else
0375     bool hasTransparency = m_convertedImage.alpha();
0376     double transparent = 0.0;
0377 #endif
0378 
0379     for (int dy = 0; dy < height; dy++) {
0380         QApplication::processEvents();
0381         progress.setValue(dy * width);
0382 
0383         if (progress.wasCanceled()) {
0384             break;
0385         }
0386 
0387         for (int dx = 0; dx < width; dx++) {
0388 #if MagickLibVersion < 0x700
0389             Magick::ColorRGB rgb = Magick::Color(*pixels++);
0390 #else
0391             Magick::ColorRGB rgb = m_convertedImage.pixelColor(dx, dy);
0392 #endif
0393 
0394             if (hasTransparency && (rgb.alpha() == transparent)) {
0395                 // ignore this pixel as it is transparent
0396             } else {
0397                 if (!(ui.IgnoreColor->isChecked() && rgb == m_ignoreColorValue)) {
0398                     QColor color((int)(255 * rgb.red()), (int)(255 * rgb.green()), (int)(255 * rgb.blue()));
0399                     painter.setPen(QPen(color));
0400                     painter.drawPoint(dx, dy);
0401                 }
0402             }
0403         }
0404     }
0405 
0406     painter.end();
0407     ui.ImagePreview->setPixmap(m_pixmap);
0408     ui.ImagePreview->setCursor(Qt::ArrowCursor);
0409 }
0410 
0411 void ImportImageDlg::timerEvent(QTimerEvent *)
0412 {
0413     killTimer(m_timer);
0414     renderPixmap();
0415 }
0416 
0417 void ImportImageDlg::pickColor()
0418 {
0419     if (ui.IgnoreColor->isChecked()) {
0420         m_alphaSelect = new AlphaSelect(ui.ImagePreview);
0421         connect(m_alphaSelect, &AlphaSelect::clicked, this, &ImportImageDlg::selectColor);
0422         m_alphaSelect->show();
0423     } else {
0424         delete m_alphaSelect;
0425         m_alphaSelect = nullptr;
0426     }
0427 }
0428 
0429 void ImportImageDlg::selectColor(const QPoint &p)
0430 {
0431     QSize trueSize(m_convertedImage.columns(), m_convertedImage.rows());
0432     QRect pixmapRect = m_alphaSelect->pixmapRect();
0433 
0434     delete m_alphaSelect;
0435     m_alphaSelect = nullptr;
0436 
0437     // convert p that is relative to the ScaledImageLabel to the pixmap size
0438     int x = (((p.x() - pixmapRect.left()) * trueSize.width()) / pixmapRect.width());
0439     int y = (((p.y() - pixmapRect.top()) * trueSize.height()) / pixmapRect.height());
0440 
0441     x = (x < 0) ? 0 : std::min(x, trueSize.width());
0442     y = (y < 0) ? 0 : std::min(y, trueSize.height());
0443 
0444     m_ignoreColorValue = m_convertedImage.pixelColor(x, y);
0445     QPixmap swatch(ui.ColorButton->size());
0446     swatch.fill(QColor((int)(255 * m_ignoreColorValue.red()), (int)(255 * m_ignoreColorValue.green()), (int)(255 * m_ignoreColorValue.blue())));
0447     ui.ColorButton->setIcon(swatch);
0448 
0449     renderPixmap();
0450 }
0451 
0452 void ImportImageDlg::on_DialogButtonBox_accepted()
0453 {
0454     accept();
0455 }
0456 
0457 void ImportImageDlg::on_DialogButtonBox_rejected()
0458 {
0459     reject();
0460 }
0461 
0462 void ImportImageDlg::on_DialogButtonBox_helpRequested()
0463 {
0464     KHelpClient::invokeHelp(QStringLiteral("ImportImageDialog"), QStringLiteral("kxstitch"));
0465 }
0466 
0467 void ImportImageDlg::on_DialogButtonBox_clicked(QAbstractButton *button)
0468 {
0469     if (ui.DialogButtonBox->button(QDialogButtonBox::Reset) == button) {
0470         m_convertedImage = m_originalImage;
0471         resetImportParameters();
0472         renderPixmap();
0473     }
0474 }
0475 
0476 void ImportImageDlg::resetImportParameters()
0477 {
0478     double horizontalClothCount = Configuration::editor_HorizontalClothCount();
0479     double verticalClothCount = Configuration::editor_VerticalClothCount();
0480 
0481     Configuration::EnumEditor_ClothCountUnits::type clothCountUnits = Configuration::editor_ClothCountUnits();
0482 
0483     if (clothCountUnits == Configuration::EnumEditor_ClothCountUnits::Default) {
0484         clothCountUnits = (QLocale::system().measurementSystem() == QLocale::MetricSystem) ? Configuration::EnumEditor_ClothCountUnits::Centimeters
0485                                                                                            : Configuration::EnumEditor_ClothCountUnits::Inches;
0486     }
0487 
0488     if (clothCountUnits == Configuration::EnumEditor_ClothCountUnits::Centimeters) {
0489         ui.HorizontalClothCount->setSuffix(i18nc("Per centimeter measurements", "/cm"));
0490         ui.VerticalClothCount->setSuffix(i18nc("Per centimeter measurements", "/cm"));
0491         ui.HorizontalClothCount->setSingleStep(0.1);
0492         ui.VerticalClothCount->setSingleStep(0.1);
0493         ui.HorizontalClothCount->setDecimals(1);
0494         ui.VerticalClothCount->setDecimals(1);
0495     } else {
0496         ui.HorizontalClothCount->setSuffix(i18nc("Per inch measurements", "/in"));
0497         ui.VerticalClothCount->setSuffix(i18nc("Per inch measurements", "/in"));
0498         ui.HorizontalClothCount->setSingleStep(1.0);
0499         ui.VerticalClothCount->setSingleStep(1.0);
0500         ui.HorizontalClothCount->setDecimals(0);
0501         ui.VerticalClothCount->setDecimals(0);
0502     }
0503 
0504     ui.HorizontalClothCount->setValue(horizontalClothCount);
0505     ui.VerticalClothCount->setValue(verticalClothCount);
0506     ui.ClothCountLink->setChecked(Configuration::editor_ClothCountLink());
0507     ui.VerticalClothCount->setEnabled(!ui.ClothCountLink->isChecked());
0508     ui.ClothCountLink->setIcon(ui.ClothCountLink->isChecked() ? QIcon::fromTheme(QStringLiteral("object-locked"))
0509                                                               : QIcon::fromTheme(QStringLiteral("object-unlocked")));
0510 
0511     m_preferredSize = QSize(Configuration::document_Width(), Configuration::document_Height());
0512 
0513     Configuration::EnumDocument_UnitsFormat::type preferredSizeUnits = Configuration::document_UnitsFormat();
0514 
0515     switch (preferredSizeUnits) {
0516     case Configuration::EnumDocument_UnitsFormat::Inches:
0517         switch (clothCountUnits) {
0518         case Configuration::EnumEditor_ClothCountUnits::Inches:
0519             m_preferredSize = QSize(m_preferredSize.width() * horizontalClothCount, m_preferredSize.height() * verticalClothCount);
0520             break;
0521 
0522         case Configuration::EnumEditor_ClothCountUnits::Centimeters:
0523             m_preferredSize = QSize(m_preferredSize.width() * horizontalClothCount * 2.54, m_preferredSize.height() * verticalClothCount * 2.54);
0524             break;
0525 
0526         default:
0527             // No conversion required
0528             break;
0529         }
0530 
0531         break;
0532 
0533     case Configuration::EnumDocument_UnitsFormat::Centimeters:
0534         switch (clothCountUnits) {
0535         case Configuration::EnumEditor_ClothCountUnits::Inches:
0536             m_preferredSize = QSize(m_preferredSize.width() * horizontalClothCount / 2.54, m_preferredSize.height() * verticalClothCount / 2.54);
0537             break;
0538 
0539         case Configuration::EnumEditor_ClothCountUnits::Centimeters:
0540             m_preferredSize = QSize(m_preferredSize.width() * horizontalClothCount, m_preferredSize.height() * verticalClothCount);
0541             break;
0542 
0543         default:
0544             // No conversion required
0545             break;
0546         }
0547 
0548         break;
0549 
0550     default:
0551         break;
0552     }
0553 
0554     int scaledWidth = m_preferredSize.width() * 100 / m_originalSize.width();
0555     int scaledHeight = m_preferredSize.height() * 100 / m_originalSize.height();
0556     int scale = std::min(scaledWidth, scaledHeight);
0557 
0558     QString scheme = Configuration::palette_DefaultScheme();
0559 
0560     if (SchemeManager::scheme(scheme) == nullptr) {
0561         scheme = SchemeManager::schemes().at(scheme.toInt());
0562     }
0563 
0564     ui.FlossScheme->setCurrentItem(scheme);
0565     ui.PatternScale->setValue(scale);
0566     ui.UseMaximumColors->setChecked(Configuration::import_UseMaximumColors());
0567     ui.MaximumColors->setEnabled(ui.UseMaximumColors->isChecked());
0568     ui.MaximumColors->setValue(Configuration::import_MaximumColors());
0569     ui.MaximumColors->setMaximum(SymbolManager::library(Configuration::palette_DefaultSymbolLibrary())->indexes().count());
0570     ui.MaximumColors->setToolTip(QString(i18n("Colors limited to %1 due to the number of symbols available", ui.MaximumColors->maximum())));
0571 }
0572 
0573 #include "moc_ImportImageDlg.cpp"