13#include <QApplication>
15#include <QDialogButtonBox>
23#include <kstandardguiitem.h>
54 static QString str = i18n(
"Pixels/Inch");
60 static QString str = i18n(
"Pixels/Centimeter");
64KisCustomImageWidget::KisCustomImageWidget(QWidget* parent, qint32 defWidth, qint32 defHeight,
double resolution,
const QString& defColorModel,
const QString& defColorDepth,
const QString& defColorProfile,
const QString& imageName)
67 setObjectName(
"KisCustomImageWidget");
68 m_openPane = qobject_cast<KisOpenPane*>(parent);
71 txtName->setText(imageName);
73 doubleWidth->setValue(defWidth);
74 doubleWidth->setDecimals(0);
80 doubleHeight->setValue(defHeight);
81 doubleHeight->setDecimals(0);
89 doubleResolution->setValue(72.0 * resolution);
90 doubleResolution->setDecimals(2);
94 sliderOpacity->setRange(0, 100, 0);
95 sliderOpacity->setValue(100);
99 connect(doubleResolution, SIGNAL(valueChanged(
double)),
101 connect(cmbWidthUnit, SIGNAL(activated(
int)),
103 connect(doubleWidth, SIGNAL(valueChanged(
double)),
105 connect(cmbHeightUnit, SIGNAL(activated(
int)),
107 connect(doubleHeight, SIGNAL(valueChanged(
double)),
109 connect(cmbResolutionUnit, SIGNAL(currentIndexChanged(
int)),
114 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setText(i18n(
"&Create"));
115 KGuiItem::assign(newDialogConfirmationButtonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
116 connect(newDialogConfirmationButtonBox, SIGNAL(accepted()),
this, SLOT(
createImage()));
120 connect(newDialogConfirmationButtonBox, SIGNAL(rejected()),
m_openPane, SLOT(reject()));
133 colorSpaceSelector->setCurrentColorModel(
KoID(defColorModel));
134 colorSpaceSelector->setCurrentColorDepth(
KoID(defColorDepth));
135 colorSpaceSelector->setCurrentProfile(defColorProfile);
138 connect(colorSpaceSelector, SIGNAL(selectionChanged(
bool)), newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok), SLOT(setEnabled(
bool)));
145 cmbColor->setColor(bcol);
151 radioBackgroundAsRaster->setChecked(
true);
153 radioBackgroundAsFill->setChecked(
true);
155 radioBackgroundAsProjection->setChecked(
true);
163 QPalette
p = QApplication::palette();
164 QPalette palette_highlight(
p );
165 QColor c =
p.color(QPalette::Highlight);
166 palette_highlight.setColor(QPalette::Button, c);
167 bnLandscape->setPalette(palette_highlight);
168 bnPortrait->setPalette(palette_highlight);
175 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setFocus();
176 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
200 qreal resolution = doubleResolution->value();
210 doubleResolution->setValue(resolution);
216 doubleWidth->blockSignals(
true);
220 doubleWidth->setDecimals(0);
223 doubleWidth->setDecimals(2);
228 doubleWidth->blockSignals(
false);
240 doubleHeight->blockSignals(
true);
244 doubleHeight->setDecimals(0);
247 doubleHeight->setDecimals(2);
252 doubleHeight->blockSignals(
false);
264 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
271 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
277 const KoColorSpace * cs = colorSpaceSelector->currentColorSpace();
284 if (profile->
name().contains(
"linear") ||
285 profile->
name().contains(
"scRGB") ||
286 profile->
info().contains(
"linear") ||
287 profile->
info().contains(
"scRGB")) {
290 QMessageBox::warning(
this,
291 i18nc(
"@title:window",
"Krita"),
292 i18n(
"Linear gamma RGB color spaces are not supposed to be used "
293 "in 8-bit integer modes. It is suggested to use 16-bit integer "
294 "or any floating point colorspace for linear profiles.\n\n"
295 "Press \"Ok\" to create a 8-bit integer linear RGB color space "
296 "or \"Cancel\" to return to the settings dialog."),
297 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
299 if (result == QMessageBox::Cancel) {
300 dbgKrita <<
"Model RGB8" <<
"NOT SUPPORTED";
310 qint32 width, height;
314 resolution = doubleResolution->value() / 72.0;
316 resolution = doubleResolution->value() / 28.34;
323 QColor qc = cmbColor->color().toQColor();
328 if( radioBackgroundAsRaster->isChecked() ){
330 }
else if( radioBackgroundAsFill->isChecked() ){
334 doc->
newImage(txtName->text(), width, height, cs, bgColor, bgStyle, intNumLayers->value(), txtDescription->toPlainText(), resolution);
347 intNumLayers->setValue(layers);
352 qint32 opacity = sliderOpacity->value();
357 return (opacity * 255) / 100;
361 sliderOpacity->setValue((
value * 100) / 255);
366 cmbPredefined->clear();
369 cmbPredefined->addItem(
"");
374 if (!definitions.empty()) {
376 Q_FOREACH (
const QString &definition, definitions) {
378 f.open(QIODevice::ReadOnly);
380 QString xml = QString::fromUtf8(f.readAll());
382 predefined->fromXML(xml);
383 if (predefined->hasProperty(
"name")
384 && predefined->hasProperty(
"width")
385 && predefined->hasProperty(
"height")
386 && predefined->hasProperty(
"resolution")
387 && predefined->hasProperty(
"x-unit")
388 && predefined->hasProperty(
"y-unit")) {
390 cmbPredefined->addItem(predefined->getString(
"name"));
396 cmbPredefined->setCurrentIndex(0);
406 txtPredefinedName->setText(predefined->getString(
"name"));
408 doubleResolution->setValue(predefined->getDouble(
"resolution"));
412 cmbWidthUnit->setCurrentIndex(predefined->getInt(
"x-unit"));
413 cmbHeightUnit->setCurrentIndex(predefined->getInt(
"y-unit"));
418 doubleWidth->setValue(predefined->getDouble(
"width"));
419 doubleHeight->setValue(predefined->getDouble(
"height"));
426 QString fileName = txtPredefinedName->text();
427 if (fileName.isEmpty()) {
431 QFile f(saveLocation +
'/' + fileName.replace(
' ',
'_').replace(
'(',
'_').replace(
')',
'_').replace(
':',
'_') +
".predefinedimage");
433 f.open(QIODevice::WriteOnly | QIODevice::Truncate);
435 predefined->setProperty(
"name", txtPredefinedName->text());
436 predefined->setProperty(
"width", doubleWidth->value());
437 predefined->setProperty(
"height", doubleHeight->value());
438 predefined->setProperty(
"resolution", doubleResolution->value());
439 predefined->setProperty(
"x-unit", cmbWidthUnit->currentIndex());
440 predefined->setProperty(
"y-unit", cmbHeightUnit->currentIndex());
442 QString xml = predefined->toXML();
444 f.write(xml.toUtf8());
451 if (pr->getString(
"name") == txtPredefinedName->text()) {
462 cmbPredefined->addItem(txtPredefinedName->text());
469 if (doubleWidth->value() < doubleHeight->value()) {
476 if (doubleWidth->value() > doubleHeight->value()) {
483 double width = doubleWidth->value();
484 double height = doubleHeight->value();
486 doubleHeight->clearFocus();
487 doubleWidth->clearFocus();
489 doubleHeight->blockSignals(
true);
490 doubleWidth->blockSignals(
true);
491 cmbWidthUnit->blockSignals(
true);
492 cmbHeightUnit->blockSignals(
true);
494 doubleWidth->setValue(height);
495 doubleHeight->setValue(width);
499 doubleHeight->blockSignals(
false);
500 doubleWidth->blockSignals(
false);
501 cmbWidthUnit->blockSignals(
false);
502 cmbHeightUnit->blockSignals(
false);
512 if(doubleWidth->value() > doubleHeight->value())
513 bnLandscape->setChecked(
true);
515 bnPortrait->setChecked(
true);
521 qint64 width, height;
523 resolution = doubleResolution->value() / 72.0;
528 qint64 layerSize = width * height;
529 const KoColorSpace *cs = colorSpaceSelector->currentColorSpace();
532 QString text = i18nc(
"arg1: width. arg2: height. arg3: colorspace name. arg4: size of a channel in bits. arg5: image size",
533 "This document will be %1 pixels by %2 pixels in %3. The pixel size is %4 bit. A single paint layer will use %5 of RAM.",
538 KFormat().formatByteSize(layerSize));
539 lblDocumentInfo->setText(text);
float value(const T *src, size_t ch)
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
BackgroundStyle defaultBackgroundStyle(bool defaultValue=false) const
void setNumDefaultLayers(int num)
void setDefaultBackgroundOpacity(quint8 value)
QColor defaultBackgroundColor(bool defaultValue=false) const
void setDefaultBackgroundStyle(BackgroundStyle value)
void setDefaultBackgroundColor(const QColor &value)
int numDefaultLayers(bool defaultValue=false) const
quint8 defaultBackgroundOpacity(bool defaultValue=false) const
void setModified(bool _mod)
bool newImage(const QString &name, qint32 width, qint32 height, const KoColorSpace *cs, const KoColor &bgColor, KisConfig::BackgroundStyle bgStyle, int numberOfLayers, const QString &imageDescription, const double imageResolution)
void documentSelected(KisDocument *)
this signal is emitted (as defined by KisDocument) the moment the document is 'ready'
static KisPart * instance()
KisDocument * createDocument() const
virtual quint32 pixelSize() const =0
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
static QStringList findAllAssets(const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions)
static QString saveLocation(const QString &type, const QString &suffix=QString(), bool create=true)
static qreal convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor=1.0)
qreal fromUserValue(qreal value) const
KoUnit::Type type() const
qreal toUserValuePrecise(const qreal ptValue) const
static KoUnit fromListForUi(int index, ListOptions listOptions=ListAll, qreal factor=1.0)
static QStringList listOfUnitNameForUi(ListOptions listOptions=ListAll)
Returns the list of unit types for the UI, controlled with the given listOptions.
int indexInListForUi(ListOptions listOptions=ListAll) const
void setFactor(qreal factor)
#define KIS_SAFE_ASSERT_RECOVER(cond)
QIcon loadIcon(const QString &name)
void setText(QSpinBox *spinBox, const QStringView textTemplate)
static KoColorSpaceRegistry * instance()
static const QString pixelsCentimeterStr()
static QString pixelsInchStr()